item_ops.c 19 KB

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