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