char * makenetvfslist(void) { char *str, *strptr, **listptr; int mib[3], maxvfsconf, cnt=0, i; size_t miblen; struct ovfsconf *ptr; mib[0] = CTL_VFS; mib[1] = VFS_GENERIC; mib[2] = VFS_MAXTYPENUM; miblen=sizeof(maxvfsconf); if (sysctl(mib, (unsigned int)(sizeof(mib) / sizeof(mib[0])), &maxvfsconf, &miblen, NULL, 0)) { warnx("sysctl failed"); return (NULL); } if ((listptr = malloc(sizeof(char*) * maxvfsconf)) == NULL) { warnx("malloc failed"); return (NULL); } for (ptr = getvfsent(); ptr; ptr = getvfsent()) if (ptr->vfc_flags & VFCF_NETWORK) { listptr[cnt++] = strdup(ptr->vfc_name); if (listptr[cnt-1] == NULL) { warnx("malloc failed"); return (NULL); } } if (cnt == 0 || (str = malloc(sizeof(char) * (32 * cnt + cnt + 2))) == NULL) { if (cnt > 0) warnx("malloc failed"); free(listptr); return (NULL); } *str = 'n'; *(str + 1) = 'o'; for (i = 0, strptr = str + 2; i < cnt; i++, strptr++) { strncpy(strptr, listptr[i], 32); strptr += strlen(listptr[i]); *strptr = ','; free(listptr[i]); } *(--strptr) = '\0'; free(listptr); return (str); }
static void searchvfstab(char **specialp) { FILE *vfstab; struct vfstab vfsbuf; char *blockspecial; blockspecial = getfullblkname(*specialp); if (blockspecial == NULL) blockspecial = *specialp; if ((vfstab = fopen(VFSTAB, "r")) == NULL) { fprintf(stderr, "%s: ", VFSTAB); perror("open"); } while (getvfsent(vfstab, &vfsbuf) == NULL) if (strcmp(vfsbuf.vfs_fstype, MNTTYPE_UFS) == 0) if ((strcmp(vfsbuf.vfs_mountp, *specialp) == 0) || (strcmp(vfsbuf.vfs_special, *specialp) == 0) || (strcmp(vfsbuf.vfs_special, blockspecial) == 0) || (strcmp(vfsbuf.vfs_fsckdev, *specialp) == 0)) { *specialp = strdup(vfsbuf.vfs_special); return; } fclose(vfstab); }
static struct vfstab* getfsent (void) { int r; r = getvfsent (etc_fstab, &cur_vfstab_entry); if (r == 0) return &cur_vfstab_entry; return NULL; }
/* ========================================================================= */ int next_mount_item(struct mlistd *m) { if ( NULL == m ) return(-1); if ( NULL == m->mf ) return(-1); if (( LIST_FSTAB != m->list_src ) && ( LIST_MNTAB != m->list_src )) return(-1); #if defined(PORT_Linux) || defined(PORT_AIX) if ( NULL == (m->mnt = getmntent(m->mf)) ) return(1); m->mount_point = m->mnt->mnt_dir; #endif #if defined(PORT_SunOS) if ( LIST_FSTAB == m->list_src ) { if ( getvfsent(m->mf, m->vfs) ) return(1); m->mount_point = m->vfs->vfs_mountp; } if ( LIST_MNTAB == m->list_src ) { if ( getmntent(m->mf, m->mnt) ) return(1); m->mount_point = m->mnt->mnt_mountp; } #endif if ( NULL == m->mount_point ) m->mount_point = m->nada; 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); }
static int load_vfstab() { FILE *fp; struct vfstab vp; int status = 1; fp = fopen(VFSTAB, "r"); if (fp != NULL) { (void) memset(&vp, 0, sizeof (struct vfstab)); while (getvfsent(fp, &vp) == 0) { status = add_use_record(&vp); if (status != 0) { (void) fclose(fp); return (status); } (void) memset(&vp, 0, sizeof (struct vfstab)); } (void) fclose(fp); status = 0; } return (status); }
char * makenetvfslist(void) { char *str, *strptr, **listptr; #ifndef __APPLE__ int mib[3], maxvfsconf, cnt=0, i; size_t miblen; struct ovfsconf *ptr; #else int mib[4], maxvfsconf, cnt=0, i; size_t miblen; struct vfsconf vfc; #endif mib[0] = CTL_VFS; mib[1] = VFS_GENERIC; mib[2] = VFS_MAXTYPENUM; miblen=sizeof(maxvfsconf); if (sysctl(mib, 3, &maxvfsconf, &miblen, NULL, 0)) { warn("sysctl failed"); return (NULL); } if ((listptr = malloc(sizeof(char*) * maxvfsconf)) == NULL) { warnx("malloc failed"); return (NULL); } #ifndef __APPLE__ for (ptr = getvfsent(); ptr; ptr = getvfsent()) if (ptr->vfc_flags & VFCF_NETWORK) { listptr[cnt++] = strdup(ptr->vfc_name); if (listptr[cnt-1] == NULL) { warnx("malloc failed"); return (NULL); } } #else miblen = sizeof (struct vfsconf); mib[2] = VFS_CONF; for (i = 0; i < maxvfsconf; i++) { mib[3] = i; if (sysctl(mib, 4, &vfc, &miblen, NULL, 0) == 0) { if (!(vfc.vfc_flags & MNT_LOCAL)) { listptr[cnt++] = strdup(vfc.vfc_name); if (listptr[cnt-1] == NULL) { free(listptr); warnx("malloc failed"); return (NULL); } } } } #endif if (cnt == 0 || (str = malloc(sizeof(char) * (32 * cnt + cnt + 2))) == NULL) { if (cnt > 0) warnx("malloc failed"); free(listptr); return (NULL); } *str = 'n'; *(str + 1) = 'o'; for (i = 0, strptr = str + 2; i < cnt; i++, strptr++) { strncpy(strptr, listptr[i], 32); strptr += strlen(listptr[i]); *strptr = ','; free(listptr[i]); } *(--strptr) = '\0'; free(listptr); return (str); }
/* * Read all vstab (fp) entries into memory if fstype == NULL. * If fstype is specified, than read all those that match it. * * Returns a linked list. */ vfsent_t * getvfsall(char *fstype, int takeall) { vfsent_t *vhead, *vtail; struct vfstab vget; FILE *fp; int cnt = 0, ret; if ((fp = fopen(vfstab, "r")) == NULL) { fprintf(stderr, gettext("%s: Cannot open %s\n"), myname, vfstab); exit(1); } vhead = vtail = NULL; while ((ret = getvfsent(fp, &vget)) != -1) { vfsent_t *vp; if (ret > 0) { vfserror(ret, vget.vfs_mountp); continue; } /* * If mount points were not specified, then we ignore * entries that aren't marked "yes". */ if (takeall && (vget.vfs_automnt == NULL || strcmp(vget.vfs_automnt, "yes"))) continue; if (fstype && vget.vfs_fstype && strcmp(fstype, vget.vfs_fstype)) continue; if (vget.vfs_mountp == NULL || (vget.vfs_fstype && (strcmp(vget.vfs_fstype, "swap") == 0))) continue; if (check_fields(vget.vfs_fstype, vget.vfs_mountp)) { exitcode = 1; continue; } vp = new_vfsent(&vget, cnt); /* create new vfs entry */ if (vhead == NULL) vhead = vp; else vtail->next = vp; vtail = vp; cnt++; } fclose(fp); if (vtail == NULL) { vfsarraysize = 0; vfslltail = NULL; return (NULL); } vtail->next = NULL; vfslltail = vtail; /* save it in the global variable */ vfsarraysize = cnt; return (vhead); }
/* * get_mntinfo - get the mount table, now dynamically allocated. Returns 0 if * no problem and 1 if there's a fatal error. */ int get_mntinfo(int map_client, char *vfstab_file) { static char *rn = "/"; FILE *pp; struct mnttab mtbuf; struct mnttab *mt = &mtbuf; char *install_root; int is_remote; /* * Open the mount table for the current host and establish a global * table that holds data about current mount status. */ if ((pp = setmntent(MOUNT_TABLE, "r")) == NULL) { progerr(ERR_NOTABLE, "mount", MOUNT_TABLE, strerror(errno)); return (1); } /* * First, review the mounted filesystems on the managing host. This * may also be the target host but we haven't decided that for sure * yet. */ while (!getmntent(pp, mt)) if (construct_mt(mt)) return (1); (void) endmntent(pp); /* * Now, we see if this installation is to a client. If it is, we scan * the client's vfstab to determine what filesystems are * inappropriate to write to. This simply adds the vfstab entries * representing what will be remote file systems for the client. * Everything that isn't remote to the client is already accounted * for in the fs_tab[] so far. If the remote filesystem is really on * this server, we will write through to the server from this client. */ install_root = get_inst_root(); if (install_root && strcmp(install_root, "/") != 0 && map_client) { /* OK, this is a legitimate remote client. */ struct vfstab vfsbuf; struct vfstab *vfs = &vfsbuf; char VFS_TABLE[PATH_MAX]; /* * Since we use the fsys() function later, and it depends on * an ordered list, we have to sort the list here. */ qsort(fs_tab, fs_tab_used, sizeof (struct fstable *), fs_tab_ent_comp); /* * Here's where the vfstab for the target is. If we can get * to it, we'll scan it for what the client will see as * remote filesystems, otherwise, we'll just skip this. */ if (vfstab_file) { (void) snprintf(VFS_TABLE, sizeof (VFS_TABLE), "%s", vfstab_file); } else { (void) snprintf(VFS_TABLE, sizeof (VFS_TABLE), "%s%s", install_root, VFSTAB); } if (access(VFS_TABLE, R_OK) == 0) { char *link_name; /* * Open the vfs table for the target host. */ if ((pp = setmntent(VFS_TABLE, "r")) == NULL) { progerr(ERR_NOTABLE, "vfs", VFS_TABLE, strerror(errno)); return (1); } /* Do this for each entry in the vfstab. */ while (!getvfsent(pp, vfs)) { char client_mountp[PATH_MAX]; int mnt_stat; /* * We put it into the fs table if it's * remote mounted (even from this server) or * loopback mounted from the client's point * of view. */ if (!(is_remote = is_remote_src(vfs->vfs_special)) && strcmp(vfs->vfs_fstype, MNTTYPE_LOFS) != 0) continue; /* not interesting */ /* * Construct client_mountp by prepending the * install_root to the 'mount point' name. */ if (strcmp(vfs->vfs_mountp, "/") == 0) { (void) strcpy(client_mountp, install_root); } else { (void) snprintf(client_mountp, sizeof (client_mountp), "%s%s", install_root, vfs->vfs_mountp); } /* * We also skip the entry if the vfs_special * path and the client_path are the same. * There's no need to mount it, it's just a * cachefs optimization that mounts a * directory over itself from this server. */ if ((is_remote == SELF_SERVE) && strcmp(path_part(vfs->vfs_special), client_mountp) == 0) continue; /* Determine if this is already mounted. */ link_name = strdup(path_part(vfs->vfs_special)); mnt_stat = already_mounted(vfs, (is_remote != REAL_REMOTE), client_mountp, link_name); if (mnt_stat == MNT_EXACT) { mod_existing(vfs, match_mount, is_remote); } else { /* MNT_NOT */ if (construct_vfs(vfs, client_mountp, link_name, is_remote, mnt_stat)) { return (1); } } } (void) endmntent(pp); } /* end of if(access()) */ } /* end of if(install_root) */ /* This next one may look stupid, but it can really happen. */ if (fs_tab_used <= 0) { progerr(ERR_MNT_NOMOUNTS); return (1); } /* * Now that we have the complete list of mounted (or virtually * mounted) filesystems, we sort the mountpoints in reverse order * based on the length of the 'mount point' name. */ qsort(fs_tab, fs_tab_used, sizeof (struct fstable *), fs_tab_ent_comp); if (strcmp(fs_tab[fs_tab_used-1]->name, rn) != 0) { progerr(ERR_MNT_NOROOT, fs_tab[fs_tab_used-1]->name, rn, errno, strerror(errno)); return (1); } else { return (0); } }
/*_________________---------------------------__________________ _________________ makenetvfslist __________________ -----------------___________________________------------------ */ static char * makenetvfslist(void) { char *str = NULL, *strptr, **listptr = NULL; size_t slen; int cnt = 0; int i; #if __FreeBSD_version > 500000 struct xvfsconf *xvfsp, *keep_xvfsp = NULL; size_t buflen; int maxvfsconf; if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0) { printf("sysctl(vfs.conflist)"); goto done; } keep_xvfsp = xvfsp = malloc(buflen); if (xvfsp == NULL) { printf("malloc failed"); goto done; } if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0) { printf("sysctl(vfs.conflist)"); goto done; } maxvfsconf = buflen / sizeof(struct xvfsconf); if ((listptr = malloc(sizeof(char*) * maxvfsconf)) == NULL) { printf("malloc failed"); goto done; } cnt = 0; for (i = 0; i < maxvfsconf; i++, xvfsp++) { if (xvfsp->vfc_typenum == 0) continue; if (xvfsp->vfc_flags & VFCF_NONLOCAL) continue; listptr[cnt] = strdup(xvfsp->vfc_name); if (listptr[cnt] == NULL) { printf("malloc failed"); goto done; } cnt++; } #else int mib[3], maxvfsconf; size_t miblen; struct ovfsconf *ptr; mib[0] = CTL_VFS; mib[1] = VFS_GENERIC; mib[2] = VFS_MAXTYPENUM; miblen=sizeof(maxvfsconf); if (sysctl(mib, (unsigned int)(sizeof(mib) / sizeof(mib[0])), &maxvfsconf, &miblen, NULL, 0)) { printf("sysctl failed"); goto done; } if ((listptr = malloc(sizeof(char*) * maxvfsconf)) == NULL) { printf("malloc failed"); goto done; } cnt = 0; while ((ptr = getvfsent()) != NULL && cnt < maxvfsconf) { if (ptr->vfc_flags & VFCF_NONLOCAL) continue; listptr[cnt] = strdup(ptr->vfc_name); if (listptr[cnt] == NULL) { printf("malloc failed"); goto done; } cnt++; } #endif if (cnt == 0) goto done; /* * Count up the string lengths, we need a extra byte to hold * the between entries ',' or the NUL at the end. */ slen = 0; for (i = 0; i < cnt; i++) slen += strlen(listptr[i]); /* for ',' */ slen += cnt - 1; /* Add 3 for initial "no" and the NUL. */ slen += 3; if ((str = malloc(slen)) == NULL) { printf("malloc failed"); goto done; } str[0] = 'n'; str[1] = 'o'; for (i = 0, strptr = str + 2; i < cnt; i++) { if (i > 0) *strptr++ = ','; strcpy(strptr, listptr[i]); strptr += strlen(listptr[i]); } *strptr = '\0'; done: #if __FreeBSD_version > 500000 if (keep_xvfsp != NULL) free(keep_xvfsp); #endif if (listptr != NULL) { for(i = 0; i < cnt && listptr[i] != NULL; i++) free(listptr[i]); free(listptr); } return (str); }
int main(int argc, char *argv[]) { FILE *fp; struct vfstab vfsbuf; char *ptr; int i; int verbose = 0; /* set if -V is specified */ int F_flg = 0; int usgflag = 0; int fs_flag = 0; int arg; /* argument from getopt() */ extern char *optarg; /* getopt specific */ extern int optind; extern int opterr; size_t strlen(); cbasename = ptr = argv[0]; while (*ptr) { if (*ptr++ == '/') cbasename = ptr; } /* * If there are no arguments and command is ncheck then the generic * reads the VFSTAB and executes the specific module of * each entry which has a numeric fsckpass field. */ if (argc == 1) { /* no arguments or options */ if (strcmp(cbasename, "ncheck") == 0) { /* open VFSTAB */ if ((fp = fopen(VFSTAB, "r")) == NULL) { fprintf(stderr, "%s: cannot open vfstab\n", cbasename); exit(2); } while ((i = getvfsent(fp, &vfsbuf)) == 0) { if (numbers(vfsbuf.vfs_fsckpass)) { fstype = vfsbuf.vfs_fstype; newargv[newargc] = vfsbuf.vfs_special; exec_specific(); } } exit(0); } fprintf(stderr, "Usage:\n"); fprintf(stderr, "%s [-F FSType] [-V] [current_options] [-o specific_options] special ...\n", cbasename); exit(2); } for (c_ptr = cmd_data; ((c_ptr->c_basename != NULL) && (strcmp(c_ptr->c_basename, cbasename) != 0)); c_ptr++) ; while ((arg = getopt(argc, argv, c_ptr->c_optstr)) != -1) { switch (arg) { case 'V': /* echo complete command line */ verbose = 1; break; case 'F': /* FSType specified */ F_flg++; fstype = optarg; break; case 'o': /* FSType specific arguments */ newargv[newargc++] = "-o"; newargv[newargc++] = optarg; break; case '?': /* print usage message */ newargv[newargc++] = "-?"; usgflag = 1; break; default: newargv[newargc] = (char *)malloc(3); sprintf(newargv[newargc++], "-%c", arg); if (optarg) newargv[newargc++] = optarg; break; } optarg = NULL; } if (F_flg > 1) { fprintf(stderr, "%s: more than one FSType specified\n", cbasename); usage(cbasename, c_ptr->c_usgstr); } if (F_flg && (strlen(fstype) > (size_t)FSTYPE_MAX)) { fprintf(stderr, "%s: FSType %s exceeds %d characters\n", cbasename, fstype, FSTYPE_MAX); exit(2); } if (optind == argc) { /* all commands except ncheck must exit now */ if (strcmp(cbasename, "ncheck") != 0) { if ((F_flg) && (usgflag)) { exec_specific(); exit(0); } usage(cbasename, c_ptr->c_usgstr); } if ((F_flg) && (usgflag)) { exec_specific(); exit(0); } if (usgflag) usage(cbasename, c_ptr->c_usgstr); /* open VFSTAB */ if ((fp = fopen(VFSTAB, "r")) == NULL) { fprintf(stderr, "%s: cannot open vfstab\n", cbasename); exit(2); } while ((i = getvfsent(fp, &vfsbuf)) == 0) { if (!numbers(vfsbuf.vfs_fsckpass)) continue; if ((F_flg) && (strcmp(fstype, vfsbuf.vfs_fstype) != 0)) continue; fs_flag++; fstype = vfsbuf.vfs_fstype; newargv[newargc] = vfsbuf.vfs_special; if (verbose) { printf("%s -F %s ", cbasename, vfsbuf.vfs_fstype); for (i = 2; newargv[i]; i++) printf("%s\n", newargv[i]); continue; } exec_specific(); } /* * if (! fs_flag) { * if (sysfs(GETFSIND, fstype) == (-1)) { * fprintf(stderr, * "%s: FSType %s not installed in the kernel\n", * cbasename, fstype); * exit(1); * } * } */ exit(0); } /* All other arguments must be specials */ /* perform a lookup if fstype is not specified */ for (; optind < argc; optind++) { newargv[newargc] = argv[optind]; special = newargv[newargc]; if ((F_flg) && (usgflag)) { exec_specific(); exit(0); } if (usgflag) usage(cbasename, c_ptr->c_usgstr); if (fstype == NULL) lookup(); if (verbose) { printf("%s -F %s ", cbasename, fstype); for (i = 2; newargv[i]; i++) printf("%s ", newargv[i]); printf("\n"); continue; } exec_specific(); if (!F_flg) fstype = NULL; } return (0); }
JBoolean JGetUserMountPointList ( JMountPointList* list, JMountState* state ) { time_t t; if (state != NULL && (!(JGetModificationTime(kAvailInfoName, &t)).OK() || t == state->modTime)) { return kJFalse; } list->CleanOut(); if (state != NULL) { state->modTime = t; } FILE* f = fopen(kAvailInfoName, "r"); if (f == NULL) { return kJTrue; // did clear list } const JBoolean isRoot = JI2B( getuid() == 0 ); if (isRoot) { ACE_stat stbuf; vfstab info; while (getvfsent(f, &info) == 0) { if (JIsRootDirectory(info.vfs_mountp) || strcmp(info.vfs_fstype, "swap") == 0) { continue; } const JMountType type = JGetUserMountPointType(info.vfs_mountp, info.vfs_special, info.vfs_fstype); if (type == kJUnknownMountType || ACE_OS::stat(info.vfs_mountp, &stbuf) != 0) { continue; } JFileSystemType fsType = kOtherFSType; if (JStringCompare(info.fs_vfstype, "vfat", kJFalse) == 0) { fsType = kVFATType; } JString* path = jnew JString(info.vfs_mountp); assert( path != NULL ); JString* devicePath = jnew JString(info.vfs_special); assert( devicePath != NULL ); list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType)); } } fclose(f); return kJTrue; }