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/vs_tag.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_IMMUTABLE_FL |
61 JFS_IUNLINK_FL | JFS_BARRIER_FL);
63 if (IS_IMMUTABLE(inode))
64 newflags |= JFS_IMMUTABLE_FL;
65 if (IS_IUNLINK(inode))
66 newflags |= JFS_IUNLINK_FL;
67 if (IS_BARRIER(inode))
68 newflags |= JFS_BARRIER_FL;
70 if (oldflags ^ newflags) {
71 JFS_IP(inode)->mode2 = newflags;
72 inode->i_ctime = CURRENT_TIME;
73 mark_inode_dirty(inode);
81 * FUNCTION: Allocate a new inode
84 struct inode *ialloc(struct inode *parent, umode_t mode)
86 struct super_block *sb = parent->i_sb;
88 struct jfs_inode_info *jfs_inode;
91 inode = new_inode(sb);
93 jfs_warn("ialloc: new_inode returned NULL!");
94 return ERR_PTR(-ENOMEM);
97 jfs_inode = JFS_IP(inode);
99 rc = diAlloc(parent, S_ISDIR(mode), inode);
101 jfs_warn("ialloc: diAlloc returned %d!", rc);
103 make_bad_inode(inode);
108 inode->i_uid = current->fsuid;
109 if (parent->i_mode & S_ISGID) {
110 inode->i_gid = parent->i_gid;
114 inode->i_gid = current->fsgid;
117 * New inodes need to save sane values on disk when
118 * uid & gid mount options are used
120 jfs_inode->saved_uid = inode->i_uid;
121 jfs_inode->saved_gid = inode->i_gid;
123 inode->i_tag = dx_current_fstag(sb);
124 if (DLIMIT_ALLOC_INODE(inode)) {
130 * Allocate inode to quota.
132 if (DQUOT_ALLOC_INODE(inode)) {
133 DLIMIT_FREE_INODE(inode);
135 inode->i_flags |= S_NOQUOTA;
138 return ERR_PTR(-EDQUOT);
141 inode->i_mode = mode;
142 /* inherit flags from parent */
143 jfs_inode->mode2 = JFS_IP(parent)->mode2 & JFS_FL_INHERIT;
146 jfs_inode->mode2 |= IDIRECTORY;
147 jfs_inode->mode2 &= ~JFS_DIRSYNC_FL;
150 jfs_inode->mode2 |= INLINEEA | ISPARSE;
152 jfs_inode->mode2 &= ~(JFS_IMMUTABLE_FL|JFS_APPEND_FL);
154 jfs_inode->mode2 |= mode;
157 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
158 jfs_inode->otime = inode->i_ctime.tv_sec;
159 inode->i_generation = JFS_SBI(sb)->gengen++;
161 jfs_inode->cflag = 0;
163 /* Zero remaining fields */
164 memset(&jfs_inode->acl, 0, sizeof(dxd_t));
165 memset(&jfs_inode->ea, 0, sizeof(dxd_t));
166 jfs_inode->next_index = 0;
167 jfs_inode->acltype = 0;
168 jfs_inode->btorder = 0;
169 jfs_inode->btindex = 0;
170 jfs_inode->bxflag = 0;
172 jfs_inode->atlhead = 0;
173 jfs_inode->atltail = 0;
174 jfs_inode->xtlid = 0;
175 jfs_set_inode_flags(inode);
177 jfs_info("ialloc returns inode = 0x%p\n", inode);