dir.c 13.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 *  linux/fs/hfsplus/dir.c
 *
 * Copyright (C) 2001
 * Brad Boyer (flar@allandria.com)
 * (C) 2003 Ardis Technologies <roman@ardistech.com>
 *
 * Handling of directories
 */

#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/random.h>
15
#include <linux/nls.h>
L
Linus Torvalds 已提交
16 17 18

#include "hfsplus_fs.h"
#include "hfsplus_raw.h"
19
#include "xattr.h"
20
#include "acl.h"
L
Linus Torvalds 已提交
21 22 23 24 25 26 27 28 29 30

static inline void hfsplus_instantiate(struct dentry *dentry,
				       struct inode *inode, u32 cnid)
{
	dentry->d_fsdata = (void *)(unsigned long)cnid;
	d_instantiate(dentry, inode);
}

/* Find the entry inside dir named dentry->d_name */
static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,
A
Al Viro 已提交
31
				     unsigned int flags)
L
Linus Torvalds 已提交
32 33 34 35 36 37 38 39 40 41
{
	struct inode *inode = NULL;
	struct hfs_find_data fd;
	struct super_block *sb;
	hfsplus_cat_entry entry;
	int err;
	u32 cnid, linkid = 0;
	u16 type;

	sb = dir->i_sb;
42

L
Linus Torvalds 已提交
43
	dentry->d_fsdata = NULL;
44 45 46
	err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
	if (err)
		return ERR_PTR(err);
S
Sougata Santra 已提交
47 48 49 50
	err = hfsplus_cat_build_key(sb, fd.search_key, dir->i_ino,
			&dentry->d_name);
	if (unlikely(err < 0))
		goto fail;
L
Linus Torvalds 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
again:
	err = hfs_brec_read(&fd, &entry, sizeof(entry));
	if (err) {
		if (err == -ENOENT) {
			hfs_find_exit(&fd);
			/* No such entry */
			inode = NULL;
			goto out;
		}
		goto fail;
	}
	type = be16_to_cpu(entry.type);
	if (type == HFSPLUS_FOLDER) {
		if (fd.entrylength < sizeof(struct hfsplus_cat_folder)) {
			err = -EIO;
			goto fail;
		}
		cnid = be32_to_cpu(entry.folder.id);
		dentry->d_fsdata = (void *)(unsigned long)cnid;
	} else if (type == HFSPLUS_FILE) {
		if (fd.entrylength < sizeof(struct hfsplus_cat_file)) {
			err = -EIO;
			goto fail;
		}
		cnid = be32_to_cpu(entry.file.id);
76 77 78 79 80 81 82 83
		if (entry.file.user_info.fdType ==
				cpu_to_be32(HFSP_HARDLINK_TYPE) &&
				entry.file.user_info.fdCreator ==
				cpu_to_be32(HFSP_HFSPLUS_CREATOR) &&
				(entry.file.create_date ==
					HFSPLUS_I(HFSPLUS_SB(sb)->hidden_dir)->
						create_date ||
				entry.file.create_date ==
84
					HFSPLUS_I(d_inode(sb->s_root))->
85 86
						create_date) &&
				HFSPLUS_SB(sb)->hidden_dir) {
L
Linus Torvalds 已提交
87 88 89 90
			struct qstr str;
			char name[32];

			if (dentry->d_fsdata) {
91 92 93 94 95 96 97 98
				/*
				 * We found a link pointing to another link,
				 * so ignore it and treat it as regular file.
				 */
				cnid = (unsigned long)dentry->d_fsdata;
				linkid = 0;
			} else {
				dentry->d_fsdata = (void *)(unsigned long)cnid;
99 100
				linkid =
					be32_to_cpu(entry.file.permissions.dev);
101 102
				str.len = sprintf(name, "iNode%d", linkid);
				str.name = name;
S
Sougata Santra 已提交
103
				err = hfsplus_cat_build_key(sb, fd.search_key,
104 105
					HFSPLUS_SB(sb)->hidden_dir->i_ino,
					&str);
S
Sougata Santra 已提交
106 107
				if (unlikely(err < 0))
					goto fail;
108
				goto again;
L
Linus Torvalds 已提交
109 110 111 112
			}
		} else if (!dentry->d_fsdata)
			dentry->d_fsdata = (void *)(unsigned long)cnid;
	} else {
113
		pr_err("invalid catalog entry type in lookup\n");
L
Linus Torvalds 已提交
114 115 116 117
		err = -EIO;
		goto fail;
	}
	hfs_find_exit(&fd);
118 119 120
	inode = hfsplus_iget(dir->i_sb, cnid);
	if (IS_ERR(inode))
		return ERR_CAST(inode);
L
Linus Torvalds 已提交
121
	if (S_ISREG(inode->i_mode))
C
Christoph Hellwig 已提交
122
		HFSPLUS_I(inode)->linkid = linkid;
L
Linus Torvalds 已提交
123 124 125 126 127 128 129 130
out:
	d_add(dentry, inode);
	return NULL;
fail:
	hfs_find_exit(&fd);
	return ERR_PTR(err);
}

A
Al Viro 已提交
131
static int hfsplus_readdir(struct file *file, struct dir_context *ctx)
L
Linus Torvalds 已提交
132
{
A
Al Viro 已提交
133
	struct inode *inode = file_inode(file);
L
Linus Torvalds 已提交
134 135
	struct super_block *sb = inode->i_sb;
	int len, err;
136
	char *strbuf;
L
Linus Torvalds 已提交
137 138 139 140 141
	hfsplus_cat_entry entry;
	struct hfs_find_data fd;
	struct hfsplus_readdir_data *rd;
	u16 type;

A
Al Viro 已提交
142
	if (file->f_pos >= inode->i_size)
L
Linus Torvalds 已提交
143 144
		return 0;

145 146 147
	err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
	if (err)
		return err;
148 149 150 151 152
	strbuf = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_MAX_STRLEN + 1, GFP_KERNEL);
	if (!strbuf) {
		err = -ENOMEM;
		goto out;
	}
S
Sougata Santra 已提交
153
	hfsplus_cat_build_key_with_cnid(sb, fd.search_key, inode->i_ino);
154
	err = hfs_brec_find(&fd, hfs_find_rec_by_key);
L
Linus Torvalds 已提交
155 156 157
	if (err)
		goto out;

A
Al Viro 已提交
158
	if (ctx->pos == 0) {
L
Linus Torvalds 已提交
159
		/* This is completely artificial... */
A
Al Viro 已提交
160
		if (!dir_emit_dot(file, ctx))
L
Linus Torvalds 已提交
161
			goto out;
A
Al Viro 已提交
162 163 164
		ctx->pos = 1;
	}
	if (ctx->pos == 1) {
165 166 167 168 169
		if (fd.entrylength > sizeof(entry) || fd.entrylength < 0) {
			err = -EIO;
			goto out;
		}

170 171
		hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
			fd.entrylength);
L
Linus Torvalds 已提交
172
		if (be16_to_cpu(entry.type) != HFSPLUS_FOLDER_THREAD) {
173
			pr_err("bad catalog folder thread\n");
L
Linus Torvalds 已提交
174 175 176 177
			err = -EIO;
			goto out;
		}
		if (fd.entrylength < HFSPLUS_MIN_THREAD_SZ) {
178
			pr_err("truncated catalog thread\n");
L
Linus Torvalds 已提交
179 180 181
			err = -EIO;
			goto out;
		}
A
Al Viro 已提交
182
		if (!dir_emit(ctx, "..", 2,
L
Linus Torvalds 已提交
183 184
			    be32_to_cpu(entry.thread.parentID), DT_DIR))
			goto out;
A
Al Viro 已提交
185
		ctx->pos = 2;
L
Linus Torvalds 已提交
186
	}
A
Al Viro 已提交
187 188 189 190 191
	if (ctx->pos >= inode->i_size)
		goto out;
	err = hfs_brec_goto(&fd, ctx->pos - 1);
	if (err)
		goto out;
L
Linus Torvalds 已提交
192 193
	for (;;) {
		if (be32_to_cpu(fd.key->cat.parent) != inode->i_ino) {
194
			pr_err("walked past end of dir\n");
L
Linus Torvalds 已提交
195 196 197
			err = -EIO;
			goto out;
		}
198 199 200 201 202 203

		if (fd.entrylength > sizeof(entry) || fd.entrylength < 0) {
			err = -EIO;
			goto out;
		}

204 205
		hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
			fd.entrylength);
L
Linus Torvalds 已提交
206
		type = be16_to_cpu(entry.type);
207
		len = NLS_MAX_CHARSET_SIZE * HFSPLUS_MAX_STRLEN;
L
Linus Torvalds 已提交
208 209 210 211
		err = hfsplus_uni2asc(sb, &fd.key->cat.name, strbuf, &len);
		if (err)
			goto out;
		if (type == HFSPLUS_FOLDER) {
212 213
			if (fd.entrylength <
					sizeof(struct hfsplus_cat_folder)) {
214
				pr_err("small dir entry\n");
L
Linus Torvalds 已提交
215 216 217
				err = -EIO;
				goto out;
			}
218 219 220
			if (HFSPLUS_SB(sb)->hidden_dir &&
			    HFSPLUS_SB(sb)->hidden_dir->i_ino ==
					be32_to_cpu(entry.folder.id))
L
Linus Torvalds 已提交
221
				goto next;
A
Al Viro 已提交
222
			if (!dir_emit(ctx, strbuf, len,
L
Linus Torvalds 已提交
223 224 225
				    be32_to_cpu(entry.folder.id), DT_DIR))
				break;
		} else if (type == HFSPLUS_FILE) {
226 227 228
			u16 mode;
			unsigned type = DT_UNKNOWN;

L
Linus Torvalds 已提交
229
			if (fd.entrylength < sizeof(struct hfsplus_cat_file)) {
230
				pr_err("small file entry\n");
L
Linus Torvalds 已提交
231 232 233
				err = -EIO;
				goto out;
			}
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248

			mode = be16_to_cpu(entry.file.permissions.mode);
			if (S_ISREG(mode))
				type = DT_REG;
			else if (S_ISLNK(mode))
				type = DT_LNK;
			else if (S_ISFIFO(mode))
				type = DT_FIFO;
			else if (S_ISCHR(mode))
				type = DT_CHR;
			else if (S_ISBLK(mode))
				type = DT_BLK;
			else if (S_ISSOCK(mode))
				type = DT_SOCK;

A
Al Viro 已提交
249
			if (!dir_emit(ctx, strbuf, len,
250
				      be32_to_cpu(entry.file.id), type))
L
Linus Torvalds 已提交
251 252
				break;
		} else {
253
			pr_err("bad catalog entry type\n");
L
Linus Torvalds 已提交
254 255 256
			err = -EIO;
			goto out;
		}
257
next:
A
Al Viro 已提交
258 259
		ctx->pos++;
		if (ctx->pos >= inode->i_size)
L
Linus Torvalds 已提交
260 261 262 263 264
			goto out;
		err = hfs_brec_goto(&fd, 1);
		if (err)
			goto out;
	}
A
Al Viro 已提交
265
	rd = file->private_data;
L
Linus Torvalds 已提交
266 267 268 269 270 271
	if (!rd) {
		rd = kmalloc(sizeof(struct hfsplus_readdir_data), GFP_KERNEL);
		if (!rd) {
			err = -ENOMEM;
			goto out;
		}
A
Al Viro 已提交
272 273
		file->private_data = rd;
		rd->file = file;
A
Al Viro 已提交
274
		spin_lock(&HFSPLUS_I(inode)->open_dir_lock);
275
		list_add(&rd->list, &HFSPLUS_I(inode)->open_dir_list);
A
Al Viro 已提交
276
		spin_unlock(&HFSPLUS_I(inode)->open_dir_lock);
L
Linus Torvalds 已提交
277
	}
A
Al Viro 已提交
278 279 280 281
	/*
	 * Can be done after the list insertion; exclusion with
	 * hfsplus_delete_cat() is provided by directory lock.
	 */
L
Linus Torvalds 已提交
282 283
	memcpy(&rd->key, fd.key, sizeof(struct hfsplus_cat_key));
out:
284
	kfree(strbuf);
L
Linus Torvalds 已提交
285 286 287 288 289 290 291 292
	hfs_find_exit(&fd);
	return err;
}

static int hfsplus_dir_release(struct inode *inode, struct file *file)
{
	struct hfsplus_readdir_data *rd = file->private_data;
	if (rd) {
A
Al Viro 已提交
293
		spin_lock(&HFSPLUS_I(inode)->open_dir_lock);
L
Linus Torvalds 已提交
294
		list_del(&rd->list);
A
Al Viro 已提交
295
		spin_unlock(&HFSPLUS_I(inode)->open_dir_lock);
L
Linus Torvalds 已提交
296 297 298 299 300 301 302 303
		kfree(rd);
	}
	return 0;
}

static int hfsplus_link(struct dentry *src_dentry, struct inode *dst_dir,
			struct dentry *dst_dentry)
{
304
	struct hfsplus_sb_info *sbi = HFSPLUS_SB(dst_dir->i_sb);
305 306
	struct inode *inode = d_inode(src_dentry);
	struct inode *src_dir = d_inode(src_dentry->d_parent);
L
Linus Torvalds 已提交
307 308 309 310 311 312 313
	struct qstr str;
	char name[32];
	u32 cnid, id;
	int res;

	if (HFSPLUS_IS_RSRC(inode))
		return -EPERM;
C
Christoph Hellwig 已提交
314 315
	if (!S_ISREG(inode->i_mode))
		return -EPERM;
L
Linus Torvalds 已提交
316

317
	mutex_lock(&sbi->vh_mutex);
L
Linus Torvalds 已提交
318 319 320 321 322 323 324 325
	if (inode->i_ino == (u32)(unsigned long)src_dentry->d_fsdata) {
		for (;;) {
			get_random_bytes(&id, sizeof(cnid));
			id &= 0x3fffffff;
			str.name = name;
			str.len = sprintf(name, "iNode%d", id);
			res = hfsplus_rename_cat(inode->i_ino,
						 src_dir, &src_dentry->d_name,
326
						 sbi->hidden_dir, &str);
L
Linus Torvalds 已提交
327 328 329
			if (!res)
				break;
			if (res != -EEXIST)
330
				goto out;
L
Linus Torvalds 已提交
331
		}
C
Christoph Hellwig 已提交
332
		HFSPLUS_I(inode)->linkid = id;
333
		cnid = sbi->next_cnid++;
L
Linus Torvalds 已提交
334
		src_dentry->d_fsdata = (void *)(unsigned long)cnid;
335 336
		res = hfsplus_create_cat(cnid, src_dir,
			&src_dentry->d_name, inode);
L
Linus Torvalds 已提交
337 338
		if (res)
			/* panic? */
339
			goto out;
340
		sbi->file_count++;
L
Linus Torvalds 已提交
341
	}
342
	cnid = sbi->next_cnid++;
L
Linus Torvalds 已提交
343 344
	res = hfsplus_create_cat(cnid, dst_dir, &dst_dentry->d_name, inode);
	if (res)
345
		goto out;
L
Linus Torvalds 已提交
346

347
	inc_nlink(inode);
L
Linus Torvalds 已提交
348
	hfsplus_instantiate(dst_dentry, inode, cnid);
A
Al Viro 已提交
349
	ihold(inode);
L
Linus Torvalds 已提交
350 351
	inode->i_ctime = CURRENT_TIME_SEC;
	mark_inode_dirty(inode);
352
	sbi->file_count++;
353
	hfsplus_mark_mdb_dirty(dst_dir->i_sb);
354 355 356
out:
	mutex_unlock(&sbi->vh_mutex);
	return res;
L
Linus Torvalds 已提交
357 358 359 360
}

static int hfsplus_unlink(struct inode *dir, struct dentry *dentry)
{
361
	struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb);
362
	struct inode *inode = d_inode(dentry);
L
Linus Torvalds 已提交
363 364 365 366 367 368 369 370
	struct qstr str;
	char name[32];
	u32 cnid;
	int res;

	if (HFSPLUS_IS_RSRC(inode))
		return -EPERM;

371
	mutex_lock(&sbi->vh_mutex);
L
Linus Torvalds 已提交
372 373
	cnid = (u32)(unsigned long)dentry->d_fsdata;
	if (inode->i_ino == cnid &&
374
	    atomic_read(&HFSPLUS_I(inode)->opencnt)) {
L
Linus Torvalds 已提交
375 376 377 378
		str.name = name;
		str.len = sprintf(name, "temp%lu", inode->i_ino);
		res = hfsplus_rename_cat(inode->i_ino,
					 dir, &dentry->d_name,
379
					 sbi->hidden_dir, &str);
380
		if (!res) {
L
Linus Torvalds 已提交
381
			inode->i_flags |= S_DEAD;
382 383
			drop_nlink(inode);
		}
384
		goto out;
L
Linus Torvalds 已提交
385 386 387
	}
	res = hfsplus_delete_cat(cnid, dir, &dentry->d_name);
	if (res)
388
		goto out;
L
Linus Torvalds 已提交
389

390
	if (inode->i_nlink > 0)
391
		drop_nlink(inode);
R
Roman Zippel 已提交
392 393 394 395
	if (inode->i_ino == cnid)
		clear_nlink(inode);
	if (!inode->i_nlink) {
		if (inode->i_ino != cnid) {
396
			sbi->file_count--;
397
			if (!atomic_read(&HFSPLUS_I(inode)->opencnt)) {
R
Roman Zippel 已提交
398
				res = hfsplus_delete_cat(inode->i_ino,
399
							 sbi->hidden_dir,
R
Roman Zippel 已提交
400 401 402 403 404
							 NULL);
				if (!res)
					hfsplus_delete_inode(inode);
			} else
				inode->i_flags |= S_DEAD;
L
Linus Torvalds 已提交
405
		} else
R
Roman Zippel 已提交
406
			hfsplus_delete_inode(inode);
407
	} else
408
		sbi->file_count--;
L
Linus Torvalds 已提交
409 410
	inode->i_ctime = CURRENT_TIME_SEC;
	mark_inode_dirty(inode);
411 412
out:
	mutex_unlock(&sbi->vh_mutex);
L
Linus Torvalds 已提交
413 414 415 416 417
	return res;
}

static int hfsplus_rmdir(struct inode *dir, struct dentry *dentry)
{
418
	struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb);
419
	struct inode *inode = d_inode(dentry);
L
Linus Torvalds 已提交
420 421 422 423
	int res;

	if (inode->i_size != 2)
		return -ENOTEMPTY;
424 425

	mutex_lock(&sbi->vh_mutex);
L
Linus Torvalds 已提交
426 427
	res = hfsplus_delete_cat(inode->i_ino, dir, &dentry->d_name);
	if (res)
428
		goto out;
429
	clear_nlink(inode);
L
Linus Torvalds 已提交
430 431 432
	inode->i_ctime = CURRENT_TIME_SEC;
	hfsplus_delete_inode(inode);
	mark_inode_dirty(inode);
433 434 435
out:
	mutex_unlock(&sbi->vh_mutex);
	return res;
L
Linus Torvalds 已提交
436 437 438 439 440
}

static int hfsplus_symlink(struct inode *dir, struct dentry *dentry,
			   const char *symname)
{
441
	struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb);
L
Linus Torvalds 已提交
442
	struct inode *inode;
C
Chengyu Song 已提交
443
	int res = -ENOMEM;
L
Linus Torvalds 已提交
444

445
	mutex_lock(&sbi->vh_mutex);
446
	inode = hfsplus_new_inode(dir->i_sb, S_IFLNK | S_IRWXUGO);
L
Linus Torvalds 已提交
447
	if (!inode)
448
		goto out;
L
Linus Torvalds 已提交
449 450

	res = page_symlink(inode, symname, strlen(symname) + 1);
451 452
	if (res)
		goto out_err;
L
Linus Torvalds 已提交
453 454

	res = hfsplus_create_cat(inode->i_ino, dir, &dentry->d_name, inode);
455 456
	if (res)
		goto out_err;
L
Linus Torvalds 已提交
457

458 459 460 461 462 463 464 465 466
	res = hfsplus_init_inode_security(inode, dir, &dentry->d_name);
	if (res == -EOPNOTSUPP)
		res = 0; /* Operation is not supported. */
	else if (res) {
		/* Try to delete anyway without error analysis. */
		hfsplus_delete_cat(inode->i_ino, dir, &dentry->d_name);
		goto out_err;
	}

467 468
	hfsplus_instantiate(dentry, inode, inode->i_ino);
	mark_inode_dirty(inode);
469
	goto out;
L
Linus Torvalds 已提交
470

471
out_err:
472
	clear_nlink(inode);
473 474
	hfsplus_delete_inode(inode);
	iput(inode);
475 476
out:
	mutex_unlock(&sbi->vh_mutex);
L
Linus Torvalds 已提交
477 478 479 480
	return res;
}

static int hfsplus_mknod(struct inode *dir, struct dentry *dentry,
A
Al Viro 已提交
481
			 umode_t mode, dev_t rdev)
L
Linus Torvalds 已提交
482
{
483
	struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb);
L
Linus Torvalds 已提交
484
	struct inode *inode;
C
Chengyu Song 已提交
485
	int res = -ENOMEM;
L
Linus Torvalds 已提交
486

487
	mutex_lock(&sbi->vh_mutex);
488
	inode = hfsplus_new_inode(dir->i_sb, mode);
L
Linus Torvalds 已提交
489
	if (!inode)
490
		goto out;
L
Linus Torvalds 已提交
491

492 493 494
	if (S_ISBLK(mode) || S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode))
		init_special_inode(inode, mode, rdev);

L
Linus Torvalds 已提交
495
	res = hfsplus_create_cat(inode->i_ino, dir, &dentry->d_name, inode);
496 497 498 499 500 501 502 503 504 505
	if (res)
		goto failed_mknod;

	res = hfsplus_init_inode_security(inode, dir, &dentry->d_name);
	if (res == -EOPNOTSUPP)
		res = 0; /* Operation is not supported. */
	else if (res) {
		/* Try to delete anyway without error analysis. */
		hfsplus_delete_cat(inode->i_ino, dir, &dentry->d_name);
		goto failed_mknod;
L
Linus Torvalds 已提交
506
	}
507

L
Linus Torvalds 已提交
508 509
	hfsplus_instantiate(dentry, inode, inode->i_ino);
	mark_inode_dirty(inode);
510 511 512 513 514 515
	goto out;

failed_mknod:
	clear_nlink(inode);
	hfsplus_delete_inode(inode);
	iput(inode);
516 517 518
out:
	mutex_unlock(&sbi->vh_mutex);
	return res;
L
Linus Torvalds 已提交
519 520
}

A
Al Viro 已提交
521
static int hfsplus_create(struct inode *dir, struct dentry *dentry, umode_t mode,
A
Al Viro 已提交
522
			  bool excl)
523 524 525 526
{
	return hfsplus_mknod(dir, dentry, mode, 0);
}

527
static int hfsplus_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
528 529 530 531
{
	return hfsplus_mknod(dir, dentry, mode | S_IFDIR, 0);
}

L
Linus Torvalds 已提交
532 533 534 535 536 537
static int hfsplus_rename(struct inode *old_dir, struct dentry *old_dentry,
			  struct inode *new_dir, struct dentry *new_dentry)
{
	int res;

	/* Unlink destination if it already exists */
538
	if (d_really_is_positive(new_dentry)) {
539
		if (d_is_dir(new_dentry))
540
			res = hfsplus_rmdir(new_dir, new_dentry);
541
		else
542
			res = hfsplus_unlink(new_dir, new_dentry);
L
Linus Torvalds 已提交
543 544 545 546 547 548 549 550 551 552 553 554
		if (res)
			return res;
	}

	res = hfsplus_rename_cat((u32)(unsigned long)old_dentry->d_fsdata,
				 old_dir, &old_dentry->d_name,
				 new_dir, &new_dentry->d_name);
	if (!res)
		new_dentry->d_fsdata = old_dentry->d_fsdata;
	return res;
}

555
const struct inode_operations hfsplus_dir_inode_operations = {
556 557 558 559 560 561 562 563 564 565
	.lookup			= hfsplus_lookup,
	.create			= hfsplus_create,
	.link			= hfsplus_link,
	.unlink			= hfsplus_unlink,
	.mkdir			= hfsplus_mkdir,
	.rmdir			= hfsplus_rmdir,
	.symlink		= hfsplus_symlink,
	.mknod			= hfsplus_mknod,
	.rename			= hfsplus_rename,
	.listxattr		= hfsplus_listxattr,
566 567
#ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
	.get_acl		= hfsplus_get_posix_acl,
568
	.set_acl		= hfsplus_set_posix_acl,
569
#endif
L
Linus Torvalds 已提交
570 571
};

572
const struct file_operations hfsplus_dir_operations = {
573
	.fsync		= hfsplus_file_fsync,
L
Linus Torvalds 已提交
574
	.read		= generic_read_dir,
A
Al Viro 已提交
575
	.iterate_shared	= hfsplus_readdir,
576
	.unlocked_ioctl = hfsplus_ioctl,
L
Linus Torvalds 已提交
577 578 579
	.llseek		= generic_file_llseek,
	.release	= hfsplus_dir_release,
};