⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reiserfs_fs.h

📁 linux得一些常用命令,以及linux环境下的c编程
💻 H
📖 第 1 页 / 共 5 页
字号:
    deh = B_I_DEH (bh, ih) + pos_in_item;    if (pos_in_item)	return deh_location(deh-1) - deh_location(deh);    return ih_item_len(ih) - deh_location(deh);}/* number of entries in the directory item, depends on ENTRY_COUNT being at the start of directory dynamic data. */#define I_ENTRY_COUNT(ih) (ih_entry_count((ih)))/* name by bh, ih and entry_num */#define B_I_E_NAME(bh,ih,entry_num) ((char *)(bh->b_data + ih_location(ih) + deh_location(B_I_DEH(bh,ih)+(entry_num))))// two entries per block (at least)#define REISERFS_MAX_NAME(block_size) 255/* this structure is used for operations on directory entries. It is   not a disk structure. *//* When reiserfs_find_entry or search_by_entry_key find directory   entry, they return filled reiserfs_dir_entry structure */struct reiserfs_dir_entry{  struct buffer_head * de_bh;  int de_item_num;  struct item_head * de_ih;  int de_entry_num;  struct reiserfs_de_head * de_deh;  int de_entrylen;  int de_namelen;  char * de_name;  char * de_gen_number_bit_string;  __u32 de_dir_id;  __u32 de_objectid;  struct cpu_key de_entry_key;};   /* these defines are useful when a particular member of a reiserfs_dir_entry is needed *//* pointer to file name, stored in entry */#define B_I_DEH_ENTRY_FILE_NAME(bh,ih,deh) (B_I_PITEM (bh, ih) + deh_location(deh))/* length of name */#define I_DEH_N_ENTRY_FILE_NAME_LENGTH(ih,deh,entry_num) \(I_DEH_N_ENTRY_LENGTH (ih, deh, entry_num) - (de_with_sd (deh) ? SD_SIZE : 0))/* hash value occupies bits from 7 up to 30 */#define GET_HASH_VALUE(offset) ((offset) & 0x7fffff80LL)/* generation number occupies 7 bits starting from 0 up to 6 */#define GET_GENERATION_NUMBER(offset) ((offset) & 0x7fLL)#define MAX_GENERATION_NUMBER  127#define SET_GENERATION_NUMBER(offset,gen_number) (GET_HASH_VALUE(offset)|(gen_number))/* * Picture represents an internal node of the reiserfs tree *  ______________________________________________________ * |      |  Array of     |  Array of         |  Free     | * |block |    keys       |  pointers         | space     | * | head |      N        |      N+1          |           | * |______|_______________|___________________|___________| *//***************************************************************************//*                      DISK CHILD                                         *//***************************************************************************//* Disk child pointer: The pointer from an internal node of the tree   to a node that is on disk. */struct disk_child {  __u32       dc_block_number;              /* Disk child's block number. */  __u16       dc_size;		            /* Disk child's used space.   */  __u16       dc_reserved;};#define DC_SIZE (sizeof(struct disk_child))#define dc_block_number(dc_p)	(le32_to_cpu((dc_p)->dc_block_number))#define dc_size(dc_p)		(le16_to_cpu((dc_p)->dc_size))#define put_dc_block_number(dc_p, val)   do { (dc_p)->dc_block_number = cpu_to_le32(val); } while(0)#define put_dc_size(dc_p, val)   do { (dc_p)->dc_size = cpu_to_le16(val); } while(0)/* Get disk child by buffer header and position in the tree node. */#define B_N_CHILD(p_s_bh,n_pos)  ((struct disk_child *)\((p_s_bh)->b_data+BLKH_SIZE+B_NR_ITEMS(p_s_bh)*KEY_SIZE+DC_SIZE*(n_pos)))/* Get disk child number by buffer header and position in the tree node. */#define B_N_CHILD_NUM(p_s_bh,n_pos) (dc_block_number(B_N_CHILD(p_s_bh,n_pos)))#define PUT_B_N_CHILD_NUM(p_s_bh,n_pos, val) (put_dc_block_number(B_N_CHILD(p_s_bh,n_pos), val )) /* maximal value of field child_size in structure disk_child */  /* child size is the combined size of all items and their headers */#define MAX_CHILD_SIZE(bh) ((int)( (bh)->b_size - BLKH_SIZE ))/* amount of used space in buffer (not including block head) */#define B_CHILD_SIZE(cur) (MAX_CHILD_SIZE(cur)-(B_FREE_SPACE(cur)))/* max and min number of keys in internal node */#define MAX_NR_KEY(bh) ( (MAX_CHILD_SIZE(bh)-DC_SIZE)/(KEY_SIZE+DC_SIZE) )#define MIN_NR_KEY(bh)    (MAX_NR_KEY(bh)/2)/***************************************************************************//*                      PATH STRUCTURES AND DEFINES                        *//***************************************************************************//* Search_by_key fills up the path from the root to the leaf as it descends the tree looking for the   key.  It uses reiserfs_bread to try to find buffers in the cache given their block number.  If it   does not find them in the cache it reads them from disk.  For each node search_by_key finds using   reiserfs_bread it then uses bin_search to look through that node.  bin_search will find the   position of the block_number of the next node if it is looking through an internal node.  If it   is looking through a leaf node bin_search will find the position of the item which has key either   equal to given key, or which is the maximal key less than the given key. */struct  path_element  {  struct buffer_head *	pe_buffer;    /* Pointer to the buffer at the path in the tree. */  int         		pe_position;  /* Position in the tree node which is placed in the */                                      /* buffer above.                                  */};#define MAX_HEIGHT 5 /* maximal height of a tree. don't change this without changing JOURNAL_PER_BALANCE_CNT */#define EXTENDED_MAX_HEIGHT         7 /* Must be equals MAX_HEIGHT + FIRST_PATH_ELEMENT_OFFSET */#define FIRST_PATH_ELEMENT_OFFSET   2 /* Must be equal to at least 2. */#define ILLEGAL_PATH_ELEMENT_OFFSET 1 /* Must be equal to FIRST_PATH_ELEMENT_OFFSET - 1 */#define MAX_FEB_SIZE 6   /* this MUST be MAX_HEIGHT + 1. See about FEB below *//* We need to keep track of who the ancestors of nodes are.  When we   perform a search we record which nodes were visited while   descending the tree looking for the node we searched for. This list   of nodes is called the path.  This information is used while   performing balancing.  Note that this path information may become   invalid, and this means we must check it when using it to see if it   is still valid. You'll need to read search_by_key and the comments   in it, especially about decrement_counters_in_path(), to understand   this structure.  Paths make the code so much harder to work with and debug.... Anenormous number of bugs are due to them, and trying to write or modifycode that uses them just makes my head hurt.  They are based on anexcessive effort to avoid disturbing the precious VFS code.:-( Thegods only know how we are going to SMP the code that uses them.znodes are the way! */struct  path {  int                   path_length;                      	/* Length of the array above.   */  struct  path_element  path_elements[EXTENDED_MAX_HEIGHT];	/* Array of the path elements.  */  int			pos_in_item;};#define pos_in_item(path) ((path)->pos_in_item)#define INITIALIZE_PATH(var) \struct path var = {ILLEGAL_PATH_ELEMENT_OFFSET, }/* Get path element by path and path position. */#define PATH_OFFSET_PELEMENT(p_s_path,n_offset)  ((p_s_path)->path_elements +(n_offset))/* Get buffer header at the path by path and path position. */#define PATH_OFFSET_PBUFFER(p_s_path,n_offset)   (PATH_OFFSET_PELEMENT(p_s_path,n_offset)->pe_buffer)/* Get position in the element at the path by path and path position. */#define PATH_OFFSET_POSITION(p_s_path,n_offset) (PATH_OFFSET_PELEMENT(p_s_path,n_offset)->pe_position)#define PATH_PLAST_BUFFER(p_s_path) (PATH_OFFSET_PBUFFER((p_s_path), (p_s_path)->path_length))				/* you know, to the person who didn't                                   write this the macro name does not                                   at first suggest what it does.                                   Maybe POSITION_FROM_PATH_END? Or                                   maybe we should just focus on                                   dumping paths... -Hans */#define PATH_LAST_POSITION(p_s_path) (PATH_OFFSET_POSITION((p_s_path), (p_s_path)->path_length))#define PATH_PITEM_HEAD(p_s_path)    B_N_PITEM_HEAD(PATH_PLAST_BUFFER(p_s_path),PATH_LAST_POSITION(p_s_path))/* in do_balance leaf has h == 0 in contrast with path structure,   where root has level == 0. That is why we need these defines */#define PATH_H_PBUFFER(p_s_path, h) PATH_OFFSET_PBUFFER (p_s_path, p_s_path->path_length - (h))	/* tb->S[h] */#define PATH_H_PPARENT(path, h) PATH_H_PBUFFER (path, (h) + 1)			/* tb->F[h] or tb->S[0]->b_parent */#define PATH_H_POSITION(path, h) PATH_OFFSET_POSITION (path, path->path_length - (h))	#define PATH_H_B_ITEM_ORDER(path, h) PATH_H_POSITION(path, h + 1)		/* tb->S[h]->b_item_order */#define PATH_H_PATH_OFFSET(p_s_path, n_h) ((p_s_path)->path_length - (n_h))#define get_last_bh(path) PATH_PLAST_BUFFER(path)#define get_ih(path) PATH_PITEM_HEAD(path)#define get_item_pos(path) PATH_LAST_POSITION(path)#define get_item(path) ((void *)B_N_PITEM(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION (path)))#define item_moved(ih,path) comp_items(ih, path)#define path_changed(ih,path) comp_items (ih, path)/***************************************************************************//*                       MISC                                              *//***************************************************************************//* Size of pointer to the unformatted node. */#define UNFM_P_SIZE (sizeof(unp_t))// in in-core inode key is stored on le form#define INODE_PKEY(inode) ((struct key *)((inode)->u.reiserfs_i.i_key))#define MAX_UL_INT 0xffffffff#define MAX_INT    0x7ffffff#define MAX_US_INT 0xffff// reiserfs version 2 has max offset 60 bits. Version 1 - 32 bit offset#define U32_MAX (~(__u32)0)static inline loff_t max_reiserfs_offset (const struct inode * inode){    if (get_inode_item_key_version(inode) == KEY_FORMAT_3_5)	return (loff_t)U32_MAX;    return (loff_t)((~(__u64)0) >> 4);}/*#define MAX_KEY_UNIQUENESS	MAX_UL_INT*/#define MAX_KEY_OBJECTID	MAX_UL_INT#define MAX_B_NUM  MAX_UL_INT#define MAX_FC_NUM MAX_US_INT/* the purpose is to detect overflow of an unsigned short */#define REISERFS_LINK_MAX (MAX_US_INT - 1000)/* The following defines are used in reiserfs_insert_item and reiserfs_append_item  */#define REISERFS_KERNEL_MEM		0	/* reiserfs kernel memory mode	*/#define REISERFS_USER_MEM		1	/* reiserfs user memory mode		*/#define fs_generation(s) ((s)->u.reiserfs_sb.s_generation_counter)#define get_generation(s) atomic_read (&fs_generation(s))#define FILESYSTEM_CHANGED_TB(tb)  (get_generation((tb)->tb_sb) != (tb)->fs_gen)#define fs_changed(gen,s) (gen != get_generation (s))/***************************************************************************//*                  FIXATE NODES                                           *//***************************************************************************/#define VI_TYPE_LEFT_MERGEABLE 1#define VI_TYPE_RIGHT_MERGEABLE 2/* To make any changes in the tree we always first find node, that   contains item to be changed/deleted or place to insert a new   item. We call this node S. To do balancing we need to decide what   we will shift to left/right neighbor, or to a new node, where new   item will be etc. To make this analysis simpler we build virtual   node. Virtual node is an array of items, that will replace items of   node S. (For instance if we are going to delete an item, virtual   node does not contain it). Virtual node keeps information about   item sizes and types, mergeability of first and last items, sizes   of all entries in directory item. We use this array of items when   calculating what we can shift to neighbors and how many nodes we   have to have if we do not any shiftings, if we shift to left/right   neighbor or to both. */struct virtual_item{    int vi_index; // index in the array of item operations    unsigned short vi_type;	// left/right mergeability    unsigned short vi_item_len;           /* length of item that it will have after balancing */    struct item_head * vi_ih;    const char * vi_item;     // body of item (old or new)    const void * vi_new_data; // 0 always but paste mode    void * vi_uarea;    // item specific area};struct virtual_node{  char * vn_free_ptr;		/* this is a pointer to the free space in the buffer */  unsigned short vn_nr_item;	/* number of items in virtual node */  short vn_size;        	/* size of node , that node would have if it has unlimited size and no balancing is performed */  short vn_mode;		/* mode of balancing (paste, insert, delete, cut) */  short vn_affected_item_num;   short vn_pos_in_item;  struct item_head * vn_ins_ih;	/* item header of inserted item, 0 for other modes */  const void * vn_data;  struct virtual_item * vn_vi;	/* array of items (including a new one, excluding item to be deleted) */};/* used by directory items when creating virtual nodes */struct direntry_uarea {    int flags;    __u16 entry_count;    __u16 entry_sizes[1];} __attribute__ ((__packed__)) ;/***************************************************************************//*                  TREE BALANCE                                           *//***************************************************************************//* This temporary structure is used in tree balance algorithms, and   constructed as we go to the extent that its various parts are   needed.  It contains arrays of nodes that can potentially be   involved in the balancing of node S, and parameters that define how   each of the nodes must be balanced.  Note that in these algorithms   for balancing the worst case is to need to balance the current node   S and the left and right neighbors and all of their parents plus   create a new node.  We implement S1 balancing for the leaf nodes   and S0 balancing for the internal nodes (S1 and S0 are defined in

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -