df.c revision 1.39 1 1.39 tsutsui /* $NetBSD: df.c,v 1.39 2001/02/01 10:19:51 tsutsui 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.12 cgd * 3. All advertising materials mentioning features or use of this software
21 1.12 cgd * must display the following acknowledgement:
22 1.12 cgd * This product includes software developed by the University of
23 1.12 cgd * California, Berkeley and its contributors.
24 1.12 cgd * 4. Neither the name of the University nor the names of its contributors
25 1.12 cgd * may be used to endorse or promote products derived from this software
26 1.12 cgd * without specific prior written permission.
27 1.12 cgd *
28 1.12 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.12 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.12 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.12 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.12 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.12 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.12 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.12 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.12 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.12 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.12 cgd * SUCH DAMAGE.
39 1.12 cgd */
40 1.12 cgd
41 1.24 thorpej #include <sys/cdefs.h>
42 1.12 cgd #ifndef lint
43 1.24 thorpej __COPYRIGHT(
44 1.15 mycroft "@(#) Copyright (c) 1980, 1990, 1993, 1994\n\
45 1.24 thorpej The Regents of the University of California. All rights reserved.\n");
46 1.12 cgd #endif /* not lint */
47 1.12 cgd
48 1.12 cgd #ifndef lint
49 1.19 cgd #if 0
50 1.19 cgd static char sccsid[] = "@(#)df.c 8.7 (Berkeley) 4/2/94";
51 1.19 cgd #else
52 1.39 tsutsui __RCSID("$NetBSD: df.c,v 1.39 2001/02/01 10:19:51 tsutsui Exp $");
53 1.19 cgd #endif
54 1.12 cgd #endif /* not lint */
55 1.12 cgd
56 1.12 cgd #include <sys/param.h>
57 1.12 cgd #include <sys/stat.h>
58 1.12 cgd #include <sys/mount.h>
59 1.27 mrg
60 1.25 fvdl #include <ufs/ufs/ufsmount.h>
61 1.15 mycroft
62 1.15 mycroft #include <err.h>
63 1.12 cgd #include <errno.h>
64 1.12 cgd #include <fcntl.h>
65 1.12 cgd #include <stdio.h>
66 1.12 cgd #include <stdlib.h>
67 1.12 cgd #include <string.h>
68 1.12 cgd #include <unistd.h>
69 1.12 cgd
70 1.26 fair extern char * strpct __P((u_long num, u_long denom, u_int digits));
71 1.38 christos extern char *__progname;
72 1.26 fair
73 1.24 thorpej int main __P((int, char *[]));
74 1.15 mycroft int bread __P((off_t, void *, int));
75 1.12 cgd char *getmntpt __P((char *));
76 1.15 mycroft void prtstat __P((struct statfs *, int));
77 1.17 mycroft int ufs_df __P((char *, struct statfs *));
78 1.17 mycroft int selected __P((const char *));
79 1.17 mycroft void maketypelist __P((char *));
80 1.17 mycroft long regetmntinfo __P((struct statfs **, long));
81 1.12 cgd void usage __P((void));
82 1.12 cgd
83 1.36 hubertf int aflag, iflag, kflag, lflag, mflag, nflag, Pflag;
84 1.17 mycroft char **typelist = NULL;
85 1.12 cgd struct ufs_args mdev;
86 1.12 cgd
87 1.12 cgd int
88 1.12 cgd main(argc, argv)
89 1.12 cgd int argc;
90 1.12 cgd char *argv[];
91 1.12 cgd {
92 1.12 cgd struct stat stbuf;
93 1.21 jtc struct statfs *mntbuf;
94 1.17 mycroft long mntsize;
95 1.17 mycroft int ch, i, maxwidth, width;
96 1.12 cgd char *mntpt;
97 1.12 cgd
98 1.36 hubertf while ((ch = getopt(argc, argv, "aiklmnPt:")) != -1)
99 1.15 mycroft switch (ch) {
100 1.34 christos case 'a':
101 1.34 christos aflag = 1;
102 1.34 christos break;
103 1.12 cgd case 'i':
104 1.12 cgd iflag = 1;
105 1.12 cgd break;
106 1.12 cgd case 'k':
107 1.12 cgd kflag = 1;
108 1.12 cgd break;
109 1.12 cgd case 'l':
110 1.17 mycroft lflag = 1;
111 1.12 cgd break;
112 1.36 hubertf case 'm':
113 1.36 hubertf mflag = 1;
114 1.36 hubertf break;
115 1.12 cgd case 'n':
116 1.12 cgd nflag = 1;
117 1.12 cgd break;
118 1.35 kleink case 'P':
119 1.35 kleink Pflag = 1;
120 1.35 kleink break;
121 1.16 mycroft case 't':
122 1.17 mycroft if (typelist != NULL)
123 1.17 mycroft errx(1, "only one -t option may be specified.");
124 1.17 mycroft maketypelist(optarg);
125 1.16 mycroft break;
126 1.12 cgd case '?':
127 1.12 cgd default:
128 1.12 cgd usage();
129 1.12 cgd }
130 1.12 cgd argc -= optind;
131 1.12 cgd argv += optind;
132 1.12 cgd
133 1.17 mycroft mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
134 1.12 cgd if (mntsize == 0)
135 1.14 glass err(1, "retrieving information on mounted file systems");
136 1.15 mycroft
137 1.12 cgd if (!*argv) {
138 1.17 mycroft mntsize = regetmntinfo(&mntbuf, mntsize);
139 1.17 mycroft } else {
140 1.17 mycroft mntbuf = malloc(argc * sizeof(struct statfs));
141 1.17 mycroft mntsize = 0;
142 1.17 mycroft for (; *argv; argv++) {
143 1.17 mycroft if (stat(*argv, &stbuf) < 0) {
144 1.17 mycroft if ((mntpt = getmntpt(*argv)) == 0) {
145 1.17 mycroft warn("%s", *argv);
146 1.12 cgd continue;
147 1.12 cgd }
148 1.18 mycroft } else if (S_ISCHR(stbuf.st_mode)) {
149 1.17 mycroft if (!ufs_df(*argv, &mntbuf[mntsize]))
150 1.17 mycroft ++mntsize;
151 1.17 mycroft continue;
152 1.18 mycroft } else if (S_ISBLK(stbuf.st_mode)) {
153 1.17 mycroft if ((mntpt = getmntpt(*argv)) == 0) {
154 1.28 mycroft mntpt = strdup("/tmp/df.XXXXXX");
155 1.28 mycroft if (!mkdtemp(mntpt)) {
156 1.17 mycroft warn("%s", mntpt);
157 1.17 mycroft continue;
158 1.17 mycroft }
159 1.28 mycroft mdev.fspec = *argv;
160 1.22 jtc if (mount(MOUNT_FFS, mntpt, MNT_RDONLY,
161 1.17 mycroft &mdev) != 0) {
162 1.17 mycroft (void)rmdir(mntpt);
163 1.27 mrg if (!ufs_df(*argv,
164 1.27 mrg &mntbuf[mntsize]))
165 1.17 mycroft ++mntsize;
166 1.17 mycroft continue;
167 1.27 mrg } else if (!statfs(mntpt,
168 1.27 mrg &mntbuf[mntsize])) {
169 1.27 mrg mntbuf[mntsize].f_mntonname[0] =
170 1.27 mrg '\0';
171 1.17 mycroft ++mntsize;
172 1.17 mycroft } else
173 1.17 mycroft warn("%s", *argv);
174 1.17 mycroft (void)unmount(mntpt, 0);
175 1.12 cgd (void)rmdir(mntpt);
176 1.12 cgd continue;
177 1.17 mycroft }
178 1.17 mycroft } else
179 1.17 mycroft mntpt = *argv;
180 1.17 mycroft /*
181 1.17 mycroft * Statfs does not take a `wait' flag, so we cannot
182 1.17 mycroft * implement nflag here.
183 1.17 mycroft */
184 1.17 mycroft if (!statfs(mntpt, &mntbuf[mntsize]))
185 1.23 thorpej if (lflag &&
186 1.23 thorpej (mntbuf[mntsize].f_flags & MNT_LOCAL) == 0)
187 1.23 thorpej warnx("Warning: %s is not a local %s",
188 1.23 thorpej *argv, "file system");
189 1.23 thorpej else if
190 1.23 thorpej (!selected(mntbuf[mntsize].f_fstypename))
191 1.23 thorpej warnx("Warning: %s mounted as a %s %s",
192 1.23 thorpej *argv,
193 1.23 thorpej mntbuf[mntsize].f_fstypename,
194 1.23 thorpej "file system");
195 1.23 thorpej else
196 1.23 thorpej ++mntsize;
197 1.17 mycroft else
198 1.17 mycroft warn("%s", *argv);
199 1.12 cgd }
200 1.12 cgd }
201 1.17 mycroft
202 1.17 mycroft maxwidth = 0;
203 1.17 mycroft for (i = 0; i < mntsize; i++) {
204 1.17 mycroft width = strlen(mntbuf[i].f_mntfromname);
205 1.17 mycroft if (width > maxwidth)
206 1.17 mycroft maxwidth = width;
207 1.17 mycroft }
208 1.17 mycroft for (i = 0; i < mntsize; i++)
209 1.17 mycroft prtstat(&mntbuf[i], maxwidth);
210 1.17 mycroft exit(0);
211 1.29 mycroft /* NOTREACHED */
212 1.12 cgd }
213 1.12 cgd
214 1.12 cgd char *
215 1.12 cgd getmntpt(name)
216 1.12 cgd char *name;
217 1.12 cgd {
218 1.17 mycroft long mntsize, i;
219 1.17 mycroft struct statfs *mntbuf;
220 1.12 cgd
221 1.17 mycroft mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
222 1.12 cgd for (i = 0; i < mntsize; i++) {
223 1.12 cgd if (!strcmp(mntbuf[i].f_mntfromname, name))
224 1.12 cgd return (mntbuf[i].f_mntonname);
225 1.12 cgd }
226 1.12 cgd return (0);
227 1.12 cgd }
228 1.12 cgd
229 1.17 mycroft static enum { IN_LIST, NOT_IN_LIST } which;
230 1.17 mycroft
231 1.17 mycroft int
232 1.17 mycroft selected(type)
233 1.17 mycroft const char *type;
234 1.17 mycroft {
235 1.17 mycroft char **av;
236 1.17 mycroft
237 1.17 mycroft /* If no type specified, it's always selected. */
238 1.17 mycroft if (typelist == NULL)
239 1.17 mycroft return (1);
240 1.17 mycroft for (av = typelist; *av != NULL; ++av)
241 1.20 cgd if (!strncmp(type, *av, MFSNAMELEN))
242 1.17 mycroft return (which == IN_LIST ? 1 : 0);
243 1.17 mycroft return (which == IN_LIST ? 0 : 1);
244 1.17 mycroft }
245 1.16 mycroft
246 1.16 mycroft void
247 1.17 mycroft maketypelist(fslist)
248 1.17 mycroft char *fslist;
249 1.16 mycroft {
250 1.17 mycroft int i;
251 1.17 mycroft char *nextcp, **av;
252 1.16 mycroft
253 1.17 mycroft if ((fslist == NULL) || (fslist[0] == '\0'))
254 1.17 mycroft errx(1, "empty type list");
255 1.16 mycroft
256 1.17 mycroft /*
257 1.17 mycroft * XXX
258 1.17 mycroft * Note: the syntax is "noxxx,yyy" for no xxx's and
259 1.17 mycroft * no yyy's, not the more intuitive "noyyy,noyyy".
260 1.17 mycroft */
261 1.17 mycroft if (fslist[0] == 'n' && fslist[1] == 'o') {
262 1.17 mycroft fslist += 2;
263 1.17 mycroft which = NOT_IN_LIST;
264 1.17 mycroft } else
265 1.17 mycroft which = IN_LIST;
266 1.17 mycroft
267 1.17 mycroft /* Count the number of types. */
268 1.24 thorpej for (i = 1, nextcp = fslist;
269 1.24 thorpej (nextcp = strchr(nextcp, ',')) != NULL; i++)
270 1.17 mycroft ++nextcp;
271 1.17 mycroft
272 1.17 mycroft /* Build an array of that many types. */
273 1.17 mycroft if ((av = typelist = malloc((i + 1) * sizeof(char *))) == NULL)
274 1.24 thorpej err(1, "can't allocate type array");
275 1.17 mycroft av[0] = fslist;
276 1.24 thorpej for (i = 1, nextcp = fslist;
277 1.24 thorpej (nextcp = strchr(nextcp, ',')) != NULL; i++) {
278 1.17 mycroft *nextcp = '\0';
279 1.17 mycroft av[i] = ++nextcp;
280 1.16 mycroft }
281 1.17 mycroft /* Terminate the array. */
282 1.17 mycroft av[i] = NULL;
283 1.17 mycroft }
284 1.16 mycroft
285 1.17 mycroft /*
286 1.17 mycroft * Make a pass over the filesystem info in ``mntbuf'' filtering out
287 1.17 mycroft * filesystem types not in ``fsmask'' and possibly re-stating to get
288 1.17 mycroft * current (not cached) info. Returns the new count of valid statfs bufs.
289 1.17 mycroft */
290 1.17 mycroft long
291 1.17 mycroft regetmntinfo(mntbufp, mntsize)
292 1.17 mycroft struct statfs **mntbufp;
293 1.17 mycroft long mntsize;
294 1.17 mycroft {
295 1.17 mycroft int i, j;
296 1.17 mycroft struct statfs *mntbuf;
297 1.16 mycroft
298 1.17 mycroft if (!lflag && typelist == NULL)
299 1.17 mycroft return (nflag ? mntsize : getmntinfo(mntbufp, MNT_WAIT));
300 1.16 mycroft
301 1.17 mycroft mntbuf = *mntbufp;
302 1.17 mycroft j = 0;
303 1.17 mycroft for (i = 0; i < mntsize; i++) {
304 1.34 christos if (!aflag && (mntbuf[i].f_flags & MNT_IGNORE) != 0)
305 1.34 christos continue;
306 1.17 mycroft if (lflag && (mntbuf[i].f_flags & MNT_LOCAL) == 0)
307 1.17 mycroft continue;
308 1.17 mycroft if (!selected(mntbuf[i].f_fstypename))
309 1.17 mycroft continue;
310 1.17 mycroft if (nflag)
311 1.17 mycroft mntbuf[j] = mntbuf[i];
312 1.32 sommerfe else {
313 1.32 sommerfe struct statfs layerbuf = mntbuf[i];
314 1.17 mycroft (void)statfs(mntbuf[i].f_mntonname, &mntbuf[j]);
315 1.32 sommerfe /*
316 1.32 sommerfe * If the FS name changed, then new data is for
317 1.32 sommerfe * a different layer and we don't want it.
318 1.32 sommerfe */
319 1.32 sommerfe if(memcmp(layerbuf.f_mntfromname,
320 1.32 sommerfe mntbuf[j].f_mntfromname, MNAMELEN))
321 1.32 sommerfe mntbuf[j] = layerbuf;
322 1.32 sommerfe }
323 1.17 mycroft j++;
324 1.16 mycroft }
325 1.17 mycroft return (j);
326 1.16 mycroft }
327 1.16 mycroft
328 1.12 cgd /*
329 1.15 mycroft * Convert statfs returned filesystem size into BLOCKSIZE units.
330 1.15 mycroft * Attempts to avoid overflow for large filesystems.
331 1.15 mycroft */
332 1.15 mycroft #define fsbtoblk(num, fsbs, bs) \
333 1.15 mycroft (((fsbs) != 0 && (fsbs) < (bs)) ? \
334 1.15 mycroft (num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs)))
335 1.15 mycroft
336 1.15 mycroft /*
337 1.12 cgd * Print out status about a filesystem.
338 1.12 cgd */
339 1.12 cgd void
340 1.12 cgd prtstat(sfsp, maxwidth)
341 1.15 mycroft struct statfs *sfsp;
342 1.15 mycroft int maxwidth;
343 1.12 cgd {
344 1.17 mycroft static long blocksize;
345 1.12 cgd static int headerlen, timesthrough;
346 1.12 cgd static char *header;
347 1.12 cgd long used, availblks, inodes;
348 1.26 fair static char *full = "100%";
349 1.12 cgd
350 1.12 cgd if (maxwidth < 11)
351 1.12 cgd maxwidth = 11;
352 1.12 cgd if (++timesthrough == 1) {
353 1.12 cgd if (kflag) {
354 1.17 mycroft blocksize = 1024;
355 1.35 kleink header = Pflag ? "1024-blocks" : "1K-blocks";
356 1.12 cgd headerlen = strlen(header);
357 1.36 hubertf } else if (mflag) {
358 1.36 hubertf blocksize = 1024 * 1024;
359 1.36 hubertf header = Pflag ? "1048576-blocks" : "1M-blocks";
360 1.36 hubertf headerlen = strlen(header);
361 1.12 cgd } else
362 1.12 cgd header = getbsize(&headerlen, &blocksize);
363 1.35 kleink (void)printf("%-*.*s %s Used %9s Capacity",
364 1.35 kleink maxwidth, maxwidth, "Filesystem", header,
365 1.35 kleink Pflag ? "Available" : "Avail");
366 1.12 cgd if (iflag)
367 1.12 cgd (void)printf(" iused ifree %%iused");
368 1.12 cgd (void)printf(" Mounted on\n");
369 1.12 cgd }
370 1.12 cgd (void)printf("%-*.*s", maxwidth, maxwidth, sfsp->f_mntfromname);
371 1.12 cgd used = sfsp->f_blocks - sfsp->f_bfree;
372 1.12 cgd availblks = sfsp->f_bavail + used;
373 1.35 kleink (void)printf(" %*ld %8ld %9ld", headerlen,
374 1.15 mycroft fsbtoblk(sfsp->f_blocks, sfsp->f_bsize, blocksize),
375 1.15 mycroft fsbtoblk(used, sfsp->f_bsize, blocksize),
376 1.15 mycroft fsbtoblk(sfsp->f_bavail, sfsp->f_bsize, blocksize));
377 1.39 tsutsui (void)printf("%7s",
378 1.31 wsanchez availblks == 0 ? full : strpct((u_long)used, (u_long)availblks, 0));
379 1.12 cgd if (iflag) {
380 1.12 cgd inodes = sfsp->f_files;
381 1.12 cgd used = inodes - sfsp->f_ffree;
382 1.26 fair (void)printf(" %7ld %7ld %6s ", used, sfsp->f_ffree,
383 1.31 wsanchez inodes == 0 ? full : strpct((u_long)used, (u_long)inodes, 0));
384 1.12 cgd } else
385 1.12 cgd (void)printf(" ");
386 1.12 cgd (void)printf(" %s\n", sfsp->f_mntonname);
387 1.12 cgd }
388 1.12 cgd
389 1.12 cgd /*
390 1.15 mycroft * This code constitutes the pre-system call Berkeley df code for extracting
391 1.12 cgd * information from filesystem superblocks.
392 1.12 cgd */
393 1.25 fvdl #include <ufs/ufs/dinode.h>
394 1.13 chopps #include <ufs/ffs/fs.h>
395 1.12 cgd #include <errno.h>
396 1.12 cgd #include <fstab.h>
397 1.12 cgd
398 1.12 cgd union {
399 1.12 cgd struct fs iu_fs;
400 1.12 cgd char dummy[SBSIZE];
401 1.12 cgd } sb;
402 1.12 cgd #define sblock sb.iu_fs
403 1.12 cgd
404 1.15 mycroft int rfd;
405 1.12 cgd
406 1.17 mycroft int
407 1.17 mycroft ufs_df(file, sfsp)
408 1.12 cgd char *file;
409 1.17 mycroft struct statfs *sfsp;
410 1.12 cgd {
411 1.12 cgd char *mntpt;
412 1.12 cgd static int synced;
413 1.12 cgd
414 1.12 cgd if (synced++ == 0)
415 1.12 cgd sync();
416 1.12 cgd
417 1.15 mycroft if ((rfd = open(file, O_RDONLY)) < 0) {
418 1.12 cgd warn("%s", file);
419 1.17 mycroft return (-1);
420 1.12 cgd }
421 1.15 mycroft if (bread((off_t)SBOFF, &sblock, SBSIZE) == 0) {
422 1.15 mycroft (void)close(rfd);
423 1.17 mycroft return (-1);
424 1.12 cgd }
425 1.12 cgd sfsp->f_type = 0;
426 1.12 cgd sfsp->f_flags = 0;
427 1.15 mycroft sfsp->f_bsize = sblock.fs_fsize;
428 1.12 cgd sfsp->f_iosize = sblock.fs_bsize;
429 1.12 cgd sfsp->f_blocks = sblock.fs_dsize;
430 1.12 cgd sfsp->f_bfree = sblock.fs_cstotal.cs_nbfree * sblock.fs_frag +
431 1.12 cgd sblock.fs_cstotal.cs_nffree;
432 1.33 hubertf sfsp->f_bavail = ((int64_t)sblock.fs_dsize * (100 - sblock.fs_minfree) / 100) -
433 1.12 cgd (sblock.fs_dsize - sfsp->f_bfree);
434 1.12 cgd if (sfsp->f_bavail < 0)
435 1.12 cgd sfsp->f_bavail = 0;
436 1.12 cgd sfsp->f_files = sblock.fs_ncg * sblock.fs_ipg;
437 1.12 cgd sfsp->f_ffree = sblock.fs_cstotal.cs_nifree;
438 1.12 cgd sfsp->f_fsid.val[0] = 0;
439 1.12 cgd sfsp->f_fsid.val[1] = 0;
440 1.12 cgd if ((mntpt = getmntpt(file)) == 0)
441 1.12 cgd mntpt = "";
442 1.29 mycroft (void)memmove(&sfsp->f_mntonname[0], mntpt, MNAMELEN);
443 1.29 mycroft (void)memmove(&sfsp->f_mntfromname[0], file, MNAMELEN);
444 1.29 mycroft (void)strncpy(sfsp->f_fstypename, MOUNT_FFS, MFSNAMELEN);
445 1.15 mycroft (void)close(rfd);
446 1.17 mycroft return (0);
447 1.12 cgd }
448 1.12 cgd
449 1.12 cgd int
450 1.12 cgd bread(off, buf, cnt)
451 1.15 mycroft off_t off;
452 1.15 mycroft void *buf;
453 1.12 cgd int cnt;
454 1.12 cgd {
455 1.15 mycroft int nr;
456 1.12 cgd
457 1.15 mycroft (void)lseek(rfd, off, SEEK_SET);
458 1.15 mycroft if ((nr = read(rfd, buf, cnt)) != cnt) {
459 1.15 mycroft /* Probably a dismounted disk if errno == EIO. */
460 1.15 mycroft if (errno != EIO)
461 1.37 lukem (void)fprintf(stderr, "\ndf: %lld: %s\n",
462 1.24 thorpej (long long)off, strerror(nr > 0 ? EIO : errno));
463 1.12 cgd return (0);
464 1.12 cgd }
465 1.12 cgd return (1);
466 1.12 cgd }
467 1.12 cgd
468 1.12 cgd void
469 1.12 cgd usage()
470 1.12 cgd {
471 1.34 christos (void)fprintf(stderr,
472 1.36 hubertf "Usage: %s [-aiklmnP] [-t type] [file | file_system ...]\n",
473 1.34 christos __progname);
474 1.12 cgd exit(1);
475 1.30 mycroft /* NOTREACHED */
476 1.12 cgd }
477