18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
38c2ecf20Sopenharmony_ci */
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/time.h>
68c2ecf20Sopenharmony_ci#include "reiserfs.h"
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci/*
98c2ecf20Sopenharmony_ci * this contains item handlers for old item types: sd, direct,
108c2ecf20Sopenharmony_ci * indirect, directory
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/*
148c2ecf20Sopenharmony_ci * and where are the comments? how about saying where we can find an
158c2ecf20Sopenharmony_ci * explanation of each item handler method? -Hans
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/* stat data functions */
198c2ecf20Sopenharmony_cistatic int sd_bytes_number(struct item_head *ih, int block_size)
208c2ecf20Sopenharmony_ci{
218c2ecf20Sopenharmony_ci	return 0;
228c2ecf20Sopenharmony_ci}
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistatic void sd_decrement_key(struct cpu_key *key)
258c2ecf20Sopenharmony_ci{
268c2ecf20Sopenharmony_ci	key->on_disk_key.k_objectid--;
278c2ecf20Sopenharmony_ci	set_cpu_key_k_type(key, TYPE_ANY);
288c2ecf20Sopenharmony_ci	set_cpu_key_k_offset(key, (loff_t)(~0ULL >> 1));
298c2ecf20Sopenharmony_ci}
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic int sd_is_left_mergeable(struct reiserfs_key *key, unsigned long bsize)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	return 0;
348c2ecf20Sopenharmony_ci}
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistatic void sd_print_item(struct item_head *ih, char *item)
378c2ecf20Sopenharmony_ci{
388c2ecf20Sopenharmony_ci	printk("\tmode | size | nlinks | first direct | mtime\n");
398c2ecf20Sopenharmony_ci	if (stat_data_v1(ih)) {
408c2ecf20Sopenharmony_ci		struct stat_data_v1 *sd = (struct stat_data_v1 *)item;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci		printk("\t0%-6o | %6u | %2u | %d | %u\n", sd_v1_mode(sd),
438c2ecf20Sopenharmony_ci		       sd_v1_size(sd), sd_v1_nlink(sd),
448c2ecf20Sopenharmony_ci		       sd_v1_first_direct_byte(sd),
458c2ecf20Sopenharmony_ci		       sd_v1_mtime(sd));
468c2ecf20Sopenharmony_ci	} else {
478c2ecf20Sopenharmony_ci		struct stat_data *sd = (struct stat_data *)item;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci		printk("\t0%-6o | %6llu | %2u | %d | %u\n", sd_v2_mode(sd),
508c2ecf20Sopenharmony_ci		       (unsigned long long)sd_v2_size(sd), sd_v2_nlink(sd),
518c2ecf20Sopenharmony_ci		       sd_v2_rdev(sd), sd_v2_mtime(sd));
528c2ecf20Sopenharmony_ci	}
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistatic void sd_check_item(struct item_head *ih, char *item)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	/* unused */
588c2ecf20Sopenharmony_ci}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic int sd_create_vi(struct virtual_node *vn,
618c2ecf20Sopenharmony_ci			struct virtual_item *vi,
628c2ecf20Sopenharmony_ci			int is_affected, int insert_size)
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	vi->vi_index = TYPE_STAT_DATA;
658c2ecf20Sopenharmony_ci	return 0;
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistatic int sd_check_left(struct virtual_item *vi, int free,
698c2ecf20Sopenharmony_ci			 int start_skip, int end_skip)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	BUG_ON(start_skip || end_skip);
728c2ecf20Sopenharmony_ci	return -1;
738c2ecf20Sopenharmony_ci}
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistatic int sd_check_right(struct virtual_item *vi, int free)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	return -1;
788c2ecf20Sopenharmony_ci}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic int sd_part_size(struct virtual_item *vi, int first, int count)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	BUG_ON(count);
838c2ecf20Sopenharmony_ci	return 0;
848c2ecf20Sopenharmony_ci}
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cistatic int sd_unit_num(struct virtual_item *vi)
878c2ecf20Sopenharmony_ci{
888c2ecf20Sopenharmony_ci	return vi->vi_item_len - IH_SIZE;
898c2ecf20Sopenharmony_ci}
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_cistatic void sd_print_vi(struct virtual_item *vi)
928c2ecf20Sopenharmony_ci{
938c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "reiserfs-16100",
948c2ecf20Sopenharmony_ci			 "STATDATA, index %d, type 0x%x, %h",
958c2ecf20Sopenharmony_ci			 vi->vi_index, vi->vi_type, vi->vi_ih);
968c2ecf20Sopenharmony_ci}
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistatic struct item_operations stat_data_ops = {
998c2ecf20Sopenharmony_ci	.bytes_number = sd_bytes_number,
1008c2ecf20Sopenharmony_ci	.decrement_key = sd_decrement_key,
1018c2ecf20Sopenharmony_ci	.is_left_mergeable = sd_is_left_mergeable,
1028c2ecf20Sopenharmony_ci	.print_item = sd_print_item,
1038c2ecf20Sopenharmony_ci	.check_item = sd_check_item,
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	.create_vi = sd_create_vi,
1068c2ecf20Sopenharmony_ci	.check_left = sd_check_left,
1078c2ecf20Sopenharmony_ci	.check_right = sd_check_right,
1088c2ecf20Sopenharmony_ci	.part_size = sd_part_size,
1098c2ecf20Sopenharmony_ci	.unit_num = sd_unit_num,
1108c2ecf20Sopenharmony_ci	.print_vi = sd_print_vi
1118c2ecf20Sopenharmony_ci};
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/* direct item functions */
1148c2ecf20Sopenharmony_cistatic int direct_bytes_number(struct item_head *ih, int block_size)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci	return ih_item_len(ih);
1178c2ecf20Sopenharmony_ci}
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci/* FIXME: this should probably switch to indirect as well */
1208c2ecf20Sopenharmony_cistatic void direct_decrement_key(struct cpu_key *key)
1218c2ecf20Sopenharmony_ci{
1228c2ecf20Sopenharmony_ci	cpu_key_k_offset_dec(key);
1238c2ecf20Sopenharmony_ci	if (cpu_key_k_offset(key) == 0)
1248c2ecf20Sopenharmony_ci		set_cpu_key_k_type(key, TYPE_STAT_DATA);
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistatic int direct_is_left_mergeable(struct reiserfs_key *key,
1288c2ecf20Sopenharmony_ci				    unsigned long bsize)
1298c2ecf20Sopenharmony_ci{
1308c2ecf20Sopenharmony_ci	int version = le_key_version(key);
1318c2ecf20Sopenharmony_ci	return ((le_key_k_offset(version, key) & (bsize - 1)) != 1);
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistatic void direct_print_item(struct item_head *ih, char *item)
1358c2ecf20Sopenharmony_ci{
1368c2ecf20Sopenharmony_ci	int j = 0;
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci/*    return; */
1398c2ecf20Sopenharmony_ci	printk("\"");
1408c2ecf20Sopenharmony_ci	while (j < ih_item_len(ih))
1418c2ecf20Sopenharmony_ci		printk("%c", item[j++]);
1428c2ecf20Sopenharmony_ci	printk("\"\n");
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistatic void direct_check_item(struct item_head *ih, char *item)
1468c2ecf20Sopenharmony_ci{
1478c2ecf20Sopenharmony_ci	/* unused */
1488c2ecf20Sopenharmony_ci}
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_cistatic int direct_create_vi(struct virtual_node *vn,
1518c2ecf20Sopenharmony_ci			    struct virtual_item *vi,
1528c2ecf20Sopenharmony_ci			    int is_affected, int insert_size)
1538c2ecf20Sopenharmony_ci{
1548c2ecf20Sopenharmony_ci	vi->vi_index = TYPE_DIRECT;
1558c2ecf20Sopenharmony_ci	return 0;
1568c2ecf20Sopenharmony_ci}
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_cistatic int direct_check_left(struct virtual_item *vi, int free,
1598c2ecf20Sopenharmony_ci			     int start_skip, int end_skip)
1608c2ecf20Sopenharmony_ci{
1618c2ecf20Sopenharmony_ci	int bytes;
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	bytes = free - free % 8;
1648c2ecf20Sopenharmony_ci	return bytes ? : -1;
1658c2ecf20Sopenharmony_ci}
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_cistatic int direct_check_right(struct virtual_item *vi, int free)
1688c2ecf20Sopenharmony_ci{
1698c2ecf20Sopenharmony_ci	return direct_check_left(vi, free, 0, 0);
1708c2ecf20Sopenharmony_ci}
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_cistatic int direct_part_size(struct virtual_item *vi, int first, int count)
1738c2ecf20Sopenharmony_ci{
1748c2ecf20Sopenharmony_ci	return count;
1758c2ecf20Sopenharmony_ci}
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_cistatic int direct_unit_num(struct virtual_item *vi)
1788c2ecf20Sopenharmony_ci{
1798c2ecf20Sopenharmony_ci	return vi->vi_item_len - IH_SIZE;
1808c2ecf20Sopenharmony_ci}
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_cistatic void direct_print_vi(struct virtual_item *vi)
1838c2ecf20Sopenharmony_ci{
1848c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "reiserfs-16101",
1858c2ecf20Sopenharmony_ci			 "DIRECT, index %d, type 0x%x, %h",
1868c2ecf20Sopenharmony_ci			 vi->vi_index, vi->vi_type, vi->vi_ih);
1878c2ecf20Sopenharmony_ci}
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cistatic struct item_operations direct_ops = {
1908c2ecf20Sopenharmony_ci	.bytes_number = direct_bytes_number,
1918c2ecf20Sopenharmony_ci	.decrement_key = direct_decrement_key,
1928c2ecf20Sopenharmony_ci	.is_left_mergeable = direct_is_left_mergeable,
1938c2ecf20Sopenharmony_ci	.print_item = direct_print_item,
1948c2ecf20Sopenharmony_ci	.check_item = direct_check_item,
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	.create_vi = direct_create_vi,
1978c2ecf20Sopenharmony_ci	.check_left = direct_check_left,
1988c2ecf20Sopenharmony_ci	.check_right = direct_check_right,
1998c2ecf20Sopenharmony_ci	.part_size = direct_part_size,
2008c2ecf20Sopenharmony_ci	.unit_num = direct_unit_num,
2018c2ecf20Sopenharmony_ci	.print_vi = direct_print_vi
2028c2ecf20Sopenharmony_ci};
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci/* indirect item functions */
2058c2ecf20Sopenharmony_cistatic int indirect_bytes_number(struct item_head *ih, int block_size)
2068c2ecf20Sopenharmony_ci{
2078c2ecf20Sopenharmony_ci	return ih_item_len(ih) / UNFM_P_SIZE * block_size;
2088c2ecf20Sopenharmony_ci}
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci/* decrease offset, if it becomes 0, change type to stat data */
2118c2ecf20Sopenharmony_cistatic void indirect_decrement_key(struct cpu_key *key)
2128c2ecf20Sopenharmony_ci{
2138c2ecf20Sopenharmony_ci	cpu_key_k_offset_dec(key);
2148c2ecf20Sopenharmony_ci	if (cpu_key_k_offset(key) == 0)
2158c2ecf20Sopenharmony_ci		set_cpu_key_k_type(key, TYPE_STAT_DATA);
2168c2ecf20Sopenharmony_ci}
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci/* if it is not first item of the body, then it is mergeable */
2198c2ecf20Sopenharmony_cistatic int indirect_is_left_mergeable(struct reiserfs_key *key,
2208c2ecf20Sopenharmony_ci				      unsigned long bsize)
2218c2ecf20Sopenharmony_ci{
2228c2ecf20Sopenharmony_ci	int version = le_key_version(key);
2238c2ecf20Sopenharmony_ci	return (le_key_k_offset(version, key) != 1);
2248c2ecf20Sopenharmony_ci}
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci/* printing of indirect item */
2278c2ecf20Sopenharmony_cistatic void start_new_sequence(__u32 * start, int *len, __u32 new)
2288c2ecf20Sopenharmony_ci{
2298c2ecf20Sopenharmony_ci	*start = new;
2308c2ecf20Sopenharmony_ci	*len = 1;
2318c2ecf20Sopenharmony_ci}
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_cistatic int sequence_finished(__u32 start, int *len, __u32 new)
2348c2ecf20Sopenharmony_ci{
2358c2ecf20Sopenharmony_ci	if (start == INT_MAX)
2368c2ecf20Sopenharmony_ci		return 1;
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	if (start == 0 && new == 0) {
2398c2ecf20Sopenharmony_ci		(*len)++;
2408c2ecf20Sopenharmony_ci		return 0;
2418c2ecf20Sopenharmony_ci	}
2428c2ecf20Sopenharmony_ci	if (start != 0 && (start + *len) == new) {
2438c2ecf20Sopenharmony_ci		(*len)++;
2448c2ecf20Sopenharmony_ci		return 0;
2458c2ecf20Sopenharmony_ci	}
2468c2ecf20Sopenharmony_ci	return 1;
2478c2ecf20Sopenharmony_ci}
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_cistatic void print_sequence(__u32 start, int len)
2508c2ecf20Sopenharmony_ci{
2518c2ecf20Sopenharmony_ci	if (start == INT_MAX)
2528c2ecf20Sopenharmony_ci		return;
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci	if (len == 1)
2558c2ecf20Sopenharmony_ci		printk(" %d", start);
2568c2ecf20Sopenharmony_ci	else
2578c2ecf20Sopenharmony_ci		printk(" %d(%d)", start, len);
2588c2ecf20Sopenharmony_ci}
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_cistatic void indirect_print_item(struct item_head *ih, char *item)
2618c2ecf20Sopenharmony_ci{
2628c2ecf20Sopenharmony_ci	int j;
2638c2ecf20Sopenharmony_ci	__le32 *unp;
2648c2ecf20Sopenharmony_ci	__u32 prev = INT_MAX;
2658c2ecf20Sopenharmony_ci	int num = 0;
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci	unp = (__le32 *) item;
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci	if (ih_item_len(ih) % UNFM_P_SIZE)
2708c2ecf20Sopenharmony_ci		reiserfs_warning(NULL, "reiserfs-16102", "invalid item len");
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci	printk("%d pointers\n[ ", (int)I_UNFM_NUM(ih));
2738c2ecf20Sopenharmony_ci	for (j = 0; j < I_UNFM_NUM(ih); j++) {
2748c2ecf20Sopenharmony_ci		if (sequence_finished(prev, &num, get_block_num(unp, j))) {
2758c2ecf20Sopenharmony_ci			print_sequence(prev, num);
2768c2ecf20Sopenharmony_ci			start_new_sequence(&prev, &num, get_block_num(unp, j));
2778c2ecf20Sopenharmony_ci		}
2788c2ecf20Sopenharmony_ci	}
2798c2ecf20Sopenharmony_ci	print_sequence(prev, num);
2808c2ecf20Sopenharmony_ci	printk("]\n");
2818c2ecf20Sopenharmony_ci}
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_cistatic void indirect_check_item(struct item_head *ih, char *item)
2848c2ecf20Sopenharmony_ci{
2858c2ecf20Sopenharmony_ci	/* unused */
2868c2ecf20Sopenharmony_ci}
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_cistatic int indirect_create_vi(struct virtual_node *vn,
2898c2ecf20Sopenharmony_ci			      struct virtual_item *vi,
2908c2ecf20Sopenharmony_ci			      int is_affected, int insert_size)
2918c2ecf20Sopenharmony_ci{
2928c2ecf20Sopenharmony_ci	vi->vi_index = TYPE_INDIRECT;
2938c2ecf20Sopenharmony_ci	return 0;
2948c2ecf20Sopenharmony_ci}
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_cistatic int indirect_check_left(struct virtual_item *vi, int free,
2978c2ecf20Sopenharmony_ci			       int start_skip, int end_skip)
2988c2ecf20Sopenharmony_ci{
2998c2ecf20Sopenharmony_ci	int bytes;
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci	bytes = free - free % UNFM_P_SIZE;
3028c2ecf20Sopenharmony_ci	return bytes ? : -1;
3038c2ecf20Sopenharmony_ci}
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_cistatic int indirect_check_right(struct virtual_item *vi, int free)
3068c2ecf20Sopenharmony_ci{
3078c2ecf20Sopenharmony_ci	return indirect_check_left(vi, free, 0, 0);
3088c2ecf20Sopenharmony_ci}
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci/*
3118c2ecf20Sopenharmony_ci * return size in bytes of 'units' units. If first == 0 - calculate
3128c2ecf20Sopenharmony_ci * from the head (left), otherwise - from tail (right)
3138c2ecf20Sopenharmony_ci */
3148c2ecf20Sopenharmony_cistatic int indirect_part_size(struct virtual_item *vi, int first, int units)
3158c2ecf20Sopenharmony_ci{
3168c2ecf20Sopenharmony_ci	/* unit of indirect item is byte (yet) */
3178c2ecf20Sopenharmony_ci	return units;
3188c2ecf20Sopenharmony_ci}
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_cistatic int indirect_unit_num(struct virtual_item *vi)
3218c2ecf20Sopenharmony_ci{
3228c2ecf20Sopenharmony_ci	/* unit of indirect item is byte (yet) */
3238c2ecf20Sopenharmony_ci	return vi->vi_item_len - IH_SIZE;
3248c2ecf20Sopenharmony_ci}
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_cistatic void indirect_print_vi(struct virtual_item *vi)
3278c2ecf20Sopenharmony_ci{
3288c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "reiserfs-16103",
3298c2ecf20Sopenharmony_ci			 "INDIRECT, index %d, type 0x%x, %h",
3308c2ecf20Sopenharmony_ci			 vi->vi_index, vi->vi_type, vi->vi_ih);
3318c2ecf20Sopenharmony_ci}
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_cistatic struct item_operations indirect_ops = {
3348c2ecf20Sopenharmony_ci	.bytes_number = indirect_bytes_number,
3358c2ecf20Sopenharmony_ci	.decrement_key = indirect_decrement_key,
3368c2ecf20Sopenharmony_ci	.is_left_mergeable = indirect_is_left_mergeable,
3378c2ecf20Sopenharmony_ci	.print_item = indirect_print_item,
3388c2ecf20Sopenharmony_ci	.check_item = indirect_check_item,
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	.create_vi = indirect_create_vi,
3418c2ecf20Sopenharmony_ci	.check_left = indirect_check_left,
3428c2ecf20Sopenharmony_ci	.check_right = indirect_check_right,
3438c2ecf20Sopenharmony_ci	.part_size = indirect_part_size,
3448c2ecf20Sopenharmony_ci	.unit_num = indirect_unit_num,
3458c2ecf20Sopenharmony_ci	.print_vi = indirect_print_vi
3468c2ecf20Sopenharmony_ci};
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci/* direntry functions */
3498c2ecf20Sopenharmony_cistatic int direntry_bytes_number(struct item_head *ih, int block_size)
3508c2ecf20Sopenharmony_ci{
3518c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "vs-16090",
3528c2ecf20Sopenharmony_ci			 "bytes number is asked for direntry");
3538c2ecf20Sopenharmony_ci	return 0;
3548c2ecf20Sopenharmony_ci}
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_cistatic void direntry_decrement_key(struct cpu_key *key)
3578c2ecf20Sopenharmony_ci{
3588c2ecf20Sopenharmony_ci	cpu_key_k_offset_dec(key);
3598c2ecf20Sopenharmony_ci	if (cpu_key_k_offset(key) == 0)
3608c2ecf20Sopenharmony_ci		set_cpu_key_k_type(key, TYPE_STAT_DATA);
3618c2ecf20Sopenharmony_ci}
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_cistatic int direntry_is_left_mergeable(struct reiserfs_key *key,
3648c2ecf20Sopenharmony_ci				      unsigned long bsize)
3658c2ecf20Sopenharmony_ci{
3668c2ecf20Sopenharmony_ci	if (le32_to_cpu(key->u.k_offset_v1.k_offset) == DOT_OFFSET)
3678c2ecf20Sopenharmony_ci		return 0;
3688c2ecf20Sopenharmony_ci	return 1;
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci}
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_cistatic void direntry_print_item(struct item_head *ih, char *item)
3738c2ecf20Sopenharmony_ci{
3748c2ecf20Sopenharmony_ci	int i;
3758c2ecf20Sopenharmony_ci	int namelen;
3768c2ecf20Sopenharmony_ci	struct reiserfs_de_head *deh;
3778c2ecf20Sopenharmony_ci	char *name;
3788c2ecf20Sopenharmony_ci	static char namebuf[80];
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	printk("\n # %-15s%-30s%-15s%-15s%-15s\n", "Name",
3818c2ecf20Sopenharmony_ci	       "Key of pointed object", "Hash", "Gen number", "Status");
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci	deh = (struct reiserfs_de_head *)item;
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	for (i = 0; i < ih_entry_count(ih); i++, deh++) {
3868c2ecf20Sopenharmony_ci		namelen =
3878c2ecf20Sopenharmony_ci		    (i ? (deh_location(deh - 1)) : ih_item_len(ih)) -
3888c2ecf20Sopenharmony_ci		    deh_location(deh);
3898c2ecf20Sopenharmony_ci		name = item + deh_location(deh);
3908c2ecf20Sopenharmony_ci		if (name[namelen - 1] == 0)
3918c2ecf20Sopenharmony_ci			namelen = strlen(name);
3928c2ecf20Sopenharmony_ci		namebuf[0] = '"';
3938c2ecf20Sopenharmony_ci		if (namelen > sizeof(namebuf) - 3) {
3948c2ecf20Sopenharmony_ci			strncpy(namebuf + 1, name, sizeof(namebuf) - 3);
3958c2ecf20Sopenharmony_ci			namebuf[sizeof(namebuf) - 2] = '"';
3968c2ecf20Sopenharmony_ci			namebuf[sizeof(namebuf) - 1] = 0;
3978c2ecf20Sopenharmony_ci		} else {
3988c2ecf20Sopenharmony_ci			memcpy(namebuf + 1, name, namelen);
3998c2ecf20Sopenharmony_ci			namebuf[namelen + 1] = '"';
4008c2ecf20Sopenharmony_ci			namebuf[namelen + 2] = 0;
4018c2ecf20Sopenharmony_ci		}
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci		printk("%d:  %-15s%-15d%-15d%-15lld%-15lld(%s)\n",
4048c2ecf20Sopenharmony_ci		       i, namebuf,
4058c2ecf20Sopenharmony_ci		       deh_dir_id(deh), deh_objectid(deh),
4068c2ecf20Sopenharmony_ci		       GET_HASH_VALUE(deh_offset(deh)),
4078c2ecf20Sopenharmony_ci		       GET_GENERATION_NUMBER((deh_offset(deh))),
4088c2ecf20Sopenharmony_ci		       (de_hidden(deh)) ? "HIDDEN" : "VISIBLE");
4098c2ecf20Sopenharmony_ci	}
4108c2ecf20Sopenharmony_ci}
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_cistatic void direntry_check_item(struct item_head *ih, char *item)
4138c2ecf20Sopenharmony_ci{
4148c2ecf20Sopenharmony_ci	int i;
4158c2ecf20Sopenharmony_ci	struct reiserfs_de_head *deh;
4168c2ecf20Sopenharmony_ci
4178c2ecf20Sopenharmony_ci	/* unused */
4188c2ecf20Sopenharmony_ci	deh = (struct reiserfs_de_head *)item;
4198c2ecf20Sopenharmony_ci	for (i = 0; i < ih_entry_count(ih); i++, deh++) {
4208c2ecf20Sopenharmony_ci		;
4218c2ecf20Sopenharmony_ci	}
4228c2ecf20Sopenharmony_ci}
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci#define DIRENTRY_VI_FIRST_DIRENTRY_ITEM 1
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci/*
4278c2ecf20Sopenharmony_ci * function returns old entry number in directory item in real node
4288c2ecf20Sopenharmony_ci * using new entry number in virtual item in virtual node
4298c2ecf20Sopenharmony_ci */
4308c2ecf20Sopenharmony_cistatic inline int old_entry_num(int is_affected, int virtual_entry_num,
4318c2ecf20Sopenharmony_ci				int pos_in_item, int mode)
4328c2ecf20Sopenharmony_ci{
4338c2ecf20Sopenharmony_ci	if (mode == M_INSERT || mode == M_DELETE)
4348c2ecf20Sopenharmony_ci		return virtual_entry_num;
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	if (!is_affected)
4378c2ecf20Sopenharmony_ci		/* cut or paste is applied to another item */
4388c2ecf20Sopenharmony_ci		return virtual_entry_num;
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci	if (virtual_entry_num < pos_in_item)
4418c2ecf20Sopenharmony_ci		return virtual_entry_num;
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci	if (mode == M_CUT)
4448c2ecf20Sopenharmony_ci		return virtual_entry_num + 1;
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci	RFALSE(mode != M_PASTE || virtual_entry_num == 0,
4478c2ecf20Sopenharmony_ci	       "vs-8015: old_entry_num: mode must be M_PASTE (mode = \'%c\'",
4488c2ecf20Sopenharmony_ci	       mode);
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci	return virtual_entry_num - 1;
4518c2ecf20Sopenharmony_ci}
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci/*
4548c2ecf20Sopenharmony_ci * Create an array of sizes of directory entries for virtual
4558c2ecf20Sopenharmony_ci * item. Return space used by an item. FIXME: no control over
4568c2ecf20Sopenharmony_ci * consuming of space used by this item handler
4578c2ecf20Sopenharmony_ci */
4588c2ecf20Sopenharmony_cistatic int direntry_create_vi(struct virtual_node *vn,
4598c2ecf20Sopenharmony_ci			      struct virtual_item *vi,
4608c2ecf20Sopenharmony_ci			      int is_affected, int insert_size)
4618c2ecf20Sopenharmony_ci{
4628c2ecf20Sopenharmony_ci	struct direntry_uarea *dir_u = vi->vi_uarea;
4638c2ecf20Sopenharmony_ci	int i, j;
4648c2ecf20Sopenharmony_ci	int size = sizeof(struct direntry_uarea);
4658c2ecf20Sopenharmony_ci	struct reiserfs_de_head *deh;
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci	vi->vi_index = TYPE_DIRENTRY;
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci	BUG_ON(!(vi->vi_ih) || !vi->vi_item);
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci	dir_u->flags = 0;
4728c2ecf20Sopenharmony_ci	if (le_ih_k_offset(vi->vi_ih) == DOT_OFFSET)
4738c2ecf20Sopenharmony_ci		dir_u->flags |= DIRENTRY_VI_FIRST_DIRENTRY_ITEM;
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_ci	deh = (struct reiserfs_de_head *)(vi->vi_item);
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci	/* virtual directory item have this amount of entry after */
4788c2ecf20Sopenharmony_ci	dir_u->entry_count = ih_entry_count(vi->vi_ih) +
4798c2ecf20Sopenharmony_ci	    ((is_affected) ? ((vn->vn_mode == M_CUT) ? -1 :
4808c2ecf20Sopenharmony_ci			      (vn->vn_mode == M_PASTE ? 1 : 0)) : 0);
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci	for (i = 0; i < dir_u->entry_count; i++) {
4838c2ecf20Sopenharmony_ci		j = old_entry_num(is_affected, i, vn->vn_pos_in_item,
4848c2ecf20Sopenharmony_ci				  vn->vn_mode);
4858c2ecf20Sopenharmony_ci		dir_u->entry_sizes[i] =
4868c2ecf20Sopenharmony_ci		    (j ? deh_location(&deh[j - 1]) : ih_item_len(vi->vi_ih)) -
4878c2ecf20Sopenharmony_ci		    deh_location(&deh[j]) + DEH_SIZE;
4888c2ecf20Sopenharmony_ci	}
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ci	size += (dir_u->entry_count * sizeof(short));
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci	/* set size of pasted entry */
4938c2ecf20Sopenharmony_ci	if (is_affected && vn->vn_mode == M_PASTE)
4948c2ecf20Sopenharmony_ci		dir_u->entry_sizes[vn->vn_pos_in_item] = insert_size;
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci#ifdef CONFIG_REISERFS_CHECK
4978c2ecf20Sopenharmony_ci	/* compare total size of entries with item length */
4988c2ecf20Sopenharmony_ci	{
4998c2ecf20Sopenharmony_ci		int k, l;
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ci		l = 0;
5028c2ecf20Sopenharmony_ci		for (k = 0; k < dir_u->entry_count; k++)
5038c2ecf20Sopenharmony_ci			l += dir_u->entry_sizes[k];
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_ci		if (l + IH_SIZE != vi->vi_item_len +
5068c2ecf20Sopenharmony_ci		    ((is_affected
5078c2ecf20Sopenharmony_ci		      && (vn->vn_mode == M_PASTE
5088c2ecf20Sopenharmony_ci			  || vn->vn_mode == M_CUT)) ? insert_size : 0)) {
5098c2ecf20Sopenharmony_ci			reiserfs_panic(NULL, "vs-8025", "(mode==%c, "
5108c2ecf20Sopenharmony_ci				       "insert_size==%d), invalid length of "
5118c2ecf20Sopenharmony_ci				       "directory item",
5128c2ecf20Sopenharmony_ci				       vn->vn_mode, insert_size);
5138c2ecf20Sopenharmony_ci		}
5148c2ecf20Sopenharmony_ci	}
5158c2ecf20Sopenharmony_ci#endif
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_ci	return size;
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci}
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci/*
5228c2ecf20Sopenharmony_ci * return number of entries which may fit into specified amount of
5238c2ecf20Sopenharmony_ci * free space, or -1 if free space is not enough even for 1 entry
5248c2ecf20Sopenharmony_ci */
5258c2ecf20Sopenharmony_cistatic int direntry_check_left(struct virtual_item *vi, int free,
5268c2ecf20Sopenharmony_ci			       int start_skip, int end_skip)
5278c2ecf20Sopenharmony_ci{
5288c2ecf20Sopenharmony_ci	int i;
5298c2ecf20Sopenharmony_ci	int entries = 0;
5308c2ecf20Sopenharmony_ci	struct direntry_uarea *dir_u = vi->vi_uarea;
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci	for (i = start_skip; i < dir_u->entry_count - end_skip; i++) {
5338c2ecf20Sopenharmony_ci		/* i-th entry doesn't fit into the remaining free space */
5348c2ecf20Sopenharmony_ci		if (dir_u->entry_sizes[i] > free)
5358c2ecf20Sopenharmony_ci			break;
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci		free -= dir_u->entry_sizes[i];
5388c2ecf20Sopenharmony_ci		entries++;
5398c2ecf20Sopenharmony_ci	}
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci	if (entries == dir_u->entry_count) {
5428c2ecf20Sopenharmony_ci		reiserfs_panic(NULL, "item_ops-1",
5438c2ecf20Sopenharmony_ci			       "free space %d, entry_count %d", free,
5448c2ecf20Sopenharmony_ci			       dir_u->entry_count);
5458c2ecf20Sopenharmony_ci	}
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci	/* "." and ".." can not be separated from each other */
5488c2ecf20Sopenharmony_ci	if (start_skip == 0 && (dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM)
5498c2ecf20Sopenharmony_ci	    && entries < 2)
5508c2ecf20Sopenharmony_ci		entries = 0;
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci	return entries ? : -1;
5538c2ecf20Sopenharmony_ci}
5548c2ecf20Sopenharmony_ci
5558c2ecf20Sopenharmony_cistatic int direntry_check_right(struct virtual_item *vi, int free)
5568c2ecf20Sopenharmony_ci{
5578c2ecf20Sopenharmony_ci	int i;
5588c2ecf20Sopenharmony_ci	int entries = 0;
5598c2ecf20Sopenharmony_ci	struct direntry_uarea *dir_u = vi->vi_uarea;
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci	for (i = dir_u->entry_count - 1; i >= 0; i--) {
5628c2ecf20Sopenharmony_ci		/* i-th entry doesn't fit into the remaining free space */
5638c2ecf20Sopenharmony_ci		if (dir_u->entry_sizes[i] > free)
5648c2ecf20Sopenharmony_ci			break;
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_ci		free -= dir_u->entry_sizes[i];
5678c2ecf20Sopenharmony_ci		entries++;
5688c2ecf20Sopenharmony_ci	}
5698c2ecf20Sopenharmony_ci	BUG_ON(entries == dir_u->entry_count);
5708c2ecf20Sopenharmony_ci
5718c2ecf20Sopenharmony_ci	/* "." and ".." can not be separated from each other */
5728c2ecf20Sopenharmony_ci	if ((dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM)
5738c2ecf20Sopenharmony_ci	    && entries > dir_u->entry_count - 2)
5748c2ecf20Sopenharmony_ci		entries = dir_u->entry_count - 2;
5758c2ecf20Sopenharmony_ci
5768c2ecf20Sopenharmony_ci	return entries ? : -1;
5778c2ecf20Sopenharmony_ci}
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_ci/* sum of entry sizes between from-th and to-th entries including both edges */
5808c2ecf20Sopenharmony_cistatic int direntry_part_size(struct virtual_item *vi, int first, int count)
5818c2ecf20Sopenharmony_ci{
5828c2ecf20Sopenharmony_ci	int i, retval;
5838c2ecf20Sopenharmony_ci	int from, to;
5848c2ecf20Sopenharmony_ci	struct direntry_uarea *dir_u = vi->vi_uarea;
5858c2ecf20Sopenharmony_ci
5868c2ecf20Sopenharmony_ci	retval = 0;
5878c2ecf20Sopenharmony_ci	if (first == 0)
5888c2ecf20Sopenharmony_ci		from = 0;
5898c2ecf20Sopenharmony_ci	else
5908c2ecf20Sopenharmony_ci		from = dir_u->entry_count - count;
5918c2ecf20Sopenharmony_ci	to = from + count - 1;
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci	for (i = from; i <= to; i++)
5948c2ecf20Sopenharmony_ci		retval += dir_u->entry_sizes[i];
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_ci	return retval;
5978c2ecf20Sopenharmony_ci}
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_cistatic int direntry_unit_num(struct virtual_item *vi)
6008c2ecf20Sopenharmony_ci{
6018c2ecf20Sopenharmony_ci	struct direntry_uarea *dir_u = vi->vi_uarea;
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ci	return dir_u->entry_count;
6048c2ecf20Sopenharmony_ci}
6058c2ecf20Sopenharmony_ci
6068c2ecf20Sopenharmony_cistatic void direntry_print_vi(struct virtual_item *vi)
6078c2ecf20Sopenharmony_ci{
6088c2ecf20Sopenharmony_ci	int i;
6098c2ecf20Sopenharmony_ci	struct direntry_uarea *dir_u = vi->vi_uarea;
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "reiserfs-16104",
6128c2ecf20Sopenharmony_ci			 "DIRENTRY, index %d, type 0x%x, %h, flags 0x%x",
6138c2ecf20Sopenharmony_ci			 vi->vi_index, vi->vi_type, vi->vi_ih, dir_u->flags);
6148c2ecf20Sopenharmony_ci	printk("%d entries: ", dir_u->entry_count);
6158c2ecf20Sopenharmony_ci	for (i = 0; i < dir_u->entry_count; i++)
6168c2ecf20Sopenharmony_ci		printk("%d ", dir_u->entry_sizes[i]);
6178c2ecf20Sopenharmony_ci	printk("\n");
6188c2ecf20Sopenharmony_ci}
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_cistatic struct item_operations direntry_ops = {
6218c2ecf20Sopenharmony_ci	.bytes_number = direntry_bytes_number,
6228c2ecf20Sopenharmony_ci	.decrement_key = direntry_decrement_key,
6238c2ecf20Sopenharmony_ci	.is_left_mergeable = direntry_is_left_mergeable,
6248c2ecf20Sopenharmony_ci	.print_item = direntry_print_item,
6258c2ecf20Sopenharmony_ci	.check_item = direntry_check_item,
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_ci	.create_vi = direntry_create_vi,
6288c2ecf20Sopenharmony_ci	.check_left = direntry_check_left,
6298c2ecf20Sopenharmony_ci	.check_right = direntry_check_right,
6308c2ecf20Sopenharmony_ci	.part_size = direntry_part_size,
6318c2ecf20Sopenharmony_ci	.unit_num = direntry_unit_num,
6328c2ecf20Sopenharmony_ci	.print_vi = direntry_print_vi
6338c2ecf20Sopenharmony_ci};
6348c2ecf20Sopenharmony_ci
6358c2ecf20Sopenharmony_ci/* Error catching functions to catch errors caused by incorrect item types. */
6368c2ecf20Sopenharmony_cistatic int errcatch_bytes_number(struct item_head *ih, int block_size)
6378c2ecf20Sopenharmony_ci{
6388c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "green-16001",
6398c2ecf20Sopenharmony_ci			 "Invalid item type observed, run fsck ASAP");
6408c2ecf20Sopenharmony_ci	return 0;
6418c2ecf20Sopenharmony_ci}
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_cistatic void errcatch_decrement_key(struct cpu_key *key)
6448c2ecf20Sopenharmony_ci{
6458c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "green-16002",
6468c2ecf20Sopenharmony_ci			 "Invalid item type observed, run fsck ASAP");
6478c2ecf20Sopenharmony_ci}
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_cistatic int errcatch_is_left_mergeable(struct reiserfs_key *key,
6508c2ecf20Sopenharmony_ci				      unsigned long bsize)
6518c2ecf20Sopenharmony_ci{
6528c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "green-16003",
6538c2ecf20Sopenharmony_ci			 "Invalid item type observed, run fsck ASAP");
6548c2ecf20Sopenharmony_ci	return 0;
6558c2ecf20Sopenharmony_ci}
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_cistatic void errcatch_print_item(struct item_head *ih, char *item)
6588c2ecf20Sopenharmony_ci{
6598c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "green-16004",
6608c2ecf20Sopenharmony_ci			 "Invalid item type observed, run fsck ASAP");
6618c2ecf20Sopenharmony_ci}
6628c2ecf20Sopenharmony_ci
6638c2ecf20Sopenharmony_cistatic void errcatch_check_item(struct item_head *ih, char *item)
6648c2ecf20Sopenharmony_ci{
6658c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "green-16005",
6668c2ecf20Sopenharmony_ci			 "Invalid item type observed, run fsck ASAP");
6678c2ecf20Sopenharmony_ci}
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_cistatic int errcatch_create_vi(struct virtual_node *vn,
6708c2ecf20Sopenharmony_ci			      struct virtual_item *vi,
6718c2ecf20Sopenharmony_ci			      int is_affected, int insert_size)
6728c2ecf20Sopenharmony_ci{
6738c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "green-16006",
6748c2ecf20Sopenharmony_ci			 "Invalid item type observed, run fsck ASAP");
6758c2ecf20Sopenharmony_ci	/*
6768c2ecf20Sopenharmony_ci	 * We might return -1 here as well, but it won't help as
6778c2ecf20Sopenharmony_ci	 * create_virtual_node() from where this operation is called
6788c2ecf20Sopenharmony_ci	 * from is of return type void.
6798c2ecf20Sopenharmony_ci	 */
6808c2ecf20Sopenharmony_ci	return 0;
6818c2ecf20Sopenharmony_ci}
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_cistatic int errcatch_check_left(struct virtual_item *vi, int free,
6848c2ecf20Sopenharmony_ci			       int start_skip, int end_skip)
6858c2ecf20Sopenharmony_ci{
6868c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "green-16007",
6878c2ecf20Sopenharmony_ci			 "Invalid item type observed, run fsck ASAP");
6888c2ecf20Sopenharmony_ci	return -1;
6898c2ecf20Sopenharmony_ci}
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_cistatic int errcatch_check_right(struct virtual_item *vi, int free)
6928c2ecf20Sopenharmony_ci{
6938c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "green-16008",
6948c2ecf20Sopenharmony_ci			 "Invalid item type observed, run fsck ASAP");
6958c2ecf20Sopenharmony_ci	return -1;
6968c2ecf20Sopenharmony_ci}
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_cistatic int errcatch_part_size(struct virtual_item *vi, int first, int count)
6998c2ecf20Sopenharmony_ci{
7008c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "green-16009",
7018c2ecf20Sopenharmony_ci			 "Invalid item type observed, run fsck ASAP");
7028c2ecf20Sopenharmony_ci	return 0;
7038c2ecf20Sopenharmony_ci}
7048c2ecf20Sopenharmony_ci
7058c2ecf20Sopenharmony_cistatic int errcatch_unit_num(struct virtual_item *vi)
7068c2ecf20Sopenharmony_ci{
7078c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "green-16010",
7088c2ecf20Sopenharmony_ci			 "Invalid item type observed, run fsck ASAP");
7098c2ecf20Sopenharmony_ci	return 0;
7108c2ecf20Sopenharmony_ci}
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_cistatic void errcatch_print_vi(struct virtual_item *vi)
7138c2ecf20Sopenharmony_ci{
7148c2ecf20Sopenharmony_ci	reiserfs_warning(NULL, "green-16011",
7158c2ecf20Sopenharmony_ci			 "Invalid item type observed, run fsck ASAP");
7168c2ecf20Sopenharmony_ci}
7178c2ecf20Sopenharmony_ci
7188c2ecf20Sopenharmony_cistatic struct item_operations errcatch_ops = {
7198c2ecf20Sopenharmony_ci	.bytes_number = errcatch_bytes_number,
7208c2ecf20Sopenharmony_ci	.decrement_key = errcatch_decrement_key,
7218c2ecf20Sopenharmony_ci	.is_left_mergeable = errcatch_is_left_mergeable,
7228c2ecf20Sopenharmony_ci	.print_item = errcatch_print_item,
7238c2ecf20Sopenharmony_ci	.check_item = errcatch_check_item,
7248c2ecf20Sopenharmony_ci
7258c2ecf20Sopenharmony_ci	.create_vi = errcatch_create_vi,
7268c2ecf20Sopenharmony_ci	.check_left = errcatch_check_left,
7278c2ecf20Sopenharmony_ci	.check_right = errcatch_check_right,
7288c2ecf20Sopenharmony_ci	.part_size = errcatch_part_size,
7298c2ecf20Sopenharmony_ci	.unit_num = errcatch_unit_num,
7308c2ecf20Sopenharmony_ci	.print_vi = errcatch_print_vi
7318c2ecf20Sopenharmony_ci};
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_ci#if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
7348c2ecf20Sopenharmony_ci#error Item types must use disk-format assigned values.
7358c2ecf20Sopenharmony_ci#endif
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_cistruct item_operations *item_ops[TYPE_ANY + 1] = {
7388c2ecf20Sopenharmony_ci	&stat_data_ops,
7398c2ecf20Sopenharmony_ci	&indirect_ops,
7408c2ecf20Sopenharmony_ci	&direct_ops,
7418c2ecf20Sopenharmony_ci	&direntry_ops,
7428c2ecf20Sopenharmony_ci	NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7438c2ecf20Sopenharmony_ci	&errcatch_ops		/* This is to catch errors with invalid type (15th entry for TYPE_ANY) */
7448c2ecf20Sopenharmony_ci};
745