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