dir.c 13.9 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
L
Linus Torvalds 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 *  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>
16
#include <linux/nls.h>
L
Linus Torvalds 已提交
17 18 19

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

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 已提交
32
				     unsigned int flags)
L
Linus Torvalds 已提交
33 34 35 36 37 38 39 40 41 42
{
	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;
43

L
Linus Torvalds 已提交
44
	dentry->d_fsdata = NULL;
45 46 47
	err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
	if (err)
		return ERR_PTR(err);
S
Sougata Santra 已提交
48 49 50 51
	err = hfsplus_cat_build_key(sb, fd.search_key, dir->i_ino,
			&dentry->d_name);
	if (unlikely(err < 0))
		goto fail;
L
Linus Torvalds 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
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);
77 78 79 80 81 82 83 84
		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 ==
85
					HFSPLUS_I(d_inode(sb->s_root))->
86 87
						create_date) &&
				HFSPLUS_SB(sb)->hidden_dir) {
L
Linus Torvalds 已提交
88 89 90 91
			struct qstr str;
			char name[32];

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

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

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

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

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

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

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

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

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

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

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

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

318
	mutex_lock(&sbi->vh_mutex);
L
Linus Torvalds 已提交
319 320 321 322 323 324 325 326
	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,
327
						 sbi->hidden_dir, &str);
L
Linus Torvalds 已提交
328 329 330
			if (!res)
				break;
			if (res != -EEXIST)
331
				goto out;
L
Linus Torvalds 已提交
332
		}
C
Christoph Hellwig 已提交
333
		HFSPLUS_I(inode)->linkid = id;
334
		cnid = sbi->next_cnid++;
L
Linus Torvalds 已提交
335
		src_dentry->d_fsdata = (void *)(unsigned long)cnid;
336 337
		res = hfsplus_create_cat(cnid, src_dir,
			&src_dentry->d_name, inode);
L
Linus Torvalds 已提交
338 339
		if (res)
			/* panic? */
340
			goto out;
341
		sbi->file_count++;
L
Linus Torvalds 已提交
342
	}
343
	cnid = sbi->next_cnid++;
L
Linus Torvalds 已提交
344 345
	res = hfsplus_create_cat(cnid, dst_dir, &dst_dentry->d_name, inode);
	if (res)
346
		goto out;
L
Linus Torvalds 已提交
347

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

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

	if (HFSPLUS_IS_RSRC(inode))
		return -EPERM;

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

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

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

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

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

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

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

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

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

459 460 461 462 463 464 465 466 467
	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;
	}

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

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

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

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

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

L
Linus Torvalds 已提交
496
	res = hfsplus_create_cat(inode->i_ino, dir, &dentry->d_name, inode);
497 498 499 500 501 502 503 504 505 506
	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 已提交
507
	}
508

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

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

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

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

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

539 540 541
	if (flags & ~RENAME_NOREPLACE)
		return -EINVAL;

L
Linus Torvalds 已提交
542
	/* Unlink destination if it already exists */
543
	if (d_really_is_positive(new_dentry)) {
544
		if (d_is_dir(new_dentry))
545
			res = hfsplus_rmdir(new_dir, new_dentry);
546
		else
547
			res = hfsplus_unlink(new_dir, new_dentry);
L
Linus Torvalds 已提交
548 549 550 551 552 553 554 555 556 557 558 559
		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;
}

560
const struct inode_operations hfsplus_dir_inode_operations = {
561 562 563 564 565 566 567 568 569 570
	.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,
571 572
#ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
	.get_acl		= hfsplus_get_posix_acl,
573
	.set_acl		= hfsplus_set_posix_acl,
574
#endif
L
Linus Torvalds 已提交
575 576
};

577
const struct file_operations hfsplus_dir_operations = {
578
	.fsync		= hfsplus_file_fsync,
L
Linus Torvalds 已提交
579
	.read		= generic_read_dir,
A
Al Viro 已提交
580
	.iterate_shared	= hfsplus_readdir,
581
	.unlocked_ioctl = hfsplus_ioctl,
L
Linus Torvalds 已提交
582 583 584
	.llseek		= generic_file_llseek,
	.release	= hfsplus_dir_release,
};