item_ops.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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), sd_v1_first_direct_byte(sd),
  40. print_time( sd_v1_mtime(sd) ) );
  41. } else {
  42. struct stat_data * sd = (struct stat_data *)item;
  43. printk ("\t0%-6o | %6Lu | %2u | %d | %s\n", sd_v2_mode(sd),
  44. (unsigned long long)sd_v2_size(sd), sd_v2_nlink(sd),
  45. sd_v2_rdev(sd), print_time(sd_v2_mtime(sd)));
  46. }
  47. }
  48. static void sd_check_item (struct item_head * ih, char * item)
  49. {
  50. // FIXME: type something here!
  51. }
  52. static int sd_create_vi (struct virtual_node * vn,
  53. struct virtual_item * vi,
  54. int is_affected,
  55. 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, unsigned long bsize)
  115. {
  116. int version = le_key_version (key);
  117. return ((le_key_k_offset (version, key) & (bsize - 1)) != 1);
  118. }
  119. static void direct_print_item (struct item_head * ih, char * item)
  120. {
  121. int j = 0;
  122. // return;
  123. printk ("\"");
  124. while (j < ih_item_len(ih))
  125. printk ("%c", item[j++]);
  126. printk ("\"\n");
  127. }
  128. static void direct_check_item (struct item_head * ih, char * item)
  129. {
  130. // FIXME: type something here!
  131. }
  132. static int direct_create_vi (struct virtual_node * vn,
  133. struct virtual_item * vi,
  134. int is_affected,
  135. 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, unsigned long bsize)
  194. {
  195. int version = le_key_version (key);
  196. return (le_key_k_offset (version, key) != 1);
  197. }
  198. // printing of indirect item
  199. static void start_new_sequence (__u32 * start, int * len, __u32 new)
  200. {
  201. *start = new;
  202. *len = 1;
  203. }
  204. static int sequence_finished (__u32 start, int * len, __u32 new)
  205. {
  206. if (start == INT_MAX)
  207. return 1;
  208. if (start == 0 && new == 0) {
  209. (*len) ++;
  210. return 0;
  211. }
  212. if (start != 0 && (start + *len) == new) {
  213. (*len) ++;
  214. return 0;
  215. }
  216. return 1;
  217. }
  218. static void print_sequence (__u32 start, int len)
  219. {
  220. if (start == INT_MAX)
  221. return;
  222. if (len == 1)
  223. printk (" %d", start);
  224. else
  225. printk (" %d(%d)", start, len);
  226. }
  227. static void indirect_print_item (struct item_head * ih, char * item)
  228. {
  229. int j;
  230. __le32 * unp;
  231. __u32 prev = INT_MAX;
  232. int num;
  233. unp = (__le32 *)item;
  234. if (ih_item_len(ih) % UNFM_P_SIZE)
  235. reiserfs_warning (NULL, "indirect_print_item: invalid item len");
  236. printk ("%d pointers\n[ ", (int)I_UNFM_NUM (ih));
  237. for (j = 0; j < I_UNFM_NUM (ih); j ++) {
  238. if (sequence_finished (prev, &num, get_block_num(unp, j))) {
  239. print_sequence (prev, num);
  240. start_new_sequence (&prev, &num, get_block_num(unp, j));
  241. }
  242. }
  243. print_sequence (prev, num);
  244. printk ("]\n");
  245. }
  246. static void indirect_check_item (struct item_head * ih, char * item)
  247. {
  248. // FIXME: type something here!
  249. }
  250. static int indirect_create_vi (struct virtual_node * vn,
  251. struct virtual_item * vi,
  252. int is_affected,
  253. 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, unsigned long bsize)
  315. {
  316. if (le32_to_cpu (key->u.k_offset_v1.k_offset) == DOT_OFFSET)
  317. return 0;
  318. return 1;
  319. }
  320. static void direntry_print_item (struct item_head * ih, char * item)
  321. {
  322. int i;
  323. int namelen;
  324. struct reiserfs_de_head * deh;
  325. char * name;
  326. static char namebuf [80];
  327. printk ("\n # %-15s%-30s%-15s%-15s%-15s\n", "Name", "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 = (i ? (deh_location(deh - 1)) : ih_item_len(ih)) - deh_location(deh);
  331. name = item + deh_location(deh);
  332. if (name[namelen-1] == 0)
  333. namelen = strlen (name);
  334. namebuf[0] = '"';
  335. if (namelen > sizeof (namebuf) - 3) {
  336. strncpy (namebuf + 1, name, sizeof (namebuf) - 3);
  337. namebuf[sizeof (namebuf) - 2] = '"';
  338. namebuf[sizeof (namebuf) - 1] = 0;
  339. } else {
  340. memcpy (namebuf + 1, name, namelen);
  341. namebuf[namelen + 1] = '"';
  342. namebuf[namelen + 2] = 0;
  343. }
  344. printk ("%d: %-15s%-15d%-15d%-15Ld%-15Ld(%s)\n",
  345. i, namebuf,
  346. deh_dir_id(deh), deh_objectid(deh),
  347. GET_HASH_VALUE (deh_offset (deh)), GET_GENERATION_NUMBER ((deh_offset (deh))),
  348. (de_hidden (deh)) ? "HIDDEN" : "VISIBLE");
  349. }
  350. }
  351. static void direntry_check_item (struct item_head * ih, char * item)
  352. {
  353. int i;
  354. struct reiserfs_de_head * deh;
  355. // FIXME: type something here!
  356. deh = (struct reiserfs_de_head *)item;
  357. for (i = 0; i < I_ENTRY_COUNT (ih); i ++, deh ++) {
  358. ;
  359. }
  360. }
  361. #define DIRENTRY_VI_FIRST_DIRENTRY_ITEM 1
  362. /*
  363. * function returns old entry number in directory item in real node
  364. * using new entry number in virtual item in virtual node */
  365. static inline int old_entry_num (int is_affected, int virtual_entry_num, int pos_in_item, int mode)
  366. {
  367. if ( mode == M_INSERT || mode == M_DELETE)
  368. return virtual_entry_num;
  369. if (!is_affected)
  370. /* cut or paste is applied to another item */
  371. return virtual_entry_num;
  372. if (virtual_entry_num < pos_in_item)
  373. return virtual_entry_num;
  374. if (mode == M_CUT)
  375. return virtual_entry_num + 1;
  376. RFALSE( mode != M_PASTE || virtual_entry_num == 0,
  377. "vs-8015: old_entry_num: mode must be M_PASTE (mode = \'%c\'", mode);
  378. return virtual_entry_num - 1;
  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. static int direntry_create_vi (struct virtual_node * vn,
  384. struct virtual_item * vi,
  385. int is_affected,
  386. 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. if (!(vi->vi_ih) || !vi->vi_item)
  394. BUG ();
  395. dir_u->flags = 0;
  396. if (le_ih_k_offset (vi->vi_ih) == DOT_OFFSET)
  397. dir_u->flags |= DIRENTRY_VI_FIRST_DIRENTRY_ITEM;
  398. deh = (struct reiserfs_de_head *)(vi->vi_item);
  399. /* virtual directory item have this amount of entry after */
  400. dir_u->entry_count = ih_entry_count (vi->vi_ih) +
  401. ((is_affected) ? ((vn->vn_mode == M_CUT) ? -1 :
  402. (vn->vn_mode == M_PASTE ? 1 : 0)) : 0);
  403. for (i = 0; i < dir_u->entry_count; i ++) {
  404. j = old_entry_num (is_affected, i, vn->vn_pos_in_item, vn->vn_mode);
  405. dir_u->entry_sizes[i] = (j ? deh_location( &(deh[j - 1]) ) :
  406. 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 && (vn->vn_mode == M_PASTE || vn->vn_mode == M_CUT)) ? insert_size : 0) ) {
  422. reiserfs_panic (NULL, "vs-8025: set_entry_sizes: (mode==%c, insert_size==%d), invalid length of directory item",
  423. vn->vn_mode, insert_size);
  424. }
  425. }
  426. #endif
  427. return size;
  428. }
  429. //
  430. // return number of entries which may fit into specified amount of
  431. // free space, or -1 if free space is not enough even for 1 entry
  432. //
  433. static int direntry_check_left (struct virtual_item * vi, int free,
  434. int start_skip, int end_skip)
  435. {
  436. int i;
  437. int entries = 0;
  438. struct direntry_uarea * dir_u = vi->vi_uarea;
  439. for (i = start_skip; i < dir_u->entry_count - end_skip; i ++) {
  440. if (dir_u->entry_sizes[i] > free)
  441. /* i-th entry doesn't fit into the remaining free space */
  442. break;
  443. free -= dir_u->entry_sizes[i];
  444. entries ++;
  445. }
  446. if (entries == dir_u->entry_count) {
  447. reiserfs_panic (NULL, "free space %d, entry_count %d\n", free, dir_u->entry_count);
  448. }
  449. /* "." and ".." can not be separated from each other */
  450. if (start_skip == 0 && (dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM) && entries < 2)
  451. entries = 0;
  452. return entries ?: -1;
  453. }
  454. static int direntry_check_right (struct virtual_item * vi, int free)
  455. {
  456. int i;
  457. int entries = 0;
  458. struct direntry_uarea * dir_u = vi->vi_uarea;
  459. for (i = dir_u->entry_count - 1; i >= 0; i --) {
  460. if (dir_u->entry_sizes[i] > free)
  461. /* i-th entry doesn't fit into the remaining free space */
  462. break;
  463. free -= dir_u->entry_sizes[i];
  464. entries ++;
  465. }
  466. if (entries == dir_u->entry_count)
  467. BUG ();
  468. /* "." and ".." can not be separated from each other */
  469. if ((dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM) && entries > dir_u->entry_count - 2)
  470. entries = dir_u->entry_count - 2;
  471. return entries ?: -1;
  472. }
  473. /* sum of entry sizes between from-th and to-th entries including both edges */
  474. static int direntry_part_size (struct virtual_item * vi, int first, int count)
  475. {
  476. int i, retval;
  477. int from, to;
  478. struct direntry_uarea * dir_u = vi->vi_uarea;
  479. retval = 0;
  480. if (first == 0)
  481. from = 0;
  482. else
  483. from = dir_u->entry_count - count;
  484. to = from + count - 1;
  485. for (i = from; i <= to; i ++)
  486. retval += dir_u->entry_sizes[i];
  487. return retval;
  488. }
  489. static int direntry_unit_num (struct virtual_item * vi)
  490. {
  491. struct direntry_uarea * dir_u = vi->vi_uarea;
  492. return dir_u->entry_count;
  493. }
  494. static void direntry_print_vi (struct virtual_item * vi)
  495. {
  496. int i;
  497. struct direntry_uarea * dir_u = vi->vi_uarea;
  498. reiserfs_warning (NULL, "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. //////////////////////////////////////////////////////////////////////////////
  519. // Error catching functions to catch errors caused by incorrect item types.
  520. //
  521. static int errcatch_bytes_number (struct item_head * ih, int block_size)
  522. {
  523. reiserfs_warning (NULL, "green-16001: Invalid item type observed, run fsck ASAP");
  524. return 0;
  525. }
  526. static void errcatch_decrement_key (struct cpu_key * key)
  527. {
  528. reiserfs_warning (NULL, "green-16002: Invalid item type observed, run fsck ASAP");
  529. }
  530. static int errcatch_is_left_mergeable (struct reiserfs_key * key, unsigned long bsize)
  531. {
  532. reiserfs_warning (NULL, "green-16003: Invalid item type observed, run fsck ASAP");
  533. return 0;
  534. }
  535. static void errcatch_print_item (struct item_head * ih, char * item)
  536. {
  537. reiserfs_warning (NULL, "green-16004: Invalid item type observed, run fsck ASAP");
  538. }
  539. static void errcatch_check_item (struct item_head * ih, char * item)
  540. {
  541. reiserfs_warning (NULL, "green-16005: Invalid item type observed, run fsck ASAP");
  542. }
  543. static int errcatch_create_vi (struct virtual_node * vn,
  544. struct virtual_item * vi,
  545. int is_affected,
  546. int insert_size)
  547. {
  548. reiserfs_warning (NULL, "green-16006: Invalid item type observed, run fsck ASAP");
  549. return 0; // We might return -1 here as well, but it won't help as create_virtual_node() from where
  550. // this operation is called from is of return type void.
  551. }
  552. static int errcatch_check_left (struct virtual_item * vi, int free,
  553. int start_skip, int end_skip)
  554. {
  555. reiserfs_warning (NULL, "green-16007: Invalid item type observed, run fsck ASAP");
  556. return -1;
  557. }
  558. static int errcatch_check_right (struct virtual_item * vi, int free)
  559. {
  560. reiserfs_warning (NULL, "green-16008: Invalid item type observed, run fsck ASAP");
  561. return -1;
  562. }
  563. static int errcatch_part_size (struct virtual_item * vi, int first, int count)
  564. {
  565. reiserfs_warning (NULL, "green-16009: Invalid item type observed, run fsck ASAP");
  566. return 0;
  567. }
  568. static int errcatch_unit_num (struct virtual_item * vi)
  569. {
  570. reiserfs_warning (NULL, "green-16010: Invalid item type observed, run fsck ASAP");
  571. return 0;
  572. }
  573. static void errcatch_print_vi (struct virtual_item * vi)
  574. {
  575. reiserfs_warning (NULL, "green-16011: Invalid item type observed, run fsck ASAP");
  576. }
  577. static struct item_operations errcatch_ops = {
  578. errcatch_bytes_number,
  579. errcatch_decrement_key,
  580. errcatch_is_left_mergeable,
  581. errcatch_print_item,
  582. errcatch_check_item,
  583. errcatch_create_vi,
  584. errcatch_check_left,
  585. errcatch_check_right,
  586. errcatch_part_size,
  587. errcatch_unit_num,
  588. errcatch_print_vi
  589. };
  590. //////////////////////////////////////////////////////////////////////////////
  591. //
  592. //
  593. #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
  594. do not compile
  595. #endif
  596. struct item_operations * item_ops [TYPE_ANY + 1] = {
  597. &stat_data_ops,
  598. &indirect_ops,
  599. &direct_ops,
  600. &direntry_ops,
  601. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  602. &errcatch_ops /* This is to catch errors with invalid type (15th entry for TYPE_ANY) */
  603. };