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