1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
9 * Copyright (C) 1992, 1993, 1994, 1995
10 * Remy Card (card@masi.ibp.fr)
11 * Laboratoire MASI - Institut Blaise Pascal
12 * Universite Pierre et Marie Curie (Paris VI)
16 * linux/fs/minix/file.c
18 * Copyright (C) 1991, 1992 Linus Torvalds
20 * ext2 fs regular file handling primitives
22 * 64-bit file support on 64-bit platforms by Jakub Jelinek
23 * (jj@sunsite.ms.mff.cuni.cz)
26 #include <asm/uaccess.h>
27 #include <asm/system.h>
29 #include <linux/errno.h>
31 #include <linux/fcntl.h>
32 #include <linux/sched.h>
33 #include <linux/stat.h>
34 #include <linux/locks.h>
36 #include <linux/pagemap.h>
37 #include <linux/smp_lock.h>
39 #define DEBUG_SUBSYSTEM S_LLITE
41 #include <linux/obd_support.h>
42 #include <linux/lustre_lite.h>
44 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc);
45 extern int ll_setattr(struct dentry *de, struct iattr *attr);
46 extern inline struct obdo * ll_oa_from_inode(struct inode *inode, int valid);
48 static int ll_file_open(struct inode *inode, struct file *file)
51 struct ptlrpc_request *req = NULL;
52 struct ll_file_data *fd;
54 struct ll_sb_info *sbi = ll_i2sbi(inode);
57 if (file->private_data)
60 fd = kmem_cache_alloc(ll_file_data_slab, SLAB_KERNEL);
62 GOTO(out, rc = -ENOMEM);
63 memset(fd, 0, sizeof(*fd));
65 rc = mdc_open(&sbi->ll_mds_client, sbi->ll_mds_conn, inode->i_ino,
66 S_IFREG, file->f_flags, &fd->fd_mdshandle, &req);
67 if (!fd->fd_mdshandle)
68 CERROR("mdc_open didn't assign fd_mdshandle\n");
77 oa = ll_oa_from_inode(inode, (OBD_MD_FLMODE | OBD_MD_FLID));
80 rc = obd_open(ll_i2obdconn(inode), oa);
83 /* XXX: Need to do mdc_close here! */
89 file->private_data = fd;
94 kmem_cache_free(ll_file_data_slab, fd);
95 file->private_data = NULL;
101 static int ll_file_release(struct inode *inode, struct file *file)
104 struct ptlrpc_request *req = NULL;
105 struct ll_file_data *fd;
107 struct ll_sb_info *sbi = ll_i2sbi(inode);
112 fd = (struct ll_file_data *)file->private_data;
113 if (!fd || !fd->fd_mdshandle) {
115 GOTO(out, rc = -EINVAL);
118 oa = ll_oa_from_inode(inode, (OBD_MD_FLMODE | OBD_MD_FLID));
121 rc = obd_close(ll_i2obdconn(inode), oa);
129 iattr.ia_valid = ATTR_SIZE;
130 iattr.ia_size = inode->i_size;
131 rc = ll_inode_setattr(inode, &iattr, 0);
133 CERROR("failed - %d.\n", rc);
137 rc = mdc_close(&sbi->ll_mds_client, sbi->ll_mds_conn, inode->i_ino,
138 S_IFREG, fd->fd_mdshandle, &req);
139 ptlrpc_free_req(req);
149 kmem_cache_free(ll_file_data_slab, fd);
150 file->private_data = NULL;
156 static inline void ll_remove_suid(struct inode *inode)
160 /* set S_IGID if S_IXGRP is set, and always set S_ISUID */
161 mode = (inode->i_mode & S_IXGRP)*(S_ISGID/S_IXGRP) | S_ISUID;
163 /* was any of the uid bits set? */
164 mode &= inode->i_mode;
165 if (mode && !capable(CAP_FSETID)) {
166 inode->i_mode &= ~mode;
167 // XXX careful here - we cannot change the size
173 * Write to a file (through the page cache).
176 ll_file_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
179 CDEBUG(D_INFO, "Writing inode %ld, %ld bytes, offset %Ld\n",
180 file->f_dentry->d_inode->i_ino, (long)count, *ppos);
182 retval = generic_file_write(file, buf, count, ppos);
183 CDEBUG(D_INFO, "Wrote %ld\n", (long)retval);
185 /* update mtime/ctime/atime here, NOT size */
188 attr.ia_valid = ATTR_MTIME | ATTR_CTIME | ATTR_ATIME;
189 attr.ia_mtime = attr.ia_ctime = attr.ia_atime =
191 ll_setattr(file->f_dentry, &attr);
198 /* XXX this does not need to do anything for data, it _does_ need to
200 int ll_fsync(struct file *file, struct dentry *dentry, int data)
205 struct file_operations ll_file_operations = {
206 read: generic_file_read,
207 write: ll_file_write,
209 release: ll_file_release,
210 mmap: generic_file_mmap,
215 struct inode_operations ll_file_inode_operations = {
216 truncate: ll_truncate,