Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/hfsplus/dir.c |
| 4 | * |
| 5 | * Copyright (C) 2001 |
| 6 | * Brad Boyer (flar@allandria.com) |
| 7 | * (C) 2003 Ardis Technologies <roman@ardistech.com> |
| 8 | * |
| 9 | * Handling of directories |
| 10 | */ |
| 11 | |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/slab.h> |
| 15 | #include <linux/random.h> |
Hin-Tak Leung | 017f8da | 2014-06-06 14:36:21 -0700 | [diff] [blame] | 16 | #include <linux/nls.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #include "hfsplus_fs.h" |
| 19 | #include "hfsplus_raw.h" |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 20 | #include "xattr.h" |
Vyacheslav Dubeyko | b4c1107 | 2013-09-11 14:24:30 -0700 | [diff] [blame] | 21 | #include "acl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | static inline void hfsplus_instantiate(struct dentry *dentry, |
| 24 | struct inode *inode, u32 cnid) |
| 25 | { |
| 26 | dentry->d_fsdata = (void *)(unsigned long)cnid; |
| 27 | d_instantiate(dentry, inode); |
| 28 | } |
| 29 | |
| 30 | /* Find the entry inside dir named dentry->d_name */ |
| 31 | static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry, |
Al Viro | 00cd8dd | 2012-06-10 17:13:09 -0400 | [diff] [blame] | 32 | unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | { |
| 34 | struct inode *inode = NULL; |
| 35 | struct hfs_find_data fd; |
| 36 | struct super_block *sb; |
| 37 | hfsplus_cat_entry entry; |
| 38 | int err; |
| 39 | u32 cnid, linkid = 0; |
| 40 | u16 type; |
| 41 | |
| 42 | sb = dir->i_sb; |
Duane Griffin | d45bce8 | 2007-07-15 23:41:23 -0700 | [diff] [blame] | 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | dentry->d_fsdata = NULL; |
Alexey Khoroshilov | 5bd9d99 | 2011-07-06 02:29:59 +0400 | [diff] [blame] | 45 | err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd); |
| 46 | if (err) |
| 47 | return ERR_PTR(err); |
Sougata Santra | 89ac9b4 | 2014-12-18 16:17:12 -0800 | [diff] [blame] | 48 | err = hfsplus_cat_build_key(sb, fd.search_key, dir->i_ino, |
| 49 | &dentry->d_name); |
| 50 | if (unlikely(err < 0)) |
| 51 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | again: |
| 53 | err = hfs_brec_read(&fd, &entry, sizeof(entry)); |
| 54 | if (err) { |
| 55 | if (err == -ENOENT) { |
| 56 | hfs_find_exit(&fd); |
| 57 | /* No such entry */ |
| 58 | inode = NULL; |
| 59 | goto out; |
| 60 | } |
| 61 | goto fail; |
| 62 | } |
| 63 | type = be16_to_cpu(entry.type); |
| 64 | if (type == HFSPLUS_FOLDER) { |
| 65 | if (fd.entrylength < sizeof(struct hfsplus_cat_folder)) { |
| 66 | err = -EIO; |
| 67 | goto fail; |
| 68 | } |
| 69 | cnid = be32_to_cpu(entry.folder.id); |
| 70 | dentry->d_fsdata = (void *)(unsigned long)cnid; |
| 71 | } else if (type == HFSPLUS_FILE) { |
| 72 | if (fd.entrylength < sizeof(struct hfsplus_cat_file)) { |
| 73 | err = -EIO; |
| 74 | goto fail; |
| 75 | } |
| 76 | cnid = be32_to_cpu(entry.file.id); |
Anton Salikhmetov | 2753cc2 | 2010-12-16 18:08:38 +0200 | [diff] [blame] | 77 | if (entry.file.user_info.fdType == |
| 78 | cpu_to_be32(HFSP_HARDLINK_TYPE) && |
| 79 | entry.file.user_info.fdCreator == |
| 80 | cpu_to_be32(HFSP_HFSPLUS_CREATOR) && |
| 81 | (entry.file.create_date == |
| 82 | HFSPLUS_I(HFSPLUS_SB(sb)->hidden_dir)-> |
| 83 | create_date || |
| 84 | entry.file.create_date == |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 85 | HFSPLUS_I(d_inode(sb->s_root))-> |
Anton Salikhmetov | 2753cc2 | 2010-12-16 18:08:38 +0200 | [diff] [blame] | 86 | create_date) && |
| 87 | HFSPLUS_SB(sb)->hidden_dir) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | struct qstr str; |
| 89 | char name[32]; |
| 90 | |
| 91 | if (dentry->d_fsdata) { |
Roman Zippel | af8c85b | 2006-01-18 17:43:10 -0800 | [diff] [blame] | 92 | /* |
| 93 | * We found a link pointing to another link, |
| 94 | * so ignore it and treat it as regular file. |
| 95 | */ |
| 96 | cnid = (unsigned long)dentry->d_fsdata; |
| 97 | linkid = 0; |
| 98 | } else { |
| 99 | dentry->d_fsdata = (void *)(unsigned long)cnid; |
Anton Salikhmetov | 2753cc2 | 2010-12-16 18:08:38 +0200 | [diff] [blame] | 100 | linkid = |
| 101 | be32_to_cpu(entry.file.permissions.dev); |
Roman Zippel | af8c85b | 2006-01-18 17:43:10 -0800 | [diff] [blame] | 102 | str.len = sprintf(name, "iNode%d", linkid); |
| 103 | str.name = name; |
Sougata Santra | 89ac9b4 | 2014-12-18 16:17:12 -0800 | [diff] [blame] | 104 | err = hfsplus_cat_build_key(sb, fd.search_key, |
Anton Salikhmetov | 2753cc2 | 2010-12-16 18:08:38 +0200 | [diff] [blame] | 105 | HFSPLUS_SB(sb)->hidden_dir->i_ino, |
| 106 | &str); |
Sougata Santra | 89ac9b4 | 2014-12-18 16:17:12 -0800 | [diff] [blame] | 107 | if (unlikely(err < 0)) |
| 108 | goto fail; |
Roman Zippel | af8c85b | 2006-01-18 17:43:10 -0800 | [diff] [blame] | 109 | goto again; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } else if (!dentry->d_fsdata) |
| 112 | dentry->d_fsdata = (void *)(unsigned long)cnid; |
| 113 | } else { |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 114 | pr_err("invalid catalog entry type in lookup\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | err = -EIO; |
| 116 | goto fail; |
| 117 | } |
| 118 | hfs_find_exit(&fd); |
David Howells | 6352539 | 2008-02-07 00:15:40 -0800 | [diff] [blame] | 119 | inode = hfsplus_iget(dir->i_sb, cnid); |
| 120 | if (IS_ERR(inode)) |
| 121 | return ERR_CAST(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | if (S_ISREG(inode->i_mode)) |
Christoph Hellwig | f6089ff | 2010-10-14 09:54:28 -0400 | [diff] [blame] | 123 | HFSPLUS_I(inode)->linkid = linkid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | out: |
| 125 | d_add(dentry, inode); |
| 126 | return NULL; |
| 127 | fail: |
| 128 | hfs_find_exit(&fd); |
| 129 | return ERR_PTR(err); |
| 130 | } |
| 131 | |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 132 | static int hfsplus_readdir(struct file *file, struct dir_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 134 | struct inode *inode = file_inode(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | struct super_block *sb = inode->i_sb; |
| 136 | int len, err; |
Hin-Tak Leung | 017f8da | 2014-06-06 14:36:21 -0700 | [diff] [blame] | 137 | char *strbuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | hfsplus_cat_entry entry; |
| 139 | struct hfs_find_data fd; |
| 140 | struct hfsplus_readdir_data *rd; |
| 141 | u16 type; |
| 142 | |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 143 | if (file->f_pos >= inode->i_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | return 0; |
| 145 | |
Alexey Khoroshilov | 5bd9d99 | 2011-07-06 02:29:59 +0400 | [diff] [blame] | 146 | err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd); |
| 147 | if (err) |
| 148 | return err; |
Hin-Tak Leung | 017f8da | 2014-06-06 14:36:21 -0700 | [diff] [blame] | 149 | strbuf = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_MAX_STRLEN + 1, GFP_KERNEL); |
| 150 | if (!strbuf) { |
| 151 | err = -ENOMEM; |
| 152 | goto out; |
| 153 | } |
Sougata Santra | 89ac9b4 | 2014-12-18 16:17:12 -0800 | [diff] [blame] | 154 | hfsplus_cat_build_key_with_cnid(sb, fd.search_key, inode->i_ino); |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 155 | err = hfs_brec_find(&fd, hfs_find_rec_by_key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | if (err) |
| 157 | goto out; |
| 158 | |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 159 | if (ctx->pos == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /* This is completely artificial... */ |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 161 | if (!dir_emit_dot(file, ctx)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | goto out; |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 163 | ctx->pos = 1; |
| 164 | } |
| 165 | if (ctx->pos == 1) { |
Greg Kroah-Hartman | 6f24f89 | 2012-05-04 12:09:39 -0700 | [diff] [blame] | 166 | if (fd.entrylength > sizeof(entry) || fd.entrylength < 0) { |
| 167 | err = -EIO; |
| 168 | goto out; |
| 169 | } |
| 170 | |
Anton Salikhmetov | 2753cc2 | 2010-12-16 18:08:38 +0200 | [diff] [blame] | 171 | hfs_bnode_read(fd.bnode, &entry, fd.entryoffset, |
| 172 | fd.entrylength); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | if (be16_to_cpu(entry.type) != HFSPLUS_FOLDER_THREAD) { |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 174 | pr_err("bad catalog folder thread\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | err = -EIO; |
| 176 | goto out; |
| 177 | } |
| 178 | if (fd.entrylength < HFSPLUS_MIN_THREAD_SZ) { |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 179 | pr_err("truncated catalog thread\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | err = -EIO; |
| 181 | goto out; |
| 182 | } |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 183 | if (!dir_emit(ctx, "..", 2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | be32_to_cpu(entry.thread.parentID), DT_DIR)) |
| 185 | goto out; |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 186 | ctx->pos = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 188 | if (ctx->pos >= inode->i_size) |
| 189 | goto out; |
| 190 | err = hfs_brec_goto(&fd, ctx->pos - 1); |
| 191 | if (err) |
| 192 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | for (;;) { |
| 194 | if (be32_to_cpu(fd.key->cat.parent) != inode->i_ino) { |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 195 | pr_err("walked past end of dir\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | err = -EIO; |
| 197 | goto out; |
| 198 | } |
Greg Kroah-Hartman | 6f24f89 | 2012-05-04 12:09:39 -0700 | [diff] [blame] | 199 | |
| 200 | if (fd.entrylength > sizeof(entry) || fd.entrylength < 0) { |
| 201 | err = -EIO; |
| 202 | goto out; |
| 203 | } |
| 204 | |
Anton Salikhmetov | 2753cc2 | 2010-12-16 18:08:38 +0200 | [diff] [blame] | 205 | hfs_bnode_read(fd.bnode, &entry, fd.entryoffset, |
| 206 | fd.entrylength); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | type = be16_to_cpu(entry.type); |
Hin-Tak Leung | 017f8da | 2014-06-06 14:36:21 -0700 | [diff] [blame] | 208 | len = NLS_MAX_CHARSET_SIZE * HFSPLUS_MAX_STRLEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | err = hfsplus_uni2asc(sb, &fd.key->cat.name, strbuf, &len); |
| 210 | if (err) |
| 211 | goto out; |
| 212 | if (type == HFSPLUS_FOLDER) { |
Anton Salikhmetov | 2753cc2 | 2010-12-16 18:08:38 +0200 | [diff] [blame] | 213 | if (fd.entrylength < |
| 214 | sizeof(struct hfsplus_cat_folder)) { |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 215 | pr_err("small dir entry\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | err = -EIO; |
| 217 | goto out; |
| 218 | } |
Christoph Hellwig | dd73a01 | 2010-10-01 05:42:59 +0200 | [diff] [blame] | 219 | if (HFSPLUS_SB(sb)->hidden_dir && |
| 220 | HFSPLUS_SB(sb)->hidden_dir->i_ino == |
| 221 | be32_to_cpu(entry.folder.id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | goto next; |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 223 | if (!dir_emit(ctx, strbuf, len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | be32_to_cpu(entry.folder.id), DT_DIR)) |
| 225 | break; |
| 226 | } else if (type == HFSPLUS_FILE) { |
Sergei Antonov | 97a62ea | 2014-06-06 14:36:24 -0700 | [diff] [blame] | 227 | u16 mode; |
| 228 | unsigned type = DT_UNKNOWN; |
| 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | if (fd.entrylength < sizeof(struct hfsplus_cat_file)) { |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 231 | pr_err("small file entry\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | err = -EIO; |
| 233 | goto out; |
| 234 | } |
Sergei Antonov | 97a62ea | 2014-06-06 14:36:24 -0700 | [diff] [blame] | 235 | |
| 236 | mode = be16_to_cpu(entry.file.permissions.mode); |
| 237 | if (S_ISREG(mode)) |
| 238 | type = DT_REG; |
| 239 | else if (S_ISLNK(mode)) |
| 240 | type = DT_LNK; |
| 241 | else if (S_ISFIFO(mode)) |
| 242 | type = DT_FIFO; |
| 243 | else if (S_ISCHR(mode)) |
| 244 | type = DT_CHR; |
| 245 | else if (S_ISBLK(mode)) |
| 246 | type = DT_BLK; |
| 247 | else if (S_ISSOCK(mode)) |
| 248 | type = DT_SOCK; |
| 249 | |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 250 | if (!dir_emit(ctx, strbuf, len, |
Sergei Antonov | 97a62ea | 2014-06-06 14:36:24 -0700 | [diff] [blame] | 251 | be32_to_cpu(entry.file.id), type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | break; |
| 253 | } else { |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 254 | pr_err("bad catalog entry type\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | err = -EIO; |
| 256 | goto out; |
| 257 | } |
Anton Salikhmetov | 20b7643 | 2010-12-16 18:08:40 +0200 | [diff] [blame] | 258 | next: |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 259 | ctx->pos++; |
| 260 | if (ctx->pos >= inode->i_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | goto out; |
| 262 | err = hfs_brec_goto(&fd, 1); |
| 263 | if (err) |
| 264 | goto out; |
| 265 | } |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 266 | rd = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | if (!rd) { |
| 268 | rd = kmalloc(sizeof(struct hfsplus_readdir_data), GFP_KERNEL); |
| 269 | if (!rd) { |
| 270 | err = -ENOMEM; |
| 271 | goto out; |
| 272 | } |
Al Viro | e72514e | 2013-05-22 14:59:39 -0400 | [diff] [blame] | 273 | file->private_data = rd; |
| 274 | rd->file = file; |
Al Viro | 323ee8f | 2016-05-12 20:02:09 -0400 | [diff] [blame] | 275 | spin_lock(&HFSPLUS_I(inode)->open_dir_lock); |
Christoph Hellwig | 6af502d | 2010-10-01 05:43:31 +0200 | [diff] [blame] | 276 | list_add(&rd->list, &HFSPLUS_I(inode)->open_dir_list); |
Al Viro | 323ee8f | 2016-05-12 20:02:09 -0400 | [diff] [blame] | 277 | spin_unlock(&HFSPLUS_I(inode)->open_dir_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } |
Al Viro | 323ee8f | 2016-05-12 20:02:09 -0400 | [diff] [blame] | 279 | /* |
| 280 | * Can be done after the list insertion; exclusion with |
| 281 | * hfsplus_delete_cat() is provided by directory lock. |
| 282 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | memcpy(&rd->key, fd.key, sizeof(struct hfsplus_cat_key)); |
| 284 | out: |
Hin-Tak Leung | 017f8da | 2014-06-06 14:36:21 -0700 | [diff] [blame] | 285 | kfree(strbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | hfs_find_exit(&fd); |
| 287 | return err; |
| 288 | } |
| 289 | |
| 290 | static int hfsplus_dir_release(struct inode *inode, struct file *file) |
| 291 | { |
| 292 | struct hfsplus_readdir_data *rd = file->private_data; |
| 293 | if (rd) { |
Al Viro | 323ee8f | 2016-05-12 20:02:09 -0400 | [diff] [blame] | 294 | spin_lock(&HFSPLUS_I(inode)->open_dir_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | list_del(&rd->list); |
Al Viro | 323ee8f | 2016-05-12 20:02:09 -0400 | [diff] [blame] | 296 | spin_unlock(&HFSPLUS_I(inode)->open_dir_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | kfree(rd); |
| 298 | } |
| 299 | return 0; |
| 300 | } |
| 301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | static int hfsplus_link(struct dentry *src_dentry, struct inode *dst_dir, |
| 303 | struct dentry *dst_dentry) |
| 304 | { |
Christoph Hellwig | dd73a01 | 2010-10-01 05:42:59 +0200 | [diff] [blame] | 305 | struct hfsplus_sb_info *sbi = HFSPLUS_SB(dst_dir->i_sb); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 306 | struct inode *inode = d_inode(src_dentry); |
| 307 | struct inode *src_dir = d_inode(src_dentry->d_parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | struct qstr str; |
| 309 | char name[32]; |
| 310 | u32 cnid, id; |
| 311 | int res; |
| 312 | |
| 313 | if (HFSPLUS_IS_RSRC(inode)) |
| 314 | return -EPERM; |
Christoph Hellwig | f6089ff | 2010-10-14 09:54:28 -0400 | [diff] [blame] | 315 | if (!S_ISREG(inode->i_mode)) |
| 316 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 318 | mutex_lock(&sbi->vh_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | if (inode->i_ino == (u32)(unsigned long)src_dentry->d_fsdata) { |
| 320 | for (;;) { |
| 321 | get_random_bytes(&id, sizeof(cnid)); |
| 322 | id &= 0x3fffffff; |
| 323 | str.name = name; |
| 324 | str.len = sprintf(name, "iNode%d", id); |
| 325 | res = hfsplus_rename_cat(inode->i_ino, |
| 326 | src_dir, &src_dentry->d_name, |
Christoph Hellwig | dd73a01 | 2010-10-01 05:42:59 +0200 | [diff] [blame] | 327 | sbi->hidden_dir, &str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | if (!res) |
| 329 | break; |
| 330 | if (res != -EEXIST) |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 331 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
Christoph Hellwig | f6089ff | 2010-10-14 09:54:28 -0400 | [diff] [blame] | 333 | HFSPLUS_I(inode)->linkid = id; |
Christoph Hellwig | dd73a01 | 2010-10-01 05:42:59 +0200 | [diff] [blame] | 334 | cnid = sbi->next_cnid++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | src_dentry->d_fsdata = (void *)(unsigned long)cnid; |
Anton Salikhmetov | 2753cc2 | 2010-12-16 18:08:38 +0200 | [diff] [blame] | 336 | res = hfsplus_create_cat(cnid, src_dir, |
| 337 | &src_dentry->d_name, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | if (res) |
| 339 | /* panic? */ |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 340 | goto out; |
Christoph Hellwig | dd73a01 | 2010-10-01 05:42:59 +0200 | [diff] [blame] | 341 | sbi->file_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
Christoph Hellwig | dd73a01 | 2010-10-01 05:42:59 +0200 | [diff] [blame] | 343 | cnid = sbi->next_cnid++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | res = hfsplus_create_cat(cnid, dst_dir, &dst_dentry->d_name, inode); |
| 345 | if (res) |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 346 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 348 | inc_nlink(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | hfsplus_instantiate(dst_dentry, inode, cnid); |
Al Viro | 7de9c6ee | 2010-10-23 11:11:40 -0400 | [diff] [blame] | 350 | ihold(inode); |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 351 | inode->i_ctime = current_time(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | mark_inode_dirty(inode); |
Christoph Hellwig | dd73a01 | 2010-10-01 05:42:59 +0200 | [diff] [blame] | 353 | sbi->file_count++; |
Artem Bityutskiy | 9e6c582 | 2012-07-12 17:26:31 +0300 | [diff] [blame] | 354 | hfsplus_mark_mdb_dirty(dst_dir->i_sb); |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 355 | out: |
| 356 | mutex_unlock(&sbi->vh_mutex); |
| 357 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | static int hfsplus_unlink(struct inode *dir, struct dentry *dentry) |
| 361 | { |
Christoph Hellwig | dd73a01 | 2010-10-01 05:42:59 +0200 | [diff] [blame] | 362 | struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 363 | struct inode *inode = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | struct qstr str; |
| 365 | char name[32]; |
| 366 | u32 cnid; |
| 367 | int res; |
| 368 | |
| 369 | if (HFSPLUS_IS_RSRC(inode)) |
| 370 | return -EPERM; |
| 371 | |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 372 | mutex_lock(&sbi->vh_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | cnid = (u32)(unsigned long)dentry->d_fsdata; |
| 374 | if (inode->i_ino == cnid && |
Christoph Hellwig | 6af502d | 2010-10-01 05:43:31 +0200 | [diff] [blame] | 375 | atomic_read(&HFSPLUS_I(inode)->opencnt)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | str.name = name; |
| 377 | str.len = sprintf(name, "temp%lu", inode->i_ino); |
| 378 | res = hfsplus_rename_cat(inode->i_ino, |
| 379 | dir, &dentry->d_name, |
Christoph Hellwig | dd73a01 | 2010-10-01 05:42:59 +0200 | [diff] [blame] | 380 | sbi->hidden_dir, &str); |
Christoph Hellwig | 85b8fe8 | 2010-10-27 13:45:50 +0200 | [diff] [blame] | 381 | if (!res) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | inode->i_flags |= S_DEAD; |
Christoph Hellwig | 85b8fe8 | 2010-10-27 13:45:50 +0200 | [diff] [blame] | 383 | drop_nlink(inode); |
| 384 | } |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 385 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | res = hfsplus_delete_cat(cnid, dir, &dentry->d_name); |
| 388 | if (res) |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 389 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Roman Zippel | af8c85b | 2006-01-18 17:43:10 -0800 | [diff] [blame] | 391 | if (inode->i_nlink > 0) |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 392 | drop_nlink(inode); |
Roman Zippel | 76b0c26 | 2008-04-09 17:44:07 +0200 | [diff] [blame] | 393 | if (inode->i_ino == cnid) |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 394 | clear_nlink(inode); |
Roman Zippel | 76b0c26 | 2008-04-09 17:44:07 +0200 | [diff] [blame] | 395 | if (!inode->i_nlink) { |
| 396 | if (inode->i_ino != cnid) { |
Christoph Hellwig | dd73a01 | 2010-10-01 05:42:59 +0200 | [diff] [blame] | 397 | sbi->file_count--; |
Christoph Hellwig | 6af502d | 2010-10-01 05:43:31 +0200 | [diff] [blame] | 398 | if (!atomic_read(&HFSPLUS_I(inode)->opencnt)) { |
Roman Zippel | 76b0c26 | 2008-04-09 17:44:07 +0200 | [diff] [blame] | 399 | res = hfsplus_delete_cat(inode->i_ino, |
Christoph Hellwig | dd73a01 | 2010-10-01 05:42:59 +0200 | [diff] [blame] | 400 | sbi->hidden_dir, |
Roman Zippel | 76b0c26 | 2008-04-09 17:44:07 +0200 | [diff] [blame] | 401 | NULL); |
| 402 | if (!res) |
| 403 | hfsplus_delete_inode(inode); |
| 404 | } else |
| 405 | inode->i_flags |= S_DEAD; |
| 406 | } else |
| 407 | hfsplus_delete_inode(inode); |
| 408 | } else |
Christoph Hellwig | dd73a01 | 2010-10-01 05:42:59 +0200 | [diff] [blame] | 409 | sbi->file_count--; |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 410 | inode->i_ctime = current_time(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | mark_inode_dirty(inode); |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 412 | out: |
| 413 | mutex_unlock(&sbi->vh_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | return res; |
| 415 | } |
| 416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | static int hfsplus_rmdir(struct inode *dir, struct dentry *dentry) |
| 418 | { |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 419 | struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 420 | struct inode *inode = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | int res; |
| 422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | if (inode->i_size != 2) |
| 424 | return -ENOTEMPTY; |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 425 | |
| 426 | mutex_lock(&sbi->vh_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | res = hfsplus_delete_cat(inode->i_ino, dir, &dentry->d_name); |
| 428 | if (res) |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 429 | goto out; |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 430 | clear_nlink(inode); |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 431 | inode->i_ctime = current_time(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | hfsplus_delete_inode(inode); |
| 433 | mark_inode_dirty(inode); |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 434 | out: |
| 435 | mutex_unlock(&sbi->vh_mutex); |
| 436 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | static int hfsplus_symlink(struct inode *dir, struct dentry *dentry, |
| 440 | const char *symname) |
| 441 | { |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 442 | struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | struct inode *inode; |
Chengyu Song | 27a4e38 | 2015-04-16 12:47:12 -0700 | [diff] [blame] | 444 | int res = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 446 | mutex_lock(&sbi->vh_mutex); |
Christoph Hellwig | f17c89b | 2010-10-01 05:43:54 +0200 | [diff] [blame] | 447 | inode = hfsplus_new_inode(dir->i_sb, S_IFLNK | S_IRWXUGO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | if (!inode) |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 449 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
| 451 | res = page_symlink(inode, symname, strlen(symname) + 1); |
Christoph Hellwig | f17c89b | 2010-10-01 05:43:54 +0200 | [diff] [blame] | 452 | if (res) |
| 453 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | res = hfsplus_create_cat(inode->i_ino, dir, &dentry->d_name, inode); |
Christoph Hellwig | f17c89b | 2010-10-01 05:43:54 +0200 | [diff] [blame] | 456 | if (res) |
| 457 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 459 | res = hfsplus_init_inode_security(inode, dir, &dentry->d_name); |
| 460 | if (res == -EOPNOTSUPP) |
| 461 | res = 0; /* Operation is not supported. */ |
| 462 | else if (res) { |
| 463 | /* Try to delete anyway without error analysis. */ |
| 464 | hfsplus_delete_cat(inode->i_ino, dir, &dentry->d_name); |
| 465 | goto out_err; |
| 466 | } |
| 467 | |
Christoph Hellwig | f17c89b | 2010-10-01 05:43:54 +0200 | [diff] [blame] | 468 | hfsplus_instantiate(dentry, inode, inode->i_ino); |
| 469 | mark_inode_dirty(inode); |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 470 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
Christoph Hellwig | f17c89b | 2010-10-01 05:43:54 +0200 | [diff] [blame] | 472 | out_err: |
Miklos Szeredi | 6d6b77f | 2011-10-28 14:13:28 +0200 | [diff] [blame] | 473 | clear_nlink(inode); |
Christoph Hellwig | f17c89b | 2010-10-01 05:43:54 +0200 | [diff] [blame] | 474 | hfsplus_delete_inode(inode); |
| 475 | iput(inode); |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 476 | out: |
| 477 | mutex_unlock(&sbi->vh_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | return res; |
| 479 | } |
| 480 | |
| 481 | static int hfsplus_mknod(struct inode *dir, struct dentry *dentry, |
Al Viro | 1a67aaf | 2011-07-26 01:52:52 -0400 | [diff] [blame] | 482 | umode_t mode, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 484 | struct hfsplus_sb_info *sbi = HFSPLUS_SB(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | struct inode *inode; |
Chengyu Song | 27a4e38 | 2015-04-16 12:47:12 -0700 | [diff] [blame] | 486 | int res = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 488 | mutex_lock(&sbi->vh_mutex); |
Christoph Hellwig | 30d3abb | 2010-10-01 05:43:50 +0200 | [diff] [blame] | 489 | inode = hfsplus_new_inode(dir->i_sb, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | if (!inode) |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 491 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
Christoph Hellwig | 90e6169 | 2010-10-14 09:54:39 -0400 | [diff] [blame] | 493 | if (S_ISBLK(mode) || S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) |
| 494 | init_special_inode(inode, mode, rdev); |
| 495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | res = hfsplus_create_cat(inode->i_ino, dir, &dentry->d_name, inode); |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 497 | if (res) |
| 498 | goto failed_mknod; |
| 499 | |
| 500 | res = hfsplus_init_inode_security(inode, dir, &dentry->d_name); |
| 501 | if (res == -EOPNOTSUPP) |
| 502 | res = 0; /* Operation is not supported. */ |
| 503 | else if (res) { |
| 504 | /* Try to delete anyway without error analysis. */ |
| 505 | hfsplus_delete_cat(inode->i_ino, dir, &dentry->d_name); |
| 506 | goto failed_mknod; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } |
Christoph Hellwig | 30d3abb | 2010-10-01 05:43:50 +0200 | [diff] [blame] | 508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | hfsplus_instantiate(dentry, inode, inode->i_ino); |
| 510 | mark_inode_dirty(inode); |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 511 | goto out; |
| 512 | |
| 513 | failed_mknod: |
| 514 | clear_nlink(inode); |
| 515 | hfsplus_delete_inode(inode); |
| 516 | iput(inode); |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 517 | out: |
| 518 | mutex_unlock(&sbi->vh_mutex); |
| 519 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Al Viro | 4acdaf2 | 2011-07-26 01:42:34 -0400 | [diff] [blame] | 522 | static int hfsplus_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
Al Viro | ebfc3b4 | 2012-06-10 18:05:36 -0400 | [diff] [blame] | 523 | bool excl) |
Christoph Hellwig | 30d3abb | 2010-10-01 05:43:50 +0200 | [diff] [blame] | 524 | { |
| 525 | return hfsplus_mknod(dir, dentry, mode, 0); |
| 526 | } |
| 527 | |
Al Viro | 18bb1db | 2011-07-26 01:41:39 -0400 | [diff] [blame] | 528 | static int hfsplus_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
Christoph Hellwig | 30d3abb | 2010-10-01 05:43:50 +0200 | [diff] [blame] | 529 | { |
| 530 | return hfsplus_mknod(dir, dentry, mode | S_IFDIR, 0); |
| 531 | } |
| 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | static int hfsplus_rename(struct inode *old_dir, struct dentry *old_dentry, |
Miklos Szeredi | f03b8ad | 2016-09-27 11:03:57 +0200 | [diff] [blame] | 534 | struct inode *new_dir, struct dentry *new_dentry, |
| 535 | unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | { |
| 537 | int res; |
| 538 | |
Miklos Szeredi | f03b8ad | 2016-09-27 11:03:57 +0200 | [diff] [blame] | 539 | if (flags & ~RENAME_NOREPLACE) |
| 540 | return -EINVAL; |
| 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | /* Unlink destination if it already exists */ |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 543 | if (d_really_is_positive(new_dentry)) { |
David Howells | e36cb0b | 2015-01-29 12:02:35 +0000 | [diff] [blame] | 544 | if (d_is_dir(new_dentry)) |
Christoph Hellwig | 40de9a7 | 2010-10-01 09:12:08 +0200 | [diff] [blame] | 545 | res = hfsplus_rmdir(new_dir, new_dentry); |
Sage Weil | e391178 | 2011-05-27 13:42:06 -0700 | [diff] [blame] | 546 | else |
Christoph Hellwig | 40de9a7 | 2010-10-01 09:12:08 +0200 | [diff] [blame] | 547 | res = hfsplus_unlink(new_dir, new_dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | if (res) |
| 549 | return res; |
| 550 | } |
| 551 | |
| 552 | res = hfsplus_rename_cat((u32)(unsigned long)old_dentry->d_fsdata, |
| 553 | old_dir, &old_dentry->d_name, |
| 554 | new_dir, &new_dentry->d_name); |
| 555 | if (!res) |
| 556 | new_dentry->d_fsdata = old_dentry->d_fsdata; |
| 557 | return res; |
| 558 | } |
| 559 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 560 | const struct inode_operations hfsplus_dir_inode_operations = { |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 561 | .lookup = hfsplus_lookup, |
| 562 | .create = hfsplus_create, |
| 563 | .link = hfsplus_link, |
| 564 | .unlink = hfsplus_unlink, |
| 565 | .mkdir = hfsplus_mkdir, |
| 566 | .rmdir = hfsplus_rmdir, |
| 567 | .symlink = hfsplus_symlink, |
| 568 | .mknod = hfsplus_mknod, |
| 569 | .rename = hfsplus_rename, |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 570 | .listxattr = hfsplus_listxattr, |
Vyacheslav Dubeyko | b4c1107 | 2013-09-11 14:24:30 -0700 | [diff] [blame] | 571 | #ifdef CONFIG_HFSPLUS_FS_POSIX_ACL |
| 572 | .get_acl = hfsplus_get_posix_acl, |
Christoph Hellwig | b0a7ab5 | 2013-12-20 05:16:46 -0800 | [diff] [blame] | 573 | .set_acl = hfsplus_set_posix_acl, |
Vyacheslav Dubeyko | b4c1107 | 2013-09-11 14:24:30 -0700 | [diff] [blame] | 574 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | }; |
| 576 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 577 | const struct file_operations hfsplus_dir_operations = { |
Christoph Hellwig | eb29d66 | 2010-11-23 14:38:10 +0100 | [diff] [blame] | 578 | .fsync = hfsplus_file_fsync, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | .read = generic_read_dir, |
Al Viro | 323ee8f | 2016-05-12 20:02:09 -0400 | [diff] [blame] | 580 | .iterate_shared = hfsplus_readdir, |
Arnd Bergmann | 7cc4bcc | 2010-04-27 16:24:20 +0200 | [diff] [blame] | 581 | .unlocked_ioctl = hfsplus_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | .llseek = generic_file_llseek, |
| 583 | .release = hfsplus_dir_release, |
| 584 | }; |