Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / fs / jfs / jfs_inode.c
1 /*
2  *   Copyright (C) International Business Machines Corp., 2000-2004
3  *
4  *   This program is free software;  you can redistribute it and/or modify
5  *   it under the terms of the GNU General Public License as published by
6  *   the Free Software Foundation; either version 2 of the License, or 
7  *   (at your option) any later version.
8  * 
9  *   This program is distributed in the hope that it will be useful,
10  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
12  *   the GNU General Public License for more details.
13  *
14  *   You should have received a copy of the GNU General Public License
15  *   along with this program;  if not, write to the Free Software 
16  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18
19 #include <linux/fs.h>
20 #include <linux/quotaops.h>
21 #include <linux/vs_dlimit.h>
22 #include <linux/vserver/xid.h>
23 #include "jfs_incore.h"
24 #include "jfs_inode.h"
25 #include "jfs_filsys.h"
26 #include "jfs_imap.h"
27 #include "jfs_dinode.h"
28 #include "jfs_debug.h"
29
30
31 void jfs_set_inode_flags(struct inode *inode)
32 {
33         unsigned int flags = JFS_IP(inode)->mode2;
34
35         inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
36                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
37
38         if (flags & JFS_IMMUTABLE_FL)
39                 inode->i_flags |= S_IMMUTABLE;
40         if (flags & JFS_IUNLINK_FL)
41                 inode->i_flags |= S_IUNLINK;
42         if (flags & JFS_BARRIER_FL)
43                 inode->i_flags |= S_BARRIER;
44
45         if (flags & JFS_SYNC_FL)
46                 inode->i_flags |= S_SYNC;
47         if (flags & JFS_APPEND_FL)
48                 inode->i_flags |= S_APPEND;
49         if (flags & JFS_NOATIME_FL)
50                 inode->i_flags |= S_NOATIME;
51         if (flags & JFS_DIRSYNC_FL)
52                 inode->i_flags |= S_DIRSYNC;
53 }
54
55 int jfs_sync_flags(struct inode *inode)
56 {
57         unsigned int oldflags, newflags;
58
59         oldflags = JFS_IP(inode)->mode2;
60         newflags = oldflags & ~(JFS_APPEND_FL |
61                 JFS_IMMUTABLE_FL | JFS_IUNLINK_FL |
62                 JFS_BARRIER_FL | JFS_NOATIME_FL |
63                 JFS_SYNC_FL | JFS_DIRSYNC_FL);
64
65         if (IS_APPEND(inode))
66                 newflags |= JFS_APPEND_FL;
67         if (IS_IMMUTABLE(inode))
68                 newflags |= JFS_IMMUTABLE_FL;
69         if (IS_IUNLINK(inode))
70                 newflags |= JFS_IUNLINK_FL;
71         if (IS_BARRIER(inode))
72                 newflags |= JFS_BARRIER_FL;
73
74         /* we do not want to copy superblock flags */
75         if (inode->i_flags & S_NOATIME)
76                 newflags |= JFS_NOATIME_FL;
77         if (inode->i_flags & S_SYNC)
78                 newflags |= JFS_SYNC_FL;
79         if (inode->i_flags & S_DIRSYNC)
80                 newflags |= JFS_DIRSYNC_FL;
81
82         if (oldflags ^ newflags) {
83                 JFS_IP(inode)->mode2 = newflags;
84                 inode->i_ctime = CURRENT_TIME;
85                 mark_inode_dirty(inode);
86         }
87         return 0;
88 }
89
90 /*
91  * NAME:        ialloc()
92  *
93  * FUNCTION:    Allocate a new inode
94  *
95  */
96 struct inode *ialloc(struct inode *parent, umode_t mode)
97 {
98         struct super_block *sb = parent->i_sb;
99         struct inode *inode;
100         struct jfs_inode_info *jfs_inode;
101         int rc;
102
103         inode = new_inode(sb);
104         if (!inode) {
105                 jfs_warn("ialloc: new_inode returned NULL!");
106                 return inode;
107         }
108
109         jfs_inode = JFS_IP(inode);
110
111         rc = diAlloc(parent, S_ISDIR(mode), inode);
112         if (rc) {
113                 jfs_warn("ialloc: diAlloc returned %d!", rc);
114                 make_bad_inode(inode);
115                 iput(inode);
116                 return NULL;
117         }
118
119         inode->i_uid = current->fsuid;
120         if (parent->i_mode & S_ISGID) {
121                 inode->i_gid = parent->i_gid;
122                 if (S_ISDIR(mode))
123                         mode |= S_ISGID;
124         } else
125                 inode->i_gid = current->fsgid;
126
127         /*
128          * New inodes need to save sane values on disk when
129          * uid & gid mount options are used
130          */
131         jfs_inode->saved_uid = inode->i_uid;
132         jfs_inode->saved_gid = inode->i_gid;
133
134         inode->i_xid = vx_current_fsxid(sb);
135         if (DLIMIT_ALLOC_INODE(inode)) {
136                 iput(inode);
137                 return NULL;
138         }
139
140         /*
141          * Allocate inode to quota.
142          */
143         if (DQUOT_ALLOC_INODE(inode)) {
144                 DLIMIT_FREE_INODE(inode);
145                 DQUOT_DROP(inode);
146                 inode->i_flags |= S_NOQUOTA;
147                 inode->i_nlink = 0;
148                 iput(inode);
149                 return NULL;
150         }
151
152         inode->i_mode = mode;
153         /* inherit flags from parent */
154         jfs_inode->mode2 = JFS_IP(parent)->mode2 & JFS_FL_INHERIT;
155
156         if (S_ISDIR(mode)) {
157                 jfs_inode->mode2 |= IDIRECTORY;
158                 jfs_inode->mode2 &= ~JFS_DIRSYNC_FL;
159         }
160         else {
161                 jfs_inode->mode2 |= INLINEEA | ISPARSE;
162                 if (S_ISLNK(mode))
163                         jfs_inode->mode2 &= ~(JFS_IMMUTABLE_FL|JFS_APPEND_FL);
164         }
165         jfs_inode->mode2 |= mode;
166
167         inode->i_blocks = 0;
168         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
169         jfs_inode->otime = inode->i_ctime.tv_sec;
170         inode->i_generation = JFS_SBI(sb)->gengen++;
171
172         jfs_inode->cflag = 0;
173
174         /* Zero remaining fields */
175         memset(&jfs_inode->acl, 0, sizeof(dxd_t));
176         memset(&jfs_inode->ea, 0, sizeof(dxd_t));
177         jfs_inode->next_index = 0;
178         jfs_inode->acltype = 0;
179         jfs_inode->btorder = 0;
180         jfs_inode->btindex = 0;
181         jfs_inode->bxflag = 0;
182         jfs_inode->blid = 0;
183         jfs_inode->atlhead = 0;
184         jfs_inode->atltail = 0;
185         jfs_inode->xtlid = 0;
186         jfs_set_inode_flags(inode);
187
188         jfs_info("ialloc returns inode = 0x%p\n", inode);
189
190         return inode;
191 }