Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/hfs/catalog.c |
| 3 | * |
| 4 | * Copyright (C) 1995-1997 Paul H. Hargrove |
| 5 | * (C) 2003 Ardis Technologies <roman@ardistech.com> |
| 6 | * This file may be distributed under the terms of the GNU General Public License. |
| 7 | * |
| 8 | * This file contains the functions related to the catalog B-tree. |
| 9 | * |
| 10 | * Cache code shamelessly stolen from |
| 11 | * linux/fs/inode.c Copyright (C) 1991, 1992 Linus Torvalds |
| 12 | * re-shamelessly stolen Copyright (C) 1997 Linus Torvalds |
| 13 | */ |
| 14 | |
| 15 | #include "hfs_fs.h" |
| 16 | #include "btree.h" |
| 17 | |
| 18 | /* |
| 19 | * hfs_cat_build_key() |
| 20 | * |
| 21 | * Given the ID of the parent and the name build a search key. |
| 22 | */ |
Al Viro | 71e9396 | 2016-07-20 16:22:29 -0400 | [diff] [blame] | 23 | void hfs_cat_build_key(struct super_block *sb, btree_key *key, u32 parent, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | { |
| 25 | key->cat.reserved = 0; |
| 26 | key->cat.ParID = cpu_to_be32(parent); |
| 27 | if (name) { |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 28 | hfs_asc2mac(sb, &key->cat.CName, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | key->key_len = 6 + key->cat.CName.len; |
| 30 | } else { |
| 31 | memset(&key->cat.CName, 0, sizeof(struct hfs_name)); |
| 32 | key->key_len = 6; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | static int hfs_cat_build_record(hfs_cat_rec *rec, u32 cnid, struct inode *inode) |
| 37 | { |
| 38 | __be32 mtime = hfs_mtime(); |
| 39 | |
| 40 | memset(rec, 0, sizeof(*rec)); |
| 41 | if (S_ISDIR(inode->i_mode)) { |
| 42 | rec->type = HFS_CDR_DIR; |
| 43 | rec->dir.DirID = cpu_to_be32(cnid); |
| 44 | rec->dir.CrDat = mtime; |
| 45 | rec->dir.MdDat = mtime; |
| 46 | rec->dir.BkDat = 0; |
| 47 | rec->dir.UsrInfo.frView = cpu_to_be16(0xff); |
| 48 | return sizeof(struct hfs_cat_dir); |
| 49 | } else { |
| 50 | /* init some fields for the file record */ |
| 51 | rec->type = HFS_CDR_FIL; |
| 52 | rec->file.Flags = HFS_FIL_USED | HFS_FIL_THD; |
| 53 | if (!(inode->i_mode & S_IWUSR)) |
| 54 | rec->file.Flags |= HFS_FIL_LOCK; |
| 55 | rec->file.FlNum = cpu_to_be32(cnid); |
| 56 | rec->file.CrDat = mtime; |
| 57 | rec->file.MdDat = mtime; |
| 58 | rec->file.BkDat = 0; |
| 59 | rec->file.UsrWds.fdType = HFS_SB(inode->i_sb)->s_type; |
| 60 | rec->file.UsrWds.fdCreator = HFS_SB(inode->i_sb)->s_creator; |
| 61 | return sizeof(struct hfs_cat_file); |
| 62 | } |
| 63 | } |
| 64 | |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 65 | static int hfs_cat_build_thread(struct super_block *sb, |
| 66 | hfs_cat_rec *rec, int type, |
Al Viro | 71e9396 | 2016-07-20 16:22:29 -0400 | [diff] [blame] | 67 | u32 parentid, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
| 69 | rec->type = type; |
| 70 | memset(rec->thread.reserved, 0, sizeof(rec->thread.reserved)); |
| 71 | rec->thread.ParID = cpu_to_be32(parentid); |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 72 | hfs_asc2mac(sb, &rec->thread.CName, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | return sizeof(struct hfs_cat_thread); |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * create_entry() |
| 78 | * |
| 79 | * Add a new file or directory to the catalog B-tree and |
| 80 | * return a (struct hfs_cat_entry) for it in '*result'. |
| 81 | */ |
Al Viro | 71e9396 | 2016-07-20 16:22:29 -0400 | [diff] [blame] | 82 | int hfs_cat_create(u32 cnid, struct inode *dir, const struct qstr *str, struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
| 84 | struct hfs_find_data fd; |
| 85 | struct super_block *sb; |
| 86 | union hfs_cat_rec entry; |
| 87 | int entry_size; |
| 88 | int err; |
| 89 | |
Joe Perches | c2b3e1f | 2013-04-30 15:27:54 -0700 | [diff] [blame] | 90 | hfs_dbg(CAT_MOD, "create_cat: %s,%u(%d)\n", |
| 91 | str->name, cnid, inode->i_nlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | if (dir->i_size >= HFS_MAX_VALENCE) |
| 93 | return -ENOSPC; |
| 94 | |
| 95 | sb = dir->i_sb; |
Alexey Khoroshilov | 9509f17 | 2013-04-30 15:27:52 -0700 | [diff] [blame] | 96 | err = hfs_find_init(HFS_SB(sb)->cat_tree, &fd); |
| 97 | if (err) |
| 98 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Ernesto A. Fernández | 54640c7 | 2018-10-30 15:06:17 -0700 | [diff] [blame] | 100 | /* |
| 101 | * Fail early and avoid ENOSPC during the btree operations. We may |
| 102 | * have to split the root node at most once. |
| 103 | */ |
| 104 | err = hfs_bmap_reserve(fd.tree, 2 * fd.tree->depth); |
| 105 | if (err) |
| 106 | goto err2; |
| 107 | |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 108 | hfs_cat_build_key(sb, fd.search_key, cnid, NULL); |
| 109 | entry_size = hfs_cat_build_thread(sb, &entry, S_ISDIR(inode->i_mode) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | HFS_CDR_THD : HFS_CDR_FTH, |
| 111 | dir->i_ino, str); |
| 112 | err = hfs_brec_find(&fd); |
| 113 | if (err != -ENOENT) { |
| 114 | if (!err) |
| 115 | err = -EEXIST; |
| 116 | goto err2; |
| 117 | } |
| 118 | err = hfs_brec_insert(&fd, &entry, entry_size); |
| 119 | if (err) |
| 120 | goto err2; |
| 121 | |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 122 | hfs_cat_build_key(sb, fd.search_key, dir->i_ino, str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | entry_size = hfs_cat_build_record(&entry, cnid, inode); |
| 124 | err = hfs_brec_find(&fd); |
| 125 | if (err != -ENOENT) { |
| 126 | /* panic? */ |
| 127 | if (!err) |
| 128 | err = -EEXIST; |
| 129 | goto err1; |
| 130 | } |
| 131 | err = hfs_brec_insert(&fd, &entry, entry_size); |
| 132 | if (err) |
| 133 | goto err1; |
| 134 | |
| 135 | dir->i_size++; |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 136 | dir->i_mtime = dir->i_ctime = current_time(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | mark_inode_dirty(dir); |
| 138 | hfs_find_exit(&fd); |
| 139 | return 0; |
| 140 | |
| 141 | err1: |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 142 | hfs_cat_build_key(sb, fd.search_key, cnid, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | if (!hfs_brec_find(&fd)) |
| 144 | hfs_brec_remove(&fd); |
| 145 | err2: |
| 146 | hfs_find_exit(&fd); |
| 147 | return err; |
| 148 | } |
| 149 | |
| 150 | /* |
| 151 | * hfs_cat_compare() |
| 152 | * |
| 153 | * Description: |
| 154 | * This is the comparison function used for the catalog B-tree. In |
| 155 | * comparing catalog B-tree entries, the parent id is the most |
| 156 | * significant field (compared as unsigned ints). The name field is |
| 157 | * the least significant (compared in "Macintosh lexical order", |
| 158 | * see hfs_strcmp() in string.c) |
| 159 | * Input Variable(s): |
| 160 | * struct hfs_cat_key *key1: pointer to the first key to compare |
| 161 | * struct hfs_cat_key *key2: pointer to the second key to compare |
| 162 | * Output Variable(s): |
| 163 | * NONE |
| 164 | * Returns: |
| 165 | * int: negative if key1<key2, positive if key1>key2, and 0 if key1==key2 |
| 166 | * Preconditions: |
| 167 | * key1 and key2 point to "valid" (struct hfs_cat_key)s. |
| 168 | * Postconditions: |
| 169 | * This function has no side-effects |
| 170 | */ |
| 171 | int hfs_cat_keycmp(const btree_key *key1, const btree_key *key2) |
| 172 | { |
Rasmus Villemoes | ddbc22e2 | 2014-12-10 15:54:37 -0800 | [diff] [blame] | 173 | __be32 k1p, k2p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Rasmus Villemoes | ddbc22e2 | 2014-12-10 15:54:37 -0800 | [diff] [blame] | 175 | k1p = key1->cat.ParID; |
| 176 | k2p = key2->cat.ParID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Rasmus Villemoes | ddbc22e2 | 2014-12-10 15:54:37 -0800 | [diff] [blame] | 178 | if (k1p != k2p) |
| 179 | return be32_to_cpu(k1p) < be32_to_cpu(k2p) ? -1 : 1; |
| 180 | |
| 181 | return hfs_strcmp(key1->cat.CName.name, key1->cat.CName.len, |
| 182 | key2->cat.CName.name, key2->cat.CName.len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /* Try to get a catalog entry for given catalog id */ |
| 186 | // move to read_super??? |
| 187 | int hfs_cat_find_brec(struct super_block *sb, u32 cnid, |
| 188 | struct hfs_find_data *fd) |
| 189 | { |
| 190 | hfs_cat_rec rec; |
| 191 | int res, len, type; |
| 192 | |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 193 | hfs_cat_build_key(sb, fd->search_key, cnid, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | res = hfs_brec_read(fd, &rec, sizeof(rec)); |
| 195 | if (res) |
| 196 | return res; |
| 197 | |
| 198 | type = rec.type; |
| 199 | if (type != HFS_CDR_THD && type != HFS_CDR_FTH) { |
Joe Perches | d6142673 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 200 | pr_err("found bad thread record in catalog\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | return -EIO; |
| 202 | } |
| 203 | |
| 204 | fd->search_key->cat.ParID = rec.thread.ParID; |
| 205 | len = fd->search_key->cat.CName.len = rec.thread.CName.len; |
Eric Sesterhenn | d38b7aa | 2008-10-15 22:04:11 -0700 | [diff] [blame] | 206 | if (len > HFS_NAMELEN) { |
Joe Perches | d6142673 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 207 | pr_err("bad catalog namelength\n"); |
Eric Sesterhenn | d38b7aa | 2008-10-15 22:04:11 -0700 | [diff] [blame] | 208 | return -EIO; |
| 209 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | memcpy(fd->search_key->cat.CName.name, rec.thread.CName.name, len); |
| 211 | return hfs_brec_find(fd); |
| 212 | } |
| 213 | |
| 214 | |
| 215 | /* |
| 216 | * hfs_cat_delete() |
| 217 | * |
| 218 | * Delete the indicated file or directory. |
| 219 | * The associated thread is also removed unless ('with_thread'==0). |
| 220 | */ |
Al Viro | 71e9396 | 2016-07-20 16:22:29 -0400 | [diff] [blame] | 221 | int hfs_cat_delete(u32 cnid, struct inode *dir, const struct qstr *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
| 223 | struct super_block *sb; |
| 224 | struct hfs_find_data fd; |
Geliang Tang | 2c35dea | 2016-01-20 14:59:32 -0800 | [diff] [blame] | 225 | struct hfs_readdir_data *rd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | int res, type; |
| 227 | |
Joe Perches | c2b3e1f | 2013-04-30 15:27:54 -0700 | [diff] [blame] | 228 | hfs_dbg(CAT_MOD, "delete_cat: %s,%u\n", str ? str->name : NULL, cnid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | sb = dir->i_sb; |
Alexey Khoroshilov | 9509f17 | 2013-04-30 15:27:52 -0700 | [diff] [blame] | 230 | res = hfs_find_init(HFS_SB(sb)->cat_tree, &fd); |
| 231 | if (res) |
| 232 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 234 | hfs_cat_build_key(sb, fd.search_key, dir->i_ino, str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | res = hfs_brec_find(&fd); |
| 236 | if (res) |
| 237 | goto out; |
| 238 | |
| 239 | type = hfs_bnode_read_u8(fd.bnode, fd.entryoffset); |
| 240 | if (type == HFS_CDR_FIL) { |
| 241 | struct hfs_cat_file file; |
| 242 | hfs_bnode_read(fd.bnode, &file, fd.entryoffset, sizeof(file)); |
| 243 | if (be32_to_cpu(file.FlNum) == cnid) { |
| 244 | #if 0 |
| 245 | hfs_free_fork(sb, &file, HFS_FK_DATA); |
| 246 | #endif |
| 247 | hfs_free_fork(sb, &file, HFS_FK_RSRC); |
| 248 | } |
| 249 | } |
| 250 | |
Al Viro | 9717a91 | 2016-05-12 20:13:50 -0400 | [diff] [blame] | 251 | /* we only need to take spinlock for exclusion with ->release() */ |
| 252 | spin_lock(&HFS_I(dir)->open_dir_lock); |
Geliang Tang | 2c35dea | 2016-01-20 14:59:32 -0800 | [diff] [blame] | 253 | list_for_each_entry(rd, &HFS_I(dir)->open_dir_list, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | if (fd.tree->keycmp(fd.search_key, (void *)&rd->key) < 0) |
| 255 | rd->file->f_pos--; |
| 256 | } |
Al Viro | 9717a91 | 2016-05-12 20:13:50 -0400 | [diff] [blame] | 257 | spin_unlock(&HFS_I(dir)->open_dir_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | res = hfs_brec_remove(&fd); |
| 260 | if (res) |
| 261 | goto out; |
| 262 | |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 263 | hfs_cat_build_key(sb, fd.search_key, cnid, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | res = hfs_brec_find(&fd); |
| 265 | if (!res) { |
| 266 | res = hfs_brec_remove(&fd); |
| 267 | if (res) |
| 268 | goto out; |
| 269 | } |
| 270 | |
| 271 | dir->i_size--; |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 272 | dir->i_mtime = dir->i_ctime = current_time(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | mark_inode_dirty(dir); |
| 274 | res = 0; |
| 275 | out: |
| 276 | hfs_find_exit(&fd); |
| 277 | |
| 278 | return res; |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | * hfs_cat_move() |
| 283 | * |
| 284 | * Rename a file or directory, possibly to a new directory. |
| 285 | * If the destination exists it is removed and a |
| 286 | * (struct hfs_cat_entry) for it is returned in '*result'. |
| 287 | */ |
Al Viro | 71e9396 | 2016-07-20 16:22:29 -0400 | [diff] [blame] | 288 | int hfs_cat_move(u32 cnid, struct inode *src_dir, const struct qstr *src_name, |
| 289 | struct inode *dst_dir, const struct qstr *dst_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
| 291 | struct super_block *sb; |
| 292 | struct hfs_find_data src_fd, dst_fd; |
| 293 | union hfs_cat_rec entry; |
| 294 | int entry_size, type; |
| 295 | int err; |
| 296 | |
Joe Perches | c2b3e1f | 2013-04-30 15:27:54 -0700 | [diff] [blame] | 297 | hfs_dbg(CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n", |
| 298 | cnid, src_dir->i_ino, src_name->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | dst_dir->i_ino, dst_name->name); |
| 300 | sb = src_dir->i_sb; |
Alexey Khoroshilov | 9509f17 | 2013-04-30 15:27:52 -0700 | [diff] [blame] | 301 | err = hfs_find_init(HFS_SB(sb)->cat_tree, &src_fd); |
| 302 | if (err) |
| 303 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | dst_fd = src_fd; |
| 305 | |
Ernesto A. Fernández | 54640c7 | 2018-10-30 15:06:17 -0700 | [diff] [blame] | 306 | /* |
| 307 | * Fail early and avoid ENOSPC during the btree operations. We may |
| 308 | * have to split the root node at most once. |
| 309 | */ |
| 310 | err = hfs_bmap_reserve(src_fd.tree, 2 * src_fd.tree->depth); |
| 311 | if (err) |
| 312 | goto out; |
| 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | /* find the old dir entry and read the data */ |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 315 | hfs_cat_build_key(sb, src_fd.search_key, src_dir->i_ino, src_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | err = hfs_brec_find(&src_fd); |
| 317 | if (err) |
| 318 | goto out; |
Amerigo Wang | ec81aec | 2009-12-14 17:57:37 -0800 | [diff] [blame] | 319 | if (src_fd.entrylength > sizeof(entry) || src_fd.entrylength < 0) { |
| 320 | err = -EIO; |
| 321 | goto out; |
| 322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | hfs_bnode_read(src_fd.bnode, &entry, src_fd.entryoffset, |
| 325 | src_fd.entrylength); |
| 326 | |
| 327 | /* create new dir entry with the data from the old entry */ |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 328 | hfs_cat_build_key(sb, dst_fd.search_key, dst_dir->i_ino, dst_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | err = hfs_brec_find(&dst_fd); |
| 330 | if (err != -ENOENT) { |
| 331 | if (!err) |
| 332 | err = -EEXIST; |
| 333 | goto out; |
| 334 | } |
| 335 | |
| 336 | err = hfs_brec_insert(&dst_fd, &entry, src_fd.entrylength); |
| 337 | if (err) |
| 338 | goto out; |
| 339 | dst_dir->i_size++; |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 340 | dst_dir->i_mtime = dst_dir->i_ctime = current_time(dst_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | mark_inode_dirty(dst_dir); |
| 342 | |
| 343 | /* finally remove the old entry */ |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 344 | hfs_cat_build_key(sb, src_fd.search_key, src_dir->i_ino, src_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | err = hfs_brec_find(&src_fd); |
| 346 | if (err) |
| 347 | goto out; |
| 348 | err = hfs_brec_remove(&src_fd); |
| 349 | if (err) |
| 350 | goto out; |
| 351 | src_dir->i_size--; |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 352 | src_dir->i_mtime = src_dir->i_ctime = current_time(src_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | mark_inode_dirty(src_dir); |
| 354 | |
| 355 | type = entry.type; |
| 356 | if (type == HFS_CDR_FIL && !(entry.file.Flags & HFS_FIL_THD)) |
| 357 | goto out; |
| 358 | |
| 359 | /* remove old thread entry */ |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 360 | hfs_cat_build_key(sb, src_fd.search_key, cnid, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | err = hfs_brec_find(&src_fd); |
| 362 | if (err) |
| 363 | goto out; |
| 364 | err = hfs_brec_remove(&src_fd); |
| 365 | if (err) |
| 366 | goto out; |
| 367 | |
| 368 | /* create new thread entry */ |
Roman Zippel | 328b922 | 2005-09-06 15:18:49 -0700 | [diff] [blame] | 369 | hfs_cat_build_key(sb, dst_fd.search_key, cnid, NULL); |
| 370 | entry_size = hfs_cat_build_thread(sb, &entry, type == HFS_CDR_FIL ? HFS_CDR_FTH : HFS_CDR_THD, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | dst_dir->i_ino, dst_name); |
| 372 | err = hfs_brec_find(&dst_fd); |
| 373 | if (err != -ENOENT) { |
| 374 | if (!err) |
| 375 | err = -EEXIST; |
| 376 | goto out; |
| 377 | } |
| 378 | err = hfs_brec_insert(&dst_fd, &entry, entry_size); |
| 379 | out: |
| 380 | hfs_bnode_put(dst_fd.bnode); |
| 381 | hfs_find_exit(&src_fd); |
| 382 | return err; |
| 383 | } |