DskDevNo

From Pickwiki
Jump to navigationJump to search

this program has one flaw, when accessing NFS mounted system, I get a negative number. I would like it to be a positive number instead. Anyone is welcome to fix the sign bit when you find it.

/* Author: Glen Herberta                     */
/* Created: ????                             */
/* Compile normal cc dskdevno.c -o dskdevno  */
/*   */
/*   */
/*   */
#include        <stdio.h>
#include                <sys/types.h>
#include                <sys/stat.h>
#include                <fcntl.h>

main()
{
        int fp,fstb,ret,offset=0,onset=0;
        char    buffer[8192];
        char  file[80];
        char    temp[80];
        char    temp1[80];
        struct  stat statbuf;

        fstb = open ("/etc/mnttab",[[O_RDONLY]],0);
        if (fstb == -1)
        {       /* unable to open mnttab file */
                fprintf(stderr,"ERROR: Unable to open /etc/mnttab file!\n");
                exit(1);
        }

        ret = read(fstb,buffer,8192);
        if (ret == -1)
        {       fprintf(stderr,"ERROR: Unable to read /etc/mnttab file!\n");
                exit(1);
        }
        (void)close(fstb);

        while(1)
        {       /* Grab off first file */
                (void)memset(file,0,80);
                (void)memset(temp,0,80);
                onset = 0;
                while(buffer[offset] != ' ')
                        file[onset++] = buffer[offset++];
                /* skip whitespace */
                while(buffer[offset]== ' ')
                                offset++;
                /* get mount name */
                onset = 0;
                while(buffer[offset] != ' ')
                        temp[onset++] = buffer[offset++];
                strcpy(temp1,temp);
                strcat(temp1,"/.");
                /* skip to next line */
                while(buffer[offset++] != '\n');
                /* open file */
                fp=stat(temp1,&statbuf);
                if (fp >= 0)
                {       /* display */
                        fprintf(stdout,"%12d %s\t\n",statbuf.st_dev,temp);
                }
                /* check */
                if (offset >= ret)
                        break;
        }
}