Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | /* * Extended attribute handling for presto. * * Copyright (C) 2001. All rights reserved. * Shirish H. Phatak * Tacit Networks, Inc. * */ #define __NO_VERSION__ #include <linux/module.h> #include <linux/kernel.h> #include <linux/mm.h> #include <linux/string.h> #include <linux/stat.h> #include <linux/errno.h> #include <linux/locks.h> #include <linux/unistd.h> #include <asm/system.h> #include <asm/uaccess.h> #include <linux/fs.h> #include <linux/stat.h> #include <linux/errno.h> #include <linux/locks.h> #include <linux/string.h> #include <asm/uaccess.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/smp_lock.h> #include <linux/intermezzo_fs.h> #include <linux/intermezzo_upcall.h> #include <linux/intermezzo_psdev.h> #include <linux/intermezzo_kml.h> #ifdef CONFIG_FS_EXT_ATTR #include <linux/ext_attr.h> extern inline void presto_debug_fail_blkdev(struct presto_file_set *fset, unsigned long value); extern int presto_prep(struct dentry *, struct presto_cache **, struct presto_file_set **); /* VFS interface */ /* XXX! Fixme test for user defined attributes */ int presto_set_ext_attr(struct inode *inode, const char *name, void *buffer, size_t buffer_len, int flags) { int error; struct presto_cache *cache; struct presto_file_set *fset; struct lento_vfs_context info; struct dentry *dentry; int minor = presto_i2m(inode); char *buf = NULL; ENTRY; if (minor < 0) { EXIT; return -1; } if ( ISLENTO(minor) ) { EXIT; return -EINVAL; } /* BAD...vfs should really pass down the dentry to use, especially * since every other operation in iops does. But for now * we do a reverse mapping from inode to the first dentry */ if (list_empty(&inode->i_dentry)) { printk("No alias for inode %d\n", (int) inode->i_ino); EXIT; return -EINVAL; } dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias); error = presto_prep(dentry, &cache, &fset); if ( error ) { EXIT; return error; } if ((buffer != NULL) && (buffer_len != 0)) { /* If buffer is a user space pointer copy it to kernel space * and reset the flag. We do this since the journal functions need * access to the contents of the buffer, and the file system * does not care. When we actually invoke the function, we remove * the EXT_ATTR_FLAG_USER flag. * * XXX:Check if the "fs does not care" assertion is always true -SHP * (works for ext3) */ if (flags & EXT_ATTR_FLAG_USER) { PRESTO_ALLOC(buf, char *, buffer_len); if (!buf) { printk("InterMezzo: out of memory!!!\n"); return -ENOMEM; } error = copy_from_user(buf, buffer, buffer_len); if (error) return error; } else buf = buffer; } else buf = buffer; if ( presto_get_permit(inode) < 0 ) { EXIT; if (buffer_len && (flags & EXT_ATTR_FLAG_USER)) PRESTO_FREE(buf, buffer_len); return -EROFS; } /* Simulate presto_setup_info */ memset(&info, 0, sizeof(info)); /* For now redundant..but we keep it around just in case */ info.flags = LENTO_FL_IGNORE_TIME; if (!ISLENTO(cache->cache_psdev->uc_minor)) info.flags |= LENTO_FL_KML; /* We pass in the kernel space pointer and reset the * EXT_ATTR_FLAG_USER flag. * See comments above. */ /* Note that mode is already set by VFS so we send in a NULL */ error = presto_do_set_ext_attr(fset, dentry, name, buf, buffer_len, flags & ~EXT_ATTR_FLAG_USER, NULL, &info); presto_put_permit(inode); if (buffer_len && (flags & EXT_ATTR_FLAG_USER)) PRESTO_FREE(buf, buffer_len); EXIT; return error; } /* Lento Interface */ /* XXX: ignore flags? We should be forcing these operations through? -SHP*/ int lento_set_ext_attr(const char *path, const char *name, void *buffer, size_t buffer_len, int flags, mode_t mode, struct lento_vfs_context *info) { int error; char * pathname; struct nameidata nd; struct dentry *dentry; struct presto_file_set *fset; ENTRY; lock_kernel(); pathname=getname(path); error = PTR_ERR(pathname); if (IS_ERR(pathname)) { EXIT; goto exit; } /* Note that ext_attrs apply to both files and directories..*/ error=presto_walk(pathname,&nd); if (error) goto exit; dentry = nd.dentry; fset = presto_fset(dentry); error = -EINVAL; if ( !fset ) { printk("No fileset!\n"); EXIT; goto exit_dentry; } if (buffer==NULL) buffer_len=0; error = presto_do_set_ext_attr(fset, dentry, name, buffer, buffer_len, flags, &mode, info); exit_dentry: path_release(&nd); exit_path: putname(pathname); exit: unlock_kernel(); return error; } #endif /*CONFIG_FS_EXT_ATTR*/ |