jfs_inode.c 3.55 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5
/*
 *   Copyright (C) International Business Machines Corp., 2000-2004
 *
 *   This program is free software;  you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
Dave Kleikamp's avatar
Dave Kleikamp committed
6
 *   the Free Software Foundation; either version 2 of the License, or
Linus Torvalds's avatar
Linus Torvalds committed
7
 *   (at your option) any later version.
Dave Kleikamp's avatar
Dave Kleikamp committed
8
 *
Linus Torvalds's avatar
Linus Torvalds committed
9 10 11 12 13 14
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 *   the GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
Dave Kleikamp's avatar
Dave Kleikamp committed
15
 *   along with this program;  if not, write to the Free Software
Linus Torvalds's avatar
Linus Torvalds committed
16 17 18 19 20 21
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <linux/fs.h>
#include <linux/quotaops.h>
#include "jfs_incore.h"
22
#include "jfs_inode.h"
Linus Torvalds's avatar
Linus Torvalds committed
23 24 25 26 27
#include "jfs_filsys.h"
#include "jfs_imap.h"
#include "jfs_dinode.h"
#include "jfs_debug.h"

28 29 30 31

void jfs_set_inode_flags(struct inode *inode)
{
	unsigned int flags = JFS_IP(inode)->mode2;
32
	unsigned int new_fl = 0;
33 34

	if (flags & JFS_IMMUTABLE_FL)
35
		new_fl |= S_IMMUTABLE;
36
	if (flags & JFS_APPEND_FL)
37
		new_fl |= S_APPEND;
38
	if (flags & JFS_NOATIME_FL)
39
		new_fl |= S_NOATIME;
40
	if (flags & JFS_DIRSYNC_FL)
41
		new_fl |= S_DIRSYNC;
42
	if (flags & JFS_SYNC_FL)
43 44 45
		new_fl |= S_SYNC;
	inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND | S_NOATIME |
			S_DIRSYNC | S_SYNC);
46 47
}

Linus Torvalds's avatar
Linus Torvalds committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
/*
 * NAME:	ialloc()
 *
 * FUNCTION:	Allocate a new inode
 *
 */
struct inode *ialloc(struct inode *parent, umode_t mode)
{
	struct super_block *sb = parent->i_sb;
	struct inode *inode;
	struct jfs_inode_info *jfs_inode;
	int rc;

	inode = new_inode(sb);
	if (!inode) {
		jfs_warn("ialloc: new_inode returned NULL!");
Dave Kleikamp's avatar
Dave Kleikamp committed
64 65
		rc = -ENOMEM;
		goto fail;
Linus Torvalds's avatar
Linus Torvalds committed
66 67 68 69 70 71 72
	}

	jfs_inode = JFS_IP(inode);

	rc = diAlloc(parent, S_ISDIR(mode), inode);
	if (rc) {
		jfs_warn("ialloc: diAlloc returned %d!", rc);
73 74
		if (rc == -EIO)
			make_bad_inode(inode);
Dave Kleikamp's avatar
Dave Kleikamp committed
75 76 77 78 79
		goto fail_put;
	}

	if (insert_inode_locked(inode) < 0) {
		rc = -EINVAL;
80
		goto fail_put;
Linus Torvalds's avatar
Linus Torvalds committed
81 82
	}

83
	inode_init_owner(inode, parent, mode);
84 85 86 87 88 89 90
	/*
	 * New inodes need to save sane values on disk when
	 * uid & gid mount options are used
	 */
	jfs_inode->saved_uid = inode->i_uid;
	jfs_inode->saved_gid = inode->i_gid;

Linus Torvalds's avatar
Linus Torvalds committed
91 92 93
	/*
	 * Allocate inode to quota.
	 */
94 95 96
	rc = dquot_initialize(inode);
	if (rc)
		goto fail_drop;
97 98
	rc = dquot_alloc_inode(inode);
	if (rc)
Dave Kleikamp's avatar
Dave Kleikamp committed
99
		goto fail_drop;
Linus Torvalds's avatar
Linus Torvalds committed
100

101 102 103 104 105 106 107
	/* inherit flags from parent */
	jfs_inode->mode2 = JFS_IP(parent)->mode2 & JFS_FL_INHERIT;

	if (S_ISDIR(mode)) {
		jfs_inode->mode2 |= IDIRECTORY;
		jfs_inode->mode2 &= ~JFS_DIRSYNC_FL;
	}
108
	else {
109
		jfs_inode->mode2 |= INLINEEA | ISPARSE;
110 111 112
		if (S_ISLNK(mode))
			jfs_inode->mode2 &= ~(JFS_IMMUTABLE_FL|JFS_APPEND_FL);
	}
113
	jfs_inode->mode2 |= inode->i_mode;
114

Linus Torvalds's avatar
Linus Torvalds committed
115
	inode->i_blocks = 0;
116
	inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
Linus Torvalds's avatar
Linus Torvalds committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
	jfs_inode->otime = inode->i_ctime.tv_sec;
	inode->i_generation = JFS_SBI(sb)->gengen++;

	jfs_inode->cflag = 0;

	/* Zero remaining fields */
	memset(&jfs_inode->acl, 0, sizeof(dxd_t));
	memset(&jfs_inode->ea, 0, sizeof(dxd_t));
	jfs_inode->next_index = 0;
	jfs_inode->acltype = 0;
	jfs_inode->btorder = 0;
	jfs_inode->btindex = 0;
	jfs_inode->bxflag = 0;
	jfs_inode->blid = 0;
	jfs_inode->atlhead = 0;
	jfs_inode->atltail = 0;
	jfs_inode->xtlid = 0;
134
	jfs_set_inode_flags(inode);
Linus Torvalds's avatar
Linus Torvalds committed
135

136
	jfs_info("ialloc returns inode = 0x%p", inode);
Linus Torvalds's avatar
Linus Torvalds committed
137 138

	return inode;
Dave Kleikamp's avatar
Dave Kleikamp committed
139 140

fail_drop:
141
	dquot_drop(inode);
Dave Kleikamp's avatar
Dave Kleikamp committed
142
	inode->i_flags |= S_NOQUOTA;
143
	clear_nlink(inode);
Dave Kleikamp's avatar
Dave Kleikamp committed
144 145 146 147 148
	unlock_new_inode(inode);
fail_put:
	iput(inode);
fail:
	return ERR_PTR(rc);
Linus Torvalds's avatar
Linus Torvalds committed
149
}