| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | #include <config.h> | - |
| 20 | | - |
| 21 | #include "fsusage.h" | - |
| 22 | | - |
| 23 | #include <limits.h> | - |
| 24 | #include <sys/types.h> | - |
| 25 | | - |
| 26 | #if STAT_STATVFS || STAT_STATVFS64 /* POSIX 1003.1-2001 (and later) with XSI */ | - |
| 27 | # include <sys/statvfs.h> | - |
| 28 | #else | - |
| 29 | | - |
| 30 | | - |
| 31 | # include <fcntl.h> | - |
| 32 | # include <unistd.h> | - |
| 33 | # include <sys/stat.h> | - |
| 34 | #if HAVE_SYS_PARAM_H | - |
| 35 | # include <sys/param.h> | - |
| 36 | #endif | - |
| 37 | #if HAVE_SYS_MOUNT_H | - |
| 38 | # include <sys/mount.h> | - |
| 39 | #endif | - |
| 40 | #if HAVE_SYS_VFS_H | - |
| 41 | # include <sys/vfs.h> | - |
| 42 | #endif | - |
| 43 | # if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */ | - |
| 44 | # include <sys/fs/s5param.h> | - |
| 45 | # endif | - |
| 46 | # if HAVE_SYS_STATFS_H | - |
| 47 | # include <sys/statfs.h> | - |
| 48 | # endif | - |
| 49 | # if HAVE_DUSTAT_H /* AIX PS/2 */ | - |
| 50 | # include <sys/dustat.h> | - |
| 51 | # endif | - |
| 52 | #endif | - |
| 53 | | - |
| 54 | | - |
| 55 | | - |
| 56 | | - |
| 57 | | - |
| 58 | #define PROPAGATE_ALL_ONES(x) \ | - |
| 59 | ((sizeof (x) < sizeof (uintmax_t) \ | - |
| 60 | && (~ (x) == (sizeof (x) < sizeof (int) \ | - |
| 61 | ? - (1 << (sizeof (x) * CHAR_BIT)) \ | - |
| 62 | : 0))) \ | - |
| 63 | ? UINTMAX_MAX : (uintmax_t) (x)) | - |
| 64 | | - |
| 65 | | - |
| 66 | #define EXTRACT_TOP_BIT(x) ((x) \ | - |
| 67 | & ((uintmax_t) 1 << (sizeof (x) * CHAR_BIT - 1))) | - |
| 68 | | - |
| 69 | | - |
| 70 | | - |
| 71 | | - |
| 72 | | - |
| 73 | | - |
| 74 | | - |
| 75 | | - |
| 76 | #define PROPAGATE_TOP_BIT(x) ((x) | ~ (EXTRACT_TOP_BIT (x) - 1)) | - |
| 77 | | - |
| 78 | #ifdef STAT_STATVFS | - |
| 79 | | - |
| 80 | | - |
| 81 | | - |
| 82 | | - |
| 83 | # if ! (__linux__ && (__GLIBC__ || __UCLIBC__)) | - |
| 84 | | - |
| 85 | # undef STAT_STATFS2_FRSIZE | - |
| 86 | static int statvfs_works (void) { return 1; } | - |
| 87 | # else | - |
| 88 | # include <string.h> /* for strverscmp */ | - |
| 89 | # include <sys/utsname.h> | - |
| 90 | # include <sys/statfs.h> | - |
| 91 | # define STAT_STATFS2_BSIZE 1 | - |
| 92 | | - |
| 93 | static int | - |
| 94 | statvfs_works (void) | - |
| 95 | { | - |
| 96 | static int statvfs_works_cache = -1; | - |
| 97 | struct utsname name; | - |
| 98 | if (statvfs_works_cache < 0)| TRUE | evaluated 67 times by 1 test | | FALSE | evaluated 450 times by 1 test |
| 67-450 |
| 99 | statvfs_works_cache = (uname (&name) == 0executed 67 times by 1 test: statvfs_works_cache = (uname (&name) == 0 && 0 <= strverscmp (name.release, "2.6.36")); | TRUE | evaluated 67 times by 1 test | | FALSE | never evaluated |
| 0-67 |
| 100 | && 0 <= strverscmp (name.release, "2.6.36"));executed 67 times by 1 test: statvfs_works_cache = (uname (&name) == 0 && 0 <= strverscmp (name.release, "2.6.36")); | TRUE | evaluated 67 times by 1 test | | FALSE | never evaluated |
| 0-67 |
| 101 | return statvfs_works_cache;executed 517 times by 1 test: return statvfs_works_cache; | 517 |
| 102 | } | - |
| 103 | # endif | - |
| 104 | #endif | - |
| 105 | | - |
| 106 | | - |
| 107 | | - |
| 108 | | - |
| 109 | | - |
| 110 | | - |
| 111 | | - |
| 112 | | - |
| 113 | | - |
| 114 | int | - |
| 115 | get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | - |
| 116 | { | - |
| 117 | #ifdef STAT_STATVFS /* POSIX, except pre-2.6.36 glibc/Linux */ | - |
| 118 | | - |
| 119 | if (statvfs_works ())| TRUE | evaluated 517 times by 1 test | | FALSE | never evaluated |
| 0-517 |
| 120 | { | - |
| 121 | struct statvfs vfsd; | - |
| 122 | | - |
| 123 | if (statvfs (file, &vfsd) < 0)| TRUE | evaluated 1 time by 1 test | | FALSE | evaluated 516 times by 1 test |
| 1-516 |
| 124 | return -1;executed 1 time by 1 test: return -1; | 1 |
| 125 | | - |
| 126 | | - |
| 127 | fsp->fsu_blocksize = (vfsd.f_frsize| TRUE | evaluated 516 times by 1 test | | FALSE | never evaluated |
| 0-516 |
| 128 | ? PROPAGATE_ALL_ONES (vfsd.f_frsize)| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | evaluated 516 times by 1 test |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0-516 |
| 129 | : PROPAGATE_ALL_ONES (vfsd.f_bsize));| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 130 | | - |
| 131 | fsp->fsu_blocks = PROPAGATE_ALL_ONES (vfsd.f_blocks);| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | evaluated 516 times by 1 test |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0-516 |
| 132 | fsp->fsu_bfree = PROPAGATE_ALL_ONES (vfsd.f_bfree);| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | evaluated 516 times by 1 test |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0-516 |
| 133 | fsp->fsu_bavail = PROPAGATE_TOP_BIT (vfsd.f_bavail); | - |
| 134 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (vfsd.f_bavail) != 0; | - |
| 135 | fsp->fsu_files = PROPAGATE_ALL_ONES (vfsd.f_files);| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | evaluated 516 times by 1 test |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0-516 |
| 136 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (vfsd.f_ffree);| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | evaluated 516 times by 1 test |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0-516 |
| 137 | return 0;executed 516 times by 1 test: return 0; | 516 |
| 138 | } | - |
| 139 | | - |
| 140 | #endif | - |
| 141 | | - |
| 142 | #if defined STAT_STATVFS64 /* AIX */ | - |
| 143 | | - |
| 144 | struct statvfs64 fsd; | - |
| 145 | | - |
| 146 | if (statvfs64 (file, &fsd) < 0) | - |
| 147 | return -1; | - |
| 148 | | - |
| 149 | | - |
| 150 | fsp->fsu_blocksize = (fsd.f_frsize | - |
| 151 | ? PROPAGATE_ALL_ONES (fsd.f_frsize) | - |
| 152 | : PROPAGATE_ALL_ONES (fsd.f_bsize)); | - |
| 153 | | - |
| 154 | #elif defined STAT_STATFS2_FS_DATA /* Ultrix */ | - |
| 155 | | - |
| 156 | struct fs_data fsd; | - |
| 157 | | - |
| 158 | if (statfs (file, &fsd) != 1) | - |
| 159 | return -1; | - |
| 160 | | - |
| 161 | fsp->fsu_blocksize = 1024; | - |
| 162 | fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.fd_req.btot); | - |
| 163 | fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.fd_req.bfree); | - |
| 164 | fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.fd_req.bfreen); | - |
| 165 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.fd_req.bfreen) != 0; | - |
| 166 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot); | - |
| 167 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); | - |
| 168 | | - |
| 169 | #elif defined STAT_STATFS3_OSF1 /* OSF/1 */ | - |
| 170 | | - |
| 171 | struct statfs fsd; | - |
| 172 | | - |
| 173 | if (statfs (file, &fsd, sizeof (struct statfs)) != 0) | - |
| 174 | return -1; | - |
| 175 | | - |
| 176 | fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); | - |
| 177 | | - |
| 178 | #elif defined STAT_STATFS2_FRSIZE /* 2.6 < glibc/Linux < 2.6.36 */ | - |
| 179 | | - |
| 180 | struct statfs fsd; | - |
| 181 | | - |
| 182 | if (statfs (file, &fsd) < 0)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 183 | return -1; never executed: return -1; | 0 |
| 184 | | - |
| 185 | fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_frsize);| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 186 | | - |
| 187 | #elif defined STAT_STATFS2_BSIZE /* glibc/Linux < 2.6, 4.3BSD, SunOS 4, \ | - |
| 188 | Mac OS X < 10.4, FreeBSD < 5.0, \ | - |
| 189 | NetBSD < 3.0, OpenBSD < 4.4 */ | - |
| 190 | | - |
| 191 | struct statfs fsd; | - |
| 192 | | - |
| 193 | if (statfs (file, &fsd) < 0) | - |
| 194 | return -1; | - |
| 195 | | - |
| 196 | fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_bsize); | - |
| 197 | | - |
| 198 | # ifdef STATFS_TRUNCATES_BLOCK_COUNTS | - |
| 199 | | - |
| 200 | | - |
| 201 | | - |
| 202 | | - |
| 203 | | - |
| 204 | | - |
| 205 | if (fsd.f_blocks == 0x7fffffff / fsd.f_bsize && fsd.f_spare[0] > 0) | - |
| 206 | { | - |
| 207 | fsd.f_blocks = fsd.f_spare[0]; | - |
| 208 | fsd.f_bfree = fsd.f_spare[1]; | - |
| 209 | fsd.f_bavail = fsd.f_spare[2]; | - |
| 210 | } | - |
| 211 | # endif /* STATFS_TRUNCATES_BLOCK_COUNTS */ | - |
| 212 | | - |
| 213 | #elif defined STAT_STATFS2_FSIZE /* 4.4BSD and older NetBSD */ | - |
| 214 | | - |
| 215 | struct statfs fsd; | - |
| 216 | | - |
| 217 | if (statfs (file, &fsd) < 0) | - |
| 218 | return -1; | - |
| 219 | | - |
| 220 | fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); | - |
| 221 | | - |
| 222 | #elif defined STAT_STATFS4 /* SVR3, Dynix, old Irix, old AIX, \ | - |
| 223 | Dolphin */ | - |
| 224 | | - |
| 225 | # if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN | - |
| 226 | # define f_bavail f_bfree | - |
| 227 | # endif | - |
| 228 | | - |
| 229 | struct statfs fsd; | - |
| 230 | | - |
| 231 | if (statfs (file, &fsd, sizeof fsd, 0) < 0) | - |
| 232 | return -1; | - |
| 233 | | - |
| 234 | | - |
| 235 | | - |
| 236 | | - |
| 237 | # if _AIX || defined _CRAY | - |
| 238 | fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_bsize); | - |
| 239 | # else | - |
| 240 | fsp->fsu_blocksize = 512; | - |
| 241 | # endif | - |
| 242 | | - |
| 243 | #endif | - |
| 244 | | - |
| 245 | #if (defined STAT_STATVFS64 || defined STAT_STATFS3_OSF1 \ | - |
| 246 | || defined STAT_STATFS2_FRSIZE || defined STAT_STATFS2_BSIZE \ | - |
| 247 | || defined STAT_STATFS2_FSIZE || defined STAT_STATFS4) | - |
| 248 | | - |
| 249 | fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.f_blocks);| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 250 | fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.f_bfree);| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 251 | fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.f_bavail); | - |
| 252 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.f_bavail) != 0; | - |
| 253 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files);| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 254 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree);| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 255 | | - |
| 256 | #endif | - |
| 257 | | - |
| 258 | (void) disk; | - |
| 259 | return 0; never executed: return 0; | 0 |
| 260 | } | - |
| 261 | | - |
| 262 | #if defined _AIX && defined _I386 | - |
| 263 | | - |
| 264 | | - |
| 265 | int | - |
| 266 | statfs (char *file, struct statfs *fsb) | - |
| 267 | { | - |
| 268 | struct stat stats; | - |
| 269 | struct dustat fsd; | - |
| 270 | | - |
| 271 | if (stat (file, &stats) != 0) | - |
| 272 | return -1; | - |
| 273 | if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd))) | - |
| 274 | return -1; | - |
| 275 | fsb->f_type = 0; | - |
| 276 | fsb->f_bsize = fsd.du_bsize; | - |
| 277 | fsb->f_blocks = fsd.du_fsize - fsd.du_isize; | - |
| 278 | fsb->f_bfree = fsd.du_tfree; | - |
| 279 | fsb->f_bavail = fsd.du_tfree; | - |
| 280 | fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb; | - |
| 281 | fsb->f_ffree = fsd.du_tinode; | - |
| 282 | fsb->f_fsid.val[0] = fsd.du_site; | - |
| 283 | fsb->f_fsid.val[1] = fsd.du_pckno; | - |
| 284 | return 0; | - |
| 285 | } | - |
| 286 | | - |
| 287 | #endif /* _AIX && _I386 */ | - |
| | |