From d9f4f71916c1b42ab651cf1f8bb8c9c1f01198d4 Mon Sep 17 00:00:00 2001 From: Thomas Veerman Date: Thu, 22 Nov 2012 22:00:00 +0000 Subject: [PATCH] Implement dynamic mtab support With this patch /etc/mtab becomes obsolete. --- commands/mount/mount.c | 60 ++--------------- commands/printroot/printroot.c | 4 -- commands/umount/umount.c | 54 +++++---------- common/include/sys/mount.h | 2 + etc/Makefile | 3 +- etc/rc | 1 - etc/usr/rc | 2 +- include/minix/minlib.h | 7 +- include/minix/sysinfo.h | 1 + lib/libcompat_minix/mtab.c | 119 ++++++--------------------------- servers/procfs/Makefile | 2 +- servers/procfs/mounts.c | 34 ++++++++++ servers/procfs/mounts.h | 6 ++ servers/procfs/root.c | 2 + servers/vfs/main.c | 3 +- servers/vfs/misc.c | 4 ++ servers/vfs/mount.c | 23 ++++--- servers/vfs/proto.h | 4 +- servers/vfs/vmnt.h | 5 ++ usr.sbin/mkfs.mfs/mkfs.c | 48 ++++++------- 20 files changed, 143 insertions(+), 241 deletions(-) create mode 100644 servers/procfs/mounts.c create mode 100644 servers/procfs/mounts.h diff --git a/commands/mount/mount.c b/commands/mount/mount.c index a9adecf19..f4e463cad 100644 --- a/commands/mount/mount.c +++ b/commands/mount/mount.c @@ -82,70 +82,23 @@ char *argv[]; return(EXIT_FAILURE); } - /* The mount has completed successfully. Tell the user. */ - printf("%s is read-%s mounted on %s\n", - argv[1], mountflags & MS_RDONLY ? "only" : "write", argv[2]); - - /* Update /etc/mtab. */ - update_mtab(argv[1], argv[2], type, mountflags); + printf("%s is mounted on %s\n", argv[1], argv[2]); return(EXIT_SUCCESS); } -void -update_mtab(char *dev, char *mountpoint, char *fstype, int mountflags) -{ - int n; - char *vs; - char special[PATH_MAX], mounted_on[PATH_MAX], version[10], rw_flag[10]; - - if (!write_mtab) return; - n = load_mtab("mount"); - if (n < 0) exit(1); /* something is wrong. */ - - /* Loop on all the /etc/mtab entries, copying each one to the output - * buf. */ - while (1) { - n = get_mtab_entry(special, mounted_on, version, rw_flag); - if (n < 0) break; - n = put_mtab_entry(special, mounted_on, version, rw_flag); - if (n < 0) { - std_err("mount: /etc/mtab has grown too large\n"); - exit(1); - } - } - /* For MFS, use a version number. Otherwise, use the FS type name. */ - if (!strcmp(fstype, MINIX_FS_TYPE)) { - vs = "MFSv3"; - } else if (strlen(fstype) < sizeof(version)) { - vs = fstype; - } else { - vs = "-"; - } - n = put_mtab_entry(dev, mountpoint, vs, - (mountflags & MS_RDONLY ? "ro" : "rw") ); - if (n < 0) { - std_err("mount: /etc/mtab has grown too large\n"); - exit(1); - } - - n = rewrite_mtab("mount"); -} - void list() { int n; - char special[PATH_MAX], mounted_on[PATH_MAX], version[10], rw_flag[10]; + char dev[PATH_MAX], mountpoint[PATH_MAX], type[MNTNAMELEN], flags[MNTFLAGLEN]; /* Read and print /etc/mtab. */ n = load_mtab("mount"); if (n < 0) exit(1); while (1) { - n = get_mtab_entry(special, mounted_on, version, rw_flag); + n = get_mtab_entry(dev, mountpoint, type, flags); if (n < 0) break; - printf("%s is read-%s mounted on %s (type %s)\n", - special, strcmp(rw_flag, "rw") == 0 ? "write" : "only", - mounted_on, version); + printf("%s on %s type %s (%s)\n", dev, mountpoint, type, flags); } exit(0); } @@ -200,10 +153,7 @@ mount_all() device = NULL; if (mount(device, mountpoint, mountflags, fs->fs_vfstype, - fs->fs_mntops) == 0) { - update_mtab(fs->fs_spec, fs->fs_file, fs->fs_vfstype, - mountflags); - } else { + fs->fs_mntops) != 0) { err = strerror(errno); fprintf(stderr, "mount: Can't mount %s on %s: %s\n", fs->fs_spec, fs->fs_file, err); diff --git a/commands/printroot/printroot.c b/commands/printroot/printroot.c index ad93c696b..c6afd4efc 100644 --- a/commands/printroot/printroot.c +++ b/commands/printroot/printroot.c @@ -2,10 +2,6 @@ /* This program figures out what the root device is by doing a stat on it, and * then searching /dev until it finds an entry with the same device number. - * A typical use (probably the only use) is in /etc/rc for initializing - * /etc/mtab, as follows: - * - * /usr/bin/printroot >/etc/mtab * * 9 Dec 1989 - clean up for 1.5 - full prototypes (BDE) * 15 Oct 1989 - avoid ACK cc bugs (BDE): diff --git a/commands/umount/umount.c b/commands/umount/umount.c index 9234f6201..b65921631 100644 --- a/commands/umount/umount.c +++ b/commands/umount/umount.c @@ -22,22 +22,22 @@ int find_mtab_entry(char *name); void update_mtab(void); void usage(void); -static char device[PATH_MAX+1], mountpoint[PATH_MAX+1], vs[10], rw[10]; +static char device[PATH_MAX], mount_point[PATH_MAX], type[MNTNAMELEN], + flags[MNTFLAGLEN]; int main(argc, argv) int argc; char *argv[]; { int found; - int flags = 0UL; - int i; + int umount_flags = 0UL; char c; char *name; while ((c = getopt (argc, argv, "e")) != -1) { switch (c) { - case 'e': flags |= MS_EXISTING; break; + case 'e': umount_flags |= MS_EXISTING; break; default: break; } } @@ -48,11 +48,9 @@ char *argv[]; name = argv[optind]; - found = find_mtab_entry(name); - - if (umount2(name, flags) < 0) { + if (umount2(name, umount_flags) < 0) { if (errno == EINVAL) std_err("umount: Device not mounted\n"); else if (errno == ENOTBLK) @@ -62,10 +60,8 @@ char *argv[]; exit(1); } if (found) { - printf("%s unmounted from %s\n", device, mountpoint); - update_mtab(); + printf("%s unmounted from %s\n", device, mount_point); } - else printf("%s unmounted (mtab not updated)\n", name); return(0); } @@ -76,7 +72,8 @@ char *name; * and generate a new mtab file without this entry on the fly. Do not write * out the result yet. Return whether we found a matching entry. */ - char special[PATH_MAX+1], mounted_on[PATH_MAX+1], version[10], rw_flag[10]; + char e_dev[PATH_MAX], e_mount_point[PATH_MAX], e_type[MNTNAMELEN], + e_flags[MNTFLAGLEN]; struct stat nstat, mstat; int n, found; @@ -86,44 +83,23 @@ char *name; found = 0; while (1) { - n = get_mtab_entry(special, mounted_on, version, rw_flag); + n = get_mtab_entry(e_dev, e_mount_point, e_type, e_flags); if (n < 0) break; - if (strcmp(name, special) == 0 || (stat(mounted_on, &mstat) == 0 && + if (strcmp(name, e_dev) == 0 || (stat(e_mount_point, &mstat) == 0 && mstat.st_dev == nstat.st_dev && mstat.st_ino == nstat.st_ino)) { - /* If we found an earlier match, keep that one. Mountpoints - * may be stacked on top of each other, and unmounting should - * take place in the reverse order of mounting. - */ - if (found) { - (void) put_mtab_entry(device, mountpoint, vs, rw); - } - - strcpy(device, special); - strcpy(mountpoint, mounted_on); - strcpy(vs, version); - strcpy(rw, rw_flag); + strlcpy(device, e_dev, PATH_MAX); + strlcpy(mount_point, e_mount_point, PATH_MAX); + strlcpy(type, e_type, MNTNAMELEN); + strlcpy(flags, e_flags, MNTFLAGLEN); found = 1; - continue; + break; } - (void) put_mtab_entry(special, mounted_on, version, rw_flag); } return found; } -void update_mtab() -{ -/* Write out the new mtab file. */ - int n; - - n = rewrite_mtab("umount"); - if (n < 0) { - std_err("/etc/mtab not updated.\n"); - exit(1); - } -} - void usage() { std_err("Usage: umount [-e] name\n"); diff --git a/common/include/sys/mount.h b/common/include/sys/mount.h index 606fff1e9..f4fbd7344 100644 --- a/common/include/sys/mount.h +++ b/common/include/sys/mount.h @@ -9,6 +9,8 @@ #define MS_REUSE 0x002 /* Tell RS to try reusing binary from memory */ #define MS_LABEL16 0x004 /* Mount message points to 16-byte label */ #define MS_EXISTING 0x008 /* Tell mount to use already running server */ +#define MNTNAMELEN 16 /* Length of fs type name including nul */ +#define MNTFLAGLEN 64 /* Length of flags string including nul */ int mount(char *_spec, char *_name, int _mountflags, char *type, char *args); diff --git a/etc/Makefile b/etc/Makefile index 9cd11e6c6..98e2b56f4 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -309,7 +309,8 @@ CONFIGSYMLINKS+= \ /usr/tmp /var/tmp \ /usr/pkg/bin/clang /usr/bin/cc \ /usr/pkg/bin/strip /usr/bin/strip \ - /dev/kbdaux /dev/mouse + /dev/kbdaux /dev/mouse \ + /proc/mounts /etc/mtab .endif # !defined(__MINIX) diff --git a/etc/rc b/etc/rc index 597fa0948..e78209f76 100755 --- a/etc/rc +++ b/etc/rc @@ -118,7 +118,6 @@ start) readclock || intr date -q # Initialize files. - printroot >/etc/mtab # /etc/mtab keeps track of mounts >/etc/utmp # /etc/utmp keeps track of logins # Use MFS binary only from kernel image? diff --git a/etc/usr/rc b/etc/usr/rc index 923758c48..523ac9122 100644 --- a/etc/usr/rc +++ b/etc/usr/rc @@ -212,7 +212,7 @@ start) ;; stop|down) # Save random data, if /usr is mounted rw. - if grep ' \/usr .*rw' /etc/mtab >/dev/null + if grep ' \/usr .*rw.*' /etc/mtab >/dev/null then if dd if=/dev/random of=$RANDOM_FILE.new bs=1024 count=1 2>/dev/null then diff --git a/include/minix/minlib.h b/include/minix/minlib.h index 1a65f8e1f..6a10450c2 100644 --- a/include/minix/minlib.h +++ b/include/minix/minlib.h @@ -1,6 +1,8 @@ #ifndef _MINLIB #define _MINLIB +#include + /* Miscellaneous BSD. */ char *itoa(int _n); #ifndef __NBSD_LIBC @@ -17,9 +19,8 @@ int fsversion(char *_dev, char *_prog); int getprocessor(void); void _cpuid(u32_t *eax, u32_t *ebx, u32_t *ecx, u32_t *edx); int load_mtab(char *_prog_name); -int rewrite_mtab(char *_prog_name); -int get_mtab_entry(char *_s1, char *_s2, char *_s3, char *_s4); -int put_mtab_entry(char *_s1, char *_s2, char *_s3, char *_s4); +int get_mtab_entry(char dev[PATH_MAX], char mount_point[PATH_MAX], + char type[MNTNAMELEN], char flags[MNTFLAGLEN]); /* read_tsc() and friends */ void read_tsc(u32_t *hi, u32_t *lo); diff --git a/include/minix/sysinfo.h b/include/minix/sysinfo.h index e63bb006e..88f9d6fcf 100644 --- a/include/minix/sysinfo.h +++ b/include/minix/sysinfo.h @@ -13,6 +13,7 @@ int getsysinfo(endpoint_t who, int what, void *where, size_t size); #define SI_DATA_STORE 5 /* get copy of data store mappings */ #define SI_CALL_STATS 9 /* system call statistics */ #define SI_PROCPUB_TAB 11 /* copy of public entries of process table */ +#define SI_VMNT_TAB 12 /* get vmnt table */ #endif diff --git a/lib/libcompat_minix/mtab.c b/lib/libcompat_minix/mtab.c index c40a597bd..a38dde4df 100644 --- a/lib/libcompat_minix/mtab.c +++ b/lib/libcompat_minix/mtab.c @@ -23,13 +23,11 @@ * * load_mtab(&prog_name) - read /etc/mtab into mtab_in * get_mtab_entry(&s1, &s2, &s3, &s4) - arrays that are filled in - * put_mtab_entry(&s1, &s2, &s3, &s4) - append a line to mtab_out - * rewrite_mtab(&prog_name) - write mtab_out to /etc/mtab * - * If load_mtab and rewrite_mtab work, they return 0. If they fail, they - * print their own error messages on stderr and return -1. When get_mtab_entry + * If load_mtab works, it returns 0. If it fails, it prints its own error + * message on stderr and returns -1. When get_mtab_entry * runs out of entries to return, it sets the first pointer to NULL and returns - * -1 instead of 0. Also, rewrite_mtab returns -1 if it fails. + * -1 instead of 0. */ #include @@ -46,16 +44,11 @@ char *etc_mtab = "/etc/mtab"; /* name of the /etc/mtab file */ static char mtab_in[BUF_SIZE+1]; /* holds /etc/mtab when it is read in */ -static char mtab_out[BUF_SIZE+1]; /* buf to build /etc/mtab for output later */ static char *iptr = mtab_in; /* pointer to next line to feed out. */ -static char *optr = mtab_out; /* pointer to place where next line goes */ int load_mtab(char *prog_name ); -int rewrite_mtab(char *prog_name ); -int get_mtab_entry(char *special, char *mounted_on, char *version, char - *rw_flag); -int put_mtab_entry(char *special, char *mounted_on, char *version, char - *rw_flag); +int get_mtab_entry(char dev[PATH_MAX], char mount_point[PATH_MAX], + char type[MNTNAMELEN], char flags[MNTFLAGLEN]); static void err(char *prog_name, char *str ); @@ -91,110 +84,36 @@ char *prog_name; close(fd); - /* Replace all the whitespace by '\0'. */ ptr = mtab_in; - while (*ptr != '\0') { - if (isspace(*ptr)) *ptr = '\0'; - ptr++; - } - return(0); -} - - -int rewrite_mtab(prog_name) -char *prog_name; -{ -/* Write mtab_out to /etc/mtab. */ - - int fd, n; - /* Do a creat to truncate the file. */ - fd = creat(etc_mtab, 0777); - if (fd < 0) { - err(prog_name, ": cannot overwrite "); - return(-1); - } - - /* File created. Write it. */ - n = write(fd, mtab_out, (unsigned int)(optr - mtab_out)); - if (n <= 0) { - /* Write failed. */ - err(prog_name, " could not write "); - return(-1); - } - - close(fd); return(0); } - -int get_mtab_entry(special, mounted_on, version, rw_flag) -char *special; -char *mounted_on; -char *version; -char *rw_flag; +int get_mtab_entry(char dev[PATH_MAX], char mount_point[PATH_MAX], + char type[MNTNAMELEN], char flags[MNTFLAGLEN]) { /* Return the next entry from mtab_in. */ + int r; + if (iptr >= &mtab_in[BUF_SIZE]) { - special[0] = '\0'; + dev[0] = '\0'; return(-1); } - strcpy(special, iptr); - while (isprint(*iptr)) iptr++; - while (*iptr == '\0'&& iptr < &mtab_in[BUF_SIZE]) iptr++; - - strcpy(mounted_on, iptr); - while (isprint(*iptr)) iptr++; - while (*iptr == '\0'&& iptr < &mtab_in[BUF_SIZE]) iptr++; - - strcpy(version, iptr); - while (isprint(*iptr)) iptr++; - while (*iptr == '\0'&& iptr < &mtab_in[BUF_SIZE]) iptr++; - - strcpy(rw_flag, iptr); - while (isprint(*iptr)) iptr++; - while (*iptr == '\0'&& iptr < &mtab_in[BUF_SIZE]) iptr++; - return(0); -} - - -int put_mtab_entry(special, mounted_on, version, rw_flag) -char *special; -char *mounted_on; -char *version; -char *rw_flag; -{ -/* Append an entry to the mtab_out buffer. */ - - int n1, n2, n3, n4; - - n1 = strlen(special); - n2 = strlen(mounted_on); - n3 = strlen(version); - n4 = strlen(rw_flag); - - if (optr + n1 + n2 + n3 + n4 + 5 >= &mtab_out[BUF_SIZE]) return(-1); - strcpy(optr, special); - optr += n1; - *optr++ = ' '; - - strcpy(optr, mounted_on); - optr += n2; - *optr++ = ' '; - - strcpy(optr, version); - optr += n3; - *optr++ = ' '; + r = sscanf(iptr, "%s on %s type %s (%[^)]s\n", + dev, mount_point, type, flags); + if (r != 4) { + dev[0] = '\0'; + return(-1); + } - strcpy(optr, rw_flag); - optr += n4; - *optr++ = '\n'; + iptr = strchr(iptr, '\n'); /* Find end of line */ + if (iptr != NULL) iptr++; /* Move to next line */ return(0); + } - static void err(prog_name, str) char *prog_name, *str; diff --git a/servers/procfs/Makefile b/servers/procfs/Makefile index 2697b6e0b..228425121 100644 --- a/servers/procfs/Makefile +++ b/servers/procfs/Makefile @@ -4,7 +4,7 @@ .include PROG= procfs -SRCS= buf.c main.c pid.c root.c tree.c util.c cpuinfo.c +SRCS= buf.c main.c pid.c root.c tree.c util.c cpuinfo.c mounts.c CPPFLAGS+= -I${NETBSDSRCDIR} -I${NETBSDSRCDIR}/servers diff --git a/servers/procfs/mounts.c b/servers/procfs/mounts.c new file mode 100644 index 000000000..cfd4f2663 --- /dev/null +++ b/servers/procfs/mounts.c @@ -0,0 +1,34 @@ +#include "inc.h" +#include "vfs/vmnt.h" + +extern struct mproc mproc[NR_PROCS]; + +/*===========================================================================* + * root_mtab * + *===========================================================================*/ +void +root_mounts(void) +{ + struct vmnt vmnt[NR_MNTS]; + struct vmnt *vmp; + struct mproc *rmp; + int slot; + + if (getsysinfo(VFS_PROC_NR, SI_VMNT_TAB, vmnt, sizeof(vmnt)) != OK) + return; + + for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; vmp++) { + if (vmp->m_dev == NO_DEV) + continue; + if (vmp->m_fs_e == PFS_PROC_NR) + continue; /* Skip (special case) */ + + slot = _ENDPOINT_P(vmp->m_fs_e); + if (slot < 0 || slot >= NR_PROCS) + continue; + rmp = &mproc[slot]; + buf_printf("%s on %s type %s (%s)\n", vmp->m_mount_dev, + vmp->m_mount_path, rmp->mp_name, + (vmp->m_flags & VMNT_READONLY) ? "ro" : "rw"); + } +} diff --git a/servers/procfs/mounts.h b/servers/procfs/mounts.h new file mode 100644 index 000000000..ca5712b4b --- /dev/null +++ b/servers/procfs/mounts.h @@ -0,0 +1,6 @@ +#ifndef __PROCFS_MOUNTS_H +#define __PROCFS_MOUNTS_H__ + +void root_mounts(void); + +#endif /* __PROCFS_MOUNTS_H__ */ diff --git a/servers/procfs/root.c b/servers/procfs/root.c index 44ee10539..dfd5b20e9 100644 --- a/servers/procfs/root.c +++ b/servers/procfs/root.c @@ -4,6 +4,7 @@ #include #include #include "cpuinfo.h" +#include "mounts.h" static void root_hz(void); static void root_uptime(void); @@ -24,6 +25,7 @@ struct file root_files[] = { { "dmap", REG_ALL_MODE, (data_t) root_dmap }, { "cpuinfo", REG_ALL_MODE, (data_t) root_cpuinfo }, { "ipcvecs", REG_ALL_MODE, (data_t) root_ipcvecs }, + { "mounts", REG_ALL_MODE, (data_t) root_mounts }, { NULL, 0, NULL } }; diff --git a/servers/vfs/main.c b/servers/vfs/main.c index adece2af8..249fb5259 100644 --- a/servers/vfs/main.c +++ b/servers/vfs/main.c @@ -621,7 +621,8 @@ static void *do_init_root(void *arg) } receive_from = MFS_PROC_NR; - if ((r = mount_fs(DEV_IMGRD, "/", MFS_PROC_NR, 0, mount_label)) != OK) + r = mount_fs(DEV_IMGRD, "bootramdisk", "/", MFS_PROC_NR, 0, mount_label); + if (r != OK) panic("Failed to initialize root"); receive_from = ANY; diff --git a/servers/vfs/misc.c b/servers/vfs/misc.c index cd7319f46..4c15d1249 100644 --- a/servers/vfs/misc.c +++ b/servers/vfs/misc.c @@ -91,6 +91,10 @@ int do_getsysinfo() len = sizeof(calls_stats); break; #endif + case SI_VMNT_TAB: + src_addr = (vir_bytes) vmnt; + len = sizeof(struct vmnt) * NR_MNTS; + break; default: return(EINVAL); } diff --git a/servers/vfs/mount.c b/servers/vfs/mount.c index 7b14b865b..e9354bb30 100644 --- a/servers/vfs/mount.c +++ b/servers/vfs/mount.c @@ -100,7 +100,7 @@ int do_mount() /* Perform the mount(name, mfile, mount_flags) system call. */ endpoint_t fs_e; int r, slot, rdonly, nodev; - char fullpath[PATH_MAX]; + char mount_path[PATH_MAX], mount_dev[PATH_MAX]; char mount_label[LABEL_MAX]; dev_t dev; int mflags; @@ -145,21 +145,22 @@ int do_mount() nodev = (vname1_length == 0); if (!nodev) { /* If 'name' is not for a block special file, return error. */ - if (fetch_name(vname1, vname1_length, fullpath) != OK) + if (fetch_name(vname1, vname1_length, mount_dev) != OK) return(err_code); - if ((dev = name_to_dev(FALSE /*allow_mountpt*/, fullpath)) == NO_DEV) + if ((dev = name_to_dev(FALSE /*allow_mountpt*/, mount_dev)) == NO_DEV) return(err_code); } else { /* Find a free pseudo-device as substitute for an actual device. */ if ((dev = find_free_nonedev()) == NO_DEV) return(err_code); + strlcpy(mount_dev, "none", sizeof(mount_dev)); } /* Fetch the name of the mountpoint */ - if (fetch_name(vname2, vname2_length, fullpath) != OK) return(err_code); + if (fetch_name(vname2, vname2_length, mount_path) != OK) return(err_code); /* Do the actual job */ - return mount_fs(dev, fullpath, fs_e, rdonly, mount_label); + return mount_fs(dev, mount_dev, mount_path, fs_e, rdonly, mount_label); } @@ -168,7 +169,8 @@ int do_mount() *===========================================================================*/ int mount_fs( dev_t dev, -char mountpoint[PATH_MAX], +char mount_dev[PATH_MAX], +char mount_path[PATH_MAX], endpoint_t fs_e, int rdonly, char mount_label[LABEL_MAX] ) @@ -206,10 +208,11 @@ char mount_label[LABEL_MAX] ) } else if ((new_vmp = get_free_vmnt()) == NULL) { return(ENOMEM); } - if ((r = lock_vmnt(new_vmp, VMNT_EXCL)) != OK) return(r); - isroot = (strcmp(mountpoint, "/") == 0); + strlcpy(new_vmp->m_mount_path, mount_path, PATH_MAX); + strlcpy(new_vmp->m_mount_dev, mount_dev, PATH_MAX); + isroot = (strcmp(mount_path, "/") == 0); mount_root = (isroot && have_root < 2); /* Root can be mounted twice: * 1: ramdisk * 2: boot disk (e.g., harddisk) @@ -217,7 +220,7 @@ char mount_label[LABEL_MAX] ) if (!mount_root) { /* Get vnode of mountpoint */ - lookup_init(&resolve, mountpoint, PATH_NOFLAGS, &parent_vmp, &vp); + lookup_init(&resolve, mount_path, PATH_NOFLAGS, &parent_vmp, &vp); resolve.l_vmnt_lock = VMNT_EXCL; resolve.l_vnode_lock = VNODE_WRITE; if ((vp = eat_path(&resolve, fp)) == NULL) @@ -405,6 +408,8 @@ void mount_pfs(void) vmp->m_dev = dev; vmp->m_fs_e = PFS_PROC_NR; strlcpy(vmp->m_label, "pfs", LABEL_MAX); + strlcpy(vmp->m_mount_path, "pipe", PATH_MAX); + strlcpy(vmp->m_mount_dev, "none", PATH_MAX); rfp = &fproc[_ENDPOINT_P(PFS_PROC_NR)]; } diff --git a/servers/vfs/proto.h b/servers/vfs/proto.h index 281200514..1b528b7fa 100644 --- a/servers/vfs/proto.h +++ b/servers/vfs/proto.h @@ -151,8 +151,8 @@ int do_mount(void); int do_umount(void); int is_nonedev(dev_t dev); void mount_pfs(void); -int mount_fs(dev_t dev, char fullpath[PATH_MAX+1], endpoint_t fs_e, int - rdonly, char mount_label[LABEL_MAX]); +int mount_fs(dev_t dev, char mount_dev[PATH_MAX], char mount_path[PATH_MAX], + endpoint_t fs_e, int rdonly, char mount_label[LABEL_MAX]); int unmount(dev_t dev, char label[LABEL_MAX]); void unmount_all(int force); diff --git a/servers/vfs/vmnt.h b/servers/vfs/vmnt.h index 14d00b3ab..2d3156e5f 100644 --- a/servers/vfs/vmnt.h +++ b/servers/vfs/vmnt.h @@ -1,6 +1,9 @@ #ifndef __VFS_VMNT_H__ #define __VFS_VMNT_H__ +#include "tll.h" +#include "comm.h" + EXTERN struct vmnt { int m_fs_e; /* FS process' kernel endpoint */ tll_t m_lock; @@ -10,6 +13,8 @@ EXTERN struct vmnt { struct vnode *m_mounted_on; /* vnode on which the partition is mounted */ struct vnode *m_root_node; /* root vnode */ char m_label[LABEL_MAX]; /* label of the file system process */ + char m_mount_path[PATH_MAX]; /* path on which vmnt is mounted */ + char m_mount_dev[PATH_MAX]; /* path on which vmnt is mounted */ } vmnt[NR_MNTS]; /* vmnt flags */ diff --git a/usr.sbin/mkfs.mfs/mkfs.c b/usr.sbin/mkfs.mfs/mkfs.c index d8c220338..8cb7be90b 100644 --- a/usr.sbin/mkfs.mfs/mkfs.c +++ b/usr.sbin/mkfs.mfs/mkfs.c @@ -94,9 +94,12 @@ int main(int argc, char **argv); block_t sizeup(char *device); void super(zone_t zones, ino_t inodes); void rootdir(ino_t inode); +int dir_try_enter(zone_t z, ino_t child, char *name); void eat_dir(ino_t parent); void eat_file(ino_t inode, int f); -void enter_dir(ino_t parent, char *name, ino_t child); +void enter_dir(ino_t parent, char const *name, ino_t child); +void enter_symlink(ino_t inode, char *link); +d2_inode *get_inoblock(ino_t i, block_t *blockno, d2_inode **ino); void incr_size(ino_t n, size_t count); static ino_t alloc_inode(int mode, int usrid, int grpid); static zone_t alloc_zone(void); @@ -109,7 +112,7 @@ int mode_con(char *p); void getline(char line[LINE_LEN], char *parse[MAX_TOKENS]); void check_mtab(char *devname); uint32_t file_time(int f); -void pexit(char *s); +__dead void pexit(char const *s); void copy(char *from, char *to, size_t count); void print_fs(void); int read_and_set(block_t n); @@ -120,7 +123,7 @@ void put_block(block_t n, char *buf); void mx_read(int blocknr, char *buf); void mx_write(int blocknr, char *buf); void dexit(char *s, int sectnum, int err); -void usage(void); +__dead void usage(void); void *alloc_block(void); ino_t inocount; @@ -511,14 +514,13 @@ char *device; /* * copied from fslib */ -static int bitmapsize(nr_bits, block_size) -uint32_t nr_bits; -size_t block_size; +static int bitmapsize(uint32_t nr_bits, size_t blk_size) { block_t nr_blocks; - nr_blocks = (int) (nr_bits / FS_BITS_PER_BLOCK(block_size)); - if (((uint32_t) nr_blocks * FS_BITS_PER_BLOCK(block_size)) < nr_bits) ++nr_blocks; + nr_blocks = (int) (nr_bits / FS_BITS_PER_BLOCK(blk_size)); + if (((uint32_t) nr_blocks * FS_BITS_PER_BLOCK(blk_size)) < nr_bits) + ++nr_blocks; return(nr_blocks); } @@ -788,9 +790,7 @@ int dir_try_enter(zone_t z, ino_t child, char *name) /*================================================================ * directory & inode management assist group *===============================================================*/ -void enter_dir(parent, name, child) -ino_t parent, child; -char *name; +void enter_dir(ino_t parent, char const *name, ino_t child) { /* Enter child in parent directory */ /* Works for dir > 1 block and zone > block */ @@ -810,7 +810,7 @@ char *name; ino->d2_zone[k] = z; } - if(dir_try_enter(z, child, name)) { + if(dir_try_enter(z, child, __UNCONST(name))) { put_block(b, (char *) inoblock); free(inoblock); free(indirblock); @@ -828,7 +828,7 @@ char *name; z = indirblock[k]; if(!z) z = indirblock[k] = alloc_zone(); - if(dir_try_enter(z, child, name)) { + if(dir_try_enter(z, child, __UNCONST(name))) { put_block(b, (char *) inoblock); put_block(ino->d2_zone[V2_NR_DZONES], (char *) indirblock); free(inoblock); @@ -908,10 +908,10 @@ ino_t n; off = (n - 1) % inodes_per_block; { static d2_inode *inode2 = NULL; - int n; + int s; - n = sizeof(*inode2) * V2_INODES_PER_BLOCK(block_size); - if(!inode2 && !(inode2 = malloc(n))) + s = sizeof(*inode2) * V2_INODES_PER_BLOCK(block_size); + if(!inode2 && !(inode2 = malloc(s))) pexit("couldn't allocate a block of inodes"); get_block(b, (char *) inode2); @@ -1119,7 +1119,8 @@ char *device; /* /dev/hd1 or whatever */ #if defined(__minix) int n, r; struct stat sb; - char special[PATH_MAX + 1], mounted_on[PATH_MAX + 1], version[10], rw_flag[10]; + char dev[PATH_MAX], mount_point[PATH_MAX], + type[MNTNAMELEN], flags[MNTFLAGLEN]; r= stat(device, &sb); if (r == -1) @@ -1136,14 +1137,14 @@ char *device; /* /dev/hd1 or whatever */ return; } - if (load_mtab("mkfs") < 0) return; + if (load_mtab(__UNCONST("mkfs")) < 0) return; while (1) { - n = get_mtab_entry(special, mounted_on, version, rw_flag); + n = get_mtab_entry(dev, mount_point, type, flags); if (n < 0) return; - if (strcmp(device, special) == 0) { + if (strcmp(device, dev) == 0) { /* Can't mkfs on top of a mounted file system. */ fprintf(stderr, "%s: %s is mounted on %s\n", - progname, device, mounted_on); + progname, device, mount_point); exit(1); } } @@ -1266,8 +1267,7 @@ int f; } -void pexit(s) -char *s; +__dead void pexit(char const * s) { fprintf(stderr, "%s: %s\n", progname, s); if (lct != 0) @@ -1379,7 +1379,7 @@ block_t n; return(r); } -void usage() +__dead void usage() { fprintf(stderr, "Usage: %s [-12dlot] [-b blocks] [-i inodes]\n" -- 2.44.0