1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001 Tacit Networks, Inc.
5 * Author: Shirish H. Phatak <shirish@tacitnetworks.com>
7 * This file is part of InterMezzo, http://www.inter-mezzo.org.
9 * InterMezzo is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * InterMezzo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with InterMezzo; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Extended attribute handling for presto.
25 #include <linux/module.h>
26 #include <linux/kernel.h>
28 #include <linux/string.h>
29 #include <linux/stat.h>
30 #include <linux/errno.h>
31 #include <linux/unistd.h>
33 #include <asm/system.h>
34 #include <asm/uaccess.h>
37 #include <linux/slab.h>
38 #include <linux/vmalloc.h>
39 #include <asm/segment.h>
41 #include "intermezzo_fs.h"
42 #include "intermezzo_psdev.h"
44 #ifdef CONFIG_FS_EXT_ATTR
45 #include <linux/ext_attr.h>
47 extern inline void presto_debug_fail_blkdev(struct presto_file_set *fset,
52 /* XXX! Fixme test for user defined attributes */
53 int presto_set_ext_attr(struct inode *inode,
54 const char *name, void *buffer,
55 size_t buffer_len, int flags)
58 struct presto_cache *cache;
59 struct presto_file_set *fset;
60 struct lento_vfs_context info;
61 struct dentry *dentry;
62 int minor = presto_i2m(inode);
71 if ( ISLENTO(minor) ) {
76 /* BAD...vfs should really pass down the dentry to use, especially
77 * since every other operation in iops does. But for now
78 * we do a reverse mapping from inode to the first dentry
80 if (list_empty(&inode->i_dentry)) {
81 CERROR("No alias for inode %d\n", (int) inode->i_ino);
86 dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
88 error = presto_prep(dentry, &cache, &fset);
94 if ((buffer != NULL) && (buffer_len != 0)) {
95 /* If buffer is a user space pointer copy it to kernel space
96 * and reset the flag. We do this since the journal functions need
97 * access to the contents of the buffer, and the file system
98 * does not care. When we actually invoke the function, we remove
99 * the EXT_ATTR_FLAG_USER flag.
101 * XXX:Check if the "fs does not care" assertion is always true -SHP
104 if (flags & EXT_ATTR_FLAG_USER) {
105 PRESTO_ALLOC(buf, buffer_len);
107 CERROR("InterMezzo: out of memory!!!\n");
110 error = copy_from_user(buf, buffer, buffer_len);
118 if ( presto_get_permit(inode) < 0 ) {
120 if (buffer_len && (flags & EXT_ATTR_FLAG_USER))
121 PRESTO_FREE(buf, buffer_len);
125 /* Simulate presto_setup_info */
126 memset(&info, 0, sizeof(info));
127 /* For now redundant..but we keep it around just in case */
128 info.flags = LENTO_FL_IGNORE_TIME;
129 if (!ISLENTO(cache->cache_psdev->uc_minor))
130 info.flags |= LENTO_FL_KML;
132 /* We pass in the kernel space pointer and reset the
133 * EXT_ATTR_FLAG_USER flag.
134 * See comments above.
136 /* Note that mode is already set by VFS so we send in a NULL */
137 error = presto_do_set_ext_attr(fset, dentry, name, buf,
138 buffer_len, flags & ~EXT_ATTR_FLAG_USER,
140 presto_put_permit(inode);
142 if (buffer_len && (flags & EXT_ATTR_FLAG_USER))
143 PRESTO_FREE(buf, buffer_len);
148 /* Lento Interface */
149 /* XXX: ignore flags? We should be forcing these operations through? -SHP*/
150 int lento_set_ext_attr(const char *path, const char *name,
151 void *buffer, size_t buffer_len, int flags, mode_t mode,
152 struct lento_vfs_context *info)
157 struct dentry *dentry;
158 struct presto_file_set *fset;
163 pathname=getname(path);
164 error = PTR_ERR(pathname);
165 if (IS_ERR(pathname)) {
170 /* Note that ext_attrs apply to both files and directories..*/
171 error=presto_walk(pathname,&nd);
176 fset = presto_fset(dentry);
179 CERROR("No fileset!\n");
184 if (buffer==NULL) buffer_len=0;
186 error = presto_do_set_ext_attr(fset, dentry, name, buffer,
187 buffer_len, flags, &mode, info);
197 #endif /*CONFIG_FS_EXT_ATTR*/