item_ops.c 18 KB

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