bool SystemInformation::s_getFileSystem(fs_cont& out) { #if defined(OS_LINUX) FILE* fp(setmntent(_PATH_MOUNTED, "r")); if ( nullptr == fp ) return false; fs_cont tmp; fs_type fs; struct mntent mntbuf; char buf[1024+1]; while ( nullptr not_eq getmntent_r(fp, &mntbuf, buf, sizeof(buf)) ) { if ( not s_getFileSystem(fs, mntbuf.mnt_dir) ) { ::fclose(fp); return false; } tmp.insert(fs_cont::value_type(mntbuf.mnt_dir, fs)); } ::fclose(fp); out.swap(tmp); return true; #elif defined(OS_BSD) || defined(OS_APPLE) auto fstab = getfsent(); if ( nullptr == fstab ) return false; fs_cont tmp; fs_type fs; while ( fstab ) { if ( not s_getFileSystem(fs, fstab->fs_file) ) { endfsent(); return false; } tmp.insert(fs_cont::value_type(fstab->fs_file, fs)); ++fstab; } endfsent(); out.swap(tmp); return true; #endif }
bool GetInfo_Partitions (QListView *lbox) { struct fstab *fstab_ent; if (setfsent() != 1) /* Try to open fstab */ { int s_err = errno; QString s; s = i18n("Could not check filesystem info: "); s += strerror(s_err); (void)new QListViewItem(lbox, 0, s); } else { lbox->addColumn(i18n("Device")); lbox->addColumn(i18n("Mount Point")); lbox->addColumn(i18n("FS Type")); lbox->addColumn(i18n("Mount Options")); while ((fstab_ent=getfsent())!=NULL) { new QListViewItem(lbox, fstab_ent->fs_spec, fstab_ent->fs_file, fstab_ent->fs_vfstype, fstab_ent->fs_mntops); } lbox->setSorting(0); lbox->header()->setClickEnabled(true); endfsent(); /* Close fstab */ } return true; }
void parselabel(void) { char *partname, *partduid; struct fstab *fsent; int i; i = asprintf(&partname, "/dev/%s%c", dkname, 'a'); if (i == -1) err(4, NULL); i = asprintf(&partduid, "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.a", lab.d_uid[0], lab.d_uid[1], lab.d_uid[2], lab.d_uid[3], lab.d_uid[4], lab.d_uid[5], lab.d_uid[6], lab.d_uid[7]); if (i == -1) err(4, NULL); setfsent(); for (i = 0; i < MAXPARTITIONS; i++) { partname[strlen(dkname) + 5] = 'a' + i; partduid[strlen(partduid) - 1] = 'a' + i; fsent = getfsspec(partname); if (fsent == NULL) fsent = getfsspec(partduid); if (fsent) mountpoints[i] = strdup(fsent->fs_file); } endfsent(); free(partduid); free(partname); if (aflag) editor_allocspace(&lab); }
GPtrArray * disks_new(gboolean include_NFSs) { GPtrArray * pdisks ; t_disk * pdisk ; struct fstab * pfstab ; // open fstab if (setfsent() != 1) return NULL ; // on error return NULL pdisks = g_ptr_array_new(); for(;;) { pfstab = getfsent() ; //read a line in fstab if (pfstab == NULL) break ; // on eof exit // if pfstab->fs_spec do not begins with /dev discard //if pfstab->fs_file == none discard if ( g_str_has_prefix(pfstab->fs_spec,"/dev/") && (g_str_has_prefix(pfstab->fs_file,"/") != 0) ) { pdisk = disk_new(pfstab->fs_spec, pfstab->fs_file); g_ptr_array_add( pdisks , pdisk ); } } endfsent(); //closes file return pdisks ; }
int VAttachPartitions(void) { int errors = 0; struct fstab *fsent; if (setfsent() < 0) { Log("Error listing filesystems.\n"); exit(-1); } while ((fsent = getfsent())) { if (strcmp(fsent->fs_type, "rw") != 0) continue; /* If we're going to always attach this partition, do it later. */ if (VIsAlwaysAttach(fsent->fs_file)) continue; if (VCheckPartition(fsent->fs_file, fsent->fs_spec) < 0) errors++; } endfsent(); /* Process the always-attach partitions, if any. */ VAttachPartitions2(); return errors; }
static void read_table(void) { int tab; struct fstab *ent; MountPoint *mp; clear_table(); tab = setfsent(); g_return_if_fail(tab != 0); while ((ent = getfsent())) { if (strcmp(ent->fs_vfstype, "swap") == 0) continue; if (strcmp(ent->fs_vfstype, "kernfs") == 0) continue; mp = g_malloc(sizeof(MountPoint)); mp->name = g_strdup(ent->fs_spec); /* block special device name */ mp->dir = g_strdup(ent->fs_file); /* file system path prefix */ g_hash_table_insert(fstab_mounts, mp->dir, mp); } endfsent(); }
/* * Collect the requested quota information. */ static struct quotause * getprivs(long id, int quotatype) { struct quotause *qup, *quptail = NULL; struct fstab *fs; struct quotause *quphead; struct statfs *fst; int nfst, i; qup = quphead = NULL; nfst = getmntinfo(&fst, MNT_NOWAIT); if (nfst == 0) errx(2, "no filesystems mounted!"); setfsent(); for (i=0; i<nfst; i++) { if (qup == NULL) { if ((qup = (struct quotause *)malloc(sizeof *qup)) == NULL) errx(2, "out of memory"); } if (strcmp(fst[i].f_fstypename, "nfs") == 0) { if (lflag) continue; if (getnfsquota(&fst[i], qup, id, quotatype) == 0) continue; } else if (strcmp(fst[i].f_fstypename, "ufs") == 0) { /* * XXX * UFS filesystems must be in /etc/fstab, and must * indicate that they have quotas on (?!) This is quite * unlike SunOS where quotas can be enabled/disabled * on a filesystem independent of /etc/fstab, and it * will still print quotas for them. */ if ((fs = getfsspec(fst[i].f_mntfromname)) == NULL) continue; if (getufsquota(fs, qup, id, quotatype) == 0) continue; } else continue; strcpy(qup->fsname, fst[i].f_mntonname); if (quphead == NULL) quphead = qup; else quptail->next = qup; quptail = qup; quptail->next = 0; qup = NULL; } if (qup) free(qup); endfsent(); return (quphead); }
bool GetInfo_Partitions ( QListView *lbox ) { #define NUMCOLS 5 QString Title[NUMCOLS]; int n; struct fstab *fstab_ent; struct statvfs svfs; long total,avail; QString str; QString MB(i18n("MB")+ " "); // International Text for MB=Mega-Byte if (setfsent() != 1) // Try to open fstab return false; Title[0] = i18n("Device"); Title[1] = i18n("Mount Point"); Title[2] = i18n("FS Type"); Title[3] = i18n("Total Size"); Title[4] = i18n("Free Size"); for (n=0; n<NUMCOLS; ++n) { lbox->addColumn(Title[n] ); } while ((fstab_ent=getfsent())!=NULL) { /* fstab_ent->fs_type holds only "rw","xx","ro"... */ memset(&svfs,0,sizeof(svfs)); statvfs(fstab_ent->fs_file,&svfs); get_fs_usage(fstab_ent->fs_file, &total, &avail); if (!strcmp(fstab_ent->fs_type,FSTAB_XX)) // valid drive ? svfs.f_basetype[0] = 0; if(svfs.f_basetype[0]) { new QListViewItem(lbox, QString(fstab_ent->fs_spec), QString(fstab_ent->fs_file) + QString(" "), (svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a")), Value((total+512)/1024,6) + MB, Value((avail+512)/1024,6) + MB); } else { new QListViewItem(lbox, QString(fstab_ent->fs_spec), QString(fstab_ent->fs_file) + QString(" "), (svfs.f_basetype[0] ? QString(svfs.f_basetype) : i18n("n/a"))); } } endfsent(); return true; }
void DAMountMapListRefresh1( void ) { struct stat status; /* * Determine whether the mount map list is up-to-date. */ if ( stat( _PATH_FSTAB, &status ) ) { __gDAMountMapListTime1.tv_sec = 0; __gDAMountMapListTime1.tv_nsec = 0; } if ( __gDAMountMapListTime1.tv_sec != status.st_mtimespec.tv_sec || __gDAMountMapListTime1.tv_nsec != status.st_mtimespec.tv_nsec ) { __gDAMountMapListTime1.tv_sec = status.st_mtimespec.tv_sec; __gDAMountMapListTime1.tv_nsec = status.st_mtimespec.tv_nsec; /* * Clear the mount map list. */ CFArrayRemoveAllValues( gDAMountMapList1 ); /* * Build the mount map list. */ if ( setfsent( ) ) { struct fstab * item; while ( ( item = getfsent( ) ) ) { CFDictionaryRef map; map = __DAMountMapCreate1( kCFAllocatorDefault, item ); if ( map ) { CFArrayAppendValue( gDAMountMapList1, map ); CFRelease( map ); } } endfsent( ); } } }
static struct fstab * lu_getfsfile(const char *name) { struct fstab *fs; if (name == NULL) return (struct fstab *)NULL; setfsent(); for (fs = lu_getfsent(); fs != NULL; fs = lu_getfsent()) if (!strcmp(fs->fs_file, name)) return fs; endfsent(); return (struct fstab *)NULL; }
static struct vfstab* getfsspec (const char *special_file) { int r; int close = 0; if (etc_fstab == 0) { close = 1; if (setfsent () != 1) return NULL; } rewind (etc_fstab); r = getvfsspec (etc_fstab, &cur_vfstab_entry, (char*) special_file); if (close) endfsent (); if (r == 0) return &cur_vfstab_entry; return NULL; }
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 listfstab(void) { fscounter = 0; setfsent(); // Set use of Fstab while(( fs = getfsent())) { (void)mvwprintw(fslistbox, fscounter, 2, "%s", fs->fs_spec); // Filesystem node (Devices) (void)mvwprintw(fslistbox, fscounter, 26, "%s", fs->fs_file); // Mount Point (void)mvwprintw(fslistbox, fscounter, 46 , "%s", fs->fs_vfstype); // Filesystem Type (void)mvwprintw(fslistbox, fscounter, 60, "%s", fs->fs_mntops); // Mount Opts wmove(fslistbox, fscounter++, 3); // Increment downline after each line. } endfsent(); // end use of Fstab wrefresh(fslistbox); return 0; }
/* * Collect the requested quota information. */ struct quotause * getprivs(long id, int quotatype, char *fspath) { struct quotafile *qf; struct fstab *fs; struct quotause *qup, *quptail; struct quotause *quphead; setfsent(); quphead = quptail = NULL; while ((fs = getfsent())) { if (fspath && *fspath && strcmp(fspath, fs->fs_spec) && strcmp(fspath, fs->fs_file)) continue; if (strcmp(fs->fs_vfstype, "ufs")) continue; if ((qf = quota_open(fs, quotatype, O_CREAT|O_RDWR)) == NULL) { if (errno != EOPNOTSUPP) warn("cannot open quotas on %s", fs->fs_file); continue; } if ((qup = (struct quotause *)calloc(1, sizeof(*qup))) == NULL) errx(2, "out of memory"); qup->qf = qf; strncpy(qup->fsname, fs->fs_file, sizeof(qup->fsname)); if (quota_read(qf, &qup->dqblk, id) == -1) { warn("cannot read quotas on %s", fs->fs_file); freeprivs(qup); continue; } if (quphead == NULL) quphead = qup; else quptail->next = qup; quptail = qup; qup->next = 0; } if (quphead == NULL) { warnx("No quotas on %s", fspath ? fspath : "any filesystems"); } endfsent(); return (quphead); }
/* * Check all filesystems in /etc/fstab with a fs_passno > 0 */ static int fsck(int pass) { // int save; struct fstab *fs; if (!setfsent()) { _pe("Failed opening fstab"); return 1; } // if ((save = log_is_debug())) // log_debug(); while ((fs = getfsent())) { char cmd[80]; struct stat st; if (fs->fs_passno != pass) continue; errno = 0; if (stat(fs->fs_spec, &st) || !S_ISBLK(st.st_mode)) { if (!string_match(fs->fs_spec, "UUID=") && !string_match(fs->fs_spec, "LABEL=")) { _d("Cannot fsck %s, not a block device: %s", fs->fs_spec, strerror(errno)); continue; } } if (fismnt(fs->fs_file)) { _d("Skipping fsck of %s, already mounted on %s.", fs->fs_spec, fs->fs_file); continue; } snprintf(cmd, sizeof(cmd), "fsck -a %s", fs->fs_spec); run_interactive(cmd, "Checking filesystem %.13s", fs->fs_spec); } // if (save) // log_debug(); endfsent(); return 0; }
/* * Fetch requested disklabel into 'lab' using ioctl. */ void readlabel(int f) { char *partname, *partduid; struct fstab *fsent; int i; if (cflag && ioctl(f, DIOCRLDINFO) < 0) err(4, "ioctl DIOCRLDINFO"); if ((op == RESTORE) || dflag || aflag) { if (ioctl(f, DIOCGPDINFO, &lab) < 0) err(4, "ioctl DIOCGPDINFO"); } else { if (ioctl(f, DIOCGDINFO, &lab) < 0) err(4, "ioctl DIOCGDINFO"); } asprintf(&partname, "/dev/%s%c", dkname, 'a'); asprintf(&partduid, "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx.a", lab.d_uid[0], lab.d_uid[1], lab.d_uid[2], lab.d_uid[3], lab.d_uid[4], lab.d_uid[5], lab.d_uid[6], lab.d_uid[7]); setfsent(); for (i = 0; i < MAXPARTITIONS; i++) { partname[strlen(dkname) + 5] = 'a' + i; partduid[strlen(partduid) - 1] = 'a' + i; fsent = getfsspec(partname); if (fsent == NULL) fsent = getfsspec(partduid); if (fsent) mountpoints[i] = strdup(fsent->fs_file); } endfsent(); free(partduid); free(partname); if (aflag) editor_allocspace(&lab); }
LISP lendfsent(void) {long iflag; iflag = no_interrupt(1); endfsent(); no_interrupt(iflag); return(NIL);}
int main(int argc, char *argv[]) { struct fstab *fs; struct passwd *pw; struct group *gr; struct quotaname *auxdata; int i, argnum, maxrun, errs, ch; u_int64_t done = 0; /* XXX supports maximum 64 filesystems */ char *name; errs = maxrun = 0; while ((ch = getopt(argc, argv, "adguvl:")) != -1) { switch(ch) { case 'a': flags |= CHECK_PREEN; break; case 'd': flags |= CHECK_DEBUG; break; case 'g': gflag++; break; case 'l': maxrun = atoi(optarg); break; case 'u': uflag++; break; case 'v': flags |= CHECK_VERBOSE; break; default: usage(); } } argc -= optind; argv += optind; if ((argc == 0 && !(flags&CHECK_PREEN)) || (argc > 0 && (flags&CHECK_PREEN))) usage(); if (!gflag && !uflag) { gflag++; uflag++; } if (gflag) { setgrent(); while ((gr = getgrent()) != 0) (void) addid(gr->gr_gid, GRPQUOTA, gr->gr_name); endgrent(); } if (uflag) { setpwent(); while ((pw = getpwent()) != 0) (void) addid(pw->pw_uid, USRQUOTA, pw->pw_name); endpwent(); } if (flags&CHECK_PREEN) exit(checkfstab(flags, maxrun, needchk, chkquota)); if (setfsent() == 0) err(1, "%s: can't open", FSTAB); while ((fs = getfsent()) != NULL) { if (((argnum = oneof(fs->fs_file, argv, argc)) >= 0 || (argnum = oneof(fs->fs_spec, argv, argc)) >= 0) && (auxdata = needchk(fs)) && (name = blockcheck(fs->fs_spec))) { done |= 1 << argnum; errs += chkquota(fs->fs_vfstype, name, fs->fs_file, auxdata, NULL); } } endfsent(); for (i = 0; i < argc; i++) if ((done & (1 << i)) == 0) fprintf(stderr, "%s not found in %s\n", argv[i], FSTAB); exit(errs); }
int main(int argc, char *argv[]) { struct fstab *fs; struct passwd *pw; struct group *gr; struct quotafile *qfu, *qfg; int i, argnum, maxrun, errs, ch; long done = 0; char *name; errs = maxrun = 0; while ((ch = getopt(argc, argv, "ac:guvl:")) != -1) { switch(ch) { case 'a': aflag++; break; case 'c': if (cflag) usage(); cflag = atoi(optarg); break; case 'g': gflag++; break; case 'u': uflag++; break; case 'v': vflag++; break; case 'l': maxrun = atoi(optarg); break; default: usage(); } } argc -= optind; argv += optind; if ((argc == 0 && !aflag) || (argc > 0 && aflag)) usage(); if (cflag && cflag != 32 && cflag != 64) usage(); if (!gflag && !uflag) { gflag++; uflag++; } if (gflag) { setgrent(); while ((gr = getgrent()) != NULL) (void) addid((u_long)gr->gr_gid, GRPQUOTA, gr->gr_name, NULL); endgrent(); } if (uflag) { setpwent(); while ((pw = getpwent()) != NULL) (void) addid((u_long)pw->pw_uid, USRQUOTA, pw->pw_name, NULL); endpwent(); } /* * The maxrun (-l) option is now deprecated. */ if (maxrun > 0) warnx("the -l option is now deprecated"); if (aflag) exit(checkfstab(uflag, gflag)); if (setfsent() == 0) errx(1, "%s: can't open", FSTAB); while ((fs = getfsent()) != NULL) { if (((argnum = oneof(fs->fs_file, argv, argc)) >= 0 || (argnum = oneof(fs->fs_spec, argv, argc)) >= 0) && (name = blockcheck(fs->fs_spec))) { done |= 1 << argnum; qfu = NULL; if (uflag) qfu = quota_open(fs, USRQUOTA, O_CREAT|O_RDWR); qfg = NULL; if (gflag) qfg = quota_open(fs, GRPQUOTA, O_CREAT|O_RDWR); if (qfu == NULL && qfg == NULL) continue; errs += chkquota(name, qfu, qfg); if (qfu) quota_close(qfu); if (qfg) quota_close(qfg); } } endfsent(); for (i = 0; i < argc; i++) if ((done & (1 << i)) == 0) fprintf(stderr, "%s not found in %s\n", argv[i], FSTAB); exit(errs); }
int main(int argc, char **argv) { struct fstab *fs; struct passwd *pw; struct group *gr; struct quotaname *auxdata; int i, argnum, maxrun, errs; long done = 0; char ch, *name; errs = maxrun = 0; while ((ch = getopt(argc, argv, "aguvl:")) != -1) { switch(ch) { case 'a': aflag++; break; case 'g': gflag++; break; case 'u': uflag++; break; case 'v': vflag++; break; case 'l': maxrun = atoi(optarg); break; default: usage(); } } argc -= optind; argv += optind; if ((argc == 0 && !aflag) || (argc > 0 && aflag)) usage(); if (!gflag && !uflag) { gflag++; uflag++; } if (gflag) { setgrent(); while ((gr = getgrent()) != NULL) addid((u_long)gr->gr_gid, GRPQUOTA, gr->gr_name); endgrent(); } if (uflag) { setpwent(); while ((pw = getpwent()) != NULL) addid((u_long)pw->pw_uid, USRQUOTA, pw->pw_name); endpwent(); } if (aflag) exit(checkfstab(1, maxrun, needchk, chkquota)); if (setfsent() == 0) errx(1, "%s: can't open", FSTAB); while ((fs = getfsent()) != NULL) { if (((argnum = oneof(fs->fs_file, argv, argc)) >= 0 || (argnum = oneof(fs->fs_spec, argv, argc)) >= 0) && (auxdata = needchk(fs)) && (name = blockcheck(fs->fs_spec))) { done |= 1 << argnum; errs += chkquota(name, fs->fs_file, auxdata); } } endfsent(); for (i = 0; i < argc; i++) if ((done & (1 << i)) == 0) fprintf(stderr, "%s not found in %s\n", argv[i], FSTAB); exit(errs); }
static int CheckNonmounts() { #ifdef _THREAD_SAFE AFILE_t fsFile = NULL; int passNo = 0; int ret; struct fstab entry; struct stat stbuf; ret = setfsent_r( &fsFile, &passNo ); if ( ret != 0 ) return -1; do { ret = getfsent_r ( &entry, &fsFile, &passNo ); if ( ret == 0 ) { char* l = strrchr(entry.fs_spec,'/'); if ( l != NULL ) { if ( !strncmp("cd",++l,2) ) { #ifdef DEBUG_CDROM fprintf(stderr, "Found unmounted CD ROM drive with device name %s\n", entry.fs_spec); #endif if ( CheckDrive( entry.fs_spec, &stbuf) > 0) { AddDrive( entry.fs_spec, &stbuf); } } } } } while ( ret == 0 ); ret = endfsent_r ( &fsFile ); if ( ret != 0 ) return -1; return 0; #else struct fstab* entry; struct stat stbuf; setfsent(); do { entry = getfsent(); if ( entry != NULL ) { char* l = strrchr(entry->fs_spec,'/'); if ( l != NULL ) { if ( !strncmp("cd",++l,2) ) { #ifdef DEBUG_CDROM fprintf(stderr,"Found unmounted CD ROM drive with device name %s", entry->fs_spec); #endif if ( CheckDrive( entry->fs_spec, &stbuf) > 0) { AddDrive( entry->fs_spec, &stbuf); } } } } } while ( entry != NULL ); endfsent(); #endif }
/* * Collect the requested quota information. */ struct quotause * getprivs(long id, int quotatype, char *fspath) { struct fstab *fs; struct quotause *qup, *quptail; struct quotause *quphead; int qcmd, qupsize, fd; char *qfpathname; static int warned = 0; setfsent(); quphead = quptail = NULL; qcmd = QCMD(Q_GETQUOTA, quotatype); while ((fs = getfsent())) { if (fspath && *fspath && strcmp(fspath, fs->fs_spec) && strcmp(fspath, fs->fs_file)) continue; if (strcmp(fs->fs_vfstype, "ufs")) continue; if (!hasquota(fs, quotatype, &qfpathname)) continue; qupsize = sizeof(*qup) + strlen(qfpathname); if ((qup = (struct quotause *)malloc(qupsize)) == NULL) errx(2, "out of memory"); if (quotactl(fs->fs_file, qcmd, id, &qup->dqblk) != 0) { if (errno == EOPNOTSUPP && !warned) { warned++; warnx("warning: quotas are not compiled into this kernel"); sleep(3); } if ((fd = open(qfpathname, O_RDONLY)) < 0) { fd = open(qfpathname, O_RDWR|O_CREAT, 0640); if (fd < 0 && errno != ENOENT) { warn("%s", qfpathname); free(qup); continue; } warnx("creating quota file %s", qfpathname); sleep(3); fchown(fd, getuid(), getentry(quotagroup, GRPQUOTA)); fchmod(fd, 0640); } lseek(fd, (long)(id * sizeof(struct ufs_dqblk)), L_SET); switch (read(fd, &qup->dqblk, sizeof(struct ufs_dqblk))) { case 0: /* EOF */ /* * Convert implicit 0 quota (EOF) * into an explicit one (zero'ed dqblk) */ bzero((caddr_t)&qup->dqblk, sizeof(struct ufs_dqblk)); break; case sizeof(struct ufs_dqblk): /* OK */ break; default: /* ERROR */ warn("read error in %s", qfpathname); close(fd); free(qup); continue; } close(fd); } strcpy(qup->qfname, qfpathname); strcpy(qup->fsname, fs->fs_file); if (quphead == NULL) quphead = qup; else quptail->next = qup; quptail = qup; qup->next = NULL; } endfsent(); return (quphead); }
int main(int argc, char **argv) { struct fstab *fs; const char *whoami; long argnum, done = 0; int ch, i, offmode = 0, errs = 0; whoami = getprogname(); if (strcmp(whoami, "quotaoff") == 0) offmode++; else if (strcmp(whoami, "quotaon") != 0) errx(1, "name must be quotaon or quotaoff"); while ((ch = getopt(argc, argv, "avug")) != -1) { switch(ch) { case 'a': aflag++; break; case 'g': gflag++; break; case 'u': uflag++; break; case 'v': vflag++; break; default: usage(); } } argc -= optind; argv += optind; if (argc <= 0 && !aflag) usage(); if (!gflag && !uflag) { gflag++; uflag++; } setfsent(); while ((fs = getfsent()) != NULL) { if (strcmp(fs->fs_vfstype, "ufs") || strcmp(fs->fs_type, FSTAB_RW)) continue; if (aflag) { if (gflag) errs += quotaonoff(fs, offmode, GRPQUOTA); if (uflag) errs += quotaonoff(fs, offmode, USRQUOTA); continue; } if ((argnum = oneof(fs->fs_file, argv, argc)) >= 0 || (argnum = oneof(fs->fs_spec, argv, argc)) >= 0) { done |= 1 << argnum; if (gflag) errs += quotaonoff(fs, offmode, GRPQUOTA); if (uflag) errs += quotaonoff(fs, offmode, USRQUOTA); } } endfsent(); for (i = 0; i < argc; i++) if ((done & (1 << i)) == 0) warnx("%s not found in fstab", argv[i]); exit(errs); }
int main(int argc, char **argv) { struct fstab *fs; struct passwd *pw; struct group *gr; int gflag = 0, uflag = 0, errs = 0; long i, argnum, done = 0; char ch, *qfnp; while ((ch = getopt(argc, argv, "aguv")) != -1) { switch(ch) { case 'a': aflag++; break; case 'g': gflag++; break; case 'u': uflag++; break; case 'v': vflag++; break; default: usage(); } } argc -= optind; argv += optind; if (argc == 0 && !aflag) usage(); if (!gflag && !uflag) { if (aflag) gflag++; uflag++; } if (gflag) { setgrent(); while ((gr = getgrent()) != 0) addid((u_long)gr->gr_gid, GRPQUOTA, gr->gr_name); endgrent(); } if (uflag) { setpwent(); while ((pw = getpwent()) != 0) addid((u_long)pw->pw_uid, USRQUOTA, pw->pw_name); endpwent(); } setfsent(); while ((fs = getfsent()) != NULL) { if (strcmp(fs->fs_vfstype, "ufs")) continue; if (aflag) { if (gflag && hasquota(fs, GRPQUOTA, &qfnp)) errs += repquota(fs, GRPQUOTA, qfnp); if (uflag && hasquota(fs, USRQUOTA, &qfnp)) errs += repquota(fs, USRQUOTA, qfnp); continue; } if ((argnum = oneof(fs->fs_file, argv, argc)) >= 0 || (argnum = oneof(fs->fs_spec, argv, argc)) >= 0) { done |= 1 << argnum; if (gflag && hasquota(fs, GRPQUOTA, &qfnp)) errs += repquota(fs, GRPQUOTA, qfnp); if (uflag && hasquota(fs, USRQUOTA, &qfnp)) errs += repquota(fs, USRQUOTA, qfnp); } } endfsent(); for (i = 0; i < argc; i++) if ((done & (1 << i)) == 0) warnx("%s not found in fstab", argv[i]); exit(errs); }
/* Function to detect the MB of diskspace on a path */ int detect_diskspace(const char *path) { long long avail = 0LL; if ( path[0] == '/' ) { #ifdef HAVE_SYS_STATVFS_H struct statvfs fs; #else struct statfs fs; #endif char buf[PATH_MAX], *cp; strcpy(buf, path); cp = buf+strlen(buf); while ( buf[0] && (access(buf, F_OK) < 0) ) { while ( (cp > (buf+1)) && (*cp != '/') ) { --cp; } *cp = '\0'; } if ( buf[0] ) { #ifdef HAVE_SYS_STATVFS_H if ( statvfs(buf, &fs) ) { #else if ( statfs(buf, &fs) ) { #endif perror("statfs"); return 0; } avail = fs.f_bsize; avail *= fs.f_bavail; } } return avail / (1024*1024LL); } int detect_and_mount_cdrom(char *path[SETUP_MAX_DRIVES]) { int num_cdroms = 0; #ifdef __FreeBSD__ int mounted; struct fstab *fstab; /* Try to mount unmounted CDROM filesystems */ while( (fstab = getfsent()) != NULL ){ if ( !strcmp(fstab->fs_vfstype, MNTTYPE_CDROM)) { if ( !is_fs_mounted(fstab->fs_spec)) { if ( ! run_command(NULL, MOUNT_PATH, fstab->fs_spec, 1) ) { add_mounted_entry(fstab->fs_spec, fstab->fs_file); log_normal(_("Mounted device %s"), fstab->fs_spec); } } } } endfsent(); mounted = getfsstat(NULL, 0, MNT_WAIT); if ( mounted > 0 ) { int i; struct statfs *mnts = (struct statfs *)malloc(sizeof(struct statfs) * mounted); mounted = getfsstat(mnts, mounted * sizeof(struct statfs), MNT_WAIT); for ( i = 0; i < mounted && num_cdroms < SETUP_MAX_DRIVES; ++ i ) { if ( ! strcmp(mnts[i].f_fstypename, MNTTYPE_CDROM) ) { path[num_cdroms ++] = strdup(mnts[i].f_mntonname); } } free(mnts); } #elif defined(darwin) { const char *devPrefix = "/dev/"; int prefixLen = strlen(devPrefix); mach_port_t masterPort = 0; struct statfs *mntbufp; int i, mounts; if (IOMasterPort(MACH_PORT_NULL, &masterPort) == KERN_SUCCESS) { mounts = getmntinfo(&mntbufp, MNT_WAIT); /* NOT THREAD SAFE! */ for (i = 0; i < mounts && num_cdroms < SETUP_MAX_DRIVES; i++) { char *dev = mntbufp[i].f_mntfromname; char *mnt = mntbufp[i].f_mntonname; if (strncmp(dev, devPrefix, prefixLen) != 0) /* virtual device? */ continue; /* darwinIsMountedDisc needs to skip "/dev/" part of string... */ if (darwinIsMountedDisc(dev + prefixLen, masterPort)) { strcpy(darwinEjectThisCDDevice, dev + prefixLen); path[num_cdroms ++] = strdup(mnt); } } } } #elif defined(sco) /* Quite horrible. We have to parse mount's output :( */ /* And of course, we can't try to mount unmounted filesystems */ FILE *cmd = popen("/etc/mount", "r"); if ( cmd ) { char device[32] = "", mountp[PATH_MAX] = ""; while ( fscanf(cmd, "%s on %32s %*[^\n]", mountp, device) > 0 ) { if ( !strncmp(device, "/dev/cd", 7) ) { path[num_cdroms ++] = strdup(mountp); break; } } pclose(cmd); } #elif defined(hpux) char mntdevpath[PATH_MAX]; FILE *mountfp; struct mntent *mntent; const char *fstab, *mtab, *mount_cmd, *mnttype; /* HPUX: We need to support PFS */ if ( !access("/etc/pfs_fstab", F_OK) ) { fstab = "/etc/pfs_fstab"; mtab = "/etc/pfs_mtab"; mount_cmd = "/usr/sbin/pfs_mount"; mnttype = "pfs-rrip"; } else { fstab = SETUP_FSTAB; mtab = MOUNTS_FILE; mnttype = MNTTYPE_CDROM; mount_cmd = MOUNT_PATH; } /* Try to mount unmounted CDROM filesystems */ mountfp = setmntent( fstab, "r" ); if( mountfp != NULL ) { while( (mntent = getmntent( mountfp )) != NULL ){ if ( !strcmp(mntent->mnt_type, mnttype) ) { char *fsname = strdup(mntent->mnt_fsname); char *dir = strdup(mntent->mnt_dir); if ( !is_fs_mounted(fsname)) { if ( ! run_command(NULL, mount_cmd, fsname, 1) ) { add_mounted_entry(fsname, dir); log_normal(_("Mounted device %s"), fsname); } } free(fsname); free(dir); } } endmntent(mountfp); } mountfp = setmntent(mtab, "r" ); if( mountfp != NULL ) { while( (mntent = getmntent( mountfp )) != NULL && num_cdroms < SETUP_MAX_DRIVES){ char mntdev[1024], mnt_type[32]; strcpy(mntdev, mntent->mnt_fsname); strcpy(mnt_type, mntent->mnt_type); if( strncmp(mntdev, "/dev", 4) || realpath(mntdev, mntdevpath) == NULL ) { continue; } if ( strcmp(mnt_type, mnttype) == 0 ) { path[num_cdroms ++] = strdup(mntent->mnt_dir); } } endmntent( mountfp ); } #elif defined(__svr4__) struct mnttab mnt; FILE *fstab = fopen(SETUP_FSTAB, "r"); if ( fstab != NULL ) { while ( getmntent(fstab, &mnt)==0 ) { if ( !strcmp(mnt.mnt_fstype, MNTTYPE_CDROM) ) { char *fsname = strdup(mnt.mnt_special); char *dir = strdup(mnt.mnt_mountp); if ( !is_fs_mounted(fsname)) { if ( ! run_command(NULL, MOUNT_PATH, fsname, 1) ) { add_mounted_entry(fsname, dir); log_normal(_("Mounted device %s"), fsname); } } free(fsname); free(dir); break; } } fclose(fstab); fstab = fopen(MOUNTS_FILE, "r"); if (fstab) { while ( getmntent(fstab, &mnt)==0 && num_cdroms < SETUP_MAX_DRIVES) { if ( !strcmp(mnt.mnt_fstype, MNTTYPE_CDROM) ) { path[num_cdroms ++] = strdup(mnt.mnt_mountp); } } fclose(fstab); } } #else //#ifndef darwin char mntdevpath[PATH_MAX]; FILE *mountfp; struct mntent *mntent; /* Try to mount unmounted CDROM filesystems */ mountfp = setmntent( SETUP_FSTAB, "r" ); if( mountfp != NULL ) { while( (mntent = getmntent( mountfp )) != NULL ){ if ( (!strcmp(mntent->mnt_type, MNTTYPE_CDROM) #ifdef sgi || !strcmp(mntent->mnt_type, "cdfs") || !strcmp(mntent->mnt_type, "efs") #endif || !strcmp(mntent->mnt_type, "auto")) && strncmp(mntent->mnt_fsname, DEVICE_FLOPPY, strlen(DEVICE_FLOPPY)) ) { char *fsname = strdup(mntent->mnt_fsname); char *dir = strdup(mntent->mnt_dir); if ( !is_fs_mounted(fsname)) { if ( ! run_command(NULL, MOUNT_PATH, fsname, 1) ) { add_mounted_entry(fsname, dir); log_normal(_("Mounted device %s"), fsname); } } free(fsname); free(dir); } } endmntent(mountfp); } mountfp = setmntent(MOUNTS_FILE, "r" ); if( mountfp != NULL ) { while( (mntent = getmntent( mountfp )) != NULL && num_cdroms < SETUP_MAX_DRIVES){ char *tmp, mntdev[1024], mnt_type[32]; if ( strncmp(mntent->mnt_fsname, DEVICE_FLOPPY, strlen(DEVICE_FLOPPY)) == 0) continue; strcpy(mntdev, mntent->mnt_fsname); strcpy(mnt_type, mntent->mnt_type); if ( strcmp(mnt_type, MNTTYPE_SUPER) == 0 ) { tmp = strstr(mntent->mnt_opts, "fs="); if ( tmp ) { strcpy(mnt_type, tmp+strlen("fs=")); tmp = strchr(mnt_type, ','); if ( tmp ) { *tmp = '\0'; } } tmp = strstr(mntent->mnt_opts, "dev="); if ( tmp ) { strcpy(mntdev, tmp+strlen("dev=")); tmp = strchr(mntdev, ','); if ( tmp ) { *tmp = '\0'; } } } if( strncmp(mntdev, "/dev", 4) || realpath(mntdev, mntdevpath) == NULL ) { continue; } if ( strcmp(mnt_type, MNTTYPE_CDROM) == 0 ) { path[num_cdroms ++] = strdup(mntent->mnt_dir); } else if ( strcmp(mnt_type, "auto") == 0 && strncmp(mntdev, DEVICE_FLOPPY, strlen(DEVICE_FLOPPY))) { path[num_cdroms ++] = strdup(mntent->mnt_dir); } #ifdef sgi else if ( strcmp(mnt_type, "cdfs") == 0 || strcmp(mnt_type, "efs") == 0 ) { path[num_cdroms ++] = strdup(mntent->mnt_dir); } #endif } endmntent( mountfp ); } //#endif #endif return num_cdroms; }
int main(int argc, char *argv[]) { long timeout_val; int c; int flushcache = 0; int unmount_automounted = 0; // Unmount automounted mounts struct autodir *dir, *d; char real_mntpnt[PATH_MAX]; struct stat stbuf; char *master_map = "auto_master"; int null; struct statfs *mntp; int count = 0; char *stack[STACKSIZ]; char **stkptr; char *defval; int fd; int flags, altflags; struct staticmap *static_ent; /* * Read in the values from config file first before we check * commandline options so the options override the file. */ if ((defopen(AUTOFSADMIN)) == 0) { if ((defval = defread("AUTOMOUNT_TIMEOUT=")) != NULL) { errno = 0; timeout_val = strtol(defval, (char **)NULL, 10); if (errno == 0 && timeout_val > 0 && timeout_val <= INT_MAX) mount_timeout = (int)timeout_val; } if ((defval = defread("AUTOMOUNT_VERBOSE=")) != NULL) { if (strncasecmp("true", defval, 4) == 0) verbose = TRUE; else verbose = FALSE; } if ((defval = defread("AUTOMOUNTD_TRACE=")) != NULL) { /* * Turn on tracing here too if the automountd * is set up to do it - since automount calls * many of the common library functions. */ errno = 0; trace = (int)strtol(defval, (char **)NULL, 10); if (errno != 0) trace = 0; } /* close defaults file */ defopen(NULL); } while ((c = getopt(argc, argv, "mM:D:f:t:vcu?")) != EOF) { switch (c) { case 'm': pr_msg("Warning: -m option not supported"); break; case 'M': pr_msg("Warning: -M option not supported"); break; case 'D': pr_msg("Warning: -D option not supported"); break; case 'f': pr_msg("Error: -f option no longer supported"); usage(); break; case 't': if (strchr(optarg, '=')) { pr_msg("Error: invalid value for -t"); usage(); } mount_timeout = atoi(optarg); break; case 'v': verbose++; break; case 'c': flushcache++; break; case 'u': unmount_automounted++; break; default: usage(); break; } } if (optind < argc) { pr_msg("%s: command line mountpoints/maps " "no longer supported", argv[optind]); usage(); } /* * Get an array of current system mounts */ num_current_mounts = getmntinfo(¤t_mounts, MNT_NOWAIT); if (num_current_mounts == 0) { pr_msg("Couldn't get current mounts: %m"); exit(1); } autofs_control_fd = open("/dev/" AUTOFS_CONTROL_DEVICE, O_RDONLY); if (autofs_control_fd == -1 && errno == ENOENT) { /* * Oops, we probably don't have the autofs kext * loaded. */ FTS *fts; static char *const paths[] = { "/Network", NULL }; FTSENT *ftsent; int error; /* * This means there can't be any autofs mounts yet, so * this is the first time we're being run since a reboot. * Clean out any stuff left in /Network from the reboot. */ fts = fts_open(paths, FTS_NOCHDIR|FTS_PHYSICAL|FTS_XDEV, NULL); if (fts != NULL) { while ((ftsent = fts_read(fts)) != NULL) { /* * We only remove directories - if * there are files, we assume they're * there for a purpose. * * We remove directories after we've * removed their children, so we want * to process directories visited in * post-order. * * We don't remove /Network itself. */ if (ftsent->fts_info == FTS_DP && ftsent->fts_level > FTS_ROOTLEVEL) rmdir(ftsent->fts_accpath); } fts_close(fts); } /* * Now load it. */ error = load_autofs(); if (error != 0) { pr_msg("can't load autofs kext"); exit(1); } /* * Try the open again. */ autofs_control_fd = open("/dev/" AUTOFS_CONTROL_DEVICE, O_RDONLY); } if (autofs_control_fd == -1) { if (errno == EBUSY) pr_msg("Another automount is running"); else pr_msg("Couldn't open %s: %m", "/dev/" AUTOFS_CONTROL_DEVICE); exit(1); } /* * Update the mount timeout. */ if (ioctl(autofs_control_fd, AUTOFS_SET_MOUNT_TO, &mount_timeout) == -1) pr_msg("AUTOFS_SET_MOUNT_TO failed: %m"); /* * Attempt to unmount any non-busy triggered mounts; this includes * not only autofs mounts, but, for example SMB Dfs mounts. * * This is done before sleep, and after a network change, to * try to get rid of as many network mounts as we can; each * unmounted network mount is a network mount on which we * can't hang. */ if (unmount_automounted) { if (verbose) pr_msg("Unmounting triggered mounts"); if (ioctl(autofs_control_fd, AUTOFS_UNMOUNT_TRIGGERED, 0) == -1) pr_msg("AUTOFS_UNMOUNT_TRIGGERED failed: %m"); exit(0); } if (flushcache) { /* * Notify the automounter that it should flush its caches, * as we might be on a different network with different maps. */ if (ioctl(autofs_control_fd, AUTOFS_NOTIFYCHANGE, 0) == -1) pr_msg("AUTOFS_NOTIFYCHANGE failed: %m"); } (void) umask(0); ns_setup(stack, &stkptr); (void) loadmaster_map(master_map, "", stack, &stkptr); /* * Mount the daemon at its mount points. */ for (dir = dir_head; dir; dir = dir->dir_next) { if (realpath(dir->dir_name, real_mntpnt) == NULL) { /* * We couldn't get the real path for this, * perhaps because it doesn't exist. * If it's not because it doesn't exist, just * give up on this entry. Otherwise, just null * out the real path - we'll try creating the * directory later, and will set dir_realpath * then, if that succeeds. */ if (errno != ENOENT) { pr_msg("%s: Can't convert to real path: %m", dir->dir_name); continue; } dir->dir_realpath = NULL; } else { dir->dir_realpath = strdup(real_mntpnt); if (dir->dir_realpath == NULL) { pr_msg("Couldn't allocate real path: %m"); exit(1); } } /* * Skip null entries */ if (strcmp(dir->dir_map, "-null") == 0) continue; /* * Skip null'ed entries */ null = 0; for (d = dir->dir_prev; d; d = d->dir_prev) { if (paths_match(dir, d)) null = 1; } if (null) continue; /* * If this is -fstab, and there are no fstab "net" entries, * skip this map if our directory search path doesn't * include Active Directory. We don't want /Network/Servers * (or wherever it shows up) to exist if this system isn't * using AD (AD supplies fstab entries on the fly, so they * might not exist right now) and we don't have any fstab * entries. */ if (strcmp(dir->dir_map, "-fstab") == 0) { if (!have_ad() && !havefstabkeys()) { /* * We're not using AD, and fstab is * inaccessible or devoid of "net" entries. */ free(dir->dir_map); dir->dir_map = strdup("-null"); continue; } endfsent(); } /* * If this is -fstab or -static, and there's another entry * that's supposed to mount something on the same directory * and isn't "-fstab" or "-static", ignore this; we might * have a server that's supplying real automounter maps for * the benefit of OS X systems with autofs and also supplying * fstab entries for the benefit of older OS X systems, and * we want to mount the real automounter map, not the -fstab * or -static map, in that case. */ if (strcmp(dir->dir_map, "-fstab") == 0 || strcmp(dir->dir_map, "-static") == 0) { for (d = dir_head; d; d = d->dir_next) { if (paths_match(dir, d) && strcmp(d->dir_map, "-fstab") != 0 && strcmp(d->dir_map, "-static") != 0) { pr_msg("%s: ignoring redundant %s map", dir->dir_name, dir->dir_map); break; } } if (d != NULL) { continue; } } /* * Parse the mount options and get additional flags to pass * to mount() (standard mount options) and autofs mount * options. * * XXX - we ignore flags on an update; if they're different * from the current flags for that mount, we'd need to do a * remount. */ if (!parse_mntopts(dir->dir_opts, &flags, &altflags)) { /* * Failed. */ continue; } /* * If this is -static, check whether the entry refers * to this host; if so, make the appropriate symlink * exist at the "mount point" path. */ if (strcmp(dir->dir_map, "-static") == 0) { static_ent = get_staticmap_entry(dir->dir_name); if (static_ent == NULL) { /* * Whiskey tango foxtrot? There should * be an entry here. Log an error and * ignore this mount. */ pr_msg("can't find fstab entry for %s", dir->dir_name); continue; } if (host_is_us(static_ent->host, strlen(static_ent->host)) || self_check(static_ent->host)) { /* * Yup, this is us. * Try to make the appropriate symlink. */ make_symlink(static_ent->localpath, dir->dir_name); release_staticmap_entry(static_ent); continue; } release_staticmap_entry(static_ent); } /* * Check whether there's already an entry * in the mnttab for this mountpoint. */ if (dir->dir_realpath != NULL && (mntp = find_mount(dir->dir_realpath)) != NULL) { struct autofs_update_args au; /* * If it's not an autofs mount - don't * mount over it. */ if (strcmp(mntp->f_fstypename, MNTTYPE_AUTOFS) != 0) { pr_msg("%s: already mounted on %s", mntp->f_mntfromname, dir->dir_realpath); continue; } /* * This is already mounted, so just update it. * We don't bother to check whether any options are * changing, as we'd have to make a trip into the * kernel to get the current options to check them, * so we might as well just make a trip to do the * update. */ au.fsid = mntp->f_fsid; au.opts = dir->dir_opts; au.map = dir->dir_map; au.mntflags = altflags; au.direct = dir->dir_direct; au.node_type = dir->dir_direct ? NT_TRIGGER : 0; if (ioctl(autofs_control_fd, AUTOFS_UPDATE_OPTIONS, &au) < 0) { pr_msg("update %s: %m", dir->dir_realpath); continue; } if (verbose) pr_msg("%s updated", dir->dir_realpath); } else { struct autofs_args ai; int st_flags = 0; /* * This trigger isn't already mounted; either * the path doesn't exist at all, or it * exists but nothing is mounted on it. * * Create a mount point if necessary * If the path refers to an existing symbolic * link, refuse to mount on it. This avoids * future problems. (We don't use dir->dir_realpath * because that's never a symbolic link.) */ if (lstat(dir->dir_name, &stbuf) == 0) { if ((stbuf.st_mode & S_IFMT) != S_IFDIR) { pr_msg("%s: Not a directory", dir->dir_name); continue; } st_flags = stbuf.st_flags; /* * Either realpath() succeeded or it * failed with ENOENT; otherwise, we * would have quit before getting here. * * If it failed, report an error, as * the problem isn't that "dir->dir_name" * doesn't exist, the problem is that, * somehow, we got ENOENT even though * it exists. */ if (dir->dir_realpath == NULL) { errno = ENOENT; pr_msg("%s: Can't convert to real path: %m", dir->dir_name); continue; } } else { /* * Mountpoint doesn't exist. * * Create it unless it's under /Volumes. * At boot time it's possible the volume * containing the mountpoint hasn't mounted yet. */ if (strncmp(dir->dir_name, "/Volumes/", 9) == 0) { pr_msg("%s: mountpoint unavailable", dir->dir_name); continue; } if (mkdir_r(dir->dir_name)) { pr_msg("%s: %m", dir->dir_name); continue; } /* * realpath() presumably didn't succeed, * as dir->dir_name couldn't be statted. * Call it again, to get the real path * corresponding to the newly-created * mount point. */ if (realpath(dir->dir_name, real_mntpnt) == NULL) { /* * Failed. */ pr_msg("%s: Can't convert to real path: %m", dir->dir_name); continue; } dir->dir_realpath = strdup(real_mntpnt); if (dir->dir_realpath == NULL) { pr_msg("Couldn't allocate real path for %s: %m", dir->dir_name); continue; } } /* * If the "hidefromfinder" option is set for * this autofs mountpoint then also set the * UF_HIDDEN bit on the directory so it'll still * be invisible to the Finder even if not mounted on. */ if (altflags & AUTOFS_MNT_HIDEFROMFINDER) st_flags |= UF_HIDDEN; else st_flags &= ~UF_HIDDEN; if (chflags(dir->dir_name, st_flags) < 0) pr_msg("%s: can't set hidden", dir->dir_name); /* * Mount it. Use the real path (symlink-free), * for reasons mentioned above. */ ai.version = AUTOFS_ARGSVERSION; ai.path = dir->dir_realpath; ai.opts = dir->dir_opts; ai.map = dir->dir_map; ai.subdir = ""; ai.direct = dir->dir_direct; if (dir->dir_direct) ai.key = dir->dir_name; else ai.key = ""; ai.mntflags = altflags; ai.mount_type = MOUNT_TYPE_MAP; /* top-level autofs mount */ ai.node_type = dir->dir_direct ? NT_TRIGGER : 0; if (mount(MNTTYPE_AUTOFS, dir->dir_realpath, MNT_DONTBROWSE | MNT_AUTOMOUNTED | flags, &ai) < 0) { pr_msg("mount %s: %m", dir->dir_realpath); continue; } if (verbose) pr_msg("%s mounted", dir->dir_realpath); } count++; } if (verbose && count == 0) pr_msg("no mounts"); /* * Now compare the /etc/mnttab with the master * map. Any autofs mounts in the /etc/mnttab * that are not in the master map must be * unmounted * * XXX - if there are no autofs mounts left, should we * unload autofs, or arrange that it be unloaded? */ do_unmounts(); /* * Let PremountHomeDirectoryWithAuthentication() know that we're * done. */ fd = open("/var/run/automount.initialized", O_CREAT|O_WRONLY, 0600); close(fd); return (0); }
int Mono_Posix_Syscall_endfsent (void) { endfsent (); return 0; }
/* ensure that we don't have a "/" instead of a "/dev/rxd0a" type of device. * returns pointer to static storage; copy it out quickly! */ char * vol_DevName(dev_t adev, char *wpath) { static char pbuffer[128]; char pbuf[128], *ptr; #ifdef AFS_SUN5_ENV struct mnttab mnt; FILE *mntfile; #else #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV) struct mntent *mntent; FILE *mfd; #else struct fstab *fsent; #endif #endif #ifdef AFS_AIX_ENV int nmounts; struct vmount *vmountp; #endif #ifdef AFS_AIX_ENV if ((nmounts = getmount(&vmountp)) <= 0) { return NULL; } for (; nmounts; nmounts--, vmountp = (struct vmount *)((int)vmountp + vmountp->vmt_length)) { char *part = vmt2dataptr(vmountp, VMT_STUB); #else #ifdef AFS_SUN5_ENV if (!(mntfile = fopen(MNTTAB, "r"))) { return NULL; } while (!getmntent(mntfile, &mnt)) { char *part = mnt.mnt_mountp; #else #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV) #ifdef AFS_LINUX22_ENV if ((mfd = setmntent("/proc/mounts", "r")) == NULL) { if ((mfd = setmntent("/etc/mtab", "r")) == NULL) { return NULL; } } #else if ((mfd = setmntent(MOUNTED /*MNTTAB*/, "r")) == NULL) { return NULL; } #endif while ((mntent = getmntent(mfd))) { char *part = mntent->mnt_dir; #else setfsent(); while ((fsent = getfsent())) { char *part = fsent->fs_file; #endif #endif /* AFS_SGI_ENV */ #endif struct stat status; #ifdef AFS_AIX_ENV if (vmountp->vmt_flags & (MNT_READONLY | MNT_REMOVABLE | MNT_REMOTE)) continue; /* Ignore any "special" partitions */ #else #ifdef AFS_SUN5_ENV /* Ignore non ufs or non read/write partitions */ if ((strcmp(mnt.mnt_fstype, "ufs") != 0) || (strncmp(mnt.mnt_mntopts, "ro,ignore", 9) == 0)) continue; #else #if defined(AFS_LINUX22_ENV) if (strcmp(mntent->mnt_type, "ext2")) continue; #else #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) if (!hasmntopt(mntent, MNTOPT_RW)) continue; #else if (strcmp(fsent->fs_type, "rw") != 0) continue; /* Ignore non read/write partitions */ #endif /* AFS_LINUX22_ENV */ #endif /* AFS_SGI_ENV */ #endif #endif /* Only keep track of "/vicepx" partitions since it can get hairy when NFS mounts are involved.. */ if (strncmp(part, VICE_PARTITION_PREFIX, VICE_PREFIX_SIZE)) { continue; /* Non /vicepx; ignore */ } if (stat(part, &status) == -1) { continue; } #if !defined(AFS_SGI_XFS_IOPS_ENV) && !defined(AFS_LINUX22_ENV) && !defined(AFS_DARWIN_ENV) if ((status.st_ino != ROOTINO) /*|| ((status.st_mode & S_IFMT) != S_IFBLK) */ ) { continue; } #endif if (status.st_dev == adev) { #ifdef AFS_AIX_ENV strcpy(pbuffer, vmt2dataptr(vmountp, VMT_OBJECT)); #else #ifdef AFS_SUN5_ENV strcpy(pbuffer, mnt.mnt_special); #else #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV) strcpy(pbuffer, mntent->mnt_fsname); #else strcpy(pbuffer, fsent->fs_spec); #endif #endif /* AFS_SGI_ENV */ #endif if (wpath) { strcpy(pbuf, pbuffer); ptr = (char *)strrchr(pbuf, OS_DIRSEPC); if (ptr) { *ptr = '\0'; strcpy(wpath, pbuf); } else return NULL; } ptr = (char *)strrchr(pbuffer, OS_DIRSEPC); if (ptr) { strcpy(pbuffer, ptr + 1); return pbuffer; } else return NULL; } } #ifdef AFS_SUN5_ENV (void)fclose(mntfile); #else #if defined(AFS_SGI_ENV) || defined(AFS_SUN_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX22_ENV) endmntent(mfd); #else #ifndef AFS_AIX_ENV endfsent(); #endif #endif #endif /* AFS_SGI_ENV */ return NULL; } /* Search for the raw device name. Will put an "r" in front of each * directory and file entry of the pathname until we find a character * device. */ char * afs_rawname(char *devfile) { static char rawname[100]; struct stat statbuf; int code, i; i = strlen(devfile); while (i >= 0) { strcpy(rawname, devfile); if (devfile[i] == OS_DIRSEPC) { rawname[i + 1] = 'r'; rawname[i + 2] = 0; strcat(rawname, &devfile[i + 1]); } code = stat(rawname, &statbuf); if (!code && S_ISCHR(statbuf.st_mode)) return rawname; while ((--i >= 0) && (devfile[i] != OS_DIRSEPC)); } return NULL; }
void disk_parse_config(char *token, char *cptr) { #if HAVE_GETMNTENT #if HAVE_SYS_MNTTAB_H struct mnttab mnttab; #else struct mntent *mntent; #endif FILE *mntfp; #else #if HAVE_FSTAB_H struct fstab *fstab; struct stat stat1, stat2; #endif #endif char tmpbuf[1024]; #if defined(HAVE_GETMNTENT) && !defined(HAVE_SETMNTENT) int i; #endif #if HAVE_FSTAB_H || HAVE_GETMNTENT if (numdisks == MAXDISKS) { config_perror("Too many disks specified."); sprintf(tmpbuf,"\tignoring: %s",cptr); config_perror(tmpbuf); } else { /* read disk path (eg, /1 or /usr) */ copy_word(cptr,disks[numdisks].path); cptr = skip_not_white(cptr); cptr = skip_white(cptr); /* read optional minimum disk usage spec */ if (cptr != NULL) { if (strchr(cptr, '%') == 0) { disks[numdisks].minimumspace = atoi(cptr); disks[numdisks].minpercent = -1; } else { disks[numdisks].minimumspace = -1; disks[numdisks].minpercent = atoi(cptr); } } else { disks[numdisks].minimumspace = DEFDISKMINIMUMSPACE; disks[numdisks].minpercent = -1; } /* find the device associated with the directory */ #if HAVE_GETMNTENT #if HAVE_SETMNTENT mntfp = setmntent(ETC_MNTTAB, "r"); disks[numdisks].device[0] = 0; while ((mntent = getmntent (mntfp))) if (strcmp (disks[numdisks].path, mntent->mnt_dir) == 0) { copy_word (mntent->mnt_fsname, disks[numdisks].device); DEBUGMSGTL(("ucd-snmp/disk", "Disk: %s\n",mntent->mnt_fsname)); break; } else { DEBUGMSGTL(("ucd-snmp/disk", " %s != %s\n", disks[numdisks].path, mntent->mnt_dir)); } endmntent(mntfp); if (disks[numdisks].device[0] != 0) { /* dummy clause for else below */ numdisks += 1; /* but inc numdisks here after test */ } #else /* getmentent but not setmntent */ mntfp = fopen (ETC_MNTTAB, "r"); while ((i = getmntent (mntfp, &mnttab)) == 0) if (strcmp (disks[numdisks].path, mnttab.mnt_mountp) == 0) break; else { DEBUGMSGTL(("ucd-snmp/disk", " %s != %s\n", disks[numdisks].path, mnttab.mnt_mountp)); } fclose (mntfp); if (i == 0) { copy_word (mnttab.mnt_special, disks[numdisks].device); numdisks += 1; } #endif /* HAVE_SETMNTENT */ #else #if HAVE_FSTAB_H stat(disks[numdisks].path,&stat1); setfsent(); if ((fstab = getfsfile(disks[numdisks].path))) { copy_word(fstab->fs_spec,disks[numdisks].device); numdisks += 1; } #endif #endif else { sprintf(tmpbuf, "Couldn't find device for disk %s", disks[numdisks].path); config_pwarn(tmpbuf); disks[numdisks].minimumspace = -1; disks[numdisks].minpercent = -1; disks[numdisks].path[0] = 0; } #if HAVE_FSTAB_H endfsent(); #endif } #else config_perror("'disk' checks not supported on this architecture."); #endif }
JBoolean JGetUserMountPointList ( JMountPointList* list, JMountState* state ) { time_t t; if (state != NULL && (!(JGetModificationTime(_PATH_FSTAB, &t)).OK() || t == state->modTime)) { return kJFalse; } list->CleanOut(); if (state != NULL) { state->modTime = t; } endfsent(); const JBoolean isRoot = JI2B( getuid() == 0 ); if (isRoot) { ACE_stat stbuf; while (const fstab* info = getfsent()) { if (JIsRootDirectory(info->fs_file) || strcmp(info->fs_type, FSTAB_SW) == 0) // swap partition { continue; } const JMountType type = JGetUserMountPointType(info->fs_file, info->fs_spec, info->fs_vfstype); if (type == kJUnknownMountType || ACE_OS::stat(info->fs_file, &stbuf) != 0) { continue; } JFileSystemType fsType = kOtherFSType; if (options.Contains("vfat")) { fsType = kVFATType; } JFileSystemType fsType = kOtherFSType; if (JStringCompare(info->fs_vfstype, "vfat", kJFalse) == 0) { fsType = kVFATType; } JString* path = jnew JString(info->fs_file); assert( path != NULL ); JString* devicePath = jnew JString(info->fs_spec); assert( devicePath != NULL ); list->AppendElement(JMountPoint(path, type, stbuf.st_dev, devicePath, fsType)); } } endfsent(); return kJTrue; }