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 |
Jeff Mahoney | 60e4cf6 | 2019-10-24 10:31:27 -0400 | [diff] [blame] | 380 | * in the priv tree. Also clear IOP_XATTR |
| 381 | * since we don't have xattrs on xattr files. |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 382 | */ |
Jeff Mahoney | 60e4cf6 | 2019-10-24 10:31:27 -0400 | [diff] [blame] | 383 | if (IS_PRIVATE(dir)) { |
Jeff Mahoney | 6dfede69 | 2009-03-30 14:02:32 -0400 | [diff] [blame] | 384 | inode->i_flags |= S_PRIVATE; |
Jeff Mahoney | 60e4cf6 | 2019-10-24 10:31:27 -0400 | [diff] [blame] | 385 | inode->i_opflags &= ~IOP_XATTR; |
| 386 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 387 | } |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 388 | reiserfs_write_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | if (retval == IO_ERROR) { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 390 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Pekka Enberg | d9975d6 | 2006-01-14 13:21:09 -0800 | [diff] [blame] | 393 | return d_splice_alias(inode, dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 396 | /* |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 397 | * looks up the dentry of the parent directory for child. |
| 398 | * taken from ext2_get_parent |
| 399 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | struct dentry *reiserfs_get_parent(struct dentry *child) |
| 401 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 402 | int retval; |
| 403 | struct inode *inode = NULL; |
| 404 | struct reiserfs_dir_entry de; |
| 405 | INITIALIZE_PATH(path_to_entry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 406 | struct inode *dir = d_inode(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 408 | if (dir->i_nlink == 0) { |
| 409 | return ERR_PTR(-ENOENT); |
| 410 | } |
| 411 | de.de_gen_number_bit_string = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 413 | reiserfs_write_lock(dir->i_sb); |
| 414 | retval = reiserfs_find_entry(dir, "..", 2, &path_to_entry, &de); |
| 415 | pathrelse(&path_to_entry); |
| 416 | if (retval != NAME_FOUND) { |
| 417 | reiserfs_write_unlock(dir->i_sb); |
| 418 | return ERR_PTR(-ENOENT); |
| 419 | } |
Jeff Mahoney | a228bf8 | 2014-04-23 10:00:42 -0400 | [diff] [blame] | 420 | 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] | 421 | reiserfs_write_unlock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Christoph Hellwig | 4400372 | 2008-08-11 15:49:04 +0200 | [diff] [blame] | 423 | return d_obtain_alias(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 426 | /* add entry to the directory (entry can be hidden). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
| 428 | insert definition of when hidden directories are used here -Hans |
| 429 | |
| 430 | Does not mark dir inode dirty, do it after successesfull call to it */ |
| 431 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 432 | static int reiserfs_add_entry(struct reiserfs_transaction_handle *th, |
| 433 | struct inode *dir, const char *name, int namelen, |
| 434 | struct inode *inode, int visible) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 436 | struct cpu_key entry_key; |
| 437 | struct reiserfs_de_head *deh; |
| 438 | INITIALIZE_PATH(path); |
| 439 | struct reiserfs_dir_entry de; |
Jeff Mahoney | 3af1efe | 2006-03-02 13:25:26 -0500 | [diff] [blame] | 440 | DECLARE_BITMAP(bit_string, MAX_GENERATION_NUMBER + 1); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 441 | int gen_number; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 442 | |
| 443 | /* |
| 444 | * 48 bytes now and we avoid kmalloc if we |
| 445 | * create file with short name |
| 446 | */ |
| 447 | char small_buf[32 + DEH_SIZE]; |
| 448 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 449 | char *buffer; |
| 450 | int buflen, paste_size; |
| 451 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 453 | BUG_ON(!th->t_trans_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 455 | /* cannot allow items to be added into a busy deleted directory */ |
| 456 | if (!namelen) |
| 457 | return -EINVAL; |
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 | if (namelen > REISERFS_MAX_NAME(dir->i_sb->s_blocksize)) |
| 460 | return -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 462 | /* each entry has unique key. compose it */ |
| 463 | make_cpu_key(&entry_key, dir, |
| 464 | get_third_component(dir->i_sb, name, namelen), |
| 465 | TYPE_DIRENTRY, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 467 | /* get memory for composing the entry */ |
| 468 | buflen = DEH_SIZE + ROUND_UP(namelen); |
| 469 | if (buflen > sizeof(small_buf)) { |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 470 | buffer = kmalloc(buflen, GFP_NOFS); |
Al Viro | 9dce07f | 2008-03-29 03:07:28 +0000 | [diff] [blame] | 471 | if (!buffer) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 472 | return -ENOMEM; |
| 473 | } else |
| 474 | buffer = small_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 476 | paste_size = |
| 477 | (get_inode_sd_version(dir) == |
| 478 | STAT_DATA_V1) ? (DEH_SIZE + namelen) : buflen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 480 | /* |
| 481 | * fill buffer : directory entry head, name[, dir objectid | , |
| 482 | * stat data | ,stat data, dir objectid ] |
| 483 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 484 | deh = (struct reiserfs_de_head *)buffer; |
| 485 | deh->deh_location = 0; /* JDM Endian safe if 0 */ |
| 486 | put_deh_offset(deh, cpu_key_k_offset(&entry_key)); |
| 487 | deh->deh_state = 0; /* JDM Endian safe if 0 */ |
| 488 | /* put key (ino analog) to de */ |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 489 | |
| 490 | /* safe: k_dir_id is le */ |
| 491 | deh->deh_dir_id = INODE_PKEY(inode)->k_dir_id; |
| 492 | /* safe: k_objectid is le */ |
| 493 | deh->deh_objectid = INODE_PKEY(inode)->k_objectid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 495 | /* copy name */ |
| 496 | memcpy((char *)(deh + 1), name, namelen); |
| 497 | /* padd by 0s to the 4 byte boundary */ |
| 498 | padd_item((char *)(deh + 1), ROUND_UP(namelen), namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 500 | /* |
| 501 | * entry is ready to be pasted into tree, set 'visibility' |
| 502 | * and 'stat data in entry' attributes |
| 503 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 504 | mark_de_without_sd(deh); |
| 505 | visible ? mark_de_visible(deh) : mark_de_hidden(deh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 507 | /* find the proper place for the new entry */ |
| 508 | memset(bit_string, 0, sizeof(bit_string)); |
Jeff Mahoney | 3af1efe | 2006-03-02 13:25:26 -0500 | [diff] [blame] | 509 | de.de_gen_number_bit_string = bit_string; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 510 | retval = reiserfs_find_entry(dir, name, namelen, &path, &de); |
| 511 | if (retval != NAME_NOT_FOUND) { |
| 512 | if (buffer != small_buf) |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 513 | kfree(buffer); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 514 | pathrelse(&path); |
| 515 | |
| 516 | if (retval == IO_ERROR) { |
| 517 | return -EIO; |
| 518 | } |
| 519 | |
| 520 | if (retval != NAME_FOUND) { |
Jeff Mahoney | 0030b64 | 2009-03-30 14:02:28 -0400 | [diff] [blame] | 521 | reiserfs_error(dir->i_sb, "zam-7002", |
| 522 | "reiserfs_find_entry() returned " |
| 523 | "unexpected value (%d)", retval); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | return -EEXIST; |
| 527 | } |
| 528 | |
| 529 | gen_number = |
Jeff Mahoney | 3af1efe | 2006-03-02 13:25:26 -0500 | [diff] [blame] | 530 | find_first_zero_bit(bit_string, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 531 | MAX_GENERATION_NUMBER + 1); |
| 532 | if (gen_number > MAX_GENERATION_NUMBER) { |
| 533 | /* there is no free generation number */ |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 534 | reiserfs_warning(dir->i_sb, "reiserfs-7010", |
| 535 | "Congratulations! we have got hash function " |
| 536 | "screwed up"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 537 | if (buffer != small_buf) |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 538 | kfree(buffer); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 539 | pathrelse(&path); |
| 540 | return -EBUSY; |
| 541 | } |
| 542 | /* adjust offset of directory enrty */ |
| 543 | put_deh_offset(deh, SET_GENERATION_NUMBER(deh_offset(deh), gen_number)); |
| 544 | set_cpu_key_k_offset(&entry_key, deh_offset(deh)); |
| 545 | |
| 546 | /* update max-hash-collisions counter in reiserfs_sb_info */ |
| 547 | PROC_INFO_MAX(th->t_super, max_hash_collisions, gen_number); |
| 548 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 549 | /* we need to re-search for the insertion point */ |
| 550 | if (gen_number != 0) { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 551 | if (search_by_entry_key(dir->i_sb, &entry_key, &path, &de) != |
| 552 | NAME_NOT_FOUND) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 553 | reiserfs_warning(dir->i_sb, "vs-7032", |
| 554 | "entry with this key (%K) already " |
| 555 | "exists", &entry_key); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 556 | |
| 557 | if (buffer != small_buf) |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 558 | kfree(buffer); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 559 | pathrelse(&path); |
| 560 | return -EBUSY; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | /* perform the insertion of the entry that we have prepared */ |
| 565 | retval = |
| 566 | reiserfs_paste_into_item(th, &path, &entry_key, dir, buffer, |
| 567 | paste_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | if (buffer != small_buf) |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 569 | kfree(buffer); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 570 | if (retval) { |
| 571 | reiserfs_check_path(&path); |
| 572 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 575 | dir->i_size += paste_size; |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 576 | dir->i_mtime = dir->i_ctime = current_time(dir); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 577 | if (!S_ISDIR(inode->i_mode) && visible) |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 578 | /* reiserfs_mkdir or reiserfs_rename will do that by itself */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 579 | reiserfs_update_sd(th, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 581 | reiserfs_check_path(&path); |
| 582 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 585 | /* |
| 586 | * quota utility function, call if you've had to abort after calling |
| 587 | * new_inode_init, and have not called reiserfs_new_inode yet. |
| 588 | * This should only be called on inodes that do not have stat data |
| 589 | * inserted into the tree yet. |
| 590 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 591 | static int drop_new_inode(struct inode *inode) |
| 592 | { |
Christoph Hellwig | 9f75475 | 2010-03-03 09:05:05 -0500 | [diff] [blame] | 593 | dquot_drop(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 594 | make_bad_inode(inode); |
| 595 | inode->i_flags |= S_NOQUOTA; |
| 596 | iput(inode); |
| 597 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 600 | /* |
| 601 | * utility function that does setup for reiserfs_new_inode. |
| 602 | * dquot_initialize needs lots of credits so it's better to have it |
| 603 | * outside of a transaction, so we had to pull some bits of |
| 604 | * reiserfs_new_inode out into this func. |
| 605 | */ |
Al Viro | 8e07189 | 2011-07-26 02:50:53 -0400 | [diff] [blame] | 606 | 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] | 607 | { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 608 | /* |
| 609 | * Make inode invalid - just in case we are going to drop it before |
| 610 | * the initialization happens |
| 611 | */ |
Jan Kara | 1b0a74d | 2005-08-13 13:15:34 +0200 | [diff] [blame] | 612 | INODE_PKEY(inode)->k_objectid = 0; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 613 | |
| 614 | /* |
| 615 | * the quota init calls have to know who to charge the quota to, so |
| 616 | * we have to set uid and gid here |
Dmitry Monakhov | 04b7ed0 | 2010-03-04 17:32:19 +0300 | [diff] [blame] | 617 | */ |
Christian Brauner | 21cb47b | 2021-01-21 14:19:25 +0100 | [diff] [blame] | 618 | inode_init_owner(&init_user_ns, inode, dir, mode); |
Jan Kara | 2e6c97e | 2015-07-14 13:51:55 +0200 | [diff] [blame] | 619 | return dquot_initialize(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame] | 622 | static int reiserfs_create(struct user_namespace *mnt_userns, struct inode *dir, |
| 623 | struct dentry *dentry, umode_t mode, bool excl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 625 | int retval; |
| 626 | struct inode *inode; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 627 | /* |
| 628 | * We need blocks for transaction + (user+group)*(quotas |
| 629 | * for new inode + update of quota for directory owner) |
| 630 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 631 | int jbegin_count = |
| 632 | JOURNAL_PER_BALANCE_CNT * 2 + |
| 633 | 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) + |
| 634 | REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb)); |
| 635 | struct reiserfs_transaction_handle th; |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 636 | struct reiserfs_security_handle security; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
Jan Kara | 2e6c97e | 2015-07-14 13:51:55 +0200 | [diff] [blame] | 638 | retval = dquot_initialize(dir); |
| 639 | if (retval) |
| 640 | return retval; |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 641 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 642 | if (!(inode = new_inode(dir->i_sb))) { |
| 643 | return -ENOMEM; |
| 644 | } |
Jan Kara | 2e6c97e | 2015-07-14 13:51:55 +0200 | [diff] [blame] | 645 | retval = new_inode_init(inode, dir, mode); |
| 646 | if (retval) { |
| 647 | drop_new_inode(inode); |
| 648 | return retval; |
| 649 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Jeff Mahoney | 0ab2621 | 2009-03-30 14:02:39 -0400 | [diff] [blame] | 651 | jbegin_count += reiserfs_cache_default_acl(dir); |
Eric Paris | 2a7dba3 | 2011-02-01 11:05:39 -0500 | [diff] [blame] | 652 | retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security); |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 653 | if (retval < 0) { |
| 654 | drop_new_inode(inode); |
| 655 | return retval; |
| 656 | } |
| 657 | jbegin_count += retval; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 658 | reiserfs_write_lock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 660 | retval = journal_begin(&th, dir->i_sb, jbegin_count); |
| 661 | if (retval) { |
| 662 | drop_new_inode(inode); |
| 663 | goto out_failed; |
| 664 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 666 | retval = |
| 667 | reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry, |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 668 | inode, &security); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 669 | if (retval) |
| 670 | goto out_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 672 | inode->i_op = &reiserfs_file_inode_operations; |
| 673 | inode->i_fop = &reiserfs_file_operations; |
| 674 | inode->i_mapping->a_ops = &reiserfs_address_space_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 676 | retval = |
| 677 | reiserfs_add_entry(&th, dir, dentry->d_name.name, |
| 678 | dentry->d_name.len, inode, 1 /*visible */ ); |
| 679 | if (retval) { |
| 680 | int err; |
Miklos Szeredi | 6d6b77f | 2011-10-28 14:13:28 +0200 | [diff] [blame] | 681 | drop_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 682 | reiserfs_update_sd(&th, inode); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 683 | err = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 684 | if (err) |
| 685 | retval = err; |
Al Viro | c1eaa26 | 2008-12-30 02:03:58 -0500 | [diff] [blame] | 686 | unlock_new_inode(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 687 | iput(inode); |
| 688 | goto out_failed; |
| 689 | } |
| 690 | reiserfs_update_inode_transaction(inode); |
| 691 | reiserfs_update_inode_transaction(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
Al Viro | 1e2e547 | 2018-05-04 08:23:01 -0400 | [diff] [blame] | 693 | d_instantiate_new(dentry, inode); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 694 | retval = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 695 | |
Jeff Mahoney | cf776a7 | 2014-04-23 10:00:41 -0400 | [diff] [blame] | 696 | out_failed: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 697 | reiserfs_write_unlock(dir->i_sb); |
| 698 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | } |
| 700 | |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame] | 701 | static int reiserfs_mknod(struct user_namespace *mnt_userns, struct inode *dir, |
| 702 | struct dentry *dentry, umode_t mode, dev_t rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 704 | int retval; |
| 705 | struct inode *inode; |
| 706 | struct reiserfs_transaction_handle th; |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 707 | struct reiserfs_security_handle security; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 708 | /* |
| 709 | * We need blocks for transaction + (user+group)*(quotas |
| 710 | * for new inode + update of quota for directory owner) |
| 711 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 712 | int jbegin_count = |
| 713 | JOURNAL_PER_BALANCE_CNT * 3 + |
| 714 | 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) + |
| 715 | REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Jan Kara | 2e6c97e | 2015-07-14 13:51:55 +0200 | [diff] [blame] | 717 | retval = dquot_initialize(dir); |
| 718 | if (retval) |
| 719 | return retval; |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 720 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 721 | if (!(inode = new_inode(dir->i_sb))) { |
| 722 | return -ENOMEM; |
| 723 | } |
Jan Kara | 2e6c97e | 2015-07-14 13:51:55 +0200 | [diff] [blame] | 724 | retval = new_inode_init(inode, dir, mode); |
| 725 | if (retval) { |
| 726 | drop_new_inode(inode); |
| 727 | return retval; |
| 728 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | |
Jeff Mahoney | 0ab2621 | 2009-03-30 14:02:39 -0400 | [diff] [blame] | 730 | jbegin_count += reiserfs_cache_default_acl(dir); |
Eric Paris | 2a7dba3 | 2011-02-01 11:05:39 -0500 | [diff] [blame] | 731 | retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security); |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 732 | if (retval < 0) { |
| 733 | drop_new_inode(inode); |
| 734 | return retval; |
| 735 | } |
| 736 | jbegin_count += retval; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 737 | reiserfs_write_lock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 739 | retval = journal_begin(&th, dir->i_sb, jbegin_count); |
| 740 | if (retval) { |
| 741 | drop_new_inode(inode); |
| 742 | goto out_failed; |
| 743 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 745 | retval = |
| 746 | reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry, |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 747 | inode, &security); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 748 | if (retval) { |
| 749 | goto out_failed; |
| 750 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 752 | inode->i_op = &reiserfs_special_inode_operations; |
| 753 | init_special_inode(inode, inode->i_mode, rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 755 | /* FIXME: needed for block and char devices only */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 756 | reiserfs_update_sd(&th, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 758 | reiserfs_update_inode_transaction(inode); |
| 759 | reiserfs_update_inode_transaction(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 761 | retval = |
| 762 | reiserfs_add_entry(&th, dir, dentry->d_name.name, |
| 763 | dentry->d_name.len, inode, 1 /*visible */ ); |
| 764 | if (retval) { |
| 765 | int err; |
Miklos Szeredi | 6d6b77f | 2011-10-28 14:13:28 +0200 | [diff] [blame] | 766 | drop_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 767 | reiserfs_update_sd(&th, inode); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 768 | err = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 769 | if (err) |
| 770 | retval = err; |
Al Viro | c1eaa26 | 2008-12-30 02:03:58 -0500 | [diff] [blame] | 771 | unlock_new_inode(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 772 | iput(inode); |
| 773 | goto out_failed; |
| 774 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
Al Viro | 1e2e547 | 2018-05-04 08:23:01 -0400 | [diff] [blame] | 776 | d_instantiate_new(dentry, inode); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 777 | retval = journal_end(&th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
Jeff Mahoney | cf776a7 | 2014-04-23 10:00:41 -0400 | [diff] [blame] | 779 | out_failed: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 780 | reiserfs_write_unlock(dir->i_sb); |
| 781 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame] | 784 | static int reiserfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, |
| 785 | struct dentry *dentry, umode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 787 | int retval; |
| 788 | struct inode *inode; |
| 789 | struct reiserfs_transaction_handle th; |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 790 | struct reiserfs_security_handle security; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 791 | /* |
| 792 | * We need blocks for transaction + (user+group)*(quotas |
| 793 | * for new inode + update of quota for directory owner) |
| 794 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 795 | int jbegin_count = |
| 796 | JOURNAL_PER_BALANCE_CNT * 3 + |
| 797 | 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) + |
| 798 | REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | |
Jan Kara | 2e6c97e | 2015-07-14 13:51:55 +0200 | [diff] [blame] | 800 | retval = dquot_initialize(dir); |
| 801 | if (retval) |
| 802 | return retval; |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 803 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | #ifdef DISPLACE_NEW_PACKING_LOCALITIES |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 805 | /* |
| 806 | * set flag that new packing locality created and new blocks |
| 807 | * for the content of that directory are not displaced yet |
| 808 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 809 | REISERFS_I(dir)->new_packing_locality = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | #endif |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 811 | mode = S_IFDIR | mode; |
| 812 | if (!(inode = new_inode(dir->i_sb))) { |
| 813 | return -ENOMEM; |
| 814 | } |
Jan Kara | 2e6c97e | 2015-07-14 13:51:55 +0200 | [diff] [blame] | 815 | retval = new_inode_init(inode, dir, mode); |
| 816 | if (retval) { |
| 817 | drop_new_inode(inode); |
| 818 | return retval; |
| 819 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
Jeff Mahoney | 0ab2621 | 2009-03-30 14:02:39 -0400 | [diff] [blame] | 821 | jbegin_count += reiserfs_cache_default_acl(dir); |
Eric Paris | 2a7dba3 | 2011-02-01 11:05:39 -0500 | [diff] [blame] | 822 | retval = reiserfs_security_init(dir, inode, &dentry->d_name, &security); |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 823 | if (retval < 0) { |
| 824 | drop_new_inode(inode); |
| 825 | return retval; |
| 826 | } |
| 827 | jbegin_count += retval; |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 828 | reiserfs_write_lock(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 830 | retval = journal_begin(&th, dir->i_sb, jbegin_count); |
| 831 | if (retval) { |
| 832 | drop_new_inode(inode); |
| 833 | goto out_failed; |
| 834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 836 | /* |
| 837 | * inc the link count now, so another writer doesn't overflow |
| 838 | * it while we sleep later on. |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 839 | */ |
| 840 | INC_DIR_INODE_NLINK(dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
Colin Ian King | 5404e7e | 2020-04-06 20:11:46 -0700 | [diff] [blame] | 842 | retval = reiserfs_new_inode(&th, dir, mode, NULL /*symlink */, |
| 843 | old_format_only(dir->i_sb) ? |
| 844 | EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE, |
| 845 | dentry, inode, &security); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 846 | if (retval) { |
Al Viro | 99890a3 | 2011-03-02 09:35:13 -0500 | [diff] [blame] | 847 | DEC_DIR_INODE_NLINK(dir) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 848 | goto out_failed; |
| 849 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 851 | reiserfs_update_inode_transaction(inode); |
| 852 | reiserfs_update_inode_transaction(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 854 | inode->i_op = &reiserfs_dir_inode_operations; |
| 855 | inode->i_fop = &reiserfs_dir_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 857 | /* note, _this_ add_entry will not update dir's stat data */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 858 | retval = |
| 859 | reiserfs_add_entry(&th, dir, dentry->d_name.name, |
| 860 | dentry->d_name.len, inode, 1 /*visible */ ); |
| 861 | if (retval) { |
| 862 | int err; |
Miklos Szeredi | 6d6b77f | 2011-10-28 14:13:28 +0200 | [diff] [blame] | 863 | clear_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 864 | DEC_DIR_INODE_NLINK(dir); |
| 865 | reiserfs_update_sd(&th, inode); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 866 | err = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 867 | if (err) |
| 868 | retval = err; |
Al Viro | c1eaa26 | 2008-12-30 02:03:58 -0500 | [diff] [blame] | 869 | unlock_new_inode(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 870 | iput(inode); |
| 871 | goto out_failed; |
| 872 | } |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 873 | /* the above add_entry did not update dir's stat data */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 874 | reiserfs_update_sd(&th, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Al Viro | 1e2e547 | 2018-05-04 08:23:01 -0400 | [diff] [blame] | 876 | d_instantiate_new(dentry, inode); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 877 | retval = journal_end(&th); |
Frederic Weisbecker | b10ab4c | 2009-08-25 02:44:21 +0200 | [diff] [blame] | 878 | out_failed: |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 879 | reiserfs_write_unlock(dir->i_sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 880 | return retval; |
| 881 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 883 | static inline int reiserfs_empty_dir(struct inode *inode) |
| 884 | { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 885 | /* |
| 886 | * we can cheat because an old format dir cannot have |
| 887 | * EMPTY_DIR_SIZE, and a new format dir cannot have |
| 888 | * EMPTY_DIR_SIZE_V1. So, if the inode is either size, |
| 889 | * regardless of disk format version, the directory is empty. |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 890 | */ |
| 891 | if (inode->i_size != EMPTY_DIR_SIZE && |
| 892 | inode->i_size != EMPTY_DIR_SIZE_V1) { |
| 893 | return 0; |
| 894 | } |
| 895 | return 1; |
| 896 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 898 | static int reiserfs_rmdir(struct inode *dir, struct dentry *dentry) |
| 899 | { |
| 900 | int retval, err; |
| 901 | struct inode *inode; |
| 902 | struct reiserfs_transaction_handle th; |
| 903 | int jbegin_count; |
| 904 | INITIALIZE_PATH(path); |
| 905 | struct reiserfs_dir_entry de; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 907 | /* |
| 908 | * we will be doing 2 balancings and update 2 stat data, we |
| 909 | * change quotas of the owner of the directory and of the owner |
| 910 | * of the parent directory. The quota structure is possibly |
| 911 | * deleted only on last iput => outside of this transaction |
| 912 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 913 | jbegin_count = |
| 914 | JOURNAL_PER_BALANCE_CNT * 2 + 2 + |
| 915 | 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
Jan Kara | 2e6c97e | 2015-07-14 13:51:55 +0200 | [diff] [blame] | 917 | retval = dquot_initialize(dir); |
| 918 | if (retval) |
| 919 | return retval; |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 920 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 921 | reiserfs_write_lock(dir->i_sb); |
| 922 | retval = journal_begin(&th, dir->i_sb, jbegin_count); |
| 923 | if (retval) |
| 924 | goto out_rmdir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 926 | de.de_gen_number_bit_string = NULL; |
| 927 | if ((retval = |
| 928 | reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, |
| 929 | &path, &de)) == NAME_NOT_FOUND) { |
| 930 | retval = -ENOENT; |
| 931 | goto end_rmdir; |
| 932 | } else if (retval == IO_ERROR) { |
| 933 | retval = -EIO; |
| 934 | goto end_rmdir; |
| 935 | } |
| 936 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 937 | inode = d_inode(dentry); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 938 | |
| 939 | reiserfs_update_inode_transaction(inode); |
| 940 | reiserfs_update_inode_transaction(dir); |
| 941 | |
| 942 | if (de.de_objectid != inode->i_ino) { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 943 | /* |
| 944 | * FIXME: compare key of an object and a key found in the entry |
| 945 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 946 | retval = -EIO; |
| 947 | goto end_rmdir; |
| 948 | } |
| 949 | if (!reiserfs_empty_dir(inode)) { |
| 950 | retval = -ENOTEMPTY; |
| 951 | goto end_rmdir; |
| 952 | } |
| 953 | |
| 954 | /* cut entry from dir directory */ |
Jeff Mahoney | a228bf8 | 2014-04-23 10:00:42 -0400 | [diff] [blame] | 955 | retval = reiserfs_cut_from_item(&th, &path, &de.de_entry_key, |
| 956 | dir, NULL, /* page */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 957 | 0 /*new file size - not used here */ ); |
| 958 | if (retval < 0) |
| 959 | goto end_rmdir; |
| 960 | |
| 961 | if (inode->i_nlink != 2 && inode->i_nlink != 1) |
Jeff Mahoney | 0030b64 | 2009-03-30 14:02:28 -0400 | [diff] [blame] | 962 | reiserfs_error(inode->i_sb, "reiserfs-7040", |
| 963 | "empty directory has nlink != 2 (%d)", |
| 964 | inode->i_nlink); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 965 | |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 966 | clear_nlink(inode); |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 967 | inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(dir); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 968 | reiserfs_update_sd(&th, inode); |
| 969 | |
| 970 | DEC_DIR_INODE_NLINK(dir) |
Colin Ian King | 5404e7e | 2020-04-06 20:11:46 -0700 | [diff] [blame] | 971 | dir->i_size -= (DEH_SIZE + de.de_entrylen); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 972 | reiserfs_update_sd(&th, dir); |
| 973 | |
| 974 | /* prevent empty directory from getting lost */ |
| 975 | add_save_link(&th, inode, 0 /* not truncate */ ); |
| 976 | |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 977 | retval = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 978 | reiserfs_check_path(&path); |
Jeff Mahoney | cf776a7 | 2014-04-23 10:00:41 -0400 | [diff] [blame] | 979 | out_rmdir: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 980 | reiserfs_write_unlock(dir->i_sb); |
| 981 | return retval; |
| 982 | |
Jeff Mahoney | cf776a7 | 2014-04-23 10:00:41 -0400 | [diff] [blame] | 983 | end_rmdir: |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 984 | /* |
| 985 | * we must release path, because we did not call |
| 986 | * reiserfs_cut_from_item, or reiserfs_cut_from_item does not |
| 987 | * release path if operation was not complete |
| 988 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 989 | pathrelse(&path); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 990 | err = journal_end(&th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | reiserfs_write_unlock(dir->i_sb); |
| 992 | return err ? err : retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 995 | static int reiserfs_unlink(struct inode *dir, struct dentry *dentry) |
| 996 | { |
| 997 | int retval, err; |
| 998 | struct inode *inode; |
| 999 | struct reiserfs_dir_entry de; |
| 1000 | INITIALIZE_PATH(path); |
| 1001 | struct reiserfs_transaction_handle th; |
| 1002 | int jbegin_count; |
| 1003 | unsigned long savelink; |
| 1004 | |
Jan Kara | 2e6c97e | 2015-07-14 13:51:55 +0200 | [diff] [blame] | 1005 | retval = dquot_initialize(dir); |
| 1006 | if (retval) |
| 1007 | return retval; |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 1008 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1009 | inode = d_inode(dentry); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1010 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1011 | /* |
| 1012 | * in this transaction we can be doing at max two balancings and |
| 1013 | * update two stat datas, we change quotas of the owner of the |
| 1014 | * directory and of the owner of the parent directory. The quota |
| 1015 | * structure is possibly deleted only on iput => outside of |
| 1016 | * this transaction |
| 1017 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1018 | jbegin_count = |
| 1019 | JOURNAL_PER_BALANCE_CNT * 2 + 2 + |
| 1020 | 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb); |
| 1021 | |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 1022 | reiserfs_write_lock(dir->i_sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1023 | retval = journal_begin(&th, dir->i_sb, jbegin_count); |
| 1024 | if (retval) |
| 1025 | goto out_unlink; |
| 1026 | |
| 1027 | de.de_gen_number_bit_string = NULL; |
| 1028 | if ((retval = |
| 1029 | reiserfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, |
| 1030 | &path, &de)) == NAME_NOT_FOUND) { |
| 1031 | retval = -ENOENT; |
| 1032 | goto end_unlink; |
| 1033 | } else if (retval == IO_ERROR) { |
| 1034 | retval = -EIO; |
| 1035 | goto end_unlink; |
| 1036 | } |
| 1037 | |
| 1038 | reiserfs_update_inode_transaction(inode); |
| 1039 | reiserfs_update_inode_transaction(dir); |
| 1040 | |
| 1041 | if (de.de_objectid != inode->i_ino) { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1042 | /* |
| 1043 | * FIXME: compare key of an object and a key found in the entry |
| 1044 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1045 | retval = -EIO; |
| 1046 | goto end_unlink; |
| 1047 | } |
| 1048 | |
| 1049 | if (!inode->i_nlink) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1050 | reiserfs_warning(inode->i_sb, "reiserfs-7042", |
| 1051 | "deleting nonexistent file (%lu), %d", |
| 1052 | inode->i_ino, inode->i_nlink); |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 1053 | set_nlink(inode, 1); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1056 | drop_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1057 | |
| 1058 | /* |
| 1059 | * we schedule before doing the add_save_link call, save the link |
| 1060 | * count so we don't race |
| 1061 | */ |
| 1062 | savelink = inode->i_nlink; |
| 1063 | |
| 1064 | retval = |
Jeff Mahoney | a228bf8 | 2014-04-23 10:00:42 -0400 | [diff] [blame] | 1065 | reiserfs_cut_from_item(&th, &path, &de.de_entry_key, dir, NULL, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1066 | 0); |
| 1067 | if (retval < 0) { |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 1068 | inc_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1069 | goto end_unlink; |
| 1070 | } |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 1071 | inode->i_ctime = current_time(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1072 | reiserfs_update_sd(&th, inode); |
| 1073 | |
| 1074 | dir->i_size -= (de.de_entrylen + DEH_SIZE); |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 1075 | dir->i_ctime = dir->i_mtime = current_time(dir); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1076 | reiserfs_update_sd(&th, dir); |
| 1077 | |
| 1078 | if (!savelink) |
| 1079 | /* prevent file from getting lost */ |
| 1080 | add_save_link(&th, inode, 0 /* not truncate */ ); |
| 1081 | |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 1082 | retval = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1083 | reiserfs_check_path(&path); |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 1084 | reiserfs_write_unlock(dir->i_sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1085 | return retval; |
| 1086 | |
Jeff Mahoney | cf776a7 | 2014-04-23 10:00:41 -0400 | [diff] [blame] | 1087 | end_unlink: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1088 | pathrelse(&path); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 1089 | err = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1090 | reiserfs_check_path(&path); |
| 1091 | if (err) |
| 1092 | retval = err; |
Jeff Mahoney | cf776a7 | 2014-04-23 10:00:41 -0400 | [diff] [blame] | 1093 | out_unlink: |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 1094 | reiserfs_write_unlock(dir->i_sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1095 | return retval; |
| 1096 | } |
| 1097 | |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame] | 1098 | static int reiserfs_symlink(struct user_namespace *mnt_userns, |
| 1099 | struct inode *parent_dir, struct dentry *dentry, |
| 1100 | const char *symname) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1101 | { |
| 1102 | int retval; |
| 1103 | struct inode *inode; |
| 1104 | char *name; |
| 1105 | int item_len; |
| 1106 | struct reiserfs_transaction_handle th; |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 1107 | struct reiserfs_security_handle security; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1108 | int mode = S_IFLNK | S_IRWXUGO; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1109 | /* |
| 1110 | * We need blocks for transaction + (user+group)*(quotas for |
| 1111 | * new inode + update of quota for directory owner) |
| 1112 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1113 | int jbegin_count = |
| 1114 | JOURNAL_PER_BALANCE_CNT * 3 + |
| 1115 | 2 * (REISERFS_QUOTA_INIT_BLOCKS(parent_dir->i_sb) + |
| 1116 | REISERFS_QUOTA_TRANS_BLOCKS(parent_dir->i_sb)); |
| 1117 | |
Jan Kara | 2e6c97e | 2015-07-14 13:51:55 +0200 | [diff] [blame] | 1118 | retval = dquot_initialize(parent_dir); |
| 1119 | if (retval) |
| 1120 | return retval; |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 1121 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1122 | if (!(inode = new_inode(parent_dir->i_sb))) { |
| 1123 | return -ENOMEM; |
| 1124 | } |
Jan Kara | 2e6c97e | 2015-07-14 13:51:55 +0200 | [diff] [blame] | 1125 | retval = new_inode_init(inode, parent_dir, mode); |
| 1126 | if (retval) { |
| 1127 | drop_new_inode(inode); |
| 1128 | return retval; |
| 1129 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1130 | |
Eric Paris | 2a7dba3 | 2011-02-01 11:05:39 -0500 | [diff] [blame] | 1131 | retval = reiserfs_security_init(parent_dir, inode, &dentry->d_name, |
| 1132 | &security); |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 1133 | if (retval < 0) { |
| 1134 | drop_new_inode(inode); |
| 1135 | return retval; |
| 1136 | } |
| 1137 | jbegin_count += retval; |
| 1138 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1139 | reiserfs_write_lock(parent_dir->i_sb); |
| 1140 | item_len = ROUND_UP(strlen(symname)); |
| 1141 | if (item_len > MAX_DIRECT_ITEM_LEN(parent_dir->i_sb->s_blocksize)) { |
| 1142 | retval = -ENAMETOOLONG; |
| 1143 | drop_new_inode(inode); |
| 1144 | goto out_failed; |
| 1145 | } |
| 1146 | |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 1147 | name = kmalloc(item_len, GFP_NOFS); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1148 | if (!name) { |
| 1149 | drop_new_inode(inode); |
| 1150 | retval = -ENOMEM; |
| 1151 | goto out_failed; |
| 1152 | } |
| 1153 | memcpy(name, symname, strlen(symname)); |
| 1154 | padd_item(name, item_len, strlen(symname)); |
| 1155 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1156 | retval = journal_begin(&th, parent_dir->i_sb, jbegin_count); |
| 1157 | if (retval) { |
| 1158 | drop_new_inode(inode); |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 1159 | kfree(name); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1160 | goto out_failed; |
| 1161 | } |
| 1162 | |
| 1163 | retval = |
| 1164 | reiserfs_new_inode(&th, parent_dir, mode, name, strlen(symname), |
Jeff Mahoney | 57fe60d | 2009-03-30 14:02:41 -0400 | [diff] [blame] | 1165 | dentry, inode, &security); |
Pekka Enberg | d739b42 | 2006-02-01 03:06:43 -0800 | [diff] [blame] | 1166 | kfree(name); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1167 | if (retval) { /* reiserfs_new_inode iputs for us */ |
| 1168 | goto out_failed; |
| 1169 | } |
| 1170 | |
| 1171 | reiserfs_update_inode_transaction(inode); |
| 1172 | reiserfs_update_inode_transaction(parent_dir); |
| 1173 | |
| 1174 | inode->i_op = &reiserfs_symlink_inode_operations; |
Al Viro | 21fc61c | 2015-11-17 01:07:57 -0500 | [diff] [blame] | 1175 | inode_nohighmem(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 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 | 1e2e547 | 2018-05-04 08:23:01 -0400 | [diff] [blame] | 1192 | d_instantiate_new(dentry, inode); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 1193 | retval = journal_end(&th); |
Jeff Mahoney | cf776a7 | 2014-04-23 10:00:41 -0400 | [diff] [blame] | 1194 | out_failed: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1195 | reiserfs_write_unlock(parent_dir->i_sb); |
| 1196 | return retval; |
| 1197 | } |
| 1198 | |
| 1199 | static int reiserfs_link(struct dentry *old_dentry, struct inode *dir, |
| 1200 | struct dentry *dentry) |
| 1201 | { |
| 1202 | int retval; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1203 | struct inode *inode = d_inode(old_dentry); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1204 | struct reiserfs_transaction_handle th; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1205 | /* |
| 1206 | * We need blocks for transaction + update of quotas for |
| 1207 | * the owners of the directory |
| 1208 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1209 | int jbegin_count = |
| 1210 | JOURNAL_PER_BALANCE_CNT * 3 + |
| 1211 | 2 * REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb); |
| 1212 | |
Jan Kara | 2e6c97e | 2015-07-14 13:51:55 +0200 | [diff] [blame] | 1213 | retval = dquot_initialize(dir); |
| 1214 | if (retval) |
| 1215 | return retval; |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 1216 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1217 | reiserfs_write_lock(dir->i_sb); |
| 1218 | if (inode->i_nlink >= REISERFS_LINK_MAX) { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1219 | /* FIXME: sd_nlink is 32 bit for new files */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1220 | reiserfs_write_unlock(dir->i_sb); |
| 1221 | return -EMLINK; |
| 1222 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1223 | |
| 1224 | /* inc before scheduling so reiserfs_unlink knows we are here */ |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 1225 | inc_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1226 | |
| 1227 | retval = journal_begin(&th, dir->i_sb, jbegin_count); |
| 1228 | if (retval) { |
Miklos Szeredi | 6d6b77f | 2011-10-28 14:13:28 +0200 | [diff] [blame] | 1229 | drop_nlink(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1230 | reiserfs_write_unlock(dir->i_sb); |
| 1231 | return retval; |
| 1232 | } |
| 1233 | |
| 1234 | /* create new entry */ |
| 1235 | retval = |
| 1236 | reiserfs_add_entry(&th, dir, dentry->d_name.name, |
| 1237 | dentry->d_name.len, inode, 1 /*visible */ ); |
| 1238 | |
| 1239 | reiserfs_update_inode_transaction(inode); |
| 1240 | reiserfs_update_inode_transaction(dir); |
| 1241 | |
| 1242 | if (retval) { |
| 1243 | int err; |
Miklos Szeredi | 6d6b77f | 2011-10-28 14:13:28 +0200 | [diff] [blame] | 1244 | drop_nlink(inode); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 1245 | err = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1246 | reiserfs_write_unlock(dir->i_sb); |
| 1247 | return err ? err : retval; |
| 1248 | } |
| 1249 | |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 1250 | inode->i_ctime = current_time(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1251 | reiserfs_update_sd(&th, inode); |
| 1252 | |
Al Viro | 7de9c6ee | 2010-10-23 11:11:40 -0400 | [diff] [blame] | 1253 | ihold(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1254 | d_instantiate(dentry, inode); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 1255 | retval = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1256 | reiserfs_write_unlock(dir->i_sb); |
| 1257 | return retval; |
| 1258 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 1260 | /* de contains information pointing to an entry which */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1261 | static int de_still_valid(const char *name, int len, |
| 1262 | struct reiserfs_dir_entry *de) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1264 | struct reiserfs_dir_entry tmp = *de; |
| 1265 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1266 | /* recalculate pointer to name and name length */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1267 | set_de_name_and_namelen(&tmp); |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1268 | /* FIXME: could check more */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1269 | if (tmp.de_namelen != len || memcmp(name, de->de_name, len)) |
| 1270 | return 0; |
| 1271 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1274 | static int entry_points_to_object(const char *name, int len, |
| 1275 | struct reiserfs_dir_entry *de, |
| 1276 | struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1278 | if (!de_still_valid(name, len, de)) |
| 1279 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1281 | if (inode) { |
| 1282 | if (!de_visible(de->de_deh + de->de_entry_num)) |
Jeff Mahoney | c3a9c21 | 2009-03-30 14:02:25 -0400 | [diff] [blame] | 1283 | reiserfs_panic(inode->i_sb, "vs-7042", |
| 1284 | "entry must be visible"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1285 | return (de->de_objectid == inode->i_ino) ? 1 : 0; |
| 1286 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1288 | /* this must be added hidden entry */ |
| 1289 | if (de_visible(de->de_deh + de->de_entry_num)) |
Jeff Mahoney | c3a9c21 | 2009-03-30 14:02:25 -0400 | [diff] [blame] | 1290 | reiserfs_panic(NULL, "vs-7043", "entry must be visible"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1292 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | /* sets key of objectid the entry has to point to */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1296 | static void set_ino_in_dir_entry(struct reiserfs_dir_entry *de, |
| 1297 | struct reiserfs_key *key) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1299 | /* JDM These operations are endian safe - both are le */ |
| 1300 | de->de_deh[de->de_entry_num].deh_dir_id = key->k_dir_id; |
| 1301 | de->de_deh[de->de_entry_num].deh_objectid = key->k_objectid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 1304 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | * process, that is going to call fix_nodes/do_balance must hold only |
| 1306 | * 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] | 1307 | * get_empty_nodes or its clones |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | */ |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame] | 1309 | static int reiserfs_rename(struct user_namespace *mnt_userns, |
| 1310 | struct inode *old_dir, struct dentry *old_dentry, |
Miklos Szeredi | f03b8ad | 2016-09-27 11:03:57 +0200 | [diff] [blame] | 1311 | struct inode *new_dir, struct dentry *new_dentry, |
| 1312 | unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1314 | int retval; |
| 1315 | INITIALIZE_PATH(old_entry_path); |
| 1316 | INITIALIZE_PATH(new_entry_path); |
| 1317 | INITIALIZE_PATH(dot_dot_entry_path); |
| 1318 | struct item_head new_entry_ih, old_entry_ih, dot_dot_ih; |
| 1319 | struct reiserfs_dir_entry old_de, new_de, dot_dot_de; |
| 1320 | struct inode *old_inode, *new_dentry_inode; |
| 1321 | struct reiserfs_transaction_handle th; |
| 1322 | int jbegin_count; |
| 1323 | umode_t old_inode_mode; |
| 1324 | unsigned long savelink = 1; |
Deepa Dinamani | 95582b0 | 2018-05-08 19:36:02 -0700 | [diff] [blame] | 1325 | struct timespec64 ctime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | |
Miklos Szeredi | f03b8ad | 2016-09-27 11:03:57 +0200 | [diff] [blame] | 1327 | if (flags & ~RENAME_NOREPLACE) |
| 1328 | return -EINVAL; |
| 1329 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1330 | /* |
| 1331 | * three balancings: (1) old name removal, (2) new name insertion |
| 1332 | * and (3) maybe "save" link insertion |
| 1333 | * stat data updates: (1) old directory, |
| 1334 | * (2) new directory and (3) maybe old object stat data (when it is |
| 1335 | * directory) and (4) maybe stat data of object to which new entry |
| 1336 | * pointed initially and (5) maybe block containing ".." of |
| 1337 | * renamed directory |
| 1338 | * quota updates: two parent directories |
| 1339 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1340 | jbegin_count = |
| 1341 | JOURNAL_PER_BALANCE_CNT * 3 + 5 + |
| 1342 | 4 * REISERFS_QUOTA_TRANS_BLOCKS(old_dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | |
Jan Kara | 2e6c97e | 2015-07-14 13:51:55 +0200 | [diff] [blame] | 1344 | retval = dquot_initialize(old_dir); |
| 1345 | if (retval) |
| 1346 | return retval; |
| 1347 | retval = dquot_initialize(new_dir); |
| 1348 | if (retval) |
| 1349 | return retval; |
Christoph Hellwig | 907f455 | 2010-03-03 09:05:06 -0500 | [diff] [blame] | 1350 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 1351 | old_inode = d_inode(old_dentry); |
| 1352 | new_dentry_inode = d_inode(new_dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1354 | /* |
| 1355 | * make sure that oldname still exists and points to an object we |
| 1356 | * are going to rename |
| 1357 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1358 | old_de.de_gen_number_bit_string = NULL; |
| 1359 | reiserfs_write_lock(old_dir->i_sb); |
| 1360 | retval = |
| 1361 | reiserfs_find_entry(old_dir, old_dentry->d_name.name, |
| 1362 | old_dentry->d_name.len, &old_entry_path, |
| 1363 | &old_de); |
| 1364 | pathrelse(&old_entry_path); |
| 1365 | if (retval == IO_ERROR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | reiserfs_write_unlock(old_dir->i_sb); |
| 1367 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1369 | |
| 1370 | if (retval != NAME_FOUND || old_de.de_objectid != old_inode->i_ino) { |
| 1371 | reiserfs_write_unlock(old_dir->i_sb); |
| 1372 | return -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1374 | |
| 1375 | old_inode_mode = old_inode->i_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | if (S_ISDIR(old_inode_mode)) { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1377 | /* |
| 1378 | * make sure that directory being renamed has correct ".." |
| 1379 | * and that its new parent directory has not too many links |
| 1380 | * already |
| 1381 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1382 | if (new_dentry_inode) { |
| 1383 | if (!reiserfs_empty_dir(new_dentry_inode)) { |
| 1384 | reiserfs_write_unlock(old_dir->i_sb); |
| 1385 | return -ENOTEMPTY; |
| 1386 | } |
| 1387 | } |
| 1388 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1389 | /* |
| 1390 | * directory is renamed, its parent directory will be changed, |
| 1391 | * so find ".." entry |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1392 | */ |
| 1393 | dot_dot_de.de_gen_number_bit_string = NULL; |
| 1394 | retval = |
| 1395 | reiserfs_find_entry(old_inode, "..", 2, &dot_dot_entry_path, |
| 1396 | &dot_dot_de); |
| 1397 | pathrelse(&dot_dot_entry_path); |
| 1398 | if (retval != NAME_FOUND) { |
| 1399 | reiserfs_write_unlock(old_dir->i_sb); |
| 1400 | return -EIO; |
| 1401 | } |
| 1402 | |
| 1403 | /* inode number of .. must equal old_dir->i_ino */ |
| 1404 | if (dot_dot_de.de_objectid != old_dir->i_ino) { |
| 1405 | reiserfs_write_unlock(old_dir->i_sb); |
| 1406 | return -EIO; |
| 1407 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1410 | retval = journal_begin(&th, old_dir->i_sb, jbegin_count); |
| 1411 | if (retval) { |
| 1412 | reiserfs_write_unlock(old_dir->i_sb); |
| 1413 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1416 | /* add new entry (or find the existing one) */ |
| 1417 | retval = |
| 1418 | reiserfs_add_entry(&th, new_dir, new_dentry->d_name.name, |
| 1419 | new_dentry->d_name.len, old_inode, 0); |
| 1420 | if (retval == -EEXIST) { |
| 1421 | if (!new_dentry_inode) { |
Jeff Mahoney | c3a9c21 | 2009-03-30 14:02:25 -0400 | [diff] [blame] | 1422 | reiserfs_panic(old_dir->i_sb, "vs-7050", |
| 1423 | "new entry is found, new inode == 0"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1424 | } |
| 1425 | } else if (retval) { |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 1426 | int err = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1427 | reiserfs_write_unlock(old_dir->i_sb); |
| 1428 | return err ? err : retval; |
| 1429 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1431 | reiserfs_update_inode_transaction(old_dir); |
| 1432 | reiserfs_update_inode_transaction(new_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1434 | /* |
| 1435 | * this makes it so an fsync on an open fd for the old name will |
| 1436 | * commit the rename operation |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1437 | */ |
| 1438 | reiserfs_update_inode_transaction(old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1440 | if (new_dentry_inode) |
| 1441 | reiserfs_update_inode_transaction(new_dentry_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1443 | while (1) { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1444 | /* |
| 1445 | * look for old name using corresponding entry key |
| 1446 | * (found by reiserfs_find_entry) |
| 1447 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1448 | if ((retval = |
| 1449 | search_by_entry_key(new_dir->i_sb, &old_de.de_entry_key, |
| 1450 | &old_entry_path, |
| 1451 | &old_de)) != NAME_FOUND) { |
| 1452 | pathrelse(&old_entry_path); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 1453 | journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1454 | reiserfs_write_unlock(old_dir->i_sb); |
| 1455 | return -EIO; |
| 1456 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | |
Jeff Mahoney | 4cf5f7a | 2014-04-23 10:00:35 -0400 | [diff] [blame] | 1458 | copy_item_head(&old_entry_ih, tp_item_head(&old_entry_path)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1460 | reiserfs_prepare_for_journal(old_inode->i_sb, old_de.de_bh, 1); |
| 1461 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1462 | /* look for new name by reiserfs_find_entry */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1463 | new_de.de_gen_number_bit_string = NULL; |
| 1464 | retval = |
| 1465 | reiserfs_find_entry(new_dir, new_dentry->d_name.name, |
| 1466 | new_dentry->d_name.len, &new_entry_path, |
| 1467 | &new_de); |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1468 | /* |
| 1469 | * reiserfs_add_entry should not return IO_ERROR, |
| 1470 | * because it is called with essentially same parameters from |
| 1471 | * reiserfs_add_entry above, and we'll catch any i/o errors |
| 1472 | * before we get here. |
| 1473 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1474 | if (retval != NAME_FOUND_INVISIBLE && retval != NAME_FOUND) { |
| 1475 | pathrelse(&new_entry_path); |
| 1476 | pathrelse(&old_entry_path); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 1477 | journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1478 | reiserfs_write_unlock(old_dir->i_sb); |
| 1479 | return -EIO; |
| 1480 | } |
| 1481 | |
Jeff Mahoney | 4cf5f7a | 2014-04-23 10:00:35 -0400 | [diff] [blame] | 1482 | copy_item_head(&new_entry_ih, tp_item_head(&new_entry_path)); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1483 | |
| 1484 | reiserfs_prepare_for_journal(old_inode->i_sb, new_de.de_bh, 1); |
| 1485 | |
| 1486 | if (S_ISDIR(old_inode->i_mode)) { |
| 1487 | if ((retval = |
| 1488 | search_by_entry_key(new_dir->i_sb, |
| 1489 | &dot_dot_de.de_entry_key, |
| 1490 | &dot_dot_entry_path, |
| 1491 | &dot_dot_de)) != NAME_FOUND) { |
| 1492 | pathrelse(&dot_dot_entry_path); |
| 1493 | pathrelse(&new_entry_path); |
| 1494 | pathrelse(&old_entry_path); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 1495 | journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1496 | reiserfs_write_unlock(old_dir->i_sb); |
| 1497 | return -EIO; |
| 1498 | } |
| 1499 | copy_item_head(&dot_dot_ih, |
Jeff Mahoney | 4cf5f7a | 2014-04-23 10:00:35 -0400 | [diff] [blame] | 1500 | tp_item_head(&dot_dot_entry_path)); |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1501 | /* node containing ".." gets into transaction */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1502 | reiserfs_prepare_for_journal(old_inode->i_sb, |
| 1503 | dot_dot_de.de_bh, 1); |
| 1504 | } |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1505 | /* |
| 1506 | * we should check seals here, not do |
| 1507 | * this stuff, yes? Then, having |
| 1508 | * gathered everything into RAM we |
| 1509 | * should lock the buffers, yes? -Hans |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1510 | */ |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1511 | /* |
| 1512 | * probably. our rename needs to hold more |
| 1513 | * than one path at once. The seals would |
| 1514 | * have to be written to deal with multi-path |
| 1515 | * issues -chris |
| 1516 | */ |
| 1517 | /* |
| 1518 | * sanity checking before doing the rename - avoid races many |
| 1519 | * of the above checks could have scheduled. We have to be |
| 1520 | * sure our items haven't been shifted by another process. |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1521 | */ |
| 1522 | if (item_moved(&new_entry_ih, &new_entry_path) || |
| 1523 | !entry_points_to_object(new_dentry->d_name.name, |
| 1524 | new_dentry->d_name.len, |
| 1525 | &new_de, new_dentry_inode) || |
| 1526 | item_moved(&old_entry_ih, &old_entry_path) || |
| 1527 | !entry_points_to_object(old_dentry->d_name.name, |
| 1528 | old_dentry->d_name.len, |
| 1529 | &old_de, old_inode)) { |
| 1530 | reiserfs_restore_prepared_buffer(old_inode->i_sb, |
| 1531 | new_de.de_bh); |
| 1532 | reiserfs_restore_prepared_buffer(old_inode->i_sb, |
| 1533 | old_de.de_bh); |
| 1534 | if (S_ISDIR(old_inode_mode)) |
| 1535 | reiserfs_restore_prepared_buffer(old_inode-> |
| 1536 | i_sb, |
| 1537 | dot_dot_de. |
| 1538 | de_bh); |
| 1539 | continue; |
| 1540 | } |
| 1541 | if (S_ISDIR(old_inode_mode)) { |
| 1542 | if (item_moved(&dot_dot_ih, &dot_dot_entry_path) || |
| 1543 | !entry_points_to_object("..", 2, &dot_dot_de, |
| 1544 | old_dir)) { |
| 1545 | reiserfs_restore_prepared_buffer(old_inode-> |
| 1546 | i_sb, |
| 1547 | old_de.de_bh); |
| 1548 | reiserfs_restore_prepared_buffer(old_inode-> |
| 1549 | i_sb, |
| 1550 | new_de.de_bh); |
| 1551 | reiserfs_restore_prepared_buffer(old_inode-> |
| 1552 | i_sb, |
| 1553 | dot_dot_de. |
| 1554 | de_bh); |
| 1555 | continue; |
| 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | RFALSE(S_ISDIR(old_inode_mode) && |
| 1560 | !buffer_journal_prepared(dot_dot_de.de_bh), ""); |
| 1561 | |
| 1562 | break; |
| 1563 | } |
| 1564 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1565 | /* |
| 1566 | * ok, all the changes can be done in one fell swoop when we |
| 1567 | * have claimed all the buffers needed. |
| 1568 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1569 | |
| 1570 | mark_de_visible(new_de.de_deh + new_de.de_entry_num); |
| 1571 | set_ino_in_dir_entry(&new_de, INODE_PKEY(old_inode)); |
Jeff Mahoney | 09f1b80 | 2014-04-23 10:00:39 -0400 | [diff] [blame] | 1572 | journal_mark_dirty(&th, new_de.de_bh); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1573 | |
| 1574 | mark_de_hidden(old_de.de_deh + old_de.de_entry_num); |
Jeff Mahoney | 09f1b80 | 2014-04-23 10:00:39 -0400 | [diff] [blame] | 1575 | journal_mark_dirty(&th, old_de.de_bh); |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 1576 | ctime = current_time(old_dir); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1577 | old_dir->i_ctime = old_dir->i_mtime = ctime; |
| 1578 | new_dir->i_ctime = new_dir->i_mtime = ctime; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1579 | /* |
| 1580 | * thanks to Alex Adriaanse <alex_a@caltech.edu> for patch |
| 1581 | * which adds ctime update of renamed object |
| 1582 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1583 | old_inode->i_ctime = ctime; |
| 1584 | |
| 1585 | if (new_dentry_inode) { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1586 | /* adjust link number of the victim */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1587 | if (S_ISDIR(new_dentry_inode->i_mode)) { |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 1588 | clear_nlink(new_dentry_inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1589 | } else { |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 1590 | drop_nlink(new_dentry_inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1591 | } |
| 1592 | new_dentry_inode->i_ctime = ctime; |
| 1593 | savelink = new_dentry_inode->i_nlink; |
| 1594 | } |
| 1595 | |
| 1596 | if (S_ISDIR(old_inode_mode)) { |
Jeff Mahoney | 0222e65 | 2009-03-30 14:02:44 -0400 | [diff] [blame] | 1597 | /* adjust ".." of renamed directory */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1598 | set_ino_in_dir_entry(&dot_dot_de, INODE_PKEY(new_dir)); |
Jeff Mahoney | 09f1b80 | 2014-04-23 10:00:39 -0400 | [diff] [blame] | 1599 | journal_mark_dirty(&th, dot_dot_de.de_bh); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1600 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1601 | /* |
| 1602 | * there (in new_dir) was no directory, so it got new link |
| 1603 | * (".." of renamed directory) |
| 1604 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1605 | if (!new_dentry_inode) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1606 | INC_DIR_INODE_NLINK(new_dir); |
| 1607 | |
| 1608 | /* old directory lost one link - ".. " of renamed directory */ |
| 1609 | DEC_DIR_INODE_NLINK(old_dir); |
| 1610 | } |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1611 | /* |
| 1612 | * looks like in 2.3.99pre3 brelse is atomic. |
| 1613 | * so we can use pathrelse |
| 1614 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1615 | pathrelse(&new_entry_path); |
| 1616 | pathrelse(&dot_dot_entry_path); |
| 1617 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1618 | /* |
| 1619 | * FIXME: this reiserfs_cut_from_item's return value may screw up |
| 1620 | * anybody, but it will panic if will not be able to find the |
| 1621 | * entry. This needs one more clean up |
| 1622 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1623 | if (reiserfs_cut_from_item |
Jeff Mahoney | a228bf8 | 2014-04-23 10:00:42 -0400 | [diff] [blame] | 1624 | (&th, &old_entry_path, &old_de.de_entry_key, old_dir, NULL, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1625 | 0) < 0) |
Jeff Mahoney | 0030b64 | 2009-03-30 14:02:28 -0400 | [diff] [blame] | 1626 | reiserfs_error(old_dir->i_sb, "vs-7060", |
| 1627 | "couldn't not cut old name. Fsck later?"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1628 | |
| 1629 | old_dir->i_size -= DEH_SIZE + old_de.de_entrylen; |
| 1630 | |
| 1631 | reiserfs_update_sd(&th, old_dir); |
| 1632 | reiserfs_update_sd(&th, new_dir); |
| 1633 | reiserfs_update_sd(&th, old_inode); |
| 1634 | |
| 1635 | if (new_dentry_inode) { |
| 1636 | if (savelink == 0) |
| 1637 | add_save_link(&th, new_dentry_inode, |
| 1638 | 0 /* not truncate */ ); |
| 1639 | reiserfs_update_sd(&th, new_dentry_inode); |
| 1640 | } |
| 1641 | |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 1642 | retval = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1643 | reiserfs_write_unlock(old_dir->i_sb); |
| 1644 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | } |
| 1646 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1647 | /* directories can handle most operations... */ |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 1648 | const struct inode_operations reiserfs_dir_inode_operations = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1649 | .create = reiserfs_create, |
| 1650 | .lookup = reiserfs_lookup, |
| 1651 | .link = reiserfs_link, |
| 1652 | .unlink = reiserfs_unlink, |
| 1653 | .symlink = reiserfs_symlink, |
| 1654 | .mkdir = reiserfs_mkdir, |
| 1655 | .rmdir = reiserfs_rmdir, |
| 1656 | .mknod = reiserfs_mknod, |
| 1657 | .rename = reiserfs_rename, |
| 1658 | .setattr = reiserfs_setattr, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1659 | .listxattr = reiserfs_listxattr, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1660 | .permission = reiserfs_permission, |
Christoph Hellwig | 4e34e71 | 2011-07-23 17:37:31 +0200 | [diff] [blame] | 1661 | .get_acl = reiserfs_get_acl, |
Christoph Hellwig | 47f70d0 | 2013-12-20 05:16:49 -0800 | [diff] [blame] | 1662 | .set_acl = reiserfs_set_acl, |
Miklos Szeredi | 03eb606 | 2021-04-07 14:36:44 +0200 | [diff] [blame] | 1663 | .fileattr_get = reiserfs_fileattr_get, |
| 1664 | .fileattr_set = reiserfs_fileattr_set, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | }; |
| 1666 | |
| 1667 | /* |
| 1668 | * symlink operations.. same as page_symlink_inode_operations, with xattr |
| 1669 | * stuff added |
| 1670 | */ |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 1671 | const struct inode_operations reiserfs_symlink_inode_operations = { |
Al Viro | 6b25539 | 2015-11-17 10:20:54 -0500 | [diff] [blame] | 1672 | .get_link = page_get_link, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1673 | .setattr = reiserfs_setattr, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1674 | .listxattr = reiserfs_listxattr, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1675 | .permission = reiserfs_permission, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | }; |
| 1677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | /* |
| 1679 | * special file operations.. just xattr/acl stuff |
| 1680 | */ |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 1681 | const struct inode_operations reiserfs_special_inode_operations = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1682 | .setattr = reiserfs_setattr, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1683 | .listxattr = reiserfs_listxattr, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1684 | .permission = reiserfs_permission, |
Christoph Hellwig | 4e34e71 | 2011-07-23 17:37:31 +0200 | [diff] [blame] | 1685 | .get_acl = reiserfs_get_acl, |
Christoph Hellwig | 47f70d0 | 2013-12-20 05:16:49 -0800 | [diff] [blame] | 1686 | .set_acl = reiserfs_set_acl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | }; |