diff --git a/servers/vfs/main.c b/servers/vfs/main.c index bfd62da0f..49a8233e7 100644 --- a/servers/vfs/main.c +++ b/servers/vfs/main.c @@ -222,8 +222,8 @@ PRIVATE void fs_init() int s; /* Clear endpoint field */ - last_login_fs_e = 0; - mount_m_in.m1_p3 = 0; + last_login_fs_e = NONE; + mount_m_in.m1_p3 = (char *) NONE; /* Initialize the process table with help of the process manager messages. * Expect one message for each system process with its slot number and pid. @@ -313,7 +313,7 @@ PRIVATE void init_root() panic(__FILE__, "Error receiving login request from root filesystem\n", ROOT_FS_E); } } - last_login_fs_e = 0; + last_login_fs_e = NONE; /* Initialize vmnt table */ for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp) diff --git a/servers/vfs/mount.c b/servers/vfs/mount.c index 769926ea3..f337e3bef 100644 --- a/servers/vfs/mount.c +++ b/servers/vfs/mount.c @@ -72,10 +72,19 @@ PUBLIC int do_mount() { endpoint_t fs_e; int r; + + /* Only the super-user may do MOUNT. */ + if (!super_user) return(EPERM); /* FS process' endpoint number */ fs_e = (unsigned long)m_in.m1_p3; + /* Sanity check on process number. */ + if(fs_e <= 0) { + printf("vfs: warning: got process number %d for mount call.\n", fs_e); + return EINVAL; + } + /* Do the actual job */ r = mount_fs(fs_e); @@ -123,10 +132,10 @@ PRIVATE int mount_fs(endpoint_t fs_e) /* Mount request got after FS login or * FS login arrived after a suspended mount */ - last_login_fs_e = 0; + last_login_fs_e = NONE; /* Clear endpoint field */ - mount_m_in.m1_p3 = 0; + mount_m_in.m1_p3 = (char *) NONE; /* If 'name' is not for a block special file, return error. */ if (fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code); @@ -466,18 +475,23 @@ PUBLIC int unmount(dev) Dev_t dev; { struct vnode *vp; - struct vmnt *vmp; + struct vmnt *vmp_i = NULL, *vmp = NULL; struct dmap *dp; int count, r; int fs_e; /* Find vmnt */ - for (vmp = &vmnt[0]; vmp < &vmnt[NR_MNTS]; ++vmp) { - if (vmp->m_dev == dev) break; - else if (vmp == &vmnt[NR_MNTS]) - return EINVAL; + for (vmp_i = &vmnt[0]; vmp_i < &vmnt[NR_MNTS]; ++vmp_i) { + if (vmp->m_dev == dev) { + if(vmp) panic(__FILE__, "device mounted more than once", dev); + vmp = vmp_i; + } } + /* Device mounted? */ + if(!vmp) + return EINVAL; + /* See if the mounted device is busy. Only 1 vnode using it should be * open -- the root vnode -- and that inode only 1 time. */ @@ -496,6 +510,8 @@ Dev_t dev; vnode_clean_refs(vmp->m_root_node); /* Request FS the unmount */ + if(vmp->m_fs_e <= 0) + panic(__FILE__, "unmount: strange fs endpoint", vmp->m_fs_e); if ((r = req_unmount(vmp->m_fs_e)) != OK) return r; /* Close the device the file system lives on. */ @@ -541,8 +557,8 @@ Dev_t dev; vmp->m_root_node = NIL_VNODE; vmp->m_mounted_on = NIL_VNODE; vmp->m_dev = NO_DEV; - vmp->m_fs_e = 0; - vmp->m_driver_e = 0; + vmp->m_fs_e = NONE; + vmp->m_driver_e = NONE; /* Ask RS to bring down FS */ if (-1 == fs_exit(fs_e)) { diff --git a/servers/vfs/open.c b/servers/vfs/open.c index 13a49de5c..ae8756299 100644 --- a/servers/vfs/open.c +++ b/servers/vfs/open.c @@ -150,7 +150,7 @@ PRIVATE int common_open(register int oflags, mode_t omode) r= OK; else { - printf("common_open: / in pathrem"); + printf("common_open: / in pathrem\n"); } } diff --git a/servers/vfs/proto.h b/servers/vfs/proto.h index 67aaf73ac..bfcca929f 100644 --- a/servers/vfs/proto.h +++ b/servers/vfs/proto.h @@ -133,7 +133,6 @@ _PROTOTYPE( int do_getdents, (void) ); _PROTOTYPE( int read_write, (int rw_flag) ); /* request.c */ -_PROTOTYPE( int fs_sendrec, (endpoint_t fs_e, message *reqm) ); _PROTOTYPE( int req_getnode, (node_req_t *req, node_details_t *res) ); _PROTOTYPE( int req_putnode, (int fs_e, ino_t inode_nr, int count) ); _PROTOTYPE( int req_open, (open_req_t *req, node_details_t *res) ); diff --git a/servers/vfs/request.c b/servers/vfs/request.c index b41ea8746..4e2d739f3 100644 --- a/servers/vfs/request.c +++ b/servers/vfs/request.c @@ -28,6 +28,7 @@ #include "vnode.h" #include "param.h" +FORWARD _PROTOTYPE(int fs_sendrec, (endpoint_t fs_e, message *reqm)); /*===========================================================================* * req_getnode * @@ -954,7 +955,7 @@ _t *res; /*===========================================================================* * fs_sendrec * *===========================================================================*/ -PUBLIC int fs_sendrec(endpoint_t fs_e, message *reqm) +PRIVATE int fs_sendrec(endpoint_t fs_e, message *reqm) { /* This is the low level function that sends requests to FS processes. * It also handles driver recovery mechanism and reissuing the