item_ops.c 19 KB

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