int get_rootmetadevice(char *mntpath, char **mdname) { struct vfstab v; FILE *fp; int rval = RET_SUCCESS; char *cp; char vfstab_name[PATH_MAX + 1]; if (mdname == NULL) return (EINVAL); *mdname = NULL; if (snprintf(vfstab_name, PATH_MAX + 1, "%s%s", mntpath, VFSTAB) < 0) return (ENOMEM); debug_printf("get_rootmetadevice(): mntpath %s %s\n", mntpath, vfstab_name); if ((fp = fopen(vfstab_name, "r")) == NULL) { rval = errno; return (rval); } if ((rval = getvfsfile(fp, &v, ROOT_MNTPT)) != 0) { goto out; } debug_printf("get_rootmetadevice(): vfs_special %s\n", v.vfs_special); if (strstr(v.vfs_special, ROOT_METADEVICE) == NULL) { /* md device not found */ rval = RET_ERROR; goto out; } /* found a match fill it and return */ cp = v.vfs_special + strlen(ROOT_METADEVICE); *mdname = (char *)malloc(strlen(cp) + 1); if (*mdname == NULL) { rval = ENOMEM; goto out; } (void) strcpy(*mdname, cp); debug_printf("get_rootmetadevice(): *mdname %s rval %d\n", *mdname, rval); out: (void) fclose(fp); return (rval); }
static struct vfstab* getfsfile (const char *mount_point) { int r; int close = 0; if (etc_fstab == 0) { close = 1; if (setfsent () != 1) return NULL; } rewind (etc_fstab); r = getvfsfile (etc_fstab, &cur_vfstab_entry, (char*) mount_point); if (close) endfsent (); if (r == 0) return &cur_vfstab_entry; return NULL; }
int main (int argc, char **argv) { int i; int j; struct usage use_by_uid [SSP_MAXUID]; FILE *fp; struct vfstab vfstab; if (argc < 2) err_quit ("Usage: diskuse file_system ..."); if ((fp = fopen (VFSTAB, "r")) == NULL) err_quit ("Can't open %s", VFSTAB); for (j = 1; j < argc; j++) { rewind (fp); if (getvfsfile (fp, &vfstab, argv [j]) == -1) { log_msg ("%s: Not found in %s", argv [j], VFSTAB); continue; } memset (use_by_uid, 0, sizeof (use_by_uid)); for (i = 0; i < SSP_MAXUID; i++) use_by_uid [i].uid = i; if (diskuse (vfstab.vfs_fsckdev, use_by_uid) == -1) continue; qsort (use_by_uid, SSP_MAXUID, sizeof (struct usage), blk_compare); print_results (vfstab.vfs_mountp, vfstab.vfs_fsckdev, use_by_uid); } fclose (fp); return (0); }
int main (int argc, char **argv) { FILE *fp; struct vfstab vp; int ret; int i; if ((fp = fopen ("/etc/vfstab", "r")) == NULL) err_msg ("Can't open /etc/vfstab"); if (argc == 1) { while ((ret = getvfsent (fp, &vp)) == 0) print_vfstab (&vp); if (ret != -1) err_quit ("Bad /etc/vfstab file.\n"); } else { for (i = 1; argc-- > 1; i++) { switch (getvfsfile (fp, &vp, argv [i])) { case -1: rewind (fp); break; case 0: print_vfstab (&vp); rewind (fp); break; default: err_quit ("Bad /etc/vfstab file.\n"); break; } } } return (0); }