home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1920 < prev    next >
Text File  |  1990-12-28  |  4KB  |  130 lines

  1. Newsgroups: alt.sources
  2. From: kimcm@diku.dk (Kim Christian Madsen)
  3. Subject: [unix-pc...] Re: is a PD implementation of statfs() available anywhere?
  4. Message-ID: <1990Oct8.023724.2034@math.lsa.umich.edu>
  5. Date: Mon, 8 Oct 90 02:37:24 GMT
  6.  
  7. Archive-name: aix-statfs/07-Oct-90
  8. Original-posting-by: kimcm@diku.dk (Kim Christian Madsen)
  9. Original-subject: Re: is a PD implementation of statfs() available anywhere?
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [Reposted from unix-pc.general,comp.sys.att,comp.unix.questions.
  13. Comments on this service to emv@math.lsa.umich.edu (Edward Vielmetti).]
  14.  
  15. dave@galaxia.Newport.RI.US (David H. Brierley) writes:
  16.  
  17. >>So, does anyone know of PD statfs()?
  18.  
  19. >I have started to work on a PD statfs call but I ran into a slight problem in
  20. >that I was not sure exactly what the call was supposed to do.  In general I
  21. >know that it returns info about a mounted file system but I'm not sure what
  22. >info it is supposed to return.  I looked through the "du" program that was
  23. >posted and determined what fields from the structure it was examining and
  24. >put togethor an include file and a library function that would fill in those
  25. >fields.  If anyone can send me a copy of the description of the statfs routine
  26. >then I can finish writing the routine and post it.
  27.  
  28. >Of course, if someone already has a PD version of statfs that they are
  29. >willing to post I would gladly use that instead.  One drawback to the statfs
  30. >routine that I have started to write is that all the information you need to
  31. >know is contained in the file systems superblock.  This means that you either
  32. >have to be writing kernel level code so that you can access the incore copy
  33. >of the superblock or you have to have read access to the raw file system or
  34. >you have to figure out how to poke through the kernel memory and find the
  35. >incore copy of the superblock.
  36.  
  37. OK, once I've written a statfs() simulation routine for the AIX system,
  38. running on an IBM PC-RT6150. If you can use it feel free to do it, but
  39. remember you might have to hack it to please your particular superblock.
  40.  
  41. If you however use SYSV R3.0 or later you should have statfs(2) as
  42. an integral part of your system call routines.
  43.  
  44.                 Kim Chr. Madsen
  45.  
  46. /*-------------------------CUT HERE-------------------------*/
  47. #ifdef HAS_STATFS
  48. #include <sys/statfs.h>
  49. #else
  50. #include <sys/param.h>
  51. #include <sys/filsys.h>
  52. #include <sys/ino.h>
  53. #endif
  54.  
  55. #define    MNTTAB    "/etc/mnttab"
  56. #define    MNTSIZ    sizeof(struct mnttab)
  57.  
  58. struct mnttab mt;
  59.  
  60. #ifndef    HAS_STATFS
  61. struct statfs {
  62.     short    f_fstyp;    /* File system type */
  63.     short    f_bsize;    /* Block Size */
  64.     short    f_frsize;    /* Fragment Size */
  65.     long    f_blocks;    /* Total number of blocks */
  66.     long    f_bfree;    /* Count of free blocks */
  67.     long    f_files;    /* Total number of file nodes */
  68.     long    f_ffree;    /* Count of free file nodes */
  69.     char    f_fname[6];    /* Volume name */
  70.     char    f_fpack[6];    /* Pack Name */
  71. };
  72. #endif /* HAS_STATFS */
  73.  
  74.  
  75. #ifndef    HAS_STATFS
  76.  
  77. #define    HD_BLOCKSIZE    2048
  78. #define    FD_BLOCKSIZE     512
  79.  
  80. int statfs(path,buf,len,fstyp)
  81. char        *path;
  82. struct statfs    *buf;
  83. int        len, fstyp;
  84. {
  85.     int        fd;
  86.     int        mntfd;
  87.     struct mnttab    tab;
  88.     filsys_t    fs;
  89.     register int    i;
  90.     char        devicename[256];
  91.     void        sync();        /* Update superblock(s) */
  92.  
  93.     if (fstyp) return(-1);
  94.     if ((mntfd=open(MNTTAB,O_RDONLY)) < 0) return(-1);
  95.     devicename[0] = 0;
  96.     while (read(mntfd,(char *)&tab,MNTSIZ) == MNTSIZ) {
  97.         if (strcmp(path,tab.mt_filsys) == 0) {
  98.             sprintf(devicename,"/dev/%s",tab.mt_dev);
  99.             break;
  100.         }
  101.     }
  102.     if (devicename[0] == 0) return(-1);
  103.     sync();
  104.     if ((fd=open(devicename,O_RDONLY)) < 0) return(-1);
  105.     lseek(fd,HD_BLOCKSIZE,0);
  106.     if (read(fd,(char *)&fs,FSfixsz) != FSfixsz)  return(-1);
  107.     if (strncmp(fs.s_magic,FSmagic,4)) return(-1);
  108.     buf->f_fstyp = (short) fs.s_type;
  109.     switch (fs.s_type) {
  110.     case Fs1b: buf->f_bsize = 512; break;
  111.     case Fs2b: buf->f_bsize = 1024; break;
  112.     case Fs4b: buf->f_bsize = 2048; break;
  113.     case Fs8b: buf->f_bsize = 4096; break;
  114.     }
  115.     buf->f_frsize = 0;    /* Unknown Value in superblock */
  116.     buf->f_blocks = (long) fs.s_fsize;
  117.     buf->f_bfree  = (long) fs.s_tfree;
  118.     buf->f_files  = (long) (fs.s_isize*buf->f_bsize)/sizeof(struct dinode);
  119.     buf->f_ffree  = (long) fs.s_tinode;
  120.     for (i=0; i<6; i++) {
  121.         buf->f_fname[i] = fs.s_fname[i];
  122.         buf->f_fpack[i] = fs.s_fpack[i];
  123.     }
  124.     close(mntfd);
  125.     close(fd);
  126.     return(0);
  127. }
  128.  
  129. #endif /* HAS_STATFS */
  130.