blob: 2352a75bd9d6902da50cb317581ad922a7a185f3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/fs/affs/inode.c
4 *
5 * (c) 1996 Hans-Joachim Widmaier - Rewritten
6 *
7 * (C) 1993 Ray Burr - Modified for Amiga FFS filesystem.
8 *
9 * (C) 1992 Eric Youngdale Modified for ISO9660 filesystem.
10 *
11 * (C) 1991 Linus Torvalds - minix filesystem
12 */
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040013#include <linux/sched.h>
Ingo Molnar5b825c32017-02-02 17:54:15 +010014#include <linux/cred.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include "affs.h"
17
David Howells210f8552008-02-07 00:15:29 -080018struct inode *affs_iget(struct super_block *sb, unsigned long ino)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019{
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 struct affs_sb_info *sbi = AFFS_SB(sb);
21 struct buffer_head *bh;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 struct affs_tail *tail;
David Howells210f8552008-02-07 00:15:29 -080023 struct inode *inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 u32 block;
25 u32 size;
26 u32 prot;
27 u16 id;
28
David Howells210f8552008-02-07 00:15:29 -080029 inode = iget_locked(sb, ino);
30 if (!inode)
31 return ERR_PTR(-ENOMEM);
32 if (!(inode->i_state & I_NEW))
33 return inode;
34
Fabian Frederick9606d9a2014-06-06 14:37:25 -070035 pr_debug("affs_iget(%lu)\n", inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 block = inode->i_ino;
38 bh = affs_bread(sb, block);
39 if (!bh) {
40 affs_warning(sb, "read_inode", "Cannot read block %d", block);
41 goto bad_inode;
42 }
43 if (affs_checksum_block(sb, bh) || be32_to_cpu(AFFS_HEAD(bh)->ptype) != T_SHORT) {
44 affs_warning(sb,"read_inode",
45 "Checksum or type (ptype=%d) error on inode %d",
46 AFFS_HEAD(bh)->ptype, block);
47 goto bad_inode;
48 }
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 tail = AFFS_TAIL(sb, bh);
51 prot = be32_to_cpu(tail->protect);
52
53 inode->i_size = 0;
Miklos Szeredibfe86842011-10-28 14:13:29 +020054 set_nlink(inode, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 inode->i_mode = 0;
56 AFFS_I(inode)->i_extcnt = 1;
57 AFFS_I(inode)->i_ext_last = ~1;
58 AFFS_I(inode)->i_protect = prot;
Roman Zippeldca3c332008-04-29 17:02:20 +020059 atomic_set(&AFFS_I(inode)->i_opencnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 AFFS_I(inode)->i_blkcnt = 0;
61 AFFS_I(inode)->i_lc = NULL;
62 AFFS_I(inode)->i_lc_size = 0;
63 AFFS_I(inode)->i_lc_shift = 0;
64 AFFS_I(inode)->i_lc_mask = 0;
65 AFFS_I(inode)->i_ac = NULL;
66 AFFS_I(inode)->i_ext_bh = NULL;
67 AFFS_I(inode)->mmu_private = 0;
68 AFFS_I(inode)->i_lastalloc = 0;
69 AFFS_I(inode)->i_pa_cnt = 0;
70
Fabian Frederick79bda4d2015-04-16 12:48:24 -070071 if (affs_test_opt(sbi->s_flags, SF_SETMODE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 inode->i_mode = sbi->s_mode;
73 else
Fabian Frederickc1618202017-02-27 14:27:54 -080074 inode->i_mode = affs_prot_to_mode(prot);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 id = be16_to_cpu(tail->uid);
Fabian Frederick79bda4d2015-04-16 12:48:24 -070077 if (id == 0 || affs_test_opt(sbi->s_flags, SF_SETUID))
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 inode->i_uid = sbi->s_uid;
Fabian Frederick79bda4d2015-04-16 12:48:24 -070079 else if (id == 0xFFFF && affs_test_opt(sbi->s_flags, SF_MUFS))
Eric W. Biederman8fed10b2012-02-07 16:20:16 -080080 i_uid_write(inode, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 else
Eric W. Biederman8fed10b2012-02-07 16:20:16 -080082 i_uid_write(inode, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 id = be16_to_cpu(tail->gid);
Fabian Frederick79bda4d2015-04-16 12:48:24 -070085 if (id == 0 || affs_test_opt(sbi->s_flags, SF_SETGID))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 inode->i_gid = sbi->s_gid;
Fabian Frederick79bda4d2015-04-16 12:48:24 -070087 else if (id == 0xFFFF && affs_test_opt(sbi->s_flags, SF_MUFS))
Eric W. Biederman8fed10b2012-02-07 16:20:16 -080088 i_gid_write(inode, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 else
Eric W. Biederman8fed10b2012-02-07 16:20:16 -080090 i_gid_write(inode, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 switch (be32_to_cpu(tail->stype)) {
93 case ST_ROOT:
94 inode->i_uid = sbi->s_uid;
95 inode->i_gid = sbi->s_gid;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -050096 fallthrough;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 case ST_USERDIR:
98 if (be32_to_cpu(tail->stype) == ST_USERDIR ||
Fabian Frederick79bda4d2015-04-16 12:48:24 -070099 affs_test_opt(sbi->s_flags, SF_SETMODE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 if (inode->i_mode & S_IRUSR)
101 inode->i_mode |= S_IXUSR;
102 if (inode->i_mode & S_IRGRP)
103 inode->i_mode |= S_IXGRP;
104 if (inode->i_mode & S_IROTH)
105 inode->i_mode |= S_IXOTH;
106 inode->i_mode |= S_IFDIR;
107 } else
108 inode->i_mode = S_IRUGO | S_IXUGO | S_IWUSR | S_IFDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 /* Maybe it should be controlled by mount parameter? */
110 //inode->i_mode |= S_ISVTX;
111 inode->i_op = &affs_dir_inode_operations;
112 inode->i_fop = &affs_dir_operations;
113 break;
114 case ST_LINKDIR:
115#if 0
116 affs_warning(sb, "read_inode", "inode is LINKDIR");
117 goto bad_inode;
118#else
119 inode->i_mode |= S_IFDIR;
Al Viroc765d472008-12-04 09:50:55 -0500120 /* ... and leave ->i_op and ->i_fop pointing to empty */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 break;
122#endif
123 case ST_LINKFILE:
124 affs_warning(sb, "read_inode", "inode is LINKFILE");
125 goto bad_inode;
126 case ST_FILE:
127 size = be32_to_cpu(tail->size);
128 inode->i_mode |= S_IFREG;
129 AFFS_I(inode)->mmu_private = inode->i_size = size;
130 if (inode->i_size) {
131 AFFS_I(inode)->i_blkcnt = (size - 1) /
132 sbi->s_data_blksize + 1;
133 AFFS_I(inode)->i_extcnt = (AFFS_I(inode)->i_blkcnt - 1) /
134 sbi->s_hashsize + 1;
135 }
136 if (tail->link_chain)
Miklos Szeredibfe86842011-10-28 14:13:29 +0200137 set_nlink(inode, 2);
Fabian Frederick79bda4d2015-04-16 12:48:24 -0700138 inode->i_mapping->a_ops = affs_test_opt(sbi->s_flags, SF_OFS) ?
Fabian Fredericka0016ff2015-04-16 12:48:15 -0700139 &affs_aops_ofs : &affs_aops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 inode->i_op = &affs_file_inode_operations;
141 inode->i_fop = &affs_file_operations;
142 break;
143 case ST_SOFTLINK:
Fabian Frederickf1bf9072017-04-15 08:54:36 +0200144 inode->i_size = strlen((char *)AFFS_HEAD(bh)->table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 inode->i_mode |= S_IFLNK;
Al Viro21fc61c2015-11-17 01:07:57 -0500146 inode_nohighmem(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 inode->i_op = &affs_symlink_inode_operations;
148 inode->i_data.a_ops = &affs_symlink_aops;
149 break;
150 }
151
152 inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec
Deepa Dinamani487b25b2019-03-21 14:05:12 -0700153 = (be32_to_cpu(tail->change.days) * 86400LL +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 be32_to_cpu(tail->change.mins) * 60 +
155 be32_to_cpu(tail->change.ticks) / 50 +
Deepa Dinamani487b25b2019-03-21 14:05:12 -0700156 AFFS_EPOCH_DELTA) +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 sys_tz.tz_minuteswest * 60;
158 inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec = inode->i_atime.tv_nsec = 0;
159 affs_brelse(bh);
David Howells210f8552008-02-07 00:15:29 -0800160 unlock_new_inode(inode);
161 return inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163bad_inode:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 affs_brelse(bh);
David Howells210f8552008-02-07 00:15:29 -0800165 iget_failed(inode);
166 return ERR_PTR(-EIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167}
168
169int
Christoph Hellwiga9185b42010-03-05 09:21:37 +0100170affs_write_inode(struct inode *inode, struct writeback_control *wbc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
172 struct super_block *sb = inode->i_sb;
173 struct buffer_head *bh;
174 struct affs_tail *tail;
175 uid_t uid;
176 gid_t gid;
177
Fabian Frederick9606d9a2014-06-06 14:37:25 -0700178 pr_debug("write_inode(%lu)\n", inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 if (!inode->i_nlink)
181 // possibly free block
182 return 0;
183 bh = affs_bread(sb, inode->i_ino);
184 if (!bh) {
185 affs_error(sb,"write_inode","Cannot read block %lu",inode->i_ino);
186 return -EIO;
187 }
188 tail = AFFS_TAIL(sb, bh);
189 if (tail->stype == cpu_to_be32(ST_ROOT)) {
Fabian Frederickc1618202017-02-27 14:27:54 -0800190 affs_secs_to_datestamp(inode->i_mtime.tv_sec,
191 &AFFS_ROOT_TAIL(sb, bh)->root_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 } else {
193 tail->protect = cpu_to_be32(AFFS_I(inode)->i_protect);
194 tail->size = cpu_to_be32(inode->i_size);
Fabian Frederickc1618202017-02-27 14:27:54 -0800195 affs_secs_to_datestamp(inode->i_mtime.tv_sec, &tail->change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 if (!(inode->i_ino == AFFS_SB(sb)->s_root_block)) {
Eric W. Biederman8fed10b2012-02-07 16:20:16 -0800197 uid = i_uid_read(inode);
198 gid = i_gid_read(inode);
Fabian Frederick79bda4d2015-04-16 12:48:24 -0700199 if (affs_test_opt(AFFS_SB(sb)->s_flags, SF_MUFS)) {
Eric W. Biederman8fed10b2012-02-07 16:20:16 -0800200 if (uid == 0 || uid == 0xFFFF)
201 uid = uid ^ ~0;
202 if (gid == 0 || gid == 0xFFFF)
203 gid = gid ^ ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 }
Fabian Frederick79bda4d2015-04-16 12:48:24 -0700205 if (!affs_test_opt(AFFS_SB(sb)->s_flags, SF_SETUID))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 tail->uid = cpu_to_be16(uid);
Fabian Frederick79bda4d2015-04-16 12:48:24 -0700207 if (!affs_test_opt(AFFS_SB(sb)->s_flags, SF_SETGID))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 tail->gid = cpu_to_be16(gid);
209 }
210 }
211 affs_fix_checksum(sb, bh);
212 mark_buffer_dirty_inode(bh, inode);
213 affs_brelse(bh);
214 affs_free_prealloc(inode);
215 return 0;
216}
217
218int
Christian Brauner549c7292021-01-21 14:19:43 +0100219affs_notify_change(struct user_namespace *mnt_userns, struct dentry *dentry,
220 struct iattr *attr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
David Howells2b0143b2015-03-17 22:25:59 +0000222 struct inode *inode = d_inode(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 int error;
224
Fabian Frederick9606d9a2014-06-06 14:37:25 -0700225 pr_debug("notify_change(%lu,0x%x)\n", inode->i_ino, attr->ia_valid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Christian Brauner2f221d62021-01-21 14:19:26 +0100227 error = setattr_prepare(&init_user_ns, dentry, attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (error)
229 goto out;
230
Fabian Fredericka0016ff2015-04-16 12:48:15 -0700231 if (((attr->ia_valid & ATTR_UID) &&
Fabian Frederick79bda4d2015-04-16 12:48:24 -0700232 affs_test_opt(AFFS_SB(inode->i_sb)->s_flags, SF_SETUID)) ||
Fabian Fredericka0016ff2015-04-16 12:48:15 -0700233 ((attr->ia_valid & ATTR_GID) &&
Fabian Frederick79bda4d2015-04-16 12:48:24 -0700234 affs_test_opt(AFFS_SB(inode->i_sb)->s_flags, SF_SETGID)) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 ((attr->ia_valid & ATTR_MODE) &&
Fabian Fredericka0016ff2015-04-16 12:48:15 -0700236 (AFFS_SB(inode->i_sb)->s_flags &
237 (AFFS_MOUNT_SF_SETMODE | AFFS_MOUNT_SF_IMMUTABLE)))) {
Fabian Frederick79bda4d2015-04-16 12:48:24 -0700238 if (!affs_test_opt(AFFS_SB(inode->i_sb)->s_flags, SF_QUIET))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 error = -EPERM;
240 goto out;
241 }
242
Christoph Hellwig10257742010-06-04 11:30:02 +0200243 if ((attr->ia_valid & ATTR_SIZE) &&
244 attr->ia_size != i_size_read(inode)) {
Marco Stornelli1dc18342012-12-15 11:51:53 +0100245 error = inode_newsize_ok(inode, attr->ia_size);
Christoph Hellwig10257742010-06-04 11:30:02 +0200246 if (error)
247 return error;
Marco Stornelli1dc18342012-12-15 11:51:53 +0100248
249 truncate_setsize(inode, attr->ia_size);
250 affs_truncate(inode);
Christoph Hellwig10257742010-06-04 11:30:02 +0200251 }
252
Christian Brauner2f221d62021-01-21 14:19:26 +0100253 setattr_copy(&init_user_ns, inode, attr);
Christoph Hellwig10257742010-06-04 11:30:02 +0200254 mark_inode_dirty(inode);
255
256 if (attr->ia_valid & ATTR_MODE)
Fabian Frederickc1618202017-02-27 14:27:54 -0800257 affs_mode_to_prot(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258out:
259 return error;
260}
261
262void
Al Virof053ddd2010-06-06 10:16:41 -0400263affs_evict_inode(struct inode *inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Roman Zippeldca3c332008-04-29 17:02:20 +0200265 unsigned long cache_page;
Fabian Frederick9606d9a2014-06-06 14:37:25 -0700266 pr_debug("evict_inode(ino=%lu, nlink=%u)\n",
267 inode->i_ino, inode->i_nlink);
Johannes Weiner91b0abe2014-04-03 14:47:49 -0700268 truncate_inode_pages_final(&inode->i_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Al Virof053ddd2010-06-06 10:16:41 -0400270 if (!inode->i_nlink) {
271 inode->i_size = 0;
272 affs_truncate(inode);
273 }
Roman Zippeldca3c332008-04-29 17:02:20 +0200274
Al Virof053ddd2010-06-06 10:16:41 -0400275 invalidate_inode_buffers(inode);
Jan Karadbd57682012-05-03 14:48:02 +0200276 clear_inode(inode);
Roman Zippeldca3c332008-04-29 17:02:20 +0200277 affs_free_prealloc(inode);
278 cache_page = (unsigned long)AFFS_I(inode)->i_lc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 if (cache_page) {
Fabian Frederick9606d9a2014-06-06 14:37:25 -0700280 pr_debug("freeing ext cache\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 AFFS_I(inode)->i_lc = NULL;
282 AFFS_I(inode)->i_ac = NULL;
283 free_page(cache_page);
284 }
285 affs_brelse(AFFS_I(inode)->i_ext_bh);
286 AFFS_I(inode)->i_ext_last = ~1;
287 AFFS_I(inode)->i_ext_bh = NULL;
Al Virof053ddd2010-06-06 10:16:41 -0400288
289 if (!inode->i_nlink)
290 affs_free_block(inode->i_sb, inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
292
293struct inode *
294affs_new_inode(struct inode *dir)
295{
296 struct super_block *sb = dir->i_sb;
297 struct inode *inode;
298 u32 block;
299 struct buffer_head *bh;
300
301 if (!(inode = new_inode(sb)))
302 goto err_inode;
303
304 if (!(block = affs_alloc_block(dir, dir->i_ino)))
305 goto err_block;
306
307 bh = affs_getzeroblk(sb, block);
308 if (!bh)
309 goto err_bh;
310 mark_buffer_dirty_inode(bh, inode);
311 affs_brelse(bh);
312
David Howells21559982008-11-14 10:38:45 +1100313 inode->i_uid = current_fsuid();
314 inode->i_gid = current_fsgid();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 inode->i_ino = block;
Miklos Szeredibfe86842011-10-28 14:13:29 +0200316 set_nlink(inode, 1);
Deepa Dinamani02027d42016-09-14 07:48:05 -0700317 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
Roman Zippeldca3c332008-04-29 17:02:20 +0200318 atomic_set(&AFFS_I(inode)->i_opencnt, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 AFFS_I(inode)->i_blkcnt = 0;
320 AFFS_I(inode)->i_lc = NULL;
321 AFFS_I(inode)->i_lc_size = 0;
322 AFFS_I(inode)->i_lc_shift = 0;
323 AFFS_I(inode)->i_lc_mask = 0;
324 AFFS_I(inode)->i_ac = NULL;
325 AFFS_I(inode)->i_ext_bh = NULL;
326 AFFS_I(inode)->mmu_private = 0;
327 AFFS_I(inode)->i_protect = 0;
328 AFFS_I(inode)->i_lastalloc = 0;
329 AFFS_I(inode)->i_pa_cnt = 0;
330 AFFS_I(inode)->i_extcnt = 1;
331 AFFS_I(inode)->i_ext_last = ~1;
332
333 insert_inode_hash(inode);
334
335 return inode;
336
337err_bh:
338 affs_free_block(sb, block);
339err_block:
340 iput(inode);
341err_inode:
342 return NULL;
343}
344
345/*
346 * Add an entry to a directory. Create the header block
347 * and insert it into the hash table.
348 */
349
350int
351affs_add_entry(struct inode *dir, struct inode *inode, struct dentry *dentry, s32 type)
352{
353 struct super_block *sb = dir->i_sb;
354 struct buffer_head *inode_bh = NULL;
Fabian Frederick78f444f2015-06-30 14:57:55 -0700355 struct buffer_head *bh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 u32 block = 0;
357 int retval;
358
Geert Uytterhoeven08fe1002015-02-17 13:46:10 -0800359 pr_debug("%s(dir=%lu, inode=%lu, \"%pd\", type=%d)\n", __func__,
360 dir->i_ino, inode->i_ino, dentry, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 retval = -EIO;
363 bh = affs_bread(sb, inode->i_ino);
364 if (!bh)
365 goto done;
366
367 affs_lock_link(inode);
368 switch (type) {
369 case ST_LINKFILE:
370 case ST_LINKDIR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 retval = -ENOSPC;
372 block = affs_alloc_block(dir, dir->i_ino);
373 if (!block)
374 goto err;
375 retval = -EIO;
Roman Zippeldca3c332008-04-29 17:02:20 +0200376 inode_bh = bh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 bh = affs_getzeroblk(sb, block);
378 if (!bh)
379 goto err;
380 break;
381 default:
382 break;
383 }
384
385 AFFS_HEAD(bh)->ptype = cpu_to_be32(T_SHORT);
386 AFFS_HEAD(bh)->key = cpu_to_be32(bh->b_blocknr);
387 affs_copy_name(AFFS_TAIL(sb, bh)->name, dentry);
388 AFFS_TAIL(sb, bh)->stype = cpu_to_be32(type);
389 AFFS_TAIL(sb, bh)->parent = cpu_to_be32(dir->i_ino);
390
391 if (inode_bh) {
392 __be32 chain;
393 chain = AFFS_TAIL(sb, inode_bh)->link_chain;
394 AFFS_TAIL(sb, bh)->original = cpu_to_be32(inode->i_ino);
395 AFFS_TAIL(sb, bh)->link_chain = chain;
396 AFFS_TAIL(sb, inode_bh)->link_chain = cpu_to_be32(block);
397 affs_adjust_checksum(inode_bh, block - be32_to_cpu(chain));
398 mark_buffer_dirty_inode(inode_bh, inode);
Miklos Szeredibfe86842011-10-28 14:13:29 +0200399 set_nlink(inode, 2);
Al Viro7de9c6ee2010-10-23 11:11:40 -0400400 ihold(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
402 affs_fix_checksum(sb, bh);
403 mark_buffer_dirty_inode(bh, inode);
404 dentry->d_fsdata = (void *)(long)bh->b_blocknr;
405
406 affs_lock_dir(dir);
407 retval = affs_insert_hash(dir, bh);
408 mark_buffer_dirty_inode(bh, inode);
409 affs_unlock_dir(dir);
410 affs_unlock_link(inode);
411
412 d_instantiate(dentry, inode);
413done:
414 affs_brelse(inode_bh);
415 affs_brelse(bh);
416 return retval;
417err:
418 if (block)
419 affs_free_block(sb, block);
420 affs_unlock_link(inode);
421 goto done;
422}