Whamcloud - gitweb
f6abf6fc9e7997ee69d037f3d4380b5abed8bda5
[fs/lustre-release.git] / lustre / obdfs / file.c
1 /*
2  *  linux/fs/ext2/file.c
3  *
4  * This code is issued under the GNU General Public License.
5  * See the file COPYING in this distribution
6  *
7  * Copyright (C) 1992, 1993, 1994, 1995
8  * Remy Card (card@masi.ibp.fr)
9  * Laboratoire MASI - Institut Blaise Pascal
10  * Universite Pierre et Marie Curie (Paris VI)
11  *
12  *  from
13  *
14  *  linux/fs/minix/file.c
15  *
16  *  Copyright (C) 1991, 1992  Linus Torvalds
17  *
18  *  ext2 fs regular file handling primitives
19  *
20  *  64-bit file support on 64-bit platforms by Jakub Jelinek
21  *      (jj@sunsite.ms.mff.cuni.cz)
22  */
23
24 #include <asm/uaccess.h>
25 #include <asm/system.h>
26
27 #include <linux/errno.h>
28 #include <linux/fs.h>
29 #include <linux/fcntl.h>
30 #include <linux/sched.h>
31 #include <linux/stat.h>
32 #include <linux/locks.h>
33 #include <linux/mm.h>
34 #include <linux/pagemap.h>
35 #include <linux/smp_lock.h>
36
37 #include <linux/obd_support.h>
38 #include <linux/obdfs.h>
39
40 extern int obdfs_setattr(struct dentry *de, struct iattr *attr);
41 void obdfs_change_inode(struct inode *inode);
42
43 static inline void obdfs_remove_suid(struct inode *inode)
44 {
45         unsigned int mode;
46
47         /* set S_IGID if S_IXGRP is set, and always set S_ISUID */
48         mode = (inode->i_mode & S_IXGRP)*(S_ISGID/S_IXGRP) | S_ISUID;
49
50         /* was any of the uid bits set? */
51         mode &= inode->i_mode;
52         if (mode && !capable(CAP_FSETID)) {
53                 inode->i_mode &= ~mode;
54                 // XXX careful here - we cannot change the size
55                 //obdfs_change_inode(inode);
56         }
57 }
58
59 /*
60  * Write to a file (through the page cache).
61  */
62 static ssize_t
63 obdfs_file_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
64 {
65         ssize_t retval;
66         CDEBUG(D_INFO, "Writing inode %ld, %d bytes, offset %ld\n",
67                file->f_dentry->d_inode->i_ino, count, (long)*ppos);
68
69         retval = generic_file_write(file, buf, count, ppos);
70         CDEBUG(D_INFO, "Wrote %d\n", retval);
71
72         /* update mtime/ctime/atime here, NOT size */
73         if (retval > 0) {
74                 struct iattr attr;
75                 attr.ia_valid = ATTR_MTIME | ATTR_CTIME | ATTR_ATIME;
76                 attr.ia_mtime = attr.ia_ctime = attr.ia_atime =
77                         CURRENT_TIME;
78                 obdfs_setattr(file->f_dentry, &attr);
79         }
80         EXIT;
81         return retval;
82 }
83
84
85 /* XXX this does not need to do anything for data, it _does_ need to
86    call setattr */ 
87 int obdfs_fsync(struct file *file, struct dentry *dentry, int data)
88 {
89         return 0;
90 }
91
92 struct file_operations obdfs_file_operations = {
93         read: generic_file_read,
94         write: obdfs_file_write,
95         mmap: generic_file_mmap,
96         fsync: NULL
97 };
98
99
100 struct inode_operations obdfs_file_inode_operations = {
101         truncate: obdfs_truncate,
102         setattr: obdfs_setattr
103 };
104