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