17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5d1a180b0Smaheshvs * Common Development and Distribution License (the "License"). 6d1a180b0Smaheshvs * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*af33352aS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 317c478bd9Sstevel@tonic-gate * The Regents of the University of California 327c478bd9Sstevel@tonic-gate * All Rights Reserved 337c478bd9Sstevel@tonic-gate * 347c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 357c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 367c478bd9Sstevel@tonic-gate * contributors. 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * df 427c478bd9Sstevel@tonic-gate */ 437c478bd9Sstevel@tonic-gate #include <stdio.h> 447c478bd9Sstevel@tonic-gate #include <fcntl.h> 457c478bd9Sstevel@tonic-gate #include <sys/param.h> 467c478bd9Sstevel@tonic-gate #include <sys/types.h> 477c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 487c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h> 497c478bd9Sstevel@tonic-gate #include <sys/stat.h> 507c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 517c478bd9Sstevel@tonic-gate #include <sys/file.h> 527c478bd9Sstevel@tonic-gate #include <sys/statvfs.h> 537c478bd9Sstevel@tonic-gate #include <sys/mnttab.h> 547c478bd9Sstevel@tonic-gate #include <sys/mkdev.h> 557c478bd9Sstevel@tonic-gate #include <locale.h> 567c478bd9Sstevel@tonic-gate #include <stdarg.h> 577c478bd9Sstevel@tonic-gate #include <string.h> 587c478bd9Sstevel@tonic-gate #include <errno.h> 597c478bd9Sstevel@tonic-gate #include <libintl.h> 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate extern char *getenv(); 627c478bd9Sstevel@tonic-gate extern char *getcwd(); 637c478bd9Sstevel@tonic-gate extern char *realpath(); 647c478bd9Sstevel@tonic-gate extern off_t lseek(); 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * Raw name to block device name translation function. 687c478bd9Sstevel@tonic-gate * This comes from libadm. 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate extern char *getfullblkname(); 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate static void usage(), pheader(); 73d1a180b0Smaheshvs static char *mpath(char *); 74d1a180b0Smaheshvs static char *zap_chroot(char *); 75d1a180b0Smaheshvs static char *pathsuffix(char *, char *); 76d1a180b0Smaheshvs static char *xmalloc(unsigned int); 77d1a180b0Smaheshvs static int chroot_stat(char *, int (*)(), char *, char **); 78d1a180b0Smaheshvs static int bread(char *, int, daddr_t, char *, int); 79d1a180b0Smaheshvs static int subpath(char *, char *); 80d1a180b0Smaheshvs static int abspath(char *, char *, char *); 817c478bd9Sstevel@tonic-gate static void show_inode_usage(); 82d1a180b0Smaheshvs static void dfreedev(char *); 83d1a180b0Smaheshvs static void dfreemnt(char *, struct mnttab *); 847c478bd9Sstevel@tonic-gate static void print_totals(); 857c478bd9Sstevel@tonic-gate static void print_itotals(); 86d1a180b0Smaheshvs static void print_statvfs(struct statvfs64 *); 87d1a180b0Smaheshvs static int mdev(char *, struct mnttab **); 887c478bd9Sstevel@tonic-gate static struct mntlist *mkmntlist(); 89d1a180b0Smaheshvs static struct mnttab *mntdup(struct mnttab *mnt); 90d1a180b0Smaheshvs static struct mntlist *findmntent(char *, struct stat64 *, struct mntlist *); 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate #define bcopy(f, t, n) memcpy(t, f, n) 937c478bd9Sstevel@tonic-gate #define bzero(s, n) memset(s, 0, n) 947c478bd9Sstevel@tonic-gate #define bcmp(s, d, n) memcmp(s, d, n) 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate #define index(s, r) strchr(s, r) 977c478bd9Sstevel@tonic-gate #define rindex(s, r) strrchr(s, r) 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate #define dbtok(x, b) \ 1007c478bd9Sstevel@tonic-gate ((b) < (fsblkcnt64_t)1024 ? \ 1017c478bd9Sstevel@tonic-gate (x) / ((fsblkcnt64_t)1024 / (b)) : (x) * ((b) / (fsblkcnt64_t)1024)) 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate int aflag = 0; /* even the uninteresting ones */ 1047c478bd9Sstevel@tonic-gate int bflag = 0; /* print only number of kilobytes free */ 1057c478bd9Sstevel@tonic-gate int eflag = 0; /* print only number of file entries free */ 1067c478bd9Sstevel@tonic-gate int gflag = 0; /* print entire statvfs structure */ 1077c478bd9Sstevel@tonic-gate int hflag = 0; /* don't print header */ 1087c478bd9Sstevel@tonic-gate int iflag = 0; /* information for inodes */ 1097c478bd9Sstevel@tonic-gate int nflag = 0; /* print VFStype name */ 1107c478bd9Sstevel@tonic-gate int tflag = 0; /* print totals */ 1117c478bd9Sstevel@tonic-gate int errflag = 0; 1127c478bd9Sstevel@tonic-gate int errcode = 0; 1137c478bd9Sstevel@tonic-gate char *typestr = "ufs"; 1147c478bd9Sstevel@tonic-gate fsblkcnt64_t t_totalblks, t_avail, t_free, t_used, t_reserved; 1157c478bd9Sstevel@tonic-gate int t_inodes, t_iused, t_ifree; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* 1187c478bd9Sstevel@tonic-gate * cached information recording previous chroot history. 1197c478bd9Sstevel@tonic-gate */ 1207c478bd9Sstevel@tonic-gate static char *chrootpath; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate extern int optind; 1237c478bd9Sstevel@tonic-gate extern char *optarg; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate union { 1267c478bd9Sstevel@tonic-gate struct fs iu_fs; 1277c478bd9Sstevel@tonic-gate char dummy[SBSIZE]; 1287c478bd9Sstevel@tonic-gate } sb; 1297c478bd9Sstevel@tonic-gate #define sblock sb.iu_fs 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate /* 1327c478bd9Sstevel@tonic-gate * This structure is used to chain mntent structures into a list 1337c478bd9Sstevel@tonic-gate * and to cache stat information for each member of the list. 1347c478bd9Sstevel@tonic-gate */ 1357c478bd9Sstevel@tonic-gate struct mntlist { 1367c478bd9Sstevel@tonic-gate struct mnttab *mntl_mnt; 1377c478bd9Sstevel@tonic-gate struct mntlist *mntl_next; 1387c478bd9Sstevel@tonic-gate dev_t mntl_dev; 1397c478bd9Sstevel@tonic-gate int mntl_devvalid; 1407c478bd9Sstevel@tonic-gate }; 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate char *subopts [] = { 1437c478bd9Sstevel@tonic-gate #define A_FLAG 0 1447c478bd9Sstevel@tonic-gate "a", 1457c478bd9Sstevel@tonic-gate #define I_FLAG 1 1467c478bd9Sstevel@tonic-gate "i", 1477c478bd9Sstevel@tonic-gate NULL 1487c478bd9Sstevel@tonic-gate }; 1497c478bd9Sstevel@tonic-gate 150d1a180b0Smaheshvs int 151d1a180b0Smaheshvs main(int argc, char *argv[]) 1527c478bd9Sstevel@tonic-gate { 1537c478bd9Sstevel@tonic-gate struct mnttab mnt; 1547c478bd9Sstevel@tonic-gate int opt; 1557c478bd9Sstevel@tonic-gate char *suboptions, *value; 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 1587c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ 1597c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ 1607c478bd9Sstevel@tonic-gate #endif 1617c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate while ((opt = getopt(argc, argv, "beghkno:t")) != EOF) { 1647c478bd9Sstevel@tonic-gate switch (opt) { 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate case 'b': /* print only number of kilobytes free */ 1677c478bd9Sstevel@tonic-gate bflag++; 1687c478bd9Sstevel@tonic-gate break; 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate case 'e': 1717c478bd9Sstevel@tonic-gate eflag++; /* print only number of file entries free */ 1727c478bd9Sstevel@tonic-gate iflag++; 1737c478bd9Sstevel@tonic-gate break; 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate case 'g': 1767c478bd9Sstevel@tonic-gate gflag++; 1777c478bd9Sstevel@tonic-gate break; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate case 'n': 1807c478bd9Sstevel@tonic-gate nflag++; 1817c478bd9Sstevel@tonic-gate break; 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate case 'k': 1847c478bd9Sstevel@tonic-gate break; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate case 'h': 1877c478bd9Sstevel@tonic-gate hflag++; 1887c478bd9Sstevel@tonic-gate break; 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate case 'o': 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * ufs specific options. 1937c478bd9Sstevel@tonic-gate */ 1947c478bd9Sstevel@tonic-gate suboptions = optarg; 1957c478bd9Sstevel@tonic-gate while (*suboptions != '\0') { 1967c478bd9Sstevel@tonic-gate switch (getsubopt(&suboptions, 1977c478bd9Sstevel@tonic-gate subopts, &value)) { 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate case I_FLAG: /* information for inodes */ 2007c478bd9Sstevel@tonic-gate iflag++; 2017c478bd9Sstevel@tonic-gate break; 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate default: 2047c478bd9Sstevel@tonic-gate usage(); 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate break; 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate case 't': /* print totals */ 2107c478bd9Sstevel@tonic-gate tflag++; 2117c478bd9Sstevel@tonic-gate break; 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate case 'V': /* Print command line */ 2147c478bd9Sstevel@tonic-gate { 2157c478bd9Sstevel@tonic-gate char *opt_text; 2167c478bd9Sstevel@tonic-gate int opt_count; 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "df -F ufs "); 2197c478bd9Sstevel@tonic-gate for (opt_count = 1; opt_count < argc; 2207c478bd9Sstevel@tonic-gate opt_count++) { 2217c478bd9Sstevel@tonic-gate opt_text = argv[opt_count]; 2227c478bd9Sstevel@tonic-gate if (opt_text) 2237c478bd9Sstevel@tonic-gate (void) fprintf(stdout, " %s ", 2247c478bd9Sstevel@tonic-gate opt_text); 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "\n"); 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate break; 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate case '?': 2317c478bd9Sstevel@tonic-gate errflag++; 2327c478bd9Sstevel@tonic-gate } 2337c478bd9Sstevel@tonic-gate } 2347c478bd9Sstevel@tonic-gate if (errflag) 2357c478bd9Sstevel@tonic-gate usage(); 2367c478bd9Sstevel@tonic-gate if (gflag && iflag) { 2377c478bd9Sstevel@tonic-gate printf(gettext("df: '-g' and '-o i' are mutually exclusive\n")); 2387c478bd9Sstevel@tonic-gate exit(1); 2397c478bd9Sstevel@tonic-gate } 2407c478bd9Sstevel@tonic-gate if (bflag || eflag) 2417c478bd9Sstevel@tonic-gate tflag = 0; 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate /* 2447c478bd9Sstevel@tonic-gate * Cache CHROOT information for later use; assume that $CHROOT matches 2457c478bd9Sstevel@tonic-gate * the cumulative arguments given to chroot calls. 2467c478bd9Sstevel@tonic-gate */ 2477c478bd9Sstevel@tonic-gate chrootpath = getenv("CHROOT"); 2487c478bd9Sstevel@tonic-gate if (chrootpath != NULL && strcmp(chrootpath, "/") == 0) 2497c478bd9Sstevel@tonic-gate chrootpath = NULL; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate if (argc <= optind) { 2527c478bd9Sstevel@tonic-gate /* 2537c478bd9Sstevel@tonic-gate * Take this path when "/usr/lib/fs/ufs/df" is specified, and 2547c478bd9Sstevel@tonic-gate * there are no mountpoints specified. 2557c478bd9Sstevel@tonic-gate * E.g., these command lines take us down this path 2567c478bd9Sstevel@tonic-gate * /usr/lib/fs/ufs/df -o i 2577c478bd9Sstevel@tonic-gate * /usr/lib/fs/ufs/df 2587c478bd9Sstevel@tonic-gate */ 259d1a180b0Smaheshvs FILE *mtabp; 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate if ((mtabp = fopen(MNTTAB, "r")) == NULL) { 2627c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "df: "); 2637c478bd9Sstevel@tonic-gate perror(MNTTAB); 2647c478bd9Sstevel@tonic-gate exit(1); 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate pheader(); 2677c478bd9Sstevel@tonic-gate while (getmntent(mtabp, &mnt) == 0) { 2687c478bd9Sstevel@tonic-gate if (strcmp(typestr, mnt.mnt_fstype) != 0) { 2697c478bd9Sstevel@tonic-gate continue; 2707c478bd9Sstevel@tonic-gate } 2717c478bd9Sstevel@tonic-gate dfreemnt(mnt.mnt_mountp, &mnt); 2727c478bd9Sstevel@tonic-gate } 2737c478bd9Sstevel@tonic-gate if (tflag) 2747c478bd9Sstevel@tonic-gate if (iflag) 2757c478bd9Sstevel@tonic-gate print_itotals(); 2767c478bd9Sstevel@tonic-gate else 2777c478bd9Sstevel@tonic-gate print_totals(); 2787c478bd9Sstevel@tonic-gate (void) fclose(mtabp); 2797c478bd9Sstevel@tonic-gate } else { 2807c478bd9Sstevel@tonic-gate int i; 2817c478bd9Sstevel@tonic-gate struct mntlist *mntl; 2827c478bd9Sstevel@tonic-gate struct stat64 *argstat; 2837c478bd9Sstevel@tonic-gate char **devnames; 2847c478bd9Sstevel@tonic-gate char *cp; 2857c478bd9Sstevel@tonic-gate 286*af33352aS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" /* Arguments are processed till optind, adjust the pointers */ 287*af33352aS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" argv += optind; 288*af33352aS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" argc -= optind; 289*af33352aS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 2907c478bd9Sstevel@tonic-gate /* 2917c478bd9Sstevel@tonic-gate * Obtain stat64 information for each argument before 2927c478bd9Sstevel@tonic-gate * constructing the list of mounted file systems. This 2937c478bd9Sstevel@tonic-gate * ordering forces the automounter to establish any 2947c478bd9Sstevel@tonic-gate * mounts required to access the arguments, so that the 2957c478bd9Sstevel@tonic-gate * corresponding mount table entries will exist when 2967c478bd9Sstevel@tonic-gate * we look for them. 2977c478bd9Sstevel@tonic-gate */ 2987c478bd9Sstevel@tonic-gate argstat = (struct stat64 *)xmalloc(argc * sizeof (*argstat)); 2997c478bd9Sstevel@tonic-gate devnames = (char **)xmalloc(argc * sizeof (char *)); 3007c478bd9Sstevel@tonic-gate for (i = 0; i < argc; i++) { 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate /* 3037c478bd9Sstevel@tonic-gate * Given a raw device name, get the block device name 3047c478bd9Sstevel@tonic-gate */ 3057c478bd9Sstevel@tonic-gate cp = getfullblkname(argv[i]); 3067c478bd9Sstevel@tonic-gate if (cp == NULL || *cp == '\0') { 3077c478bd9Sstevel@tonic-gate if (cp != NULL) 3087c478bd9Sstevel@tonic-gate free(cp); 3097c478bd9Sstevel@tonic-gate cp = strdup(argv[i]); 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate if (cp == NULL) { 3127c478bd9Sstevel@tonic-gate int j; 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate fprintf(stderr, gettext( 3157c478bd9Sstevel@tonic-gate "df: memory allocation failure\n")); 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) 3187c478bd9Sstevel@tonic-gate free(devnames[j]); 3197c478bd9Sstevel@tonic-gate free(devnames); 3207c478bd9Sstevel@tonic-gate free(argstat); 3217c478bd9Sstevel@tonic-gate exit(1); 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate } 3247c478bd9Sstevel@tonic-gate if (stat64(cp, &argstat[i]) < 0) { 3257c478bd9Sstevel@tonic-gate errcode = errno; 3267c478bd9Sstevel@tonic-gate /* 3277c478bd9Sstevel@tonic-gate * Mark as no longer interesting. 3287c478bd9Sstevel@tonic-gate */ 3297c478bd9Sstevel@tonic-gate argv[i] = NULL; 3307c478bd9Sstevel@tonic-gate devnames[i] = NULL; 3317c478bd9Sstevel@tonic-gate free(cp); 3327c478bd9Sstevel@tonic-gate } else { 3337c478bd9Sstevel@tonic-gate devnames[i] = cp; 3347c478bd9Sstevel@tonic-gate } 3357c478bd9Sstevel@tonic-gate } 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate pheader(); 3387c478bd9Sstevel@tonic-gate aflag++; 3397c478bd9Sstevel@tonic-gate /* 3407c478bd9Sstevel@tonic-gate * Construct the list of mounted file systems. 3417c478bd9Sstevel@tonic-gate */ 3427c478bd9Sstevel@tonic-gate mntl = mkmntlist(); 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate /* 3457c478bd9Sstevel@tonic-gate * Iterate through the argument list, reporting on each one. 3467c478bd9Sstevel@tonic-gate */ 3477c478bd9Sstevel@tonic-gate for (i = 0; i < argc; i++) { 348d1a180b0Smaheshvs struct mntlist *mlp; 3497c478bd9Sstevel@tonic-gate int isblk; 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate /* 3527c478bd9Sstevel@tonic-gate * Skip if we've already determined that we can't 3537c478bd9Sstevel@tonic-gate * process it. 3547c478bd9Sstevel@tonic-gate */ 3557c478bd9Sstevel@tonic-gate if (argv[i] == NULL) 3567c478bd9Sstevel@tonic-gate continue; 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate /* 3597c478bd9Sstevel@tonic-gate * If the argument names a device, report on the file 3607c478bd9Sstevel@tonic-gate * system associated with the device rather than on 3617c478bd9Sstevel@tonic-gate * the one containing the device's directory entry 3627c478bd9Sstevel@tonic-gate */ 3637c478bd9Sstevel@tonic-gate cp = devnames[i]; 3647c478bd9Sstevel@tonic-gate if ((isblk = (argstat[i].st_mode&S_IFMT) == S_IFBLK) || 3657c478bd9Sstevel@tonic-gate (argstat[i].st_mode & S_IFMT) == S_IFCHR) { 3667c478bd9Sstevel@tonic-gate if (isblk && strcmp(mpath(cp), "") != 0) { 367d1a180b0Smaheshvs struct mnttab *mp; 368d1a180b0Smaheshvs if (mdev(cp, &mp)) 369d1a180b0Smaheshvs return (1); 3707c478bd9Sstevel@tonic-gate dfreemnt(mp->mnt_mountp, mp); 3717c478bd9Sstevel@tonic-gate } else { 3727c478bd9Sstevel@tonic-gate dfreedev(cp); 3737c478bd9Sstevel@tonic-gate } 3747c478bd9Sstevel@tonic-gate free(cp); 3757c478bd9Sstevel@tonic-gate devnames[i] = NULL; 3767c478bd9Sstevel@tonic-gate continue; 3777c478bd9Sstevel@tonic-gate } 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate /* 3807c478bd9Sstevel@tonic-gate * Get this argument's corresponding mount table 3817c478bd9Sstevel@tonic-gate * entry. 3827c478bd9Sstevel@tonic-gate */ 3837c478bd9Sstevel@tonic-gate mlp = findmntent(cp, &argstat[i], mntl); 3847c478bd9Sstevel@tonic-gate free(cp); 3857c478bd9Sstevel@tonic-gate devnames[i] = NULL; 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate if (mlp == NULL) { 3887c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 3897c478bd9Sstevel@tonic-gate gettext("Could not find mount point for %s\n"), 3907c478bd9Sstevel@tonic-gate argv[i]); 3917c478bd9Sstevel@tonic-gate continue; 3927c478bd9Sstevel@tonic-gate } 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate dfreemnt(mlp->mntl_mnt->mnt_mountp, mlp->mntl_mnt); 3957c478bd9Sstevel@tonic-gate } 3967c478bd9Sstevel@tonic-gate free(devnames); 3977c478bd9Sstevel@tonic-gate free(argstat); 3987c478bd9Sstevel@tonic-gate } 399d1a180b0Smaheshvs return (0); 4007c478bd9Sstevel@tonic-gate } 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate void 4037c478bd9Sstevel@tonic-gate pheader() 4047c478bd9Sstevel@tonic-gate { 4057c478bd9Sstevel@tonic-gate if (hflag) 4067c478bd9Sstevel@tonic-gate return; 4077c478bd9Sstevel@tonic-gate if (nflag) 4087c478bd9Sstevel@tonic-gate (void) printf(gettext("VFStype name - ufs\n")); 4097c478bd9Sstevel@tonic-gate if (iflag) { 4107c478bd9Sstevel@tonic-gate if (eflag) 4117c478bd9Sstevel@tonic-gate /* 4127c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 4137c478bd9Sstevel@tonic-gate * Following string is used as a table header. 4147c478bd9Sstevel@tonic-gate * Translated items should start at the same 4157c478bd9Sstevel@tonic-gate * columns as the original items. 4167c478bd9Sstevel@tonic-gate */ 4177c478bd9Sstevel@tonic-gate (void) printf(gettext( 4187c478bd9Sstevel@tonic-gate "Filesystem ifree\n")); 4197c478bd9Sstevel@tonic-gate else { 4207c478bd9Sstevel@tonic-gate /* 4217c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 4227c478bd9Sstevel@tonic-gate * Following string is used as a table header. 4237c478bd9Sstevel@tonic-gate * Translated items should start at the same 4247c478bd9Sstevel@tonic-gate * columns as the original items. 4257c478bd9Sstevel@tonic-gate */ 4267c478bd9Sstevel@tonic-gate (void) printf(gettext( 4277c478bd9Sstevel@tonic-gate "Filesystem iused ifree %%iused Mounted on\n")); 4287c478bd9Sstevel@tonic-gate } 4297c478bd9Sstevel@tonic-gate } else { 4307c478bd9Sstevel@tonic-gate if (gflag) 4317c478bd9Sstevel@tonic-gate /* 4327c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 4337c478bd9Sstevel@tonic-gate * Following string is used as a table header. 4347c478bd9Sstevel@tonic-gate * Translated items should start at the same 4357c478bd9Sstevel@tonic-gate * columns as the original items. 4367c478bd9Sstevel@tonic-gate */ 4377c478bd9Sstevel@tonic-gate (void) printf(gettext( 4387c478bd9Sstevel@tonic-gate "Filesystem f_type f_fsize f_bfree f_bavail f_files f_ffree " 4397c478bd9Sstevel@tonic-gate "f_fsid f_flag f_fstr\n")); 4407c478bd9Sstevel@tonic-gate else 4417c478bd9Sstevel@tonic-gate if (bflag) 4427c478bd9Sstevel@tonic-gate /* 4437c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 4447c478bd9Sstevel@tonic-gate * Following string is used as a table header. 4457c478bd9Sstevel@tonic-gate * Translated items should start at the same 4467c478bd9Sstevel@tonic-gate * columns as the original items. 4477c478bd9Sstevel@tonic-gate */ 4487c478bd9Sstevel@tonic-gate (void) printf(gettext( 4497c478bd9Sstevel@tonic-gate "Filesystem avail\n")); 4507c478bd9Sstevel@tonic-gate else { 4517c478bd9Sstevel@tonic-gate /* 4527c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 4537c478bd9Sstevel@tonic-gate * Following string is used as a table header. 4547c478bd9Sstevel@tonic-gate * Translated items should start at the same 4557c478bd9Sstevel@tonic-gate * columns as the original items. 4567c478bd9Sstevel@tonic-gate */ 4577c478bd9Sstevel@tonic-gate (void) printf(gettext( 4587c478bd9Sstevel@tonic-gate "Filesystem kbytes used avail capacity Mounted on\n")); 4597c478bd9Sstevel@tonic-gate } 4607c478bd9Sstevel@tonic-gate } 4617c478bd9Sstevel@tonic-gate } 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate /* 4647c478bd9Sstevel@tonic-gate * Report on a block or character special device. Assumed not to be 4657c478bd9Sstevel@tonic-gate * mounted. N.B. checks for a valid UFS superblock. 4667c478bd9Sstevel@tonic-gate */ 4677c478bd9Sstevel@tonic-gate void 468d1a180b0Smaheshvs dfreedev(char *file) 4697c478bd9Sstevel@tonic-gate { 4707c478bd9Sstevel@tonic-gate fsblkcnt64_t totalblks, availblks, avail, free, used; 4717c478bd9Sstevel@tonic-gate int fi; 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate fi = open64(file, 0); 4747c478bd9Sstevel@tonic-gate if (fi < 0) { 4757c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "df: "); 4767c478bd9Sstevel@tonic-gate perror(file); 4777c478bd9Sstevel@tonic-gate return; 4787c478bd9Sstevel@tonic-gate } 4797c478bd9Sstevel@tonic-gate if (bread(file, fi, SBLOCK, (char *)&sblock, SBSIZE) == 0) { 4807c478bd9Sstevel@tonic-gate (void) close(fi); 4817c478bd9Sstevel@tonic-gate return; 4827c478bd9Sstevel@tonic-gate } 4837c478bd9Sstevel@tonic-gate if ((sblock.fs_magic != FS_MAGIC) && 4847c478bd9Sstevel@tonic-gate (sblock.fs_magic != MTB_UFS_MAGIC)) { 4857c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext( 4867c478bd9Sstevel@tonic-gate "df: %s: not a ufs file system\n"), 4877c478bd9Sstevel@tonic-gate file); 4887c478bd9Sstevel@tonic-gate (void) close(fi); 4897c478bd9Sstevel@tonic-gate return; 4907c478bd9Sstevel@tonic-gate } 4916451fdbcSvsakar if (sblock.fs_magic == FS_MAGIC && 4926451fdbcSvsakar (sblock.fs_version != UFS_EFISTYLE4NONEFI_VERSION_2 && 4936451fdbcSvsakar sblock.fs_version != UFS_VERSION_MIN)) { 4946451fdbcSvsakar (void) fprintf(stderr, gettext( 4956451fdbcSvsakar "df: %s: unrecognized version of UFS: %d\n"), 4966451fdbcSvsakar file, sblock.fs_version); 4976451fdbcSvsakar (void) close(fi); 4986451fdbcSvsakar return; 4996451fdbcSvsakar } 5007c478bd9Sstevel@tonic-gate if (sblock.fs_magic == MTB_UFS_MAGIC && 5017c478bd9Sstevel@tonic-gate (sblock.fs_version > MTB_UFS_VERSION_1 || 5027c478bd9Sstevel@tonic-gate sblock.fs_version < MTB_UFS_VERSION_MIN)) { 5037c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext( 5047c478bd9Sstevel@tonic-gate "df: %s: unrecognized version of UFS: %d\n"), 5057c478bd9Sstevel@tonic-gate file, sblock.fs_version); 5067c478bd9Sstevel@tonic-gate (void) close(fi); 5077c478bd9Sstevel@tonic-gate return; 5087c478bd9Sstevel@tonic-gate } 5097c478bd9Sstevel@tonic-gate (void) printf("%-20.20s", file); 5107c478bd9Sstevel@tonic-gate if (iflag) { 5117c478bd9Sstevel@tonic-gate if (eflag) { 5127c478bd9Sstevel@tonic-gate (void) printf("%8ld", sblock.fs_cstotal.cs_nifree); 5137c478bd9Sstevel@tonic-gate } else { 5147c478bd9Sstevel@tonic-gate show_inode_usage( 515*af33352aS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" (fsfilcnt64_t)sblock.fs_ncg * 516*af33352aS"Nagaraj Yedathore - Sun Microsystems - Bangalore India" (fsfilcnt64_t)sblock.fs_ipg, 5177c478bd9Sstevel@tonic-gate (fsfilcnt64_t)sblock.fs_cstotal.cs_nifree); 5187c478bd9Sstevel@tonic-gate } 5197c478bd9Sstevel@tonic-gate } else { 5207c478bd9Sstevel@tonic-gate totalblks = (fsblkcnt64_t)sblock.fs_dsize; 5217c478bd9Sstevel@tonic-gate free = 5227c478bd9Sstevel@tonic-gate (fsblkcnt64_t)sblock.fs_cstotal.cs_nbfree * 5237c478bd9Sstevel@tonic-gate (fsblkcnt64_t)sblock.fs_frag + 5247c478bd9Sstevel@tonic-gate (fsblkcnt64_t)sblock.fs_cstotal.cs_nffree; 5257c478bd9Sstevel@tonic-gate used = totalblks - free; 5267c478bd9Sstevel@tonic-gate availblks = totalblks / (fsblkcnt64_t)100 * 5277c478bd9Sstevel@tonic-gate ((fsblkcnt64_t)100 - (fsblkcnt64_t)sblock.fs_minfree); 5287c478bd9Sstevel@tonic-gate avail = availblks > used ? availblks - used : (fsblkcnt64_t)0; 5297c478bd9Sstevel@tonic-gate if (bflag) { 5307c478bd9Sstevel@tonic-gate (void) printf("%8lld\n", dbtok(avail, 5317c478bd9Sstevel@tonic-gate (fsblkcnt64_t)sblock.fs_fsize)); 5327c478bd9Sstevel@tonic-gate } else { 5337c478bd9Sstevel@tonic-gate (void) printf(" %7lld %7lld %7lld", 5347c478bd9Sstevel@tonic-gate dbtok(totalblks, (fsblkcnt64_t)sblock.fs_fsize), 5357c478bd9Sstevel@tonic-gate dbtok(used, (fsblkcnt64_t)sblock.fs_fsize), 5367c478bd9Sstevel@tonic-gate dbtok(avail, (fsblkcnt64_t)sblock.fs_fsize)); 5377c478bd9Sstevel@tonic-gate (void) printf("%6.0f%%", 5387c478bd9Sstevel@tonic-gate availblks == 0 ? 0.0 : 5397c478bd9Sstevel@tonic-gate (double)used / (double)availblks * 100.0); 5407c478bd9Sstevel@tonic-gate (void) printf(" "); 5417c478bd9Sstevel@tonic-gate } 5427c478bd9Sstevel@tonic-gate if (tflag) { 5437c478bd9Sstevel@tonic-gate t_totalblks += dbtok(totalblks, 5447c478bd9Sstevel@tonic-gate (fsblkcnt64_t)sblock.fs_fsize); 5457c478bd9Sstevel@tonic-gate t_used += dbtok(used, (fsblkcnt64_t)sblock.fs_fsize); 5467c478bd9Sstevel@tonic-gate t_avail += dbtok(avail, (fsblkcnt64_t)sblock.fs_fsize); 5477c478bd9Sstevel@tonic-gate t_free += free; 5487c478bd9Sstevel@tonic-gate } 5497c478bd9Sstevel@tonic-gate } 5507c478bd9Sstevel@tonic-gate if ((!bflag) && (!eflag)) 5517c478bd9Sstevel@tonic-gate (void) printf(" %s\n", mpath(file)); 5527c478bd9Sstevel@tonic-gate else if (eflag) 5537c478bd9Sstevel@tonic-gate (void) printf("\n"); 5547c478bd9Sstevel@tonic-gate (void) close(fi); 5557c478bd9Sstevel@tonic-gate } 5567c478bd9Sstevel@tonic-gate 5577c478bd9Sstevel@tonic-gate void 558d1a180b0Smaheshvs dfreemnt(char *file, struct mnttab *mnt) 5597c478bd9Sstevel@tonic-gate { 5607c478bd9Sstevel@tonic-gate struct statvfs64 fs; 5617c478bd9Sstevel@tonic-gate 5627c478bd9Sstevel@tonic-gate if (statvfs64(file, &fs) < 0 && 5637c478bd9Sstevel@tonic-gate chroot_stat(file, statvfs64, (char *)&fs, &file) < 0) { 5647c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "df: "); 5657c478bd9Sstevel@tonic-gate perror(file); 5667c478bd9Sstevel@tonic-gate return; 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate if (!aflag && fs.f_blocks == 0) { 5707c478bd9Sstevel@tonic-gate return; 5717c478bd9Sstevel@tonic-gate } 5727c478bd9Sstevel@tonic-gate if (!isatty(fileno(stdout))) { 5737c478bd9Sstevel@tonic-gate (void) printf("%s", mnt->mnt_special); 5747c478bd9Sstevel@tonic-gate } else { 5757c478bd9Sstevel@tonic-gate if (strlen(mnt->mnt_special) > (size_t)20) { 5767c478bd9Sstevel@tonic-gate (void) printf("%s\n", mnt->mnt_special); 5777c478bd9Sstevel@tonic-gate (void) printf(" "); 5787c478bd9Sstevel@tonic-gate } else { 5797c478bd9Sstevel@tonic-gate (void) printf("%-20.20s", mnt->mnt_special); 5807c478bd9Sstevel@tonic-gate } 5817c478bd9Sstevel@tonic-gate } 5827c478bd9Sstevel@tonic-gate if (iflag) { 5837c478bd9Sstevel@tonic-gate if (eflag) { 5847c478bd9Sstevel@tonic-gate (void) printf("%8lld", fs.f_ffree); 5857c478bd9Sstevel@tonic-gate } else { 5867c478bd9Sstevel@tonic-gate show_inode_usage(fs.f_files, fs.f_ffree); 5877c478bd9Sstevel@tonic-gate } 5887c478bd9Sstevel@tonic-gate } else { 5897c478bd9Sstevel@tonic-gate if (gflag) { 5907c478bd9Sstevel@tonic-gate print_statvfs(&fs); 5917c478bd9Sstevel@tonic-gate } else { 5927c478bd9Sstevel@tonic-gate fsblkcnt64_t totalblks, avail, free, used, reserved; 5937c478bd9Sstevel@tonic-gate 5947c478bd9Sstevel@tonic-gate totalblks = fs.f_blocks; 5957c478bd9Sstevel@tonic-gate free = fs.f_bfree; 5967c478bd9Sstevel@tonic-gate used = totalblks - free; 5977c478bd9Sstevel@tonic-gate avail = fs.f_bavail; 5987c478bd9Sstevel@tonic-gate reserved = free - avail; 5997c478bd9Sstevel@tonic-gate if ((long long)avail < 0) 6007c478bd9Sstevel@tonic-gate avail = 0; 6017c478bd9Sstevel@tonic-gate if (bflag) { 6027c478bd9Sstevel@tonic-gate (void) printf("%8lld\n", dbtok(avail, 6037c478bd9Sstevel@tonic-gate (fsblkcnt64_t)fs.f_frsize)); 6047c478bd9Sstevel@tonic-gate } else { 6057c478bd9Sstevel@tonic-gate (void) printf(" %7lld %7lld %7lld", 6067c478bd9Sstevel@tonic-gate dbtok(totalblks, 6077c478bd9Sstevel@tonic-gate (fsblkcnt64_t)fs.f_frsize), 6087c478bd9Sstevel@tonic-gate dbtok(used, (fsblkcnt64_t)fs.f_frsize), 6097c478bd9Sstevel@tonic-gate dbtok(avail, (fsblkcnt64_t)fs.f_frsize)); 6107c478bd9Sstevel@tonic-gate totalblks -= reserved; 6117c478bd9Sstevel@tonic-gate (void) printf("%6.0f%%", 6127c478bd9Sstevel@tonic-gate totalblks == 0 ? 0.0 : 6137c478bd9Sstevel@tonic-gate (double)used / (double)totalblks * 100.0); 6147c478bd9Sstevel@tonic-gate (void) printf(" "); 6157c478bd9Sstevel@tonic-gate if (tflag) { 6167c478bd9Sstevel@tonic-gate t_totalblks += dbtok(totalblks + reserved, 6177c478bd9Sstevel@tonic-gate (fsblkcnt64_t)fs.f_bsize); 6187c478bd9Sstevel@tonic-gate t_reserved += reserved; 6197c478bd9Sstevel@tonic-gate t_used += dbtok(used, 6207c478bd9Sstevel@tonic-gate (fsblkcnt64_t)fs.f_frsize); 6217c478bd9Sstevel@tonic-gate t_avail += dbtok(avail, 6227c478bd9Sstevel@tonic-gate (fsblkcnt64_t)fs.f_frsize); 6237c478bd9Sstevel@tonic-gate t_free += free; 6247c478bd9Sstevel@tonic-gate } 6257c478bd9Sstevel@tonic-gate } 6267c478bd9Sstevel@tonic-gate } 6277c478bd9Sstevel@tonic-gate } 6287c478bd9Sstevel@tonic-gate if ((!bflag) && (!eflag) && (!gflag)) 6297c478bd9Sstevel@tonic-gate (void) printf(" %s\n", mnt->mnt_mountp); 6307c478bd9Sstevel@tonic-gate else if (eflag) 6317c478bd9Sstevel@tonic-gate (void) printf("\n"); 6327c478bd9Sstevel@tonic-gate } 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate static void 6357c478bd9Sstevel@tonic-gate show_inode_usage(fsfilcnt64_t total, fsfilcnt64_t free) 6367c478bd9Sstevel@tonic-gate { 6377c478bd9Sstevel@tonic-gate fsfilcnt64_t used = total - free; 6387c478bd9Sstevel@tonic-gate int missing_info = ((long long)total == (long long)-1 || 6397c478bd9Sstevel@tonic-gate (long long)free == (long long)-1); 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate if (missing_info) 6427c478bd9Sstevel@tonic-gate (void) printf("%8s", "*"); 6437c478bd9Sstevel@tonic-gate else 6447c478bd9Sstevel@tonic-gate (void) printf("%8lld", used); 6457c478bd9Sstevel@tonic-gate if ((long long)free == (long long)-1) 6467c478bd9Sstevel@tonic-gate (void) printf("%8s", "*"); 6477c478bd9Sstevel@tonic-gate else 6487c478bd9Sstevel@tonic-gate (void) printf(" %7lld", free); 6497c478bd9Sstevel@tonic-gate if (missing_info) 6507c478bd9Sstevel@tonic-gate (void) printf("%6s ", "*"); 6517c478bd9Sstevel@tonic-gate else 6527c478bd9Sstevel@tonic-gate (void) printf("%6.0f%% ", (double)used / (double)total * 100.0); 6537c478bd9Sstevel@tonic-gate } 6547c478bd9Sstevel@tonic-gate 6557c478bd9Sstevel@tonic-gate /* 6567c478bd9Sstevel@tonic-gate * Return the suffix of path obtained by stripping off the prefix 6577c478bd9Sstevel@tonic-gate * that is the value of the CHROOT environment variable. If this 6587c478bd9Sstevel@tonic-gate * value isn't obtainable or if it's not a prefix of path, return NULL. 6597c478bd9Sstevel@tonic-gate */ 6607c478bd9Sstevel@tonic-gate static char * 661d1a180b0Smaheshvs zap_chroot(char *path) 6627c478bd9Sstevel@tonic-gate { 6637c478bd9Sstevel@tonic-gate return (pathsuffix(path, chrootpath)); 6647c478bd9Sstevel@tonic-gate } 6657c478bd9Sstevel@tonic-gate 6667c478bd9Sstevel@tonic-gate /* 6677c478bd9Sstevel@tonic-gate * Stat/statfs a file after stripping off leading directory to which we are 6687c478bd9Sstevel@tonic-gate * chroot'd. Used to find the TFS mount that applies to the current 6697c478bd9Sstevel@tonic-gate * activated NSE environment. 6707c478bd9Sstevel@tonic-gate */ 6717c478bd9Sstevel@tonic-gate static int 672d1a180b0Smaheshvs chroot_stat(char *dir, int (*statfunc)(), char *statp, char **dirp) 6737c478bd9Sstevel@tonic-gate { 6747c478bd9Sstevel@tonic-gate if ((dir = zap_chroot(dir)) == NULL) 6757c478bd9Sstevel@tonic-gate return (-1); 6767c478bd9Sstevel@tonic-gate if (dirp) 6777c478bd9Sstevel@tonic-gate *dirp = dir; 6787c478bd9Sstevel@tonic-gate return (*statfunc)(dir, statp); 6797c478bd9Sstevel@tonic-gate } 6807c478bd9Sstevel@tonic-gate 6817c478bd9Sstevel@tonic-gate /* 6827c478bd9Sstevel@tonic-gate * Given a name like /dev/dsk/c1d0s2, returns the mounted path, like /usr. 6837c478bd9Sstevel@tonic-gate */ 6847c478bd9Sstevel@tonic-gate char * 6857c478bd9Sstevel@tonic-gate mpath(char *file) 6867c478bd9Sstevel@tonic-gate { 6877c478bd9Sstevel@tonic-gate struct mnttab mnt; 6887c478bd9Sstevel@tonic-gate FILE *mnttab; 6897c478bd9Sstevel@tonic-gate struct stat64 device_stat, mount_stat; 6907c478bd9Sstevel@tonic-gate char *mname; 6917c478bd9Sstevel@tonic-gate 6927c478bd9Sstevel@tonic-gate mnttab = fopen(MNTTAB, "r"); 6937c478bd9Sstevel@tonic-gate if (mnttab == NULL) { 6947c478bd9Sstevel@tonic-gate return (""); 6957c478bd9Sstevel@tonic-gate } 6967c478bd9Sstevel@tonic-gate mname = ""; 6977c478bd9Sstevel@tonic-gate while ((getmntent(mnttab, &mnt)) == 0) { 6987c478bd9Sstevel@tonic-gate if (strcmp(mnt.mnt_fstype, MNTTYPE_UFS) != 0) { 6997c478bd9Sstevel@tonic-gate continue; 7007c478bd9Sstevel@tonic-gate } 7017c478bd9Sstevel@tonic-gate if (strcmp(file, mnt.mnt_special) == 0) { 7027c478bd9Sstevel@tonic-gate if (stat64(mnt.mnt_mountp, &mount_stat) != 0) 7037c478bd9Sstevel@tonic-gate continue; 7047c478bd9Sstevel@tonic-gate if (stat64(mnt.mnt_special, &device_stat) != 0) 7057c478bd9Sstevel@tonic-gate continue; 7067c478bd9Sstevel@tonic-gate 7077c478bd9Sstevel@tonic-gate if (device_stat.st_rdev == mount_stat.st_dev) { 7087c478bd9Sstevel@tonic-gate mname = mnt.mnt_mountp; 7097c478bd9Sstevel@tonic-gate break; 7107c478bd9Sstevel@tonic-gate } 7117c478bd9Sstevel@tonic-gate } 7127c478bd9Sstevel@tonic-gate } 7137c478bd9Sstevel@tonic-gate fclose(mnttab); 7147c478bd9Sstevel@tonic-gate return (mname); 7157c478bd9Sstevel@tonic-gate } 7167c478bd9Sstevel@tonic-gate 7177c478bd9Sstevel@tonic-gate /* 7187c478bd9Sstevel@tonic-gate * Given a special device, return mnttab entry 719d1a180b0Smaheshvs * Returns 0 on success 7207c478bd9Sstevel@tonic-gate */ 7217c478bd9Sstevel@tonic-gate 722d1a180b0Smaheshvs int 723d1a180b0Smaheshvs mdev(char *spec, struct mnttab **mntbp) 7247c478bd9Sstevel@tonic-gate { 7257c478bd9Sstevel@tonic-gate FILE *mntp; 7267c478bd9Sstevel@tonic-gate struct mnttab mnt; 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate if ((mntp = fopen(MNTTAB, "r")) == 0) { 7297c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "df: "); 7307c478bd9Sstevel@tonic-gate perror(MNTTAB); 731d1a180b0Smaheshvs return (1); 7327c478bd9Sstevel@tonic-gate } 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate while (getmntent(mntp, &mnt) == 0) { 7357c478bd9Sstevel@tonic-gate if (strcmp(spec, mnt.mnt_special) == 0) { 7367c478bd9Sstevel@tonic-gate (void) fclose(mntp); 737d1a180b0Smaheshvs *mntbp = mntdup(&mnt); 738d1a180b0Smaheshvs return (0); 7397c478bd9Sstevel@tonic-gate } 7407c478bd9Sstevel@tonic-gate } 7417c478bd9Sstevel@tonic-gate (void) fclose(mntp); 7427c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "df : couldn't find mnttab entry for %s", spec); 743d1a180b0Smaheshvs return (1); 7447c478bd9Sstevel@tonic-gate } 7457c478bd9Sstevel@tonic-gate 7467c478bd9Sstevel@tonic-gate /* 7477c478bd9Sstevel@tonic-gate * Find the entry in mlist that corresponds to the file named by path 7487c478bd9Sstevel@tonic-gate * (i.e., that names a mount table entry for the file system in which 7497c478bd9Sstevel@tonic-gate * path lies). The pstat argument must point to stat information for 7507c478bd9Sstevel@tonic-gate * path. 7517c478bd9Sstevel@tonic-gate * 7527c478bd9Sstevel@tonic-gate * Return the entry or NULL if there's no match. 7537c478bd9Sstevel@tonic-gate * 7547c478bd9Sstevel@tonic-gate * As it becomes necessary to obtain stat information about previously 7557c478bd9Sstevel@tonic-gate * unexamined mlist entries, gather the information and cache it with the 7567c478bd9Sstevel@tonic-gate * entries. 7577c478bd9Sstevel@tonic-gate * 7587c478bd9Sstevel@tonic-gate * The routine's strategy is to convert path into its canonical, symlink-free 7597c478bd9Sstevel@tonic-gate * representation canon (which will require accessing the file systems on the 7607c478bd9Sstevel@tonic-gate * branch from the root to path and thus may cause the routine to hang if any 7617c478bd9Sstevel@tonic-gate * of them are inaccessible) and to use it to search for a mount point whose 7627c478bd9Sstevel@tonic-gate * name is a substring of canon and whose corresponding device matches that of 7637c478bd9Sstevel@tonic-gate * canon. This technique avoids accessing unnecessary file system resources 7647c478bd9Sstevel@tonic-gate * and thus prevents the program from hanging on inaccessible resources unless 7657c478bd9Sstevel@tonic-gate * those resources are necessary for accessing path. 7667c478bd9Sstevel@tonic-gate */ 7677c478bd9Sstevel@tonic-gate static struct mntlist * 768d1a180b0Smaheshvs findmntent(char *path, struct stat64 *pstat, struct mntlist *mlist) 7697c478bd9Sstevel@tonic-gate { 7707c478bd9Sstevel@tonic-gate static char cwd[MAXPATHLEN]; 7717c478bd9Sstevel@tonic-gate char canon[MAXPATHLEN]; 7727c478bd9Sstevel@tonic-gate char scratch[MAXPATHLEN]; 773d1a180b0Smaheshvs struct mntlist *mlp; 7747c478bd9Sstevel@tonic-gate 7757c478bd9Sstevel@tonic-gate /* 7767c478bd9Sstevel@tonic-gate * If path is relative and we haven't already determined the current 7777c478bd9Sstevel@tonic-gate * working directory, do so now. Calculating the working directory 7787c478bd9Sstevel@tonic-gate * here lets us do the work once, instead of (potentially) repeatedly 7797c478bd9Sstevel@tonic-gate * in realpath(). 7807c478bd9Sstevel@tonic-gate */ 7817c478bd9Sstevel@tonic-gate if (*path != '/' && cwd[0] == '\0') { 7827c478bd9Sstevel@tonic-gate if (getcwd(cwd, MAXPATHLEN) == NULL) { 7837c478bd9Sstevel@tonic-gate cwd[0] = '\0'; 7847c478bd9Sstevel@tonic-gate return (NULL); 7857c478bd9Sstevel@tonic-gate } 7867c478bd9Sstevel@tonic-gate } 7877c478bd9Sstevel@tonic-gate 7887c478bd9Sstevel@tonic-gate /* 7897c478bd9Sstevel@tonic-gate * Find an absolute pathname in the native file system name space that 7907c478bd9Sstevel@tonic-gate * corresponds to path, stuffing it into canon. 7917c478bd9Sstevel@tonic-gate * 7927c478bd9Sstevel@tonic-gate * If CHROOT is set in the environment, assume that chroot($CHROOT) 7937c478bd9Sstevel@tonic-gate * (or an equivalent series of calls) was executed and convert the 7947c478bd9Sstevel@tonic-gate * path to the equivalent name in the native file system's name space. 7957c478bd9Sstevel@tonic-gate * Doing so allows direct comparison with the names in mtab entires, 7967c478bd9Sstevel@tonic-gate * which are assumed to be recorded relative to the native name space. 7977c478bd9Sstevel@tonic-gate */ 7987c478bd9Sstevel@tonic-gate if (abspath(cwd, path, scratch) < 0) 7997c478bd9Sstevel@tonic-gate return (NULL); 8007c478bd9Sstevel@tonic-gate if (strcmp(scratch, "/") == 0 && chrootpath != NULL) { 8017c478bd9Sstevel@tonic-gate /* 8027c478bd9Sstevel@tonic-gate * Force canon to be in canonical form; if the result from 8037c478bd9Sstevel@tonic-gate * abspath was "/" and chrootpath isn't the null string, we 8047c478bd9Sstevel@tonic-gate * must strip off a trailing slash. 8057c478bd9Sstevel@tonic-gate */ 8067c478bd9Sstevel@tonic-gate scratch[0] = '\0'; 8077c478bd9Sstevel@tonic-gate } 8087c478bd9Sstevel@tonic-gate (void) sprintf(canon, "%s%s", chrootpath ? chrootpath : "", scratch); 8097c478bd9Sstevel@tonic-gate 8107c478bd9Sstevel@tonic-gate again: 8117c478bd9Sstevel@tonic-gate for (mlp = mlist; mlp; mlp = mlp->mntl_next) { 8127c478bd9Sstevel@tonic-gate struct mnttab *mnt = mlp->mntl_mnt; 8137c478bd9Sstevel@tonic-gate 8147c478bd9Sstevel@tonic-gate /* 8157c478bd9Sstevel@tonic-gate * Ignore uninteresting mounts. 8167c478bd9Sstevel@tonic-gate */ 8177c478bd9Sstevel@tonic-gate if (strcmp(mnt->mnt_fstype, typestr) != 0) 8187c478bd9Sstevel@tonic-gate continue; 8197c478bd9Sstevel@tonic-gate 8207c478bd9Sstevel@tonic-gate /* 8217c478bd9Sstevel@tonic-gate * The mount entry covers some prefix of the file. 8227c478bd9Sstevel@tonic-gate * See whether it's the entry for the file system 8237c478bd9Sstevel@tonic-gate * containing the file by comparing device ids. 8247c478bd9Sstevel@tonic-gate */ 8257c478bd9Sstevel@tonic-gate if (mlp->mntl_dev == NODEV) { 8267c478bd9Sstevel@tonic-gate struct stat64 fs_sb; 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate if (stat64(mnt->mnt_mountp, &fs_sb) < 0 && 8297c478bd9Sstevel@tonic-gate chroot_stat(mnt->mnt_mountp, stat64, (char *)&fs_sb, 8307c478bd9Sstevel@tonic-gate (char **)NULL) < 0) { 8317c478bd9Sstevel@tonic-gate continue; 8327c478bd9Sstevel@tonic-gate } 8337c478bd9Sstevel@tonic-gate mlp->mntl_dev = fs_sb.st_dev; 8347c478bd9Sstevel@tonic-gate } 8357c478bd9Sstevel@tonic-gate 8367c478bd9Sstevel@tonic-gate if (pstat->st_dev == mlp->mntl_dev) 8377c478bd9Sstevel@tonic-gate return (mlp); 8387c478bd9Sstevel@tonic-gate } 8397c478bd9Sstevel@tonic-gate 8407c478bd9Sstevel@tonic-gate return (NULL); 8417c478bd9Sstevel@tonic-gate } 8427c478bd9Sstevel@tonic-gate 8437c478bd9Sstevel@tonic-gate /* 8447c478bd9Sstevel@tonic-gate * Convert the path given in raw to canonical, absolute, symlink-free 8457c478bd9Sstevel@tonic-gate * form, storing the result in the buffer named by canon, which must be 8467c478bd9Sstevel@tonic-gate * at least MAXPATHLEN bytes long. "wd" contains the current working 8477c478bd9Sstevel@tonic-gate * directory; accepting this value as an argument lets our caller cache 8487c478bd9Sstevel@tonic-gate * the value, so that realpath (called from this routine) doesn't have 8497c478bd9Sstevel@tonic-gate * to recalculate it each time it's given a relative pathname. 8507c478bd9Sstevel@tonic-gate * 8517c478bd9Sstevel@tonic-gate * Return 0 on success, -1 on failure. 8527c478bd9Sstevel@tonic-gate */ 8537c478bd9Sstevel@tonic-gate static int 854d1a180b0Smaheshvs abspath(char *wd, char *raw, char *canon) 8557c478bd9Sstevel@tonic-gate { 8567c478bd9Sstevel@tonic-gate char absbuf[MAXPATHLEN]; 8577c478bd9Sstevel@tonic-gate 8587c478bd9Sstevel@tonic-gate /* 8597c478bd9Sstevel@tonic-gate * Preliminary sanity check. 8607c478bd9Sstevel@tonic-gate */ 8617c478bd9Sstevel@tonic-gate if (wd == NULL || raw == NULL || canon == NULL) 8627c478bd9Sstevel@tonic-gate return (-1); 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate /* 8657c478bd9Sstevel@tonic-gate * If the path is relative, convert it to absolute form, 8667c478bd9Sstevel@tonic-gate * using wd if it's been supplied. 8677c478bd9Sstevel@tonic-gate */ 8687c478bd9Sstevel@tonic-gate if (raw[0] != '/') { 869d1a180b0Smaheshvs char *limit = absbuf + sizeof (absbuf); 870d1a180b0Smaheshvs char *d; 8717c478bd9Sstevel@tonic-gate 8727c478bd9Sstevel@tonic-gate /* Fill in working directory. */ 8737c478bd9Sstevel@tonic-gate if (strlcpy(absbuf, wd, sizeof (absbuf)) >= sizeof (absbuf)) 8747c478bd9Sstevel@tonic-gate return (-1); 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate /* Add separating slash. */ 8777c478bd9Sstevel@tonic-gate d = absbuf + strlen(absbuf); 8787c478bd9Sstevel@tonic-gate if (d < limit) 8797c478bd9Sstevel@tonic-gate *d++ = '/'; 8807c478bd9Sstevel@tonic-gate 8817c478bd9Sstevel@tonic-gate /* Glue on the relative part of the path. */ 8827c478bd9Sstevel@tonic-gate while (d < limit && (*d++ = *raw++)) 8837c478bd9Sstevel@tonic-gate continue; 8847c478bd9Sstevel@tonic-gate 8857c478bd9Sstevel@tonic-gate raw = absbuf; 8867c478bd9Sstevel@tonic-gate } 8877c478bd9Sstevel@tonic-gate 8887c478bd9Sstevel@tonic-gate /* 8897c478bd9Sstevel@tonic-gate * Call realpath to canonicalize and resolve symlinks. 8907c478bd9Sstevel@tonic-gate */ 8917c478bd9Sstevel@tonic-gate return (realpath(raw, canon) == NULL ? -1 : 0); 8927c478bd9Sstevel@tonic-gate } 8937c478bd9Sstevel@tonic-gate 8947c478bd9Sstevel@tonic-gate /* 8957c478bd9Sstevel@tonic-gate * Return a pointer to the trailing suffix of full that follows the prefix 8967c478bd9Sstevel@tonic-gate * given by pref. If pref isn't a prefix of full, return NULL. Apply 8977c478bd9Sstevel@tonic-gate * pathname semantics to the prefix test, so that pref must match at a 8987c478bd9Sstevel@tonic-gate * component boundary. 8997c478bd9Sstevel@tonic-gate */ 9007c478bd9Sstevel@tonic-gate static char * 901d1a180b0Smaheshvs pathsuffix(char *full, char *pref) 9027c478bd9Sstevel@tonic-gate { 903d1a180b0Smaheshvs int preflen; 9047c478bd9Sstevel@tonic-gate 9057c478bd9Sstevel@tonic-gate if (full == NULL || pref == NULL) 9067c478bd9Sstevel@tonic-gate return (NULL); 9077c478bd9Sstevel@tonic-gate 9087c478bd9Sstevel@tonic-gate preflen = strlen(pref); 9097c478bd9Sstevel@tonic-gate if (strncmp(pref, full, preflen) != 0) 9107c478bd9Sstevel@tonic-gate return (NULL); 9117c478bd9Sstevel@tonic-gate 9127c478bd9Sstevel@tonic-gate /* 9137c478bd9Sstevel@tonic-gate * pref is a substring of full. To be a subpath, it cannot cover a 9147c478bd9Sstevel@tonic-gate * partial component of full. The last clause of the test handles the 9157c478bd9Sstevel@tonic-gate * special case of the root. 9167c478bd9Sstevel@tonic-gate */ 9177c478bd9Sstevel@tonic-gate if (full[preflen] != '\0' && full[preflen] != '/' && preflen > 1) 9187c478bd9Sstevel@tonic-gate return (NULL); 9197c478bd9Sstevel@tonic-gate 9207c478bd9Sstevel@tonic-gate if (preflen == 1 && full[0] == '/') 9217c478bd9Sstevel@tonic-gate return (full); 9227c478bd9Sstevel@tonic-gate else 9237c478bd9Sstevel@tonic-gate return (full + preflen); 9247c478bd9Sstevel@tonic-gate } 9257c478bd9Sstevel@tonic-gate 9267c478bd9Sstevel@tonic-gate /* 9277c478bd9Sstevel@tonic-gate * Return zero iff the path named by sub is a leading subpath 9287c478bd9Sstevel@tonic-gate * of the path named by full. 9297c478bd9Sstevel@tonic-gate * 9307c478bd9Sstevel@tonic-gate * Treat null paths as matching nothing. 9317c478bd9Sstevel@tonic-gate */ 9327c478bd9Sstevel@tonic-gate static int 933d1a180b0Smaheshvs subpath(char *full, char *sub) 9347c478bd9Sstevel@tonic-gate { 9357c478bd9Sstevel@tonic-gate return (pathsuffix(full, sub) == NULL); 9367c478bd9Sstevel@tonic-gate } 9377c478bd9Sstevel@tonic-gate 9387c478bd9Sstevel@tonic-gate offset_t llseek(); 9397c478bd9Sstevel@tonic-gate 9407c478bd9Sstevel@tonic-gate int 941d1a180b0Smaheshvs bread(char *file, int fi, daddr_t bno, char *buf, int cnt) 9427c478bd9Sstevel@tonic-gate { 943d1a180b0Smaheshvs int n; 9447c478bd9Sstevel@tonic-gate 9457c478bd9Sstevel@tonic-gate (void) llseek(fi, (offset_t)bno * DEV_BSIZE, 0); 9467c478bd9Sstevel@tonic-gate if ((n = read(fi, buf, cnt)) < 0) { 9477c478bd9Sstevel@tonic-gate /* probably a dismounted disk if errno == EIO */ 9487c478bd9Sstevel@tonic-gate if (errno != EIO) { 9497c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("df: read error on ")); 9507c478bd9Sstevel@tonic-gate perror(file); 9517c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "bno = %ld\n", bno); 9527c478bd9Sstevel@tonic-gate } else { 9537c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext( 9547c478bd9Sstevel@tonic-gate "df: premature EOF on %s\n"), file); 9557c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 9567c478bd9Sstevel@tonic-gate "bno = %ld expected = %d count = %d\n", bno, cnt, n); 9577c478bd9Sstevel@tonic-gate } 9587c478bd9Sstevel@tonic-gate return (0); 9597c478bd9Sstevel@tonic-gate } 9607c478bd9Sstevel@tonic-gate return (1); 9617c478bd9Sstevel@tonic-gate } 9627c478bd9Sstevel@tonic-gate 9637c478bd9Sstevel@tonic-gate char * 964d1a180b0Smaheshvs xmalloc(unsigned int size) 9657c478bd9Sstevel@tonic-gate { 966d1a180b0Smaheshvs char *ret; 9677c478bd9Sstevel@tonic-gate char *malloc(); 9687c478bd9Sstevel@tonic-gate 9697c478bd9Sstevel@tonic-gate if ((ret = (char *)malloc(size)) == NULL) { 9707c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("umount: ran out of memory!\n")); 9717c478bd9Sstevel@tonic-gate exit(1); 9727c478bd9Sstevel@tonic-gate } 9737c478bd9Sstevel@tonic-gate return (ret); 9747c478bd9Sstevel@tonic-gate } 9757c478bd9Sstevel@tonic-gate 9767c478bd9Sstevel@tonic-gate struct mnttab * 977d1a180b0Smaheshvs mntdup(struct mnttab *mnt) 9787c478bd9Sstevel@tonic-gate { 979d1a180b0Smaheshvs struct mnttab *new; 9807c478bd9Sstevel@tonic-gate 9817c478bd9Sstevel@tonic-gate new = (struct mnttab *)xmalloc(sizeof (*new)); 9827c478bd9Sstevel@tonic-gate 9837c478bd9Sstevel@tonic-gate new->mnt_special = 9847c478bd9Sstevel@tonic-gate (char *)xmalloc((unsigned)(strlen(mnt->mnt_special) + 1)); 9857c478bd9Sstevel@tonic-gate (void) strcpy(new->mnt_special, mnt->mnt_special); 9867c478bd9Sstevel@tonic-gate 9877c478bd9Sstevel@tonic-gate new->mnt_mountp = 9887c478bd9Sstevel@tonic-gate (char *)xmalloc((unsigned)(strlen(mnt->mnt_mountp) + 1)); 9897c478bd9Sstevel@tonic-gate (void) strcpy(new->mnt_mountp, mnt->mnt_mountp); 9907c478bd9Sstevel@tonic-gate 9917c478bd9Sstevel@tonic-gate new->mnt_fstype = 9927c478bd9Sstevel@tonic-gate (char *)xmalloc((unsigned)(strlen(mnt->mnt_fstype) + 1)); 9937c478bd9Sstevel@tonic-gate (void) strcpy(new->mnt_fstype, mnt->mnt_fstype); 9947c478bd9Sstevel@tonic-gate 9957c478bd9Sstevel@tonic-gate if (mnt->mnt_mntopts != NULL) { 9967c478bd9Sstevel@tonic-gate new->mnt_mntopts = 9977c478bd9Sstevel@tonic-gate (char *)xmalloc((unsigned)(strlen(mnt->mnt_mntopts) + 1)); 9987c478bd9Sstevel@tonic-gate (void) strcpy(new->mnt_mntopts, mnt->mnt_mntopts); 9997c478bd9Sstevel@tonic-gate } else { 10007c478bd9Sstevel@tonic-gate new->mnt_mntopts = NULL; 10017c478bd9Sstevel@tonic-gate } 10027c478bd9Sstevel@tonic-gate 10037c478bd9Sstevel@tonic-gate #ifdef never 10047c478bd9Sstevel@tonic-gate new->mnt_freq = mnt->mnt_freq; 10057c478bd9Sstevel@tonic-gate new->mnt_passno = mnt->mnt_passno; 10067c478bd9Sstevel@tonic-gate #endif /* never */ 10077c478bd9Sstevel@tonic-gate 10087c478bd9Sstevel@tonic-gate return (new); 10097c478bd9Sstevel@tonic-gate } 10107c478bd9Sstevel@tonic-gate 10117c478bd9Sstevel@tonic-gate void 10127c478bd9Sstevel@tonic-gate usage() 10137c478bd9Sstevel@tonic-gate { 10147c478bd9Sstevel@tonic-gate 10157c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext( 10167c478bd9Sstevel@tonic-gate "ufs usage: df [generic options] [-o i] [directory | special]\n")); 10177c478bd9Sstevel@tonic-gate exit(1); 10187c478bd9Sstevel@tonic-gate } 10197c478bd9Sstevel@tonic-gate 10207c478bd9Sstevel@tonic-gate struct mntlist * 10217c478bd9Sstevel@tonic-gate mkmntlist() 10227c478bd9Sstevel@tonic-gate { 10237c478bd9Sstevel@tonic-gate FILE *mounted; 10247c478bd9Sstevel@tonic-gate struct mntlist *mntl; 10257c478bd9Sstevel@tonic-gate struct mntlist *mntst = NULL; 10267c478bd9Sstevel@tonic-gate struct extmnttab mnt; 10277c478bd9Sstevel@tonic-gate 10287c478bd9Sstevel@tonic-gate if ((mounted = fopen(MNTTAB, "r")) == NULL) { 10297c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "df : "); 10307c478bd9Sstevel@tonic-gate perror(MNTTAB); 10317c478bd9Sstevel@tonic-gate exit(1); 10327c478bd9Sstevel@tonic-gate } 10337c478bd9Sstevel@tonic-gate resetmnttab(mounted); 10347c478bd9Sstevel@tonic-gate while (getextmntent(mounted, &mnt, sizeof (struct extmnttab)) == NULL) { 10357c478bd9Sstevel@tonic-gate mntl = (struct mntlist *)xmalloc(sizeof (*mntl)); 10367c478bd9Sstevel@tonic-gate mntl->mntl_mnt = mntdup((struct mnttab *)(&mnt)); 10377c478bd9Sstevel@tonic-gate mntl->mntl_next = mntst; 10387c478bd9Sstevel@tonic-gate mntl->mntl_devvalid = 1; 10397c478bd9Sstevel@tonic-gate mntl->mntl_dev = makedev(mnt.mnt_major, mnt.mnt_minor); 10407c478bd9Sstevel@tonic-gate mntst = mntl; 10417c478bd9Sstevel@tonic-gate } 10427c478bd9Sstevel@tonic-gate (void) fclose(mounted); 10437c478bd9Sstevel@tonic-gate return (mntst); 10447c478bd9Sstevel@tonic-gate } 10457c478bd9Sstevel@tonic-gate 10467c478bd9Sstevel@tonic-gate void 1047d1a180b0Smaheshvs print_statvfs(struct statvfs64 *fs) 10487c478bd9Sstevel@tonic-gate { 10497c478bd9Sstevel@tonic-gate int i; 10507c478bd9Sstevel@tonic-gate 10517c478bd9Sstevel@tonic-gate for (i = 0; i < FSTYPSZ; i++) 10527c478bd9Sstevel@tonic-gate (void) printf("%c", fs->f_basetype[i]); 10537c478bd9Sstevel@tonic-gate (void) printf(" %7d %7lld %7lld", 10547c478bd9Sstevel@tonic-gate fs->f_frsize, 10557c478bd9Sstevel@tonic-gate fs->f_blocks, 10567c478bd9Sstevel@tonic-gate fs->f_bavail); 10577c478bd9Sstevel@tonic-gate (void) printf(" %7lld %7lld %7d", 10587c478bd9Sstevel@tonic-gate fs->f_files, 10597c478bd9Sstevel@tonic-gate fs->f_ffree, 10607c478bd9Sstevel@tonic-gate fs->f_fsid); 10617c478bd9Sstevel@tonic-gate (void) printf(" 0x%x ", 10627c478bd9Sstevel@tonic-gate fs->f_flag); 10637c478bd9Sstevel@tonic-gate for (i = 0; i < 14; i++) 10647c478bd9Sstevel@tonic-gate (void) printf("%c", 10657c478bd9Sstevel@tonic-gate (fs->f_fstr[i] == '\0') ? ' ' : fs->f_fstr[i]); 10667c478bd9Sstevel@tonic-gate printf("\n"); 10677c478bd9Sstevel@tonic-gate } 10687c478bd9Sstevel@tonic-gate 10697c478bd9Sstevel@tonic-gate void 10707c478bd9Sstevel@tonic-gate print_totals() 10717c478bd9Sstevel@tonic-gate { 10727c478bd9Sstevel@tonic-gate /* 10737c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 10747c478bd9Sstevel@tonic-gate * Following string is used as a table header. 10757c478bd9Sstevel@tonic-gate * Translated items should start at the same 10767c478bd9Sstevel@tonic-gate * columns as the original items. 10777c478bd9Sstevel@tonic-gate */ 10787c478bd9Sstevel@tonic-gate (void) printf(gettext("Totals %8lld %7lld %7lld"), 10797c478bd9Sstevel@tonic-gate t_totalblks, t_used, t_avail); 10807c478bd9Sstevel@tonic-gate (void) printf("%6.0f%%\n", 10817c478bd9Sstevel@tonic-gate (t_totalblks - t_reserved) == (fsblkcnt64_t)0 ? 10827c478bd9Sstevel@tonic-gate 0.0 : 10837c478bd9Sstevel@tonic-gate (double)t_used / (double)(t_totalblks - t_reserved) * 100.0); 10847c478bd9Sstevel@tonic-gate } 10857c478bd9Sstevel@tonic-gate 10867c478bd9Sstevel@tonic-gate void 10877c478bd9Sstevel@tonic-gate print_itotals() 10887c478bd9Sstevel@tonic-gate { 10897c478bd9Sstevel@tonic-gate /* 10907c478bd9Sstevel@tonic-gate * TRANSLATION_NOTE 10917c478bd9Sstevel@tonic-gate * Following string is used as a table header. 10927c478bd9Sstevel@tonic-gate * Translated items should start at the same 10937c478bd9Sstevel@tonic-gate * columns as the original items. 10947c478bd9Sstevel@tonic-gate */ 10957c478bd9Sstevel@tonic-gate (void) printf(gettext("Totals %8d %7d%6.0f%%\n"), 10967c478bd9Sstevel@tonic-gate t_iused, 10977c478bd9Sstevel@tonic-gate t_ifree, 10987c478bd9Sstevel@tonic-gate t_inodes == 0 ? 0.0 : (double)t_iused / (double)t_inodes * 100.0); 10997c478bd9Sstevel@tonic-gate } 1100