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 | |
| 5 | #include <linux/time.h> |
| 6 | #include <linux/reiserfs_fs.h> |
| 7 | |
| 8 | // this contains item handlers for old item types: sd, direct, |
| 9 | // indirect, directory |
| 10 | |
| 11 | /* and where are the comments? how about saying where we can find an |
| 12 | explanation of each item handler method? -Hans */ |
| 13 | |
| 14 | ////////////////////////////////////////////////////////////////////////////// |
| 15 | // stat data functions |
| 16 | // |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 17 | static int sd_bytes_number(struct item_head *ih, int block_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 19 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | } |
| 21 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 22 | static void sd_decrement_key(struct cpu_key *key) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 24 | key->on_disk_key.k_objectid--; |
| 25 | set_cpu_key_k_type(key, TYPE_ANY); |
| 26 | set_cpu_key_k_offset(key, (loff_t) (-1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 29 | static int sd_is_left_mergeable(struct reiserfs_key *key, unsigned long bsize) |
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 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 34 | static char *print_time(time_t t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 36 | static char timebuf[256]; |
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 | sprintf(timebuf, "%ld", t); |
| 39 | return timebuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 42 | static void sd_print_item(struct item_head *ih, char *item) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 44 | printk("\tmode | size | nlinks | first direct | mtime\n"); |
| 45 | if (stat_data_v1(ih)) { |
| 46 | struct stat_data_v1 *sd = (struct stat_data_v1 *)item; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 48 | printk("\t0%-6o | %6u | %2u | %d | %s\n", sd_v1_mode(sd), |
| 49 | sd_v1_size(sd), sd_v1_nlink(sd), |
| 50 | sd_v1_first_direct_byte(sd), |
| 51 | print_time(sd_v1_mtime(sd))); |
| 52 | } else { |
| 53 | struct stat_data *sd = (struct stat_data *)item; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 55 | printk("\t0%-6o | %6Lu | %2u | %d | %s\n", sd_v2_mode(sd), |
| 56 | (unsigned long long)sd_v2_size(sd), sd_v2_nlink(sd), |
| 57 | sd_v2_rdev(sd), print_time(sd_v2_mtime(sd))); |
| 58 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 61 | static void sd_check_item(struct item_head *ih, char *item) |
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 | // FIXME: type something here! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 66 | static int sd_create_vi(struct virtual_node *vn, |
| 67 | struct virtual_item *vi, |
| 68 | int is_affected, int insert_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 70 | vi->vi_index = TYPE_STAT_DATA; |
| 71 | //vi->vi_type |= VI_TYPE_STAT_DATA;// not needed? |
| 72 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 75 | static int sd_check_left(struct virtual_item *vi, int free, |
| 76 | int start_skip, int end_skip) |
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 | if (start_skip || end_skip) |
| 79 | BUG(); |
| 80 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 83 | static int sd_check_right(struct virtual_item *vi, int free) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 85 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 88 | static int sd_part_size(struct virtual_item *vi, int first, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 90 | if (count) |
| 91 | BUG(); |
| 92 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 95 | static int sd_unit_num(struct virtual_item *vi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 97 | return vi->vi_item_len - IH_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 100 | static void sd_print_vi(struct virtual_item *vi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 102 | reiserfs_warning(NULL, "STATDATA, index %d, type 0x%x, %h", |
| 103 | vi->vi_index, vi->vi_type, vi->vi_ih); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static struct item_operations stat_data_ops = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 107 | .bytes_number = sd_bytes_number, |
| 108 | .decrement_key = sd_decrement_key, |
| 109 | .is_left_mergeable = sd_is_left_mergeable, |
| 110 | .print_item = sd_print_item, |
| 111 | .check_item = sd_check_item, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 113 | .create_vi = sd_create_vi, |
| 114 | .check_left = sd_check_left, |
| 115 | .check_right = sd_check_right, |
| 116 | .part_size = sd_part_size, |
| 117 | .unit_num = sd_unit_num, |
| 118 | .print_vi = sd_print_vi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | ////////////////////////////////////////////////////////////////////////////// |
| 122 | // direct item functions |
| 123 | // |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 124 | static int direct_bytes_number(struct item_head *ih, int block_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 126 | return ih_item_len(ih); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | // FIXME: this should probably switch to indirect as well |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 130 | static void direct_decrement_key(struct cpu_key *key) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 132 | cpu_key_k_offset_dec(key); |
| 133 | if (cpu_key_k_offset(key) == 0) |
| 134 | set_cpu_key_k_type(key, TYPE_STAT_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 137 | static int direct_is_left_mergeable(struct reiserfs_key *key, |
| 138 | unsigned long bsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 140 | int version = le_key_version(key); |
| 141 | return ((le_key_k_offset(version, key) & (bsize - 1)) != 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 144 | static void direct_print_item(struct item_head *ih, char *item) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 146 | int j = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | // return; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 149 | printk("\""); |
| 150 | while (j < ih_item_len(ih)) |
| 151 | printk("%c", item[j++]); |
| 152 | printk("\"\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 155 | static void direct_check_item(struct item_head *ih, char *item) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 157 | // FIXME: type something here! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 160 | static int direct_create_vi(struct virtual_node *vn, |
| 161 | struct virtual_item *vi, |
| 162 | int is_affected, int insert_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 164 | vi->vi_index = TYPE_DIRECT; |
| 165 | //vi->vi_type |= VI_TYPE_DIRECT; |
| 166 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 169 | static int direct_check_left(struct virtual_item *vi, int free, |
| 170 | int start_skip, int end_skip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 172 | int bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 174 | bytes = free - free % 8; |
| 175 | return bytes ? : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 178 | static int direct_check_right(struct virtual_item *vi, int free) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 180 | return direct_check_left(vi, free, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 183 | static int direct_part_size(struct virtual_item *vi, int first, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 185 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 188 | static int direct_unit_num(struct virtual_item *vi) |
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 | return vi->vi_item_len - IH_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 193 | static void direct_print_vi(struct virtual_item *vi) |
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 | reiserfs_warning(NULL, "DIRECT, index %d, type 0x%x, %h", |
| 196 | vi->vi_index, vi->vi_type, vi->vi_ih); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static struct item_operations direct_ops = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 200 | .bytes_number = direct_bytes_number, |
| 201 | .decrement_key = direct_decrement_key, |
| 202 | .is_left_mergeable = direct_is_left_mergeable, |
| 203 | .print_item = direct_print_item, |
| 204 | .check_item = direct_check_item, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 206 | .create_vi = direct_create_vi, |
| 207 | .check_left = direct_check_left, |
| 208 | .check_right = direct_check_right, |
| 209 | .part_size = direct_part_size, |
| 210 | .unit_num = direct_unit_num, |
| 211 | .print_vi = direct_print_vi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | ////////////////////////////////////////////////////////////////////////////// |
| 215 | // indirect item functions |
| 216 | // |
| 217 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 218 | static int indirect_bytes_number(struct item_head *ih, int block_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 220 | return ih_item_len(ih) / UNFM_P_SIZE * block_size; //- get_ih_free_space (ih); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | // decrease offset, if it becomes 0, change type to stat data |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 224 | static void indirect_decrement_key(struct cpu_key *key) |
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 | cpu_key_k_offset_dec(key); |
| 227 | if (cpu_key_k_offset(key) == 0) |
| 228 | set_cpu_key_k_type(key, TYPE_STAT_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | // if it is not first item of the body, then it is mergeable |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 232 | static int indirect_is_left_mergeable(struct reiserfs_key *key, |
| 233 | unsigned long bsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 235 | int version = le_key_version(key); |
| 236 | return (le_key_k_offset(version, key) != 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | // printing of indirect item |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 240 | static void start_new_sequence(__u32 * start, int *len, __u32 new) |
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 | *start = new; |
| 243 | *len = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 246 | static int sequence_finished(__u32 start, int *len, __u32 new) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 248 | if (start == INT_MAX) |
| 249 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 251 | if (start == 0 && new == 0) { |
| 252 | (*len)++; |
| 253 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 255 | if (start != 0 && (start + *len) == new) { |
| 256 | (*len)++; |
| 257 | return 0; |
| 258 | } |
| 259 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 262 | static void print_sequence(__u32 start, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 264 | if (start == INT_MAX) |
| 265 | return; |
| 266 | |
| 267 | if (len == 1) |
| 268 | printk(" %d", start); |
| 269 | else |
| 270 | printk(" %d(%d)", start, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 273 | static void indirect_print_item(struct item_head *ih, char *item) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 275 | int j; |
| 276 | __le32 *unp; |
| 277 | __u32 prev = INT_MAX; |
Benoit Boissinot | d5ee4ea | 2006-03-25 03:07:54 -0800 | [diff] [blame] | 278 | int num = 0; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 279 | |
| 280 | unp = (__le32 *) item; |
| 281 | |
| 282 | if (ih_item_len(ih) % UNFM_P_SIZE) |
| 283 | reiserfs_warning(NULL, "indirect_print_item: invalid item len"); |
| 284 | |
| 285 | printk("%d pointers\n[ ", (int)I_UNFM_NUM(ih)); |
| 286 | for (j = 0; j < I_UNFM_NUM(ih); j++) { |
| 287 | if (sequence_finished(prev, &num, get_block_num(unp, j))) { |
| 288 | print_sequence(prev, num); |
| 289 | start_new_sequence(&prev, &num, get_block_num(unp, j)); |
| 290 | } |
| 291 | } |
| 292 | print_sequence(prev, num); |
| 293 | printk("]\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 296 | static void indirect_check_item(struct item_head *ih, char *item) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 298 | // FIXME: type something here! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 301 | static int indirect_create_vi(struct virtual_node *vn, |
| 302 | struct virtual_item *vi, |
| 303 | int is_affected, int insert_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 305 | vi->vi_index = TYPE_INDIRECT; |
| 306 | //vi->vi_type |= VI_TYPE_INDIRECT; |
| 307 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 310 | static int indirect_check_left(struct virtual_item *vi, int free, |
| 311 | int start_skip, int end_skip) |
| 312 | { |
| 313 | int bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 315 | bytes = free - free % UNFM_P_SIZE; |
| 316 | return bytes ? : -1; |
| 317 | } |
| 318 | |
| 319 | static int indirect_check_right(struct virtual_item *vi, int free) |
| 320 | { |
| 321 | return indirect_check_left(vi, free, 0, 0); |
| 322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | // return size in bytes of 'units' units. If first == 0 - calculate from the head (left), otherwise - from tail (right) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 325 | static int indirect_part_size(struct virtual_item *vi, int first, int units) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 327 | // unit of indirect item is byte (yet) |
| 328 | return units; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 331 | static int indirect_unit_num(struct virtual_item *vi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 333 | // unit of indirect item is byte (yet) |
| 334 | return vi->vi_item_len - IH_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 337 | static void indirect_print_vi(struct virtual_item *vi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 339 | reiserfs_warning(NULL, "INDIRECT, index %d, type 0x%x, %h", |
| 340 | vi->vi_index, vi->vi_type, vi->vi_ih); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | static struct item_operations indirect_ops = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 344 | .bytes_number = indirect_bytes_number, |
| 345 | .decrement_key = indirect_decrement_key, |
| 346 | .is_left_mergeable = indirect_is_left_mergeable, |
| 347 | .print_item = indirect_print_item, |
| 348 | .check_item = indirect_check_item, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 350 | .create_vi = indirect_create_vi, |
| 351 | .check_left = indirect_check_left, |
| 352 | .check_right = indirect_check_right, |
| 353 | .part_size = indirect_part_size, |
| 354 | .unit_num = indirect_unit_num, |
| 355 | .print_vi = indirect_print_vi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | }; |
| 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | ////////////////////////////////////////////////////////////////////////////// |
| 359 | // direntry functions |
| 360 | // |
| 361 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 362 | static int direntry_bytes_number(struct item_head *ih, int block_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 364 | reiserfs_warning(NULL, "vs-16090: direntry_bytes_number: " |
| 365 | "bytes number is asked for direntry"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 369 | static void direntry_decrement_key(struct cpu_key *key) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 371 | cpu_key_k_offset_dec(key); |
| 372 | if (cpu_key_k_offset(key) == 0) |
| 373 | set_cpu_key_k_type(key, TYPE_STAT_DATA); |
| 374 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 376 | static int direntry_is_left_mergeable(struct reiserfs_key *key, |
| 377 | unsigned long bsize) |
| 378 | { |
| 379 | if (le32_to_cpu(key->u.k_offset_v1.k_offset) == DOT_OFFSET) |
| 380 | return 0; |
| 381 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 383 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 385 | static void direntry_print_item(struct item_head *ih, char *item) |
| 386 | { |
| 387 | int i; |
| 388 | int namelen; |
| 389 | struct reiserfs_de_head *deh; |
| 390 | char *name; |
| 391 | static char namebuf[80]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 393 | printk("\n # %-15s%-30s%-15s%-15s%-15s\n", "Name", |
| 394 | "Key of pointed object", "Hash", "Gen number", "Status"); |
| 395 | |
| 396 | deh = (struct reiserfs_de_head *)item; |
| 397 | |
| 398 | for (i = 0; i < I_ENTRY_COUNT(ih); i++, deh++) { |
| 399 | namelen = |
| 400 | (i ? (deh_location(deh - 1)) : ih_item_len(ih)) - |
| 401 | deh_location(deh); |
| 402 | name = item + deh_location(deh); |
| 403 | if (name[namelen - 1] == 0) |
| 404 | namelen = strlen(name); |
| 405 | namebuf[0] = '"'; |
| 406 | if (namelen > sizeof(namebuf) - 3) { |
| 407 | strncpy(namebuf + 1, name, sizeof(namebuf) - 3); |
| 408 | namebuf[sizeof(namebuf) - 2] = '"'; |
| 409 | namebuf[sizeof(namebuf) - 1] = 0; |
| 410 | } else { |
| 411 | memcpy(namebuf + 1, name, namelen); |
| 412 | namebuf[namelen + 1] = '"'; |
| 413 | namebuf[namelen + 2] = 0; |
| 414 | } |
| 415 | |
| 416 | printk("%d: %-15s%-15d%-15d%-15Ld%-15Ld(%s)\n", |
| 417 | i, namebuf, |
| 418 | deh_dir_id(deh), deh_objectid(deh), |
| 419 | GET_HASH_VALUE(deh_offset(deh)), |
| 420 | GET_GENERATION_NUMBER((deh_offset(deh))), |
| 421 | (de_hidden(deh)) ? "HIDDEN" : "VISIBLE"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 425 | static void direntry_check_item(struct item_head *ih, char *item) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 427 | int i; |
| 428 | struct reiserfs_de_head *deh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 430 | // FIXME: type something here! |
| 431 | deh = (struct reiserfs_de_head *)item; |
| 432 | for (i = 0; i < I_ENTRY_COUNT(ih); i++, deh++) { |
| 433 | ; |
| 434 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | #define DIRENTRY_VI_FIRST_DIRENTRY_ITEM 1 |
| 438 | |
| 439 | /* |
| 440 | * function returns old entry number in directory item in real node |
| 441 | * using new entry number in virtual item in virtual node */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 442 | static inline int old_entry_num(int is_affected, int virtual_entry_num, |
| 443 | int pos_in_item, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 445 | if (mode == M_INSERT || mode == M_DELETE) |
| 446 | return virtual_entry_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 448 | if (!is_affected) |
| 449 | /* cut or paste is applied to another item */ |
| 450 | return virtual_entry_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 452 | if (virtual_entry_num < pos_in_item) |
| 453 | return virtual_entry_num; |
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 | if (mode == M_CUT) |
| 456 | return virtual_entry_num + 1; |
| 457 | |
| 458 | RFALSE(mode != M_PASTE || virtual_entry_num == 0, |
| 459 | "vs-8015: old_entry_num: mode must be M_PASTE (mode = \'%c\'", |
| 460 | mode); |
| 461 | |
| 462 | return virtual_entry_num - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | /* Create an array of sizes of directory entries for virtual |
| 466 | item. Return space used by an item. FIXME: no control over |
| 467 | consuming of space used by this item handler */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 468 | static int direntry_create_vi(struct virtual_node *vn, |
| 469 | struct virtual_item *vi, |
| 470 | int is_affected, int insert_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 472 | struct direntry_uarea *dir_u = vi->vi_uarea; |
| 473 | int i, j; |
| 474 | int size = sizeof(struct direntry_uarea); |
| 475 | struct reiserfs_de_head *deh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 477 | vi->vi_index = TYPE_DIRENTRY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 479 | if (!(vi->vi_ih) || !vi->vi_item) |
| 480 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 482 | dir_u->flags = 0; |
| 483 | if (le_ih_k_offset(vi->vi_ih) == DOT_OFFSET) |
| 484 | dir_u->flags |= DIRENTRY_VI_FIRST_DIRENTRY_ITEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 486 | deh = (struct reiserfs_de_head *)(vi->vi_item); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 488 | /* virtual directory item have this amount of entry after */ |
| 489 | dir_u->entry_count = ih_entry_count(vi->vi_ih) + |
| 490 | ((is_affected) ? ((vn->vn_mode == M_CUT) ? -1 : |
| 491 | (vn->vn_mode == M_PASTE ? 1 : 0)) : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 493 | for (i = 0; i < dir_u->entry_count; i++) { |
| 494 | j = old_entry_num(is_affected, i, vn->vn_pos_in_item, |
| 495 | vn->vn_mode); |
| 496 | dir_u->entry_sizes[i] = |
| 497 | (j ? deh_location(&(deh[j - 1])) : ih_item_len(vi->vi_ih)) - |
| 498 | deh_location(&(deh[j])) + DEH_SIZE; |
| 499 | } |
| 500 | |
| 501 | size += (dir_u->entry_count * sizeof(short)); |
| 502 | |
| 503 | /* set size of pasted entry */ |
| 504 | if (is_affected && vn->vn_mode == M_PASTE) |
| 505 | dir_u->entry_sizes[vn->vn_pos_in_item] = insert_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
| 507 | #ifdef CONFIG_REISERFS_CHECK |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 508 | /* compare total size of entries with item length */ |
| 509 | { |
| 510 | int k, l; |
| 511 | |
| 512 | l = 0; |
| 513 | for (k = 0; k < dir_u->entry_count; k++) |
| 514 | l += dir_u->entry_sizes[k]; |
| 515 | |
| 516 | if (l + IH_SIZE != vi->vi_item_len + |
| 517 | ((is_affected |
| 518 | && (vn->vn_mode == M_PASTE |
| 519 | || vn->vn_mode == M_CUT)) ? insert_size : 0)) { |
| 520 | reiserfs_panic(NULL, |
| 521 | "vs-8025: set_entry_sizes: (mode==%c, insert_size==%d), invalid length of directory item", |
| 522 | vn->vn_mode, insert_size); |
| 523 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | #endif |
| 526 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 527 | return size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | } |
| 530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | // |
| 532 | // return number of entries which may fit into specified amount of |
| 533 | // free space, or -1 if free space is not enough even for 1 entry |
| 534 | // |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 535 | static int direntry_check_left(struct virtual_item *vi, int free, |
| 536 | int start_skip, int end_skip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 538 | int i; |
| 539 | int entries = 0; |
| 540 | struct direntry_uarea *dir_u = vi->vi_uarea; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 542 | for (i = start_skip; i < dir_u->entry_count - end_skip; i++) { |
| 543 | if (dir_u->entry_sizes[i] > free) |
| 544 | /* i-th entry doesn't fit into the remaining free space */ |
| 545 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 547 | free -= dir_u->entry_sizes[i]; |
| 548 | entries++; |
| 549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 551 | if (entries == dir_u->entry_count) { |
| 552 | reiserfs_panic(NULL, "free space %d, entry_count %d\n", free, |
| 553 | dir_u->entry_count); |
| 554 | } |
| 555 | |
| 556 | /* "." and ".." can not be separated from each other */ |
| 557 | if (start_skip == 0 && (dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM) |
| 558 | && entries < 2) |
| 559 | entries = 0; |
| 560 | |
| 561 | return entries ? : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 564 | static int direntry_check_right(struct virtual_item *vi, int free) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 566 | int i; |
| 567 | int entries = 0; |
| 568 | struct direntry_uarea *dir_u = vi->vi_uarea; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 570 | for (i = dir_u->entry_count - 1; i >= 0; i--) { |
| 571 | if (dir_u->entry_sizes[i] > free) |
| 572 | /* i-th entry doesn't fit into the remaining free space */ |
| 573 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 575 | free -= dir_u->entry_sizes[i]; |
| 576 | entries++; |
| 577 | } |
| 578 | if (entries == dir_u->entry_count) |
| 579 | BUG(); |
| 580 | |
| 581 | /* "." and ".." can not be separated from each other */ |
| 582 | if ((dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM) |
| 583 | && entries > dir_u->entry_count - 2) |
| 584 | entries = dir_u->entry_count - 2; |
| 585 | |
| 586 | return entries ? : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | /* sum of entry sizes between from-th and to-th entries including both edges */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 590 | static int direntry_part_size(struct virtual_item *vi, int first, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 592 | int i, retval; |
| 593 | int from, to; |
| 594 | struct direntry_uarea *dir_u = vi->vi_uarea; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 596 | retval = 0; |
| 597 | if (first == 0) |
| 598 | from = 0; |
| 599 | else |
| 600 | from = dir_u->entry_count - count; |
| 601 | to = from + count - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 603 | for (i = from; i <= to; i++) |
| 604 | retval += dir_u->entry_sizes[i]; |
| 605 | |
| 606 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 609 | static int direntry_unit_num(struct virtual_item *vi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 611 | struct direntry_uarea *dir_u = vi->vi_uarea; |
| 612 | |
| 613 | return dir_u->entry_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 616 | static void direntry_print_vi(struct virtual_item *vi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 618 | int i; |
| 619 | struct direntry_uarea *dir_u = vi->vi_uarea; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 621 | reiserfs_warning(NULL, "DIRENTRY, index %d, type 0x%x, %h, flags 0x%x", |
| 622 | vi->vi_index, vi->vi_type, vi->vi_ih, dir_u->flags); |
| 623 | printk("%d entries: ", dir_u->entry_count); |
| 624 | for (i = 0; i < dir_u->entry_count; i++) |
| 625 | printk("%d ", dir_u->entry_sizes[i]); |
| 626 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | static struct item_operations direntry_ops = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 630 | .bytes_number = direntry_bytes_number, |
| 631 | .decrement_key = direntry_decrement_key, |
| 632 | .is_left_mergeable = direntry_is_left_mergeable, |
| 633 | .print_item = direntry_print_item, |
| 634 | .check_item = direntry_check_item, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 636 | .create_vi = direntry_create_vi, |
| 637 | .check_left = direntry_check_left, |
| 638 | .check_right = direntry_check_right, |
| 639 | .part_size = direntry_part_size, |
| 640 | .unit_num = direntry_unit_num, |
| 641 | .print_vi = direntry_print_vi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | }; |
| 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | ////////////////////////////////////////////////////////////////////////////// |
| 645 | // Error catching functions to catch errors caused by incorrect item types. |
| 646 | // |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 647 | static int errcatch_bytes_number(struct item_head *ih, int block_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 649 | reiserfs_warning(NULL, |
| 650 | "green-16001: Invalid item type observed, run fsck ASAP"); |
| 651 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 654 | static void errcatch_decrement_key(struct cpu_key *key) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 656 | reiserfs_warning(NULL, |
| 657 | "green-16002: Invalid item type observed, run fsck ASAP"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 660 | static int errcatch_is_left_mergeable(struct reiserfs_key *key, |
| 661 | unsigned long bsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 663 | reiserfs_warning(NULL, |
| 664 | "green-16003: Invalid item type observed, run fsck ASAP"); |
| 665 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 668 | static void errcatch_print_item(struct item_head *ih, char *item) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 670 | reiserfs_warning(NULL, |
| 671 | "green-16004: Invalid item type observed, run fsck ASAP"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 674 | static void errcatch_check_item(struct item_head *ih, char *item) |
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 | reiserfs_warning(NULL, |
| 677 | "green-16005: Invalid item type observed, run fsck ASAP"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 680 | static int errcatch_create_vi(struct virtual_node *vn, |
| 681 | struct virtual_item *vi, |
| 682 | int is_affected, int insert_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 684 | reiserfs_warning(NULL, |
| 685 | "green-16006: Invalid item type observed, run fsck ASAP"); |
| 686 | return 0; // We might return -1 here as well, but it won't help as create_virtual_node() from where |
| 687 | // this operation is called from is of return type void. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 690 | static int errcatch_check_left(struct virtual_item *vi, int free, |
| 691 | int start_skip, int end_skip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 693 | reiserfs_warning(NULL, |
| 694 | "green-16007: Invalid item type observed, run fsck ASAP"); |
| 695 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 698 | static int errcatch_check_right(struct virtual_item *vi, int free) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 700 | reiserfs_warning(NULL, |
| 701 | "green-16008: Invalid item type observed, run fsck ASAP"); |
| 702 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 705 | static int errcatch_part_size(struct virtual_item *vi, int first, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 707 | reiserfs_warning(NULL, |
| 708 | "green-16009: Invalid item type observed, run fsck ASAP"); |
| 709 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 712 | static int errcatch_unit_num(struct virtual_item *vi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 714 | reiserfs_warning(NULL, |
| 715 | "green-16010: Invalid item type observed, run fsck ASAP"); |
| 716 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 719 | static void errcatch_print_vi(struct virtual_item *vi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 721 | reiserfs_warning(NULL, |
| 722 | "green-16011: Invalid item type observed, run fsck ASAP"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | static struct item_operations errcatch_ops = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 726 | errcatch_bytes_number, |
| 727 | errcatch_decrement_key, |
| 728 | errcatch_is_left_mergeable, |
| 729 | errcatch_print_item, |
| 730 | errcatch_check_item, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 732 | errcatch_create_vi, |
| 733 | errcatch_check_left, |
| 734 | errcatch_check_right, |
| 735 | errcatch_part_size, |
| 736 | errcatch_unit_num, |
| 737 | errcatch_print_vi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | }; |
| 739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | ////////////////////////////////////////////////////////////////////////////// |
| 741 | // |
| 742 | // |
| 743 | #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3) |
Jeff Mahoney | 7fa94c8 | 2005-07-12 19:19:30 -0400 | [diff] [blame] | 744 | #error Item types must use disk-format assigned values. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | #endif |
| 746 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 747 | struct item_operations *item_ops[TYPE_ANY + 1] = { |
| 748 | &stat_data_ops, |
| 749 | &indirect_ops, |
| 750 | &direct_ops, |
| 751 | &direntry_ops, |
| 752 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
| 753 | &errcatch_ops /* This is to catch errors with invalid type (15th entry for TYPE_ANY) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | }; |