lib/fsusage.c

ソースコードを見る。

関数

static SMB_BIG_UINT adjust_blocks (SMB_BIG_UINT blocks, SMB_BIG_UINT fromsize, SMB_BIG_UINT tosize)
int sys_fsusage (const char *path, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)


関数

static SMB_BIG_UINT adjust_blocks ( SMB_BIG_UINT  blocks,
SMB_BIG_UINT  fromsize,
SMB_BIG_UINT  tosize 
) [static]

fsusage.c27 行で定義されています。

00028 {
00029         if (fromsize == tosize) { /* e.g., from 512 to 512 */
00030                 return blocks;
00031         } else if (fromsize > tosize) { /* e.g., from 2048 to 512 */
00032                 return blocks * (fromsize / tosize);
00033         } else { /* e.g., from 256 to 512 */
00034                 /* Protect against broken filesystems... */
00035                 if (fromsize == 0) {
00036                         fromsize = tosize;
00037                 }
00038                 return (blocks + 1) / (tosize / fromsize);
00039         }
00040 }

int sys_fsusage ( const char *  path,
SMB_BIG_UINT *  dfree,
SMB_BIG_UINT *  dsize 
)

fsusage.c48 行で定義されています。

参照元 print_job_start()sys_disk_free().

00049 {
00050 #ifdef STAT_STATFS3_OSF1
00051 #define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_fsize, (SMB_BIG_UINT)512)
00052         struct statfs fsd;
00053 
00054         if (statfs (path, &fsd, sizeof (struct statfs)) != 0)
00055                 return -1;
00056 #endif /* STAT_STATFS3_OSF1 */
00057         
00058 #ifdef STAT_STATFS2_FS_DATA     /* Ultrix */
00059 #define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)1024, (SMB_BIG_UINT)512)      
00060         struct fs_data fsd;
00061         
00062         if (statfs (path, &fsd) != 1)
00063                 return -1;
00064         
00065         (*dsize) = CONVERT_BLOCKS (fsd.fd_req.btot);
00066         (*dfree) = CONVERT_BLOCKS (fsd.fd_req.bfreen);
00067 #endif /* STAT_STATFS2_FS_DATA */
00068         
00069 #ifdef STAT_STATFS2_BSIZE       /* 4.3BSD, SunOS 4, HP-UX, AIX */
00070 #define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_bsize, (SMB_BIG_UINT)512)
00071         struct statfs fsd;
00072         
00073         if (statfs (path, &fsd) < 0)
00074                 return -1;
00075         
00076 #ifdef STATFS_TRUNCATES_BLOCK_COUNTS
00077         /* In SunOS 4.1.2, 4.1.3, and 4.1.3_U1, the block counts in the
00078            struct statfs are truncated to 2GB.  These conditions detect that
00079            truncation, presumably without botching the 4.1.1 case, in which
00080            the values are not truncated.  The correct counts are stored in
00081            undocumented spare fields.  */
00082         if (fsd.f_blocks == 0x1fffff && fsd.f_spare[0] > 0) {
00083                 fsd.f_blocks = fsd.f_spare[0];
00084                 fsd.f_bfree = fsd.f_spare[1];
00085                 fsd.f_bavail = fsd.f_spare[2];
00086         }
00087 #endif /* STATFS_TRUNCATES_BLOCK_COUNTS */
00088 #endif /* STAT_STATFS2_BSIZE */
00089         
00090 
00091 #ifdef STAT_STATFS2_FSIZE       /* 4.4BSD */
00092 #define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_fsize, (SMB_BIG_UINT)512)
00093         
00094         struct statfs fsd;
00095         
00096         if (statfs (path, &fsd) < 0)
00097                 return -1;
00098 #endif /* STAT_STATFS2_FSIZE */
00099         
00100 #ifdef STAT_STATFS4             /* SVR3, Dynix, Irix, AIX */
00101 # if _AIX || defined(_CRAY)
00102 #  define CONVERT_BLOCKS(B) adjust_blocks ((SMB_BIG_UINT)(B), (SMB_BIG_UINT)fsd.f_bsize, (SMB_BIG_UINT)512)
00103 #  ifdef _CRAY
00104 #   define f_bavail f_bfree
00105 #  endif
00106 # else
00107 #  define CONVERT_BLOCKS(B) ((SMB_BIG_UINT)B)
00108 #  ifndef _SEQUENT_             /* _SEQUENT_ is DYNIX/ptx */
00109 #   ifndef DOLPHIN              /* DOLPHIN 3.8.alfa/7.18 has f_bavail */
00110 #    define f_bavail f_bfree
00111 #   endif
00112 #  endif
00113 # endif
00114         
00115         struct statfs fsd;
00116 
00117         if (statfs (path, &fsd, sizeof fsd, 0) < 0)
00118                 return -1;
00119         /* Empirically, the block counts on most SVR3 and SVR3-derived
00120            systems seem to always be in terms of 512-byte blocks,
00121            no matter what value f_bsize has.  */
00122 
00123 #endif /* STAT_STATFS4 */
00124 
00125 #if defined(STAT_STATVFS) || defined(STAT_STATVFS64)            /* SVR4 */
00126 # define CONVERT_BLOCKS(B) \
00127         adjust_blocks ((SMB_BIG_UINT)(B), fsd.f_frsize ? (SMB_BIG_UINT)fsd.f_frsize : (SMB_BIG_UINT)fsd.f_bsize, (SMB_BIG_UINT)512)
00128 
00129 #ifdef STAT_STATVFS64
00130         struct statvfs64 fsd;
00131         if (statvfs64(path, &fsd) < 0) return -1;
00132 #else
00133         struct statvfs fsd;
00134         if (statvfs(path, &fsd) < 0) return -1;
00135 #endif
00136 
00137         /* f_frsize isn't guaranteed to be supported.  */
00138 
00139 #endif /* STAT_STATVFS */
00140 
00141 #ifndef CONVERT_BLOCKS
00142         /* we don't have any dfree code! */
00143         return -1;
00144 #else
00145 #if !defined(STAT_STATFS2_FS_DATA)
00146         /* !Ultrix */
00147         (*dsize) = CONVERT_BLOCKS (fsd.f_blocks);
00148         (*dfree) = CONVERT_BLOCKS (fsd.f_bavail);
00149 #endif /* not STAT_STATFS2_FS_DATA */
00150 #endif
00151 
00152         return 0;
00153 }


Sambaに対してSat Aug 29 21:23:36 2009に生成されました。  doxygen 1.4.7