blob: e3c558d1b78c02c711ae9868fe409d349127103f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
3 */
4
5#include <linux/time.h>
Al Virof466c6f2012-03-17 01:16:43 -04006#include "reiserfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
Jeff Mahoney098297b2014-04-23 10:00:36 -04008/*
9 * this contains item handlers for old item types: sd, direct,
10 * indirect, directory
11 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Jeff Mahoney098297b2014-04-23 10:00:36 -040013/*
14 * and where are the comments? how about saying where we can find an
15 * explanation of each item handler method? -Hans
16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Jeff Mahoney098297b2014-04-23 10:00:36 -040018/* stat data functions */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070019static int sd_bytes_number(struct item_head *ih, int block_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070021 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022}
23
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070024static void sd_decrement_key(struct cpu_key *key)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070026 key->on_disk_key.k_objectid--;
27 set_cpu_key_k_type(key, TYPE_ANY);
Vladimir Saveliev6d205f12007-04-11 23:28:44 -070028 set_cpu_key_k_offset(key, (loff_t)(~0ULL >> 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070029}
30
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070031static int sd_is_left_mergeable(struct reiserfs_key *key, unsigned long bsize)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070033 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034}
35
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070036static char *print_time(time_t t)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070038 static char timebuf[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070040 sprintf(timebuf, "%ld", t);
41 return timebuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
43
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070044static void sd_print_item(struct item_head *ih, char *item)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070046 printk("\tmode | size | nlinks | first direct | mtime\n");
47 if (stat_data_v1(ih)) {
48 struct stat_data_v1 *sd = (struct stat_data_v1 *)item;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070050 printk("\t0%-6o | %6u | %2u | %d | %s\n", sd_v1_mode(sd),
51 sd_v1_size(sd), sd_v1_nlink(sd),
52 sd_v1_first_direct_byte(sd),
53 print_time(sd_v1_mtime(sd)));
54 } else {
55 struct stat_data *sd = (struct stat_data *)item;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Fabian Frederick53872ed2014-08-08 14:21:10 -070057 printk("\t0%-6o | %6llu | %2u | %d | %s\n", sd_v2_mode(sd),
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070058 (unsigned long long)sd_v2_size(sd), sd_v2_nlink(sd),
59 sd_v2_rdev(sd), print_time(sd_v2_mtime(sd)));
60 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
62
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070063static void sd_check_item(struct item_head *ih, char *item)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Jeff Mahoney098297b2014-04-23 10:00:36 -040065 /* unused */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070068static int sd_create_vi(struct virtual_node *vn,
69 struct virtual_item *vi,
70 int is_affected, int insert_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070072 vi->vi_index = TYPE_STAT_DATA;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070073 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070076static int sd_check_left(struct virtual_item *vi, int free,
77 int start_skip, int end_skip)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Eric Sesterhenn14a61442006-10-03 23:36:38 +020079 BUG_ON(start_skip || end_skip);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070080 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070083static int sd_check_right(struct virtual_item *vi, int free)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070085 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070088static int sd_part_size(struct virtual_item *vi, int first, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
Eric Sesterhenn14a61442006-10-03 23:36:38 +020090 BUG_ON(count);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070091 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070094static int sd_unit_num(struct virtual_item *vi)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070096 return vi->vi_item_len - IH_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
Linus Torvaldsbd4c6252005-07-12 20:21:28 -070099static void sd_print_vi(struct virtual_item *vi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400101 reiserfs_warning(NULL, "reiserfs-16100",
102 "STATDATA, index %d, type 0x%x, %h",
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700103 vi->vi_index, vi->vi_type, vi->vi_ih);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
106static struct item_operations stat_data_ops = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700107 .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 Torvalds1da177e2005-04-16 15:20:36 -0700112
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700113 .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 Torvalds1da177e2005-04-16 15:20:36 -0700119};
120
Jeff Mahoney098297b2014-04-23 10:00:36 -0400121/* direct item functions */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700122static int direct_bytes_number(struct item_head *ih, int block_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700124 return ih_item_len(ih);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125}
126
Jeff Mahoney098297b2014-04-23 10:00:36 -0400127/* FIXME: this should probably switch to indirect as well */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700128static void direct_decrement_key(struct cpu_key *key)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700130 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 Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700135static int direct_is_left_mergeable(struct reiserfs_key *key,
136 unsigned long bsize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700138 int version = le_key_version(key);
139 return ((le_key_k_offset(version, key) & (bsize - 1)) != 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700142static void direct_print_item(struct item_head *ih, char *item)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700144 int j = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Jeff Mahoney098297b2014-04-23 10:00:36 -0400146/* return; */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700147 printk("\"");
148 while (j < ih_item_len(ih))
149 printk("%c", item[j++]);
150 printk("\"\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700153static void direct_check_item(struct item_head *ih, char *item)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Jeff Mahoney098297b2014-04-23 10:00:36 -0400155 /* unused */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
157
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700158static int direct_create_vi(struct virtual_node *vn,
159 struct virtual_item *vi,
160 int is_affected, int insert_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700162 vi->vi_index = TYPE_DIRECT;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700163 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164}
165
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700166static int direct_check_left(struct virtual_item *vi, int free,
167 int start_skip, int end_skip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700169 int bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700171 bytes = free - free % 8;
172 return bytes ? : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173}
174
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700175static int direct_check_right(struct virtual_item *vi, int free)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700177 return direct_check_left(vi, free, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700180static int direct_part_size(struct virtual_item *vi, int first, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700182 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183}
184
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700185static int direct_unit_num(struct virtual_item *vi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700187 return vi->vi_item_len - IH_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188}
189
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700190static void direct_print_vi(struct virtual_item *vi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400192 reiserfs_warning(NULL, "reiserfs-16101",
193 "DIRECT, index %d, type 0x%x, %h",
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700194 vi->vi_index, vi->vi_type, vi->vi_ih);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195}
196
197static struct item_operations direct_ops = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700198 .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 Torvalds1da177e2005-04-16 15:20:36 -0700203
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700204 .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 Torvalds1da177e2005-04-16 15:20:36 -0700210};
211
Jeff Mahoney098297b2014-04-23 10:00:36 -0400212/* indirect item functions */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700213static int indirect_bytes_number(struct item_head *ih, int block_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Jeff Mahoney098297b2014-04-23 10:00:36 -0400215 return ih_item_len(ih) / UNFM_P_SIZE * block_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
Jeff Mahoney098297b2014-04-23 10:00:36 -0400218/* decrease offset, if it becomes 0, change type to stat data */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700219static void indirect_decrement_key(struct cpu_key *key)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700221 cpu_key_k_offset_dec(key);
222 if (cpu_key_k_offset(key) == 0)
223 set_cpu_key_k_type(key, TYPE_STAT_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}
225
Jeff Mahoney098297b2014-04-23 10:00:36 -0400226/* if it is not first item of the body, then it is mergeable */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700227static int indirect_is_left_mergeable(struct reiserfs_key *key,
228 unsigned long bsize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700230 int version = le_key_version(key);
231 return (le_key_k_offset(version, key) != 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
Jeff Mahoney098297b2014-04-23 10:00:36 -0400234/* printing of indirect item */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700235static void start_new_sequence(__u32 * start, int *len, __u32 new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700237 *start = new;
238 *len = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239}
240
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700241static int sequence_finished(__u32 start, int *len, __u32 new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700243 if (start == INT_MAX)
244 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700246 if (start == 0 && new == 0) {
247 (*len)++;
248 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700250 if (start != 0 && (start + *len) == new) {
251 (*len)++;
252 return 0;
253 }
254 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255}
256
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700257static void print_sequence(__u32 start, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700259 if (start == INT_MAX)
260 return;
261
262 if (len == 1)
263 printk(" %d", start);
264 else
265 printk(" %d(%d)", start, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266}
267
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700268static void indirect_print_item(struct item_head *ih, char *item)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700270 int j;
271 __le32 *unp;
272 __u32 prev = INT_MAX;
Benoit Boissinotd5ee4ea2006-03-25 03:07:54 -0800273 int num = 0;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700274
275 unp = (__le32 *) item;
276
277 if (ih_item_len(ih) % UNFM_P_SIZE)
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400278 reiserfs_warning(NULL, "reiserfs-16102", "invalid item len");
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700279
280 printk("%d pointers\n[ ", (int)I_UNFM_NUM(ih));
281 for (j = 0; j < I_UNFM_NUM(ih); j++) {
282 if (sequence_finished(prev, &num, get_block_num(unp, j))) {
283 print_sequence(prev, num);
284 start_new_sequence(&prev, &num, get_block_num(unp, j));
285 }
286 }
287 print_sequence(prev, num);
288 printk("]\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289}
290
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700291static void indirect_check_item(struct item_head *ih, char *item)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Jeff Mahoney098297b2014-04-23 10:00:36 -0400293 /* unused */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294}
295
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700296static int indirect_create_vi(struct virtual_node *vn,
297 struct virtual_item *vi,
298 int is_affected, int insert_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700300 vi->vi_index = TYPE_INDIRECT;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700301 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
303
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700304static int indirect_check_left(struct virtual_item *vi, int free,
305 int start_skip, int end_skip)
306{
307 int bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700309 bytes = free - free % UNFM_P_SIZE;
310 return bytes ? : -1;
311}
312
313static int indirect_check_right(struct virtual_item *vi, int free)
314{
315 return indirect_check_left(vi, free, 0, 0);
316}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Jeff Mahoney098297b2014-04-23 10:00:36 -0400318/*
319 * return size in bytes of 'units' units. If first == 0 - calculate
320 * from the head (left), otherwise - from tail (right)
321 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700322static int indirect_part_size(struct virtual_item *vi, int first, int units)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
Jeff Mahoney098297b2014-04-23 10:00:36 -0400324 /* unit of indirect item is byte (yet) */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700325 return units;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326}
327
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700328static int indirect_unit_num(struct virtual_item *vi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Jeff Mahoney098297b2014-04-23 10:00:36 -0400330 /* unit of indirect item is byte (yet) */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700331 return vi->vi_item_len - IH_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700334static void indirect_print_vi(struct virtual_item *vi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400336 reiserfs_warning(NULL, "reiserfs-16103",
337 "INDIRECT, index %d, type 0x%x, %h",
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700338 vi->vi_index, vi->vi_type, vi->vi_ih);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339}
340
341static struct item_operations indirect_ops = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700342 .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 Torvalds1da177e2005-04-16 15:20:36 -0700347
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700348 .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 Torvalds1da177e2005-04-16 15:20:36 -0700354};
355
Jeff Mahoney098297b2014-04-23 10:00:36 -0400356/* direntry functions */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700357static int direntry_bytes_number(struct item_head *ih, int block_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400359 reiserfs_warning(NULL, "vs-16090",
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700360 "bytes number is asked for direntry");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700364static void direntry_decrement_key(struct cpu_key *key)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700366 cpu_key_k_offset_dec(key);
367 if (cpu_key_k_offset(key) == 0)
368 set_cpu_key_k_type(key, TYPE_STAT_DATA);
369}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700371static int direntry_is_left_mergeable(struct reiserfs_key *key,
372 unsigned long bsize)
373{
374 if (le32_to_cpu(key->u.k_offset_v1.k_offset) == DOT_OFFSET)
375 return 0;
376 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700378}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700380static void direntry_print_item(struct item_head *ih, char *item)
381{
382 int i;
383 int namelen;
384 struct reiserfs_de_head *deh;
385 char *name;
386 static char namebuf[80];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700388 printk("\n # %-15s%-30s%-15s%-15s%-15s\n", "Name",
389 "Key of pointed object", "Hash", "Gen number", "Status");
390
391 deh = (struct reiserfs_de_head *)item;
392
Jeff Mahoney4cf5f7a2014-04-23 10:00:35 -0400393 for (i = 0; i < ih_entry_count(ih); i++, deh++) {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700394 namelen =
395 (i ? (deh_location(deh - 1)) : ih_item_len(ih)) -
396 deh_location(deh);
397 name = item + deh_location(deh);
398 if (name[namelen - 1] == 0)
399 namelen = strlen(name);
400 namebuf[0] = '"';
401 if (namelen > sizeof(namebuf) - 3) {
402 strncpy(namebuf + 1, name, sizeof(namebuf) - 3);
403 namebuf[sizeof(namebuf) - 2] = '"';
404 namebuf[sizeof(namebuf) - 1] = 0;
405 } else {
406 memcpy(namebuf + 1, name, namelen);
407 namebuf[namelen + 1] = '"';
408 namebuf[namelen + 2] = 0;
409 }
410
Fabian Frederick53872ed2014-08-08 14:21:10 -0700411 printk("%d: %-15s%-15d%-15d%-15lld%-15lld(%s)\n",
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700412 i, namebuf,
413 deh_dir_id(deh), deh_objectid(deh),
414 GET_HASH_VALUE(deh_offset(deh)),
415 GET_GENERATION_NUMBER((deh_offset(deh))),
416 (de_hidden(deh)) ? "HIDDEN" : "VISIBLE");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
419
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700420static void direntry_check_item(struct item_head *ih, char *item)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700422 int i;
423 struct reiserfs_de_head *deh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Jeff Mahoney098297b2014-04-23 10:00:36 -0400425 /* unused */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700426 deh = (struct reiserfs_de_head *)item;
Jeff Mahoney4cf5f7a2014-04-23 10:00:35 -0400427 for (i = 0; i < ih_entry_count(ih); i++, deh++) {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700428 ;
429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432#define DIRENTRY_VI_FIRST_DIRENTRY_ITEM 1
433
434/*
435 * function returns old entry number in directory item in real node
Jeff Mahoney098297b2014-04-23 10:00:36 -0400436 * using new entry number in virtual item in virtual node
437 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700438static inline int old_entry_num(int is_affected, int virtual_entry_num,
439 int pos_in_item, int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700441 if (mode == M_INSERT || mode == M_DELETE)
442 return virtual_entry_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700444 if (!is_affected)
445 /* cut or paste is applied to another item */
446 return virtual_entry_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700448 if (virtual_entry_num < pos_in_item)
449 return virtual_entry_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700451 if (mode == M_CUT)
452 return virtual_entry_num + 1;
453
454 RFALSE(mode != M_PASTE || virtual_entry_num == 0,
455 "vs-8015: old_entry_num: mode must be M_PASTE (mode = \'%c\'",
456 mode);
457
458 return virtual_entry_num - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
460
Jeff Mahoney098297b2014-04-23 10:00:36 -0400461/*
462 * Create an array of sizes of directory entries for virtual
463 * item. Return space used by an item. FIXME: no control over
464 * consuming of space used by this item handler
465 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700466static int direntry_create_vi(struct virtual_node *vn,
467 struct virtual_item *vi,
468 int is_affected, int insert_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700470 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 Torvalds1da177e2005-04-16 15:20:36 -0700474
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700475 vi->vi_index = TYPE_DIRENTRY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Eric Sesterhenn14a61442006-10-03 23:36:38 +0200477 BUG_ON(!(vi->vi_ih) || !vi->vi_item);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700479 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 Torvalds1da177e2005-04-16 15:20:36 -0700482
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700483 deh = (struct reiserfs_de_head *)(vi->vi_item);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700485 /* 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 Torvalds1da177e2005-04-16 15:20:36 -0700489
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700490 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] =
Jeff Mahoneya228bf82014-04-23 10:00:42 -0400494 (j ? deh_location(&deh[j - 1]) : ih_item_len(vi->vi_ih)) -
495 deh_location(&deh[j]) + DEH_SIZE;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700496 }
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 Torvalds1da177e2005-04-16 15:20:36 -0700503
504#ifdef CONFIG_REISERFS_CHECK
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700505 /* 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)) {
Jeff Mahoneyc3a9c212009-03-30 14:02:25 -0400517 reiserfs_panic(NULL, "vs-8025", "(mode==%c, "
518 "insert_size==%d), invalid length of "
519 "directory item",
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700520 vn->vn_mode, insert_size);
521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523#endif
524
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700525 return size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527}
528
Jeff Mahoney098297b2014-04-23 10:00:36 -0400529/*
530 * return number of entries which may fit into specified amount of
531 * free space, or -1 if free space is not enough even for 1 entry
532 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700533static int direntry_check_left(struct virtual_item *vi, int free,
534 int start_skip, int end_skip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700536 int i;
537 int entries = 0;
538 struct direntry_uarea *dir_u = vi->vi_uarea;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700540 for (i = start_skip; i < dir_u->entry_count - end_skip; i++) {
Jeff Mahoney098297b2014-04-23 10:00:36 -0400541 /* i-th entry doesn't fit into the remaining free space */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700542 if (dir_u->entry_sizes[i] > free)
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700543 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700545 free -= dir_u->entry_sizes[i];
546 entries++;
547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700549 if (entries == dir_u->entry_count) {
Jeff Mahoneyc3a9c212009-03-30 14:02:25 -0400550 reiserfs_panic(NULL, "item_ops-1",
551 "free space %d, entry_count %d", free,
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700552 dir_u->entry_count);
553 }
554
555 /* "." and ".." can not be separated from each other */
556 if (start_skip == 0 && (dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM)
557 && entries < 2)
558 entries = 0;
559
560 return entries ? : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561}
562
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700563static int direntry_check_right(struct virtual_item *vi, int free)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700565 int i;
566 int entries = 0;
567 struct direntry_uarea *dir_u = vi->vi_uarea;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700569 for (i = dir_u->entry_count - 1; i >= 0; i--) {
Jeff Mahoney098297b2014-04-23 10:00:36 -0400570 /* i-th entry doesn't fit into the remaining free space */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700571 if (dir_u->entry_sizes[i] > free)
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700572 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700574 free -= dir_u->entry_sizes[i];
575 entries++;
576 }
Eric Sesterhenn14a61442006-10-03 23:36:38 +0200577 BUG_ON(entries == dir_u->entry_count);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700578
579 /* "." and ".." can not be separated from each other */
580 if ((dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM)
581 && entries > dir_u->entry_count - 2)
582 entries = dir_u->entry_count - 2;
583
584 return entries ? : -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585}
586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587/* sum of entry sizes between from-th and to-th entries including both edges */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700588static int direntry_part_size(struct virtual_item *vi, int first, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700590 int i, retval;
591 int from, to;
592 struct direntry_uarea *dir_u = vi->vi_uarea;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700594 retval = 0;
595 if (first == 0)
596 from = 0;
597 else
598 from = dir_u->entry_count - count;
599 to = from + count - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700601 for (i = from; i <= to; i++)
602 retval += dir_u->entry_sizes[i];
603
604 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605}
606
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700607static int direntry_unit_num(struct virtual_item *vi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700609 struct direntry_uarea *dir_u = vi->vi_uarea;
610
611 return dir_u->entry_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612}
613
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700614static void direntry_print_vi(struct virtual_item *vi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700616 int i;
617 struct direntry_uarea *dir_u = vi->vi_uarea;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400619 reiserfs_warning(NULL, "reiserfs-16104",
620 "DIRENTRY, index %d, type 0x%x, %h, flags 0x%x",
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700621 vi->vi_index, vi->vi_type, vi->vi_ih, dir_u->flags);
622 printk("%d entries: ", dir_u->entry_count);
623 for (i = 0; i < dir_u->entry_count; i++)
624 printk("%d ", dir_u->entry_sizes[i]);
625 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626}
627
628static struct item_operations direntry_ops = {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700629 .bytes_number = direntry_bytes_number,
630 .decrement_key = direntry_decrement_key,
631 .is_left_mergeable = direntry_is_left_mergeable,
632 .print_item = direntry_print_item,
633 .check_item = direntry_check_item,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700635 .create_vi = direntry_create_vi,
636 .check_left = direntry_check_left,
637 .check_right = direntry_check_right,
638 .part_size = direntry_part_size,
639 .unit_num = direntry_unit_num,
640 .print_vi = direntry_print_vi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641};
642
Jeff Mahoney098297b2014-04-23 10:00:36 -0400643/* Error catching functions to catch errors caused by incorrect item types. */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700644static int errcatch_bytes_number(struct item_head *ih, int block_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400646 reiserfs_warning(NULL, "green-16001",
647 "Invalid item type observed, run fsck ASAP");
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700648 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649}
650
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700651static void errcatch_decrement_key(struct cpu_key *key)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400653 reiserfs_warning(NULL, "green-16002",
654 "Invalid item type observed, run fsck ASAP");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655}
656
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700657static int errcatch_is_left_mergeable(struct reiserfs_key *key,
658 unsigned long bsize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400660 reiserfs_warning(NULL, "green-16003",
661 "Invalid item type observed, run fsck ASAP");
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700662 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663}
664
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700665static void errcatch_print_item(struct item_head *ih, char *item)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400667 reiserfs_warning(NULL, "green-16004",
668 "Invalid item type observed, run fsck ASAP");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669}
670
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700671static void errcatch_check_item(struct item_head *ih, char *item)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400673 reiserfs_warning(NULL, "green-16005",
674 "Invalid item type observed, run fsck ASAP");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675}
676
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700677static int errcatch_create_vi(struct virtual_node *vn,
678 struct virtual_item *vi,
679 int is_affected, int insert_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400681 reiserfs_warning(NULL, "green-16006",
682 "Invalid item type observed, run fsck ASAP");
Jeff Mahoney098297b2014-04-23 10:00:36 -0400683 /*
684 * We might return -1 here as well, but it won't help as
685 * create_virtual_node() from where this operation is called
686 * from is of return type void.
687 */
688 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700691static int errcatch_check_left(struct virtual_item *vi, int free,
692 int start_skip, int end_skip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400694 reiserfs_warning(NULL, "green-16007",
695 "Invalid item type observed, run fsck ASAP");
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700696 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697}
698
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700699static int errcatch_check_right(struct virtual_item *vi, int free)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400701 reiserfs_warning(NULL, "green-16008",
702 "Invalid item type observed, run fsck ASAP");
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700703 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704}
705
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700706static int errcatch_part_size(struct virtual_item *vi, int first, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400708 reiserfs_warning(NULL, "green-16009",
709 "Invalid item type observed, run fsck ASAP");
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700710 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711}
712
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700713static int errcatch_unit_num(struct virtual_item *vi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400715 reiserfs_warning(NULL, "green-16010",
716 "Invalid item type observed, run fsck ASAP");
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700717 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718}
719
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700720static void errcatch_print_vi(struct virtual_item *vi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721{
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400722 reiserfs_warning(NULL, "green-16011",
723 "Invalid item type observed, run fsck ASAP");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724}
725
726static struct item_operations errcatch_ops = {
Kees Cook7fe6a422017-05-08 15:56:08 -0700727 .bytes_number = errcatch_bytes_number,
728 .decrement_key = errcatch_decrement_key,
729 .is_left_mergeable = errcatch_is_left_mergeable,
730 .print_item = errcatch_print_item,
731 .check_item = errcatch_check_item,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Kees Cook7fe6a422017-05-08 15:56:08 -0700733 .create_vi = errcatch_create_vi,
734 .check_left = errcatch_check_left,
735 .check_right = errcatch_check_right,
736 .part_size = errcatch_part_size,
737 .unit_num = errcatch_unit_num,
738 .print_vi = errcatch_print_vi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739};
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741#if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
Jeff Mahoney7fa94c82005-07-12 19:19:30 -0400742#error Item types must use disk-format assigned values.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743#endif
744
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700745struct item_operations *item_ops[TYPE_ANY + 1] = {
746 &stat_data_ops,
747 &indirect_ops,
748 &direct_ops,
749 &direntry_ops,
750 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
751 &errcatch_ops /* This is to catch errors with invalid type (15th entry for TYPE_ANY) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752};