Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README |
| 3 | * |
| 4 | * Trivial changes by Alan Cox to remove EHASHCOLLISION for compatibility |
| 5 | * |
| 6 | * Trivial Changes: |
| 7 | * Rights granted to Hans Reiser to redistribute under other terms providing |
| 8 | * he accepts all liability including but not limited to patent, fitness |
| 9 | * for purpose, and direct or indirect claims arising from failure to perform. |
| 10 | * |
| 11 | * NO WARRANTY |
| 12 | */ |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/time.h> |
| 15 | #include <linux/bitops.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Al Viro | f466c6f | 2012-03-17 01:16:43 -0400 | [diff] [blame] | 17 | #include "reiserfs.h" |
Al Viro | a3063ab | 2012-03-17 01:03:10 -0400 | [diff] [blame] | 18 | #include "acl.h" |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 19 | #include "xattr.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/quotaops.h> |
| 21 | |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 22 | #define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) set_nlink(i, 1); } |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 23 | #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | // directory item contains array of entry headers. This performs |
| 26 | // binary search through that array |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 27 | static int bin_search_in_dir_item(struct reiserfs_dir_entry *de, loff_t off) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 29 | struct item_head *ih = de->de_ih; |
| 30 | struct reiserfs_de_head *deh = de->de_deh; |
| 31 | int rbound, lbound, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 33 | lbound = 0; |
| 34 | rbound = I_ENTRY_COUNT(ih) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 36 | for (j = (rbound + lbound) / 2; lbound <= rbound; |
| 37 | j = (rbound + lbound) / 2) { |
| 38 | if (off < deh_offset(deh + j)) { |
| 39 | rbound = j - 1; |
| 40 | continue; |
| 41 | } |
| 42 | if (off > deh_offset(deh + j)) { |
| 43 | lbound = j + 1; |
| 44 | continue; |
| 45 | } |
| 46 | // this is not name found, but matched third key component |
| 47 | de->de_entry_num = j; |
| 48 | return NAME_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 51 | de->de_entry_num = lbound; |
| 52 | return NAME_NOT_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | // comment? maybe something like set de to point to what the path points to? |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 56 | static inline void set_de_item_location(struct reiserfs_dir_entry *de, |
Josef "Jeff" Sipek | fec6d05 | 2006-12-08 02:36:32 -0800 | [diff] [blame] | 57 | struct treepath *path) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 59 | de->de_bh = get_last_bh(path); |
| 60 | de->de_ih = get_ih(path); |
| 61 | de->de_deh = B_I_DEH(de->de_bh, de->de_ih); |
| 62 | de->de_item_num = PATH_LAST_POSITION(path); |
| 63 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | // de_bh, de_ih, de_deh (points to first element of array), de_item_num is set |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 66 | inline void set_de_name_and_namelen(struct reiserfs_dir_entry *de) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 68 | struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Eric Sesterhenn | 14a6144 | 2006-10-03 23:36:38 +0200 | [diff] [blame] | 70 | BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 72 | de->de_entrylen = entry_length(de->de_bh, de->de_ih, de->de_entry_num); |
| 73 | de->de_namelen = de->de_entrylen - (de_with_sd(deh) ? SD_SIZE : 0); |
| 74 | de->de_name = B_I_PITEM(de->de_bh, de->de_ih) + deh_location(deh); |
| 75 | if (de->de_name[de->de_namelen - 1] == 0) |
| 76 | de->de_namelen = strlen(de->de_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | // what entry points to |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 80 | static inline void set_de_object_key(struct reiserfs_dir_entry *de) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
Eric Sesterhenn | 14a6144 | 2006-10-03 23:36:38 +0200 | [diff] [blame] | 82 | BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih)); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 83 | de->de_dir_id = deh_dir_id(&(de->de_deh[de->de_entry_num])); |
| 84 | de->de_objectid = deh_objectid(&(de->de_deh[de->de_entry_num])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 87 | static inline void store_de_entry_key(struct reiserfs_dir_entry *de) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 89 | struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Eric Sesterhenn | 14a6144 | 2006-10-03 23:36:38 +0200 | [diff] [blame] | 91 | BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 93 | /* store key of the found entry */ |
| 94 | de->de_entry_key.version = KEY_FORMAT_3_5; |
| 95 | de->de_entry_key.on_disk_key.k_dir_id = |
| 96 | le32_to_cpu(de->de_ih->ih_key.k_dir_id); |
| 97 | de->de_entry_key.on_disk_key.k_objectid = |
| 98 | le32_to_cpu(de->de_ih->ih_key.k_objectid); |
| 99 | set_cpu_key_k_offset(&(de->de_entry_key), deh_offset(deh)); |
| 100 | set_cpu_key_k_type(&(de->de_entry_key), TYPE_DIRENTRY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | /* We assign a key to each directory item, and place multiple entries |
| 104 | in a single directory item. A directory item has a key equal to the |
| 105 | key of the first directory entry in it. |
| 106 | |
| 107 | This function first calls search_by_key, then, if item whose first |
| 108 | entry matches is not found it looks for the entry inside directory |
| 109 | item found by search_by_key. Fills the path to the entry, and to the |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 110 | entry position in the item |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | */ |
| 113 | |
| 114 | /* The function is NOT SCHEDULE-SAFE! */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 115 | int search_by_entry_key(struct super_block *sb, const struct cpu_key *key, |
Josef "Jeff" Sipek | fec6d05 | 2006-12-08 02:36:32 -0800 | [diff] [blame] | 116 | struct treepath *path, struct reiserfs_dir_entry *de) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 118 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 120 | retval = search_item(sb, key, path); |
| 121 | switch (retval) { |
| 122 | case ITEM_NOT_FOUND: |
| 123 | if (!PATH_LAST_POSITION(path)) { |
Jeff Mahoney | 0030b64 | 2009-03-30 14:02:28 -0400 | [diff] [blame] | 124 | reiserfs_error(sb, "vs-7000", "search_by_key " |
| 125 | "returned item position == 0"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 126 | pathrelse(path); |
| 127 | return IO_ERROR; |
| 128 | } |
| 129 | PATH_LAST_POSITION(path)--; |
| 130 | |
| 131 | case ITEM_FOUND: |
| 132 | break; |
| 133 | |
| 134 | case IO_ERROR: |
| 135 | return retval; |
| 136 | |
| 137 | default: |
| 138 | pathrelse(path); |
Jeff Mahoney | 0030b64 | 2009-03-30 14:02:28 -0400 | [diff] [blame] | 139 | reiserfs_error(sb, "vs-7002", "no path to here"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 140 | return IO_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 143 | set_de_item_location(de, path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | #ifdef CONFIG_REISERFS_CHECK |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 146 | if (!is_direntry_le_ih(de->de_ih) || |
| 147 | COMP_SHORT_KEYS(&(de->de_ih->ih_key), key)) { |
| 148 | print_block(de->de_bh, 0, -1, -1); |
Jeff Mahoney | c3a9c21 | 2009-03-30 14:02:25 -0400 | [diff] [blame] | 149 | reiserfs_panic(sb, "vs-7005", "found item %h is not directory " |
| 150 | "item or does not belong to the same directory " |
| 151 | "as key %K", de->de_ih, key); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 152 | } |
| 153 | #endif /* CONFIG_REISERFS_CHECK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 155 | /* binary search in directory item by third componen t of the |
| 156 | key. sets de->de_entry_num of de */ |
| 157 | retval = bin_search_in_dir_item(de, cpu_key_k_offset(key)); |
| 158 | path->pos_in_item = de->de_entry_num; |
| 159 | if (retval != NAME_NOT_FOUND) { |
| 160 | // ugly, but rename needs de_bh, de_deh, de_name, de_namelen, de_objectid set |
| 161 | set_de_name_and_namelen(de); |
| 162 | set_de_object_key(de); |
| 163 | } |
| 164 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | /* Keyed 32-bit hash function using TEA in a Davis-Meyer function */ |
| 168 | |
| 169 | /* The third component is hashed, and you can choose from more than |
| 170 | one hash function. Per directory hashes are not yet implemented |
| 171 | but are thought about. This function should be moved to hashes.c |
| 172 | Jedi, please do so. -Hans */ |
| 173 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 174 | static __u32 get_third_component(struct super_block *s, |
| 175 | const char *name, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 177 | __u32 res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 179 | if (!len || (len == 1 && name[0] == '.')) |
| 180 | return DOT_OFFSET; |
| 181 | if (len == 2 && name[0] == '.' && name[1] == '.') |
| 182 | return DOT_DOT_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 184 | res = REISERFS_SB(s)->s_hash_function(name, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 186 | // take bits from 7-th to 30-th including both bounds |
| 187 | res = GET_HASH_VALUE(res); |
| 188 | if (res == 0) |
| 189 | // needed to have no names before "." and ".." those have hash |
| 190 | // value == 0 and generation conters 1 and 2 accordingly |
| 191 | res = 128; |
| 192 | return res + MAX_GENERATION_NUMBER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 195 | static int reiserfs_match(struct reiserfs_dir_entry *de, |
| 196 | const char *name, int namelen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 198 | int retval = NAME_NOT_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 200 | if ((namelen == de->de_namelen) && |
| 201 | !memcmp(de->de_name, name, de->de_namelen)) |
| 202 | retval = |
| 203 | (de_visible(de->de_deh + de->de_entry_num) ? NAME_FOUND : |
| 204 | NAME_FOUND_INVISIBLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 206 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | /* de's de_bh, de_ih, de_deh, de_item_num, de_entry_num are set already */ |
| 210 | |
| 211 | /* used when hash collisions exist */ |
| 212 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 213 | static int linear_search_in_dir_item(struct cpu_key *key, |
| 214 | struct reiserfs_dir_entry *de, |
| 215 | const char *name, int namelen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 217 | struct reiserfs_de_head *deh = de->de_deh; |
| 218 | int retval; |
| 219 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 221 | i = de->de_entry_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 223 | if (i == I_ENTRY_COUNT(de->de_ih) || |
| 224 | GET_HASH_VALUE(deh_offset(deh + i)) != |
| 225 | GET_HASH_VALUE(cpu_key_k_offset(key))) { |
| 226 | i--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 229 | RFALSE(de->de_deh != B_I_DEH(de->de_bh, de->de_ih), |
| 230 | "vs-7010: array of entry headers not found"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 232 | deh += i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 234 | for (; i >= 0; i--, deh--) { |
| 235 | if (GET_HASH_VALUE(deh_offset(deh)) != |
| 236 | GET_HASH_VALUE(cpu_key_k_offset(key))) { |
| 237 | // hash value does not match, no need to check whole name |
| 238 | return NAME_NOT_FOUND; |
| 239 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 241 | /* mark, that this generation number is used */ |
| 242 | if (de->de_gen_number_bit_string) |
| 243 | set_bit(GET_GENERATION_NUMBER(deh_offset(deh)), |
Jeff Mahoney | 3af1efe | 2006-03-02 13:25:26 -0500 | [diff] [blame] | 244 | de->de_gen_number_bit_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 246 | // calculate pointer to name and namelen |
| 247 | de->de_entry_num = i; |
| 248 | set_de_name_and_namelen(de); |
| 249 | |
| 250 | if ((retval = |
| 251 | reiserfs_match(de, name, namelen)) != NAME_NOT_FOUND) { |
| 252 | // de's de_name, de_namelen, de_recordlen are set. Fill the rest: |
| 253 | |
| 254 | // key of pointed object |
| 255 | set_de_object_key(de); |
| 256 | |
| 257 | store_de_entry_key(de); |
| 258 | |
| 259 | // retval can be NAME_FOUND or NAME_FOUND_INVISIBLE |
| 260 | return retval; |
| 261 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 264 | if (GET_GENERATION_NUMBER(le_ih_k_offset(de->de_ih)) == 0) |
| 265 | /* we have reached left most entry in the node. In common we |
| 266 | have to go to the left neighbor, but if generation counter |
| 267 | is 0 already, we know for sure, that there is no name with |
| 268 | the same hash value */ |
| 269 | // FIXME: this work correctly only because hash value can not |
| 270 | // be 0. Btw, in case of Yura's hash it is probably possible, |
| 271 | // so, this is a bug |
| 272 | return NAME_NOT_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 274 | RFALSE(de->de_item_num, |
| 275 | "vs-7015: two diritems of the same directory in one node?"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 277 | return GOTO_PREVIOUS_ITEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | // may return NAME_FOUND, NAME_FOUND_INVISIBLE, NAME_NOT_FOUND |
| 281 | // FIXME: should add something like IOERROR |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 282 | static int reiserfs_find_entry(struct inode *dir, const char *name, int namelen, |
Josef "Jeff" Sipek | fec6d05 | 2006-12-08 02:36:32 -0800 | [diff] [blame] | 283 | struct treepath *path_to_entry, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 284 | struct reiserfs_dir_entry *de) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 286 | struct cpu_key key_to_search; |
| 287 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 289 | if (namelen > REISERFS_MAX_NAME(dir->i_sb->s_blocksize)) |
| 290 | return NAME_NOT_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 292 | /* we will search for this key in the tree */ |
| 293 | make_cpu_key(&key_to_search, dir, |
| 294 | get_third_component(dir->i_sb, name, namelen), |
| 295 | TYPE_DIRENTRY, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 297 | while (1) { |
| 298 | retval = |
| 299 | search_by_entry_key(dir->i_sb, &key_to_search, |
| 300 | path_to_entry, de); |
| 301 | if (retval == IO_ERROR) { |
Jeff Mahoney | 0030b64 | 2009-03-30 14:02:28 -0400 | [diff] [blame] | 302 | reiserfs_error(dir->i_sb, "zam-7001", "io error"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 303 | return IO_ERROR; |
| 304 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 306 | /* compare names for all entries having given hash value */ |
| 307 | retval = |
| 308 | linear_search_in_dir_item(&key_to_search, de, name, |
| 309 | namelen); |
| 310 | if (retval != GOTO_PREVIOUS_ITEM) { |
| 311 | /* there is no need to scan directory anymore. Given entry found or does not exist */ |
| 312 | path_to_entry->pos_in_item = de->de_entry_num; |
| 313 | return retval; |
| 314 | } |
| 315 | |
| 316 | /* there is left neighboring item of this directory and given entry can be there */ |
| 317 | set_cpu_key_k_offset(&key_to_search, |
| 318 | le_ih_k_offset(de->de_ih) - 1); |
| 319 | pathrelse(path_to_entry); |
| 320 | |
| 321 | } /* while (1) */ |
| 322 | } |
| 323 | |
| 324 | static struct dentry *reiserfs_lookup(struct inode *dir, struct dentry *dentry, |
Al Viro | 00cd8dd | 2012-06-10 17:13:09 -0400 | [diff] [blame] | 325 | unsigned int flags) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 326 | { |
| 327 | int retval; |
| 328 | struct inode *inode = NULL; |
| 329 | struct reiserfs_dir_entry de; |
| 330 | INITIALIZE_PATH(path_to_entry); |
| 331 | |
| 332 | if (REISERFS_MAX_NAME(dir->i_sb->s_blocksize) < dentry->d_name.len) |
| 333 | return ERR_PTR(-ENAMETOOLONG); |
| 334 | |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 335 | reiserfs_write_lock(dir->i_sb); |
Frederic Weisbecker | b1c839b | 2009-05-08 01:05:06 +0200 | [diff] [blame] | 336 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 337 | de.de_gen_number_bit_string = NULL; |
| 338 | retval = |
| 339 | reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, |
| 340 | &path_to_entry, &de); |
| 341 | pathrelse(&path_to_entry); |
| 342 | if (retval == NAME_FOUND) { |
Jeff Mahoney | 677c9b2 | 2009-05-05 15:30:17 -0400 | [diff] [blame] | 343 | inode = reiserfs_iget(dir->i_sb, |
| 344 | (struct cpu_key *)&(de.de_dir_id)); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 345 | if (!inode || IS_ERR(inode)) { |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 346 | reiserfs_write_unlock(dir->i_sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 347 | return ERR_PTR(-EACCES); |
| 348 | } |
| 349 | |
Jeff Mahoney | 6dfede69 | 2009-03-30 14:02:32 -0400 | [diff] [blame] | 350 | /* Propagate the private flag so we know we're |
| 351 | * in the priv tree */ |
| 352 | if (IS_PRIVATE(dir)) |
| 353 | inode->i_flags |= S_PRIVATE; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 354 | } |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 355 | reiserfs_write_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | if (retval == IO_ERROR) { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 357 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Pekka Enberg | d9975d6 | 2006-01-14 13:21:09 -0800 | [diff] [blame] | 360 | return d_splice_alias(inode, dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 363 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | ** looks up the dentry of the parent directory for child. |
| 365 | ** taken from ext2_get_parent |
| 366 | */ |
| 367 | struct dentry *reiserfs_get_parent(struct dentry *child) |
| 368 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 369 | int retval; |
| 370 | struct inode *inode = NULL; |
| 371 | struct reiserfs_dir_entry de; |
| 372 | INITIALIZE_PATH(path_to_entry); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 373 | struct inode *dir = child->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 375 | if (dir->i_nlink == 0) { |
| 376 | return ERR_PTR(-ENOENT); |
| 377 | } |
| 378 | de.de_gen_number_bit_string = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 380 | reiserfs_write_lock(dir->i_sb); |
| 381 | retval = reiserfs_find_entry(dir, "..", 2, &path_to_entry, &de); |
| 382 | pathrelse(&path_to_entry); |
| 383 | if (retval != NAME_FOUND) { |
| 384 | reiserfs_write_unlock(dir->i_sb); |
| 385 | return ERR_PTR(-ENOENT); |
| 386 | } |
| 387 | inode = reiserfs_iget(dir->i_sb, (struct cpu_key *)&(de.de_dir_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | reiserfs_write_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Christoph Hellwig | 4400372 | 2008-08-11 15:49:04 +0200 | [diff] [blame] | 390 | return d_obtain_alias(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 393 | /* add entry to the directory (entry can be hidden). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | insert definition of when hidden directories are used here -Hans |
| 396 | |
| 397 | Does not mark dir inode dirty, do it after successesfull call to it */ |
| 398 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 399 | static int reiserfs_add_entry(struct reiserfs_transaction_handle *th, |
| 400 | struct inode *dir, const char *name, int namelen, |
| 401 | struct inode *inode, int visible) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 403 | struct cpu_key entry_key; |
| 404 | struct reiserfs_de_head *deh; |
| 405 | INITIALIZE_PATH(path); |
| 406 | struct reiserfs_dir_entry de; |
Jeff Mahoney | 3af1efe | 2006-03-02 13:25:26 -0500 | [diff] [blame] | 407 | DECLARE_BITMAP(bit_string, MAX_GENERATION_NUMBER + 1); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 408 | int gen_number; |
| 409 | char small_buf[32 + DEH_SIZE]; /* 48 bytes now and we avoid kmalloc |
| 410 | if we create file with short name */ |
| 411 | char *buffer; |
| 412 | int buflen, paste_size; |
| 413 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 415 | BUG_ON(!th->t_trans_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 417 | /* cannot allow items to be added into a busy deleted directory */ |
| 418 | if (!namelen) |
| 419 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 421 | if (namelen > REISERFS_MAX_NAME(dir->i_sb->s_blocksize)) |
| 422 | return -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 424 | /* each entry has unique key. compose it */ |
| 425 | make_cpu_key(&entry_key, dir, |
| 426 | get_third_component(dir->i_sb, name, namelen), |
| 427 | TYPE_DIRENTRY, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 429 | /* get memory for composing the entry */ |
| 430 | buflen = DEH_SIZE + ROUND_UP(namelen); |
| 431 | if (buflen > sizeof(small_buf)) { |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 432 | buffer = kmalloc(buflen, GFP_NOFS); |
Al Viro | 9dce07f | 2008-03-29 03:07:28 +0000 | [diff] [blame] | 433 | if (!buffer) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 434 | return -ENOMEM; |
| 435 | } else |
| 436 | buffer = small_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 438 | paste_size = |
| 439 | (get_inode_sd_version(dir) == |
| 440 | STAT_DATA_V1) ? (DEH_SIZE + namelen) : buflen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 442 | /* fill buffer : directory entry head, name[, dir objectid | , stat data | ,stat data, dir objectid ] */ |
| 443 | deh = (struct reiserfs_de_head *)buffer; |
| 444 | deh->deh_location = 0; /* JDM Endian safe if 0 */ |
| 445 | put_deh_offset(deh, cpu_key_k_offset(&entry_key)); |
| 446 | deh->deh_state = 0; /* JDM Endian safe if 0 */ |
| 447 | /* put key (ino analog) to de */ |
| 448 | deh->deh_dir_id = INODE_PKEY(inode)->k_dir_id; /* safe: k_dir_id is le */ |
| 449 | deh->deh_objectid = INODE_PKEY(inode)->k_objectid; /* safe: k_objectid is le */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 451 | /* copy name */ |
| 452 | memcpy((char *)(deh + 1), name, namelen); |
| 453 | /* padd by 0s to the 4 byte boundary */ |
| 454 | padd_item((char *)(deh + 1), ROUND_UP(namelen), namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 456 | /* entry is ready to be pasted into tree, set 'visibility' and 'stat data in entry' attributes */ |
| 457 | mark_de_without_sd(deh); |
| 458 | visible ? mark_de_visible(deh) : mark_de_hidden(deh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 460 | /* find the proper place for the new entry */ |
| 461 | memset(bit_string, 0, sizeof(bit_string)); |
Jeff Mahoney | 3af1efe | 2006-03-02 13:25:26 -0500 | [diff] [blame] | 462 | de.de_gen_number_bit_string = bit_string; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 463 | retval = reiserfs_find_entry(dir, name, namelen, &path, &de); |
| 464 | if (retval != NAME_NOT_FOUND) { |
| 465 | if (buffer != small_buf) |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 466 | kfree(buffer); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 467 | pathrelse(&path); |
| 468 | |
| 469 | if (retval == IO_ERROR) { |
| 470 | return -EIO; |
| 471 | } |
| 472 | |
| 473 | if (retval != NAME_FOUND) { |
Jeff Mahoney | 0030b64 | 2009-03-30 14:02:28 -0400 | [diff] [blame] | 474 | reiserfs_error(dir->i_sb, "zam-7002", |
| 475 | "reiserfs_find_entry() returned " |
| 476 | "unexpected value (%d)", retval); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | return -EEXIST; |
| 480 | } |
| 481 | |
| 482 | gen_number = |
Jeff Mahoney | 3af1efe | 2006-03-02 13:25:26 -0500 | [diff] [blame] | 483 | find_first_zero_bit(bit_string, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 484 | MAX_GENERATION_NUMBER + 1); |
| 485 | if (gen_number > MAX_GENERATION_NUMBER) { |
| 486 | /* there is no free generation number */ |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 487 | reiserfs_warning(dir->i_sb, "reiserfs-7010", |
| 488 | "Congratulations! we have got hash function " |
| 489 | "screwed up"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 490 | if (buffer != small_buf) |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 491 | kfree(buffer); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 492 | pathrelse(&path); |
| 493 | return -EBUSY; |
| 494 | } |
| 495 | /* adjust offset of directory enrty */ |
| 496 | put_deh_offset(deh, SET_GENERATION_NUMBER(deh_offset(deh), gen_number)); |
| 497 | set_cpu_key_k_offset(&entry_key, deh_offset(deh)); |
| 498 | |
| 499 | /* update max-hash-collisions counter in reiserfs_sb_info */ |
| 500 | PROC_INFO_MAX(th->t_super, max_hash_collisions, gen_number); |
| 501 | |
| 502 | if (gen_number != 0) { /* we need to re-search for the insertion point */ |
| 503 | if (search_by_entry_key(dir->i_sb, &entry_key, &path, &de) != |
| 504 | NAME_NOT_FOUND) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 505 | reiserfs_warning(dir->i_sb, "vs-7032", |
| 506 | "entry with this key (%K) already " |
| 507 | "exists", &entry_key); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 508 | |
| 509 | if (buffer != small_buf) |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 510 | kfree(buffer); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 511 | pathrelse(&path); |
| 512 | return -EBUSY; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | /* perform the insertion of the entry that we have prepared */ |
| 517 | retval = |
| 518 | reiserfs_paste_into_item(th, &path, &entry_key, dir, buffer, |
| 519 | paste_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | if (buffer != small_buf) |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 521 | kfree(buffer); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 522 | if (retval) { |
| 523 | reiserfs_check_path(&path); |
| 524 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 527 | dir->i_size += paste_size; |
| 528 | dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC; |
| 529 | if (!S_ISDIR(inode->i_mode) && visible) |
| 530 | // reiserfs_mkdir or reiserfs_rename will do that by itself |
| 531 | reiserfs_update_sd(th, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 533 | reiserfs_check_path(&path); |
| 534 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | /* quota utility function, call if you've had to abort after calling |
| 538 | ** new_inode_init, and have not called reiserfs_new_inode yet. |
| 539 | ** This should only be called on inodes that do not have stat data |
| 540 | ** inserted into the tree yet. |
| 541 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 542 | static int drop_new_inode(struct inode *inode) |
| 543 | { |
Christoph Hellwig | 9f75475 | 2010-03-03 09:05:05 -0500 | [diff] [blame] | 544 | dquot_drop(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 545 | make_bad_inode(inode); |
| 546 | inode->i_flags |= S_NOQUOTA; |
| 547 | iput(inode); |
| 548 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 551 | /* utility function that does setup for reiserfs_new_inode. |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 552 | ** dquot_initialize needs lots of credits so it's better to have it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | ** outside of a transaction, so we had to pull some bits of |
| 554 | ** reiserfs_new_inode out into this func. |
| 555 | */ |
Al Viro | 8e07189 | 2011-07-26 02:50:53 -0400 | [diff] [blame] | 556 | static int new_inode_init(struct inode *inode, struct inode *dir, umode_t mode) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 557 | { |
Jan Kara | 1b0a74d | 2005-08-13 13:15:34 +0200 | [diff] [blame] | 558 | /* Make inode invalid - just in case we are going to drop it before |
| 559 | * the initialization happens */ |
| 560 | INODE_PKEY(inode)->k_objectid = 0; |
Dmitry Monakhov | 04b7ed0 | 2010-03-04 17:32:19 +0300 | [diff] [blame] | 561 | /* the quota init calls have to know who to charge the quota to, so |
| 562 | ** we have to set uid and gid here |
| 563 | */ |
| 564 | inode_init_owner(inode, dir, mode); |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 565 | dquot_initialize(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 566 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Al Viro | 4acdaf2 | 2011-07-26 01:42:34 -0400 | [diff] [blame] | 569 | static int reiserfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
Al Viro | ebfc3b4 | 2012-06-10 18:05:36 -0400 | [diff] [blame] | 570 | bool excl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 572 | int retval; |
| 573 | struct inode *inode; |
| 574 | /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */ |
| 575 | int jbegin_count = |
| 576 | JOURNAL_PER_BALANCE_CNT * 2 + |
| 577 | 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) + |
| 578 | REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb)); |
| 579 | struct reiserfs_transaction_handle th; |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 580 | struct reiserfs_security_handle security; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 582 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 583 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 584 | if (!(inode = new_inode(dir->i_sb))) { |
| 585 | return -ENOMEM; |
| 586 | } |
| 587 | new_inode_init(inode, dir, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
Jeff Mahoney | 0ab2621 | 2009-03-30 14:02:39 -0400 | [diff] [blame] | 589 | jbegin_count += reiserfs_cache_default_acl(dir); |
Eric Paris | 2a7dba3 | 2011-02-01 11:05:39 -0500 | [diff] [blame] | 590 | retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security); |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 591 | if (retval < 0) { |
| 592 | drop_new_inode(inode); |
| 593 | return retval; |
| 594 | } |
| 595 | jbegin_count += retval; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 596 | reiserfs_write_lock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 598 | retval = journal_begin(&th, dir->i_sb, jbegin_count); |
| 599 | if (retval) { |
| 600 | drop_new_inode(inode); |
| 601 | goto out_failed; |
| 602 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 604 | retval = |
| 605 | reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry, |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 606 | inode, &security); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 607 | if (retval) |
| 608 | goto out_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 610 | inode->i_op = &reiserfs_file_inode_operations; |
| 611 | inode->i_fop = &reiserfs_file_operations; |
| 612 | inode->i_mapping->a_ops = &reiserfs_address_space_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 614 | retval = |
| 615 | reiserfs_add_entry(&th, dir, dentry->d_name.name, |
| 616 | dentry->d_name.len, inode, 1 /*visible */ ); |
| 617 | if (retval) { |
| 618 | int err; |
Miklos Szeredi | 6d6b77f | 2011-10-28 14:13:28 +0200 | [diff] [blame] | 619 | drop_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 620 | reiserfs_update_sd(&th, inode); |
| 621 | err = journal_end(&th, dir->i_sb, jbegin_count); |
| 622 | if (err) |
| 623 | retval = err; |
Al Viro | c1eaa26 | 2008-12-30 02:03:58 -0500 | [diff] [blame] | 624 | unlock_new_inode(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 625 | iput(inode); |
| 626 | goto out_failed; |
| 627 | } |
| 628 | reiserfs_update_inode_transaction(inode); |
| 629 | reiserfs_update_inode_transaction(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
Al Viro | c1eaa26 | 2008-12-30 02:03:58 -0500 | [diff] [blame] | 631 | unlock_new_inode(inode); |
Al Viro | 8fc37ec | 2012-07-19 09:18:15 +0400 | [diff] [blame] | 632 | d_instantiate(dentry, inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 633 | retval = journal_end(&th, dir->i_sb, jbegin_count); |
| 634 | |
| 635 | out_failed: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 636 | reiserfs_write_unlock(dir->i_sb); |
| 637 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Al Viro | 1a67aaf | 2011-07-26 01:52:52 -0400 | [diff] [blame] | 640 | static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 641 | dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 643 | int retval; |
| 644 | struct inode *inode; |
| 645 | struct reiserfs_transaction_handle th; |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 646 | struct reiserfs_security_handle security; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 647 | /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */ |
| 648 | int jbegin_count = |
| 649 | JOURNAL_PER_BALANCE_CNT * 3 + |
| 650 | 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) + |
| 651 | REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 653 | if (!new_valid_dev(rdev)) |
| 654 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 656 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 657 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 658 | if (!(inode = new_inode(dir->i_sb))) { |
| 659 | return -ENOMEM; |
| 660 | } |
| 661 | new_inode_init(inode, dir, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Jeff Mahoney | 0ab2621 | 2009-03-30 14:02:39 -0400 | [diff] [blame] | 663 | jbegin_count += reiserfs_cache_default_acl(dir); |
Eric Paris | 2a7dba3 | 2011-02-01 11:05:39 -0500 | [diff] [blame] | 664 | retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security); |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 665 | if (retval < 0) { |
| 666 | drop_new_inode(inode); |
| 667 | return retval; |
| 668 | } |
| 669 | jbegin_count += retval; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 670 | reiserfs_write_lock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 672 | retval = journal_begin(&th, dir->i_sb, jbegin_count); |
| 673 | if (retval) { |
| 674 | drop_new_inode(inode); |
| 675 | goto out_failed; |
| 676 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 678 | retval = |
| 679 | reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry, |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 680 | inode, &security); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 681 | if (retval) { |
| 682 | goto out_failed; |
| 683 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 685 | inode->i_op = &reiserfs_special_inode_operations; |
| 686 | init_special_inode(inode, inode->i_mode, rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 688 | //FIXME: needed for block and char devices only |
| 689 | reiserfs_update_sd(&th, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 691 | reiserfs_update_inode_transaction(inode); |
| 692 | reiserfs_update_inode_transaction(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 694 | retval = |
| 695 | reiserfs_add_entry(&th, dir, dentry->d_name.name, |
| 696 | dentry->d_name.len, inode, 1 /*visible */ ); |
| 697 | if (retval) { |
| 698 | int err; |
Miklos Szeredi | 6d6b77f | 2011-10-28 14:13:28 +0200 | [diff] [blame] | 699 | drop_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 700 | reiserfs_update_sd(&th, inode); |
| 701 | err = journal_end(&th, dir->i_sb, jbegin_count); |
| 702 | if (err) |
| 703 | retval = err; |
Al Viro | c1eaa26 | 2008-12-30 02:03:58 -0500 | [diff] [blame] | 704 | unlock_new_inode(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 705 | iput(inode); |
| 706 | goto out_failed; |
| 707 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
Al Viro | c1eaa26 | 2008-12-30 02:03:58 -0500 | [diff] [blame] | 709 | unlock_new_inode(inode); |
Al Viro | 8fc37ec | 2012-07-19 09:18:15 +0400 | [diff] [blame] | 710 | d_instantiate(dentry, inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 711 | retval = journal_end(&th, dir->i_sb, jbegin_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 713 | out_failed: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 714 | reiserfs_write_unlock(dir->i_sb); |
| 715 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Al Viro | 18bb1db | 2011-07-26 01:41:39 -0400 | [diff] [blame] | 718 | static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 720 | int retval; |
| 721 | struct inode *inode; |
| 722 | struct reiserfs_transaction_handle th; |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 723 | struct reiserfs_security_handle security; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 724 | /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */ |
| 725 | int jbegin_count = |
| 726 | JOURNAL_PER_BALANCE_CNT * 3 + |
| 727 | 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) + |
| 728 | REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 730 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 733 | /* set flag that new packing locality created and new blocks for the content * of that directory are not displaced yet */ |
| 734 | REISERFS_I(dir)->new_packing_locality = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | #endif |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 736 | mode = S_IFDIR | mode; |
| 737 | if (!(inode = new_inode(dir->i_sb))) { |
| 738 | return -ENOMEM; |
| 739 | } |
| 740 | new_inode_init(inode, dir, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | |
Jeff Mahoney | 0ab2621 | 2009-03-30 14:02:39 -0400 | [diff] [blame] | 742 | jbegin_count += reiserfs_cache_default_acl(dir); |
Eric Paris | 2a7dba3 | 2011-02-01 11:05:39 -0500 | [diff] [blame] | 743 | retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security); |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 744 | if (retval < 0) { |
| 745 | drop_new_inode(inode); |
| 746 | return retval; |
| 747 | } |
| 748 | jbegin_count += retval; |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 749 | reiserfs_write_lock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 751 | retval = journal_begin(&th, dir->i_sb, jbegin_count); |
| 752 | if (retval) { |
| 753 | drop_new_inode(inode); |
| 754 | goto out_failed; |
| 755 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 757 | /* inc the link count now, so another writer doesn't overflow it while |
| 758 | ** we sleep later on. |
| 759 | */ |
| 760 | INC_DIR_INODE_NLINK(dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 762 | retval = reiserfs_new_inode(&th, dir, mode, NULL /*symlink */ , |
| 763 | old_format_only(dir->i_sb) ? |
| 764 | EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE, |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 765 | dentry, inode, &security); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 766 | if (retval) { |
Al Viro | 99890a3 | 2011-03-02 09:35:13 -0500 | [diff] [blame] | 767 | DEC_DIR_INODE_NLINK(dir) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 768 | goto out_failed; |
| 769 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 771 | reiserfs_update_inode_transaction(inode); |
| 772 | reiserfs_update_inode_transaction(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 774 | inode->i_op = &reiserfs_dir_inode_operations; |
| 775 | inode->i_fop = &reiserfs_dir_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 777 | // note, _this_ add_entry will not update dir's stat data |
| 778 | retval = |
| 779 | reiserfs_add_entry(&th, dir, dentry->d_name.name, |
| 780 | dentry->d_name.len, inode, 1 /*visible */ ); |
| 781 | if (retval) { |
| 782 | int err; |
Miklos Szeredi | 6d6b77f | 2011-10-28 14:13:28 +0200 | [diff] [blame] | 783 | clear_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 784 | DEC_DIR_INODE_NLINK(dir); |
| 785 | reiserfs_update_sd(&th, inode); |
| 786 | err = journal_end(&th, dir->i_sb, jbegin_count); |
| 787 | if (err) |
| 788 | retval = err; |
Al Viro | c1eaa26 | 2008-12-30 02:03:58 -0500 | [diff] [blame] | 789 | unlock_new_inode(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 790 | iput(inode); |
| 791 | goto out_failed; |
| 792 | } |
| 793 | // the above add_entry did not update dir's stat data |
| 794 | reiserfs_update_sd(&th, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
Al Viro | c1eaa26 | 2008-12-30 02:03:58 -0500 | [diff] [blame] | 796 | unlock_new_inode(inode); |
Al Viro | 8fc37ec | 2012-07-19 09:18:15 +0400 | [diff] [blame] | 797 | d_instantiate(dentry, inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 798 | retval = journal_end(&th, dir->i_sb, jbegin_count); |
Frederic Weisbecker | b10ab4c | 2009-08-25 02:44:21 +0200 | [diff] [blame] | 799 | out_failed: |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 800 | reiserfs_write_unlock(dir->i_sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 801 | return retval; |
| 802 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 804 | static inline int reiserfs_empty_dir(struct inode *inode) |
| 805 | { |
| 806 | /* we can cheat because an old format dir cannot have |
| 807 | ** EMPTY_DIR_SIZE, and a new format dir cannot have |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 808 | ** EMPTY_DIR_SIZE_V1. So, if the inode is either size, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 809 | ** regardless of disk format version, the directory is empty. |
| 810 | */ |
| 811 | if (inode->i_size != EMPTY_DIR_SIZE && |
| 812 | inode->i_size != EMPTY_DIR_SIZE_V1) { |
| 813 | return 0; |
| 814 | } |
| 815 | return 1; |
| 816 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 818 | static int reiserfs_rmdir(struct inode *dir, struct dentry *dentry) |
| 819 | { |
| 820 | int retval, err; |
| 821 | struct inode *inode; |
| 822 | struct reiserfs_transaction_handle th; |
| 823 | int jbegin_count; |
| 824 | INITIALIZE_PATH(path); |
| 825 | struct reiserfs_dir_entry de; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 827 | /* we will be doing 2 balancings and update 2 stat data, we change quotas |
| 828 | * of the owner of the directory and of the owner of the parent directory. |
| 829 | * The quota structure is possibly deleted only on last iput => outside |
| 830 | * of this transaction */ |
| 831 | jbegin_count = |
| 832 | JOURNAL_PER_BALANCE_CNT * 2 + 2 + |
| 833 | 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 835 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 836 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 837 | reiserfs_write_lock(dir->i_sb); |
| 838 | retval = journal_begin(&th, dir->i_sb, jbegin_count); |
| 839 | if (retval) |
| 840 | goto out_rmdir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 842 | de.de_gen_number_bit_string = NULL; |
| 843 | if ((retval = |
| 844 | reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, |
| 845 | &path, &de)) == NAME_NOT_FOUND) { |
| 846 | retval = -ENOENT; |
| 847 | goto end_rmdir; |
| 848 | } else if (retval == IO_ERROR) { |
| 849 | retval = -EIO; |
| 850 | goto end_rmdir; |
| 851 | } |
| 852 | |
| 853 | inode = dentry->d_inode; |
| 854 | |
| 855 | reiserfs_update_inode_transaction(inode); |
| 856 | reiserfs_update_inode_transaction(dir); |
| 857 | |
| 858 | if (de.de_objectid != inode->i_ino) { |
| 859 | // FIXME: compare key of an object and a key found in the |
| 860 | // entry |
| 861 | retval = -EIO; |
| 862 | goto end_rmdir; |
| 863 | } |
| 864 | if (!reiserfs_empty_dir(inode)) { |
| 865 | retval = -ENOTEMPTY; |
| 866 | goto end_rmdir; |
| 867 | } |
| 868 | |
| 869 | /* cut entry from dir directory */ |
| 870 | retval = reiserfs_cut_from_item(&th, &path, &(de.de_entry_key), dir, NULL, /* page */ |
| 871 | 0 /*new file size - not used here */ ); |
| 872 | if (retval < 0) |
| 873 | goto end_rmdir; |
| 874 | |
| 875 | if (inode->i_nlink != 2 && inode->i_nlink != 1) |
Jeff Mahoney | 0030b64 | 2009-03-30 14:02:28 -0400 | [diff] [blame] | 876 | reiserfs_error(inode->i_sb, "reiserfs-7040", |
| 877 | "empty directory has nlink != 2 (%d)", |
| 878 | inode->i_nlink); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 879 | |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 880 | clear_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 881 | inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC; |
| 882 | reiserfs_update_sd(&th, inode); |
| 883 | |
| 884 | DEC_DIR_INODE_NLINK(dir) |
| 885 | dir->i_size -= (DEH_SIZE + de.de_entrylen); |
| 886 | reiserfs_update_sd(&th, dir); |
| 887 | |
| 888 | /* prevent empty directory from getting lost */ |
| 889 | add_save_link(&th, inode, 0 /* not truncate */ ); |
| 890 | |
| 891 | retval = journal_end(&th, dir->i_sb, jbegin_count); |
| 892 | reiserfs_check_path(&path); |
| 893 | out_rmdir: |
| 894 | reiserfs_write_unlock(dir->i_sb); |
| 895 | return retval; |
| 896 | |
| 897 | end_rmdir: |
| 898 | /* we must release path, because we did not call |
| 899 | reiserfs_cut_from_item, or reiserfs_cut_from_item does not |
| 900 | release path if operation was not complete */ |
| 901 | pathrelse(&path); |
| 902 | err = journal_end(&th, dir->i_sb, jbegin_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | reiserfs_write_unlock(dir->i_sb); |
| 904 | return err ? err : retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 907 | static int reiserfs_unlink(struct inode *dir, struct dentry *dentry) |
| 908 | { |
| 909 | int retval, err; |
| 910 | struct inode *inode; |
| 911 | struct reiserfs_dir_entry de; |
| 912 | INITIALIZE_PATH(path); |
| 913 | struct reiserfs_transaction_handle th; |
| 914 | int jbegin_count; |
| 915 | unsigned long savelink; |
| 916 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 917 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 918 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 919 | inode = dentry->d_inode; |
| 920 | |
| 921 | /* in this transaction we can be doing at max two balancings and update |
| 922 | * two stat datas, we change quotas of the owner of the directory and of |
| 923 | * the owner of the parent directory. The quota structure is possibly |
| 924 | * deleted only on iput => outside of this transaction */ |
| 925 | jbegin_count = |
| 926 | JOURNAL_PER_BALANCE_CNT * 2 + 2 + |
| 927 | 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb); |
| 928 | |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 929 | reiserfs_write_lock(dir->i_sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 930 | retval = journal_begin(&th, dir->i_sb, jbegin_count); |
| 931 | if (retval) |
| 932 | goto out_unlink; |
| 933 | |
| 934 | de.de_gen_number_bit_string = NULL; |
| 935 | if ((retval = |
| 936 | reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, |
| 937 | &path, &de)) == NAME_NOT_FOUND) { |
| 938 | retval = -ENOENT; |
| 939 | goto end_unlink; |
| 940 | } else if (retval == IO_ERROR) { |
| 941 | retval = -EIO; |
| 942 | goto end_unlink; |
| 943 | } |
| 944 | |
| 945 | reiserfs_update_inode_transaction(inode); |
| 946 | reiserfs_update_inode_transaction(dir); |
| 947 | |
| 948 | if (de.de_objectid != inode->i_ino) { |
| 949 | // FIXME: compare key of an object and a key found in the |
| 950 | // entry |
| 951 | retval = -EIO; |
| 952 | goto end_unlink; |
| 953 | } |
| 954 | |
| 955 | if (!inode->i_nlink) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 956 | reiserfs_warning(inode->i_sb, "reiserfs-7042", |
| 957 | "deleting nonexistent file (%lu), %d", |
| 958 | inode->i_ino, inode->i_nlink); |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 959 | set_nlink(inode, 1); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 962 | drop_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 963 | |
| 964 | /* |
| 965 | * we schedule before doing the add_save_link call, save the link |
| 966 | * count so we don't race |
| 967 | */ |
| 968 | savelink = inode->i_nlink; |
| 969 | |
| 970 | retval = |
| 971 | reiserfs_cut_from_item(&th, &path, &(de.de_entry_key), dir, NULL, |
| 972 | 0); |
| 973 | if (retval < 0) { |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 974 | inc_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 975 | goto end_unlink; |
| 976 | } |
| 977 | inode->i_ctime = CURRENT_TIME_SEC; |
| 978 | reiserfs_update_sd(&th, inode); |
| 979 | |
| 980 | dir->i_size -= (de.de_entrylen + DEH_SIZE); |
| 981 | dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC; |
| 982 | reiserfs_update_sd(&th, dir); |
| 983 | |
| 984 | if (!savelink) |
| 985 | /* prevent file from getting lost */ |
| 986 | add_save_link(&th, inode, 0 /* not truncate */ ); |
| 987 | |
| 988 | retval = journal_end(&th, dir->i_sb, jbegin_count); |
| 989 | reiserfs_check_path(&path); |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 990 | reiserfs_write_unlock(dir->i_sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 991 | return retval; |
| 992 | |
| 993 | end_unlink: |
| 994 | pathrelse(&path); |
| 995 | err = journal_end(&th, dir->i_sb, jbegin_count); |
| 996 | reiserfs_check_path(&path); |
| 997 | if (err) |
| 998 | retval = err; |
| 999 | out_unlink: |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 1000 | reiserfs_write_unlock(dir->i_sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1001 | return retval; |
| 1002 | } |
| 1003 | |
| 1004 | static int reiserfs_symlink(struct inode *parent_dir, |
| 1005 | struct dentry *dentry, const char *symname) |
| 1006 | { |
| 1007 | int retval; |
| 1008 | struct inode *inode; |
| 1009 | char *name; |
| 1010 | int item_len; |
| 1011 | struct reiserfs_transaction_handle th; |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 1012 | struct reiserfs_security_handle security; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1013 | int mode = S_IFLNK | S_IRWXUGO; |
| 1014 | /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */ |
| 1015 | int jbegin_count = |
| 1016 | JOURNAL_PER_BALANCE_CNT * 3 + |
| 1017 | 2 * (REISERFS_QUOTA_INIT_BLOCKS(parent_dir->i_sb) + |
| 1018 | REISERFS_QUOTA_TRANS_BLOCKS(parent_dir->i_sb)); |
| 1019 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 1020 | dquot_initialize(parent_dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 1021 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1022 | if (!(inode = new_inode(parent_dir->i_sb))) { |
| 1023 | return -ENOMEM; |
| 1024 | } |
| 1025 | new_inode_init(inode, parent_dir, mode); |
| 1026 | |
Eric Paris | 2a7dba3 | 2011-02-01 11:05:39 -0500 | [diff] [blame] | 1027 | retval = reiserfs_security_init(parent_dir, inode, &dentry->d_name, |
| 1028 | &security); |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 1029 | if (retval < 0) { |
| 1030 | drop_new_inode(inode); |
| 1031 | return retval; |
| 1032 | } |
| 1033 | jbegin_count += retval; |
| 1034 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1035 | reiserfs_write_lock(parent_dir->i_sb); |
| 1036 | item_len = ROUND_UP(strlen(symname)); |
| 1037 | if (item_len > MAX_DIRECT_ITEM_LEN(parent_dir->i_sb->s_blocksize)) { |
| 1038 | retval = -ENAMETOOLONG; |
| 1039 | drop_new_inode(inode); |
| 1040 | goto out_failed; |
| 1041 | } |
| 1042 | |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 1043 | name = kmalloc(item_len, GFP_NOFS); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1044 | if (!name) { |
| 1045 | drop_new_inode(inode); |
| 1046 | retval = -ENOMEM; |
| 1047 | goto out_failed; |
| 1048 | } |
| 1049 | memcpy(name, symname, strlen(symname)); |
| 1050 | padd_item(name, item_len, strlen(symname)); |
| 1051 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1052 | retval = journal_begin(&th, parent_dir->i_sb, jbegin_count); |
| 1053 | if (retval) { |
| 1054 | drop_new_inode(inode); |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 1055 | kfree(name); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1056 | goto out_failed; |
| 1057 | } |
| 1058 | |
| 1059 | retval = |
| 1060 | reiserfs_new_inode(&th, parent_dir, mode, name, strlen(symname), |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 1061 | dentry, inode, &security); |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 1062 | kfree(name); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1063 | if (retval) { /* reiserfs_new_inode iputs for us */ |
| 1064 | goto out_failed; |
| 1065 | } |
| 1066 | |
| 1067 | reiserfs_update_inode_transaction(inode); |
| 1068 | reiserfs_update_inode_transaction(parent_dir); |
| 1069 | |
| 1070 | inode->i_op = &reiserfs_symlink_inode_operations; |
| 1071 | inode->i_mapping->a_ops = &reiserfs_address_space_operations; |
| 1072 | |
| 1073 | // must be sure this inode is written with this transaction |
| 1074 | // |
| 1075 | //reiserfs_update_sd (&th, inode, READ_BLOCKS); |
| 1076 | |
| 1077 | retval = reiserfs_add_entry(&th, parent_dir, dentry->d_name.name, |
| 1078 | dentry->d_name.len, inode, 1 /*visible */ ); |
| 1079 | if (retval) { |
| 1080 | int err; |
Miklos Szeredi | 6d6b77f | 2011-10-28 14:13:28 +0200 | [diff] [blame] | 1081 | drop_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1082 | reiserfs_update_sd(&th, inode); |
| 1083 | err = journal_end(&th, parent_dir->i_sb, jbegin_count); |
| 1084 | if (err) |
| 1085 | retval = err; |
Al Viro | c1eaa26 | 2008-12-30 02:03:58 -0500 | [diff] [blame] | 1086 | unlock_new_inode(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1087 | iput(inode); |
| 1088 | goto out_failed; |
| 1089 | } |
| 1090 | |
Al Viro | c1eaa26 | 2008-12-30 02:03:58 -0500 | [diff] [blame] | 1091 | unlock_new_inode(inode); |
Al Viro | 8fc37ec | 2012-07-19 09:18:15 +0400 | [diff] [blame] | 1092 | d_instantiate(dentry, inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1093 | retval = journal_end(&th, parent_dir->i_sb, jbegin_count); |
| 1094 | out_failed: |
| 1095 | reiserfs_write_unlock(parent_dir->i_sb); |
| 1096 | return retval; |
| 1097 | } |
| 1098 | |
| 1099 | static int reiserfs_link(struct dentry *old_dentry, struct inode *dir, |
| 1100 | struct dentry *dentry) |
| 1101 | { |
| 1102 | int retval; |
| 1103 | struct inode *inode = old_dentry->d_inode; |
| 1104 | struct reiserfs_transaction_handle th; |
| 1105 | /* We need blocks for transaction + update of quotas for the owners of the directory */ |
| 1106 | int jbegin_count = |
| 1107 | JOURNAL_PER_BALANCE_CNT * 3 + |
| 1108 | 2 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb); |
| 1109 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 1110 | dquot_initialize(dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 1111 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1112 | reiserfs_write_lock(dir->i_sb); |
| 1113 | if (inode->i_nlink >= REISERFS_LINK_MAX) { |
| 1114 | //FIXME: sd_nlink is 32 bit for new files |
| 1115 | reiserfs_write_unlock(dir->i_sb); |
| 1116 | return -EMLINK; |
| 1117 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1118 | |
| 1119 | /* inc before scheduling so reiserfs_unlink knows we are here */ |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 1120 | inc_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1121 | |
| 1122 | retval = journal_begin(&th, dir->i_sb, jbegin_count); |
| 1123 | if (retval) { |
Miklos Szeredi | 6d6b77f | 2011-10-28 14:13:28 +0200 | [diff] [blame] | 1124 | drop_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1125 | reiserfs_write_unlock(dir->i_sb); |
| 1126 | return retval; |
| 1127 | } |
| 1128 | |
| 1129 | /* create new entry */ |
| 1130 | retval = |
| 1131 | reiserfs_add_entry(&th, dir, dentry->d_name.name, |
| 1132 | dentry->d_name.len, inode, 1 /*visible */ ); |
| 1133 | |
| 1134 | reiserfs_update_inode_transaction(inode); |
| 1135 | reiserfs_update_inode_transaction(dir); |
| 1136 | |
| 1137 | if (retval) { |
| 1138 | int err; |
Miklos Szeredi | 6d6b77f | 2011-10-28 14:13:28 +0200 | [diff] [blame] | 1139 | drop_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1140 | err = journal_end(&th, dir->i_sb, jbegin_count); |
| 1141 | reiserfs_write_unlock(dir->i_sb); |
| 1142 | return err ? err : retval; |
| 1143 | } |
| 1144 | |
| 1145 | inode->i_ctime = CURRENT_TIME_SEC; |
| 1146 | reiserfs_update_sd(&th, inode); |
| 1147 | |
Al Viro | 7de9c6ee | 2010-10-23 11:11:40 -0400 | [diff] [blame] | 1148 | ihold(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1149 | d_instantiate(dentry, inode); |
| 1150 | retval = journal_end(&th, dir->i_sb, jbegin_count); |
| 1151 | reiserfs_write_unlock(dir->i_sb); |
| 1152 | return retval; |
| 1153 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 1155 | /* de contains information pointing to an entry which */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1156 | static int de_still_valid(const char *name, int len, |
| 1157 | struct reiserfs_dir_entry *de) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1159 | struct reiserfs_dir_entry tmp = *de; |
| 1160 | |
| 1161 | // recalculate pointer to name and name length |
| 1162 | set_de_name_and_namelen(&tmp); |
| 1163 | // FIXME: could check more |
| 1164 | if (tmp.de_namelen != len || memcmp(name, de->de_name, len)) |
| 1165 | return 0; |
| 1166 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1169 | static int entry_points_to_object(const char *name, int len, |
| 1170 | struct reiserfs_dir_entry *de, |
| 1171 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1173 | if (!de_still_valid(name, len, de)) |
| 1174 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1176 | if (inode) { |
| 1177 | if (!de_visible(de->de_deh + de->de_entry_num)) |
Jeff Mahoney | c3a9c21 | 2009-03-30 14:02:25 -0400 | [diff] [blame] | 1178 | reiserfs_panic(inode->i_sb, "vs-7042", |
| 1179 | "entry must be visible"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1180 | return (de->de_objectid == inode->i_ino) ? 1 : 0; |
| 1181 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1183 | /* this must be added hidden entry */ |
| 1184 | if (de_visible(de->de_deh + de->de_entry_num)) |
Jeff Mahoney | c3a9c21 | 2009-03-30 14:02:25 -0400 | [diff] [blame] | 1185 | reiserfs_panic(NULL, "vs-7043", "entry must be visible"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1187 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | /* sets key of objectid the entry has to point to */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1191 | static void set_ino_in_dir_entry(struct reiserfs_dir_entry *de, |
| 1192 | struct reiserfs_key *key) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1194 | /* JDM These operations are endian safe - both are le */ |
| 1195 | de->de_deh[de->de_entry_num].deh_dir_id = key->k_dir_id; |
| 1196 | de->de_deh[de->de_entry_num].deh_objectid = key->k_objectid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 1199 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | * process, that is going to call fix_nodes/do_balance must hold only |
| 1201 | * one path. If it holds 2 or more, it can get into endless waiting in |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 1202 | * get_empty_nodes or its clones |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1204 | static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 1205 | struct inode *new_dir, struct dentry *new_dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1207 | int retval; |
| 1208 | INITIALIZE_PATH(old_entry_path); |
| 1209 | INITIALIZE_PATH(new_entry_path); |
| 1210 | INITIALIZE_PATH(dot_dot_entry_path); |
| 1211 | struct item_head new_entry_ih, old_entry_ih, dot_dot_ih; |
| 1212 | struct reiserfs_dir_entry old_de, new_de, dot_dot_de; |
| 1213 | struct inode *old_inode, *new_dentry_inode; |
| 1214 | struct reiserfs_transaction_handle th; |
| 1215 | int jbegin_count; |
| 1216 | umode_t old_inode_mode; |
| 1217 | unsigned long savelink = 1; |
| 1218 | struct timespec ctime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1220 | /* three balancings: (1) old name removal, (2) new name insertion |
| 1221 | and (3) maybe "save" link insertion |
| 1222 | stat data updates: (1) old directory, |
| 1223 | (2) new directory and (3) maybe old object stat data (when it is |
| 1224 | directory) and (4) maybe stat data of object to which new entry |
| 1225 | pointed initially and (5) maybe block containing ".." of |
| 1226 | renamed directory |
| 1227 | quota updates: two parent directories */ |
| 1228 | jbegin_count = |
| 1229 | JOURNAL_PER_BALANCE_CNT * 3 + 5 + |
| 1230 | 4 * REISERFS_QUOTA_TRANS_BLOCKS(old_dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 1232 | dquot_initialize(old_dir); |
| 1233 | dquot_initialize(new_dir); |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 1234 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1235 | old_inode = old_dentry->d_inode; |
| 1236 | new_dentry_inode = new_dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1238 | // make sure, that oldname still exists and points to an object we |
| 1239 | // are going to rename |
| 1240 | old_de.de_gen_number_bit_string = NULL; |
| 1241 | reiserfs_write_lock(old_dir->i_sb); |
| 1242 | retval = |
| 1243 | reiserfs_find_entry(old_dir, old_dentry->d_name.name, |
| 1244 | old_dentry->d_name.len, &old_entry_path, |
| 1245 | &old_de); |
| 1246 | pathrelse(&old_entry_path); |
| 1247 | if (retval == IO_ERROR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | reiserfs_write_unlock(old_dir->i_sb); |
| 1249 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1251 | |
| 1252 | if (retval != NAME_FOUND || old_de.de_objectid != old_inode->i_ino) { |
| 1253 | reiserfs_write_unlock(old_dir->i_sb); |
| 1254 | return -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1256 | |
| 1257 | old_inode_mode = old_inode->i_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | if (S_ISDIR(old_inode_mode)) { |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 1259 | // make sure, that directory being renamed has correct ".." |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1260 | // and that its new parent directory has not too many links |
| 1261 | // already |
| 1262 | |
| 1263 | if (new_dentry_inode) { |
| 1264 | if (!reiserfs_empty_dir(new_dentry_inode)) { |
| 1265 | reiserfs_write_unlock(old_dir->i_sb); |
| 1266 | return -ENOTEMPTY; |
| 1267 | } |
| 1268 | } |
| 1269 | |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 1270 | /* directory is renamed, its parent directory will be changed, |
| 1271 | ** so find ".." entry |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1272 | */ |
| 1273 | dot_dot_de.de_gen_number_bit_string = NULL; |
| 1274 | retval = |
| 1275 | reiserfs_find_entry(old_inode, "..", 2, &dot_dot_entry_path, |
| 1276 | &dot_dot_de); |
| 1277 | pathrelse(&dot_dot_entry_path); |
| 1278 | if (retval != NAME_FOUND) { |
| 1279 | reiserfs_write_unlock(old_dir->i_sb); |
| 1280 | return -EIO; |
| 1281 | } |
| 1282 | |
| 1283 | /* inode number of .. must equal old_dir->i_ino */ |
| 1284 | if (dot_dot_de.de_objectid != old_dir->i_ino) { |
| 1285 | reiserfs_write_unlock(old_dir->i_sb); |
| 1286 | return -EIO; |
| 1287 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1290 | retval = journal_begin(&th, old_dir->i_sb, jbegin_count); |
| 1291 | if (retval) { |
| 1292 | reiserfs_write_unlock(old_dir->i_sb); |
| 1293 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1296 | /* add new entry (or find the existing one) */ |
| 1297 | retval = |
| 1298 | reiserfs_add_entry(&th, new_dir, new_dentry->d_name.name, |
| 1299 | new_dentry->d_name.len, old_inode, 0); |
| 1300 | if (retval == -EEXIST) { |
| 1301 | if (!new_dentry_inode) { |
Jeff Mahoney | c3a9c21 | 2009-03-30 14:02:25 -0400 | [diff] [blame] | 1302 | reiserfs_panic(old_dir->i_sb, "vs-7050", |
| 1303 | "new entry is found, new inode == 0"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1304 | } |
| 1305 | } else if (retval) { |
| 1306 | int err = journal_end(&th, old_dir->i_sb, jbegin_count); |
| 1307 | reiserfs_write_unlock(old_dir->i_sb); |
| 1308 | return err ? err : retval; |
| 1309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1311 | reiserfs_update_inode_transaction(old_dir); |
| 1312 | reiserfs_update_inode_transaction(new_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1314 | /* this makes it so an fsync on an open fd for the old name will |
| 1315 | ** commit the rename operation |
| 1316 | */ |
| 1317 | reiserfs_update_inode_transaction(old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1319 | if (new_dentry_inode) |
| 1320 | reiserfs_update_inode_transaction(new_dentry_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1322 | while (1) { |
| 1323 | // look for old name using corresponding entry key (found by reiserfs_find_entry) |
| 1324 | if ((retval = |
| 1325 | search_by_entry_key(new_dir->i_sb, &old_de.de_entry_key, |
| 1326 | &old_entry_path, |
| 1327 | &old_de)) != NAME_FOUND) { |
| 1328 | pathrelse(&old_entry_path); |
| 1329 | journal_end(&th, old_dir->i_sb, jbegin_count); |
| 1330 | reiserfs_write_unlock(old_dir->i_sb); |
| 1331 | return -EIO; |
| 1332 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1334 | copy_item_head(&old_entry_ih, get_ih(&old_entry_path)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1336 | reiserfs_prepare_for_journal(old_inode->i_sb, old_de.de_bh, 1); |
| 1337 | |
| 1338 | // look for new name by reiserfs_find_entry |
| 1339 | new_de.de_gen_number_bit_string = NULL; |
| 1340 | retval = |
| 1341 | reiserfs_find_entry(new_dir, new_dentry->d_name.name, |
| 1342 | new_dentry->d_name.len, &new_entry_path, |
| 1343 | &new_de); |
| 1344 | // reiserfs_add_entry should not return IO_ERROR, because it is called with essentially same parameters from |
| 1345 | // reiserfs_add_entry above, and we'll catch any i/o errors before we get here. |
| 1346 | if (retval != NAME_FOUND_INVISIBLE && retval != NAME_FOUND) { |
| 1347 | pathrelse(&new_entry_path); |
| 1348 | pathrelse(&old_entry_path); |
| 1349 | journal_end(&th, old_dir->i_sb, jbegin_count); |
| 1350 | reiserfs_write_unlock(old_dir->i_sb); |
| 1351 | return -EIO; |
| 1352 | } |
| 1353 | |
| 1354 | copy_item_head(&new_entry_ih, get_ih(&new_entry_path)); |
| 1355 | |
| 1356 | reiserfs_prepare_for_journal(old_inode->i_sb, new_de.de_bh, 1); |
| 1357 | |
| 1358 | if (S_ISDIR(old_inode->i_mode)) { |
| 1359 | if ((retval = |
| 1360 | search_by_entry_key(new_dir->i_sb, |
| 1361 | &dot_dot_de.de_entry_key, |
| 1362 | &dot_dot_entry_path, |
| 1363 | &dot_dot_de)) != NAME_FOUND) { |
| 1364 | pathrelse(&dot_dot_entry_path); |
| 1365 | pathrelse(&new_entry_path); |
| 1366 | pathrelse(&old_entry_path); |
| 1367 | journal_end(&th, old_dir->i_sb, jbegin_count); |
| 1368 | reiserfs_write_unlock(old_dir->i_sb); |
| 1369 | return -EIO; |
| 1370 | } |
| 1371 | copy_item_head(&dot_dot_ih, |
| 1372 | get_ih(&dot_dot_entry_path)); |
| 1373 | // node containing ".." gets into transaction |
| 1374 | reiserfs_prepare_for_journal(old_inode->i_sb, |
| 1375 | dot_dot_de.de_bh, 1); |
| 1376 | } |
| 1377 | /* we should check seals here, not do |
| 1378 | this stuff, yes? Then, having |
| 1379 | gathered everything into RAM we |
| 1380 | should lock the buffers, yes? -Hans */ |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 1381 | /* probably. our rename needs to hold more |
| 1382 | ** than one path at once. The seals would |
| 1383 | ** have to be written to deal with multi-path |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1384 | ** issues -chris |
| 1385 | */ |
| 1386 | /* sanity checking before doing the rename - avoid races many |
| 1387 | ** of the above checks could have scheduled. We have to be |
| 1388 | ** sure our items haven't been shifted by another process. |
| 1389 | */ |
| 1390 | if (item_moved(&new_entry_ih, &new_entry_path) || |
| 1391 | !entry_points_to_object(new_dentry->d_name.name, |
| 1392 | new_dentry->d_name.len, |
| 1393 | &new_de, new_dentry_inode) || |
| 1394 | item_moved(&old_entry_ih, &old_entry_path) || |
| 1395 | !entry_points_to_object(old_dentry->d_name.name, |
| 1396 | old_dentry->d_name.len, |
| 1397 | &old_de, old_inode)) { |
| 1398 | reiserfs_restore_prepared_buffer(old_inode->i_sb, |
| 1399 | new_de.de_bh); |
| 1400 | reiserfs_restore_prepared_buffer(old_inode->i_sb, |
| 1401 | old_de.de_bh); |
| 1402 | if (S_ISDIR(old_inode_mode)) |
| 1403 | reiserfs_restore_prepared_buffer(old_inode-> |
| 1404 | i_sb, |
| 1405 | dot_dot_de. |
| 1406 | de_bh); |
| 1407 | continue; |
| 1408 | } |
| 1409 | if (S_ISDIR(old_inode_mode)) { |
| 1410 | if (item_moved(&dot_dot_ih, &dot_dot_entry_path) || |
| 1411 | !entry_points_to_object("..", 2, &dot_dot_de, |
| 1412 | old_dir)) { |
| 1413 | reiserfs_restore_prepared_buffer(old_inode-> |
| 1414 | i_sb, |
| 1415 | old_de.de_bh); |
| 1416 | reiserfs_restore_prepared_buffer(old_inode-> |
| 1417 | i_sb, |
| 1418 | new_de.de_bh); |
| 1419 | reiserfs_restore_prepared_buffer(old_inode-> |
| 1420 | i_sb, |
| 1421 | dot_dot_de. |
| 1422 | de_bh); |
| 1423 | continue; |
| 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | RFALSE(S_ISDIR(old_inode_mode) && |
| 1428 | !buffer_journal_prepared(dot_dot_de.de_bh), ""); |
| 1429 | |
| 1430 | break; |
| 1431 | } |
| 1432 | |
| 1433 | /* ok, all the changes can be done in one fell swoop when we |
| 1434 | have claimed all the buffers needed. */ |
| 1435 | |
| 1436 | mark_de_visible(new_de.de_deh + new_de.de_entry_num); |
| 1437 | set_ino_in_dir_entry(&new_de, INODE_PKEY(old_inode)); |
| 1438 | journal_mark_dirty(&th, old_dir->i_sb, new_de.de_bh); |
| 1439 | |
| 1440 | mark_de_hidden(old_de.de_deh + old_de.de_entry_num); |
| 1441 | journal_mark_dirty(&th, old_dir->i_sb, old_de.de_bh); |
| 1442 | ctime = CURRENT_TIME_SEC; |
| 1443 | old_dir->i_ctime = old_dir->i_mtime = ctime; |
| 1444 | new_dir->i_ctime = new_dir->i_mtime = ctime; |
| 1445 | /* thanks to Alex Adriaanse <alex_a@caltech.edu> for patch which adds ctime update of |
| 1446 | renamed object */ |
| 1447 | old_inode->i_ctime = ctime; |
| 1448 | |
| 1449 | if (new_dentry_inode) { |
| 1450 | // adjust link number of the victim |
| 1451 | if (S_ISDIR(new_dentry_inode->i_mode)) { |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 1452 | clear_nlink(new_dentry_inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1453 | } else { |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1454 | drop_nlink(new_dentry_inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1455 | } |
| 1456 | new_dentry_inode->i_ctime = ctime; |
| 1457 | savelink = new_dentry_inode->i_nlink; |
| 1458 | } |
| 1459 | |
| 1460 | if (S_ISDIR(old_inode_mode)) { |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 1461 | /* adjust ".." of renamed directory */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1462 | set_ino_in_dir_entry(&dot_dot_de, INODE_PKEY(new_dir)); |
| 1463 | journal_mark_dirty(&th, new_dir->i_sb, dot_dot_de.de_bh); |
| 1464 | |
| 1465 | if (!new_dentry_inode) |
| 1466 | /* there (in new_dir) was no directory, so it got new link |
| 1467 | (".." of renamed directory) */ |
| 1468 | INC_DIR_INODE_NLINK(new_dir); |
| 1469 | |
| 1470 | /* old directory lost one link - ".. " of renamed directory */ |
| 1471 | DEC_DIR_INODE_NLINK(old_dir); |
| 1472 | } |
| 1473 | // looks like in 2.3.99pre3 brelse is atomic. so we can use pathrelse |
| 1474 | pathrelse(&new_entry_path); |
| 1475 | pathrelse(&dot_dot_entry_path); |
| 1476 | |
| 1477 | // FIXME: this reiserfs_cut_from_item's return value may screw up |
| 1478 | // anybody, but it will panic if will not be able to find the |
| 1479 | // entry. This needs one more clean up |
| 1480 | if (reiserfs_cut_from_item |
| 1481 | (&th, &old_entry_path, &(old_de.de_entry_key), old_dir, NULL, |
| 1482 | 0) < 0) |
Jeff Mahoney | 0030b64 | 2009-03-30 14:02:28 -0400 | [diff] [blame] | 1483 | reiserfs_error(old_dir->i_sb, "vs-7060", |
| 1484 | "couldn't not cut old name. Fsck later?"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1485 | |
| 1486 | old_dir->i_size -= DEH_SIZE + old_de.de_entrylen; |
| 1487 | |
| 1488 | reiserfs_update_sd(&th, old_dir); |
| 1489 | reiserfs_update_sd(&th, new_dir); |
| 1490 | reiserfs_update_sd(&th, old_inode); |
| 1491 | |
| 1492 | if (new_dentry_inode) { |
| 1493 | if (savelink == 0) |
| 1494 | add_save_link(&th, new_dentry_inode, |
| 1495 | 0 /* not truncate */ ); |
| 1496 | reiserfs_update_sd(&th, new_dentry_inode); |
| 1497 | } |
| 1498 | |
| 1499 | retval = journal_end(&th, old_dir->i_sb, jbegin_count); |
| 1500 | reiserfs_write_unlock(old_dir->i_sb); |
| 1501 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | /* |
| 1505 | * directories can handle most operations... |
| 1506 | */ |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 1507 | const struct inode_operations reiserfs_dir_inode_operations = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1508 | //&reiserfs_dir_operations, /* default_file_ops */ |
| 1509 | .create = reiserfs_create, |
| 1510 | .lookup = reiserfs_lookup, |
| 1511 | .link = reiserfs_link, |
| 1512 | .unlink = reiserfs_unlink, |
| 1513 | .symlink = reiserfs_symlink, |
| 1514 | .mkdir = reiserfs_mkdir, |
| 1515 | .rmdir = reiserfs_rmdir, |
| 1516 | .mknod = reiserfs_mknod, |
| 1517 | .rename = reiserfs_rename, |
| 1518 | .setattr = reiserfs_setattr, |
| 1519 | .setxattr = reiserfs_setxattr, |
| 1520 | .getxattr = reiserfs_getxattr, |
| 1521 | .listxattr = reiserfs_listxattr, |
| 1522 | .removexattr = reiserfs_removexattr, |
| 1523 | .permission = reiserfs_permission, |
Christoph Hellwig | 4e34e71 | 2011-07-23 17:37:31 +0200 | [diff] [blame] | 1524 | .get_acl = reiserfs_get_acl, |
Christoph Hellwig | 47f70d0 | 2013-12-20 05:16:49 -0800 | [diff] [blame] | 1525 | .set_acl = reiserfs_set_acl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | }; |
| 1527 | |
| 1528 | /* |
| 1529 | * symlink operations.. same as page_symlink_inode_operations, with xattr |
| 1530 | * stuff added |
| 1531 | */ |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 1532 | const struct inode_operations reiserfs_symlink_inode_operations = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1533 | .readlink = generic_readlink, |
| 1534 | .follow_link = page_follow_link_light, |
| 1535 | .put_link = page_put_link, |
| 1536 | .setattr = reiserfs_setattr, |
| 1537 | .setxattr = reiserfs_setxattr, |
| 1538 | .getxattr = reiserfs_getxattr, |
| 1539 | .listxattr = reiserfs_listxattr, |
| 1540 | .removexattr = reiserfs_removexattr, |
| 1541 | .permission = reiserfs_permission, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | }; |
| 1543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | /* |
| 1545 | * special file operations.. just xattr/acl stuff |
| 1546 | */ |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 1547 | const struct inode_operations reiserfs_special_inode_operations = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1548 | .setattr = reiserfs_setattr, |
| 1549 | .setxattr = reiserfs_setxattr, |
| 1550 | .getxattr = reiserfs_getxattr, |
| 1551 | .listxattr = reiserfs_listxattr, |
| 1552 | .removexattr = reiserfs_removexattr, |
| 1553 | .permission = reiserfs_permission, |
Christoph Hellwig | 4e34e71 | 2011-07-23 17:37:31 +0200 | [diff] [blame] | 1554 | .get_acl = reiserfs_get_acl, |
Christoph Hellwig | 47f70d0 | 2013-12-20 05:16:49 -0800 | [diff] [blame] | 1555 | .set_acl = reiserfs_set_acl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | }; |