xref: /openbmc/linux/fs/jfs/jfs_inode.c (revision 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2)
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 "jfs_incore.h"
22 #include "jfs_filsys.h"
23 #include "jfs_imap.h"
24 #include "jfs_dinode.h"
25 #include "jfs_debug.h"
26 
27 /*
28  * NAME:	ialloc()
29  *
30  * FUNCTION:	Allocate a new inode
31  *
32  */
33 struct inode *ialloc(struct inode *parent, umode_t mode)
34 {
35 	struct super_block *sb = parent->i_sb;
36 	struct inode *inode;
37 	struct jfs_inode_info *jfs_inode;
38 	int rc;
39 
40 	inode = new_inode(sb);
41 	if (!inode) {
42 		jfs_warn("ialloc: new_inode returned NULL!");
43 		return inode;
44 	}
45 
46 	jfs_inode = JFS_IP(inode);
47 
48 	rc = diAlloc(parent, S_ISDIR(mode), inode);
49 	if (rc) {
50 		jfs_warn("ialloc: diAlloc returned %d!", rc);
51 		make_bad_inode(inode);
52 		iput(inode);
53 		return NULL;
54 	}
55 
56 	inode->i_uid = current->fsuid;
57 	if (parent->i_mode & S_ISGID) {
58 		inode->i_gid = parent->i_gid;
59 		if (S_ISDIR(mode))
60 			mode |= S_ISGID;
61 	} else
62 		inode->i_gid = current->fsgid;
63 
64 	/*
65 	 * Allocate inode to quota.
66 	 */
67 	if (DQUOT_ALLOC_INODE(inode)) {
68 		DQUOT_DROP(inode);
69 		inode->i_flags |= S_NOQUOTA;
70 		inode->i_nlink = 0;
71 		iput(inode);
72 		return NULL;
73 	}
74 
75 	inode->i_mode = mode;
76 	if (S_ISDIR(mode))
77 		jfs_inode->mode2 = IDIRECTORY | mode;
78 	else
79 		jfs_inode->mode2 = INLINEEA | ISPARSE | mode;
80 	inode->i_blksize = sb->s_blocksize;
81 	inode->i_blocks = 0;
82 	inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
83 	jfs_inode->otime = inode->i_ctime.tv_sec;
84 	inode->i_generation = JFS_SBI(sb)->gengen++;
85 
86 	jfs_inode->cflag = 0;
87 
88 	/* Zero remaining fields */
89 	memset(&jfs_inode->acl, 0, sizeof(dxd_t));
90 	memset(&jfs_inode->ea, 0, sizeof(dxd_t));
91 	jfs_inode->next_index = 0;
92 	jfs_inode->acltype = 0;
93 	jfs_inode->btorder = 0;
94 	jfs_inode->btindex = 0;
95 	jfs_inode->bxflag = 0;
96 	jfs_inode->blid = 0;
97 	jfs_inode->atlhead = 0;
98 	jfs_inode->atltail = 0;
99 	jfs_inode->xtlid = 0;
100 
101 	jfs_info("ialloc returns inode = 0x%p\n", inode);
102 
103 	return inode;
104 }
105