Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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