STATIC int linvfs_rename( struct inode *odir, struct dentry *odentry, struct inode *ndir, struct dentry *ndentry) { int error; vnode_t *fvp; /* from directory */ vnode_t *tvp; /* target directory */ struct inode *new_inode = NULL; fvp = LINVFS_GET_VP(odir); tvp = LINVFS_GET_VP(ndir); new_inode = ndentry->d_inode; VOP_RENAME(fvp, odentry, tvp, ndentry, NULL, error); if (error) return -error; if (new_inode) { validate_fields(new_inode); } validate_fields(odir); if (ndir != odir) validate_fields(ndir); mark_inode_dirty(ndir); return 0; }
STATIC int linvfs_link( struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) { struct inode *ip; /* inode of guy being linked to */ vnode_t *tdvp; /* target directory for new name/link */ vnode_t *vp; /* vp of name being linked */ int error; ip = old_dentry->d_inode; /* inode being linked to */ if (S_ISDIR(ip->i_mode)) return -EPERM; tdvp = LINVFS_GET_VP(dir); vp = LINVFS_GET_VP(ip); VOP_LINK(tdvp, vp, dentry, NULL, error); if (!error) { VMODIFY(tdvp); VN_HOLD(vp); validate_fields(ip); d_instantiate(dentry, ip); } return -error; }
STATIC int linvfs_setxattr( struct dentry *dentry, const char *name, const void *data, size_t size, int flags) { vnode_t *vp = LINVFS_GET_VP(dentry->d_inode); char *attr = (char *)name; attrnames_t *namesp; int xflags = 0; int error; namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT); if (!namesp) return -EOPNOTSUPP; attr += namesp->attr_namelen; error = namesp->attr_capable(vp, NULL); if (error) return error; /* Convert Linux syscall to XFS internal ATTR flags */ if (flags & XATTR_CREATE) xflags |= ATTR_CREATE; if (flags & XATTR_REPLACE) xflags |= ATTR_REPLACE; xflags |= namesp->attr_flag; return namesp->attr_set(vp, attr, (void *)data, size, xflags); }
STATIC struct dentry * linvfs_get_parent( struct dentry *child) { int error; vnode_t *vp, *cvp; struct dentry *parent; struct inode *ip = NULL; struct dentry dotdot; dotdot.d_name.name = ".."; dotdot.d_name.len = 2; dotdot.d_inode = 0; cvp = NULL; vp = LINVFS_GET_VP(child->d_inode); VOP_LOOKUP(vp, &dotdot, &cvp, 0, NULL, NULL, error); if (!error) { ASSERT(cvp); ip = LINVFS_GET_IP(cvp); if (!ip) { VN_RELE(cvp); return ERR_PTR(-EACCES); } } if (error) return ERR_PTR(-error); parent = d_alloc_anon(ip); if (!parent) { VN_RELE(cvp); parent = ERR_PTR(-ENOMEM); } return parent; }
STATIC ssize_t linvfs_getxattr( struct dentry *dentry, const char *name, void *data, size_t size) { vnode_t *vp = LINVFS_GET_VP(dentry->d_inode); char *attr = (char *)name; attrnames_t *namesp; int xflags = 0; ssize_t error; namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT); if (!namesp) return -EOPNOTSUPP; attr += namesp->attr_namelen; error = namesp->attr_capable(vp, NULL); if (error) return error; /* Convert Linux syscall to XFS internal ATTR flags */ if (!size) { xflags |= ATTR_KERNOVAL; data = NULL; } xflags |= namesp->attr_flag; return namesp->attr_get(vp, attr, (void *)data, size, xflags); }
int dm_fd_to_hdl( int fd, /* any file descriptor */ void *hanp, /* user's data buffer */ size_t *hlenp) /* set to size of data copied */ { /* REFERENCED */ dm_fsreg_t *fsrp; xfs_handle_t handle; size_t hlen; int error; int lc; /* lock cookie */ struct file *filep = fget(fd); if (!filep) return(EBADF); if ((error = dm_vp_to_handle(LINVFS_GET_VP(filep->f_dentry->d_inode), &handle)) != 0) return(error); if ((fsrp = dm_find_fsreg_and_lock((fsid_t*)&handle.ha_fsid, &lc)) == NULL) return(EBADF); mutex_spinunlock(&fsrp->fr_lock, lc); hlen = XFS_HSIZE(handle); if (copy_to_user(hanp, &handle, (int)hlen)) return(EFAULT); fput(filep); return(put_user(hlen, hlenp)); }
STATIC int linvfs_symlink( struct inode *dir, struct dentry *dentry, const char *symname) { struct inode *ip; vattr_t va; vnode_t *dvp; /* directory containing name of symlink */ vnode_t *cvp; /* used to lookup symlink to put in dentry */ int error; dvp = LINVFS_GET_VP(dir); cvp = NULL; memset(&va, 0, sizeof(va)); va.va_mode = S_IFLNK | (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO); va.va_mask = XFS_AT_TYPE|XFS_AT_MODE; error = 0; VOP_SYMLINK(dvp, dentry, &va, (char *)symname, &cvp, NULL, error); if (likely(!error && cvp)) { error = linvfs_init_security(cvp, dir); if (likely(!error)) { ip = LINVFS_GET_IP(cvp); d_instantiate(dentry, ip); validate_fields(dir); validate_fields(ip); } } return -error; }
int dm_path_to_fshdl( char *path, /* any path name */ void *hanp, /* user's data buffer */ size_t *hlenp) /* set to size of data copied */ { /* REFERENCED */ dm_fsreg_t *fsrp; xfs_handle_t handle; vnode_t *vp; size_t hlen; int error; int lc; /* lock cookie */ struct nameidata nd; struct inode *inode; size_t len; char *name; /* XXX get things straightened out so getname() works here? */ len = strnlen_user(path, 2000); name = kmem_alloc(len, KM_SLEEP); if (copy_from_user(name, path, len)) return(EFAULT); error = 0; if (path_init(name, LOOKUP_POSITIVE|LOOKUP_FOLLOW, &nd)) error = path_walk(name, &nd); if (error) return error; kmem_free(name, len); ASSERT(nd.dentry); ASSERT(nd.dentry->d_inode); inode = igrab(nd.dentry->d_inode); path_release(&nd); /* we need the vnode */ vp = LINVFS_GET_VP(inode); if (!vp || !vp->v_vfsp->vfs_altfsid) { /* we're not in XFS anymore, Toto */ iput(inode); return EINVAL; } error = dm_vp_to_handle(vp, &handle); iput(inode);/*was VN_RELE(vp);*/ if (error) return(error); if ((fsrp = dm_find_fsreg_and_lock((fsid_t*)&handle.ha_fsid, &lc)) == NULL) return(EBADF); mutex_spinunlock(&fsrp->fr_lock, lc); hlen = FSHSIZE; if(copy_to_user(hanp, &handle, (int)hlen)) return(EFAULT); return(put_user(hlen,hlenp)); }
STATIC int linvfs_readlink( struct dentry *dentry, char *buf, int size) { vnode_t *vp = LINVFS_GET_VP(dentry->d_inode); uio_t uio; iovec_t iov; int error; iov.iov_base = buf; iov.iov_len = size; uio.uio_iov = &iov; uio.uio_offset = 0; uio.uio_segflg = UIO_USERSPACE; uio.uio_resid = size; uio.uio_iovcnt = 1; VOP_READLINK(vp, &uio, 0, NULL, error); if (error) return -error; return (size - uio.uio_resid); }
struct vnode * vn_initialize( struct inode *inode) { struct vnode *vp = LINVFS_GET_VP(inode); XFS_STATS_INC(vn_active); XFS_STATS_INC(vn_alloc); vp->v_flag = VMODIFIED; spinlock_init(&vp->v_lock, "v_lock"); spin_lock(&vnumber_lock); if (!++vn_generation) /* v_number shouldn't be zero */ vn_generation++; vp->v_number = vn_generation; spin_unlock(&vnumber_lock); ASSERT(VN_CACHED(vp) == 0); /* Initialize the first behavior and the behavior chain head. */ vn_bhv_head_init(VN_BHV_HEAD(vp), "vnode"); #ifdef XFS_VNODE_TRACE vp->v_trace = ktrace_alloc(VNODE_TRACE_SIZE, KM_SLEEP); #endif /* XFS_VNODE_TRACE */ vn_trace_exit(vp, "vn_initialize", (inst_t *)__return_address); return vp; }
STATIC int linvfs_symlink( struct inode *dir, struct dentry *dentry, const char *symname) { struct inode *ip; vattr_t va; vnode_t *dvp; /* directory containing name of symlink */ vnode_t *cvp; /* used to lookup symlink to put in dentry */ int error; dvp = LINVFS_GET_VP(dir); cvp = NULL; memset(&va, 0, sizeof(va)); va.va_type = VLNK; va.va_mode = irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO; va.va_mask = XFS_AT_TYPE|XFS_AT_MODE; error = 0; VOP_SYMLINK(dvp, dentry, &va, (char *)symname, &cvp, NULL, error); if (!error && cvp) { ASSERT(cvp->v_type == VLNK); ip = LINVFS_GET_IP(cvp); d_instantiate(dentry, ip); validate_fields(dir); validate_fields(ip); /* size needs update */ } return -error; }
STATIC __inline__ void xfs_set_inodeops( struct inode *inode) { vnode_t *vp = LINVFS_GET_VP(inode); if (vp->v_type == VNON) { make_bad_inode(inode); } else if (S_ISREG(inode->i_mode)) { inode->i_op = &linvfs_file_inode_operations; inode->i_fop = &linvfs_file_operations; inode->i_mapping->a_ops = &linvfs_aops; } else if (S_ISDIR(inode->i_mode)) { inode->i_op = &linvfs_dir_inode_operations; inode->i_fop = &linvfs_dir_operations; } else if (S_ISLNK(inode->i_mode)) { inode->i_op = &linvfs_symlink_inode_operations; if (inode->i_blocks) inode->i_mapping->a_ops = &linvfs_aops; } else { inode->i_op = &linvfs_file_inode_operations; init_special_inode(inode, inode->i_mode, inode->i_rdev); } }
STATIC struct dentry * linvfs_lookup( struct inode *dir, struct dentry *dentry) { struct inode *ip = NULL; vnode_t *vp, *cvp = NULL; int error; if (dentry->d_name.len >= MAXNAMELEN) return ERR_PTR(-ENAMETOOLONG); vp = LINVFS_GET_VP(dir); VOP_LOOKUP(vp, dentry, &cvp, 0, NULL, NULL, error); if (!error) { ASSERT(cvp); ip = LINVFS_GET_IP(cvp); if (!ip) { VN_RELE(cvp); return ERR_PTR(-EACCES); } } if (error && (error != ENOENT)) return ERR_PTR(-error); d_add(dentry, ip); /* Negative entry goes in if ip is NULL */ return NULL; }
STATIC int linvfs_file_mmap( struct file *filp, struct vm_area_struct *vma) { struct inode *ip = filp->f_dentry->d_inode; vnode_t *vp = LINVFS_GET_VP(ip); vattr_t va = { .va_mask = XFS_AT_UPDATIME }; int error; if (vp->v_vfsp->vfs_flag & VFS_DMI) { xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp); error = -XFS_SEND_MMAP(mp, vma, 0); if (error) return error; } vma->vm_ops = &linvfs_file_vm_ops; VOP_SETATTR(vp, &va, XFS_AT_UPDATIME, NULL, error); if (!error) vn_revalidate(vp); /* update Linux inode flags */ return 0; }
STATIC int linvfs_setattr( struct dentry *dentry, struct iattr *attr) { struct inode *inode = dentry->d_inode; unsigned int ia_valid = attr->ia_valid; vnode_t *vp = LINVFS_GET_VP(inode); vattr_t vattr; int flags = 0; int error; memset(&vattr, 0, sizeof(vattr_t)); if (ia_valid & ATTR_UID) { vattr.va_mask |= XFS_AT_UID; vattr.va_uid = attr->ia_uid; } if (ia_valid & ATTR_GID) { vattr.va_mask |= XFS_AT_GID; vattr.va_gid = attr->ia_gid; } if (ia_valid & ATTR_SIZE) { vattr.va_mask |= XFS_AT_SIZE; vattr.va_size = attr->ia_size; } if (ia_valid & ATTR_ATIME) { vattr.va_mask |= XFS_AT_ATIME; vattr.va_atime = attr->ia_atime; inode->i_atime = attr->ia_atime; } if (ia_valid & ATTR_MTIME) { vattr.va_mask |= XFS_AT_MTIME; vattr.va_mtime = attr->ia_mtime; } if (ia_valid & ATTR_CTIME) { vattr.va_mask |= XFS_AT_CTIME; vattr.va_ctime = attr->ia_ctime; } if (ia_valid & ATTR_MODE) { vattr.va_mask |= XFS_AT_MODE; vattr.va_mode = attr->ia_mode; if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID)) inode->i_mode &= ~S_ISGID; } if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) flags |= ATTR_UTIME; #ifdef ATTR_NO_BLOCK if ((ia_valid & ATTR_NO_BLOCK)) flags |= ATTR_NONBLOCK; #endif VOP_SETATTR(vp, &vattr, flags, NULL, error); if (error) return -error; vn_revalidate(vp); return error; }
/* Brute force approach for now - copy data into linux inode * from the results of a getattr. This gets called out of things * like stat. */ int linvfs_revalidate_core( struct inode *inode, int flags) { vnode_t *vp = LINVFS_GET_VP(inode); /* vn_revalidate returns (-) error so this is ok */ return vn_revalidate(vp, flags); }
STATIC int linvfs_revalidate( struct dentry *dentry) { vnode_t *vp = LINVFS_GET_VP(dentry->d_inode); if (unlikely(vp->v_flag & VMODIFIED)) return vn_revalidate(vp); return 0; }
STATIC int linvfs_permission( struct inode *inode, int mode) { vnode_t *vp = LINVFS_GET_VP(inode); int error; mode <<= 6; /* convert from linux to vnode access bits */ VOP_ACCESS(vp, mode, NULL, error); return -error; }
STATIC int linvfs_release( struct inode *inode, struct file *filp) { vnode_t *vp = LINVFS_GET_VP(inode); int error = 0; if (vp) VOP_RELEASE(vp, error); return -error; }
/* * Pull the link count and size up from the xfs inode to the linux inode */ STATIC void validate_fields( struct inode *ip) { vnode_t *vp = LINVFS_GET_VP(ip); vattr_t va; int error; va.va_mask = XFS_AT_NLINK|XFS_AT_SIZE|XFS_AT_NBLOCKS; VOP_GETATTR(vp, &va, ATTR_LAZY, NULL, error); ip->i_nlink = va.va_nlink; ip->i_size = va.va_size; ip->i_blocks = va.va_nblocks; }
STATIC int linvfs_open( struct inode *inode, struct file *filp) { vnode_t *vp = LINVFS_GET_VP(inode); vnode_t *newvp; int error; ASSERT(vp); VOP_OPEN(vp, &newvp, 0, get_current_cred(), error); return -error; }
/* * careful here - this function can get called recursively, so * we need to be very careful about how much stack we use. * uio is kmalloced for this reason... */ STATIC void * linvfs_follow_link( struct dentry *dentry, struct nameidata *nd) { vnode_t *vp; uio_t *uio; iovec_t iov; int error; char *link; ASSERT(dentry); ASSERT(nd); link = (char *)kmalloc(MAXPATHLEN+1, GFP_KERNEL); if (!link) { nd_set_link(nd, ERR_PTR(-ENOMEM)); return NULL; } uio = (uio_t *)kmalloc(sizeof(uio_t), GFP_KERNEL); if (!uio) { kfree(link); nd_set_link(nd, ERR_PTR(-ENOMEM)); return NULL; } vp = LINVFS_GET_VP(dentry->d_inode); iov.iov_base = link; iov.iov_len = MAXPATHLEN; uio->uio_iov = &iov; uio->uio_offset = 0; uio->uio_segflg = UIO_SYSSPACE; uio->uio_resid = MAXPATHLEN; uio->uio_iovcnt = 1; VOP_READLINK(vp, uio, 0, NULL, error); if (error) { kfree(link); link = ERR_PTR(-error); } else { link[MAXPATHLEN - uio->uio_resid] = '\0'; } kfree(uio); nd_set_link(nd, link); return NULL; }
STATIC ssize_t linvfs_sendfile( struct file *filp, loff_t *ppos, size_t count, read_actor_t actor, void *target) { vnode_t *vp = LINVFS_GET_VP(filp->f_dentry->d_inode); ssize_t rval; VOP_SENDFILE(vp, filp, ppos, 0, count, actor, target, NULL, rval); return rval; }
/* * careful here - this function can get called recursively, so * we need to be very careful about how much stack we use. * uio is kmalloced for this reason... */ STATIC int linvfs_follow_link( struct dentry *dentry, struct nameidata *nd) { vnode_t *vp; uio_t *uio; iovec_t iov; int error; char *link; ASSERT(dentry); ASSERT(nd); link = (char *)kmalloc(MAXNAMELEN+1, GFP_KERNEL); if (!link) return -ENOMEM; uio = (uio_t *)kmalloc(sizeof(uio_t), GFP_KERNEL); if (!uio) { kfree(link); return -ENOMEM; } vp = LINVFS_GET_VP(dentry->d_inode); iov.iov_base = link; iov.iov_len = MAXNAMELEN; uio->uio_iov = &iov; uio->uio_offset = 0; uio->uio_segflg = UIO_SYSSPACE; uio->uio_resid = MAXNAMELEN; uio->uio_iovcnt = 1; VOP_READLINK(vp, uio, 0, NULL, error); if (error) { kfree(uio); kfree(link); return -error; } link[MAXNAMELEN - uio->uio_resid] = '\0'; kfree(uio); /* vfs_follow_link returns (-) errors */ error = vfs_follow_link(nd, link); kfree(link); return error; }
/* * Attempt to flush the inode, this will actually fail * if the inode is pinned, but we dirty the inode again * at the point when it is unpinned after a log write, * since this is when the inode itself becomes flushable. */ STATIC void linvfs_write_inode( struct inode *inode, int sync) { vnode_t *vp = LINVFS_GET_VP(inode); int error, flags = FLUSH_INODE; if (vp) { vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address); if (sync) flags |= FLUSH_SYNC; VOP_IFLUSH(vp, flags, error); } }
STATIC void linvfs_clear_inode( struct inode *inode) { vnode_t *vp = LINVFS_GET_VP(inode); if (vp) { vn_rele(vp); vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address); /* * Do all our cleanup, and remove this vnode. */ vn_remove(vp); } }
STATIC int linvfs_open( struct inode *inode, struct file *filp) { vnode_t *vp = LINVFS_GET_VP(inode); int error; if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS) return -EFBIG; ASSERT(vp); VOP_OPEN(vp, NULL, error); return -error; }
STATIC int linvfs_getattr( struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) { struct inode *inode = dentry->d_inode; vnode_t *vp = LINVFS_GET_VP(inode); int error = 0; if (unlikely(vp->v_flag & VMODIFIED)) error = vn_revalidate(vp); if (!error) generic_fillattr(inode, stat); return 0; }
STATIC int linvfs_rmdir( struct inode *dir, struct dentry *dentry) { struct inode *inode = dentry->d_inode; vnode_t *dvp = LINVFS_GET_VP(dir); int error; VOP_RMDIR(dvp, dentry, NULL, error); if (!error) { validate_fields(inode); validate_fields(dir); } return -error; }
STATIC int linvfs_mprotect( struct vm_area_struct *vma, unsigned int newflags) { vnode_t *vp = LINVFS_GET_VP(vma->vm_file->f_dentry->d_inode); int error = 0; if (vp->v_vfsp->vfs_flag & VFS_DMI) { if ((vma->vm_flags & VM_MAYSHARE) && (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE)) { xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp); error = XFS_SEND_MMAP(mp, vma, VM_WRITE); } } return error; }