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)(~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, "reiserfs-16100",
  83. "STATDATA, index %d, type 0x%x, %h",
  84. vi->vi_index, vi->vi_type, vi->vi_ih);
  85. }
  86. static struct item_operations stat_data_ops = {
  87. .bytes_number = sd_bytes_number,
  88. .decrement_key = sd_decrement_key,
  89. .is_left_mergeable = sd_is_left_mergeable,
  90. .print_item = sd_print_item,
  91. .check_item = sd_check_item,
  92. .create_vi = sd_create_vi,
  93. .check_left = sd_check_left,
  94. .check_right = sd_check_right,
  95. .part_size = sd_part_size,
  96. .unit_num = sd_unit_num,
  97. .print_vi = sd_print_vi
  98. };
  99. //////////////////////////////////////////////////////////////////////////////
  100. // direct item functions
  101. //
  102. static int direct_bytes_number(struct item_head *ih, int block_size)
  103. {
  104. return ih_item_len(ih);
  105. }
  106. // FIXME: this should probably switch to indirect as well
  107. static void direct_decrement_key(struct cpu_key *key)
  108. {
  109. cpu_key_k_offset_dec(key);
  110. if (cpu_key_k_offset(key) == 0)
  111. set_cpu_key_k_type(key, TYPE_STAT_DATA);
  112. }
  113. static int direct_is_left_mergeable(struct reiserfs_key *key,
  114. 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, int insert_size)
  135. {
  136. vi->vi_index = TYPE_DIRECT;
  137. //vi->vi_type |= VI_TYPE_DIRECT;
  138. return 0;
  139. }
  140. static int direct_check_left(struct virtual_item *vi, int free,
  141. int start_skip, int end_skip)
  142. {
  143. int bytes;
  144. bytes = free - free % 8;
  145. return bytes ? : -1;
  146. }
  147. static int direct_check_right(struct virtual_item *vi, int free)
  148. {
  149. return direct_check_left(vi, free, 0, 0);
  150. }
  151. static int direct_part_size(struct virtual_item *vi, int first, int count)
  152. {
  153. return count;
  154. }
  155. static int direct_unit_num(struct virtual_item *vi)
  156. {
  157. return vi->vi_item_len - IH_SIZE;
  158. }
  159. static void direct_print_vi(struct virtual_item *vi)
  160. {
  161. reiserfs_warning(NULL, "reiserfs-16101",
  162. "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, "reiserfs-16102", "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, "reiserfs-16103",
  284. "INDIRECT, index %d, type 0x%x, %h",
  285. vi->vi_index, vi->vi_type, vi->vi_ih);
  286. }
  287. static struct item_operations indirect_ops = {
  288. .bytes_number = indirect_bytes_number,
  289. .decrement_key = indirect_decrement_key,
  290. .is_left_mergeable = indirect_is_left_mergeable,
  291. .print_item = indirect_print_item,
  292. .check_item = indirect_check_item,
  293. .create_vi = indirect_create_vi,
  294. .check_left = indirect_check_left,
  295. .check_right = indirect_check_right,
  296. .part_size = indirect_part_size,
  297. .unit_num = indirect_unit_num,
  298. .print_vi = indirect_print_vi
  299. };
  300. //////////////////////////////////////////////////////////////////////////////
  301. // direntry functions
  302. //
  303. static int direntry_bytes_number(struct item_head *ih, int block_size)
  304. {
  305. reiserfs_warning(NULL, "vs-16090",
  306. "bytes number is asked for direntry");
  307. return 0;
  308. }
  309. static void direntry_decrement_key(struct cpu_key *key)
  310. {
  311. cpu_key_k_offset_dec(key);
  312. if (cpu_key_k_offset(key) == 0)
  313. set_cpu_key_k_type(key, TYPE_STAT_DATA);
  314. }
  315. static int direntry_is_left_mergeable(struct reiserfs_key *key,
  316. unsigned long bsize)
  317. {
  318. if (le32_to_cpu(key->u.k_offset_v1.k_offset) == DOT_OFFSET)
  319. return 0;
  320. return 1;
  321. }
  322. static void direntry_print_item(struct item_head *ih, char *item)
  323. {
  324. int i;
  325. int namelen;
  326. struct reiserfs_de_head *deh;
  327. char *name;
  328. static char namebuf[80];
  329. printk("\n # %-15s%-30s%-15s%-15s%-15s\n", "Name",
  330. "Key of pointed object", "Hash", "Gen number", "Status");
  331. deh = (struct reiserfs_de_head *)item;
  332. for (i = 0; i < I_ENTRY_COUNT(ih); i++, deh++) {
  333. namelen =
  334. (i ? (deh_location(deh - 1)) : ih_item_len(ih)) -
  335. deh_location(deh);
  336. name = item + deh_location(deh);
  337. if (name[namelen - 1] == 0)
  338. namelen = strlen(name);
  339. namebuf[0] = '"';
  340. if (namelen > sizeof(namebuf) - 3) {
  341. strncpy(namebuf + 1, name, sizeof(namebuf) - 3);
  342. namebuf[sizeof(namebuf) - 2] = '"';
  343. namebuf[sizeof(namebuf) - 1] = 0;
  344. } else {
  345. memcpy(namebuf + 1, name, namelen);
  346. namebuf[namelen + 1] = '"';
  347. namebuf[namelen + 2] = 0;
  348. }
  349. printk("%d: %-15s%-15d%-15d%-15Ld%-15Ld(%s)\n",
  350. i, namebuf,
  351. deh_dir_id(deh), deh_objectid(deh),
  352. GET_HASH_VALUE(deh_offset(deh)),
  353. GET_GENERATION_NUMBER((deh_offset(deh))),
  354. (de_hidden(deh)) ? "HIDDEN" : "VISIBLE");
  355. }
  356. }
  357. static void direntry_check_item(struct item_head *ih, char *item)
  358. {
  359. int i;
  360. struct reiserfs_de_head *deh;
  361. // FIXME: type something here!
  362. deh = (struct reiserfs_de_head *)item;
  363. for (i = 0; i < I_ENTRY_COUNT(ih); i++, deh++) {
  364. ;
  365. }
  366. }
  367. #define DIRENTRY_VI_FIRST_DIRENTRY_ITEM 1
  368. /*
  369. * function returns old entry number in directory item in real node
  370. * using new entry number in virtual item in virtual node */
  371. static inline int old_entry_num(int is_affected, int virtual_entry_num,
  372. int pos_in_item, int mode)
  373. {
  374. if (mode == M_INSERT || mode == M_DELETE)
  375. return virtual_entry_num;
  376. if (!is_affected)
  377. /* cut or paste is applied to another item */
  378. return virtual_entry_num;
  379. if (virtual_entry_num < pos_in_item)
  380. return virtual_entry_num;
  381. if (mode == M_CUT)
  382. return virtual_entry_num + 1;
  383. RFALSE(mode != M_PASTE || virtual_entry_num == 0,
  384. "vs-8015: old_entry_num: mode must be M_PASTE (mode = \'%c\'",
  385. mode);
  386. return virtual_entry_num - 1;
  387. }
  388. /* Create an array of sizes of directory entries for virtual
  389. item. Return space used by an item. FIXME: no control over
  390. consuming of space used by this item handler */
  391. static int direntry_create_vi(struct virtual_node *vn,
  392. struct virtual_item *vi,
  393. int is_affected, int insert_size)
  394. {
  395. struct direntry_uarea *dir_u = vi->vi_uarea;
  396. int i, j;
  397. int size = sizeof(struct direntry_uarea);
  398. struct reiserfs_de_head *deh;
  399. vi->vi_index = TYPE_DIRENTRY;
  400. BUG_ON(!(vi->vi_ih) || !vi->vi_item);
  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. BUG_ON(entries == dir_u->entry_count);
  479. /* "." and ".." can not be separated from each other */
  480. if ((dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM)
  481. && entries > dir_u->entry_count - 2)
  482. entries = dir_u->entry_count - 2;
  483. return entries ? : -1;
  484. }
  485. /* sum of entry sizes between from-th and to-th entries including both edges */
  486. static int direntry_part_size(struct virtual_item *vi, int first, int count)
  487. {
  488. int i, retval;
  489. int from, to;
  490. struct direntry_uarea *dir_u = vi->vi_uarea;
  491. retval = 0;
  492. if (first == 0)
  493. from = 0;
  494. else
  495. from = dir_u->entry_count - count;
  496. to = from + count - 1;
  497. for (i = from; i <= to; i++)
  498. retval += dir_u->entry_sizes[i];
  499. return retval;
  500. }
  501. static int direntry_unit_num(struct virtual_item *vi)
  502. {
  503. struct direntry_uarea *dir_u = vi->vi_uarea;
  504. return dir_u->entry_count;
  505. }
  506. static void direntry_print_vi(struct virtual_item *vi)
  507. {
  508. int i;
  509. struct direntry_uarea *dir_u = vi->vi_uarea;
  510. reiserfs_warning(NULL, "reiserfs-16104",
  511. "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, "green-16001",
  537. "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, "green-16002",
  543. "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, "green-16003",
  549. "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, "green-16004",
  555. "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, "green-16005",
  560. "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, "green-16006",
  567. "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, "green-16007",
  575. "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, "green-16008",
  581. "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, "green-16009",
  587. "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, "green-16010",
  593. "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, "green-16011",
  599. "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. };