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