item_ops.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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. namebuf[0] = '"';
  330. if (namelen > sizeof(namebuf) - 3) {
  331. strncpy(namebuf + 1, name, sizeof(namebuf) - 3);
  332. namebuf[sizeof(namebuf) - 2] = '"';
  333. namebuf[sizeof(namebuf) - 1] = 0;
  334. } else {
  335. memcpy(namebuf + 1, name, namelen);
  336. namebuf[namelen + 1] = '"';
  337. namebuf[namelen + 2] = 0;
  338. }
  339. printk("%d: %-15s%-15d%-15d%-15lld%-15lld(%s)\n",
  340. i, namebuf,
  341. deh_dir_id(deh), deh_objectid(deh),
  342. GET_HASH_VALUE(deh_offset(deh)),
  343. GET_GENERATION_NUMBER((deh_offset(deh))),
  344. (de_hidden(deh)) ? "HIDDEN" : "VISIBLE");
  345. }
  346. }
  347. static void direntry_check_item(struct item_head *ih, char *item)
  348. {
  349. int i;
  350. struct reiserfs_de_head *deh;
  351. /* unused */
  352. deh = (struct reiserfs_de_head *)item;
  353. for (i = 0; i < ih_entry_count(ih); i++, deh++) {
  354. ;
  355. }
  356. }
  357. #define DIRENTRY_VI_FIRST_DIRENTRY_ITEM 1
  358. /*
  359. * function returns old entry number in directory item in real node
  360. * using new entry number in virtual item in virtual node
  361. */
  362. static inline int old_entry_num(int is_affected, int virtual_entry_num,
  363. int pos_in_item, int mode)
  364. {
  365. if (mode == M_INSERT || mode == M_DELETE)
  366. return virtual_entry_num;
  367. if (!is_affected)
  368. /* cut or paste is applied to another item */
  369. return virtual_entry_num;
  370. if (virtual_entry_num < pos_in_item)
  371. return virtual_entry_num;
  372. if (mode == M_CUT)
  373. return virtual_entry_num + 1;
  374. RFALSE(mode != M_PASTE || virtual_entry_num == 0,
  375. "vs-8015: old_entry_num: mode must be M_PASTE (mode = \'%c\'",
  376. mode);
  377. return virtual_entry_num - 1;
  378. }
  379. /*
  380. * Create an array of sizes of directory entries for virtual
  381. * item. Return space used by an item. FIXME: no control over
  382. * consuming of space used by this item handler
  383. */
  384. static int direntry_create_vi(struct virtual_node *vn,
  385. struct virtual_item *vi,
  386. int is_affected, int insert_size)
  387. {
  388. struct direntry_uarea *dir_u = vi->vi_uarea;
  389. int i, j;
  390. int size = sizeof(struct direntry_uarea);
  391. struct reiserfs_de_head *deh;
  392. vi->vi_index = TYPE_DIRENTRY;
  393. BUG_ON(!(vi->vi_ih) || !vi->vi_item);
  394. dir_u->flags = 0;
  395. if (le_ih_k_offset(vi->vi_ih) == DOT_OFFSET)
  396. dir_u->flags |= DIRENTRY_VI_FIRST_DIRENTRY_ITEM;
  397. deh = (struct reiserfs_de_head *)(vi->vi_item);
  398. /* virtual directory item have this amount of entry after */
  399. dir_u->entry_count = ih_entry_count(vi->vi_ih) +
  400. ((is_affected) ? ((vn->vn_mode == M_CUT) ? -1 :
  401. (vn->vn_mode == M_PASTE ? 1 : 0)) : 0);
  402. for (i = 0; i < dir_u->entry_count; i++) {
  403. j = old_entry_num(is_affected, i, vn->vn_pos_in_item,
  404. vn->vn_mode);
  405. dir_u->entry_sizes[i] =
  406. (j ? deh_location(&deh[j - 1]) : ih_item_len(vi->vi_ih)) -
  407. deh_location(&deh[j]) + DEH_SIZE;
  408. }
  409. size += (dir_u->entry_count * sizeof(short));
  410. /* set size of pasted entry */
  411. if (is_affected && vn->vn_mode == M_PASTE)
  412. dir_u->entry_sizes[vn->vn_pos_in_item] = insert_size;
  413. #ifdef CONFIG_REISERFS_CHECK
  414. /* compare total size of entries with item length */
  415. {
  416. int k, l;
  417. l = 0;
  418. for (k = 0; k < dir_u->entry_count; k++)
  419. l += dir_u->entry_sizes[k];
  420. if (l + IH_SIZE != vi->vi_item_len +
  421. ((is_affected
  422. && (vn->vn_mode == M_PASTE
  423. || vn->vn_mode == M_CUT)) ? insert_size : 0)) {
  424. reiserfs_panic(NULL, "vs-8025", "(mode==%c, "
  425. "insert_size==%d), invalid length of "
  426. "directory item",
  427. vn->vn_mode, insert_size);
  428. }
  429. }
  430. #endif
  431. return size;
  432. }
  433. /*
  434. * return number of entries which may fit into specified amount of
  435. * free space, or -1 if free space is not enough even for 1 entry
  436. */
  437. static int direntry_check_left(struct virtual_item *vi, int free,
  438. int start_skip, int end_skip)
  439. {
  440. int i;
  441. int entries = 0;
  442. struct direntry_uarea *dir_u = vi->vi_uarea;
  443. for (i = start_skip; i < dir_u->entry_count - end_skip; i++) {
  444. /* i-th entry doesn't fit into the remaining free space */
  445. if (dir_u->entry_sizes[i] > free)
  446. break;
  447. free -= dir_u->entry_sizes[i];
  448. entries++;
  449. }
  450. if (entries == dir_u->entry_count) {
  451. reiserfs_panic(NULL, "item_ops-1",
  452. "free space %d, entry_count %d", free,
  453. dir_u->entry_count);
  454. }
  455. /* "." and ".." can not be separated from each other */
  456. if (start_skip == 0 && (dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM)
  457. && entries < 2)
  458. entries = 0;
  459. return entries ? : -1;
  460. }
  461. static int direntry_check_right(struct virtual_item *vi, int free)
  462. {
  463. int i;
  464. int entries = 0;
  465. struct direntry_uarea *dir_u = vi->vi_uarea;
  466. for (i = dir_u->entry_count - 1; i >= 0; i--) {
  467. /* i-th entry doesn't fit into the remaining free space */
  468. if (dir_u->entry_sizes[i] > free)
  469. break;
  470. free -= dir_u->entry_sizes[i];
  471. entries++;
  472. }
  473. BUG_ON(entries == dir_u->entry_count);
  474. /* "." and ".." can not be separated from each other */
  475. if ((dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM)
  476. && entries > dir_u->entry_count - 2)
  477. entries = dir_u->entry_count - 2;
  478. return entries ? : -1;
  479. }
  480. /* sum of entry sizes between from-th and to-th entries including both edges */
  481. static int direntry_part_size(struct virtual_item *vi, int first, int count)
  482. {
  483. int i, retval;
  484. int from, to;
  485. struct direntry_uarea *dir_u = vi->vi_uarea;
  486. retval = 0;
  487. if (first == 0)
  488. from = 0;
  489. else
  490. from = dir_u->entry_count - count;
  491. to = from + count - 1;
  492. for (i = from; i <= to; i++)
  493. retval += dir_u->entry_sizes[i];
  494. return retval;
  495. }
  496. static int direntry_unit_num(struct virtual_item *vi)
  497. {
  498. struct direntry_uarea *dir_u = vi->vi_uarea;
  499. return dir_u->entry_count;
  500. }
  501. static void direntry_print_vi(struct virtual_item *vi)
  502. {
  503. int i;
  504. struct direntry_uarea *dir_u = vi->vi_uarea;
  505. reiserfs_warning(NULL, "reiserfs-16104",
  506. "DIRENTRY, index %d, type 0x%x, %h, flags 0x%x",
  507. vi->vi_index, vi->vi_type, vi->vi_ih, dir_u->flags);
  508. printk("%d entries: ", dir_u->entry_count);
  509. for (i = 0; i < dir_u->entry_count; i++)
  510. printk("%d ", dir_u->entry_sizes[i]);
  511. printk("\n");
  512. }
  513. static struct item_operations direntry_ops = {
  514. .bytes_number = direntry_bytes_number,
  515. .decrement_key = direntry_decrement_key,
  516. .is_left_mergeable = direntry_is_left_mergeable,
  517. .print_item = direntry_print_item,
  518. .check_item = direntry_check_item,
  519. .create_vi = direntry_create_vi,
  520. .check_left = direntry_check_left,
  521. .check_right = direntry_check_right,
  522. .part_size = direntry_part_size,
  523. .unit_num = direntry_unit_num,
  524. .print_vi = direntry_print_vi
  525. };
  526. /* Error catching functions to catch errors caused by incorrect item types. */
  527. static int errcatch_bytes_number(struct item_head *ih, int block_size)
  528. {
  529. reiserfs_warning(NULL, "green-16001",
  530. "Invalid item type observed, run fsck ASAP");
  531. return 0;
  532. }
  533. static void errcatch_decrement_key(struct cpu_key *key)
  534. {
  535. reiserfs_warning(NULL, "green-16002",
  536. "Invalid item type observed, run fsck ASAP");
  537. }
  538. static int errcatch_is_left_mergeable(struct reiserfs_key *key,
  539. unsigned long bsize)
  540. {
  541. reiserfs_warning(NULL, "green-16003",
  542. "Invalid item type observed, run fsck ASAP");
  543. return 0;
  544. }
  545. static void errcatch_print_item(struct item_head *ih, char *item)
  546. {
  547. reiserfs_warning(NULL, "green-16004",
  548. "Invalid item type observed, run fsck ASAP");
  549. }
  550. static void errcatch_check_item(struct item_head *ih, char *item)
  551. {
  552. reiserfs_warning(NULL, "green-16005",
  553. "Invalid item type observed, run fsck ASAP");
  554. }
  555. static int errcatch_create_vi(struct virtual_node *vn,
  556. struct virtual_item *vi,
  557. int is_affected, int insert_size)
  558. {
  559. reiserfs_warning(NULL, "green-16006",
  560. "Invalid item type observed, run fsck ASAP");
  561. /*
  562. * We might return -1 here as well, but it won't help as
  563. * create_virtual_node() from where this operation is called
  564. * from is of return type void.
  565. */
  566. return 0;
  567. }
  568. static int errcatch_check_left(struct virtual_item *vi, int free,
  569. int start_skip, int end_skip)
  570. {
  571. reiserfs_warning(NULL, "green-16007",
  572. "Invalid item type observed, run fsck ASAP");
  573. return -1;
  574. }
  575. static int errcatch_check_right(struct virtual_item *vi, int free)
  576. {
  577. reiserfs_warning(NULL, "green-16008",
  578. "Invalid item type observed, run fsck ASAP");
  579. return -1;
  580. }
  581. static int errcatch_part_size(struct virtual_item *vi, int first, int count)
  582. {
  583. reiserfs_warning(NULL, "green-16009",
  584. "Invalid item type observed, run fsck ASAP");
  585. return 0;
  586. }
  587. static int errcatch_unit_num(struct virtual_item *vi)
  588. {
  589. reiserfs_warning(NULL, "green-16010",
  590. "Invalid item type observed, run fsck ASAP");
  591. return 0;
  592. }
  593. static void errcatch_print_vi(struct virtual_item *vi)
  594. {
  595. reiserfs_warning(NULL, "green-16011",
  596. "Invalid item type observed, run fsck ASAP");
  597. }
  598. static struct item_operations errcatch_ops = {
  599. .bytes_number = errcatch_bytes_number,
  600. .decrement_key = errcatch_decrement_key,
  601. .is_left_mergeable = errcatch_is_left_mergeable,
  602. .print_item = errcatch_print_item,
  603. .check_item = errcatch_check_item,
  604. .create_vi = errcatch_create_vi,
  605. .check_left = errcatch_check_left,
  606. .check_right = errcatch_check_right,
  607. .part_size = errcatch_part_size,
  608. .unit_num = errcatch_unit_num,
  609. .print_vi = errcatch_print_vi
  610. };
  611. #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
  612. #error Item types must use disk-format assigned values.
  613. #endif
  614. struct item_operations *item_ops[TYPE_ANY + 1] = {
  615. &stat_data_ops,
  616. &indirect_ops,
  617. &direct_ops,
  618. &direntry_ops,
  619. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  620. &errcatch_ops /* This is to catch errors with invalid type (15th entry for TYPE_ANY) */
  621. };