df.c revision 1.73 1 1.73 christos /* $NetBSD: df.c,v 1.73 2007/06/24 01:52:46 christos Exp $ */
2 1.19 cgd
3 1.12 cgd /*
4 1.15 mycroft * Copyright (c) 1980, 1990, 1993, 1994
5 1.15 mycroft * The Regents of the University of California. All rights reserved.
6 1.12 cgd * (c) UNIX System Laboratories, Inc.
7 1.12 cgd * All or some portions of this file are derived from material licensed
8 1.12 cgd * to the University of California by American Telephone and Telegraph
9 1.12 cgd * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 1.12 cgd * the permission of UNIX System Laboratories, Inc.
11 1.12 cgd *
12 1.12 cgd * Redistribution and use in source and binary forms, with or without
13 1.12 cgd * modification, are permitted provided that the following conditions
14 1.12 cgd * are met:
15 1.12 cgd * 1. Redistributions of source code must retain the above copyright
16 1.12 cgd * notice, this list of conditions and the following disclaimer.
17 1.12 cgd * 2. Redistributions in binary form must reproduce the above copyright
18 1.12 cgd * notice, this list of conditions and the following disclaimer in the
19 1.12 cgd * documentation and/or other materials provided with the distribution.
20 1.49 agc * 3. Neither the name of the University nor the names of its contributors
21 1.12 cgd * may be used to endorse or promote products derived from this software
22 1.12 cgd * without specific prior written permission.
23 1.12 cgd *
24 1.12 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.12 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.12 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.12 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.12 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.12 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.12 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.12 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.12 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.12 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.12 cgd * SUCH DAMAGE.
35 1.12 cgd */
36 1.12 cgd
37 1.24 thorpej #include <sys/cdefs.h>
38 1.12 cgd #ifndef lint
39 1.24 thorpej __COPYRIGHT(
40 1.15 mycroft "@(#) Copyright (c) 1980, 1990, 1993, 1994\n\
41 1.24 thorpej The Regents of the University of California. All rights reserved.\n");
42 1.12 cgd #endif /* not lint */
43 1.12 cgd
44 1.12 cgd #ifndef lint
45 1.19 cgd #if 0
46 1.19 cgd static char sccsid[] = "@(#)df.c 8.7 (Berkeley) 4/2/94";
47 1.19 cgd #else
48 1.73 christos __RCSID("$NetBSD: df.c,v 1.73 2007/06/24 01:52:46 christos Exp $");
49 1.19 cgd #endif
50 1.12 cgd #endif /* not lint */
51 1.12 cgd
52 1.12 cgd #include <sys/param.h>
53 1.12 cgd #include <sys/stat.h>
54 1.12 cgd #include <sys/mount.h>
55 1.27 mrg
56 1.15 mycroft #include <err.h>
57 1.12 cgd #include <errno.h>
58 1.12 cgd #include <fcntl.h>
59 1.44 provos #include <util.h>
60 1.12 cgd #include <stdio.h>
61 1.12 cgd #include <stdlib.h>
62 1.12 cgd #include <string.h>
63 1.12 cgd #include <unistd.h>
64 1.12 cgd
65 1.41 enami extern char *strpct(u_long, u_long, u_int);
66 1.26 fair
67 1.41 enami int main(int, char *[]);
68 1.41 enami int bread(off_t, void *, int);
69 1.41 enami char *getmntpt(char *);
70 1.62 christos void prtstat(struct statvfs *, int);
71 1.41 enami int selected(const char *);
72 1.41 enami void maketypelist(char *);
73 1.62 christos long regetmntinfo(struct statvfs **, long);
74 1.41 enami void usage(void);
75 1.68 christos void prthumanval(int64_t, const char *);
76 1.62 christos void prthuman(struct statvfs *, int64_t, int64_t);
77 1.66 enami const char *
78 1.66 enami strpct64(uint64_t, uint64_t, u_int);
79 1.12 cgd
80 1.73 christos int aflag, gflag, hflag, iflag, lflag, nflag, Pflag;
81 1.73 christos long usize = 0;
82 1.17 mycroft char **typelist = NULL;
83 1.12 cgd
84 1.12 cgd int
85 1.41 enami main(int argc, char *argv[])
86 1.12 cgd {
87 1.12 cgd struct stat stbuf;
88 1.62 christos struct statvfs *mntbuf;
89 1.17 mycroft long mntsize;
90 1.17 mycroft int ch, i, maxwidth, width;
91 1.12 cgd char *mntpt;
92 1.12 cgd
93 1.73 christos while ((ch = getopt(argc, argv, "aGghiklmnPt:")) != -1)
94 1.15 mycroft switch (ch) {
95 1.34 christos case 'a':
96 1.34 christos aflag = 1;
97 1.34 christos break;
98 1.73 christos case 'G':
99 1.71 christos hflag = 0;
100 1.71 christos usize = 1024 * 1024 * 1024;
101 1.46 grant break;
102 1.73 christos case 'g':
103 1.73 christos gflag = 1;
104 1.73 christos break;
105 1.44 provos case 'h':
106 1.44 provos hflag = 1;
107 1.71 christos usize = 0;
108 1.44 provos break;
109 1.12 cgd case 'i':
110 1.12 cgd iflag = 1;
111 1.12 cgd break;
112 1.12 cgd case 'k':
113 1.71 christos hflag = 0;
114 1.71 christos usize = 1024;
115 1.12 cgd break;
116 1.12 cgd case 'l':
117 1.17 mycroft lflag = 1;
118 1.12 cgd break;
119 1.36 hubertf case 'm':
120 1.71 christos hflag = 0;
121 1.71 christos usize = 1024 * 1024;
122 1.36 hubertf break;
123 1.12 cgd case 'n':
124 1.12 cgd nflag = 1;
125 1.12 cgd break;
126 1.35 kleink case 'P':
127 1.35 kleink Pflag = 1;
128 1.35 kleink break;
129 1.16 mycroft case 't':
130 1.17 mycroft if (typelist != NULL)
131 1.17 mycroft errx(1, "only one -t option may be specified.");
132 1.17 mycroft maketypelist(optarg);
133 1.16 mycroft break;
134 1.12 cgd case '?':
135 1.12 cgd default:
136 1.12 cgd usage();
137 1.12 cgd }
138 1.73 christos
139 1.73 christos if (gflag && (Pflag || iflag))
140 1.73 christos errx(1, "only one of -g and -P or -i may be specified");
141 1.73 christos if (Pflag && iflag)
142 1.73 christos errx(1, "only one of -P and -i may be specified");
143 1.73 christos
144 1.12 cgd argc -= optind;
145 1.12 cgd argv += optind;
146 1.12 cgd
147 1.17 mycroft mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
148 1.12 cgd if (mntsize == 0)
149 1.41 enami err(1, "retrieving information on mounted file systems");
150 1.15 mycroft
151 1.41 enami if (*argv == NULL) {
152 1.17 mycroft mntsize = regetmntinfo(&mntbuf, mntsize);
153 1.17 mycroft } else {
154 1.70 rumble if ((mntbuf = malloc(argc * sizeof(*mntbuf))) == NULL)
155 1.70 rumble err(1, "can't allocate statvfs array");
156 1.17 mycroft mntsize = 0;
157 1.41 enami for (; *argv != NULL; argv++) {
158 1.17 mycroft if (stat(*argv, &stbuf) < 0) {
159 1.17 mycroft if ((mntpt = getmntpt(*argv)) == 0) {
160 1.17 mycroft warn("%s", *argv);
161 1.12 cgd continue;
162 1.12 cgd }
163 1.18 mycroft } else if (S_ISBLK(stbuf.st_mode)) {
164 1.43 soren if ((mntpt = getmntpt(*argv)) == 0)
165 1.43 soren mntpt = *argv;
166 1.17 mycroft } else
167 1.17 mycroft mntpt = *argv;
168 1.17 mycroft /*
169 1.17 mycroft * Statfs does not take a `wait' flag, so we cannot
170 1.17 mycroft * implement nflag here.
171 1.17 mycroft */
172 1.62 christos if (!statvfs(mntpt, &mntbuf[mntsize]))
173 1.23 thorpej if (lflag &&
174 1.62 christos (mntbuf[mntsize].f_flag & MNT_LOCAL) == 0)
175 1.23 thorpej warnx("Warning: %s is not a local %s",
176 1.23 thorpej *argv, "file system");
177 1.23 thorpej else if
178 1.23 thorpej (!selected(mntbuf[mntsize].f_fstypename))
179 1.23 thorpej warnx("Warning: %s mounted as a %s %s",
180 1.23 thorpej *argv,
181 1.23 thorpej mntbuf[mntsize].f_fstypename,
182 1.23 thorpej "file system");
183 1.23 thorpej else
184 1.23 thorpej ++mntsize;
185 1.17 mycroft else
186 1.17 mycroft warn("%s", *argv);
187 1.12 cgd }
188 1.12 cgd }
189 1.17 mycroft
190 1.17 mycroft maxwidth = 0;
191 1.17 mycroft for (i = 0; i < mntsize; i++) {
192 1.17 mycroft width = strlen(mntbuf[i].f_mntfromname);
193 1.17 mycroft if (width > maxwidth)
194 1.17 mycroft maxwidth = width;
195 1.17 mycroft }
196 1.17 mycroft for (i = 0; i < mntsize; i++)
197 1.17 mycroft prtstat(&mntbuf[i], maxwidth);
198 1.17 mycroft exit(0);
199 1.29 mycroft /* NOTREACHED */
200 1.12 cgd }
201 1.12 cgd
202 1.12 cgd char *
203 1.41 enami getmntpt(char *name)
204 1.12 cgd {
205 1.17 mycroft long mntsize, i;
206 1.62 christos struct statvfs *mntbuf;
207 1.12 cgd
208 1.17 mycroft mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
209 1.12 cgd for (i = 0; i < mntsize; i++) {
210 1.12 cgd if (!strcmp(mntbuf[i].f_mntfromname, name))
211 1.12 cgd return (mntbuf[i].f_mntonname);
212 1.12 cgd }
213 1.12 cgd return (0);
214 1.12 cgd }
215 1.12 cgd
216 1.17 mycroft static enum { IN_LIST, NOT_IN_LIST } which;
217 1.17 mycroft
218 1.17 mycroft int
219 1.41 enami selected(const char *type)
220 1.17 mycroft {
221 1.17 mycroft char **av;
222 1.17 mycroft
223 1.17 mycroft /* If no type specified, it's always selected. */
224 1.17 mycroft if (typelist == NULL)
225 1.17 mycroft return (1);
226 1.17 mycroft for (av = typelist; *av != NULL; ++av)
227 1.20 cgd if (!strncmp(type, *av, MFSNAMELEN))
228 1.17 mycroft return (which == IN_LIST ? 1 : 0);
229 1.17 mycroft return (which == IN_LIST ? 0 : 1);
230 1.17 mycroft }
231 1.16 mycroft
232 1.16 mycroft void
233 1.41 enami maketypelist(char *fslist)
234 1.16 mycroft {
235 1.17 mycroft int i;
236 1.17 mycroft char *nextcp, **av;
237 1.16 mycroft
238 1.17 mycroft if ((fslist == NULL) || (fslist[0] == '\0'))
239 1.17 mycroft errx(1, "empty type list");
240 1.16 mycroft
241 1.17 mycroft /*
242 1.17 mycroft * XXX
243 1.17 mycroft * Note: the syntax is "noxxx,yyy" for no xxx's and
244 1.17 mycroft * no yyy's, not the more intuitive "noyyy,noyyy".
245 1.17 mycroft */
246 1.17 mycroft if (fslist[0] == 'n' && fslist[1] == 'o') {
247 1.17 mycroft fslist += 2;
248 1.17 mycroft which = NOT_IN_LIST;
249 1.17 mycroft } else
250 1.17 mycroft which = IN_LIST;
251 1.17 mycroft
252 1.17 mycroft /* Count the number of types. */
253 1.24 thorpej for (i = 1, nextcp = fslist;
254 1.24 thorpej (nextcp = strchr(nextcp, ',')) != NULL; i++)
255 1.17 mycroft ++nextcp;
256 1.17 mycroft
257 1.17 mycroft /* Build an array of that many types. */
258 1.17 mycroft if ((av = typelist = malloc((i + 1) * sizeof(char *))) == NULL)
259 1.24 thorpej err(1, "can't allocate type array");
260 1.17 mycroft av[0] = fslist;
261 1.24 thorpej for (i = 1, nextcp = fslist;
262 1.24 thorpej (nextcp = strchr(nextcp, ',')) != NULL; i++) {
263 1.17 mycroft *nextcp = '\0';
264 1.17 mycroft av[i] = ++nextcp;
265 1.16 mycroft }
266 1.17 mycroft /* Terminate the array. */
267 1.17 mycroft av[i] = NULL;
268 1.17 mycroft }
269 1.16 mycroft
270 1.17 mycroft /*
271 1.17 mycroft * Make a pass over the filesystem info in ``mntbuf'' filtering out
272 1.17 mycroft * filesystem types not in ``fsmask'' and possibly re-stating to get
273 1.62 christos * current (not cached) info. Returns the new count of valid statvfs bufs.
274 1.17 mycroft */
275 1.17 mycroft long
276 1.62 christos regetmntinfo(struct statvfs **mntbufp, long mntsize)
277 1.17 mycroft {
278 1.17 mycroft int i, j;
279 1.62 christos struct statvfs *mntbuf;
280 1.16 mycroft
281 1.42 christos if (!lflag && typelist == NULL && aflag)
282 1.17 mycroft return (nflag ? mntsize : getmntinfo(mntbufp, MNT_WAIT));
283 1.16 mycroft
284 1.17 mycroft mntbuf = *mntbufp;
285 1.17 mycroft j = 0;
286 1.17 mycroft for (i = 0; i < mntsize; i++) {
287 1.62 christos if (!aflag && (mntbuf[i].f_flag & MNT_IGNORE) != 0)
288 1.34 christos continue;
289 1.62 christos if (lflag && (mntbuf[i].f_flag & MNT_LOCAL) == 0)
290 1.17 mycroft continue;
291 1.17 mycroft if (!selected(mntbuf[i].f_fstypename))
292 1.17 mycroft continue;
293 1.17 mycroft if (nflag)
294 1.17 mycroft mntbuf[j] = mntbuf[i];
295 1.32 sommerfe else {
296 1.62 christos struct statvfs layerbuf = mntbuf[i];
297 1.62 christos (void)statvfs(mntbuf[i].f_mntonname, &mntbuf[j]);
298 1.32 sommerfe /*
299 1.32 sommerfe * If the FS name changed, then new data is for
300 1.32 sommerfe * a different layer and we don't want it.
301 1.32 sommerfe */
302 1.41 enami if (memcmp(layerbuf.f_mntfromname,
303 1.41 enami mntbuf[j].f_mntfromname, MNAMELEN))
304 1.41 enami mntbuf[j] = layerbuf;
305 1.32 sommerfe }
306 1.17 mycroft j++;
307 1.16 mycroft }
308 1.17 mycroft return (j);
309 1.16 mycroft }
310 1.16 mycroft
311 1.44 provos void
312 1.68 christos prthumanval(int64_t bytes, const char *pad)
313 1.44 provos {
314 1.59 enami char buf[6];
315 1.44 provos
316 1.59 enami humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1),
317 1.59 enami bytes, "", HN_AUTOSCALE,
318 1.44 provos HN_B | HN_NOSPACE | HN_DECIMAL);
319 1.44 provos
320 1.44 provos (void)printf("%s %6s", pad, buf);
321 1.44 provos }
322 1.44 provos
323 1.44 provos void
324 1.62 christos prthuman(struct statvfs *sfsp, int64_t used, int64_t bavail)
325 1.44 provos {
326 1.60 enami
327 1.62 christos prthumanval(sfsp->f_blocks * sfsp->f_frsize, "");
328 1.72 christos prthumanval(used * sfsp->f_frsize, " ");
329 1.73 christos prthumanval(bavail * sfsp->f_frsize, " ");
330 1.44 provos }
331 1.44 provos
332 1.12 cgd /*
333 1.62 christos * Convert statvfs returned filesystem size into BLOCKSIZE units.
334 1.15 mycroft * Attempts to avoid overflow for large filesystems.
335 1.15 mycroft */
336 1.41 enami #define fsbtoblk(num, fsbs, bs) \
337 1.41 enami (((fsbs) != 0 && (fsbs) < (bs)) ? \
338 1.63 martin (int64_t)(num) / (int64_t)((bs) / (fsbs)) : \
339 1.56 enami (int64_t)(num) * ((fsbs) / (bs)))
340 1.15 mycroft
341 1.15 mycroft /*
342 1.12 cgd * Print out status about a filesystem.
343 1.12 cgd */
344 1.12 cgd void
345 1.62 christos prtstat(struct statvfs *sfsp, int maxwidth)
346 1.12 cgd {
347 1.17 mycroft static long blocksize;
348 1.12 cgd static int headerlen, timesthrough;
349 1.68 christos static const char *header;
350 1.58 enami static const char full[] = "100%";
351 1.58 enami static const char empty[] = " 0%";
352 1.62 christos int64_t used, availblks, inodes;
353 1.60 enami int64_t bavail;
354 1.12 cgd
355 1.73 christos if (gflag) {
356 1.73 christos /*
357 1.73 christos * From SunOS-5.6:
358 1.73 christos *
359 1.73 christos * /var (/dev/dsk/c0t0d0s3 ): 8192 block size 1024 frag size
360 1.73 christos * 984242 total blocks 860692 free blocks 859708 available 249984 total files
361 1.73 christos * 248691 free files 8388611 filesys id
362 1.73 christos * ufs fstype 0x00000004 flag 255 filename length
363 1.73 christos *
364 1.73 christos */
365 1.73 christos (void)printf("%10s (%-12s): %7ld block size %12ld frag size\n",
366 1.73 christos sfsp->f_mntonname, sfsp->f_mntfromname,
367 1.73 christos sfsp->f_iosize, /* On UFS/FFS systems this is
368 1.73 christos * also called the "optimal
369 1.73 christos * transfer block size" but it
370 1.73 christos * is of course the file
371 1.73 christos * system's block size too.
372 1.73 christos */
373 1.73 christos sfsp->f_bsize); /* not so surprisingly the
374 1.73 christos * "fundamental file system
375 1.73 christos * block size" is the frag
376 1.73 christos * size.
377 1.73 christos */
378 1.73 christos (void)printf("%10" PRId64 " total blocks %10" PRId64
379 1.73 christos " free blocks %10" PRId64 " available\n",
380 1.73 christos (uint64_t)sfsp->f_blocks, (uint64_t)sfsp->f_bfree,
381 1.73 christos (uint64_t)sfsp->f_bavail);
382 1.73 christos (void)printf("%10" PRId64 " total files %10" PRId64
383 1.73 christos " free files %12lx filesys id\n",
384 1.73 christos (uint64_t)sfsp->f_ffree, (uint64_t)sfsp->f_files,
385 1.73 christos sfsp->f_fsid);
386 1.73 christos (void)printf("%10s fstype %#15lx flag %17ld filename "
387 1.73 christos "length\n", sfsp->f_fstypename, sfsp->f_flag,
388 1.73 christos sfsp->f_namemax);
389 1.73 christos (void)printf("%10lu owner %17" PRId64 " syncwrites %12" PRId64
390 1.73 christos " asyncwrites\n\n", (unsigned long)sfsp->f_owner,
391 1.73 christos sfsp->f_syncwrites, sfsp->f_asyncwrites);
392 1.73 christos
393 1.73 christos /*
394 1.73 christos * a concession by the structured programming police to the
395 1.73 christos * indentation police....
396 1.73 christos */
397 1.73 christos return;
398 1.73 christos }
399 1.73 christos if (maxwidth < 12)
400 1.73 christos maxwidth = 12;
401 1.12 cgd if (++timesthrough == 1) {
402 1.71 christos switch (blocksize = usize) {
403 1.71 christos case 1024:
404 1.35 kleink header = Pflag ? "1024-blocks" : "1K-blocks";
405 1.12 cgd headerlen = strlen(header);
406 1.71 christos break;
407 1.71 christos case 1024 * 1024:
408 1.36 hubertf header = Pflag ? "1048576-blocks" : "1M-blocks";
409 1.36 hubertf headerlen = strlen(header);
410 1.71 christos break;
411 1.71 christos case 1024 * 1024 * 1024:
412 1.46 grant header = Pflag ? "1073741824-blocks" : "1G-blocks";
413 1.46 grant headerlen = strlen(header);
414 1.71 christos break;
415 1.71 christos default:
416 1.71 christos if (hflag) {
417 1.71 christos header = " Size";
418 1.71 christos headerlen = strlen(header);
419 1.71 christos } else
420 1.71 christos header = getbsize(&headerlen, &blocksize);
421 1.71 christos break;
422 1.71 christos }
423 1.73 christos if (Pflag) {
424 1.73 christos /*
425 1.73 christos * "Filesystem {1024,512}-blocks Used Available
426 1.73 christos * Capacity Mounted on\n"
427 1.73 christos */
428 1.73 christos (void)printf("Filesystem %s Used Available Capacity "
429 1.73 christos "Mounted on\n", header);
430 1.73 christos } else {
431 1.73 christos (void)printf("%-*.*s %s Used Avail %%Cap",
432 1.73 christos maxwidth - (headerlen - 9),
433 1.73 christos maxwidth - (headerlen - 9),
434 1.73 christos "Filesystem", header);
435 1.73 christos if (iflag)
436 1.73 christos (void)printf(" iUsed iAvail %%iCap");
437 1.73 christos (void)printf(" Mounted on\n");
438 1.73 christos }
439 1.12 cgd }
440 1.12 cgd used = sfsp->f_blocks - sfsp->f_bfree;
441 1.62 christos bavail = sfsp->f_bfree - sfsp->f_bresvd;
442 1.62 christos availblks = bavail + used;
443 1.73 christos if (Pflag) {
444 1.73 christos /*
445 1.73 christos * "%s %d %d %d %s %s\n", <file system name>, <total space>,
446 1.73 christos * <space used>, <space free>, <percentage used>,
447 1.73 christos * <file system root>
448 1.73 christos */
449 1.73 christos (void)printf("%s %" PRId64 " %" PRId64 " %" PRId64 " %s %s\n",
450 1.73 christos sfsp->f_mntfromname,
451 1.73 christos fsbtoblk(sfsp->f_blocks, sfsp->f_bsize, blocksize),
452 1.73 christos fsbtoblk(used, sfsp->f_bsize, blocksize),
453 1.73 christos fsbtoblk(sfsp->f_bavail, sfsp->f_bsize, blocksize),
454 1.73 christos availblks == 0 ? full : strpct64((uint64_t) used,
455 1.73 christos (uint64_t) availblks, 0), sfsp->f_mntonname);
456 1.73 christos /*
457 1.73 christos * another concession by the structured programming police to
458 1.73 christos * the indentation police....
459 1.73 christos *
460 1.73 christos * Note iflag cannot be set when Pflag is set.
461 1.73 christos */
462 1.73 christos return;
463 1.73 christos }
464 1.73 christos
465 1.73 christos (void)printf("%-*.*s", maxwidth, maxwidth, sfsp->f_mntfromname);
466 1.73 christos
467 1.44 provos if (hflag)
468 1.65 enami prthuman(sfsp, used, bavail);
469 1.61 enami else
470 1.73 christos (void)printf("%10" PRId64 " %10" PRId64 " %10" PRId64,
471 1.62 christos fsbtoblk(sfsp->f_blocks, sfsp->f_frsize, blocksize),
472 1.62 christos fsbtoblk(used, sfsp->f_frsize, blocksize),
473 1.62 christos fsbtoblk(bavail, sfsp->f_frsize, blocksize));
474 1.73 christos (void)printf(" %4s",
475 1.66 enami availblks == 0 ? full :
476 1.66 enami /* We know that these values are never negative */
477 1.66 enami strpct64((uint64_t)used, (uint64_t)availblks, 0));
478 1.12 cgd if (iflag) {
479 1.12 cgd inodes = sfsp->f_files;
480 1.12 cgd used = inodes - sfsp->f_ffree;
481 1.73 christos (void)printf(" %8ld %8ld %4s",
482 1.64 enami (u_long)used, (u_long)sfsp->f_ffree,
483 1.57 enami inodes == 0 ? (used == 0 ? empty : full) :
484 1.66 enami strpct64((uint64_t)used, (uint64_t)inodes, 0));
485 1.73 christos }
486 1.73 christos (void)printf(" %s\n", sfsp->f_mntonname);
487 1.12 cgd }
488 1.12 cgd
489 1.12 cgd void
490 1.41 enami usage(void)
491 1.12 cgd {
492 1.41 enami
493 1.34 christos (void)fprintf(stderr,
494 1.73 christos "Usage: %s [-aGghklmn] [-i|-p] [-t type] [file | "
495 1.73 christos "file_system ...]\n",
496 1.40 cgd getprogname());
497 1.12 cgd exit(1);
498 1.30 mycroft /* NOTREACHED */
499 1.12 cgd }
500 1.66 enami
501 1.66 enami const char *
502 1.66 enami strpct64(uint64_t numerator, uint64_t denominator, u_int digits)
503 1.66 enami {
504 1.66 enami
505 1.66 enami while (denominator > ULONG_MAX) {
506 1.66 enami numerator >>= 1;
507 1.66 enami denominator >>= 1;
508 1.66 enami }
509 1.66 enami return (strpct((u_long)numerator, (u_long)denominator, digits));
510 1.66 enami }
511