2 * Copyright (C) International Business Machines Corp., 2000-2004
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.
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.
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
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"
27 #include "jfs_dinode.h"
28 #include "jfs_debug.h"
31 void jfs_set_inode_flags(struct inode *inode)
33 unsigned int flags = JFS_IP(inode)->mode2;
35 inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
36 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
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;
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;
55 int jfs_sync_flags(struct inode *inode)
57 unsigned int oldflags, newflags;
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);
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;
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;
82 if (oldflags ^ newflags) {
83 JFS_IP(inode)->mode2 = newflags;
84 inode->i_ctime = CURRENT_TIME;
85 mark_inode_dirty(inode);
93 * FUNCTION: Allocate a new inode
96 struct inode *ialloc(struct inode *parent, umode_t mode)
98 struct super_block *sb = parent->i_sb;
100 struct jfs_inode_info *jfs_inode;
103 inode = new_inode(sb);
105 jfs_warn("ialloc: new_inode returned NULL!");
109 jfs_inode = JFS_IP(inode);
111 rc = diAlloc(parent, S_ISDIR(mode), inode);
113 jfs_warn("ialloc: diAlloc returned %d!", rc);
114 make_bad_inode(inode);
119 inode->i_uid = current->fsuid;
120 if (parent->i_mode & S_ISGID) {
121 inode->i_gid = parent->i_gid;
125 inode->i_gid = current->fsgid;
128 * New inodes need to save sane values on disk when
129 * uid & gid mount options are used
131 jfs_inode->saved_uid = inode->i_uid;
132 jfs_inode->saved_gid = inode->i_gid;
134 inode->i_xid = vx_current_fsxid(sb);
135 if (DLIMIT_ALLOC_INODE(inode)) {
141 * Allocate inode to quota.
143 if (DQUOT_ALLOC_INODE(inode)) {
144 DLIMIT_FREE_INODE(inode);
146 inode->i_flags |= S_NOQUOTA;
152 inode->i_mode = mode;
153 /* inherit flags from parent */
154 jfs_inode->mode2 = JFS_IP(parent)->mode2 & JFS_FL_INHERIT;
157 jfs_inode->mode2 |= IDIRECTORY;
158 jfs_inode->mode2 &= ~JFS_DIRSYNC_FL;
161 jfs_inode->mode2 |= INLINEEA | ISPARSE;
163 jfs_inode->mode2 &= ~(JFS_IMMUTABLE_FL|JFS_APPEND_FL);
165 jfs_inode->mode2 |= mode;
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++;
172 jfs_inode->cflag = 0;
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;
183 jfs_inode->atlhead = 0;
184 jfs_inode->atltail = 0;
185 jfs_inode->xtlid = 0;
186 jfs_set_inode_flags(inode);
188 jfs_info("ialloc returns inode = 0x%p\n", inode);