diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 15:20:36 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 15:20:36 -0700 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/coda |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'fs/coda')
-rw-r--r-- | fs/coda/Makefile | 12 | ||||
-rw-r--r-- | fs/coda/cache.c | 120 | ||||
-rw-r--r-- | fs/coda/cnode.c | 172 | ||||
-rw-r--r-- | fs/coda/coda_linux.c | 197 | ||||
-rw-r--r-- | fs/coda/dir.c | 704 | ||||
-rw-r--r-- | fs/coda/file.c | 300 | ||||
-rw-r--r-- | fs/coda/inode.c | 321 | ||||
-rw-r--r-- | fs/coda/pioctl.c | 95 | ||||
-rw-r--r-- | fs/coda/psdev.c | 462 | ||||
-rw-r--r-- | fs/coda/symlink.c | 55 | ||||
-rw-r--r-- | fs/coda/sysctl.c | 254 | ||||
-rw-r--r-- | fs/coda/upcall.c | 914 |
12 files changed, 3606 insertions, 0 deletions
diff --git a/fs/coda/Makefile b/fs/coda/Makefile new file mode 100644 index 00000000000..6c22e61da39 --- /dev/null +++ b/fs/coda/Makefile @@ -0,0 +1,12 @@ +# +# Makefile for the Linux Coda filesystem routines. +# + +obj-$(CONFIG_CODA_FS) += coda.o + +coda-objs := psdev.o cache.o cnode.o inode.o dir.o file.o upcall.o \ + coda_linux.o symlink.o pioctl.o sysctl.o + +# If you want debugging output, please uncomment the following line. + +# EXTRA_CFLAGS += -DDEBUG -DDEBUG_SMB_MALLOC=1 diff --git a/fs/coda/cache.c b/fs/coda/cache.c new file mode 100644 index 00000000000..80072fd9b7f --- /dev/null +++ b/fs/coda/cache.c @@ -0,0 +1,120 @@ +/* + * Cache operations for Coda. + * For Linux 2.1: (C) 1997 Carnegie Mellon University + * For Linux 2.3: (C) 2000 Carnegie Mellon University + * + * Carnegie Mellon encourages users of this code to contribute improvements + * to the Coda project http://www.coda.cs.cmu.edu/ <coda@cs.cmu.edu>. + */ + +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/time.h> +#include <linux/fs.h> +#include <linux/stat.h> +#include <linux/errno.h> +#include <asm/uaccess.h> +#include <linux/string.h> +#include <linux/list.h> + +#include <linux/coda.h> +#include <linux/coda_linux.h> +#include <linux/coda_psdev.h> +#include <linux/coda_fs_i.h> +#include <linux/coda_cache.h> + +static atomic_t permission_epoch = ATOMIC_INIT(0); + +/* replace or extend an acl cache hit */ +void coda_cache_enter(struct inode *inode, int mask) +{ + struct coda_inode_info *cii = ITOC(inode); + + cii->c_cached_epoch = atomic_read(&permission_epoch); + if (cii->c_uid != current->fsuid) { + cii->c_uid = current->fsuid; + cii->c_cached_perm = mask; + } else + cii->c_cached_perm |= mask; +} + +/* remove cached acl from an inode */ +void coda_cache_clear_inode(struct inode *inode) +{ + struct coda_inode_info *cii = ITOC(inode); + cii->c_cached_perm = 0; +} + +/* remove all acl caches */ +void coda_cache_clear_all(struct super_block *sb) +{ + struct coda_sb_info *sbi; + + sbi = coda_sbp(sb); + if (!sbi) BUG(); + + atomic_inc(&permission_epoch); +} + + +/* check if the mask has been matched against the acl already */ +int coda_cache_check(struct inode *inode, int mask) +{ + struct coda_inode_info *cii = ITOC(inode); + int hit; + + hit = (mask & cii->c_cached_perm) == mask && + cii->c_uid == current->fsuid && + cii->c_cached_epoch == atomic_read(&permission_epoch); + + return hit; +} + + +/* Purging dentries and children */ +/* The following routines drop dentries which are not + in use and flag dentries which are in use to be + zapped later. + + The flags are detected by: + - coda_dentry_revalidate (for lookups) if the flag is C_PURGE + - coda_dentry_delete: to remove dentry from the cache when d_count + falls to zero + - an inode method coda_revalidate (for attributes) if the + flag is C_VATTR +*/ + +/* this won't do any harm: just flag all children */ +static void coda_flag_children(struct dentry *parent, int flag) +{ + struct list_head *child; + struct dentry *de; + + spin_lock(&dcache_lock); + list_for_each(child, &parent->d_subdirs) + { + de = list_entry(child, struct dentry, d_child); + /* don't know what to do with negative dentries */ + if ( ! de->d_inode ) + continue; + coda_flag_inode(de->d_inode, flag); + } + spin_unlock(&dcache_lock); + return; +} + +void coda_flag_inode_children(struct inode *inode, int flag) +{ + struct dentry *alias_de; + + if ( !inode || !S_ISDIR(inode->i_mode)) + return; + + alias_de = d_find_alias(inode); + if (!alias_de) + return; + coda_flag_children(alias_de, flag); + shrink_dcache_parent(alias_de); + dput(alias_de); +} + diff --git a/fs/coda/cnode.c b/fs/coda/cnode.c new file mode 100644 index 00000000000..23aeef5aa81 --- /dev/null +++ b/fs/coda/cnode.c @@ -0,0 +1,172 @@ +/* cnode related routines for the coda kernel code + (C) 1996 Peter Braam + */ + +#include <linux/types.h> +#include <linux/string.h> +#include <linux/time.h> + +#include <linux/coda.h> +#include <linux/coda_linux.h> +#include <linux/coda_fs_i.h> +#include <linux/coda_psdev.h> + +static inline int coda_fideq(struct CodaFid *fid1, struct CodaFid *fid2) +{ + return memcmp(fid1, fid2, sizeof(*fid1)) == 0; +} + +static struct inode_operations coda_symlink_inode_operations = { + .readlink = generic_readlink, + .follow_link = page_follow_link_light, + .put_link = page_put_link, + .setattr = coda_setattr, +}; + +/* cnode.c */ +static void coda_fill_inode(struct inode *inode, struct coda_vattr *attr) +{ + coda_vattr_to_iattr(inode, attr); + + if (S_ISREG(inode->i_mode)) { + inode->i_op = &coda_file_inode_operations; + inode->i_fop = &coda_file_operations; + } else if (S_ISDIR(inode->i_mode)) { + inode->i_op = &coda_dir_inode_operations; + inode->i_fop = &coda_dir_operations; + } else if (S_ISLNK(inode->i_mode)) { + inode->i_op = &coda_symlink_inode_operations; + inode->i_data.a_ops = &coda_symlink_aops; + inode->i_mapping = &inode->i_data; + } else + init_special_inode(inode, inode->i_mode, huge_decode_dev(attr->va_rdev)); +} + +static int coda_test_inode(struct inode *inode, void *data) +{ + struct CodaFid *fid = (struct CodaFid *)data; + return coda_fideq(&(ITOC(inode)->c_fid), fid); +} + +static int coda_set_inode(struct inode *inode, void *data) +{ + struct CodaFid *fid = (struct CodaFid *)data; + ITOC(inode)->c_fid = *fid; + return 0; +} + +static int coda_fail_inode(struct inode *inode, void *data) +{ + return -1; +} + +struct inode * coda_iget(struct super_block * sb, struct CodaFid * fid, + struct coda_vattr * attr) +{ + struct inode *inode; + struct coda_inode_info *cii; + unsigned long hash = coda_f2i(fid); + + inode = iget5_locked(sb, hash, coda_test_inode, coda_set_inode, fid); + + if (!inode) + return ERR_PTR(-ENOMEM); + + if (inode->i_state & I_NEW) { + cii = ITOC(inode); + /* we still need to set i_ino for things like stat(2) */ + inode->i_ino = hash; + cii->c_mapcount = 0; + unlock_new_inode(inode); + } + + /* always replace the attributes, type might have changed */ + coda_fill_inode(inode, attr); + return inode; +} + +/* this is effectively coda_iget: + - get attributes (might be cached) + - get the inode for the fid using vfs iget + - link the two up if this is needed + - fill in the attributes +*/ +int coda_cnode_make(struct inode **inode, struct CodaFid *fid, struct super_block *sb) +{ + struct coda_vattr attr; + int error; + + /* We get inode numbers from Venus -- see venus source */ + error = venus_getattr(sb, fid, &attr); + if ( error ) { + *inode = NULL; + return error; + } + + *inode = coda_iget(sb, fid, &attr); + if ( IS_ERR(*inode) ) { + printk("coda_cnode_make: coda_iget failed\n"); + return PTR_ERR(*inode); + } + return 0; +} + + +void coda_replace_fid(struct inode *inode, struct CodaFid *oldfid, + struct CodaFid *newfid) +{ + struct coda_inode_info *cii; + unsigned long hash = coda_f2i(newfid); + + cii = ITOC(inode); + + if (!coda_fideq(&cii->c_fid, oldfid)) + BUG(); + + /* replace fid and rehash inode */ + /* XXX we probably need to hold some lock here! */ + remove_inode_hash(inode); + cii->c_fid = *newfid; + inode->i_ino = hash; + __insert_inode_hash(inode, hash); +} + +/* convert a fid to an inode. */ +struct inode *coda_fid_to_inode(struct CodaFid *fid, struct super_block *sb) +{ + struct inode *inode; + unsigned long hash = coda_f2i(fid); + + if ( !sb ) { + printk("coda_fid_to_inode: no sb!\n"); + return NULL; + } + + inode = iget5_locked(sb, hash, coda_test_inode, coda_fail_inode, fid); + if ( !inode ) + return NULL; + + /* we should never see newly created inodes because we intentionally + * fail in the initialization callback */ + BUG_ON(inode->i_state & I_NEW); + + return inode; +} + +/* the CONTROL inode is made without asking attributes from Venus */ +int coda_cnode_makectl(struct inode **inode, struct super_block *sb) +{ + int error = -ENOMEM; + + *inode = new_inode(sb); + if (*inode) { + (*inode)->i_ino = CTL_INO; + (*inode)->i_op = &coda_ioctl_inode_operations; + (*inode)->i_fop = &coda_ioctl_operations; + (*inode)->i_mode = 0444; + error = 0; + } + + return error; +} + diff --git a/fs/coda/coda_linux.c b/fs/coda/coda_linux.c new file mode 100644 index 00000000000..5597080cb81 --- /dev/null +++ b/fs/coda/coda_linux.c @@ -0,0 +1,197 @@ +/* + * Inode operations for Coda filesystem + * Original version: (C) 1996 P. Braam and M. Callahan + * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University + * + * Carnegie Mellon encourages users to contribute improvements to + * the Coda project. Contact Peter Braam (coda@cs.cmu.edu). + */ + +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/time.h> +#include <linux/fs.h> +#include <linux/stat.h> +#include <linux/errno.h> +#include <asm/uaccess.h> +#include <linux/string.h> + +#include <linux/coda.h> +#include <linux/coda_linux.h> +#include <linux/coda_psdev.h> +#include <linux/coda_fs_i.h> + +/* initialize the debugging variables */ +int coda_fake_statfs; + +/* print a fid */ +char * coda_f2s(struct CodaFid *f) +{ + static char s[60]; +#ifdef CONFIG_CODA_FS_OLD_API + sprintf(s, "(%08x.%08x.%08x)", f->opaque[0], f->opaque[1], f->opaque[2]); +#else + sprintf(s, "(%08x.%08x.%08x.%08x)", f->opaque[0], f->opaque[1], f->opaque[2], f->opaque[3]); +#endif + return s; +} + +/* recognize special .CONTROL name */ +int coda_iscontrol(const char *name, size_t length) +{ + return ((CODA_CONTROLLEN == length) && + (strncmp(name, CODA_CONTROL, CODA_CONTROLLEN) == 0)); +} + +/* recognize /coda inode */ +int coda_isroot(struct inode *i) +{ + return ( i->i_sb->s_root->d_inode == i ); +} + +unsigned short coda_flags_to_cflags(unsigned short flags) +{ + unsigned short coda_flags = 0; + + if ((flags & O_ACCMODE) == O_RDONLY) + coda_flags |= C_O_READ; + + if ((flags & O_ACCMODE) == O_RDWR) + coda_flags |= C_O_READ | C_O_WRITE; + + if ((flags & O_ACCMODE) == O_WRONLY) + coda_flags |= C_O_WRITE; + + if (flags & O_TRUNC) + coda_flags |= C_O_TRUNC; + + if (flags & O_CREAT) + coda_flags |= C_O_CREAT; + + if (flags & O_EXCL) + coda_flags |= C_O_EXCL; + + return coda_flags; +} + + +/* utility functions below */ +void coda_vattr_to_iattr(struct inode *inode, struct coda_vattr *attr) +{ + int inode_type; + /* inode's i_flags, i_ino are set by iget + XXX: is this all we need ?? + */ + switch (attr->va_type) { + case C_VNON: + inode_type = 0; + break; + case C_VREG: + inode_type = S_IFREG; + break; + case C_VDIR: + inode_type = S_IFDIR; + break; + case C_VLNK: + inode_type = S_IFLNK; + break; + default: + inode_type = 0; + } + inode->i_mode |= inode_type; + + if (attr->va_mode != (u_short) -1) + inode->i_mode = attr->va_mode | inode_type; + if (attr->va_uid != -1) + inode->i_uid = (uid_t) attr->va_uid; + if (attr->va_gid != -1) + inode->i_gid = (gid_t) attr->va_gid; + if (attr->va_nlink != -1) + inode->i_nlink = attr->va_nlink; + if (attr->va_size != -1) + inode->i_size = attr->va_size; + if (attr->va_blocksize != -1) + inode->i_blksize = attr->va_blocksize; + if (attr->va_size != -1) + inode->i_blocks = (attr->va_size + 511) >> 9; + if (attr->va_atime.tv_sec != -1) + inode->i_atime = attr->va_atime; + if (attr->va_mtime.tv_sec != -1) + inode->i_mtime = attr->va_mtime; + if (attr->va_ctime.tv_sec != -1) + inode->i_ctime = attr->va_ctime; +} + + +/* + * BSD sets attributes that need not be modified to -1. + * Linux uses the valid field to indicate what should be + * looked at. The BSD type field needs to be deduced from linux + * mode. + * So we have to do some translations here. + */ + +void coda_iattr_to_vattr(struct iattr *iattr, struct coda_vattr *vattr) +{ + unsigned int valid; + + /* clean out */ + vattr->va_mode = (umode_t) -1; + vattr->va_uid = (vuid_t) -1; + vattr->va_gid = (vgid_t) -1; + vattr->va_size = (off_t) -1; + vattr->va_atime.tv_sec = (time_t) -1; + vattr->va_atime.tv_nsec = (time_t) -1; + vattr->va_mtime.tv_sec = (time_t) -1; + vattr->va_mtime.tv_nsec = (time_t) -1; + vattr->va_ctime.tv_sec = (time_t) -1; + vattr->va_ctime.tv_nsec = (time_t) -1; + vattr->va_type = C_VNON; + vattr->va_fileid = -1; + vattr->va_gen = -1; + vattr->va_bytes = -1; + vattr->va_nlink = -1; + vattr->va_blocksize = -1; + vattr->va_rdev = -1; + vattr->va_flags = 0; + + /* determine the type */ +#if 0 + mode = iattr->ia_mode; + if ( S_ISDIR(mode) ) { + vattr->va_type = C_VDIR; + } else if ( S_ISREG(mode) ) { + vattr->va_type = C_VREG; + } else if ( S_ISLNK(mode) ) { + vattr->va_type = C_VLNK; + } else { + /* don't do others */ + vattr->va_type = C_VNON; + } +#endif + + /* set those vattrs that need change */ + valid = iattr->ia_valid; + if ( valid & ATTR_MODE ) { + vattr->va_mode = iattr->ia_mode; + } + if ( valid & ATTR_UID ) { + vattr->va_uid = (vuid_t) iattr->ia_uid; + } + if ( valid & ATTR_GID ) { + vattr->va_gid = (vgid_t) iattr->ia_gid; + } + if ( valid & ATTR_SIZE ) { + vattr->va_size = iattr->ia_size; + } + if ( valid & ATTR_ATIME ) { + vattr->va_atime = iattr->ia_atime; + } + if ( valid & ATTR_MTIME ) { + vattr->va_mtime = iattr->ia_mtime; + } + if ( valid & ATTR_CTIME ) { + vattr->va_ctime = iattr->ia_ctime; + } +} + diff --git a/fs/coda/dir.c b/fs/coda/dir.c new file mode 100644 index 00000000000..2391766e9c7 --- /dev/null +++ b/fs/coda/dir.c @@ -0,0 +1,704 @@ + +/* + * Directory operations for Coda filesystem + * Original version: (C) 1996 P. Braam and M. Callahan + * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University + * + * Carnegie Mellon encourages users to contribute improvements to + * the Coda project. Contact Peter Braam (coda@cs.cmu.edu). + */ + +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/time.h> +#include <linux/fs.h> +#include <linux/file.h> +#include <linux/stat.h> +#include <linux/errno.h> +#include <linux/string.h> +#include <linux/smp_lock.h> + +#include <asm/uaccess.h> + +#include <linux/coda.h> +#include <linux/coda_linux.h> +#include <linux/coda_psdev.h> +#include <linux/coda_fs_i.h> +#include <linux/coda_cache.h> +#include <linux/coda_proc.h> + +/* dir inode-ops */ +static int coda_create(struct inode *dir, struct dentry *new, int mode, struct nameidata *nd); +static struct dentry *coda_lookup(struct inode *dir, struct dentry *target, struct nameidata *nd); +static int coda_link(struct dentry *old_dentry, struct inode *dir_inode, + struct dentry *entry); +static int coda_unlink(struct inode *dir_inode, struct dentry *entry); +static int coda_symlink(struct inode *dir_inode, struct dentry *entry, + const char *symname); +static int coda_mkdir(struct inode *dir_inode, struct dentry *entry, int mode); +static int coda_rmdir(struct inode *dir_inode, struct dentry *entry); +static int coda_rename(struct inode *old_inode, struct dentry *old_dentry, + struct inode *new_inode, struct dentry *new_dentry); + +/* dir file-ops */ +static int coda_readdir(struct file *file, void *dirent, filldir_t filldir); + +/* dentry ops */ +static int coda_dentry_revalidate(struct dentry *de, struct nameidata *nd); +static int coda_dentry_delete(struct dentry *); + +/* support routines */ +static int coda_venus_readdir(struct file *filp, filldir_t filldir, + void *dirent, struct dentry *dir); +int coda_fsync(struct file *, struct dentry *dentry, int datasync); + +/* same as fs/bad_inode.c */ +static int coda_return_EIO(void) +{ + return -EIO; +} +#define CODA_EIO_ERROR ((void *) (coda_return_EIO)) + +static struct dentry_operations coda_dentry_operations = +{ + .d_revalidate = coda_dentry_revalidate, + .d_delete = coda_dentry_delete, +}; + +struct inode_operations coda_dir_inode_operations = +{ + .create = coda_create, + .lookup = coda_lookup, + .link = coda_link, + .unlink = coda_unlink, + .symlink = coda_symlink, + .mkdir = coda_mkdir, + .rmdir = coda_rmdir, + .mknod = CODA_EIO_ERROR, + .rename = coda_rename, + .permission = coda_permission, + .getattr = coda_getattr, + .setattr = coda_setattr, +}; + +struct file_operations coda_dir_operations = { + .llseek = generic_file_llseek, + .read = generic_read_dir, + .readdir = coda_readdir, + .open = coda_open, + .flush = coda_flush, + .release = coda_release, + .fsync = coda_fsync, +}; + + +/* inode operations for directories */ +/* access routines: lookup, readlink, permission */ +static struct dentry *coda_lookup(struct inode *dir, struct dentry *entry, struct nameidata *nd) +{ + struct inode *res_inode = NULL; + struct CodaFid resfid = { { 0, } }; + int dropme = 0; /* to indicate entry should not be cached */ + int type = 0; + int error = 0; + const char *name = entry->d_name.name; + size_t length = entry->d_name.len; + + if ( length > CODA_MAXNAMLEN ) { + printk("name too long: lookup, %s (%*s)\n", + coda_i2s(dir), (int)length, name); + return ERR_PTR(-ENAMETOOLONG); + } + + lock_kernel(); + /* control object, create inode on the fly */ + if (coda_isroot(dir) && coda_iscontrol(name, length)) { + error = coda_cnode_makectl(&res_inode, dir->i_sb); + dropme = 1; + goto exit; + } + + error = venus_lookup(dir->i_sb, coda_i2f(dir), + (const char *)name, length, &type, &resfid); + + res_inode = NULL; + if (!error) { + if (type & CODA_NOCACHE) { + type &= (~CODA_NOCACHE); + dropme = 1; + } + + error = coda_cnode_make(&res_inode, &resfid, dir->i_sb); + if (error) { + unlock_kernel(); + return ERR_PTR(error); + } + } else if (error != -ENOENT) { + unlock_kernel(); + return ERR_PTR(error); + } + +exit: + entry->d_time = 0; + entry->d_op = &coda_dentry_operations; + d_add(entry, res_inode); + if ( dropme ) { + d_drop(entry); + coda_flag_inode(res_inode, C_VATTR); + } + unlock_kernel(); + return NULL; +} + + +int coda_permission(struct inode *inode, int mask, struct nameidata *nd) +{ + int error = 0; + + if (!mask) + return 0; + + lock_kernel(); + + coda_vfs_stat.permission++; + + if (coda_cache_check(inode, mask)) + goto out; + + error = venus_access(inode->i_sb, coda_i2f(inode), mask); + + if (!error) + coda_cache_enter(inode, mask); + + out: + unlock_kernel(); + + return error; +} + + +static inline void coda_dir_changed(struct inode *dir, int link) +{ +#ifdef REQUERY_VENUS_FOR_MTIME + /* invalidate the directory cnode's attributes so we refetch the + * attributes from venus next time the inode is referenced */ + coda_flag_inode(dir, C_VATTR); +#else + /* optimistically we can also act as if our nose bleeds. The + * granularity of the mtime is coarse anyways so we might actually be + * right most of the time. Note: we only do this for directories. */ + dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC; +#endif + if (link) + dir->i_nlink += link; +} + +/* creation routines: create, mknod, mkdir, link, symlink */ +static int coda_create(struct inode *dir, struct dentry *de, int mode, struct nameidata *nd) +{ + int error=0; + const char *name=de->d_name.name; + int length=de->d_name.len; + struct inode *inode; + struct CodaFid newfid; + struct coda_vattr attrs; + + lock_kernel(); + coda_vfs_stat.create++; + + if (coda_isroot(dir) && coda_iscontrol(name, length)) { + unlock_kernel(); + return -EPERM; + } + + error = venus_create(dir->i_sb, coda_i2f(dir), name, length, + 0, mode, &newfid, &attrs); + + if ( error ) { + unlock_kernel(); + d_drop(de); + return error; + } + + inode = coda_iget(dir->i_sb, &newfid, &attrs); + if ( IS_ERR(inode) ) { + unlock_kernel(); + d_drop(de); + return PTR_ERR(inode); + } + + /* invalidate the directory cnode's attributes */ + coda_dir_changed(dir, 0); + unlock_kernel(); + d_instantiate(de, inode); + return 0; +} + +static int coda_mkdir(struct inode *dir, struct dentry *de, int mode) +{ + struct inode *inode; + struct coda_vattr attrs; + const char *name = de->d_name.name; + int len = de->d_name.len; + int error; + struct CodaFid newfid; + + lock_kernel(); + coda_vfs_stat.mkdir++; + + if (coda_isroot(dir) && coda_iscontrol(name, len)) { + unlock_kernel(); + return -EPERM; + } + + attrs.va_mode = mode; + error = venus_mkdir(dir->i_sb, coda_i2f(dir), + name, len, &newfid, &attrs); + + if ( error ) { + unlock_kernel(); + d_drop(de); + return error; + } + + inode = coda_iget(dir->i_sb, &newfid, &attrs); + if ( IS_ERR(inode) ) { + unlock_kernel(); + d_drop(de); + return PTR_ERR(inode); + } + + /* invalidate the directory cnode's attributes */ + coda_dir_changed(dir, 1); + unlock_kernel(); + d_instantiate(de, inode); + return 0; +} + +/* try to make de an entry in dir_inodde linked to source_de */ +static int coda_link(struct dentry *source_de, struct inode *dir_inode, + struct dentry *de) +{ + struct inode *inode = source_de->d_inode; + const char * name = de->d_name.name; + int len = de->d_name.len; + int error; + + lock_kernel(); + coda_vfs_stat.link++; + + if (coda_isroot(dir_inode) && coda_iscontrol(name, len)) { + unlock_kernel(); + return -EPERM; + } + + error = venus_link(dir_inode->i_sb, coda_i2f(inode), + coda_i2f(dir_inode), (const char *)name, len); + + if (error) { + d_drop(de); + goto out; + } + + coda_dir_changed(dir_inode, 0); + atomic_inc(&inode->i_count); + d_instantiate(de, inode); + inode->i_nlink++; + +out: + unlock_kernel(); + return(error); +} + + +static int coda_symlink(struct inode *dir_inode, struct dentry *de, + const char *symname) +{ + const char *name = de->d_name.name; + int len = de->d_name.len; + int symlen; + int error=0; + + lock_kernel(); + coda_vfs_stat.symlink++; + + if (coda_isroot(dir_inode) && coda_iscontrol(name, len)) { + unlock_kernel(); + return -EPERM; + } + + symlen = strlen(symname); + if ( symlen > CODA_MAXPATHLEN ) { + unlock_kernel(); + return -ENAMETOOLONG; + } + + /* + * This entry is now negative. Since we do not create + * an inode for the entry we have to drop it. + */ + d_drop(de); + error = venus_symlink(dir_inode->i_sb, coda_i2f(dir_inode), name, len, + symname, symlen); + + /* mtime is no good anymore */ + if ( !error ) + coda_dir_changed(dir_inode, 0); + + unlock_kernel(); + return error; +} + +/* destruction routines: unlink, rmdir */ +int coda_unlink(struct inode *dir, struct dentry *de) +{ + int error; + const char *name = de->d_name.name; + int len = de->d_name.len; + + lock_kernel(); + coda_vfs_stat.unlink++; + + error = venus_remove(dir->i_sb, coda_i2f(dir), name, len); + if ( error ) { + unlock_kernel(); + return error; + } + + coda_dir_changed(dir, 0); + de->d_inode->i_nlink--; + unlock_kernel(); + + return 0; +} + +int coda_rmdir(struct inode *dir, struct dentry *de) +{ + const char *name = de->d_name.name; + int len = de->d_name.len; + int error; + + lock_kernel(); + coda_vfs_stat.rmdir++; + + if (!d_unhashed(de)) { + unlock_kernel(); + return -EBUSY; + } + error = venus_rmdir(dir->i_sb, coda_i2f(dir), name, len); + + if ( error ) { + unlock_kernel(); + return error; + } + + coda_dir_changed(dir, -1); + de->d_inode->i_nlink--; + d_delete(de); + unlock_kernel(); + + return 0; +} + +/* rename */ +static int coda_rename(struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry) +{ + const char *old_name = old_dentry->d_name.name; + const char *new_name = new_dentry->d_name.name; + int old_length = old_dentry->d_name.len; + int new_length = new_dentry->d_name.len; + int link_adjust = 0; + int error; + + lock_kernel(); + coda_vfs_stat.rename++; + + error = venus_rename(old_dir->i_sb, coda_i2f(old_dir), + coda_i2f(new_dir), old_length, new_length, + (const char *) old_name, (const char *)new_name); + + if ( !error ) { + if ( new_dentry->d_inode ) { + if ( S_ISDIR(new_dentry->d_inode->i_mode) ) + link_adjust = 1; + + coda_dir_changed(old_dir, -link_adjust); + coda_dir_changed(new_dir, link_adjust); + coda_flag_inode(new_dentry->d_inode, C_VATTR); + } else { + coda_flag_inode(old_dir, C_VATTR); + coda_flag_inode(new_dir, C_VATTR); + } + } + unlock_kernel(); + + return error; +} + + +/* file operations for directories */ +int coda_readdir(struct file *coda_file, void *dirent, filldir_t filldir) +{ + struct dentry *coda_dentry = coda_file->f_dentry; + struct coda_file_info *cfi; + struct file *host_file; + struct inode *host_inode; + int ret; + + cfi = CODA_FTOC(coda_file); + BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); + host_file = cfi->cfi_container; + + coda_vfs_stat.readdir++; + + host_inode = host_file->f_dentry->d_inode; + down(&host_inode->i_sem); + host_file->f_pos = coda_file->f_pos; + + if (!host_file->f_op->readdir) { + /* Venus: we must read Venus dirents from the file */ + ret = coda_venus_readdir(host_file, filldir, dirent, coda_dentry); + } else { + /* potemkin case: we were handed a directory inode. */ + /* Yuk, we can't call vfs_readdir because we are already + * holding the inode semaphore. */ + ret = -ENOTDIR; + if (!host_file->f_op || !host_file->f_op->readdir) + goto out; + + ret = -ENOENT; + if (!IS_DEADDIR(host_inode)) { + ret = host_file->f_op->readdir(host_file, filldir, dirent); + file_accessed(host_file); + } + } +out: + coda_file->f_pos = host_file->f_pos; + up(&host_inode->i_sem); + + return ret; +} + +static inline unsigned int CDT2DT(unsigned char cdt) +{ + unsigned int dt; + + switch(cdt) { + case CDT_UNKNOWN: dt = DT_UNKNOWN; break; + case CDT_FIFO: dt = DT_FIFO; break; + case CDT_CHR: dt = DT_CHR; break; + case CDT_DIR: dt = DT_DIR; break; + case CDT_BLK: dt = DT_BLK; break; + case CDT_REG: dt = DT_REG; break; + case CDT_LNK: dt = DT_LNK; break; + case CDT_SOCK: dt = DT_SOCK; break; + case CDT_WHT: dt = DT_WHT; break; + default: dt = DT_UNKNOWN; break; + } + return dt; +} + +/* support routines */ +static int coda_venus_readdir(struct file *filp, filldir_t filldir, + void *dirent, struct dentry *dir) +{ + int result = 0; /* # of entries returned */ + struct venus_dirent *vdir; + unsigned long vdir_size = + (unsigned long)(&((struct venus_dirent *)0)->d_name); + unsigned int type; + struct qstr name; + ino_t ino; + int ret, i; + + vdir = (struct venus_dirent *)kmalloc(sizeof(*vdir), GFP_KERNEL); + if (!vdir) return -ENOMEM; + + i = filp->f_pos; + switch(i) { + case 0: + ret = filldir(dirent, ".", 1, 0, dir->d_inode->i_ino, DT_DIR); + if (ret < 0) break; + result++; + filp->f_pos++; + /* fallthrough */ + case 1: + ret = filldir(dirent, "..", 2, 1, dir->d_parent->d_inode->i_ino, DT_DIR); + if (ret < 0) break; + result++; + filp->f_pos++; + /* fallthrough */ + default: + while (1) { + /* read entries from the directory file */ + ret = kernel_read(filp, filp->f_pos - 2, (char *)vdir, + sizeof(*vdir)); + if (ret < 0) { + printk("coda_venus_readdir: read dir failed %d\n", ret); + break; + } + if (ret == 0) break; /* end of directory file reached */ + + /* catch truncated reads */ + if (ret < vdir_size || ret < vdir_size + vdir->d_namlen) { + printk("coda_venus_readdir: short read: %ld\n", + filp->f_dentry->d_inode->i_ino); + ret = -EBADF; + break; + } + /* validate whether the directory file actually makes sense */ + if (vdir->d_reclen < vdir_size + vdir->d_namlen) { + printk("coda_venus_readdir: Invalid dir: %ld\n", + filp->f_dentry->d_inode->i_ino); + ret = -EBADF; + break; + } + + name.len = vdir->d_namlen; + name.name = vdir->d_name; + + /* Make sure we skip '.' and '..', we already got those */ + if (name.name[0] == '.' && (name.len == 1 || + (vdir->d_name[1] == '.' && name.len == 2))) + vdir->d_fileno = name.len = 0; + + /* skip null entries */ + if (vdir->d_fileno && name.len) { + /* try to look up this entry in the dcache, that way + * use |