[PATCH] x86-64 update
[linux-2.6/history.git] / fs / jfs / file.c
blobcfc55c2d230abccad3151b21fc4e20fbdc7726aa
1 /*
2 * Copyright (c) International Business Machines Corp., 2000-2002
3 * Portions Copyright (c) Christoph Hellwig, 2001-2002
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/fs.h>
21 #include "jfs_incore.h"
22 #include "jfs_dmap.h"
23 #include "jfs_txnmgr.h"
24 #include "jfs_xattr.h"
25 #include "jfs_acl.h"
26 #include "jfs_debug.h"
29 extern int jfs_commit_inode(struct inode *, int);
30 extern void jfs_truncate(struct inode *);
32 int jfs_fsync(struct file *file, struct dentry *dentry, int datasync)
34 struct inode *inode = dentry->d_inode;
35 int rc = 0;
37 if (!(inode->i_state & I_DIRTY))
38 return rc;
39 if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
40 return rc;
42 rc |= jfs_commit_inode(inode, 1);
44 return rc ? -EIO : 0;
47 static int jfs_open(struct inode *inode, struct file *file)
49 int rc;
51 if ((rc = generic_file_open(inode, file)))
52 return rc;
55 * We attempt to allow only one "active" file open per aggregate
56 * group. Otherwise, appending to files in parallel can cause
57 * fragmentation within the files.
59 * If the file is empty, it was probably just created and going
60 * to be written to. If it has a size, we'll hold off until the
61 * file is actually grown.
63 if (S_ISREG(inode->i_mode) && file->f_mode & FMODE_WRITE &&
64 (inode->i_size == 0)) {
65 struct jfs_inode_info *ji = JFS_IP(inode);
66 if (ji->active_ag == -1) {
67 ji->active_ag = ji->agno;
68 atomic_inc(
69 &JFS_SBI(inode->i_sb)->bmap->db_active[ji->agno]);
73 return 0;
75 static int jfs_release(struct inode *inode, struct file *file)
77 struct jfs_inode_info *ji = JFS_IP(inode);
79 if (ji->active_ag != -1) {
80 struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap;
81 atomic_dec(&bmap->db_active[ji->active_ag]);
82 ji->active_ag = -1;
85 return 0;
88 struct inode_operations jfs_file_inode_operations = {
89 .truncate = jfs_truncate,
90 .setxattr = jfs_setxattr,
91 .getxattr = jfs_getxattr,
92 .listxattr = jfs_listxattr,
93 .removexattr = jfs_removexattr,
94 #ifdef CONFIG_JFS_POSIX_ACL
95 .setattr = jfs_setattr,
96 .permission = jfs_permission,
97 #endif
100 struct file_operations jfs_file_operations = {
101 .open = jfs_open,
102 .llseek = generic_file_llseek,
103 .write = generic_file_write,
104 .read = generic_file_read,
105 .aio_read = generic_file_aio_read,
106 .aio_write = generic_file_aio_write,
107 .mmap = generic_file_mmap,
108 .readv = generic_file_readv,
109 .writev = generic_file_writev,
110 .sendfile = generic_file_sendfile,
111 .fsync = jfs_fsync,
112 .release = jfs_release,