/*===========================================================================* * do_link * *===========================================================================*/ PUBLIC int do_link() { /* Perform the link(name1, name2) system call. */ int r; endpoint_t linked_fs_e, link_lastdir_fs_e; struct vnode *vp_o, *vp_d; if (fetch_name(m_in.name1, m_in.name1_length, M1) != OK) return(err_code); /* Request lookup */ if ((r = lookup_vp(0 /*flags*/, 0 /*!use_realuid*/, &vp_o)) != OK) return r; linked_fs_e = vp_o->v_fs_e; /* Does the final directory of 'name2' exist? */ if (fetch_name(m_in.name2, m_in.name2_length, M1) != OK) { put_vnode(vp_o); return(err_code); } /* Request lookup */ if ((r = lookup_lastdir(0 /*!use_realuid*/, &vp_d)) != OK) { put_vnode(vp_o); return r; } link_lastdir_fs_e = vp_d->v_fs_e; /* Check for links across devices. */ if (linked_fs_e != link_lastdir_fs_e) { put_vnode(vp_o); put_vnode(vp_d); return EXDEV; } /* Make sure that the object is a directory */ if ((vp_d->v_mode & I_TYPE) != I_DIRECTORY) { put_vnode(vp_o); put_vnode(vp_d); return ENOTDIR; } r= forbidden(vp_d, W_BIT|X_BIT, 0 /*!use_realuid*/); if (r != OK) { put_vnode(vp_o); put_vnode(vp_d); return r; } /* Issue request */ r= req_link(linked_fs_e, vp_d->v_inode_nr, user_fullpath, vp_o->v_inode_nr); put_vnode(vp_o); put_vnode(vp_d); return r; }
/*===========================================================================* * do_utime * *===========================================================================*/ PUBLIC int do_utime() { /* Perform the utime(name, timep) system call. */ register int len; int r; uid_t uid; time_t actime, modtime; struct vnode *vp; /* Adjust for case of 'timep' being NULL; * utime_strlen then holds the actual size: strlen(name)+1. */ len = m_in.utime_length; if (len == 0) len = m_in.utime_strlen; if (fetch_name(m_in.utime_file, len, M1) != OK) return(err_code); /* Request lookup */ if ((r = lookup_vp(0 /*flags*/, 0 /*!use_realuid*/, &vp)) != OK) return r; /* Fill in request fields.*/ if (m_in.utime_length == 0) { actime = modtime = clock_time(); } else { actime = m_in.utime_actime; modtime = m_in.utime_modtime; } uid= fp->fp_effuid; r= OK; if (vp->v_uid != uid && uid != SU_UID) r = EPERM; if (m_in.utime_length == 0 && r != OK) { /* With a null times pointer, updating the times (to the current time) * is allow if the object is writable. */ r = forbidden(vp, W_BIT, 0 /*!use_realuid*/); } if (r != OK) { put_vnode(vp); return r; } /* Issue request */ r= req_utime(vp->v_fs_e, vp->v_inode_nr, actime, modtime); put_vnode(vp); return r; }
/*===========================================================================* * do_truncate * *===========================================================================*/ PUBLIC int do_truncate() { /* truncate_inode() does the actual work of do_truncate() and do_ftruncate(). * do_truncate() and do_ftruncate() have to get hold of the inode, either * by name or fd, do checks on it, and call truncate_inode() to do the * work. */ struct vnode *vp; int r; printf("in do_truncate\n"); if (fetch_name(m_in.m2_p1, m_in.m2_i1, M1) != OK) return err_code; /* Request lookup */ if ((r = lookup_vp(0 /*flags*/, 0 /*!use_realuid*/, &vp)) != OK) return r; if ((r = forbidden(vp, W_BIT, 0 /*!use_realuid*/)) == OK) r = truncate_vn(vp, m_in.m2_l1); put_vnode(vp); return r; }
/*===========================================================================* * mount * *===========================================================================*/ PRIVATE int mount_fs(endpoint_t fs_e) { /* Perform the mount(name, mfile, rd_only) system call. */ int rdir, mdir; /* TRUE iff {root|mount} file is dir */ int i, r, found, isroot, replace_root; struct fproc *tfp; struct dmap *dp; dev_t dev; message m; struct vnode *root_node, *mounted_on = NULL, *bspec; struct vmnt *vmp; char *label; struct node_details res; SANITYCHECK; /* Only the super-user may do MOUNT. */ if (!super_user) return(EPERM); /* If FS not yet logged in, save message and suspend mount */ if (last_login_fs_e != fs_e) { mount_m_in = m_in; return SUSPEND; } /* Mount request got after FS login or * FS login arrived after a suspended mount */ last_login_fs_e = NONE; /* Clear endpoint field */ 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); /* Convert name to device number */ if ((dev = name_to_dev()) == NO_DEV) return(err_code); /* Check whether there is a block special file open which uses the * same device (partition) */ for (bspec = &vnode[0]; bspec < &vnode[NR_VNODES]; ++bspec) { if (bspec->v_ref_count > 0 && bspec->v_sdev == dev) { /* Found, sync the buffer cache */ req_sync(bspec->v_fs_e); break; /* Note: there are probably some blocks in the FS process' buffer * cache which contain data on this minor, although they will be * purged since the handling moves to the new FS process (if * everything goes well with the mount...) */ } } /* Didn't find? */ if (bspec == &vnode[NR_VNODES] && bspec->v_sdev != dev) bspec = NULL; /* Scan vmnt table to see if dev already mounted, if not, * find a free slot.*/ found = FALSE; vmp = NIL_VMNT; for (i = 0; i < NR_MNTS; ++i) { if (vmnt[i].m_dev == dev) { vmp = &vmnt[i]; found = TRUE; break; } else if (!vmp && vmnt[i].m_dev == NO_DEV) { vmp = &vmnt[i]; } } /* Partition was/is already mounted */ if (found) { /* It is possible that we have an old root lying around that * needs to be remounted. */ if (vmp->m_mounted_on || vmp->m_mounted_on == fproc[FS_PROC_NR].fp_rd) { /* Normally, m_mounted_on refers to the mount point. For a * root filesystem, m_mounted_on is equal to the root vnode. * We assume that the root of FS is always the real root. If * the two vnodes are different or if the root of FS is equal * to the root of the filesystem we found, we found a * filesystem that is in use. */ return EBUSY; /* already mounted */ } if(vmp->m_mounted_on) panic("vfs", "root unexpectedly mounted somewhere", NO_NUM); if (root_dev == vmp->m_dev) panic("fs", "inconsistency remounting old root", NO_NUM); /* Now get the inode of the file to be mounted on. */ if (fetch_name(m_in.name2, m_in.name2_length, M1) != OK) { return(err_code); } /* Request lookup */ r = lookup_vp(0 /*flags*/, 0 /*!use_realuid*/, &mounted_on); if (r != OK) return r; if (mounted_on->v_ref_count != 1) { put_vnode(mounted_on); printf("vfs:mount_fs: mount point is busy\n"); return EBUSY; } /* Issue mountpoint request */ r = req_mountpoint(mounted_on->v_fs_e, mounted_on->v_inode_nr); if (r != OK) { put_vnode(mounted_on); printf("vfs:mount_fs: req_mountpoint_s failed with %d\n", r); return r; } /* Get the root inode of the mounted file system. */ root_node = vmp->m_root_node; /* File types may not conflict. */ if (r == OK) { mdir = ((mounted_on->v_mode & I_TYPE) == I_DIRECTORY); /* TRUE iff dir */ rdir = ((root_node->v_mode & I_TYPE) == I_DIRECTORY); if (!mdir && rdir) r = EISDIR; } /* If error, return the mount point. */ if (r != OK) { put_vnode(mounted_on); return(r); } /* Nothing else can go wrong. Perform the mount. */ vmp->m_mounted_on = mounted_on; vmp->m_flags = m_in.rd_only; allow_newroot = 0; /* The root is now fixed */ return(OK); } /* Fetch the name of the mountpoint */ if (fetch_name(m_in.name2, m_in.name2_length, M1) != OK) { return(err_code); } isroot= (strcmp(user_fullpath, "/") == 0); replace_root= (isroot && allow_newroot); if (!replace_root) { /* Get mount point and inform the FS it is on. */ #if 0 printf("vfs:mount_fs: mount point at '%s'\n", user_fullpath); #endif r = lookup_vp(0 /*flags*/, 0 /*!use_realuid*/, &mounted_on); if (r != OK) return r; /* Issue mountpoint request */ r = req_mountpoint(mounted_on->v_fs_e, mounted_on->v_inode_nr); if (r != OK) { put_vnode(mounted_on); printf("vfs:mount_fs: req_mountpoint_s failed with %d\n", r); return r; } } /* We'll need a vnode for the root inode, check whether there is one */ if ((root_node = get_free_vnode(__FILE__, __LINE__)) == NIL_VNODE) { printf("VFSmount: no free vnode available\n"); return ENFILE; } /* Get driver process' endpoint */ dp = &dmap[(dev >> MAJOR) & BYTE]; if (dp->dmap_driver == NONE) { printf("VFSmount: no driver for dev %x\n", dev); return(EINVAL); } label= dp->dmap_label; if (strlen(label) == 0) { panic(__FILE__, "vfs:mount_fs: no label for major", dev >> MAJOR); }