18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright 1996, 1997, 1998 Hans Reiser, see reiserfs/README for 48c2ecf20Sopenharmony_ci * licensing and copyright details 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <linux/reiserfs_fs.h> 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/slab.h> 108c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 118c2ecf20Sopenharmony_ci#include <linux/sched.h> 128c2ecf20Sopenharmony_ci#include <linux/bug.h> 138c2ecf20Sopenharmony_ci#include <linux/workqueue.h> 148c2ecf20Sopenharmony_ci#include <asm/unaligned.h> 158c2ecf20Sopenharmony_ci#include <linux/bitops.h> 168c2ecf20Sopenharmony_ci#include <linux/proc_fs.h> 178c2ecf20Sopenharmony_ci#include <linux/buffer_head.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* the 32 bit compat definitions with int argument */ 208c2ecf20Sopenharmony_ci#define REISERFS_IOC32_UNPACK _IOW(0xCD, 1, int) 218c2ecf20Sopenharmony_ci#define REISERFS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 228c2ecf20Sopenharmony_ci#define REISERFS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 238c2ecf20Sopenharmony_ci#define REISERFS_IOC32_GETVERSION FS_IOC32_GETVERSION 248c2ecf20Sopenharmony_ci#define REISERFS_IOC32_SETVERSION FS_IOC32_SETVERSION 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistruct reiserfs_journal_list; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* bitmasks for i_flags field in reiserfs-specific part of inode */ 298c2ecf20Sopenharmony_citypedef enum { 308c2ecf20Sopenharmony_ci /* 318c2ecf20Sopenharmony_ci * this says what format of key do all items (but stat data) of 328c2ecf20Sopenharmony_ci * an object have. If this is set, that format is 3.6 otherwise - 3.5 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci i_item_key_version_mask = 0x0001, 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci /* 378c2ecf20Sopenharmony_ci * If this is unset, object has 3.5 stat data, otherwise, 388c2ecf20Sopenharmony_ci * it has 3.6 stat data with 64bit size, 32bit nlink etc. 398c2ecf20Sopenharmony_ci */ 408c2ecf20Sopenharmony_ci i_stat_data_version_mask = 0x0002, 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci /* file might need tail packing on close */ 438c2ecf20Sopenharmony_ci i_pack_on_close_mask = 0x0004, 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci /* don't pack tail of file */ 468c2ecf20Sopenharmony_ci i_nopack_mask = 0x0008, 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci /* 498c2ecf20Sopenharmony_ci * If either of these are set, "safe link" was created for this 508c2ecf20Sopenharmony_ci * file during truncate or unlink. Safe link is used to avoid 518c2ecf20Sopenharmony_ci * leakage of disk space on crash with some files open, but unlinked. 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_ci i_link_saved_unlink_mask = 0x0010, 548c2ecf20Sopenharmony_ci i_link_saved_truncate_mask = 0x0020, 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci i_has_xattr_dir = 0x0040, 578c2ecf20Sopenharmony_ci i_data_log = 0x0080, 588c2ecf20Sopenharmony_ci} reiserfs_inode_flags; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistruct reiserfs_inode_info { 618c2ecf20Sopenharmony_ci __u32 i_key[4]; /* key is still 4 32 bit integers */ 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci /* 648c2ecf20Sopenharmony_ci * transient inode flags that are never stored on disk. Bitmasks 658c2ecf20Sopenharmony_ci * for this field are defined above. 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_ci __u32 i_flags; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci /* offset of first byte stored in direct item. */ 708c2ecf20Sopenharmony_ci __u32 i_first_direct_byte; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci /* copy of persistent inode flags read from sd_attrs. */ 738c2ecf20Sopenharmony_ci __u32 i_attrs; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci /* first unused block of a sequence of unused blocks */ 768c2ecf20Sopenharmony_ci int i_prealloc_block; 778c2ecf20Sopenharmony_ci int i_prealloc_count; /* length of that sequence */ 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci /* per-transaction list of inodes which have preallocated blocks */ 808c2ecf20Sopenharmony_ci struct list_head i_prealloc_list; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci /* 838c2ecf20Sopenharmony_ci * new_packing_locality is created; new blocks for the contents 848c2ecf20Sopenharmony_ci * of this directory should be displaced 858c2ecf20Sopenharmony_ci */ 868c2ecf20Sopenharmony_ci unsigned new_packing_locality:1; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci /* 898c2ecf20Sopenharmony_ci * we use these for fsync or O_SYNC to decide which transaction 908c2ecf20Sopenharmony_ci * needs to be committed in order for this inode to be properly 918c2ecf20Sopenharmony_ci * flushed 928c2ecf20Sopenharmony_ci */ 938c2ecf20Sopenharmony_ci unsigned int i_trans_id; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci struct reiserfs_journal_list *i_jl; 968c2ecf20Sopenharmony_ci atomic_t openers; 978c2ecf20Sopenharmony_ci struct mutex tailpack; 988c2ecf20Sopenharmony_ci#ifdef CONFIG_REISERFS_FS_XATTR 998c2ecf20Sopenharmony_ci struct rw_semaphore i_xattr_sem; 1008c2ecf20Sopenharmony_ci#endif 1018c2ecf20Sopenharmony_ci#ifdef CONFIG_QUOTA 1028c2ecf20Sopenharmony_ci struct dquot *i_dquot[MAXQUOTAS]; 1038c2ecf20Sopenharmony_ci#endif 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci struct inode vfs_inode; 1068c2ecf20Sopenharmony_ci}; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_citypedef enum { 1098c2ecf20Sopenharmony_ci reiserfs_attrs_cleared = 0x00000001, 1108c2ecf20Sopenharmony_ci} reiserfs_super_block_flags; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci/* 1138c2ecf20Sopenharmony_ci * struct reiserfs_super_block accessors/mutators since this is a disk 1148c2ecf20Sopenharmony_ci * structure, it will always be in little endian format. 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_ci#define sb_block_count(sbp) (le32_to_cpu((sbp)->s_v1.s_block_count)) 1178c2ecf20Sopenharmony_ci#define set_sb_block_count(sbp,v) ((sbp)->s_v1.s_block_count = cpu_to_le32(v)) 1188c2ecf20Sopenharmony_ci#define sb_free_blocks(sbp) (le32_to_cpu((sbp)->s_v1.s_free_blocks)) 1198c2ecf20Sopenharmony_ci#define set_sb_free_blocks(sbp,v) ((sbp)->s_v1.s_free_blocks = cpu_to_le32(v)) 1208c2ecf20Sopenharmony_ci#define sb_root_block(sbp) (le32_to_cpu((sbp)->s_v1.s_root_block)) 1218c2ecf20Sopenharmony_ci#define set_sb_root_block(sbp,v) ((sbp)->s_v1.s_root_block = cpu_to_le32(v)) 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci#define sb_jp_journal_1st_block(sbp) \ 1248c2ecf20Sopenharmony_ci (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_1st_block)) 1258c2ecf20Sopenharmony_ci#define set_sb_jp_journal_1st_block(sbp,v) \ 1268c2ecf20Sopenharmony_ci ((sbp)->s_v1.s_journal.jp_journal_1st_block = cpu_to_le32(v)) 1278c2ecf20Sopenharmony_ci#define sb_jp_journal_dev(sbp) \ 1288c2ecf20Sopenharmony_ci (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_dev)) 1298c2ecf20Sopenharmony_ci#define set_sb_jp_journal_dev(sbp,v) \ 1308c2ecf20Sopenharmony_ci ((sbp)->s_v1.s_journal.jp_journal_dev = cpu_to_le32(v)) 1318c2ecf20Sopenharmony_ci#define sb_jp_journal_size(sbp) \ 1328c2ecf20Sopenharmony_ci (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_size)) 1338c2ecf20Sopenharmony_ci#define set_sb_jp_journal_size(sbp,v) \ 1348c2ecf20Sopenharmony_ci ((sbp)->s_v1.s_journal.jp_journal_size = cpu_to_le32(v)) 1358c2ecf20Sopenharmony_ci#define sb_jp_journal_trans_max(sbp) \ 1368c2ecf20Sopenharmony_ci (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_trans_max)) 1378c2ecf20Sopenharmony_ci#define set_sb_jp_journal_trans_max(sbp,v) \ 1388c2ecf20Sopenharmony_ci ((sbp)->s_v1.s_journal.jp_journal_trans_max = cpu_to_le32(v)) 1398c2ecf20Sopenharmony_ci#define sb_jp_journal_magic(sbp) \ 1408c2ecf20Sopenharmony_ci (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_magic)) 1418c2ecf20Sopenharmony_ci#define set_sb_jp_journal_magic(sbp,v) \ 1428c2ecf20Sopenharmony_ci ((sbp)->s_v1.s_journal.jp_journal_magic = cpu_to_le32(v)) 1438c2ecf20Sopenharmony_ci#define sb_jp_journal_max_batch(sbp) \ 1448c2ecf20Sopenharmony_ci (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_max_batch)) 1458c2ecf20Sopenharmony_ci#define set_sb_jp_journal_max_batch(sbp,v) \ 1468c2ecf20Sopenharmony_ci ((sbp)->s_v1.s_journal.jp_journal_max_batch = cpu_to_le32(v)) 1478c2ecf20Sopenharmony_ci#define sb_jp_jourmal_max_commit_age(sbp) \ 1488c2ecf20Sopenharmony_ci (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_max_commit_age)) 1498c2ecf20Sopenharmony_ci#define set_sb_jp_journal_max_commit_age(sbp,v) \ 1508c2ecf20Sopenharmony_ci ((sbp)->s_v1.s_journal.jp_journal_max_commit_age = cpu_to_le32(v)) 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci#define sb_blocksize(sbp) (le16_to_cpu((sbp)->s_v1.s_blocksize)) 1538c2ecf20Sopenharmony_ci#define set_sb_blocksize(sbp,v) ((sbp)->s_v1.s_blocksize = cpu_to_le16(v)) 1548c2ecf20Sopenharmony_ci#define sb_oid_maxsize(sbp) (le16_to_cpu((sbp)->s_v1.s_oid_maxsize)) 1558c2ecf20Sopenharmony_ci#define set_sb_oid_maxsize(sbp,v) ((sbp)->s_v1.s_oid_maxsize = cpu_to_le16(v)) 1568c2ecf20Sopenharmony_ci#define sb_oid_cursize(sbp) (le16_to_cpu((sbp)->s_v1.s_oid_cursize)) 1578c2ecf20Sopenharmony_ci#define set_sb_oid_cursize(sbp,v) ((sbp)->s_v1.s_oid_cursize = cpu_to_le16(v)) 1588c2ecf20Sopenharmony_ci#define sb_umount_state(sbp) (le16_to_cpu((sbp)->s_v1.s_umount_state)) 1598c2ecf20Sopenharmony_ci#define set_sb_umount_state(sbp,v) ((sbp)->s_v1.s_umount_state = cpu_to_le16(v)) 1608c2ecf20Sopenharmony_ci#define sb_fs_state(sbp) (le16_to_cpu((sbp)->s_v1.s_fs_state)) 1618c2ecf20Sopenharmony_ci#define set_sb_fs_state(sbp,v) ((sbp)->s_v1.s_fs_state = cpu_to_le16(v)) 1628c2ecf20Sopenharmony_ci#define sb_hash_function_code(sbp) \ 1638c2ecf20Sopenharmony_ci (le32_to_cpu((sbp)->s_v1.s_hash_function_code)) 1648c2ecf20Sopenharmony_ci#define set_sb_hash_function_code(sbp,v) \ 1658c2ecf20Sopenharmony_ci ((sbp)->s_v1.s_hash_function_code = cpu_to_le32(v)) 1668c2ecf20Sopenharmony_ci#define sb_tree_height(sbp) (le16_to_cpu((sbp)->s_v1.s_tree_height)) 1678c2ecf20Sopenharmony_ci#define set_sb_tree_height(sbp,v) ((sbp)->s_v1.s_tree_height = cpu_to_le16(v)) 1688c2ecf20Sopenharmony_ci#define sb_bmap_nr(sbp) (le16_to_cpu((sbp)->s_v1.s_bmap_nr)) 1698c2ecf20Sopenharmony_ci#define set_sb_bmap_nr(sbp,v) ((sbp)->s_v1.s_bmap_nr = cpu_to_le16(v)) 1708c2ecf20Sopenharmony_ci#define sb_version(sbp) (le16_to_cpu((sbp)->s_v1.s_version)) 1718c2ecf20Sopenharmony_ci#define set_sb_version(sbp,v) ((sbp)->s_v1.s_version = cpu_to_le16(v)) 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci#define sb_mnt_count(sbp) (le16_to_cpu((sbp)->s_mnt_count)) 1748c2ecf20Sopenharmony_ci#define set_sb_mnt_count(sbp, v) ((sbp)->s_mnt_count = cpu_to_le16(v)) 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci#define sb_reserved_for_journal(sbp) \ 1778c2ecf20Sopenharmony_ci (le16_to_cpu((sbp)->s_v1.s_reserved_for_journal)) 1788c2ecf20Sopenharmony_ci#define set_sb_reserved_for_journal(sbp,v) \ 1798c2ecf20Sopenharmony_ci ((sbp)->s_v1.s_reserved_for_journal = cpu_to_le16(v)) 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci/* LOGGING -- */ 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci/* 1848c2ecf20Sopenharmony_ci * These all interelate for performance. 1858c2ecf20Sopenharmony_ci * 1868c2ecf20Sopenharmony_ci * If the journal block count is smaller than n transactions, you lose speed. 1878c2ecf20Sopenharmony_ci * I don't know what n is yet, I'm guessing 8-16. 1888c2ecf20Sopenharmony_ci * 1898c2ecf20Sopenharmony_ci * typical transaction size depends on the application, how often fsync is 1908c2ecf20Sopenharmony_ci * called, and how many metadata blocks you dirty in a 30 second period. 1918c2ecf20Sopenharmony_ci * The more small files (<16k) you use, the larger your transactions will 1928c2ecf20Sopenharmony_ci * be. 1938c2ecf20Sopenharmony_ci * 1948c2ecf20Sopenharmony_ci * If your journal fills faster than dirty buffers get flushed to disk, it 1958c2ecf20Sopenharmony_ci * must flush them before allowing the journal to wrap, which slows things 1968c2ecf20Sopenharmony_ci * down. If you need high speed meta data updates, the journal should be 1978c2ecf20Sopenharmony_ci * big enough to prevent wrapping before dirty meta blocks get to disk. 1988c2ecf20Sopenharmony_ci * 1998c2ecf20Sopenharmony_ci * If the batch max is smaller than the transaction max, you'll waste space 2008c2ecf20Sopenharmony_ci * at the end of the journal because journal_end sets the next transaction 2018c2ecf20Sopenharmony_ci * to start at 0 if the next transaction has any chance of wrapping. 2028c2ecf20Sopenharmony_ci * 2038c2ecf20Sopenharmony_ci * The large the batch max age, the better the speed, and the more meta 2048c2ecf20Sopenharmony_ci * data changes you'll lose after a crash. 2058c2ecf20Sopenharmony_ci */ 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci/* don't mess with these for a while */ 2088c2ecf20Sopenharmony_ci/* we have a node size define somewhere in reiserfs_fs.h. -Hans */ 2098c2ecf20Sopenharmony_ci#define JOURNAL_BLOCK_SIZE 4096 /* BUG gotta get rid of this */ 2108c2ecf20Sopenharmony_ci#define JOURNAL_MAX_CNODE 1500 /* max cnodes to allocate. */ 2118c2ecf20Sopenharmony_ci#define JOURNAL_HASH_SIZE 8192 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci/* number of copies of the bitmaps to have floating. Must be >= 2 */ 2148c2ecf20Sopenharmony_ci#define JOURNAL_NUM_BITMAPS 5 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci/* 2178c2ecf20Sopenharmony_ci * One of these for every block in every transaction 2188c2ecf20Sopenharmony_ci * Each one is in two hash tables. First, a hash of the current transaction, 2198c2ecf20Sopenharmony_ci * and after journal_end, a hash of all the in memory transactions. 2208c2ecf20Sopenharmony_ci * next and prev are used by the current transaction (journal_hash). 2218c2ecf20Sopenharmony_ci * hnext and hprev are used by journal_list_hash. If a block is in more 2228c2ecf20Sopenharmony_ci * than one transaction, the journal_list_hash links it in multiple times. 2238c2ecf20Sopenharmony_ci * This allows flush_journal_list to remove just the cnode belonging to a 2248c2ecf20Sopenharmony_ci * given transaction. 2258c2ecf20Sopenharmony_ci */ 2268c2ecf20Sopenharmony_cistruct reiserfs_journal_cnode { 2278c2ecf20Sopenharmony_ci struct buffer_head *bh; /* real buffer head */ 2288c2ecf20Sopenharmony_ci struct super_block *sb; /* dev of real buffer head */ 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci /* block number of real buffer head, == 0 when buffer on disk */ 2318c2ecf20Sopenharmony_ci __u32 blocknr; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci unsigned long state; 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci /* journal list this cnode lives in */ 2368c2ecf20Sopenharmony_ci struct reiserfs_journal_list *jlist; 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci struct reiserfs_journal_cnode *next; /* next in transaction list */ 2398c2ecf20Sopenharmony_ci struct reiserfs_journal_cnode *prev; /* prev in transaction list */ 2408c2ecf20Sopenharmony_ci struct reiserfs_journal_cnode *hprev; /* prev in hash list */ 2418c2ecf20Sopenharmony_ci struct reiserfs_journal_cnode *hnext; /* next in hash list */ 2428c2ecf20Sopenharmony_ci}; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_cistruct reiserfs_bitmap_node { 2458c2ecf20Sopenharmony_ci int id; 2468c2ecf20Sopenharmony_ci char *data; 2478c2ecf20Sopenharmony_ci struct list_head list; 2488c2ecf20Sopenharmony_ci}; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_cistruct reiserfs_list_bitmap { 2518c2ecf20Sopenharmony_ci struct reiserfs_journal_list *journal_list; 2528c2ecf20Sopenharmony_ci struct reiserfs_bitmap_node **bitmaps; 2538c2ecf20Sopenharmony_ci}; 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci/* 2568c2ecf20Sopenharmony_ci * one of these for each transaction. The most important part here is the 2578c2ecf20Sopenharmony_ci * j_realblock. this list of cnodes is used to hash all the blocks in all 2588c2ecf20Sopenharmony_ci * the commits, to mark all the real buffer heads dirty once all the commits 2598c2ecf20Sopenharmony_ci * hit the disk, and to make sure every real block in a transaction is on 2608c2ecf20Sopenharmony_ci * disk before allowing the log area to be overwritten 2618c2ecf20Sopenharmony_ci */ 2628c2ecf20Sopenharmony_cistruct reiserfs_journal_list { 2638c2ecf20Sopenharmony_ci unsigned long j_start; 2648c2ecf20Sopenharmony_ci unsigned long j_state; 2658c2ecf20Sopenharmony_ci unsigned long j_len; 2668c2ecf20Sopenharmony_ci atomic_t j_nonzerolen; 2678c2ecf20Sopenharmony_ci atomic_t j_commit_left; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci /* all commits older than this on disk */ 2708c2ecf20Sopenharmony_ci atomic_t j_older_commits_done; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci struct mutex j_commit_mutex; 2738c2ecf20Sopenharmony_ci unsigned int j_trans_id; 2748c2ecf20Sopenharmony_ci time64_t j_timestamp; /* write-only but useful for crash dump analysis */ 2758c2ecf20Sopenharmony_ci struct reiserfs_list_bitmap *j_list_bitmap; 2768c2ecf20Sopenharmony_ci struct buffer_head *j_commit_bh; /* commit buffer head */ 2778c2ecf20Sopenharmony_ci struct reiserfs_journal_cnode *j_realblock; 2788c2ecf20Sopenharmony_ci struct reiserfs_journal_cnode *j_freedlist; /* list of buffers that were freed during this trans. free each of these on flush */ 2798c2ecf20Sopenharmony_ci /* time ordered list of all active transactions */ 2808c2ecf20Sopenharmony_ci struct list_head j_list; 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci /* 2838c2ecf20Sopenharmony_ci * time ordered list of all transactions we haven't tried 2848c2ecf20Sopenharmony_ci * to flush yet 2858c2ecf20Sopenharmony_ci */ 2868c2ecf20Sopenharmony_ci struct list_head j_working_list; 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci /* list of tail conversion targets in need of flush before commit */ 2898c2ecf20Sopenharmony_ci struct list_head j_tail_bh_list; 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci /* list of data=ordered buffers in need of flush before commit */ 2928c2ecf20Sopenharmony_ci struct list_head j_bh_list; 2938c2ecf20Sopenharmony_ci int j_refcount; 2948c2ecf20Sopenharmony_ci}; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_cistruct reiserfs_journal { 2978c2ecf20Sopenharmony_ci struct buffer_head **j_ap_blocks; /* journal blocks on disk */ 2988c2ecf20Sopenharmony_ci /* newest journal block */ 2998c2ecf20Sopenharmony_ci struct reiserfs_journal_cnode *j_last; 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci /* oldest journal block. start here for traverse */ 3028c2ecf20Sopenharmony_ci struct reiserfs_journal_cnode *j_first; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci struct block_device *j_dev_bd; 3058c2ecf20Sopenharmony_ci fmode_t j_dev_mode; 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci /* first block on s_dev of reserved area journal */ 3088c2ecf20Sopenharmony_ci int j_1st_reserved_block; 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci unsigned long j_state; 3118c2ecf20Sopenharmony_ci unsigned int j_trans_id; 3128c2ecf20Sopenharmony_ci unsigned long j_mount_id; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci /* start of current waiting commit (index into j_ap_blocks) */ 3158c2ecf20Sopenharmony_ci unsigned long j_start; 3168c2ecf20Sopenharmony_ci unsigned long j_len; /* length of current waiting commit */ 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci /* number of buffers requested by journal_begin() */ 3198c2ecf20Sopenharmony_ci unsigned long j_len_alloc; 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci atomic_t j_wcount; /* count of writers for current commit */ 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci /* batch count. allows turning X transactions into 1 */ 3248c2ecf20Sopenharmony_ci unsigned long j_bcount; 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci /* first unflushed transactions offset */ 3278c2ecf20Sopenharmony_ci unsigned long j_first_unflushed_offset; 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci /* last fully flushed journal timestamp */ 3308c2ecf20Sopenharmony_ci unsigned j_last_flush_trans_id; 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci struct buffer_head *j_header_bh; 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci time64_t j_trans_start_time; /* time this transaction started */ 3358c2ecf20Sopenharmony_ci struct mutex j_mutex; 3368c2ecf20Sopenharmony_ci struct mutex j_flush_mutex; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci /* wait for current transaction to finish before starting new one */ 3398c2ecf20Sopenharmony_ci wait_queue_head_t j_join_wait; 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci atomic_t j_jlock; /* lock for j_join_wait */ 3428c2ecf20Sopenharmony_ci int j_list_bitmap_index; /* number of next list bitmap to use */ 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci /* no more journal begins allowed. MUST sleep on j_join_wait */ 3458c2ecf20Sopenharmony_ci int j_must_wait; 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci /* next journal_end will flush all journal list */ 3488c2ecf20Sopenharmony_ci int j_next_full_flush; 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci /* next journal_end will flush all async commits */ 3518c2ecf20Sopenharmony_ci int j_next_async_flush; 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci int j_cnode_used; /* number of cnodes on the used list */ 3548c2ecf20Sopenharmony_ci int j_cnode_free; /* number of cnodes on the free list */ 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci /* max number of blocks in a transaction. */ 3578c2ecf20Sopenharmony_ci unsigned int j_trans_max; 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci /* max number of blocks to batch into a trans */ 3608c2ecf20Sopenharmony_ci unsigned int j_max_batch; 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci /* in seconds, how old can an async commit be */ 3638c2ecf20Sopenharmony_ci unsigned int j_max_commit_age; 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci /* in seconds, how old can a transaction be */ 3668c2ecf20Sopenharmony_ci unsigned int j_max_trans_age; 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci /* the default for the max commit age */ 3698c2ecf20Sopenharmony_ci unsigned int j_default_max_commit_age; 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci struct reiserfs_journal_cnode *j_cnode_free_list; 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci /* orig pointer returned from vmalloc */ 3748c2ecf20Sopenharmony_ci struct reiserfs_journal_cnode *j_cnode_free_orig; 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci struct reiserfs_journal_list *j_current_jl; 3778c2ecf20Sopenharmony_ci int j_free_bitmap_nodes; 3788c2ecf20Sopenharmony_ci int j_used_bitmap_nodes; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci int j_num_lists; /* total number of active transactions */ 3818c2ecf20Sopenharmony_ci int j_num_work_lists; /* number that need attention from kreiserfsd */ 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci /* debugging to make sure things are flushed in order */ 3848c2ecf20Sopenharmony_ci unsigned int j_last_flush_id; 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci /* debugging to make sure things are committed in order */ 3878c2ecf20Sopenharmony_ci unsigned int j_last_commit_id; 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci struct list_head j_bitmap_nodes; 3908c2ecf20Sopenharmony_ci struct list_head j_dirty_buffers; 3918c2ecf20Sopenharmony_ci spinlock_t j_dirty_buffers_lock; /* protects j_dirty_buffers */ 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci /* list of all active transactions */ 3948c2ecf20Sopenharmony_ci struct list_head j_journal_list; 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci /* lists that haven't been touched by writeback attempts */ 3978c2ecf20Sopenharmony_ci struct list_head j_working_list; 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci /* hash table for real buffer heads in current trans */ 4008c2ecf20Sopenharmony_ci struct reiserfs_journal_cnode *j_hash_table[JOURNAL_HASH_SIZE]; 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci /* hash table for all the real buffer heads in all the transactions */ 4038c2ecf20Sopenharmony_ci struct reiserfs_journal_cnode *j_list_hash_table[JOURNAL_HASH_SIZE]; 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci /* array of bitmaps to record the deleted blocks */ 4068c2ecf20Sopenharmony_ci struct reiserfs_list_bitmap j_list_bitmap[JOURNAL_NUM_BITMAPS]; 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci /* list of inodes which have preallocated blocks */ 4098c2ecf20Sopenharmony_ci struct list_head j_prealloc_list; 4108c2ecf20Sopenharmony_ci int j_persistent_trans; 4118c2ecf20Sopenharmony_ci unsigned long j_max_trans_size; 4128c2ecf20Sopenharmony_ci unsigned long j_max_batch_size; 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci int j_errno; 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci /* when flushing ordered buffers, throttle new ordered writers */ 4178c2ecf20Sopenharmony_ci struct delayed_work j_work; 4188c2ecf20Sopenharmony_ci struct super_block *j_work_sb; 4198c2ecf20Sopenharmony_ci atomic_t j_async_throttle; 4208c2ecf20Sopenharmony_ci}; 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_cienum journal_state_bits { 4238c2ecf20Sopenharmony_ci J_WRITERS_BLOCKED = 1, /* set when new writers not allowed */ 4248c2ecf20Sopenharmony_ci J_WRITERS_QUEUED, /* set when log is full due to too many writers */ 4258c2ecf20Sopenharmony_ci J_ABORTED, /* set when log is aborted */ 4268c2ecf20Sopenharmony_ci}; 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci/* ick. magic string to find desc blocks in the journal */ 4298c2ecf20Sopenharmony_ci#define JOURNAL_DESC_MAGIC "ReIsErLB" 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_citypedef __u32(*hashf_t) (const signed char *, int); 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_cistruct reiserfs_bitmap_info { 4348c2ecf20Sopenharmony_ci __u32 free_count; 4358c2ecf20Sopenharmony_ci}; 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_cistruct proc_dir_entry; 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci#if defined( CONFIG_PROC_FS ) && defined( CONFIG_REISERFS_PROC_INFO ) 4408c2ecf20Sopenharmony_citypedef unsigned long int stat_cnt_t; 4418c2ecf20Sopenharmony_citypedef struct reiserfs_proc_info_data { 4428c2ecf20Sopenharmony_ci spinlock_t lock; 4438c2ecf20Sopenharmony_ci int exiting; 4448c2ecf20Sopenharmony_ci int max_hash_collisions; 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci stat_cnt_t breads; 4478c2ecf20Sopenharmony_ci stat_cnt_t bread_miss; 4488c2ecf20Sopenharmony_ci stat_cnt_t search_by_key; 4498c2ecf20Sopenharmony_ci stat_cnt_t search_by_key_fs_changed; 4508c2ecf20Sopenharmony_ci stat_cnt_t search_by_key_restarted; 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci stat_cnt_t insert_item_restarted; 4538c2ecf20Sopenharmony_ci stat_cnt_t paste_into_item_restarted; 4548c2ecf20Sopenharmony_ci stat_cnt_t cut_from_item_restarted; 4558c2ecf20Sopenharmony_ci stat_cnt_t delete_solid_item_restarted; 4568c2ecf20Sopenharmony_ci stat_cnt_t delete_item_restarted; 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ci stat_cnt_t leaked_oid; 4598c2ecf20Sopenharmony_ci stat_cnt_t leaves_removable; 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci /* 4628c2ecf20Sopenharmony_ci * balances per level. 4638c2ecf20Sopenharmony_ci * Use explicit 5 as MAX_HEIGHT is not visible yet. 4648c2ecf20Sopenharmony_ci */ 4658c2ecf20Sopenharmony_ci stat_cnt_t balance_at[5]; /* XXX */ 4668c2ecf20Sopenharmony_ci /* sbk == search_by_key */ 4678c2ecf20Sopenharmony_ci stat_cnt_t sbk_read_at[5]; /* XXX */ 4688c2ecf20Sopenharmony_ci stat_cnt_t sbk_fs_changed[5]; 4698c2ecf20Sopenharmony_ci stat_cnt_t sbk_restarted[5]; 4708c2ecf20Sopenharmony_ci stat_cnt_t items_at[5]; /* XXX */ 4718c2ecf20Sopenharmony_ci stat_cnt_t free_at[5]; /* XXX */ 4728c2ecf20Sopenharmony_ci stat_cnt_t can_node_be_removed[5]; /* XXX */ 4738c2ecf20Sopenharmony_ci long int lnum[5]; /* XXX */ 4748c2ecf20Sopenharmony_ci long int rnum[5]; /* XXX */ 4758c2ecf20Sopenharmony_ci long int lbytes[5]; /* XXX */ 4768c2ecf20Sopenharmony_ci long int rbytes[5]; /* XXX */ 4778c2ecf20Sopenharmony_ci stat_cnt_t get_neighbors[5]; 4788c2ecf20Sopenharmony_ci stat_cnt_t get_neighbors_restart[5]; 4798c2ecf20Sopenharmony_ci stat_cnt_t need_l_neighbor[5]; 4808c2ecf20Sopenharmony_ci stat_cnt_t need_r_neighbor[5]; 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci stat_cnt_t free_block; 4838c2ecf20Sopenharmony_ci struct __scan_bitmap_stats { 4848c2ecf20Sopenharmony_ci stat_cnt_t call; 4858c2ecf20Sopenharmony_ci stat_cnt_t wait; 4868c2ecf20Sopenharmony_ci stat_cnt_t bmap; 4878c2ecf20Sopenharmony_ci stat_cnt_t retry; 4888c2ecf20Sopenharmony_ci stat_cnt_t in_journal_hint; 4898c2ecf20Sopenharmony_ci stat_cnt_t in_journal_nohint; 4908c2ecf20Sopenharmony_ci stat_cnt_t stolen; 4918c2ecf20Sopenharmony_ci } scan_bitmap; 4928c2ecf20Sopenharmony_ci struct __journal_stats { 4938c2ecf20Sopenharmony_ci stat_cnt_t in_journal; 4948c2ecf20Sopenharmony_ci stat_cnt_t in_journal_bitmap; 4958c2ecf20Sopenharmony_ci stat_cnt_t in_journal_reusable; 4968c2ecf20Sopenharmony_ci stat_cnt_t lock_journal; 4978c2ecf20Sopenharmony_ci stat_cnt_t lock_journal_wait; 4988c2ecf20Sopenharmony_ci stat_cnt_t journal_being; 4998c2ecf20Sopenharmony_ci stat_cnt_t journal_relock_writers; 5008c2ecf20Sopenharmony_ci stat_cnt_t journal_relock_wcount; 5018c2ecf20Sopenharmony_ci stat_cnt_t mark_dirty; 5028c2ecf20Sopenharmony_ci stat_cnt_t mark_dirty_already; 5038c2ecf20Sopenharmony_ci stat_cnt_t mark_dirty_notjournal; 5048c2ecf20Sopenharmony_ci stat_cnt_t restore_prepared; 5058c2ecf20Sopenharmony_ci stat_cnt_t prepare; 5068c2ecf20Sopenharmony_ci stat_cnt_t prepare_retry; 5078c2ecf20Sopenharmony_ci } journal; 5088c2ecf20Sopenharmony_ci} reiserfs_proc_info_data_t; 5098c2ecf20Sopenharmony_ci#else 5108c2ecf20Sopenharmony_citypedef struct reiserfs_proc_info_data { 5118c2ecf20Sopenharmony_ci} reiserfs_proc_info_data_t; 5128c2ecf20Sopenharmony_ci#endif 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci/* Number of quota types we support */ 5158c2ecf20Sopenharmony_ci#define REISERFS_MAXQUOTAS 2 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci/* reiserfs union of in-core super block data */ 5188c2ecf20Sopenharmony_cistruct reiserfs_sb_info { 5198c2ecf20Sopenharmony_ci /* Buffer containing the super block */ 5208c2ecf20Sopenharmony_ci struct buffer_head *s_sbh; 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci /* Pointer to the on-disk super block in the buffer */ 5238c2ecf20Sopenharmony_ci struct reiserfs_super_block *s_rs; 5248c2ecf20Sopenharmony_ci struct reiserfs_bitmap_info *s_ap_bitmap; 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci /* pointer to journal information */ 5278c2ecf20Sopenharmony_ci struct reiserfs_journal *s_journal; 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci unsigned short s_mount_state; /* reiserfs state (valid, invalid) */ 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci /* Serialize writers access, replace the old bkl */ 5328c2ecf20Sopenharmony_ci struct mutex lock; 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci /* Owner of the lock (can be recursive) */ 5358c2ecf20Sopenharmony_ci struct task_struct *lock_owner; 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci /* Depth of the lock, start from -1 like the bkl */ 5388c2ecf20Sopenharmony_ci int lock_depth; 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci struct workqueue_struct *commit_wq; 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci /* Comment? -Hans */ 5438c2ecf20Sopenharmony_ci void (*end_io_handler) (struct buffer_head *, int); 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_ci /* 5468c2ecf20Sopenharmony_ci * pointer to function which is used to sort names in directory. 5478c2ecf20Sopenharmony_ci * Set on mount 5488c2ecf20Sopenharmony_ci */ 5498c2ecf20Sopenharmony_ci hashf_t s_hash_function; 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci /* reiserfs's mount options are set here */ 5528c2ecf20Sopenharmony_ci unsigned long s_mount_opt; 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci /* This is a structure that describes block allocator options */ 5558c2ecf20Sopenharmony_ci struct { 5568c2ecf20Sopenharmony_ci /* Bitfield for enable/disable kind of options */ 5578c2ecf20Sopenharmony_ci unsigned long bits; 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci /* 5608c2ecf20Sopenharmony_ci * size started from which we consider file 5618c2ecf20Sopenharmony_ci * to be a large one (in blocks) 5628c2ecf20Sopenharmony_ci */ 5638c2ecf20Sopenharmony_ci unsigned long large_file_size; 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci int border; /* percentage of disk, border takes */ 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci /* 5688c2ecf20Sopenharmony_ci * Minimal file size (in blocks) starting 5698c2ecf20Sopenharmony_ci * from which we do preallocations 5708c2ecf20Sopenharmony_ci */ 5718c2ecf20Sopenharmony_ci int preallocmin; 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci /* 5748c2ecf20Sopenharmony_ci * Number of blocks we try to prealloc when file 5758c2ecf20Sopenharmony_ci * reaches preallocmin size (in blocks) or prealloc_list 5768c2ecf20Sopenharmony_ci is empty. 5778c2ecf20Sopenharmony_ci */ 5788c2ecf20Sopenharmony_ci int preallocsize; 5798c2ecf20Sopenharmony_ci } s_alloc_options; 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci /* Comment? -Hans */ 5828c2ecf20Sopenharmony_ci wait_queue_head_t s_wait; 5838c2ecf20Sopenharmony_ci /* increased by one every time the tree gets re-balanced */ 5848c2ecf20Sopenharmony_ci atomic_t s_generation_counter; 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci /* File system properties. Currently holds on-disk FS format */ 5878c2ecf20Sopenharmony_ci unsigned long s_properties; 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci /* session statistics */ 5908c2ecf20Sopenharmony_ci int s_disk_reads; 5918c2ecf20Sopenharmony_ci int s_disk_writes; 5928c2ecf20Sopenharmony_ci int s_fix_nodes; 5938c2ecf20Sopenharmony_ci int s_do_balance; 5948c2ecf20Sopenharmony_ci int s_unneeded_left_neighbor; 5958c2ecf20Sopenharmony_ci int s_good_search_by_key_reada; 5968c2ecf20Sopenharmony_ci int s_bmaps; 5978c2ecf20Sopenharmony_ci int s_bmaps_without_search; 5988c2ecf20Sopenharmony_ci int s_direct2indirect; 5998c2ecf20Sopenharmony_ci int s_indirect2direct; 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci /* 6028c2ecf20Sopenharmony_ci * set up when it's ok for reiserfs_read_inode2() to read from 6038c2ecf20Sopenharmony_ci * disk inode with nlink==0. Currently this is only used during 6048c2ecf20Sopenharmony_ci * finish_unfinished() processing at mount time 6058c2ecf20Sopenharmony_ci */ 6068c2ecf20Sopenharmony_ci int s_is_unlinked_ok; 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci reiserfs_proc_info_data_t s_proc_info_data; 6098c2ecf20Sopenharmony_ci struct proc_dir_entry *procdir; 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci /* amount of blocks reserved for further allocations */ 6128c2ecf20Sopenharmony_ci int reserved_blocks; 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci /* this lock on now only used to protect reserved_blocks variable */ 6168c2ecf20Sopenharmony_ci spinlock_t bitmap_lock; 6178c2ecf20Sopenharmony_ci struct dentry *priv_root; /* root of /.reiserfs_priv */ 6188c2ecf20Sopenharmony_ci struct dentry *xattr_root; /* root of /.reiserfs_priv/xattrs */ 6198c2ecf20Sopenharmony_ci int j_errno; 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci int work_queued; /* non-zero delayed work is queued */ 6228c2ecf20Sopenharmony_ci struct delayed_work old_work; /* old transactions flush delayed work */ 6238c2ecf20Sopenharmony_ci spinlock_t old_work_lock; /* protects old_work and work_queued */ 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci#ifdef CONFIG_QUOTA 6268c2ecf20Sopenharmony_ci char *s_qf_names[REISERFS_MAXQUOTAS]; 6278c2ecf20Sopenharmony_ci int s_jquota_fmt; 6288c2ecf20Sopenharmony_ci#endif 6298c2ecf20Sopenharmony_ci char *s_jdev; /* Stored jdev for mount option showing */ 6308c2ecf20Sopenharmony_ci#ifdef CONFIG_REISERFS_CHECK 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci /* 6338c2ecf20Sopenharmony_ci * Detects whether more than one copy of tb exists per superblock 6348c2ecf20Sopenharmony_ci * as a means of checking whether do_balance is executing 6358c2ecf20Sopenharmony_ci * concurrently against another tree reader/writer on a same 6368c2ecf20Sopenharmony_ci * mount point. 6378c2ecf20Sopenharmony_ci */ 6388c2ecf20Sopenharmony_ci struct tree_balance *cur_tb; 6398c2ecf20Sopenharmony_ci#endif 6408c2ecf20Sopenharmony_ci}; 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci/* Definitions of reiserfs on-disk properties: */ 6438c2ecf20Sopenharmony_ci#define REISERFS_3_5 0 6448c2ecf20Sopenharmony_ci#define REISERFS_3_6 1 6458c2ecf20Sopenharmony_ci#define REISERFS_OLD_FORMAT 2 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci/* Mount options */ 6488c2ecf20Sopenharmony_cienum reiserfs_mount_options { 6498c2ecf20Sopenharmony_ci /* large tails will be created in a session */ 6508c2ecf20Sopenharmony_ci REISERFS_LARGETAIL, 6518c2ecf20Sopenharmony_ci /* 6528c2ecf20Sopenharmony_ci * small (for files less than block size) tails will 6538c2ecf20Sopenharmony_ci * be created in a session 6548c2ecf20Sopenharmony_ci */ 6558c2ecf20Sopenharmony_ci REISERFS_SMALLTAIL, 6568c2ecf20Sopenharmony_ci 6578c2ecf20Sopenharmony_ci /* replay journal and return 0. Use by fsck */ 6588c2ecf20Sopenharmony_ci REPLAYONLY, 6598c2ecf20Sopenharmony_ci 6608c2ecf20Sopenharmony_ci /* 6618c2ecf20Sopenharmony_ci * -o conv: causes conversion of old format super block to the 6628c2ecf20Sopenharmony_ci * new format. If not specified - old partition will be dealt 6638c2ecf20Sopenharmony_ci * with in a manner of 3.5.x 6648c2ecf20Sopenharmony_ci */ 6658c2ecf20Sopenharmony_ci REISERFS_CONVERT, 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci /* 6688c2ecf20Sopenharmony_ci * -o hash={tea, rupasov, r5, detect} is meant for properly mounting 6698c2ecf20Sopenharmony_ci * reiserfs disks from 3.5.19 or earlier. 99% of the time, this 6708c2ecf20Sopenharmony_ci * option is not required. If the normal autodection code can't 6718c2ecf20Sopenharmony_ci * determine which hash to use (because both hashes had the same 6728c2ecf20Sopenharmony_ci * value for a file) use this option to force a specific hash. 6738c2ecf20Sopenharmony_ci * It won't allow you to override the existing hash on the FS, so 6748c2ecf20Sopenharmony_ci * if you have a tea hash disk, and mount with -o hash=rupasov, 6758c2ecf20Sopenharmony_ci * the mount will fail. 6768c2ecf20Sopenharmony_ci */ 6778c2ecf20Sopenharmony_ci FORCE_TEA_HASH, /* try to force tea hash on mount */ 6788c2ecf20Sopenharmony_ci FORCE_RUPASOV_HASH, /* try to force rupasov hash on mount */ 6798c2ecf20Sopenharmony_ci FORCE_R5_HASH, /* try to force rupasov hash on mount */ 6808c2ecf20Sopenharmony_ci FORCE_HASH_DETECT, /* try to detect hash function on mount */ 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci REISERFS_DATA_LOG, 6838c2ecf20Sopenharmony_ci REISERFS_DATA_ORDERED, 6848c2ecf20Sopenharmony_ci REISERFS_DATA_WRITEBACK, 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ci /* 6878c2ecf20Sopenharmony_ci * used for testing experimental features, makes benchmarking new 6888c2ecf20Sopenharmony_ci * features with and without more convenient, should never be used by 6898c2ecf20Sopenharmony_ci * users in any code shipped to users (ideally) 6908c2ecf20Sopenharmony_ci */ 6918c2ecf20Sopenharmony_ci 6928c2ecf20Sopenharmony_ci REISERFS_NO_BORDER, 6938c2ecf20Sopenharmony_ci REISERFS_NO_UNHASHED_RELOCATION, 6948c2ecf20Sopenharmony_ci REISERFS_HASHED_RELOCATION, 6958c2ecf20Sopenharmony_ci REISERFS_ATTRS, 6968c2ecf20Sopenharmony_ci REISERFS_XATTRS_USER, 6978c2ecf20Sopenharmony_ci REISERFS_POSIXACL, 6988c2ecf20Sopenharmony_ci REISERFS_EXPOSE_PRIVROOT, 6998c2ecf20Sopenharmony_ci REISERFS_BARRIER_NONE, 7008c2ecf20Sopenharmony_ci REISERFS_BARRIER_FLUSH, 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci /* Actions on error */ 7038c2ecf20Sopenharmony_ci REISERFS_ERROR_PANIC, 7048c2ecf20Sopenharmony_ci REISERFS_ERROR_RO, 7058c2ecf20Sopenharmony_ci REISERFS_ERROR_CONTINUE, 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_ci REISERFS_USRQUOTA, /* User quota option specified */ 7088c2ecf20Sopenharmony_ci REISERFS_GRPQUOTA, /* Group quota option specified */ 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci REISERFS_TEST1, 7118c2ecf20Sopenharmony_ci REISERFS_TEST2, 7128c2ecf20Sopenharmony_ci REISERFS_TEST3, 7138c2ecf20Sopenharmony_ci REISERFS_TEST4, 7148c2ecf20Sopenharmony_ci REISERFS_UNSUPPORTED_OPT, 7158c2ecf20Sopenharmony_ci}; 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci#define reiserfs_r5_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_R5_HASH)) 7188c2ecf20Sopenharmony_ci#define reiserfs_rupasov_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_RUPASOV_HASH)) 7198c2ecf20Sopenharmony_ci#define reiserfs_tea_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_TEA_HASH)) 7208c2ecf20Sopenharmony_ci#define reiserfs_hash_detect(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_HASH_DETECT)) 7218c2ecf20Sopenharmony_ci#define reiserfs_no_border(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_NO_BORDER)) 7228c2ecf20Sopenharmony_ci#define reiserfs_no_unhashed_relocation(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_NO_UNHASHED_RELOCATION)) 7238c2ecf20Sopenharmony_ci#define reiserfs_hashed_relocation(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_HASHED_RELOCATION)) 7248c2ecf20Sopenharmony_ci#define reiserfs_test4(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TEST4)) 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci#define have_large_tails(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_LARGETAIL)) 7278c2ecf20Sopenharmony_ci#define have_small_tails(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_SMALLTAIL)) 7288c2ecf20Sopenharmony_ci#define replay_only(s) (REISERFS_SB(s)->s_mount_opt & (1 << REPLAYONLY)) 7298c2ecf20Sopenharmony_ci#define reiserfs_attrs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ATTRS)) 7308c2ecf20Sopenharmony_ci#define old_format_only(s) (REISERFS_SB(s)->s_properties & (1 << REISERFS_3_5)) 7318c2ecf20Sopenharmony_ci#define convert_reiserfs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_CONVERT)) 7328c2ecf20Sopenharmony_ci#define reiserfs_data_log(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_LOG)) 7338c2ecf20Sopenharmony_ci#define reiserfs_data_ordered(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_ORDERED)) 7348c2ecf20Sopenharmony_ci#define reiserfs_data_writeback(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_WRITEBACK)) 7358c2ecf20Sopenharmony_ci#define reiserfs_xattrs_user(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_XATTRS_USER)) 7368c2ecf20Sopenharmony_ci#define reiserfs_posixacl(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_POSIXACL)) 7378c2ecf20Sopenharmony_ci#define reiserfs_expose_privroot(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_EXPOSE_PRIVROOT)) 7388c2ecf20Sopenharmony_ci#define reiserfs_xattrs_optional(s) (reiserfs_xattrs_user(s) || reiserfs_posixacl(s)) 7398c2ecf20Sopenharmony_ci#define reiserfs_barrier_none(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_BARRIER_NONE)) 7408c2ecf20Sopenharmony_ci#define reiserfs_barrier_flush(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_BARRIER_FLUSH)) 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ci#define reiserfs_error_panic(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_PANIC)) 7438c2ecf20Sopenharmony_ci#define reiserfs_error_ro(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_RO)) 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_civoid reiserfs_file_buffer(struct buffer_head *bh, int list); 7468c2ecf20Sopenharmony_ciextern struct file_system_type reiserfs_fs_type; 7478c2ecf20Sopenharmony_ciint reiserfs_resize(struct super_block *, unsigned long); 7488c2ecf20Sopenharmony_ci 7498c2ecf20Sopenharmony_ci#define CARRY_ON 0 7508c2ecf20Sopenharmony_ci#define SCHEDULE_OCCURRED 1 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci#define SB_BUFFER_WITH_SB(s) (REISERFS_SB(s)->s_sbh) 7538c2ecf20Sopenharmony_ci#define SB_JOURNAL(s) (REISERFS_SB(s)->s_journal) 7548c2ecf20Sopenharmony_ci#define SB_JOURNAL_1st_RESERVED_BLOCK(s) (SB_JOURNAL(s)->j_1st_reserved_block) 7558c2ecf20Sopenharmony_ci#define SB_JOURNAL_LEN_FREE(s) (SB_JOURNAL(s)->j_journal_len_free) 7568c2ecf20Sopenharmony_ci#define SB_AP_BITMAP(s) (REISERFS_SB(s)->s_ap_bitmap) 7578c2ecf20Sopenharmony_ci 7588c2ecf20Sopenharmony_ci#define SB_DISK_JOURNAL_HEAD(s) (SB_JOURNAL(s)->j_header_bh->) 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_ci#define reiserfs_is_journal_aborted(journal) (unlikely (__reiserfs_is_journal_aborted (journal))) 7618c2ecf20Sopenharmony_cistatic inline int __reiserfs_is_journal_aborted(struct reiserfs_journal 7628c2ecf20Sopenharmony_ci *journal) 7638c2ecf20Sopenharmony_ci{ 7648c2ecf20Sopenharmony_ci return test_bit(J_ABORTED, &journal->j_state); 7658c2ecf20Sopenharmony_ci} 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_ci/* 7688c2ecf20Sopenharmony_ci * Locking primitives. The write lock is a per superblock 7698c2ecf20Sopenharmony_ci * special mutex that has properties close to the Big Kernel Lock 7708c2ecf20Sopenharmony_ci * which was used in the previous locking scheme. 7718c2ecf20Sopenharmony_ci */ 7728c2ecf20Sopenharmony_civoid reiserfs_write_lock(struct super_block *s); 7738c2ecf20Sopenharmony_civoid reiserfs_write_unlock(struct super_block *s); 7748c2ecf20Sopenharmony_ciint __must_check reiserfs_write_unlock_nested(struct super_block *s); 7758c2ecf20Sopenharmony_civoid reiserfs_write_lock_nested(struct super_block *s, int depth); 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ci#ifdef CONFIG_REISERFS_CHECK 7788c2ecf20Sopenharmony_civoid reiserfs_lock_check_recursive(struct super_block *s); 7798c2ecf20Sopenharmony_ci#else 7808c2ecf20Sopenharmony_cistatic inline void reiserfs_lock_check_recursive(struct super_block *s) { } 7818c2ecf20Sopenharmony_ci#endif 7828c2ecf20Sopenharmony_ci 7838c2ecf20Sopenharmony_ci/* 7848c2ecf20Sopenharmony_ci * Several mutexes depend on the write lock. 7858c2ecf20Sopenharmony_ci * However sometimes we want to relax the write lock while we hold 7868c2ecf20Sopenharmony_ci * these mutexes, according to the release/reacquire on schedule() 7878c2ecf20Sopenharmony_ci * properties of the Bkl that were used. 7888c2ecf20Sopenharmony_ci * Reiserfs performances and locking were based on this scheme. 7898c2ecf20Sopenharmony_ci * Now that the write lock is a mutex and not the bkl anymore, doing so 7908c2ecf20Sopenharmony_ci * may result in a deadlock: 7918c2ecf20Sopenharmony_ci * 7928c2ecf20Sopenharmony_ci * A acquire write_lock 7938c2ecf20Sopenharmony_ci * A acquire j_commit_mutex 7948c2ecf20Sopenharmony_ci * A release write_lock and wait for something 7958c2ecf20Sopenharmony_ci * B acquire write_lock 7968c2ecf20Sopenharmony_ci * B can't acquire j_commit_mutex and sleep 7978c2ecf20Sopenharmony_ci * A can't acquire write lock anymore 7988c2ecf20Sopenharmony_ci * deadlock 7998c2ecf20Sopenharmony_ci * 8008c2ecf20Sopenharmony_ci * What we do here is avoiding such deadlock by playing the same game 8018c2ecf20Sopenharmony_ci * than the Bkl: if we can't acquire a mutex that depends on the write lock, 8028c2ecf20Sopenharmony_ci * we release the write lock, wait a bit and then retry. 8038c2ecf20Sopenharmony_ci * 8048c2ecf20Sopenharmony_ci * The mutexes concerned by this hack are: 8058c2ecf20Sopenharmony_ci * - The commit mutex of a journal list 8068c2ecf20Sopenharmony_ci * - The flush mutex 8078c2ecf20Sopenharmony_ci * - The journal lock 8088c2ecf20Sopenharmony_ci * - The inode mutex 8098c2ecf20Sopenharmony_ci */ 8108c2ecf20Sopenharmony_cistatic inline void reiserfs_mutex_lock_safe(struct mutex *m, 8118c2ecf20Sopenharmony_ci struct super_block *s) 8128c2ecf20Sopenharmony_ci{ 8138c2ecf20Sopenharmony_ci int depth; 8148c2ecf20Sopenharmony_ci 8158c2ecf20Sopenharmony_ci depth = reiserfs_write_unlock_nested(s); 8168c2ecf20Sopenharmony_ci mutex_lock(m); 8178c2ecf20Sopenharmony_ci reiserfs_write_lock_nested(s, depth); 8188c2ecf20Sopenharmony_ci} 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_cistatic inline void 8218c2ecf20Sopenharmony_cireiserfs_mutex_lock_nested_safe(struct mutex *m, unsigned int subclass, 8228c2ecf20Sopenharmony_ci struct super_block *s) 8238c2ecf20Sopenharmony_ci{ 8248c2ecf20Sopenharmony_ci int depth; 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_ci depth = reiserfs_write_unlock_nested(s); 8278c2ecf20Sopenharmony_ci mutex_lock_nested(m, subclass); 8288c2ecf20Sopenharmony_ci reiserfs_write_lock_nested(s, depth); 8298c2ecf20Sopenharmony_ci} 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_cistatic inline void 8328c2ecf20Sopenharmony_cireiserfs_down_read_safe(struct rw_semaphore *sem, struct super_block *s) 8338c2ecf20Sopenharmony_ci{ 8348c2ecf20Sopenharmony_ci int depth; 8358c2ecf20Sopenharmony_ci depth = reiserfs_write_unlock_nested(s); 8368c2ecf20Sopenharmony_ci down_read(sem); 8378c2ecf20Sopenharmony_ci reiserfs_write_lock_nested(s, depth); 8388c2ecf20Sopenharmony_ci} 8398c2ecf20Sopenharmony_ci 8408c2ecf20Sopenharmony_ci/* 8418c2ecf20Sopenharmony_ci * When we schedule, we usually want to also release the write lock, 8428c2ecf20Sopenharmony_ci * according to the previous bkl based locking scheme of reiserfs. 8438c2ecf20Sopenharmony_ci */ 8448c2ecf20Sopenharmony_cistatic inline void reiserfs_cond_resched(struct super_block *s) 8458c2ecf20Sopenharmony_ci{ 8468c2ecf20Sopenharmony_ci if (need_resched()) { 8478c2ecf20Sopenharmony_ci int depth; 8488c2ecf20Sopenharmony_ci 8498c2ecf20Sopenharmony_ci depth = reiserfs_write_unlock_nested(s); 8508c2ecf20Sopenharmony_ci schedule(); 8518c2ecf20Sopenharmony_ci reiserfs_write_lock_nested(s, depth); 8528c2ecf20Sopenharmony_ci } 8538c2ecf20Sopenharmony_ci} 8548c2ecf20Sopenharmony_ci 8558c2ecf20Sopenharmony_cistruct fid; 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci/* 8588c2ecf20Sopenharmony_ci * in reading the #defines, it may help to understand that they employ 8598c2ecf20Sopenharmony_ci * the following abbreviations: 8608c2ecf20Sopenharmony_ci * 8618c2ecf20Sopenharmony_ci * B = Buffer 8628c2ecf20Sopenharmony_ci * I = Item header 8638c2ecf20Sopenharmony_ci * H = Height within the tree (should be changed to LEV) 8648c2ecf20Sopenharmony_ci * N = Number of the item in the node 8658c2ecf20Sopenharmony_ci * STAT = stat data 8668c2ecf20Sopenharmony_ci * DEH = Directory Entry Header 8678c2ecf20Sopenharmony_ci * EC = Entry Count 8688c2ecf20Sopenharmony_ci * E = Entry number 8698c2ecf20Sopenharmony_ci * UL = Unsigned Long 8708c2ecf20Sopenharmony_ci * BLKH = BLocK Header 8718c2ecf20Sopenharmony_ci * UNFM = UNForMatted node 8728c2ecf20Sopenharmony_ci * DC = Disk Child 8738c2ecf20Sopenharmony_ci * P = Path 8748c2ecf20Sopenharmony_ci * 8758c2ecf20Sopenharmony_ci * These #defines are named by concatenating these abbreviations, 8768c2ecf20Sopenharmony_ci * where first comes the arguments, and last comes the return value, 8778c2ecf20Sopenharmony_ci * of the macro. 8788c2ecf20Sopenharmony_ci */ 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_ci#define USE_INODE_GENERATION_COUNTER 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_ci#define REISERFS_PREALLOCATE 8838c2ecf20Sopenharmony_ci#define DISPLACE_NEW_PACKING_LOCALITIES 8848c2ecf20Sopenharmony_ci#define PREALLOCATION_SIZE 9 8858c2ecf20Sopenharmony_ci 8868c2ecf20Sopenharmony_ci/* n must be power of 2 */ 8878c2ecf20Sopenharmony_ci#define _ROUND_UP(x,n) (((x)+(n)-1u) & ~((n)-1u)) 8888c2ecf20Sopenharmony_ci 8898c2ecf20Sopenharmony_ci/* 8908c2ecf20Sopenharmony_ci * to be ok for alpha and others we have to align structures to 8 byte 8918c2ecf20Sopenharmony_ci * boundary. 8928c2ecf20Sopenharmony_ci * FIXME: do not change 4 by anything else: there is code which relies on that 8938c2ecf20Sopenharmony_ci */ 8948c2ecf20Sopenharmony_ci#define ROUND_UP(x) _ROUND_UP(x,8LL) 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_ci/* 8978c2ecf20Sopenharmony_ci * debug levels. Right now, CONFIG_REISERFS_CHECK means print all debug 8988c2ecf20Sopenharmony_ci * messages. 8998c2ecf20Sopenharmony_ci */ 9008c2ecf20Sopenharmony_ci#define REISERFS_DEBUG_CODE 5 /* extra messages to help find/debug errors */ 9018c2ecf20Sopenharmony_ci 9028c2ecf20Sopenharmony_civoid __reiserfs_warning(struct super_block *s, const char *id, 9038c2ecf20Sopenharmony_ci const char *func, const char *fmt, ...); 9048c2ecf20Sopenharmony_ci#define reiserfs_warning(s, id, fmt, args...) \ 9058c2ecf20Sopenharmony_ci __reiserfs_warning(s, id, __func__, fmt, ##args) 9068c2ecf20Sopenharmony_ci/* assertions handling */ 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_ci/* always check a condition and panic if it's false. */ 9098c2ecf20Sopenharmony_ci#define __RASSERT(cond, scond, format, args...) \ 9108c2ecf20Sopenharmony_cido { \ 9118c2ecf20Sopenharmony_ci if (!(cond)) \ 9128c2ecf20Sopenharmony_ci reiserfs_panic(NULL, "assertion failure", "(" #cond ") at " \ 9138c2ecf20Sopenharmony_ci __FILE__ ":%i:%s: " format "\n", \ 9148c2ecf20Sopenharmony_ci __LINE__, __func__ , ##args); \ 9158c2ecf20Sopenharmony_ci} while (0) 9168c2ecf20Sopenharmony_ci 9178c2ecf20Sopenharmony_ci#define RASSERT(cond, format, args...) __RASSERT(cond, #cond, format, ##args) 9188c2ecf20Sopenharmony_ci 9198c2ecf20Sopenharmony_ci#if defined( CONFIG_REISERFS_CHECK ) 9208c2ecf20Sopenharmony_ci#define RFALSE(cond, format, args...) __RASSERT(!(cond), "!(" #cond ")", format, ##args) 9218c2ecf20Sopenharmony_ci#else 9228c2ecf20Sopenharmony_ci#define RFALSE( cond, format, args... ) do {;} while( 0 ) 9238c2ecf20Sopenharmony_ci#endif 9248c2ecf20Sopenharmony_ci 9258c2ecf20Sopenharmony_ci#define CONSTF __attribute_const__ 9268c2ecf20Sopenharmony_ci/* 9278c2ecf20Sopenharmony_ci * Disk Data Structures 9288c2ecf20Sopenharmony_ci */ 9298c2ecf20Sopenharmony_ci 9308c2ecf20Sopenharmony_ci/*************************************************************************** 9318c2ecf20Sopenharmony_ci * SUPER BLOCK * 9328c2ecf20Sopenharmony_ci ***************************************************************************/ 9338c2ecf20Sopenharmony_ci 9348c2ecf20Sopenharmony_ci/* 9358c2ecf20Sopenharmony_ci * Structure of super block on disk, a version of which in RAM is often 9368c2ecf20Sopenharmony_ci * accessed as REISERFS_SB(s)->s_rs. The version in RAM is part of a larger 9378c2ecf20Sopenharmony_ci * structure containing fields never written to disk. 9388c2ecf20Sopenharmony_ci */ 9398c2ecf20Sopenharmony_ci#define UNSET_HASH 0 /* Detect hash on disk */ 9408c2ecf20Sopenharmony_ci#define TEA_HASH 1 9418c2ecf20Sopenharmony_ci#define YURA_HASH 2 9428c2ecf20Sopenharmony_ci#define R5_HASH 3 9438c2ecf20Sopenharmony_ci#define DEFAULT_HASH R5_HASH 9448c2ecf20Sopenharmony_ci 9458c2ecf20Sopenharmony_cistruct journal_params { 9468c2ecf20Sopenharmony_ci /* where does journal start from on its * device */ 9478c2ecf20Sopenharmony_ci __le32 jp_journal_1st_block; 9488c2ecf20Sopenharmony_ci 9498c2ecf20Sopenharmony_ci /* journal device st_rdev */ 9508c2ecf20Sopenharmony_ci __le32 jp_journal_dev; 9518c2ecf20Sopenharmony_ci 9528c2ecf20Sopenharmony_ci /* size of the journal */ 9538c2ecf20Sopenharmony_ci __le32 jp_journal_size; 9548c2ecf20Sopenharmony_ci 9558c2ecf20Sopenharmony_ci /* max number of blocks in a transaction. */ 9568c2ecf20Sopenharmony_ci __le32 jp_journal_trans_max; 9578c2ecf20Sopenharmony_ci 9588c2ecf20Sopenharmony_ci /* 9598c2ecf20Sopenharmony_ci * random value made on fs creation 9608c2ecf20Sopenharmony_ci * (this was sb_journal_block_count) 9618c2ecf20Sopenharmony_ci */ 9628c2ecf20Sopenharmony_ci __le32 jp_journal_magic; 9638c2ecf20Sopenharmony_ci 9648c2ecf20Sopenharmony_ci /* max number of blocks to batch into a trans */ 9658c2ecf20Sopenharmony_ci __le32 jp_journal_max_batch; 9668c2ecf20Sopenharmony_ci 9678c2ecf20Sopenharmony_ci /* in seconds, how old can an async commit be */ 9688c2ecf20Sopenharmony_ci __le32 jp_journal_max_commit_age; 9698c2ecf20Sopenharmony_ci 9708c2ecf20Sopenharmony_ci /* in seconds, how old can a transaction be */ 9718c2ecf20Sopenharmony_ci __le32 jp_journal_max_trans_age; 9728c2ecf20Sopenharmony_ci}; 9738c2ecf20Sopenharmony_ci 9748c2ecf20Sopenharmony_ci/* this is the super from 3.5.X, where X >= 10 */ 9758c2ecf20Sopenharmony_cistruct reiserfs_super_block_v1 { 9768c2ecf20Sopenharmony_ci __le32 s_block_count; /* blocks count */ 9778c2ecf20Sopenharmony_ci __le32 s_free_blocks; /* free blocks count */ 9788c2ecf20Sopenharmony_ci __le32 s_root_block; /* root block number */ 9798c2ecf20Sopenharmony_ci struct journal_params s_journal; 9808c2ecf20Sopenharmony_ci __le16 s_blocksize; /* block size */ 9818c2ecf20Sopenharmony_ci 9828c2ecf20Sopenharmony_ci /* max size of object id array, see get_objectid() commentary */ 9838c2ecf20Sopenharmony_ci __le16 s_oid_maxsize; 9848c2ecf20Sopenharmony_ci __le16 s_oid_cursize; /* current size of object id array */ 9858c2ecf20Sopenharmony_ci 9868c2ecf20Sopenharmony_ci /* this is set to 1 when filesystem was umounted, to 2 - when not */ 9878c2ecf20Sopenharmony_ci __le16 s_umount_state; 9888c2ecf20Sopenharmony_ci 9898c2ecf20Sopenharmony_ci /* 9908c2ecf20Sopenharmony_ci * reiserfs magic string indicates that file system is reiserfs: 9918c2ecf20Sopenharmony_ci * "ReIsErFs" or "ReIsEr2Fs" or "ReIsEr3Fs" 9928c2ecf20Sopenharmony_ci */ 9938c2ecf20Sopenharmony_ci char s_magic[10]; 9948c2ecf20Sopenharmony_ci 9958c2ecf20Sopenharmony_ci /* 9968c2ecf20Sopenharmony_ci * it is set to used by fsck to mark which 9978c2ecf20Sopenharmony_ci * phase of rebuilding is done 9988c2ecf20Sopenharmony_ci */ 9998c2ecf20Sopenharmony_ci __le16 s_fs_state; 10008c2ecf20Sopenharmony_ci /* 10018c2ecf20Sopenharmony_ci * indicate, what hash function is being use 10028c2ecf20Sopenharmony_ci * to sort names in a directory 10038c2ecf20Sopenharmony_ci */ 10048c2ecf20Sopenharmony_ci __le32 s_hash_function_code; 10058c2ecf20Sopenharmony_ci __le16 s_tree_height; /* height of disk tree */ 10068c2ecf20Sopenharmony_ci 10078c2ecf20Sopenharmony_ci /* 10088c2ecf20Sopenharmony_ci * amount of bitmap blocks needed to address 10098c2ecf20Sopenharmony_ci * each block of file system 10108c2ecf20Sopenharmony_ci */ 10118c2ecf20Sopenharmony_ci __le16 s_bmap_nr; 10128c2ecf20Sopenharmony_ci 10138c2ecf20Sopenharmony_ci /* 10148c2ecf20Sopenharmony_ci * this field is only reliable on filesystem with non-standard journal 10158c2ecf20Sopenharmony_ci */ 10168c2ecf20Sopenharmony_ci __le16 s_version; 10178c2ecf20Sopenharmony_ci 10188c2ecf20Sopenharmony_ci /* 10198c2ecf20Sopenharmony_ci * size in blocks of journal area on main device, we need to 10208c2ecf20Sopenharmony_ci * keep after making fs with non-standard journal 10218c2ecf20Sopenharmony_ci */ 10228c2ecf20Sopenharmony_ci __le16 s_reserved_for_journal; 10238c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 10248c2ecf20Sopenharmony_ci 10258c2ecf20Sopenharmony_ci#define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1)) 10268c2ecf20Sopenharmony_ci 10278c2ecf20Sopenharmony_ci/* this is the on disk super block */ 10288c2ecf20Sopenharmony_cistruct reiserfs_super_block { 10298c2ecf20Sopenharmony_ci struct reiserfs_super_block_v1 s_v1; 10308c2ecf20Sopenharmony_ci __le32 s_inode_generation; 10318c2ecf20Sopenharmony_ci 10328c2ecf20Sopenharmony_ci /* Right now used only by inode-attributes, if enabled */ 10338c2ecf20Sopenharmony_ci __le32 s_flags; 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_ci unsigned char s_uuid[16]; /* filesystem unique identifier */ 10368c2ecf20Sopenharmony_ci unsigned char s_label[16]; /* filesystem volume label */ 10378c2ecf20Sopenharmony_ci __le16 s_mnt_count; /* Count of mounts since last fsck */ 10388c2ecf20Sopenharmony_ci __le16 s_max_mnt_count; /* Maximum mounts before check */ 10398c2ecf20Sopenharmony_ci __le32 s_lastcheck; /* Timestamp of last fsck */ 10408c2ecf20Sopenharmony_ci __le32 s_check_interval; /* Interval between checks */ 10418c2ecf20Sopenharmony_ci 10428c2ecf20Sopenharmony_ci /* 10438c2ecf20Sopenharmony_ci * zero filled by mkreiserfs and reiserfs_convert_objectid_map_v1() 10448c2ecf20Sopenharmony_ci * so any additions must be updated there as well. */ 10458c2ecf20Sopenharmony_ci char s_unused[76]; 10468c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 10478c2ecf20Sopenharmony_ci 10488c2ecf20Sopenharmony_ci#define SB_SIZE (sizeof(struct reiserfs_super_block)) 10498c2ecf20Sopenharmony_ci 10508c2ecf20Sopenharmony_ci#define REISERFS_VERSION_1 0 10518c2ecf20Sopenharmony_ci#define REISERFS_VERSION_2 2 10528c2ecf20Sopenharmony_ci 10538c2ecf20Sopenharmony_ci/* on-disk super block fields converted to cpu form */ 10548c2ecf20Sopenharmony_ci#define SB_DISK_SUPER_BLOCK(s) (REISERFS_SB(s)->s_rs) 10558c2ecf20Sopenharmony_ci#define SB_V1_DISK_SUPER_BLOCK(s) (&(SB_DISK_SUPER_BLOCK(s)->s_v1)) 10568c2ecf20Sopenharmony_ci#define SB_BLOCKSIZE(s) \ 10578c2ecf20Sopenharmony_ci le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_blocksize)) 10588c2ecf20Sopenharmony_ci#define SB_BLOCK_COUNT(s) \ 10598c2ecf20Sopenharmony_ci le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_block_count)) 10608c2ecf20Sopenharmony_ci#define SB_FREE_BLOCKS(s) \ 10618c2ecf20Sopenharmony_ci le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_free_blocks)) 10628c2ecf20Sopenharmony_ci#define SB_REISERFS_MAGIC(s) \ 10638c2ecf20Sopenharmony_ci (SB_V1_DISK_SUPER_BLOCK(s)->s_magic) 10648c2ecf20Sopenharmony_ci#define SB_ROOT_BLOCK(s) \ 10658c2ecf20Sopenharmony_ci le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_root_block)) 10668c2ecf20Sopenharmony_ci#define SB_TREE_HEIGHT(s) \ 10678c2ecf20Sopenharmony_ci le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height)) 10688c2ecf20Sopenharmony_ci#define SB_REISERFS_STATE(s) \ 10698c2ecf20Sopenharmony_ci le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state)) 10708c2ecf20Sopenharmony_ci#define SB_VERSION(s) le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_version)) 10718c2ecf20Sopenharmony_ci#define SB_BMAP_NR(s) le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr)) 10728c2ecf20Sopenharmony_ci 10738c2ecf20Sopenharmony_ci#define PUT_SB_BLOCK_COUNT(s, val) \ 10748c2ecf20Sopenharmony_ci do { SB_V1_DISK_SUPER_BLOCK(s)->s_block_count = cpu_to_le32(val); } while (0) 10758c2ecf20Sopenharmony_ci#define PUT_SB_FREE_BLOCKS(s, val) \ 10768c2ecf20Sopenharmony_ci do { SB_V1_DISK_SUPER_BLOCK(s)->s_free_blocks = cpu_to_le32(val); } while (0) 10778c2ecf20Sopenharmony_ci#define PUT_SB_ROOT_BLOCK(s, val) \ 10788c2ecf20Sopenharmony_ci do { SB_V1_DISK_SUPER_BLOCK(s)->s_root_block = cpu_to_le32(val); } while (0) 10798c2ecf20Sopenharmony_ci#define PUT_SB_TREE_HEIGHT(s, val) \ 10808c2ecf20Sopenharmony_ci do { SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height = cpu_to_le16(val); } while (0) 10818c2ecf20Sopenharmony_ci#define PUT_SB_REISERFS_STATE(s, val) \ 10828c2ecf20Sopenharmony_ci do { SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state = cpu_to_le16(val); } while (0) 10838c2ecf20Sopenharmony_ci#define PUT_SB_VERSION(s, val) \ 10848c2ecf20Sopenharmony_ci do { SB_V1_DISK_SUPER_BLOCK(s)->s_version = cpu_to_le16(val); } while (0) 10858c2ecf20Sopenharmony_ci#define PUT_SB_BMAP_NR(s, val) \ 10868c2ecf20Sopenharmony_ci do { SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr = cpu_to_le16 (val); } while (0) 10878c2ecf20Sopenharmony_ci 10888c2ecf20Sopenharmony_ci#define SB_ONDISK_JP(s) (&SB_V1_DISK_SUPER_BLOCK(s)->s_journal) 10898c2ecf20Sopenharmony_ci#define SB_ONDISK_JOURNAL_SIZE(s) \ 10908c2ecf20Sopenharmony_ci le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_size)) 10918c2ecf20Sopenharmony_ci#define SB_ONDISK_JOURNAL_1st_BLOCK(s) \ 10928c2ecf20Sopenharmony_ci le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_1st_block)) 10938c2ecf20Sopenharmony_ci#define SB_ONDISK_JOURNAL_DEVICE(s) \ 10948c2ecf20Sopenharmony_ci le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_dev)) 10958c2ecf20Sopenharmony_ci#define SB_ONDISK_RESERVED_FOR_JOURNAL(s) \ 10968c2ecf20Sopenharmony_ci le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_reserved_for_journal)) 10978c2ecf20Sopenharmony_ci 10988c2ecf20Sopenharmony_ci#define is_block_in_log_or_reserved_area(s, block) \ 10998c2ecf20Sopenharmony_ci block >= SB_JOURNAL_1st_RESERVED_BLOCK(s) \ 11008c2ecf20Sopenharmony_ci && block < SB_JOURNAL_1st_RESERVED_BLOCK(s) + \ 11018c2ecf20Sopenharmony_ci ((!is_reiserfs_jr(SB_DISK_SUPER_BLOCK(s)) ? \ 11028c2ecf20Sopenharmony_ci SB_ONDISK_JOURNAL_SIZE(s) + 1 : SB_ONDISK_RESERVED_FOR_JOURNAL(s))) 11038c2ecf20Sopenharmony_ci 11048c2ecf20Sopenharmony_ciint is_reiserfs_3_5(struct reiserfs_super_block *rs); 11058c2ecf20Sopenharmony_ciint is_reiserfs_3_6(struct reiserfs_super_block *rs); 11068c2ecf20Sopenharmony_ciint is_reiserfs_jr(struct reiserfs_super_block *rs); 11078c2ecf20Sopenharmony_ci 11088c2ecf20Sopenharmony_ci/* 11098c2ecf20Sopenharmony_ci * ReiserFS leaves the first 64k unused, so that partition labels have 11108c2ecf20Sopenharmony_ci * enough space. If someone wants to write a fancy bootloader that 11118c2ecf20Sopenharmony_ci * needs more than 64k, let us know, and this will be increased in size. 11128c2ecf20Sopenharmony_ci * This number must be larger than the largest block size on any 11138c2ecf20Sopenharmony_ci * platform, or code will break. -Hans 11148c2ecf20Sopenharmony_ci */ 11158c2ecf20Sopenharmony_ci#define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024) 11168c2ecf20Sopenharmony_ci#define REISERFS_FIRST_BLOCK unused_define 11178c2ecf20Sopenharmony_ci#define REISERFS_JOURNAL_OFFSET_IN_BYTES REISERFS_DISK_OFFSET_IN_BYTES 11188c2ecf20Sopenharmony_ci 11198c2ecf20Sopenharmony_ci/* the spot for the super in versions 3.5 - 3.5.10 (inclusive) */ 11208c2ecf20Sopenharmony_ci#define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024) 11218c2ecf20Sopenharmony_ci 11228c2ecf20Sopenharmony_ci/* reiserfs internal error code (used by search_by_key and fix_nodes)) */ 11238c2ecf20Sopenharmony_ci#define CARRY_ON 0 11248c2ecf20Sopenharmony_ci#define REPEAT_SEARCH -1 11258c2ecf20Sopenharmony_ci#define IO_ERROR -2 11268c2ecf20Sopenharmony_ci#define NO_DISK_SPACE -3 11278c2ecf20Sopenharmony_ci#define NO_BALANCING_NEEDED (-4) 11288c2ecf20Sopenharmony_ci#define NO_MORE_UNUSED_CONTIGUOUS_BLOCKS (-5) 11298c2ecf20Sopenharmony_ci#define QUOTA_EXCEEDED -6 11308c2ecf20Sopenharmony_ci 11318c2ecf20Sopenharmony_citypedef __u32 b_blocknr_t; 11328c2ecf20Sopenharmony_citypedef __le32 unp_t; 11338c2ecf20Sopenharmony_ci 11348c2ecf20Sopenharmony_cistruct unfm_nodeinfo { 11358c2ecf20Sopenharmony_ci unp_t unfm_nodenum; 11368c2ecf20Sopenharmony_ci unsigned short unfm_freespace; 11378c2ecf20Sopenharmony_ci}; 11388c2ecf20Sopenharmony_ci 11398c2ecf20Sopenharmony_ci/* there are two formats of keys: 3.5 and 3.6 */ 11408c2ecf20Sopenharmony_ci#define KEY_FORMAT_3_5 0 11418c2ecf20Sopenharmony_ci#define KEY_FORMAT_3_6 1 11428c2ecf20Sopenharmony_ci 11438c2ecf20Sopenharmony_ci/* there are two stat datas */ 11448c2ecf20Sopenharmony_ci#define STAT_DATA_V1 0 11458c2ecf20Sopenharmony_ci#define STAT_DATA_V2 1 11468c2ecf20Sopenharmony_ci 11478c2ecf20Sopenharmony_cistatic inline struct reiserfs_inode_info *REISERFS_I(const struct inode *inode) 11488c2ecf20Sopenharmony_ci{ 11498c2ecf20Sopenharmony_ci return container_of(inode, struct reiserfs_inode_info, vfs_inode); 11508c2ecf20Sopenharmony_ci} 11518c2ecf20Sopenharmony_ci 11528c2ecf20Sopenharmony_cistatic inline struct reiserfs_sb_info *REISERFS_SB(const struct super_block *sb) 11538c2ecf20Sopenharmony_ci{ 11548c2ecf20Sopenharmony_ci return sb->s_fs_info; 11558c2ecf20Sopenharmony_ci} 11568c2ecf20Sopenharmony_ci 11578c2ecf20Sopenharmony_ci/* 11588c2ecf20Sopenharmony_ci * Don't trust REISERFS_SB(sb)->s_bmap_nr, it's a u16 11598c2ecf20Sopenharmony_ci * which overflows on large file systems. 11608c2ecf20Sopenharmony_ci */ 11618c2ecf20Sopenharmony_cistatic inline __u32 reiserfs_bmap_count(struct super_block *sb) 11628c2ecf20Sopenharmony_ci{ 11638c2ecf20Sopenharmony_ci return (SB_BLOCK_COUNT(sb) - 1) / (sb->s_blocksize * 8) + 1; 11648c2ecf20Sopenharmony_ci} 11658c2ecf20Sopenharmony_ci 11668c2ecf20Sopenharmony_cistatic inline int bmap_would_wrap(unsigned bmap_nr) 11678c2ecf20Sopenharmony_ci{ 11688c2ecf20Sopenharmony_ci return bmap_nr > ((1LL << 16) - 1); 11698c2ecf20Sopenharmony_ci} 11708c2ecf20Sopenharmony_ci 11718c2ecf20Sopenharmony_ciextern const struct xattr_handler *reiserfs_xattr_handlers[]; 11728c2ecf20Sopenharmony_ci 11738c2ecf20Sopenharmony_ci/* 11748c2ecf20Sopenharmony_ci * this says about version of key of all items (but stat data) the 11758c2ecf20Sopenharmony_ci * object consists of 11768c2ecf20Sopenharmony_ci */ 11778c2ecf20Sopenharmony_ci#define get_inode_item_key_version( inode ) \ 11788c2ecf20Sopenharmony_ci ((REISERFS_I(inode)->i_flags & i_item_key_version_mask) ? KEY_FORMAT_3_6 : KEY_FORMAT_3_5) 11798c2ecf20Sopenharmony_ci 11808c2ecf20Sopenharmony_ci#define set_inode_item_key_version( inode, version ) \ 11818c2ecf20Sopenharmony_ci ({ if((version)==KEY_FORMAT_3_6) \ 11828c2ecf20Sopenharmony_ci REISERFS_I(inode)->i_flags |= i_item_key_version_mask; \ 11838c2ecf20Sopenharmony_ci else \ 11848c2ecf20Sopenharmony_ci REISERFS_I(inode)->i_flags &= ~i_item_key_version_mask; }) 11858c2ecf20Sopenharmony_ci 11868c2ecf20Sopenharmony_ci#define get_inode_sd_version(inode) \ 11878c2ecf20Sopenharmony_ci ((REISERFS_I(inode)->i_flags & i_stat_data_version_mask) ? STAT_DATA_V2 : STAT_DATA_V1) 11888c2ecf20Sopenharmony_ci 11898c2ecf20Sopenharmony_ci#define set_inode_sd_version(inode, version) \ 11908c2ecf20Sopenharmony_ci ({ if((version)==STAT_DATA_V2) \ 11918c2ecf20Sopenharmony_ci REISERFS_I(inode)->i_flags |= i_stat_data_version_mask; \ 11928c2ecf20Sopenharmony_ci else \ 11938c2ecf20Sopenharmony_ci REISERFS_I(inode)->i_flags &= ~i_stat_data_version_mask; }) 11948c2ecf20Sopenharmony_ci 11958c2ecf20Sopenharmony_ci/* 11968c2ecf20Sopenharmony_ci * This is an aggressive tail suppression policy, I am hoping it 11978c2ecf20Sopenharmony_ci * improves our benchmarks. The principle behind it is that percentage 11988c2ecf20Sopenharmony_ci * space saving is what matters, not absolute space saving. This is 11998c2ecf20Sopenharmony_ci * non-intuitive, but it helps to understand it if you consider that the 12008c2ecf20Sopenharmony_ci * cost to access 4 blocks is not much more than the cost to access 1 12018c2ecf20Sopenharmony_ci * block, if you have to do a seek and rotate. A tail risks a 12028c2ecf20Sopenharmony_ci * non-linear disk access that is significant as a percentage of total 12038c2ecf20Sopenharmony_ci * time cost for a 4 block file and saves an amount of space that is 12048c2ecf20Sopenharmony_ci * less significant as a percentage of space, or so goes the hypothesis. 12058c2ecf20Sopenharmony_ci * -Hans 12068c2ecf20Sopenharmony_ci */ 12078c2ecf20Sopenharmony_ci#define STORE_TAIL_IN_UNFM_S1(n_file_size,n_tail_size,n_block_size) \ 12088c2ecf20Sopenharmony_ci(\ 12098c2ecf20Sopenharmony_ci (!(n_tail_size)) || \ 12108c2ecf20Sopenharmony_ci (((n_tail_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) || \ 12118c2ecf20Sopenharmony_ci ( (n_file_size) >= (n_block_size) * 4 ) || \ 12128c2ecf20Sopenharmony_ci ( ( (n_file_size) >= (n_block_size) * 3 ) && \ 12138c2ecf20Sopenharmony_ci ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size))/4) ) || \ 12148c2ecf20Sopenharmony_ci ( ( (n_file_size) >= (n_block_size) * 2 ) && \ 12158c2ecf20Sopenharmony_ci ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size))/2) ) || \ 12168c2ecf20Sopenharmony_ci ( ( (n_file_size) >= (n_block_size) ) && \ 12178c2ecf20Sopenharmony_ci ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size) * 3)/4) ) ) \ 12188c2ecf20Sopenharmony_ci) 12198c2ecf20Sopenharmony_ci 12208c2ecf20Sopenharmony_ci/* 12218c2ecf20Sopenharmony_ci * Another strategy for tails, this one means only create a tail if all the 12228c2ecf20Sopenharmony_ci * file would fit into one DIRECT item. 12238c2ecf20Sopenharmony_ci * Primary intention for this one is to increase performance by decreasing 12248c2ecf20Sopenharmony_ci * seeking. 12258c2ecf20Sopenharmony_ci*/ 12268c2ecf20Sopenharmony_ci#define STORE_TAIL_IN_UNFM_S2(n_file_size,n_tail_size,n_block_size) \ 12278c2ecf20Sopenharmony_ci(\ 12288c2ecf20Sopenharmony_ci (!(n_tail_size)) || \ 12298c2ecf20Sopenharmony_ci (((n_file_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) ) \ 12308c2ecf20Sopenharmony_ci) 12318c2ecf20Sopenharmony_ci 12328c2ecf20Sopenharmony_ci/* 12338c2ecf20Sopenharmony_ci * values for s_umount_state field 12348c2ecf20Sopenharmony_ci */ 12358c2ecf20Sopenharmony_ci#define REISERFS_VALID_FS 1 12368c2ecf20Sopenharmony_ci#define REISERFS_ERROR_FS 2 12378c2ecf20Sopenharmony_ci 12388c2ecf20Sopenharmony_ci/* 12398c2ecf20Sopenharmony_ci * there are 5 item types currently 12408c2ecf20Sopenharmony_ci */ 12418c2ecf20Sopenharmony_ci#define TYPE_STAT_DATA 0 12428c2ecf20Sopenharmony_ci#define TYPE_INDIRECT 1 12438c2ecf20Sopenharmony_ci#define TYPE_DIRECT 2 12448c2ecf20Sopenharmony_ci#define TYPE_DIRENTRY 3 12458c2ecf20Sopenharmony_ci#define TYPE_MAXTYPE 3 12468c2ecf20Sopenharmony_ci#define TYPE_ANY 15 /* FIXME: comment is required */ 12478c2ecf20Sopenharmony_ci 12488c2ecf20Sopenharmony_ci/*************************************************************************** 12498c2ecf20Sopenharmony_ci * KEY & ITEM HEAD * 12508c2ecf20Sopenharmony_ci ***************************************************************************/ 12518c2ecf20Sopenharmony_ci 12528c2ecf20Sopenharmony_ci/* * directories use this key as well as old files */ 12538c2ecf20Sopenharmony_cistruct offset_v1 { 12548c2ecf20Sopenharmony_ci __le32 k_offset; 12558c2ecf20Sopenharmony_ci __le32 k_uniqueness; 12568c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 12578c2ecf20Sopenharmony_ci 12588c2ecf20Sopenharmony_cistruct offset_v2 { 12598c2ecf20Sopenharmony_ci __le64 v; 12608c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 12618c2ecf20Sopenharmony_ci 12628c2ecf20Sopenharmony_cistatic inline __u16 offset_v2_k_type(const struct offset_v2 *v2) 12638c2ecf20Sopenharmony_ci{ 12648c2ecf20Sopenharmony_ci __u8 type = le64_to_cpu(v2->v) >> 60; 12658c2ecf20Sopenharmony_ci return (type <= TYPE_MAXTYPE) ? type : TYPE_ANY; 12668c2ecf20Sopenharmony_ci} 12678c2ecf20Sopenharmony_ci 12688c2ecf20Sopenharmony_cistatic inline void set_offset_v2_k_type(struct offset_v2 *v2, int type) 12698c2ecf20Sopenharmony_ci{ 12708c2ecf20Sopenharmony_ci v2->v = 12718c2ecf20Sopenharmony_ci (v2->v & cpu_to_le64(~0ULL >> 4)) | cpu_to_le64((__u64) type << 60); 12728c2ecf20Sopenharmony_ci} 12738c2ecf20Sopenharmony_ci 12748c2ecf20Sopenharmony_cistatic inline loff_t offset_v2_k_offset(const struct offset_v2 *v2) 12758c2ecf20Sopenharmony_ci{ 12768c2ecf20Sopenharmony_ci return le64_to_cpu(v2->v) & (~0ULL >> 4); 12778c2ecf20Sopenharmony_ci} 12788c2ecf20Sopenharmony_ci 12798c2ecf20Sopenharmony_cistatic inline void set_offset_v2_k_offset(struct offset_v2 *v2, loff_t offset) 12808c2ecf20Sopenharmony_ci{ 12818c2ecf20Sopenharmony_ci offset &= (~0ULL >> 4); 12828c2ecf20Sopenharmony_ci v2->v = (v2->v & cpu_to_le64(15ULL << 60)) | cpu_to_le64(offset); 12838c2ecf20Sopenharmony_ci} 12848c2ecf20Sopenharmony_ci 12858c2ecf20Sopenharmony_ci/* 12868c2ecf20Sopenharmony_ci * Key of an item determines its location in the S+tree, and 12878c2ecf20Sopenharmony_ci * is composed of 4 components 12888c2ecf20Sopenharmony_ci */ 12898c2ecf20Sopenharmony_cistruct reiserfs_key { 12908c2ecf20Sopenharmony_ci /* packing locality: by default parent directory object id */ 12918c2ecf20Sopenharmony_ci __le32 k_dir_id; 12928c2ecf20Sopenharmony_ci 12938c2ecf20Sopenharmony_ci __le32 k_objectid; /* object identifier */ 12948c2ecf20Sopenharmony_ci union { 12958c2ecf20Sopenharmony_ci struct offset_v1 k_offset_v1; 12968c2ecf20Sopenharmony_ci struct offset_v2 k_offset_v2; 12978c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) u; 12988c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 12998c2ecf20Sopenharmony_ci 13008c2ecf20Sopenharmony_cistruct in_core_key { 13018c2ecf20Sopenharmony_ci /* packing locality: by default parent directory object id */ 13028c2ecf20Sopenharmony_ci __u32 k_dir_id; 13038c2ecf20Sopenharmony_ci __u32 k_objectid; /* object identifier */ 13048c2ecf20Sopenharmony_ci __u64 k_offset; 13058c2ecf20Sopenharmony_ci __u8 k_type; 13068c2ecf20Sopenharmony_ci}; 13078c2ecf20Sopenharmony_ci 13088c2ecf20Sopenharmony_cistruct cpu_key { 13098c2ecf20Sopenharmony_ci struct in_core_key on_disk_key; 13108c2ecf20Sopenharmony_ci int version; 13118c2ecf20Sopenharmony_ci /* 3 in all cases but direct2indirect and indirect2direct conversion */ 13128c2ecf20Sopenharmony_ci int key_length; 13138c2ecf20Sopenharmony_ci}; 13148c2ecf20Sopenharmony_ci 13158c2ecf20Sopenharmony_ci/* 13168c2ecf20Sopenharmony_ci * Our function for comparing keys can compare keys of different 13178c2ecf20Sopenharmony_ci * lengths. It takes as a parameter the length of the keys it is to 13188c2ecf20Sopenharmony_ci * compare. These defines are used in determining what is to be passed 13198c2ecf20Sopenharmony_ci * to it as that parameter. 13208c2ecf20Sopenharmony_ci */ 13218c2ecf20Sopenharmony_ci#define REISERFS_FULL_KEY_LEN 4 13228c2ecf20Sopenharmony_ci#define REISERFS_SHORT_KEY_LEN 2 13238c2ecf20Sopenharmony_ci 13248c2ecf20Sopenharmony_ci/* The result of the key compare */ 13258c2ecf20Sopenharmony_ci#define FIRST_GREATER 1 13268c2ecf20Sopenharmony_ci#define SECOND_GREATER -1 13278c2ecf20Sopenharmony_ci#define KEYS_IDENTICAL 0 13288c2ecf20Sopenharmony_ci#define KEY_FOUND 1 13298c2ecf20Sopenharmony_ci#define KEY_NOT_FOUND 0 13308c2ecf20Sopenharmony_ci 13318c2ecf20Sopenharmony_ci#define KEY_SIZE (sizeof(struct reiserfs_key)) 13328c2ecf20Sopenharmony_ci 13338c2ecf20Sopenharmony_ci/* return values for search_by_key and clones */ 13348c2ecf20Sopenharmony_ci#define ITEM_FOUND 1 13358c2ecf20Sopenharmony_ci#define ITEM_NOT_FOUND 0 13368c2ecf20Sopenharmony_ci#define ENTRY_FOUND 1 13378c2ecf20Sopenharmony_ci#define ENTRY_NOT_FOUND 0 13388c2ecf20Sopenharmony_ci#define DIRECTORY_NOT_FOUND -1 13398c2ecf20Sopenharmony_ci#define REGULAR_FILE_FOUND -2 13408c2ecf20Sopenharmony_ci#define DIRECTORY_FOUND -3 13418c2ecf20Sopenharmony_ci#define BYTE_FOUND 1 13428c2ecf20Sopenharmony_ci#define BYTE_NOT_FOUND 0 13438c2ecf20Sopenharmony_ci#define FILE_NOT_FOUND -1 13448c2ecf20Sopenharmony_ci 13458c2ecf20Sopenharmony_ci#define POSITION_FOUND 1 13468c2ecf20Sopenharmony_ci#define POSITION_NOT_FOUND 0 13478c2ecf20Sopenharmony_ci 13488c2ecf20Sopenharmony_ci/* return values for reiserfs_find_entry and search_by_entry_key */ 13498c2ecf20Sopenharmony_ci#define NAME_FOUND 1 13508c2ecf20Sopenharmony_ci#define NAME_NOT_FOUND 0 13518c2ecf20Sopenharmony_ci#define GOTO_PREVIOUS_ITEM 2 13528c2ecf20Sopenharmony_ci#define NAME_FOUND_INVISIBLE 3 13538c2ecf20Sopenharmony_ci 13548c2ecf20Sopenharmony_ci/* 13558c2ecf20Sopenharmony_ci * Everything in the filesystem is stored as a set of items. The 13568c2ecf20Sopenharmony_ci * item head contains the key of the item, its free space (for 13578c2ecf20Sopenharmony_ci * indirect items) and specifies the location of the item itself 13588c2ecf20Sopenharmony_ci * within the block. 13598c2ecf20Sopenharmony_ci */ 13608c2ecf20Sopenharmony_ci 13618c2ecf20Sopenharmony_cistruct item_head { 13628c2ecf20Sopenharmony_ci /* 13638c2ecf20Sopenharmony_ci * Everything in the tree is found by searching for it based on 13648c2ecf20Sopenharmony_ci * its key. 13658c2ecf20Sopenharmony_ci */ 13668c2ecf20Sopenharmony_ci struct reiserfs_key ih_key; 13678c2ecf20Sopenharmony_ci union { 13688c2ecf20Sopenharmony_ci /* 13698c2ecf20Sopenharmony_ci * The free space in the last unformatted node of an 13708c2ecf20Sopenharmony_ci * indirect item if this is an indirect item. This 13718c2ecf20Sopenharmony_ci * equals 0xFFFF iff this is a direct item or stat data 13728c2ecf20Sopenharmony_ci * item. Note that the key, not this field, is used to 13738c2ecf20Sopenharmony_ci * determine the item type, and thus which field this 13748c2ecf20Sopenharmony_ci * union contains. 13758c2ecf20Sopenharmony_ci */ 13768c2ecf20Sopenharmony_ci __le16 ih_free_space_reserved; 13778c2ecf20Sopenharmony_ci 13788c2ecf20Sopenharmony_ci /* 13798c2ecf20Sopenharmony_ci * Iff this is a directory item, this field equals the 13808c2ecf20Sopenharmony_ci * number of directory entries in the directory item. 13818c2ecf20Sopenharmony_ci */ 13828c2ecf20Sopenharmony_ci __le16 ih_entry_count; 13838c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) u; 13848c2ecf20Sopenharmony_ci __le16 ih_item_len; /* total size of the item body */ 13858c2ecf20Sopenharmony_ci 13868c2ecf20Sopenharmony_ci /* an offset to the item body within the block */ 13878c2ecf20Sopenharmony_ci __le16 ih_item_location; 13888c2ecf20Sopenharmony_ci 13898c2ecf20Sopenharmony_ci /* 13908c2ecf20Sopenharmony_ci * 0 for all old items, 2 for new ones. Highest bit is set by fsck 13918c2ecf20Sopenharmony_ci * temporary, cleaned after all done 13928c2ecf20Sopenharmony_ci */ 13938c2ecf20Sopenharmony_ci __le16 ih_version; 13948c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 13958c2ecf20Sopenharmony_ci/* size of item header */ 13968c2ecf20Sopenharmony_ci#define IH_SIZE (sizeof(struct item_head)) 13978c2ecf20Sopenharmony_ci 13988c2ecf20Sopenharmony_ci#define ih_free_space(ih) le16_to_cpu((ih)->u.ih_free_space_reserved) 13998c2ecf20Sopenharmony_ci#define ih_version(ih) le16_to_cpu((ih)->ih_version) 14008c2ecf20Sopenharmony_ci#define ih_entry_count(ih) le16_to_cpu((ih)->u.ih_entry_count) 14018c2ecf20Sopenharmony_ci#define ih_location(ih) le16_to_cpu((ih)->ih_item_location) 14028c2ecf20Sopenharmony_ci#define ih_item_len(ih) le16_to_cpu((ih)->ih_item_len) 14038c2ecf20Sopenharmony_ci 14048c2ecf20Sopenharmony_ci#define put_ih_free_space(ih, val) do { (ih)->u.ih_free_space_reserved = cpu_to_le16(val); } while(0) 14058c2ecf20Sopenharmony_ci#define put_ih_version(ih, val) do { (ih)->ih_version = cpu_to_le16(val); } while (0) 14068c2ecf20Sopenharmony_ci#define put_ih_entry_count(ih, val) do { (ih)->u.ih_entry_count = cpu_to_le16(val); } while (0) 14078c2ecf20Sopenharmony_ci#define put_ih_location(ih, val) do { (ih)->ih_item_location = cpu_to_le16(val); } while (0) 14088c2ecf20Sopenharmony_ci#define put_ih_item_len(ih, val) do { (ih)->ih_item_len = cpu_to_le16(val); } while (0) 14098c2ecf20Sopenharmony_ci 14108c2ecf20Sopenharmony_ci#define unreachable_item(ih) (ih_version(ih) & (1 << 15)) 14118c2ecf20Sopenharmony_ci 14128c2ecf20Sopenharmony_ci#define get_ih_free_space(ih) (ih_version (ih) == KEY_FORMAT_3_6 ? 0 : ih_free_space (ih)) 14138c2ecf20Sopenharmony_ci#define set_ih_free_space(ih,val) put_ih_free_space((ih), ((ih_version(ih) == KEY_FORMAT_3_6) ? 0 : (val))) 14148c2ecf20Sopenharmony_ci 14158c2ecf20Sopenharmony_ci/* 14168c2ecf20Sopenharmony_ci * these operate on indirect items, where you've got an array of ints 14178c2ecf20Sopenharmony_ci * at a possibly unaligned location. These are a noop on ia32 14188c2ecf20Sopenharmony_ci * 14198c2ecf20Sopenharmony_ci * p is the array of __u32, i is the index into the array, v is the value 14208c2ecf20Sopenharmony_ci * to store there. 14218c2ecf20Sopenharmony_ci */ 14228c2ecf20Sopenharmony_ci#define get_block_num(p, i) get_unaligned_le32((p) + (i)) 14238c2ecf20Sopenharmony_ci#define put_block_num(p, i, v) put_unaligned_le32((v), (p) + (i)) 14248c2ecf20Sopenharmony_ci 14258c2ecf20Sopenharmony_ci/* * in old version uniqueness field shows key type */ 14268c2ecf20Sopenharmony_ci#define V1_SD_UNIQUENESS 0 14278c2ecf20Sopenharmony_ci#define V1_INDIRECT_UNIQUENESS 0xfffffffe 14288c2ecf20Sopenharmony_ci#define V1_DIRECT_UNIQUENESS 0xffffffff 14298c2ecf20Sopenharmony_ci#define V1_DIRENTRY_UNIQUENESS 500 14308c2ecf20Sopenharmony_ci#define V1_ANY_UNIQUENESS 555 /* FIXME: comment is required */ 14318c2ecf20Sopenharmony_ci 14328c2ecf20Sopenharmony_ci/* here are conversion routines */ 14338c2ecf20Sopenharmony_cistatic inline int uniqueness2type(__u32 uniqueness) CONSTF; 14348c2ecf20Sopenharmony_cistatic inline int uniqueness2type(__u32 uniqueness) 14358c2ecf20Sopenharmony_ci{ 14368c2ecf20Sopenharmony_ci switch ((int)uniqueness) { 14378c2ecf20Sopenharmony_ci case V1_SD_UNIQUENESS: 14388c2ecf20Sopenharmony_ci return TYPE_STAT_DATA; 14398c2ecf20Sopenharmony_ci case V1_INDIRECT_UNIQUENESS: 14408c2ecf20Sopenharmony_ci return TYPE_INDIRECT; 14418c2ecf20Sopenharmony_ci case V1_DIRECT_UNIQUENESS: 14428c2ecf20Sopenharmony_ci return TYPE_DIRECT; 14438c2ecf20Sopenharmony_ci case V1_DIRENTRY_UNIQUENESS: 14448c2ecf20Sopenharmony_ci return TYPE_DIRENTRY; 14458c2ecf20Sopenharmony_ci case V1_ANY_UNIQUENESS: 14468c2ecf20Sopenharmony_ci default: 14478c2ecf20Sopenharmony_ci return TYPE_ANY; 14488c2ecf20Sopenharmony_ci } 14498c2ecf20Sopenharmony_ci} 14508c2ecf20Sopenharmony_ci 14518c2ecf20Sopenharmony_cistatic inline __u32 type2uniqueness(int type) CONSTF; 14528c2ecf20Sopenharmony_cistatic inline __u32 type2uniqueness(int type) 14538c2ecf20Sopenharmony_ci{ 14548c2ecf20Sopenharmony_ci switch (type) { 14558c2ecf20Sopenharmony_ci case TYPE_STAT_DATA: 14568c2ecf20Sopenharmony_ci return V1_SD_UNIQUENESS; 14578c2ecf20Sopenharmony_ci case TYPE_INDIRECT: 14588c2ecf20Sopenharmony_ci return V1_INDIRECT_UNIQUENESS; 14598c2ecf20Sopenharmony_ci case TYPE_DIRECT: 14608c2ecf20Sopenharmony_ci return V1_DIRECT_UNIQUENESS; 14618c2ecf20Sopenharmony_ci case TYPE_DIRENTRY: 14628c2ecf20Sopenharmony_ci return V1_DIRENTRY_UNIQUENESS; 14638c2ecf20Sopenharmony_ci case TYPE_ANY: 14648c2ecf20Sopenharmony_ci default: 14658c2ecf20Sopenharmony_ci return V1_ANY_UNIQUENESS; 14668c2ecf20Sopenharmony_ci } 14678c2ecf20Sopenharmony_ci} 14688c2ecf20Sopenharmony_ci 14698c2ecf20Sopenharmony_ci/* 14708c2ecf20Sopenharmony_ci * key is pointer to on disk key which is stored in le, result is cpu, 14718c2ecf20Sopenharmony_ci * there is no way to get version of object from key, so, provide 14728c2ecf20Sopenharmony_ci * version to these defines 14738c2ecf20Sopenharmony_ci */ 14748c2ecf20Sopenharmony_cistatic inline loff_t le_key_k_offset(int version, 14758c2ecf20Sopenharmony_ci const struct reiserfs_key *key) 14768c2ecf20Sopenharmony_ci{ 14778c2ecf20Sopenharmony_ci return (version == KEY_FORMAT_3_5) ? 14788c2ecf20Sopenharmony_ci le32_to_cpu(key->u.k_offset_v1.k_offset) : 14798c2ecf20Sopenharmony_ci offset_v2_k_offset(&(key->u.k_offset_v2)); 14808c2ecf20Sopenharmony_ci} 14818c2ecf20Sopenharmony_ci 14828c2ecf20Sopenharmony_cistatic inline loff_t le_ih_k_offset(const struct item_head *ih) 14838c2ecf20Sopenharmony_ci{ 14848c2ecf20Sopenharmony_ci return le_key_k_offset(ih_version(ih), &(ih->ih_key)); 14858c2ecf20Sopenharmony_ci} 14868c2ecf20Sopenharmony_ci 14878c2ecf20Sopenharmony_cistatic inline loff_t le_key_k_type(int version, const struct reiserfs_key *key) 14888c2ecf20Sopenharmony_ci{ 14898c2ecf20Sopenharmony_ci if (version == KEY_FORMAT_3_5) { 14908c2ecf20Sopenharmony_ci loff_t val = le32_to_cpu(key->u.k_offset_v1.k_uniqueness); 14918c2ecf20Sopenharmony_ci return uniqueness2type(val); 14928c2ecf20Sopenharmony_ci } else 14938c2ecf20Sopenharmony_ci return offset_v2_k_type(&(key->u.k_offset_v2)); 14948c2ecf20Sopenharmony_ci} 14958c2ecf20Sopenharmony_ci 14968c2ecf20Sopenharmony_cistatic inline loff_t le_ih_k_type(const struct item_head *ih) 14978c2ecf20Sopenharmony_ci{ 14988c2ecf20Sopenharmony_ci return le_key_k_type(ih_version(ih), &(ih->ih_key)); 14998c2ecf20Sopenharmony_ci} 15008c2ecf20Sopenharmony_ci 15018c2ecf20Sopenharmony_cistatic inline void set_le_key_k_offset(int version, struct reiserfs_key *key, 15028c2ecf20Sopenharmony_ci loff_t offset) 15038c2ecf20Sopenharmony_ci{ 15048c2ecf20Sopenharmony_ci if (version == KEY_FORMAT_3_5) 15058c2ecf20Sopenharmony_ci key->u.k_offset_v1.k_offset = cpu_to_le32(offset); 15068c2ecf20Sopenharmony_ci else 15078c2ecf20Sopenharmony_ci set_offset_v2_k_offset(&key->u.k_offset_v2, offset); 15088c2ecf20Sopenharmony_ci} 15098c2ecf20Sopenharmony_ci 15108c2ecf20Sopenharmony_cistatic inline void add_le_key_k_offset(int version, struct reiserfs_key *key, 15118c2ecf20Sopenharmony_ci loff_t offset) 15128c2ecf20Sopenharmony_ci{ 15138c2ecf20Sopenharmony_ci set_le_key_k_offset(version, key, 15148c2ecf20Sopenharmony_ci le_key_k_offset(version, key) + offset); 15158c2ecf20Sopenharmony_ci} 15168c2ecf20Sopenharmony_ci 15178c2ecf20Sopenharmony_cistatic inline void add_le_ih_k_offset(struct item_head *ih, loff_t offset) 15188c2ecf20Sopenharmony_ci{ 15198c2ecf20Sopenharmony_ci add_le_key_k_offset(ih_version(ih), &(ih->ih_key), offset); 15208c2ecf20Sopenharmony_ci} 15218c2ecf20Sopenharmony_ci 15228c2ecf20Sopenharmony_cistatic inline void set_le_ih_k_offset(struct item_head *ih, loff_t offset) 15238c2ecf20Sopenharmony_ci{ 15248c2ecf20Sopenharmony_ci set_le_key_k_offset(ih_version(ih), &(ih->ih_key), offset); 15258c2ecf20Sopenharmony_ci} 15268c2ecf20Sopenharmony_ci 15278c2ecf20Sopenharmony_cistatic inline void set_le_key_k_type(int version, struct reiserfs_key *key, 15288c2ecf20Sopenharmony_ci int type) 15298c2ecf20Sopenharmony_ci{ 15308c2ecf20Sopenharmony_ci if (version == KEY_FORMAT_3_5) { 15318c2ecf20Sopenharmony_ci type = type2uniqueness(type); 15328c2ecf20Sopenharmony_ci key->u.k_offset_v1.k_uniqueness = cpu_to_le32(type); 15338c2ecf20Sopenharmony_ci } else 15348c2ecf20Sopenharmony_ci set_offset_v2_k_type(&key->u.k_offset_v2, type); 15358c2ecf20Sopenharmony_ci} 15368c2ecf20Sopenharmony_ci 15378c2ecf20Sopenharmony_cistatic inline void set_le_ih_k_type(struct item_head *ih, int type) 15388c2ecf20Sopenharmony_ci{ 15398c2ecf20Sopenharmony_ci set_le_key_k_type(ih_version(ih), &(ih->ih_key), type); 15408c2ecf20Sopenharmony_ci} 15418c2ecf20Sopenharmony_ci 15428c2ecf20Sopenharmony_cistatic inline int is_direntry_le_key(int version, struct reiserfs_key *key) 15438c2ecf20Sopenharmony_ci{ 15448c2ecf20Sopenharmony_ci return le_key_k_type(version, key) == TYPE_DIRENTRY; 15458c2ecf20Sopenharmony_ci} 15468c2ecf20Sopenharmony_ci 15478c2ecf20Sopenharmony_cistatic inline int is_direct_le_key(int version, struct reiserfs_key *key) 15488c2ecf20Sopenharmony_ci{ 15498c2ecf20Sopenharmony_ci return le_key_k_type(version, key) == TYPE_DIRECT; 15508c2ecf20Sopenharmony_ci} 15518c2ecf20Sopenharmony_ci 15528c2ecf20Sopenharmony_cistatic inline int is_indirect_le_key(int version, struct reiserfs_key *key) 15538c2ecf20Sopenharmony_ci{ 15548c2ecf20Sopenharmony_ci return le_key_k_type(version, key) == TYPE_INDIRECT; 15558c2ecf20Sopenharmony_ci} 15568c2ecf20Sopenharmony_ci 15578c2ecf20Sopenharmony_cistatic inline int is_statdata_le_key(int version, struct reiserfs_key *key) 15588c2ecf20Sopenharmony_ci{ 15598c2ecf20Sopenharmony_ci return le_key_k_type(version, key) == TYPE_STAT_DATA; 15608c2ecf20Sopenharmony_ci} 15618c2ecf20Sopenharmony_ci 15628c2ecf20Sopenharmony_ci/* item header has version. */ 15638c2ecf20Sopenharmony_cistatic inline int is_direntry_le_ih(struct item_head *ih) 15648c2ecf20Sopenharmony_ci{ 15658c2ecf20Sopenharmony_ci return is_direntry_le_key(ih_version(ih), &ih->ih_key); 15668c2ecf20Sopenharmony_ci} 15678c2ecf20Sopenharmony_ci 15688c2ecf20Sopenharmony_cistatic inline int is_direct_le_ih(struct item_head *ih) 15698c2ecf20Sopenharmony_ci{ 15708c2ecf20Sopenharmony_ci return is_direct_le_key(ih_version(ih), &ih->ih_key); 15718c2ecf20Sopenharmony_ci} 15728c2ecf20Sopenharmony_ci 15738c2ecf20Sopenharmony_cistatic inline int is_indirect_le_ih(struct item_head *ih) 15748c2ecf20Sopenharmony_ci{ 15758c2ecf20Sopenharmony_ci return is_indirect_le_key(ih_version(ih), &ih->ih_key); 15768c2ecf20Sopenharmony_ci} 15778c2ecf20Sopenharmony_ci 15788c2ecf20Sopenharmony_cistatic inline int is_statdata_le_ih(struct item_head *ih) 15798c2ecf20Sopenharmony_ci{ 15808c2ecf20Sopenharmony_ci return is_statdata_le_key(ih_version(ih), &ih->ih_key); 15818c2ecf20Sopenharmony_ci} 15828c2ecf20Sopenharmony_ci 15838c2ecf20Sopenharmony_ci/* key is pointer to cpu key, result is cpu */ 15848c2ecf20Sopenharmony_cistatic inline loff_t cpu_key_k_offset(const struct cpu_key *key) 15858c2ecf20Sopenharmony_ci{ 15868c2ecf20Sopenharmony_ci return key->on_disk_key.k_offset; 15878c2ecf20Sopenharmony_ci} 15888c2ecf20Sopenharmony_ci 15898c2ecf20Sopenharmony_cistatic inline loff_t cpu_key_k_type(const struct cpu_key *key) 15908c2ecf20Sopenharmony_ci{ 15918c2ecf20Sopenharmony_ci return key->on_disk_key.k_type; 15928c2ecf20Sopenharmony_ci} 15938c2ecf20Sopenharmony_ci 15948c2ecf20Sopenharmony_cistatic inline void set_cpu_key_k_offset(struct cpu_key *key, loff_t offset) 15958c2ecf20Sopenharmony_ci{ 15968c2ecf20Sopenharmony_ci key->on_disk_key.k_offset = offset; 15978c2ecf20Sopenharmony_ci} 15988c2ecf20Sopenharmony_ci 15998c2ecf20Sopenharmony_cistatic inline void set_cpu_key_k_type(struct cpu_key *key, int type) 16008c2ecf20Sopenharmony_ci{ 16018c2ecf20Sopenharmony_ci key->on_disk_key.k_type = type; 16028c2ecf20Sopenharmony_ci} 16038c2ecf20Sopenharmony_ci 16048c2ecf20Sopenharmony_cistatic inline void cpu_key_k_offset_dec(struct cpu_key *key) 16058c2ecf20Sopenharmony_ci{ 16068c2ecf20Sopenharmony_ci key->on_disk_key.k_offset--; 16078c2ecf20Sopenharmony_ci} 16088c2ecf20Sopenharmony_ci 16098c2ecf20Sopenharmony_ci#define is_direntry_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRENTRY) 16108c2ecf20Sopenharmony_ci#define is_direct_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRECT) 16118c2ecf20Sopenharmony_ci#define is_indirect_cpu_key(key) (cpu_key_k_type (key) == TYPE_INDIRECT) 16128c2ecf20Sopenharmony_ci#define is_statdata_cpu_key(key) (cpu_key_k_type (key) == TYPE_STAT_DATA) 16138c2ecf20Sopenharmony_ci 16148c2ecf20Sopenharmony_ci/* are these used ? */ 16158c2ecf20Sopenharmony_ci#define is_direntry_cpu_ih(ih) (is_direntry_cpu_key (&((ih)->ih_key))) 16168c2ecf20Sopenharmony_ci#define is_direct_cpu_ih(ih) (is_direct_cpu_key (&((ih)->ih_key))) 16178c2ecf20Sopenharmony_ci#define is_indirect_cpu_ih(ih) (is_indirect_cpu_key (&((ih)->ih_key))) 16188c2ecf20Sopenharmony_ci#define is_statdata_cpu_ih(ih) (is_statdata_cpu_key (&((ih)->ih_key))) 16198c2ecf20Sopenharmony_ci 16208c2ecf20Sopenharmony_ci#define I_K_KEY_IN_ITEM(ih, key, n_blocksize) \ 16218c2ecf20Sopenharmony_ci (!COMP_SHORT_KEYS(ih, key) && \ 16228c2ecf20Sopenharmony_ci I_OFF_BYTE_IN_ITEM(ih, k_offset(key), n_blocksize)) 16238c2ecf20Sopenharmony_ci 16248c2ecf20Sopenharmony_ci/* maximal length of item */ 16258c2ecf20Sopenharmony_ci#define MAX_ITEM_LEN(block_size) (block_size - BLKH_SIZE - IH_SIZE) 16268c2ecf20Sopenharmony_ci#define MIN_ITEM_LEN 1 16278c2ecf20Sopenharmony_ci 16288c2ecf20Sopenharmony_ci/* object identifier for root dir */ 16298c2ecf20Sopenharmony_ci#define REISERFS_ROOT_OBJECTID 2 16308c2ecf20Sopenharmony_ci#define REISERFS_ROOT_PARENT_OBJECTID 1 16318c2ecf20Sopenharmony_ci 16328c2ecf20Sopenharmony_ciextern struct reiserfs_key root_key; 16338c2ecf20Sopenharmony_ci 16348c2ecf20Sopenharmony_ci/* 16358c2ecf20Sopenharmony_ci * Picture represents a leaf of the S+tree 16368c2ecf20Sopenharmony_ci * ______________________________________________________ 16378c2ecf20Sopenharmony_ci * | | Array of | | | 16388c2ecf20Sopenharmony_ci * |Block | Object-Item | F r e e | Objects- | 16398c2ecf20Sopenharmony_ci * | head | Headers | S p a c e | Items | 16408c2ecf20Sopenharmony_ci * |______|_______________|___________________|___________| 16418c2ecf20Sopenharmony_ci */ 16428c2ecf20Sopenharmony_ci 16438c2ecf20Sopenharmony_ci/* 16448c2ecf20Sopenharmony_ci * Header of a disk block. More precisely, header of a formatted leaf 16458c2ecf20Sopenharmony_ci * or internal node, and not the header of an unformatted node. 16468c2ecf20Sopenharmony_ci */ 16478c2ecf20Sopenharmony_cistruct block_head { 16488c2ecf20Sopenharmony_ci __le16 blk_level; /* Level of a block in the tree. */ 16498c2ecf20Sopenharmony_ci __le16 blk_nr_item; /* Number of keys/items in a block. */ 16508c2ecf20Sopenharmony_ci __le16 blk_free_space; /* Block free space in bytes. */ 16518c2ecf20Sopenharmony_ci __le16 blk_reserved; 16528c2ecf20Sopenharmony_ci /* dump this in v4/planA */ 16538c2ecf20Sopenharmony_ci 16548c2ecf20Sopenharmony_ci /* kept only for compatibility */ 16558c2ecf20Sopenharmony_ci struct reiserfs_key blk_right_delim_key; 16568c2ecf20Sopenharmony_ci}; 16578c2ecf20Sopenharmony_ci 16588c2ecf20Sopenharmony_ci#define BLKH_SIZE (sizeof(struct block_head)) 16598c2ecf20Sopenharmony_ci#define blkh_level(p_blkh) (le16_to_cpu((p_blkh)->blk_level)) 16608c2ecf20Sopenharmony_ci#define blkh_nr_item(p_blkh) (le16_to_cpu((p_blkh)->blk_nr_item)) 16618c2ecf20Sopenharmony_ci#define blkh_free_space(p_blkh) (le16_to_cpu((p_blkh)->blk_free_space)) 16628c2ecf20Sopenharmony_ci#define blkh_reserved(p_blkh) (le16_to_cpu((p_blkh)->blk_reserved)) 16638c2ecf20Sopenharmony_ci#define set_blkh_level(p_blkh,val) ((p_blkh)->blk_level = cpu_to_le16(val)) 16648c2ecf20Sopenharmony_ci#define set_blkh_nr_item(p_blkh,val) ((p_blkh)->blk_nr_item = cpu_to_le16(val)) 16658c2ecf20Sopenharmony_ci#define set_blkh_free_space(p_blkh,val) ((p_blkh)->blk_free_space = cpu_to_le16(val)) 16668c2ecf20Sopenharmony_ci#define set_blkh_reserved(p_blkh,val) ((p_blkh)->blk_reserved = cpu_to_le16(val)) 16678c2ecf20Sopenharmony_ci#define blkh_right_delim_key(p_blkh) ((p_blkh)->blk_right_delim_key) 16688c2ecf20Sopenharmony_ci#define set_blkh_right_delim_key(p_blkh,val) ((p_blkh)->blk_right_delim_key = val) 16698c2ecf20Sopenharmony_ci 16708c2ecf20Sopenharmony_ci/* values for blk_level field of the struct block_head */ 16718c2ecf20Sopenharmony_ci 16728c2ecf20Sopenharmony_ci/* 16738c2ecf20Sopenharmony_ci * When node gets removed from the tree its blk_level is set to FREE_LEVEL. 16748c2ecf20Sopenharmony_ci * It is then used to see whether the node is still in the tree 16758c2ecf20Sopenharmony_ci */ 16768c2ecf20Sopenharmony_ci#define FREE_LEVEL 0 16778c2ecf20Sopenharmony_ci 16788c2ecf20Sopenharmony_ci#define DISK_LEAF_NODE_LEVEL 1 /* Leaf node level. */ 16798c2ecf20Sopenharmony_ci 16808c2ecf20Sopenharmony_ci/* 16818c2ecf20Sopenharmony_ci * Given the buffer head of a formatted node, resolve to the 16828c2ecf20Sopenharmony_ci * block head of that node. 16838c2ecf20Sopenharmony_ci */ 16848c2ecf20Sopenharmony_ci#define B_BLK_HEAD(bh) ((struct block_head *)((bh)->b_data)) 16858c2ecf20Sopenharmony_ci/* Number of items that are in buffer. */ 16868c2ecf20Sopenharmony_ci#define B_NR_ITEMS(bh) (blkh_nr_item(B_BLK_HEAD(bh))) 16878c2ecf20Sopenharmony_ci#define B_LEVEL(bh) (blkh_level(B_BLK_HEAD(bh))) 16888c2ecf20Sopenharmony_ci#define B_FREE_SPACE(bh) (blkh_free_space(B_BLK_HEAD(bh))) 16898c2ecf20Sopenharmony_ci 16908c2ecf20Sopenharmony_ci#define PUT_B_NR_ITEMS(bh, val) do { set_blkh_nr_item(B_BLK_HEAD(bh), val); } while (0) 16918c2ecf20Sopenharmony_ci#define PUT_B_LEVEL(bh, val) do { set_blkh_level(B_BLK_HEAD(bh), val); } while (0) 16928c2ecf20Sopenharmony_ci#define PUT_B_FREE_SPACE(bh, val) do { set_blkh_free_space(B_BLK_HEAD(bh), val); } while (0) 16938c2ecf20Sopenharmony_ci 16948c2ecf20Sopenharmony_ci/* Get right delimiting key. -- little endian */ 16958c2ecf20Sopenharmony_ci#define B_PRIGHT_DELIM_KEY(bh) (&(blk_right_delim_key(B_BLK_HEAD(bh)))) 16968c2ecf20Sopenharmony_ci 16978c2ecf20Sopenharmony_ci/* Does the buffer contain a disk leaf. */ 16988c2ecf20Sopenharmony_ci#define B_IS_ITEMS_LEVEL(bh) (B_LEVEL(bh) == DISK_LEAF_NODE_LEVEL) 16998c2ecf20Sopenharmony_ci 17008c2ecf20Sopenharmony_ci/* Does the buffer contain a disk internal node */ 17018c2ecf20Sopenharmony_ci#define B_IS_KEYS_LEVEL(bh) (B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL \ 17028c2ecf20Sopenharmony_ci && B_LEVEL(bh) <= MAX_HEIGHT) 17038c2ecf20Sopenharmony_ci 17048c2ecf20Sopenharmony_ci/*************************************************************************** 17058c2ecf20Sopenharmony_ci * STAT DATA * 17068c2ecf20Sopenharmony_ci ***************************************************************************/ 17078c2ecf20Sopenharmony_ci 17088c2ecf20Sopenharmony_ci/* 17098c2ecf20Sopenharmony_ci * old stat data is 32 bytes long. We are going to distinguish new one by 17108c2ecf20Sopenharmony_ci * different size 17118c2ecf20Sopenharmony_ci*/ 17128c2ecf20Sopenharmony_cistruct stat_data_v1 { 17138c2ecf20Sopenharmony_ci __le16 sd_mode; /* file type, permissions */ 17148c2ecf20Sopenharmony_ci __le16 sd_nlink; /* number of hard links */ 17158c2ecf20Sopenharmony_ci __le16 sd_uid; /* owner */ 17168c2ecf20Sopenharmony_ci __le16 sd_gid; /* group */ 17178c2ecf20Sopenharmony_ci __le32 sd_size; /* file size */ 17188c2ecf20Sopenharmony_ci __le32 sd_atime; /* time of last access */ 17198c2ecf20Sopenharmony_ci __le32 sd_mtime; /* time file was last modified */ 17208c2ecf20Sopenharmony_ci 17218c2ecf20Sopenharmony_ci /* 17228c2ecf20Sopenharmony_ci * time inode (stat data) was last changed 17238c2ecf20Sopenharmony_ci * (except changes to sd_atime and sd_mtime) 17248c2ecf20Sopenharmony_ci */ 17258c2ecf20Sopenharmony_ci __le32 sd_ctime; 17268c2ecf20Sopenharmony_ci union { 17278c2ecf20Sopenharmony_ci __le32 sd_rdev; 17288c2ecf20Sopenharmony_ci __le32 sd_blocks; /* number of blocks file uses */ 17298c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) u; 17308c2ecf20Sopenharmony_ci 17318c2ecf20Sopenharmony_ci /* 17328c2ecf20Sopenharmony_ci * first byte of file which is stored in a direct item: except that if 17338c2ecf20Sopenharmony_ci * it equals 1 it is a symlink and if it equals ~(__u32)0 there is no 17348c2ecf20Sopenharmony_ci * direct item. The existence of this field really grates on me. 17358c2ecf20Sopenharmony_ci * Let's replace it with a macro based on sd_size and our tail 17368c2ecf20Sopenharmony_ci * suppression policy. Someday. -Hans 17378c2ecf20Sopenharmony_ci */ 17388c2ecf20Sopenharmony_ci __le32 sd_first_direct_byte; 17398c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 17408c2ecf20Sopenharmony_ci 17418c2ecf20Sopenharmony_ci#define SD_V1_SIZE (sizeof(struct stat_data_v1)) 17428c2ecf20Sopenharmony_ci#define stat_data_v1(ih) (ih_version (ih) == KEY_FORMAT_3_5) 17438c2ecf20Sopenharmony_ci#define sd_v1_mode(sdp) (le16_to_cpu((sdp)->sd_mode)) 17448c2ecf20Sopenharmony_ci#define set_sd_v1_mode(sdp,v) ((sdp)->sd_mode = cpu_to_le16(v)) 17458c2ecf20Sopenharmony_ci#define sd_v1_nlink(sdp) (le16_to_cpu((sdp)->sd_nlink)) 17468c2ecf20Sopenharmony_ci#define set_sd_v1_nlink(sdp,v) ((sdp)->sd_nlink = cpu_to_le16(v)) 17478c2ecf20Sopenharmony_ci#define sd_v1_uid(sdp) (le16_to_cpu((sdp)->sd_uid)) 17488c2ecf20Sopenharmony_ci#define set_sd_v1_uid(sdp,v) ((sdp)->sd_uid = cpu_to_le16(v)) 17498c2ecf20Sopenharmony_ci#define sd_v1_gid(sdp) (le16_to_cpu((sdp)->sd_gid)) 17508c2ecf20Sopenharmony_ci#define set_sd_v1_gid(sdp,v) ((sdp)->sd_gid = cpu_to_le16(v)) 17518c2ecf20Sopenharmony_ci#define sd_v1_size(sdp) (le32_to_cpu((sdp)->sd_size)) 17528c2ecf20Sopenharmony_ci#define set_sd_v1_size(sdp,v) ((sdp)->sd_size = cpu_to_le32(v)) 17538c2ecf20Sopenharmony_ci#define sd_v1_atime(sdp) (le32_to_cpu((sdp)->sd_atime)) 17548c2ecf20Sopenharmony_ci#define set_sd_v1_atime(sdp,v) ((sdp)->sd_atime = cpu_to_le32(v)) 17558c2ecf20Sopenharmony_ci#define sd_v1_mtime(sdp) (le32_to_cpu((sdp)->sd_mtime)) 17568c2ecf20Sopenharmony_ci#define set_sd_v1_mtime(sdp,v) ((sdp)->sd_mtime = cpu_to_le32(v)) 17578c2ecf20Sopenharmony_ci#define sd_v1_ctime(sdp) (le32_to_cpu((sdp)->sd_ctime)) 17588c2ecf20Sopenharmony_ci#define set_sd_v1_ctime(sdp,v) ((sdp)->sd_ctime = cpu_to_le32(v)) 17598c2ecf20Sopenharmony_ci#define sd_v1_rdev(sdp) (le32_to_cpu((sdp)->u.sd_rdev)) 17608c2ecf20Sopenharmony_ci#define set_sd_v1_rdev(sdp,v) ((sdp)->u.sd_rdev = cpu_to_le32(v)) 17618c2ecf20Sopenharmony_ci#define sd_v1_blocks(sdp) (le32_to_cpu((sdp)->u.sd_blocks)) 17628c2ecf20Sopenharmony_ci#define set_sd_v1_blocks(sdp,v) ((sdp)->u.sd_blocks = cpu_to_le32(v)) 17638c2ecf20Sopenharmony_ci#define sd_v1_first_direct_byte(sdp) \ 17648c2ecf20Sopenharmony_ci (le32_to_cpu((sdp)->sd_first_direct_byte)) 17658c2ecf20Sopenharmony_ci#define set_sd_v1_first_direct_byte(sdp,v) \ 17668c2ecf20Sopenharmony_ci ((sdp)->sd_first_direct_byte = cpu_to_le32(v)) 17678c2ecf20Sopenharmony_ci 17688c2ecf20Sopenharmony_ci/* inode flags stored in sd_attrs (nee sd_reserved) */ 17698c2ecf20Sopenharmony_ci 17708c2ecf20Sopenharmony_ci/* 17718c2ecf20Sopenharmony_ci * we want common flags to have the same values as in ext2, 17728c2ecf20Sopenharmony_ci * so chattr(1) will work without problems 17738c2ecf20Sopenharmony_ci */ 17748c2ecf20Sopenharmony_ci#define REISERFS_IMMUTABLE_FL FS_IMMUTABLE_FL 17758c2ecf20Sopenharmony_ci#define REISERFS_APPEND_FL FS_APPEND_FL 17768c2ecf20Sopenharmony_ci#define REISERFS_SYNC_FL FS_SYNC_FL 17778c2ecf20Sopenharmony_ci#define REISERFS_NOATIME_FL FS_NOATIME_FL 17788c2ecf20Sopenharmony_ci#define REISERFS_NODUMP_FL FS_NODUMP_FL 17798c2ecf20Sopenharmony_ci#define REISERFS_SECRM_FL FS_SECRM_FL 17808c2ecf20Sopenharmony_ci#define REISERFS_UNRM_FL FS_UNRM_FL 17818c2ecf20Sopenharmony_ci#define REISERFS_COMPR_FL FS_COMPR_FL 17828c2ecf20Sopenharmony_ci#define REISERFS_NOTAIL_FL FS_NOTAIL_FL 17838c2ecf20Sopenharmony_ci 17848c2ecf20Sopenharmony_ci/* persistent flags that file inherits from the parent directory */ 17858c2ecf20Sopenharmony_ci#define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL | \ 17868c2ecf20Sopenharmony_ci REISERFS_SYNC_FL | \ 17878c2ecf20Sopenharmony_ci REISERFS_NOATIME_FL | \ 17888c2ecf20Sopenharmony_ci REISERFS_NODUMP_FL | \ 17898c2ecf20Sopenharmony_ci REISERFS_SECRM_FL | \ 17908c2ecf20Sopenharmony_ci REISERFS_COMPR_FL | \ 17918c2ecf20Sopenharmony_ci REISERFS_NOTAIL_FL ) 17928c2ecf20Sopenharmony_ci 17938c2ecf20Sopenharmony_ci/* 17948c2ecf20Sopenharmony_ci * Stat Data on disk (reiserfs version of UFS disk inode minus the 17958c2ecf20Sopenharmony_ci * address blocks) 17968c2ecf20Sopenharmony_ci */ 17978c2ecf20Sopenharmony_cistruct stat_data { 17988c2ecf20Sopenharmony_ci __le16 sd_mode; /* file type, permissions */ 17998c2ecf20Sopenharmony_ci __le16 sd_attrs; /* persistent inode flags */ 18008c2ecf20Sopenharmony_ci __le32 sd_nlink; /* number of hard links */ 18018c2ecf20Sopenharmony_ci __le64 sd_size; /* file size */ 18028c2ecf20Sopenharmony_ci __le32 sd_uid; /* owner */ 18038c2ecf20Sopenharmony_ci __le32 sd_gid; /* group */ 18048c2ecf20Sopenharmony_ci __le32 sd_atime; /* time of last access */ 18058c2ecf20Sopenharmony_ci __le32 sd_mtime; /* time file was last modified */ 18068c2ecf20Sopenharmony_ci 18078c2ecf20Sopenharmony_ci /* 18088c2ecf20Sopenharmony_ci * time inode (stat data) was last changed 18098c2ecf20Sopenharmony_ci * (except changes to sd_atime and sd_mtime) 18108c2ecf20Sopenharmony_ci */ 18118c2ecf20Sopenharmony_ci __le32 sd_ctime; 18128c2ecf20Sopenharmony_ci __le32 sd_blocks; 18138c2ecf20Sopenharmony_ci union { 18148c2ecf20Sopenharmony_ci __le32 sd_rdev; 18158c2ecf20Sopenharmony_ci __le32 sd_generation; 18168c2ecf20Sopenharmony_ci } __attribute__ ((__packed__)) u; 18178c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 18188c2ecf20Sopenharmony_ci 18198c2ecf20Sopenharmony_ci/* this is 44 bytes long */ 18208c2ecf20Sopenharmony_ci#define SD_SIZE (sizeof(struct stat_data)) 18218c2ecf20Sopenharmony_ci#define SD_V2_SIZE SD_SIZE 18228c2ecf20Sopenharmony_ci#define stat_data_v2(ih) (ih_version (ih) == KEY_FORMAT_3_6) 18238c2ecf20Sopenharmony_ci#define sd_v2_mode(sdp) (le16_to_cpu((sdp)->sd_mode)) 18248c2ecf20Sopenharmony_ci#define set_sd_v2_mode(sdp,v) ((sdp)->sd_mode = cpu_to_le16(v)) 18258c2ecf20Sopenharmony_ci/* sd_reserved */ 18268c2ecf20Sopenharmony_ci/* set_sd_reserved */ 18278c2ecf20Sopenharmony_ci#define sd_v2_nlink(sdp) (le32_to_cpu((sdp)->sd_nlink)) 18288c2ecf20Sopenharmony_ci#define set_sd_v2_nlink(sdp,v) ((sdp)->sd_nlink = cpu_to_le32(v)) 18298c2ecf20Sopenharmony_ci#define sd_v2_size(sdp) (le64_to_cpu((sdp)->sd_size)) 18308c2ecf20Sopenharmony_ci#define set_sd_v2_size(sdp,v) ((sdp)->sd_size = cpu_to_le64(v)) 18318c2ecf20Sopenharmony_ci#define sd_v2_uid(sdp) (le32_to_cpu((sdp)->sd_uid)) 18328c2ecf20Sopenharmony_ci#define set_sd_v2_uid(sdp,v) ((sdp)->sd_uid = cpu_to_le32(v)) 18338c2ecf20Sopenharmony_ci#define sd_v2_gid(sdp) (le32_to_cpu((sdp)->sd_gid)) 18348c2ecf20Sopenharmony_ci#define set_sd_v2_gid(sdp,v) ((sdp)->sd_gid = cpu_to_le32(v)) 18358c2ecf20Sopenharmony_ci#define sd_v2_atime(sdp) (le32_to_cpu((sdp)->sd_atime)) 18368c2ecf20Sopenharmony_ci#define set_sd_v2_atime(sdp,v) ((sdp)->sd_atime = cpu_to_le32(v)) 18378c2ecf20Sopenharmony_ci#define sd_v2_mtime(sdp) (le32_to_cpu((sdp)->sd_mtime)) 18388c2ecf20Sopenharmony_ci#define set_sd_v2_mtime(sdp,v) ((sdp)->sd_mtime = cpu_to_le32(v)) 18398c2ecf20Sopenharmony_ci#define sd_v2_ctime(sdp) (le32_to_cpu((sdp)->sd_ctime)) 18408c2ecf20Sopenharmony_ci#define set_sd_v2_ctime(sdp,v) ((sdp)->sd_ctime = cpu_to_le32(v)) 18418c2ecf20Sopenharmony_ci#define sd_v2_blocks(sdp) (le32_to_cpu((sdp)->sd_blocks)) 18428c2ecf20Sopenharmony_ci#define set_sd_v2_blocks(sdp,v) ((sdp)->sd_blocks = cpu_to_le32(v)) 18438c2ecf20Sopenharmony_ci#define sd_v2_rdev(sdp) (le32_to_cpu((sdp)->u.sd_rdev)) 18448c2ecf20Sopenharmony_ci#define set_sd_v2_rdev(sdp,v) ((sdp)->u.sd_rdev = cpu_to_le32(v)) 18458c2ecf20Sopenharmony_ci#define sd_v2_generation(sdp) (le32_to_cpu((sdp)->u.sd_generation)) 18468c2ecf20Sopenharmony_ci#define set_sd_v2_generation(sdp,v) ((sdp)->u.sd_generation = cpu_to_le32(v)) 18478c2ecf20Sopenharmony_ci#define sd_v2_attrs(sdp) (le16_to_cpu((sdp)->sd_attrs)) 18488c2ecf20Sopenharmony_ci#define set_sd_v2_attrs(sdp,v) ((sdp)->sd_attrs = cpu_to_le16(v)) 18498c2ecf20Sopenharmony_ci 18508c2ecf20Sopenharmony_ci/*************************************************************************** 18518c2ecf20Sopenharmony_ci * DIRECTORY STRUCTURE * 18528c2ecf20Sopenharmony_ci ***************************************************************************/ 18538c2ecf20Sopenharmony_ci/* 18548c2ecf20Sopenharmony_ci * Picture represents the structure of directory items 18558c2ecf20Sopenharmony_ci * ________________________________________________ 18568c2ecf20Sopenharmony_ci * | Array of | | | | | | 18578c2ecf20Sopenharmony_ci * | directory |N-1| N-2 | .... | 1st |0th| 18588c2ecf20Sopenharmony_ci * | entry headers | | | | | | 18598c2ecf20Sopenharmony_ci * |_______________|___|_____|________|_______|___| 18608c2ecf20Sopenharmony_ci * <---- directory entries ------> 18618c2ecf20Sopenharmony_ci * 18628c2ecf20Sopenharmony_ci * First directory item has k_offset component 1. We store "." and ".." 18638c2ecf20Sopenharmony_ci * in one item, always, we never split "." and ".." into differing 18648c2ecf20Sopenharmony_ci * items. This makes, among other things, the code for removing 18658c2ecf20Sopenharmony_ci * directories simpler. 18668c2ecf20Sopenharmony_ci */ 18678c2ecf20Sopenharmony_ci#define SD_OFFSET 0 18688c2ecf20Sopenharmony_ci#define SD_UNIQUENESS 0 18698c2ecf20Sopenharmony_ci#define DOT_OFFSET 1 18708c2ecf20Sopenharmony_ci#define DOT_DOT_OFFSET 2 18718c2ecf20Sopenharmony_ci#define DIRENTRY_UNIQUENESS 500 18728c2ecf20Sopenharmony_ci 18738c2ecf20Sopenharmony_ci#define FIRST_ITEM_OFFSET 1 18748c2ecf20Sopenharmony_ci 18758c2ecf20Sopenharmony_ci/* 18768c2ecf20Sopenharmony_ci * Q: How to get key of object pointed to by entry from entry? 18778c2ecf20Sopenharmony_ci * 18788c2ecf20Sopenharmony_ci * A: Each directory entry has its header. This header has deh_dir_id 18798c2ecf20Sopenharmony_ci * and deh_objectid fields, those are key of object, entry points to 18808c2ecf20Sopenharmony_ci */ 18818c2ecf20Sopenharmony_ci 18828c2ecf20Sopenharmony_ci/* 18838c2ecf20Sopenharmony_ci * NOT IMPLEMENTED: 18848c2ecf20Sopenharmony_ci * Directory will someday contain stat data of object 18858c2ecf20Sopenharmony_ci */ 18868c2ecf20Sopenharmony_ci 18878c2ecf20Sopenharmony_cistruct reiserfs_de_head { 18888c2ecf20Sopenharmony_ci __le32 deh_offset; /* third component of the directory entry key */ 18898c2ecf20Sopenharmony_ci 18908c2ecf20Sopenharmony_ci /* 18918c2ecf20Sopenharmony_ci * objectid of the parent directory of the object, that is referenced 18928c2ecf20Sopenharmony_ci * by directory entry 18938c2ecf20Sopenharmony_ci */ 18948c2ecf20Sopenharmony_ci __le32 deh_dir_id; 18958c2ecf20Sopenharmony_ci 18968c2ecf20Sopenharmony_ci /* objectid of the object, that is referenced by directory entry */ 18978c2ecf20Sopenharmony_ci __le32 deh_objectid; 18988c2ecf20Sopenharmony_ci __le16 deh_location; /* offset of name in the whole item */ 18998c2ecf20Sopenharmony_ci 19008c2ecf20Sopenharmony_ci /* 19018c2ecf20Sopenharmony_ci * whether 1) entry contains stat data (for future), and 19028c2ecf20Sopenharmony_ci * 2) whether entry is hidden (unlinked) 19038c2ecf20Sopenharmony_ci */ 19048c2ecf20Sopenharmony_ci __le16 deh_state; 19058c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 19068c2ecf20Sopenharmony_ci#define DEH_SIZE sizeof(struct reiserfs_de_head) 19078c2ecf20Sopenharmony_ci#define deh_offset(p_deh) (le32_to_cpu((p_deh)->deh_offset)) 19088c2ecf20Sopenharmony_ci#define deh_dir_id(p_deh) (le32_to_cpu((p_deh)->deh_dir_id)) 19098c2ecf20Sopenharmony_ci#define deh_objectid(p_deh) (le32_to_cpu((p_deh)->deh_objectid)) 19108c2ecf20Sopenharmony_ci#define deh_location(p_deh) (le16_to_cpu((p_deh)->deh_location)) 19118c2ecf20Sopenharmony_ci#define deh_state(p_deh) (le16_to_cpu((p_deh)->deh_state)) 19128c2ecf20Sopenharmony_ci 19138c2ecf20Sopenharmony_ci#define put_deh_offset(p_deh,v) ((p_deh)->deh_offset = cpu_to_le32((v))) 19148c2ecf20Sopenharmony_ci#define put_deh_dir_id(p_deh,v) ((p_deh)->deh_dir_id = cpu_to_le32((v))) 19158c2ecf20Sopenharmony_ci#define put_deh_objectid(p_deh,v) ((p_deh)->deh_objectid = cpu_to_le32((v))) 19168c2ecf20Sopenharmony_ci#define put_deh_location(p_deh,v) ((p_deh)->deh_location = cpu_to_le16((v))) 19178c2ecf20Sopenharmony_ci#define put_deh_state(p_deh,v) ((p_deh)->deh_state = cpu_to_le16((v))) 19188c2ecf20Sopenharmony_ci 19198c2ecf20Sopenharmony_ci/* empty directory contains two entries "." and ".." and their headers */ 19208c2ecf20Sopenharmony_ci#define EMPTY_DIR_SIZE \ 19218c2ecf20Sopenharmony_ci(DEH_SIZE * 2 + ROUND_UP (sizeof(".") - 1) + ROUND_UP (sizeof("..") - 1)) 19228c2ecf20Sopenharmony_ci 19238c2ecf20Sopenharmony_ci/* old format directories have this size when empty */ 19248c2ecf20Sopenharmony_ci#define EMPTY_DIR_SIZE_V1 (DEH_SIZE * 2 + 3) 19258c2ecf20Sopenharmony_ci 19268c2ecf20Sopenharmony_ci#define DEH_Statdata 0 /* not used now */ 19278c2ecf20Sopenharmony_ci#define DEH_Visible 2 19288c2ecf20Sopenharmony_ci 19298c2ecf20Sopenharmony_ci/* 64 bit systems (and the S/390) need to be aligned explicitly -jdm */ 19308c2ecf20Sopenharmony_ci#if BITS_PER_LONG == 64 || defined(__s390__) || defined(__hppa__) 19318c2ecf20Sopenharmony_ci# define ADDR_UNALIGNED_BITS (3) 19328c2ecf20Sopenharmony_ci#endif 19338c2ecf20Sopenharmony_ci 19348c2ecf20Sopenharmony_ci/* 19358c2ecf20Sopenharmony_ci * These are only used to manipulate deh_state. 19368c2ecf20Sopenharmony_ci * Because of this, we'll use the ext2_ bit routines, 19378c2ecf20Sopenharmony_ci * since they are little endian 19388c2ecf20Sopenharmony_ci */ 19398c2ecf20Sopenharmony_ci#ifdef ADDR_UNALIGNED_BITS 19408c2ecf20Sopenharmony_ci 19418c2ecf20Sopenharmony_ci# define aligned_address(addr) ((void *)((long)(addr) & ~((1UL << ADDR_UNALIGNED_BITS) - 1))) 19428c2ecf20Sopenharmony_ci# define unaligned_offset(addr) (((int)((long)(addr) & ((1 << ADDR_UNALIGNED_BITS) - 1))) << 3) 19438c2ecf20Sopenharmony_ci 19448c2ecf20Sopenharmony_ci# define set_bit_unaligned(nr, addr) \ 19458c2ecf20Sopenharmony_ci __test_and_set_bit_le((nr) + unaligned_offset(addr), aligned_address(addr)) 19468c2ecf20Sopenharmony_ci# define clear_bit_unaligned(nr, addr) \ 19478c2ecf20Sopenharmony_ci __test_and_clear_bit_le((nr) + unaligned_offset(addr), aligned_address(addr)) 19488c2ecf20Sopenharmony_ci# define test_bit_unaligned(nr, addr) \ 19498c2ecf20Sopenharmony_ci test_bit_le((nr) + unaligned_offset(addr), aligned_address(addr)) 19508c2ecf20Sopenharmony_ci 19518c2ecf20Sopenharmony_ci#else 19528c2ecf20Sopenharmony_ci 19538c2ecf20Sopenharmony_ci# define set_bit_unaligned(nr, addr) __test_and_set_bit_le(nr, addr) 19548c2ecf20Sopenharmony_ci# define clear_bit_unaligned(nr, addr) __test_and_clear_bit_le(nr, addr) 19558c2ecf20Sopenharmony_ci# define test_bit_unaligned(nr, addr) test_bit_le(nr, addr) 19568c2ecf20Sopenharmony_ci 19578c2ecf20Sopenharmony_ci#endif 19588c2ecf20Sopenharmony_ci 19598c2ecf20Sopenharmony_ci#define mark_de_with_sd(deh) set_bit_unaligned (DEH_Statdata, &((deh)->deh_state)) 19608c2ecf20Sopenharmony_ci#define mark_de_without_sd(deh) clear_bit_unaligned (DEH_Statdata, &((deh)->deh_state)) 19618c2ecf20Sopenharmony_ci#define mark_de_visible(deh) set_bit_unaligned (DEH_Visible, &((deh)->deh_state)) 19628c2ecf20Sopenharmony_ci#define mark_de_hidden(deh) clear_bit_unaligned (DEH_Visible, &((deh)->deh_state)) 19638c2ecf20Sopenharmony_ci 19648c2ecf20Sopenharmony_ci#define de_with_sd(deh) test_bit_unaligned (DEH_Statdata, &((deh)->deh_state)) 19658c2ecf20Sopenharmony_ci#define de_visible(deh) test_bit_unaligned (DEH_Visible, &((deh)->deh_state)) 19668c2ecf20Sopenharmony_ci#define de_hidden(deh) !test_bit_unaligned (DEH_Visible, &((deh)->deh_state)) 19678c2ecf20Sopenharmony_ci 19688c2ecf20Sopenharmony_ciextern void make_empty_dir_item_v1(char *body, __le32 dirid, __le32 objid, 19698c2ecf20Sopenharmony_ci __le32 par_dirid, __le32 par_objid); 19708c2ecf20Sopenharmony_ciextern void make_empty_dir_item(char *body, __le32 dirid, __le32 objid, 19718c2ecf20Sopenharmony_ci __le32 par_dirid, __le32 par_objid); 19728c2ecf20Sopenharmony_ci 19738c2ecf20Sopenharmony_ci/* two entries per block (at least) */ 19748c2ecf20Sopenharmony_ci#define REISERFS_MAX_NAME(block_size) 255 19758c2ecf20Sopenharmony_ci 19768c2ecf20Sopenharmony_ci/* 19778c2ecf20Sopenharmony_ci * this structure is used for operations on directory entries. It is 19788c2ecf20Sopenharmony_ci * not a disk structure. 19798c2ecf20Sopenharmony_ci * 19808c2ecf20Sopenharmony_ci * When reiserfs_find_entry or search_by_entry_key find directory 19818c2ecf20Sopenharmony_ci * entry, they return filled reiserfs_dir_entry structure 19828c2ecf20Sopenharmony_ci */ 19838c2ecf20Sopenharmony_cistruct reiserfs_dir_entry { 19848c2ecf20Sopenharmony_ci struct buffer_head *de_bh; 19858c2ecf20Sopenharmony_ci int de_item_num; 19868c2ecf20Sopenharmony_ci struct item_head *de_ih; 19878c2ecf20Sopenharmony_ci int de_entry_num; 19888c2ecf20Sopenharmony_ci struct reiserfs_de_head *de_deh; 19898c2ecf20Sopenharmony_ci int de_entrylen; 19908c2ecf20Sopenharmony_ci int de_namelen; 19918c2ecf20Sopenharmony_ci char *de_name; 19928c2ecf20Sopenharmony_ci unsigned long *de_gen_number_bit_string; 19938c2ecf20Sopenharmony_ci 19948c2ecf20Sopenharmony_ci __u32 de_dir_id; 19958c2ecf20Sopenharmony_ci __u32 de_objectid; 19968c2ecf20Sopenharmony_ci 19978c2ecf20Sopenharmony_ci struct cpu_key de_entry_key; 19988c2ecf20Sopenharmony_ci}; 19998c2ecf20Sopenharmony_ci 20008c2ecf20Sopenharmony_ci/* 20018c2ecf20Sopenharmony_ci * these defines are useful when a particular member of 20028c2ecf20Sopenharmony_ci * a reiserfs_dir_entry is needed 20038c2ecf20Sopenharmony_ci */ 20048c2ecf20Sopenharmony_ci 20058c2ecf20Sopenharmony_ci/* pointer to file name, stored in entry */ 20068c2ecf20Sopenharmony_ci#define B_I_DEH_ENTRY_FILE_NAME(bh, ih, deh) \ 20078c2ecf20Sopenharmony_ci (ih_item_body(bh, ih) + deh_location(deh)) 20088c2ecf20Sopenharmony_ci 20098c2ecf20Sopenharmony_ci/* length of name */ 20108c2ecf20Sopenharmony_ci#define I_DEH_N_ENTRY_FILE_NAME_LENGTH(ih,deh,entry_num) \ 20118c2ecf20Sopenharmony_ci(I_DEH_N_ENTRY_LENGTH (ih, deh, entry_num) - (de_with_sd (deh) ? SD_SIZE : 0)) 20128c2ecf20Sopenharmony_ci 20138c2ecf20Sopenharmony_ci/* hash value occupies bits from 7 up to 30 */ 20148c2ecf20Sopenharmony_ci#define GET_HASH_VALUE(offset) ((offset) & 0x7fffff80LL) 20158c2ecf20Sopenharmony_ci/* generation number occupies 7 bits starting from 0 up to 6 */ 20168c2ecf20Sopenharmony_ci#define GET_GENERATION_NUMBER(offset) ((offset) & 0x7fLL) 20178c2ecf20Sopenharmony_ci#define MAX_GENERATION_NUMBER 127 20188c2ecf20Sopenharmony_ci 20198c2ecf20Sopenharmony_ci#define SET_GENERATION_NUMBER(offset,gen_number) (GET_HASH_VALUE(offset)|(gen_number)) 20208c2ecf20Sopenharmony_ci 20218c2ecf20Sopenharmony_ci/* 20228c2ecf20Sopenharmony_ci * Picture represents an internal node of the reiserfs tree 20238c2ecf20Sopenharmony_ci * ______________________________________________________ 20248c2ecf20Sopenharmony_ci * | | Array of | Array of | Free | 20258c2ecf20Sopenharmony_ci * |block | keys | pointers | space | 20268c2ecf20Sopenharmony_ci * | head | N | N+1 | | 20278c2ecf20Sopenharmony_ci * |______|_______________|___________________|___________| 20288c2ecf20Sopenharmony_ci */ 20298c2ecf20Sopenharmony_ci 20308c2ecf20Sopenharmony_ci/*************************************************************************** 20318c2ecf20Sopenharmony_ci * DISK CHILD * 20328c2ecf20Sopenharmony_ci ***************************************************************************/ 20338c2ecf20Sopenharmony_ci/* 20348c2ecf20Sopenharmony_ci * Disk child pointer: 20358c2ecf20Sopenharmony_ci * The pointer from an internal node of the tree to a node that is on disk. 20368c2ecf20Sopenharmony_ci */ 20378c2ecf20Sopenharmony_cistruct disk_child { 20388c2ecf20Sopenharmony_ci __le32 dc_block_number; /* Disk child's block number. */ 20398c2ecf20Sopenharmony_ci __le16 dc_size; /* Disk child's used space. */ 20408c2ecf20Sopenharmony_ci __le16 dc_reserved; 20418c2ecf20Sopenharmony_ci}; 20428c2ecf20Sopenharmony_ci 20438c2ecf20Sopenharmony_ci#define DC_SIZE (sizeof(struct disk_child)) 20448c2ecf20Sopenharmony_ci#define dc_block_number(dc_p) (le32_to_cpu((dc_p)->dc_block_number)) 20458c2ecf20Sopenharmony_ci#define dc_size(dc_p) (le16_to_cpu((dc_p)->dc_size)) 20468c2ecf20Sopenharmony_ci#define put_dc_block_number(dc_p, val) do { (dc_p)->dc_block_number = cpu_to_le32(val); } while(0) 20478c2ecf20Sopenharmony_ci#define put_dc_size(dc_p, val) do { (dc_p)->dc_size = cpu_to_le16(val); } while(0) 20488c2ecf20Sopenharmony_ci 20498c2ecf20Sopenharmony_ci/* Get disk child by buffer header and position in the tree node. */ 20508c2ecf20Sopenharmony_ci#define B_N_CHILD(bh, n_pos) ((struct disk_child *)\ 20518c2ecf20Sopenharmony_ci((bh)->b_data + BLKH_SIZE + B_NR_ITEMS(bh) * KEY_SIZE + DC_SIZE * (n_pos))) 20528c2ecf20Sopenharmony_ci 20538c2ecf20Sopenharmony_ci/* Get disk child number by buffer header and position in the tree node. */ 20548c2ecf20Sopenharmony_ci#define B_N_CHILD_NUM(bh, n_pos) (dc_block_number(B_N_CHILD(bh, n_pos))) 20558c2ecf20Sopenharmony_ci#define PUT_B_N_CHILD_NUM(bh, n_pos, val) \ 20568c2ecf20Sopenharmony_ci (put_dc_block_number(B_N_CHILD(bh, n_pos), val)) 20578c2ecf20Sopenharmony_ci 20588c2ecf20Sopenharmony_ci /* maximal value of field child_size in structure disk_child */ 20598c2ecf20Sopenharmony_ci /* child size is the combined size of all items and their headers */ 20608c2ecf20Sopenharmony_ci#define MAX_CHILD_SIZE(bh) ((int)( (bh)->b_size - BLKH_SIZE )) 20618c2ecf20Sopenharmony_ci 20628c2ecf20Sopenharmony_ci/* amount of used space in buffer (not including block head) */ 20638c2ecf20Sopenharmony_ci#define B_CHILD_SIZE(cur) (MAX_CHILD_SIZE(cur)-(B_FREE_SPACE(cur))) 20648c2ecf20Sopenharmony_ci 20658c2ecf20Sopenharmony_ci/* max and min number of keys in internal node */ 20668c2ecf20Sopenharmony_ci#define MAX_NR_KEY(bh) ( (MAX_CHILD_SIZE(bh)-DC_SIZE)/(KEY_SIZE+DC_SIZE) ) 20678c2ecf20Sopenharmony_ci#define MIN_NR_KEY(bh) (MAX_NR_KEY(bh)/2) 20688c2ecf20Sopenharmony_ci 20698c2ecf20Sopenharmony_ci/*************************************************************************** 20708c2ecf20Sopenharmony_ci * PATH STRUCTURES AND DEFINES * 20718c2ecf20Sopenharmony_ci ***************************************************************************/ 20728c2ecf20Sopenharmony_ci 20738c2ecf20Sopenharmony_ci/* 20748c2ecf20Sopenharmony_ci * search_by_key fills up the path from the root to the leaf as it descends 20758c2ecf20Sopenharmony_ci * the tree looking for the key. It uses reiserfs_bread to try to find 20768c2ecf20Sopenharmony_ci * buffers in the cache given their block number. If it does not find 20778c2ecf20Sopenharmony_ci * them in the cache it reads them from disk. For each node search_by_key 20788c2ecf20Sopenharmony_ci * finds using reiserfs_bread it then uses bin_search to look through that 20798c2ecf20Sopenharmony_ci * node. bin_search will find the position of the block_number of the next 20808c2ecf20Sopenharmony_ci * node if it is looking through an internal node. If it is looking through 20818c2ecf20Sopenharmony_ci * a leaf node bin_search will find the position of the item which has key 20828c2ecf20Sopenharmony_ci * either equal to given key, or which is the maximal key less than the 20838c2ecf20Sopenharmony_ci * given key. 20848c2ecf20Sopenharmony_ci */ 20858c2ecf20Sopenharmony_ci 20868c2ecf20Sopenharmony_cistruct path_element { 20878c2ecf20Sopenharmony_ci /* Pointer to the buffer at the path in the tree. */ 20888c2ecf20Sopenharmony_ci struct buffer_head *pe_buffer; 20898c2ecf20Sopenharmony_ci /* Position in the tree node which is placed in the buffer above. */ 20908c2ecf20Sopenharmony_ci int pe_position; 20918c2ecf20Sopenharmony_ci}; 20928c2ecf20Sopenharmony_ci 20938c2ecf20Sopenharmony_ci/* 20948c2ecf20Sopenharmony_ci * maximal height of a tree. don't change this without 20958c2ecf20Sopenharmony_ci * changing JOURNAL_PER_BALANCE_CNT 20968c2ecf20Sopenharmony_ci */ 20978c2ecf20Sopenharmony_ci#define MAX_HEIGHT 5 20988c2ecf20Sopenharmony_ci 20998c2ecf20Sopenharmony_ci/* Must be equals MAX_HEIGHT + FIRST_PATH_ELEMENT_OFFSET */ 21008c2ecf20Sopenharmony_ci#define EXTENDED_MAX_HEIGHT 7 21018c2ecf20Sopenharmony_ci 21028c2ecf20Sopenharmony_ci/* Must be equal to at least 2. */ 21038c2ecf20Sopenharmony_ci#define FIRST_PATH_ELEMENT_OFFSET 2 21048c2ecf20Sopenharmony_ci 21058c2ecf20Sopenharmony_ci/* Must be equal to FIRST_PATH_ELEMENT_OFFSET - 1 */ 21068c2ecf20Sopenharmony_ci#define ILLEGAL_PATH_ELEMENT_OFFSET 1 21078c2ecf20Sopenharmony_ci 21088c2ecf20Sopenharmony_ci/* this MUST be MAX_HEIGHT + 1. See about FEB below */ 21098c2ecf20Sopenharmony_ci#define MAX_FEB_SIZE 6 21108c2ecf20Sopenharmony_ci 21118c2ecf20Sopenharmony_ci/* 21128c2ecf20Sopenharmony_ci * We need to keep track of who the ancestors of nodes are. When we 21138c2ecf20Sopenharmony_ci * perform a search we record which nodes were visited while 21148c2ecf20Sopenharmony_ci * descending the tree looking for the node we searched for. This list 21158c2ecf20Sopenharmony_ci * of nodes is called the path. This information is used while 21168c2ecf20Sopenharmony_ci * performing balancing. Note that this path information may become 21178c2ecf20Sopenharmony_ci * invalid, and this means we must check it when using it to see if it 21188c2ecf20Sopenharmony_ci * is still valid. You'll need to read search_by_key and the comments 21198c2ecf20Sopenharmony_ci * in it, especially about decrement_counters_in_path(), to understand 21208c2ecf20Sopenharmony_ci * this structure. 21218c2ecf20Sopenharmony_ci * 21228c2ecf20Sopenharmony_ci * Paths make the code so much harder to work with and debug.... An 21238c2ecf20Sopenharmony_ci * enormous number of bugs are due to them, and trying to write or modify 21248c2ecf20Sopenharmony_ci * code that uses them just makes my head hurt. They are based on an 21258c2ecf20Sopenharmony_ci * excessive effort to avoid disturbing the precious VFS code.:-( The 21268c2ecf20Sopenharmony_ci * gods only know how we are going to SMP the code that uses them. 21278c2ecf20Sopenharmony_ci * znodes are the way! 21288c2ecf20Sopenharmony_ci */ 21298c2ecf20Sopenharmony_ci 21308c2ecf20Sopenharmony_ci#define PATH_READA 0x1 /* do read ahead */ 21318c2ecf20Sopenharmony_ci#define PATH_READA_BACK 0x2 /* read backwards */ 21328c2ecf20Sopenharmony_ci 21338c2ecf20Sopenharmony_cistruct treepath { 21348c2ecf20Sopenharmony_ci int path_length; /* Length of the array above. */ 21358c2ecf20Sopenharmony_ci int reada; 21368c2ecf20Sopenharmony_ci /* Array of the path elements. */ 21378c2ecf20Sopenharmony_ci struct path_element path_elements[EXTENDED_MAX_HEIGHT]; 21388c2ecf20Sopenharmony_ci int pos_in_item; 21398c2ecf20Sopenharmony_ci}; 21408c2ecf20Sopenharmony_ci 21418c2ecf20Sopenharmony_ci#define pos_in_item(path) ((path)->pos_in_item) 21428c2ecf20Sopenharmony_ci 21438c2ecf20Sopenharmony_ci#define INITIALIZE_PATH(var) \ 21448c2ecf20Sopenharmony_cistruct treepath var = {.path_length = ILLEGAL_PATH_ELEMENT_OFFSET, .reada = 0,} 21458c2ecf20Sopenharmony_ci 21468c2ecf20Sopenharmony_ci/* Get path element by path and path position. */ 21478c2ecf20Sopenharmony_ci#define PATH_OFFSET_PELEMENT(path, n_offset) ((path)->path_elements + (n_offset)) 21488c2ecf20Sopenharmony_ci 21498c2ecf20Sopenharmony_ci/* Get buffer header at the path by path and path position. */ 21508c2ecf20Sopenharmony_ci#define PATH_OFFSET_PBUFFER(path, n_offset) (PATH_OFFSET_PELEMENT(path, n_offset)->pe_buffer) 21518c2ecf20Sopenharmony_ci 21528c2ecf20Sopenharmony_ci/* Get position in the element at the path by path and path position. */ 21538c2ecf20Sopenharmony_ci#define PATH_OFFSET_POSITION(path, n_offset) (PATH_OFFSET_PELEMENT(path, n_offset)->pe_position) 21548c2ecf20Sopenharmony_ci 21558c2ecf20Sopenharmony_ci#define PATH_PLAST_BUFFER(path) (PATH_OFFSET_PBUFFER((path), (path)->path_length)) 21568c2ecf20Sopenharmony_ci 21578c2ecf20Sopenharmony_ci/* 21588c2ecf20Sopenharmony_ci * you know, to the person who didn't write this the macro name does not 21598c2ecf20Sopenharmony_ci * at first suggest what it does. Maybe POSITION_FROM_PATH_END? Or 21608c2ecf20Sopenharmony_ci * maybe we should just focus on dumping paths... -Hans 21618c2ecf20Sopenharmony_ci */ 21628c2ecf20Sopenharmony_ci#define PATH_LAST_POSITION(path) (PATH_OFFSET_POSITION((path), (path)->path_length)) 21638c2ecf20Sopenharmony_ci 21648c2ecf20Sopenharmony_ci/* 21658c2ecf20Sopenharmony_ci * in do_balance leaf has h == 0 in contrast with path structure, 21668c2ecf20Sopenharmony_ci * where root has level == 0. That is why we need these defines 21678c2ecf20Sopenharmony_ci */ 21688c2ecf20Sopenharmony_ci 21698c2ecf20Sopenharmony_ci/* tb->S[h] */ 21708c2ecf20Sopenharmony_ci#define PATH_H_PBUFFER(path, h) \ 21718c2ecf20Sopenharmony_ci PATH_OFFSET_PBUFFER(path, path->path_length - (h)) 21728c2ecf20Sopenharmony_ci 21738c2ecf20Sopenharmony_ci/* tb->F[h] or tb->S[0]->b_parent */ 21748c2ecf20Sopenharmony_ci#define PATH_H_PPARENT(path, h) PATH_H_PBUFFER(path, (h) + 1) 21758c2ecf20Sopenharmony_ci 21768c2ecf20Sopenharmony_ci#define PATH_H_POSITION(path, h) \ 21778c2ecf20Sopenharmony_ci PATH_OFFSET_POSITION(path, path->path_length - (h)) 21788c2ecf20Sopenharmony_ci 21798c2ecf20Sopenharmony_ci/* tb->S[h]->b_item_order */ 21808c2ecf20Sopenharmony_ci#define PATH_H_B_ITEM_ORDER(path, h) PATH_H_POSITION(path, h + 1) 21818c2ecf20Sopenharmony_ci 21828c2ecf20Sopenharmony_ci#define PATH_H_PATH_OFFSET(path, n_h) ((path)->path_length - (n_h)) 21838c2ecf20Sopenharmony_ci 21848c2ecf20Sopenharmony_cistatic inline void *reiserfs_node_data(const struct buffer_head *bh) 21858c2ecf20Sopenharmony_ci{ 21868c2ecf20Sopenharmony_ci return bh->b_data + sizeof(struct block_head); 21878c2ecf20Sopenharmony_ci} 21888c2ecf20Sopenharmony_ci 21898c2ecf20Sopenharmony_ci/* get key from internal node */ 21908c2ecf20Sopenharmony_cistatic inline struct reiserfs_key *internal_key(struct buffer_head *bh, 21918c2ecf20Sopenharmony_ci int item_num) 21928c2ecf20Sopenharmony_ci{ 21938c2ecf20Sopenharmony_ci struct reiserfs_key *key = reiserfs_node_data(bh); 21948c2ecf20Sopenharmony_ci 21958c2ecf20Sopenharmony_ci return &key[item_num]; 21968c2ecf20Sopenharmony_ci} 21978c2ecf20Sopenharmony_ci 21988c2ecf20Sopenharmony_ci/* get the item header from leaf node */ 21998c2ecf20Sopenharmony_cistatic inline struct item_head *item_head(const struct buffer_head *bh, 22008c2ecf20Sopenharmony_ci int item_num) 22018c2ecf20Sopenharmony_ci{ 22028c2ecf20Sopenharmony_ci struct item_head *ih = reiserfs_node_data(bh); 22038c2ecf20Sopenharmony_ci 22048c2ecf20Sopenharmony_ci return &ih[item_num]; 22058c2ecf20Sopenharmony_ci} 22068c2ecf20Sopenharmony_ci 22078c2ecf20Sopenharmony_ci/* get the key from leaf node */ 22088c2ecf20Sopenharmony_cistatic inline struct reiserfs_key *leaf_key(const struct buffer_head *bh, 22098c2ecf20Sopenharmony_ci int item_num) 22108c2ecf20Sopenharmony_ci{ 22118c2ecf20Sopenharmony_ci return &item_head(bh, item_num)->ih_key; 22128c2ecf20Sopenharmony_ci} 22138c2ecf20Sopenharmony_ci 22148c2ecf20Sopenharmony_cistatic inline void *ih_item_body(const struct buffer_head *bh, 22158c2ecf20Sopenharmony_ci const struct item_head *ih) 22168c2ecf20Sopenharmony_ci{ 22178c2ecf20Sopenharmony_ci return bh->b_data + ih_location(ih); 22188c2ecf20Sopenharmony_ci} 22198c2ecf20Sopenharmony_ci 22208c2ecf20Sopenharmony_ci/* get item body from leaf node */ 22218c2ecf20Sopenharmony_cistatic inline void *item_body(const struct buffer_head *bh, int item_num) 22228c2ecf20Sopenharmony_ci{ 22238c2ecf20Sopenharmony_ci return ih_item_body(bh, item_head(bh, item_num)); 22248c2ecf20Sopenharmony_ci} 22258c2ecf20Sopenharmony_ci 22268c2ecf20Sopenharmony_cistatic inline struct item_head *tp_item_head(const struct treepath *path) 22278c2ecf20Sopenharmony_ci{ 22288c2ecf20Sopenharmony_ci return item_head(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION(path)); 22298c2ecf20Sopenharmony_ci} 22308c2ecf20Sopenharmony_ci 22318c2ecf20Sopenharmony_cistatic inline void *tp_item_body(const struct treepath *path) 22328c2ecf20Sopenharmony_ci{ 22338c2ecf20Sopenharmony_ci return item_body(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION(path)); 22348c2ecf20Sopenharmony_ci} 22358c2ecf20Sopenharmony_ci 22368c2ecf20Sopenharmony_ci#define get_last_bh(path) PATH_PLAST_BUFFER(path) 22378c2ecf20Sopenharmony_ci#define get_item_pos(path) PATH_LAST_POSITION(path) 22388c2ecf20Sopenharmony_ci#define item_moved(ih,path) comp_items(ih, path) 22398c2ecf20Sopenharmony_ci#define path_changed(ih,path) comp_items (ih, path) 22408c2ecf20Sopenharmony_ci 22418c2ecf20Sopenharmony_ci/* array of the entry headers */ 22428c2ecf20Sopenharmony_ci /* get item body */ 22438c2ecf20Sopenharmony_ci#define B_I_DEH(bh, ih) ((struct reiserfs_de_head *)(ih_item_body(bh, ih))) 22448c2ecf20Sopenharmony_ci 22458c2ecf20Sopenharmony_ci/* 22468c2ecf20Sopenharmony_ci * length of the directory entry in directory item. This define 22478c2ecf20Sopenharmony_ci * calculates length of i-th directory entry using directory entry 22488c2ecf20Sopenharmony_ci * locations from dir entry head. When it calculates length of 0-th 22498c2ecf20Sopenharmony_ci * directory entry, it uses length of whole item in place of entry 22508c2ecf20Sopenharmony_ci * location of the non-existent following entry in the calculation. 22518c2ecf20Sopenharmony_ci * See picture above. 22528c2ecf20Sopenharmony_ci */ 22538c2ecf20Sopenharmony_cistatic inline int entry_length(const struct buffer_head *bh, 22548c2ecf20Sopenharmony_ci const struct item_head *ih, int pos_in_item) 22558c2ecf20Sopenharmony_ci{ 22568c2ecf20Sopenharmony_ci struct reiserfs_de_head *deh; 22578c2ecf20Sopenharmony_ci 22588c2ecf20Sopenharmony_ci deh = B_I_DEH(bh, ih) + pos_in_item; 22598c2ecf20Sopenharmony_ci if (pos_in_item) 22608c2ecf20Sopenharmony_ci return deh_location(deh - 1) - deh_location(deh); 22618c2ecf20Sopenharmony_ci 22628c2ecf20Sopenharmony_ci return ih_item_len(ih) - deh_location(deh); 22638c2ecf20Sopenharmony_ci} 22648c2ecf20Sopenharmony_ci 22658c2ecf20Sopenharmony_ci/*************************************************************************** 22668c2ecf20Sopenharmony_ci * MISC * 22678c2ecf20Sopenharmony_ci ***************************************************************************/ 22688c2ecf20Sopenharmony_ci 22698c2ecf20Sopenharmony_ci/* Size of pointer to the unformatted node. */ 22708c2ecf20Sopenharmony_ci#define UNFM_P_SIZE (sizeof(unp_t)) 22718c2ecf20Sopenharmony_ci#define UNFM_P_SHIFT 2 22728c2ecf20Sopenharmony_ci 22738c2ecf20Sopenharmony_ci/* in in-core inode key is stored on le form */ 22748c2ecf20Sopenharmony_ci#define INODE_PKEY(inode) ((struct reiserfs_key *)(REISERFS_I(inode)->i_key)) 22758c2ecf20Sopenharmony_ci 22768c2ecf20Sopenharmony_ci#define MAX_UL_INT 0xffffffff 22778c2ecf20Sopenharmony_ci#define MAX_INT 0x7ffffff 22788c2ecf20Sopenharmony_ci#define MAX_US_INT 0xffff 22798c2ecf20Sopenharmony_ci 22808c2ecf20Sopenharmony_ci// reiserfs version 2 has max offset 60 bits. Version 1 - 32 bit offset 22818c2ecf20Sopenharmony_cistatic inline loff_t max_reiserfs_offset(struct inode *inode) 22828c2ecf20Sopenharmony_ci{ 22838c2ecf20Sopenharmony_ci if (get_inode_item_key_version(inode) == KEY_FORMAT_3_5) 22848c2ecf20Sopenharmony_ci return (loff_t) U32_MAX; 22858c2ecf20Sopenharmony_ci 22868c2ecf20Sopenharmony_ci return (loff_t) ((~(__u64) 0) >> 4); 22878c2ecf20Sopenharmony_ci} 22888c2ecf20Sopenharmony_ci 22898c2ecf20Sopenharmony_ci#define MAX_KEY_OBJECTID MAX_UL_INT 22908c2ecf20Sopenharmony_ci 22918c2ecf20Sopenharmony_ci#define MAX_B_NUM MAX_UL_INT 22928c2ecf20Sopenharmony_ci#define MAX_FC_NUM MAX_US_INT 22938c2ecf20Sopenharmony_ci 22948c2ecf20Sopenharmony_ci/* the purpose is to detect overflow of an unsigned short */ 22958c2ecf20Sopenharmony_ci#define REISERFS_LINK_MAX (MAX_US_INT - 1000) 22968c2ecf20Sopenharmony_ci 22978c2ecf20Sopenharmony_ci/* 22988c2ecf20Sopenharmony_ci * The following defines are used in reiserfs_insert_item 22998c2ecf20Sopenharmony_ci * and reiserfs_append_item 23008c2ecf20Sopenharmony_ci */ 23018c2ecf20Sopenharmony_ci#define REISERFS_KERNEL_MEM 0 /* kernel memory mode */ 23028c2ecf20Sopenharmony_ci#define REISERFS_USER_MEM 1 /* user memory mode */ 23038c2ecf20Sopenharmony_ci 23048c2ecf20Sopenharmony_ci#define fs_generation(s) (REISERFS_SB(s)->s_generation_counter) 23058c2ecf20Sopenharmony_ci#define get_generation(s) atomic_read (&fs_generation(s)) 23068c2ecf20Sopenharmony_ci#define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen) 23078c2ecf20Sopenharmony_ci#define __fs_changed(gen,s) (gen != get_generation (s)) 23088c2ecf20Sopenharmony_ci#define fs_changed(gen,s) \ 23098c2ecf20Sopenharmony_ci({ \ 23108c2ecf20Sopenharmony_ci reiserfs_cond_resched(s); \ 23118c2ecf20Sopenharmony_ci __fs_changed(gen, s); \ 23128c2ecf20Sopenharmony_ci}) 23138c2ecf20Sopenharmony_ci 23148c2ecf20Sopenharmony_ci/*************************************************************************** 23158c2ecf20Sopenharmony_ci * FIXATE NODES * 23168c2ecf20Sopenharmony_ci ***************************************************************************/ 23178c2ecf20Sopenharmony_ci 23188c2ecf20Sopenharmony_ci#define VI_TYPE_LEFT_MERGEABLE 1 23198c2ecf20Sopenharmony_ci#define VI_TYPE_RIGHT_MERGEABLE 2 23208c2ecf20Sopenharmony_ci 23218c2ecf20Sopenharmony_ci/* 23228c2ecf20Sopenharmony_ci * To make any changes in the tree we always first find node, that 23238c2ecf20Sopenharmony_ci * contains item to be changed/deleted or place to insert a new 23248c2ecf20Sopenharmony_ci * item. We call this node S. To do balancing we need to decide what 23258c2ecf20Sopenharmony_ci * we will shift to left/right neighbor, or to a new node, where new 23268c2ecf20Sopenharmony_ci * item will be etc. To make this analysis simpler we build virtual 23278c2ecf20Sopenharmony_ci * node. Virtual node is an array of items, that will replace items of 23288c2ecf20Sopenharmony_ci * node S. (For instance if we are going to delete an item, virtual 23298c2ecf20Sopenharmony_ci * node does not contain it). Virtual node keeps information about 23308c2ecf20Sopenharmony_ci * item sizes and types, mergeability of first and last items, sizes 23318c2ecf20Sopenharmony_ci * of all entries in directory item. We use this array of items when 23328c2ecf20Sopenharmony_ci * calculating what we can shift to neighbors and how many nodes we 23338c2ecf20Sopenharmony_ci * have to have if we do not any shiftings, if we shift to left/right 23348c2ecf20Sopenharmony_ci * neighbor or to both. 23358c2ecf20Sopenharmony_ci */ 23368c2ecf20Sopenharmony_cistruct virtual_item { 23378c2ecf20Sopenharmony_ci int vi_index; /* index in the array of item operations */ 23388c2ecf20Sopenharmony_ci unsigned short vi_type; /* left/right mergeability */ 23398c2ecf20Sopenharmony_ci 23408c2ecf20Sopenharmony_ci /* length of item that it will have after balancing */ 23418c2ecf20Sopenharmony_ci unsigned short vi_item_len; 23428c2ecf20Sopenharmony_ci 23438c2ecf20Sopenharmony_ci struct item_head *vi_ih; 23448c2ecf20Sopenharmony_ci const char *vi_item; /* body of item (old or new) */ 23458c2ecf20Sopenharmony_ci const void *vi_new_data; /* 0 always but paste mode */ 23468c2ecf20Sopenharmony_ci void *vi_uarea; /* item specific area */ 23478c2ecf20Sopenharmony_ci}; 23488c2ecf20Sopenharmony_ci 23498c2ecf20Sopenharmony_cistruct virtual_node { 23508c2ecf20Sopenharmony_ci /* this is a pointer to the free space in the buffer */ 23518c2ecf20Sopenharmony_ci char *vn_free_ptr; 23528c2ecf20Sopenharmony_ci 23538c2ecf20Sopenharmony_ci unsigned short vn_nr_item; /* number of items in virtual node */ 23548c2ecf20Sopenharmony_ci 23558c2ecf20Sopenharmony_ci /* 23568c2ecf20Sopenharmony_ci * size of node , that node would have if it has 23578c2ecf20Sopenharmony_ci * unlimited size and no balancing is performed 23588c2ecf20Sopenharmony_ci */ 23598c2ecf20Sopenharmony_ci short vn_size; 23608c2ecf20Sopenharmony_ci 23618c2ecf20Sopenharmony_ci /* mode of balancing (paste, insert, delete, cut) */ 23628c2ecf20Sopenharmony_ci short vn_mode; 23638c2ecf20Sopenharmony_ci 23648c2ecf20Sopenharmony_ci short vn_affected_item_num; 23658c2ecf20Sopenharmony_ci short vn_pos_in_item; 23668c2ecf20Sopenharmony_ci 23678c2ecf20Sopenharmony_ci /* item header of inserted item, 0 for other modes */ 23688c2ecf20Sopenharmony_ci struct item_head *vn_ins_ih; 23698c2ecf20Sopenharmony_ci const void *vn_data; 23708c2ecf20Sopenharmony_ci 23718c2ecf20Sopenharmony_ci /* array of items (including a new one, excluding item to be deleted) */ 23728c2ecf20Sopenharmony_ci struct virtual_item *vn_vi; 23738c2ecf20Sopenharmony_ci}; 23748c2ecf20Sopenharmony_ci 23758c2ecf20Sopenharmony_ci/* used by directory items when creating virtual nodes */ 23768c2ecf20Sopenharmony_cistruct direntry_uarea { 23778c2ecf20Sopenharmony_ci int flags; 23788c2ecf20Sopenharmony_ci __u16 entry_count; 23798c2ecf20Sopenharmony_ci __u16 entry_sizes[1]; 23808c2ecf20Sopenharmony_ci} __attribute__ ((__packed__)); 23818c2ecf20Sopenharmony_ci 23828c2ecf20Sopenharmony_ci/*************************************************************************** 23838c2ecf20Sopenharmony_ci * TREE BALANCE * 23848c2ecf20Sopenharmony_ci ***************************************************************************/ 23858c2ecf20Sopenharmony_ci 23868c2ecf20Sopenharmony_ci/* 23878c2ecf20Sopenharmony_ci * This temporary structure is used in tree balance algorithms, and 23888c2ecf20Sopenharmony_ci * constructed as we go to the extent that its various parts are 23898c2ecf20Sopenharmony_ci * needed. It contains arrays of nodes that can potentially be 23908c2ecf20Sopenharmony_ci * involved in the balancing of node S, and parameters that define how 23918c2ecf20Sopenharmony_ci * each of the nodes must be balanced. Note that in these algorithms 23928c2ecf20Sopenharmony_ci * for balancing the worst case is to need to balance the current node 23938c2ecf20Sopenharmony_ci * S and the left and right neighbors and all of their parents plus 23948c2ecf20Sopenharmony_ci * create a new node. We implement S1 balancing for the leaf nodes 23958c2ecf20Sopenharmony_ci * and S0 balancing for the internal nodes (S1 and S0 are defined in 23968c2ecf20Sopenharmony_ci * our papers.) 23978c2ecf20Sopenharmony_ci */ 23988c2ecf20Sopenharmony_ci 23998c2ecf20Sopenharmony_ci/* size of the array of buffers to free at end of do_balance */ 24008c2ecf20Sopenharmony_ci#define MAX_FREE_BLOCK 7 24018c2ecf20Sopenharmony_ci 24028c2ecf20Sopenharmony_ci/* maximum number of FEB blocknrs on a single level */ 24038c2ecf20Sopenharmony_ci#define MAX_AMOUNT_NEEDED 2 24048c2ecf20Sopenharmony_ci 24058c2ecf20Sopenharmony_ci/* someday somebody will prefix every field in this struct with tb_ */ 24068c2ecf20Sopenharmony_cistruct tree_balance { 24078c2ecf20Sopenharmony_ci int tb_mode; 24088c2ecf20Sopenharmony_ci int need_balance_dirty; 24098c2ecf20Sopenharmony_ci struct super_block *tb_sb; 24108c2ecf20Sopenharmony_ci struct reiserfs_transaction_handle *transaction_handle; 24118c2ecf20Sopenharmony_ci struct treepath *tb_path; 24128c2ecf20Sopenharmony_ci 24138c2ecf20Sopenharmony_ci /* array of left neighbors of nodes in the path */ 24148c2ecf20Sopenharmony_ci struct buffer_head *L[MAX_HEIGHT]; 24158c2ecf20Sopenharmony_ci 24168c2ecf20Sopenharmony_ci /* array of right neighbors of nodes in the path */ 24178c2ecf20Sopenharmony_ci struct buffer_head *R[MAX_HEIGHT]; 24188c2ecf20Sopenharmony_ci 24198c2ecf20Sopenharmony_ci /* array of fathers of the left neighbors */ 24208c2ecf20Sopenharmony_ci struct buffer_head *FL[MAX_HEIGHT]; 24218c2ecf20Sopenharmony_ci 24228c2ecf20Sopenharmony_ci /* array of fathers of the right neighbors */ 24238c2ecf20Sopenharmony_ci struct buffer_head *FR[MAX_HEIGHT]; 24248c2ecf20Sopenharmony_ci /* array of common parents of center node and its left neighbor */ 24258c2ecf20Sopenharmony_ci struct buffer_head *CFL[MAX_HEIGHT]; 24268c2ecf20Sopenharmony_ci 24278c2ecf20Sopenharmony_ci /* array of common parents of center node and its right neighbor */ 24288c2ecf20Sopenharmony_ci struct buffer_head *CFR[MAX_HEIGHT]; 24298c2ecf20Sopenharmony_ci 24308c2ecf20Sopenharmony_ci /* 24318c2ecf20Sopenharmony_ci * array of empty buffers. Number of buffers in array equals 24328c2ecf20Sopenharmony_ci * cur_blknum. 24338c2ecf20Sopenharmony_ci */ 24348c2ecf20Sopenharmony_ci struct buffer_head *FEB[MAX_FEB_SIZE]; 24358c2ecf20Sopenharmony_ci struct buffer_head *used[MAX_FEB_SIZE]; 24368c2ecf20Sopenharmony_ci struct buffer_head *thrown[MAX_FEB_SIZE]; 24378c2ecf20Sopenharmony_ci 24388c2ecf20Sopenharmony_ci /* 24398c2ecf20Sopenharmony_ci * array of number of items which must be shifted to the left in 24408c2ecf20Sopenharmony_ci * order to balance the current node; for leaves includes item that 24418c2ecf20Sopenharmony_ci * will be partially shifted; for internal nodes, it is the number 24428c2ecf20Sopenharmony_ci * of child pointers rather than items. It includes the new item 24438c2ecf20Sopenharmony_ci * being created. The code sometimes subtracts one to get the 24448c2ecf20Sopenharmony_ci * number of wholly shifted items for other purposes. 24458c2ecf20Sopenharmony_ci */ 24468c2ecf20Sopenharmony_ci int lnum[MAX_HEIGHT]; 24478c2ecf20Sopenharmony_ci 24488c2ecf20Sopenharmony_ci /* substitute right for left in comment above */ 24498c2ecf20Sopenharmony_ci int rnum[MAX_HEIGHT]; 24508c2ecf20Sopenharmony_ci 24518c2ecf20Sopenharmony_ci /* 24528c2ecf20Sopenharmony_ci * array indexed by height h mapping the key delimiting L[h] and 24538c2ecf20Sopenharmony_ci * S[h] to its item number within the node CFL[h] 24548c2ecf20Sopenharmony_ci */ 24558c2ecf20Sopenharmony_ci int lkey[MAX_HEIGHT]; 24568c2ecf20Sopenharmony_ci 24578c2ecf20Sopenharmony_ci /* substitute r for l in comment above */ 24588c2ecf20Sopenharmony_ci int rkey[MAX_HEIGHT]; 24598c2ecf20Sopenharmony_ci 24608c2ecf20Sopenharmony_ci /* 24618c2ecf20Sopenharmony_ci * the number of bytes by we are trying to add or remove from 24628c2ecf20Sopenharmony_ci * S[h]. A negative value means removing. 24638c2ecf20Sopenharmony_ci */ 24648c2ecf20Sopenharmony_ci int insert_size[MAX_HEIGHT]; 24658c2ecf20Sopenharmony_ci 24668c2ecf20Sopenharmony_ci /* 24678c2ecf20Sopenharmony_ci * number of nodes that will replace node S[h] after balancing 24688c2ecf20Sopenharmony_ci * on the level h of the tree. If 0 then S is being deleted, 24698c2ecf20Sopenharmony_ci * if 1 then S is remaining and no new nodes are being created, 24708c2ecf20Sopenharmony_ci * if 2 or 3 then 1 or 2 new nodes is being created 24718c2ecf20Sopenharmony_ci */ 24728c2ecf20Sopenharmony_ci int blknum[MAX_HEIGHT]; 24738c2ecf20Sopenharmony_ci 24748c2ecf20Sopenharmony_ci /* fields that are used only for balancing leaves of the tree */ 24758c2ecf20Sopenharmony_ci 24768c2ecf20Sopenharmony_ci /* number of empty blocks having been already allocated */ 24778c2ecf20Sopenharmony_ci int cur_blknum; 24788c2ecf20Sopenharmony_ci 24798c2ecf20Sopenharmony_ci /* number of items that fall into left most node when S[0] splits */ 24808c2ecf20Sopenharmony_ci int s0num; 24818c2ecf20Sopenharmony_ci 24828c2ecf20Sopenharmony_ci /* 24838c2ecf20Sopenharmony_ci * number of bytes which can flow to the left neighbor from the left 24848c2ecf20Sopenharmony_ci * most liquid item that cannot be shifted from S[0] entirely 24858c2ecf20Sopenharmony_ci * if -1 then nothing will be partially shifted 24868c2ecf20Sopenharmony_ci */ 24878c2ecf20Sopenharmony_ci int lbytes; 24888c2ecf20Sopenharmony_ci 24898c2ecf20Sopenharmony_ci /* 24908c2ecf20Sopenharmony_ci * number of bytes which will flow to the right neighbor from the right 24918c2ecf20Sopenharmony_ci * most liquid item that cannot be shifted from S[0] entirely 24928c2ecf20Sopenharmony_ci * if -1 then nothing will be partially shifted 24938c2ecf20Sopenharmony_ci */ 24948c2ecf20Sopenharmony_ci int rbytes; 24958c2ecf20Sopenharmony_ci 24968c2ecf20Sopenharmony_ci 24978c2ecf20Sopenharmony_ci /* 24988c2ecf20Sopenharmony_ci * index into the array of item headers in 24998c2ecf20Sopenharmony_ci * S[0] of the affected item 25008c2ecf20Sopenharmony_ci */ 25018c2ecf20Sopenharmony_ci int item_pos; 25028c2ecf20Sopenharmony_ci 25038c2ecf20Sopenharmony_ci /* new nodes allocated to hold what could not fit into S */ 25048c2ecf20Sopenharmony_ci struct buffer_head *S_new[2]; 25058c2ecf20Sopenharmony_ci 25068c2ecf20Sopenharmony_ci /* 25078c2ecf20Sopenharmony_ci * number of items that will be placed into nodes in S_new 25088c2ecf20Sopenharmony_ci * when S[0] splits 25098c2ecf20Sopenharmony_ci */ 25108c2ecf20Sopenharmony_ci int snum[2]; 25118c2ecf20Sopenharmony_ci 25128c2ecf20Sopenharmony_ci /* 25138c2ecf20Sopenharmony_ci * number of bytes which flow to nodes in S_new when S[0] splits 25148c2ecf20Sopenharmony_ci * note: if S[0] splits into 3 nodes, then items do not need to be cut 25158c2ecf20Sopenharmony_ci */ 25168c2ecf20Sopenharmony_ci int sbytes[2]; 25178c2ecf20Sopenharmony_ci 25188c2ecf20Sopenharmony_ci int pos_in_item; 25198c2ecf20Sopenharmony_ci int zeroes_num; 25208c2ecf20Sopenharmony_ci 25218c2ecf20Sopenharmony_ci /* 25228c2ecf20Sopenharmony_ci * buffers which are to be freed after do_balance finishes 25238c2ecf20Sopenharmony_ci * by unfix_nodes 25248c2ecf20Sopenharmony_ci */ 25258c2ecf20Sopenharmony_ci struct buffer_head *buf_to_free[MAX_FREE_BLOCK]; 25268c2ecf20Sopenharmony_ci 25278c2ecf20Sopenharmony_ci /* 25288c2ecf20Sopenharmony_ci * kmalloced memory. Used to create virtual node and keep 25298c2ecf20Sopenharmony_ci * map of dirtied bitmap blocks 25308c2ecf20Sopenharmony_ci */ 25318c2ecf20Sopenharmony_ci char *vn_buf; 25328c2ecf20Sopenharmony_ci 25338c2ecf20Sopenharmony_ci int vn_buf_size; /* size of the vn_buf */ 25348c2ecf20Sopenharmony_ci 25358c2ecf20Sopenharmony_ci /* VN starts after bitmap of bitmap blocks */ 25368c2ecf20Sopenharmony_ci struct virtual_node *tb_vn; 25378c2ecf20Sopenharmony_ci 25388c2ecf20Sopenharmony_ci /* 25398c2ecf20Sopenharmony_ci * saved value of `reiserfs_generation' counter see 25408c2ecf20Sopenharmony_ci * FILESYSTEM_CHANGED() macro in reiserfs_fs.h 25418c2ecf20Sopenharmony_ci */ 25428c2ecf20Sopenharmony_ci int fs_gen; 25438c2ecf20Sopenharmony_ci 25448c2ecf20Sopenharmony_ci#ifdef DISPLACE_NEW_PACKING_LOCALITIES 25458c2ecf20Sopenharmony_ci /* 25468c2ecf20Sopenharmony_ci * key pointer, to pass to block allocator or 25478c2ecf20Sopenharmony_ci * another low-level subsystem 25488c2ecf20Sopenharmony_ci */ 25498c2ecf20Sopenharmony_ci struct in_core_key key; 25508c2ecf20Sopenharmony_ci#endif 25518c2ecf20Sopenharmony_ci}; 25528c2ecf20Sopenharmony_ci 25538c2ecf20Sopenharmony_ci/* These are modes of balancing */ 25548c2ecf20Sopenharmony_ci 25558c2ecf20Sopenharmony_ci/* When inserting an item. */ 25568c2ecf20Sopenharmony_ci#define M_INSERT 'i' 25578c2ecf20Sopenharmony_ci/* 25588c2ecf20Sopenharmony_ci * When inserting into (directories only) or appending onto an already 25598c2ecf20Sopenharmony_ci * existent item. 25608c2ecf20Sopenharmony_ci */ 25618c2ecf20Sopenharmony_ci#define M_PASTE 'p' 25628c2ecf20Sopenharmony_ci/* When deleting an item. */ 25638c2ecf20Sopenharmony_ci#define M_DELETE 'd' 25648c2ecf20Sopenharmony_ci/* When truncating an item or removing an entry from a (directory) item. */ 25658c2ecf20Sopenharmony_ci#define M_CUT 'c' 25668c2ecf20Sopenharmony_ci 25678c2ecf20Sopenharmony_ci/* used when balancing on leaf level skipped (in reiserfsck) */ 25688c2ecf20Sopenharmony_ci#define M_INTERNAL 'n' 25698c2ecf20Sopenharmony_ci 25708c2ecf20Sopenharmony_ci/* 25718c2ecf20Sopenharmony_ci * When further balancing is not needed, then do_balance does not need 25728c2ecf20Sopenharmony_ci * to be called. 25738c2ecf20Sopenharmony_ci */ 25748c2ecf20Sopenharmony_ci#define M_SKIP_BALANCING 's' 25758c2ecf20Sopenharmony_ci#define M_CONVERT 'v' 25768c2ecf20Sopenharmony_ci 25778c2ecf20Sopenharmony_ci/* modes of leaf_move_items */ 25788c2ecf20Sopenharmony_ci#define LEAF_FROM_S_TO_L 0 25798c2ecf20Sopenharmony_ci#define LEAF_FROM_S_TO_R 1 25808c2ecf20Sopenharmony_ci#define LEAF_FROM_R_TO_L 2 25818c2ecf20Sopenharmony_ci#define LEAF_FROM_L_TO_R 3 25828c2ecf20Sopenharmony_ci#define LEAF_FROM_S_TO_SNEW 4 25838c2ecf20Sopenharmony_ci 25848c2ecf20Sopenharmony_ci#define FIRST_TO_LAST 0 25858c2ecf20Sopenharmony_ci#define LAST_TO_FIRST 1 25868c2ecf20Sopenharmony_ci 25878c2ecf20Sopenharmony_ci/* 25888c2ecf20Sopenharmony_ci * used in do_balance for passing parent of node information that has 25898c2ecf20Sopenharmony_ci * been gotten from tb struct 25908c2ecf20Sopenharmony_ci */ 25918c2ecf20Sopenharmony_cistruct buffer_info { 25928c2ecf20Sopenharmony_ci struct tree_balance *tb; 25938c2ecf20Sopenharmony_ci struct buffer_head *bi_bh; 25948c2ecf20Sopenharmony_ci struct buffer_head *bi_parent; 25958c2ecf20Sopenharmony_ci int bi_position; 25968c2ecf20Sopenharmony_ci}; 25978c2ecf20Sopenharmony_ci 25988c2ecf20Sopenharmony_cistatic inline struct super_block *sb_from_tb(struct tree_balance *tb) 25998c2ecf20Sopenharmony_ci{ 26008c2ecf20Sopenharmony_ci return tb ? tb->tb_sb : NULL; 26018c2ecf20Sopenharmony_ci} 26028c2ecf20Sopenharmony_ci 26038c2ecf20Sopenharmony_cistatic inline struct super_block *sb_from_bi(struct buffer_info *bi) 26048c2ecf20Sopenharmony_ci{ 26058c2ecf20Sopenharmony_ci return bi ? sb_from_tb(bi->tb) : NULL; 26068c2ecf20Sopenharmony_ci} 26078c2ecf20Sopenharmony_ci 26088c2ecf20Sopenharmony_ci/* 26098c2ecf20Sopenharmony_ci * there are 4 types of items: stat data, directory item, indirect, direct. 26108c2ecf20Sopenharmony_ci * +-------------------+------------+--------------+------------+ 26118c2ecf20Sopenharmony_ci * | | k_offset | k_uniqueness | mergeable? | 26128c2ecf20Sopenharmony_ci * +-------------------+------------+--------------+------------+ 26138c2ecf20Sopenharmony_ci * | stat data | 0 | 0 | no | 26148c2ecf20Sopenharmony_ci * +-------------------+------------+--------------+------------+ 26158c2ecf20Sopenharmony_ci * | 1st directory item| DOT_OFFSET | DIRENTRY_ .. | no | 26168c2ecf20Sopenharmony_ci * | non 1st directory | hash value | UNIQUENESS | yes | 26178c2ecf20Sopenharmony_ci * | item | | | | 26188c2ecf20Sopenharmony_ci * +-------------------+------------+--------------+------------+ 26198c2ecf20Sopenharmony_ci * | indirect item | offset + 1 |TYPE_INDIRECT | [1] | 26208c2ecf20Sopenharmony_ci * +-------------------+------------+--------------+------------+ 26218c2ecf20Sopenharmony_ci * | direct item | offset + 1 |TYPE_DIRECT | [2] | 26228c2ecf20Sopenharmony_ci * +-------------------+------------+--------------+------------+ 26238c2ecf20Sopenharmony_ci * 26248c2ecf20Sopenharmony_ci * [1] if this is not the first indirect item of the object 26258c2ecf20Sopenharmony_ci * [2] if this is not the first direct item of the object 26268c2ecf20Sopenharmony_ci*/ 26278c2ecf20Sopenharmony_ci 26288c2ecf20Sopenharmony_cistruct item_operations { 26298c2ecf20Sopenharmony_ci int (*bytes_number) (struct item_head * ih, int block_size); 26308c2ecf20Sopenharmony_ci void (*decrement_key) (struct cpu_key *); 26318c2ecf20Sopenharmony_ci int (*is_left_mergeable) (struct reiserfs_key * ih, 26328c2ecf20Sopenharmony_ci unsigned long bsize); 26338c2ecf20Sopenharmony_ci void (*print_item) (struct item_head *, char *item); 26348c2ecf20Sopenharmony_ci void (*check_item) (struct item_head *, char *item); 26358c2ecf20Sopenharmony_ci 26368c2ecf20Sopenharmony_ci int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi, 26378c2ecf20Sopenharmony_ci int is_affected, int insert_size); 26388c2ecf20Sopenharmony_ci int (*check_left) (struct virtual_item * vi, int free, 26398c2ecf20Sopenharmony_ci int start_skip, int end_skip); 26408c2ecf20Sopenharmony_ci int (*check_right) (struct virtual_item * vi, int free); 26418c2ecf20Sopenharmony_ci int (*part_size) (struct virtual_item * vi, int from, int to); 26428c2ecf20Sopenharmony_ci int (*unit_num) (struct virtual_item * vi); 26438c2ecf20Sopenharmony_ci void (*print_vi) (struct virtual_item * vi); 26448c2ecf20Sopenharmony_ci}; 26458c2ecf20Sopenharmony_ci 26468c2ecf20Sopenharmony_ciextern struct item_operations *item_ops[TYPE_ANY + 1]; 26478c2ecf20Sopenharmony_ci 26488c2ecf20Sopenharmony_ci#define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize) 26498c2ecf20Sopenharmony_ci#define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize) 26508c2ecf20Sopenharmony_ci#define op_print_item(ih,item) item_ops[le_ih_k_type (ih)]->print_item (ih, item) 26518c2ecf20Sopenharmony_ci#define op_check_item(ih,item) item_ops[le_ih_k_type (ih)]->check_item (ih, item) 26528c2ecf20Sopenharmony_ci#define op_create_vi(vn,vi,is_affected,insert_size) item_ops[le_ih_k_type ((vi)->vi_ih)]->create_vi (vn,vi,is_affected,insert_size) 26538c2ecf20Sopenharmony_ci#define op_check_left(vi,free,start_skip,end_skip) item_ops[(vi)->vi_index]->check_left (vi, free, start_skip, end_skip) 26548c2ecf20Sopenharmony_ci#define op_check_right(vi,free) item_ops[(vi)->vi_index]->check_right (vi, free) 26558c2ecf20Sopenharmony_ci#define op_part_size(vi,from,to) item_ops[(vi)->vi_index]->part_size (vi, from, to) 26568c2ecf20Sopenharmony_ci#define op_unit_num(vi) item_ops[(vi)->vi_index]->unit_num (vi) 26578c2ecf20Sopenharmony_ci#define op_print_vi(vi) item_ops[(vi)->vi_index]->print_vi (vi) 26588c2ecf20Sopenharmony_ci 26598c2ecf20Sopenharmony_ci#define COMP_SHORT_KEYS comp_short_keys 26608c2ecf20Sopenharmony_ci 26618c2ecf20Sopenharmony_ci/* number of blocks pointed to by the indirect item */ 26628c2ecf20Sopenharmony_ci#define I_UNFM_NUM(ih) (ih_item_len(ih) / UNFM_P_SIZE) 26638c2ecf20Sopenharmony_ci 26648c2ecf20Sopenharmony_ci/* 26658c2ecf20Sopenharmony_ci * the used space within the unformatted node corresponding 26668c2ecf20Sopenharmony_ci * to pos within the item pointed to by ih 26678c2ecf20Sopenharmony_ci */ 26688c2ecf20Sopenharmony_ci#define I_POS_UNFM_SIZE(ih,pos,size) (((pos) == I_UNFM_NUM(ih) - 1 ) ? (size) - ih_free_space(ih) : (size)) 26698c2ecf20Sopenharmony_ci 26708c2ecf20Sopenharmony_ci/* 26718c2ecf20Sopenharmony_ci * number of bytes contained by the direct item or the 26728c2ecf20Sopenharmony_ci * unformatted nodes the indirect item points to 26738c2ecf20Sopenharmony_ci */ 26748c2ecf20Sopenharmony_ci 26758c2ecf20Sopenharmony_ci/* following defines use reiserfs buffer header and item header */ 26768c2ecf20Sopenharmony_ci 26778c2ecf20Sopenharmony_ci/* get stat-data */ 26788c2ecf20Sopenharmony_ci#define B_I_STAT_DATA(bh, ih) ( (struct stat_data * )((bh)->b_data + ih_location(ih)) ) 26798c2ecf20Sopenharmony_ci 26808c2ecf20Sopenharmony_ci/* this is 3976 for size==4096 */ 26818c2ecf20Sopenharmony_ci#define MAX_DIRECT_ITEM_LEN(size) ((size) - BLKH_SIZE - 2*IH_SIZE - SD_SIZE - UNFM_P_SIZE) 26828c2ecf20Sopenharmony_ci 26838c2ecf20Sopenharmony_ci/* 26848c2ecf20Sopenharmony_ci * indirect items consist of entries which contain blocknrs, pos 26858c2ecf20Sopenharmony_ci * indicates which entry, and B_I_POS_UNFM_POINTER resolves to the 26868c2ecf20Sopenharmony_ci * blocknr contained by the entry pos points to 26878c2ecf20Sopenharmony_ci */ 26888c2ecf20Sopenharmony_ci#define B_I_POS_UNFM_POINTER(bh, ih, pos) \ 26898c2ecf20Sopenharmony_ci le32_to_cpu(*(((unp_t *)ih_item_body(bh, ih)) + (pos))) 26908c2ecf20Sopenharmony_ci#define PUT_B_I_POS_UNFM_POINTER(bh, ih, pos, val) \ 26918c2ecf20Sopenharmony_ci (*(((unp_t *)ih_item_body(bh, ih)) + (pos)) = cpu_to_le32(val)) 26928c2ecf20Sopenharmony_ci 26938c2ecf20Sopenharmony_cistruct reiserfs_iget_args { 26948c2ecf20Sopenharmony_ci __u32 objectid; 26958c2ecf20Sopenharmony_ci __u32 dirid; 26968c2ecf20Sopenharmony_ci}; 26978c2ecf20Sopenharmony_ci 26988c2ecf20Sopenharmony_ci/*************************************************************************** 26998c2ecf20Sopenharmony_ci * FUNCTION DECLARATIONS * 27008c2ecf20Sopenharmony_ci ***************************************************************************/ 27018c2ecf20Sopenharmony_ci 27028c2ecf20Sopenharmony_ci#define get_journal_desc_magic(bh) (bh->b_data + bh->b_size - 12) 27038c2ecf20Sopenharmony_ci 27048c2ecf20Sopenharmony_ci#define journal_trans_half(blocksize) \ 27058c2ecf20Sopenharmony_ci ((blocksize - sizeof (struct reiserfs_journal_desc) + sizeof (__u32) - 12) / sizeof (__u32)) 27068c2ecf20Sopenharmony_ci 27078c2ecf20Sopenharmony_ci/* journal.c see journal.c for all the comments here */ 27088c2ecf20Sopenharmony_ci 27098c2ecf20Sopenharmony_ci/* first block written in a commit. */ 27108c2ecf20Sopenharmony_cistruct reiserfs_journal_desc { 27118c2ecf20Sopenharmony_ci __le32 j_trans_id; /* id of commit */ 27128c2ecf20Sopenharmony_ci 27138c2ecf20Sopenharmony_ci /* length of commit. len +1 is the commit block */ 27148c2ecf20Sopenharmony_ci __le32 j_len; 27158c2ecf20Sopenharmony_ci 27168c2ecf20Sopenharmony_ci __le32 j_mount_id; /* mount id of this trans */ 27178c2ecf20Sopenharmony_ci __le32 j_realblock[1]; /* real locations for each block */ 27188c2ecf20Sopenharmony_ci}; 27198c2ecf20Sopenharmony_ci 27208c2ecf20Sopenharmony_ci#define get_desc_trans_id(d) le32_to_cpu((d)->j_trans_id) 27218c2ecf20Sopenharmony_ci#define get_desc_trans_len(d) le32_to_cpu((d)->j_len) 27228c2ecf20Sopenharmony_ci#define get_desc_mount_id(d) le32_to_cpu((d)->j_mount_id) 27238c2ecf20Sopenharmony_ci 27248c2ecf20Sopenharmony_ci#define set_desc_trans_id(d,val) do { (d)->j_trans_id = cpu_to_le32 (val); } while (0) 27258c2ecf20Sopenharmony_ci#define set_desc_trans_len(d,val) do { (d)->j_len = cpu_to_le32 (val); } while (0) 27268c2ecf20Sopenharmony_ci#define set_desc_mount_id(d,val) do { (d)->j_mount_id = cpu_to_le32 (val); } while (0) 27278c2ecf20Sopenharmony_ci 27288c2ecf20Sopenharmony_ci/* last block written in a commit */ 27298c2ecf20Sopenharmony_cistruct reiserfs_journal_commit { 27308c2ecf20Sopenharmony_ci __le32 j_trans_id; /* must match j_trans_id from the desc block */ 27318c2ecf20Sopenharmony_ci __le32 j_len; /* ditto */ 27328c2ecf20Sopenharmony_ci __le32 j_realblock[1]; /* real locations for each block */ 27338c2ecf20Sopenharmony_ci}; 27348c2ecf20Sopenharmony_ci 27358c2ecf20Sopenharmony_ci#define get_commit_trans_id(c) le32_to_cpu((c)->j_trans_id) 27368c2ecf20Sopenharmony_ci#define get_commit_trans_len(c) le32_to_cpu((c)->j_len) 27378c2ecf20Sopenharmony_ci#define get_commit_mount_id(c) le32_to_cpu((c)->j_mount_id) 27388c2ecf20Sopenharmony_ci 27398c2ecf20Sopenharmony_ci#define set_commit_trans_id(c,val) do { (c)->j_trans_id = cpu_to_le32 (val); } while (0) 27408c2ecf20Sopenharmony_ci#define set_commit_trans_len(c,val) do { (c)->j_len = cpu_to_le32 (val); } while (0) 27418c2ecf20Sopenharmony_ci 27428c2ecf20Sopenharmony_ci/* 27438c2ecf20Sopenharmony_ci * this header block gets written whenever a transaction is considered 27448c2ecf20Sopenharmony_ci * fully flushed, and is more recent than the last fully flushed transaction. 27458c2ecf20Sopenharmony_ci * fully flushed means all the log blocks and all the real blocks are on 27468c2ecf20Sopenharmony_ci * disk, and this transaction does not need to be replayed. 27478c2ecf20Sopenharmony_ci */ 27488c2ecf20Sopenharmony_cistruct reiserfs_journal_header { 27498c2ecf20Sopenharmony_ci /* id of last fully flushed transaction */ 27508c2ecf20Sopenharmony_ci __le32 j_last_flush_trans_id; 27518c2ecf20Sopenharmony_ci 27528c2ecf20Sopenharmony_ci /* offset in the log of where to start replay after a crash */ 27538c2ecf20Sopenharmony_ci __le32 j_first_unflushed_offset; 27548c2ecf20Sopenharmony_ci 27558c2ecf20Sopenharmony_ci __le32 j_mount_id; 27568c2ecf20Sopenharmony_ci /* 12 */ struct journal_params jh_journal; 27578c2ecf20Sopenharmony_ci}; 27588c2ecf20Sopenharmony_ci 27598c2ecf20Sopenharmony_ci/* biggest tunable defines are right here */ 27608c2ecf20Sopenharmony_ci#define JOURNAL_BLOCK_COUNT 8192 /* number of blocks in the journal */ 27618c2ecf20Sopenharmony_ci 27628c2ecf20Sopenharmony_ci/* biggest possible single transaction, don't change for now (8/3/99) */ 27638c2ecf20Sopenharmony_ci#define JOURNAL_TRANS_MAX_DEFAULT 1024 27648c2ecf20Sopenharmony_ci#define JOURNAL_TRANS_MIN_DEFAULT 256 27658c2ecf20Sopenharmony_ci 27668c2ecf20Sopenharmony_ci/* 27678c2ecf20Sopenharmony_ci * max blocks to batch into one transaction, 27688c2ecf20Sopenharmony_ci * don't make this any bigger than 900 27698c2ecf20Sopenharmony_ci */ 27708c2ecf20Sopenharmony_ci#define JOURNAL_MAX_BATCH_DEFAULT 900 27718c2ecf20Sopenharmony_ci#define JOURNAL_MIN_RATIO 2 27728c2ecf20Sopenharmony_ci#define JOURNAL_MAX_COMMIT_AGE 30 27738c2ecf20Sopenharmony_ci#define JOURNAL_MAX_TRANS_AGE 30 27748c2ecf20Sopenharmony_ci#define JOURNAL_PER_BALANCE_CNT (3 * (MAX_HEIGHT-2) + 9) 27758c2ecf20Sopenharmony_ci#define JOURNAL_BLOCKS_PER_OBJECT(sb) (JOURNAL_PER_BALANCE_CNT * 3 + \ 27768c2ecf20Sopenharmony_ci 2 * (REISERFS_QUOTA_INIT_BLOCKS(sb) + \ 27778c2ecf20Sopenharmony_ci REISERFS_QUOTA_TRANS_BLOCKS(sb))) 27788c2ecf20Sopenharmony_ci 27798c2ecf20Sopenharmony_ci#ifdef CONFIG_QUOTA 27808c2ecf20Sopenharmony_ci#define REISERFS_QUOTA_OPTS ((1 << REISERFS_USRQUOTA) | (1 << REISERFS_GRPQUOTA)) 27818c2ecf20Sopenharmony_ci/* We need to update data and inode (atime) */ 27828c2ecf20Sopenharmony_ci#define REISERFS_QUOTA_TRANS_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? 2 : 0) 27838c2ecf20Sopenharmony_ci/* 1 balancing, 1 bitmap, 1 data per write + stat data update */ 27848c2ecf20Sopenharmony_ci#define REISERFS_QUOTA_INIT_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? \ 27858c2ecf20Sopenharmony_ci(DQUOT_INIT_ALLOC*(JOURNAL_PER_BALANCE_CNT+2)+DQUOT_INIT_REWRITE+1) : 0) 27868c2ecf20Sopenharmony_ci/* same as with INIT */ 27878c2ecf20Sopenharmony_ci#define REISERFS_QUOTA_DEL_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? \ 27888c2ecf20Sopenharmony_ci(DQUOT_DEL_ALLOC*(JOURNAL_PER_BALANCE_CNT+2)+DQUOT_DEL_REWRITE+1) : 0) 27898c2ecf20Sopenharmony_ci#else 27908c2ecf20Sopenharmony_ci#define REISERFS_QUOTA_TRANS_BLOCKS(s) 0 27918c2ecf20Sopenharmony_ci#define REISERFS_QUOTA_INIT_BLOCKS(s) 0 27928c2ecf20Sopenharmony_ci#define REISERFS_QUOTA_DEL_BLOCKS(s) 0 27938c2ecf20Sopenharmony_ci#endif 27948c2ecf20Sopenharmony_ci 27958c2ecf20Sopenharmony_ci/* 27968c2ecf20Sopenharmony_ci * both of these can be as low as 1, or as high as you want. The min is the 27978c2ecf20Sopenharmony_ci * number of 4k bitmap nodes preallocated on mount. New nodes are allocated 27988c2ecf20Sopenharmony_ci * as needed, and released when transactions are committed. On release, if 27998c2ecf20Sopenharmony_ci * the current number of nodes is > max, the node is freed, otherwise, 28008c2ecf20Sopenharmony_ci * it is put on a free list for faster use later. 28018c2ecf20Sopenharmony_ci*/ 28028c2ecf20Sopenharmony_ci#define REISERFS_MIN_BITMAP_NODES 10 28038c2ecf20Sopenharmony_ci#define REISERFS_MAX_BITMAP_NODES 100 28048c2ecf20Sopenharmony_ci 28058c2ecf20Sopenharmony_ci/* these are based on journal hash size of 8192 */ 28068c2ecf20Sopenharmony_ci#define JBH_HASH_SHIFT 13 28078c2ecf20Sopenharmony_ci#define JBH_HASH_MASK 8191 28088c2ecf20Sopenharmony_ci 28098c2ecf20Sopenharmony_ci#define _jhashfn(sb,block) \ 28108c2ecf20Sopenharmony_ci (((unsigned long)sb>>L1_CACHE_SHIFT) ^ \ 28118c2ecf20Sopenharmony_ci (((block)<<(JBH_HASH_SHIFT - 6)) ^ ((block) >> 13) ^ ((block) << (JBH_HASH_SHIFT - 12)))) 28128c2ecf20Sopenharmony_ci#define journal_hash(t,sb,block) ((t)[_jhashfn((sb),(block)) & JBH_HASH_MASK]) 28138c2ecf20Sopenharmony_ci 28148c2ecf20Sopenharmony_ci/* We need these to make journal.c code more readable */ 28158c2ecf20Sopenharmony_ci#define journal_find_get_block(s, block) __find_get_block(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize) 28168c2ecf20Sopenharmony_ci#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize) 28178c2ecf20Sopenharmony_ci#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize) 28188c2ecf20Sopenharmony_ci 28198c2ecf20Sopenharmony_cienum reiserfs_bh_state_bits { 28208c2ecf20Sopenharmony_ci BH_JDirty = BH_PrivateStart, /* buffer is in current transaction */ 28218c2ecf20Sopenharmony_ci BH_JDirty_wait, 28228c2ecf20Sopenharmony_ci /* 28238c2ecf20Sopenharmony_ci * disk block was taken off free list before being in a 28248c2ecf20Sopenharmony_ci * finished transaction, or written to disk. Can be reused immed. 28258c2ecf20Sopenharmony_ci */ 28268c2ecf20Sopenharmony_ci BH_JNew, 28278c2ecf20Sopenharmony_ci BH_JPrepared, 28288c2ecf20Sopenharmony_ci BH_JRestore_dirty, 28298c2ecf20Sopenharmony_ci BH_JTest, /* debugging only will go away */ 28308c2ecf20Sopenharmony_ci}; 28318c2ecf20Sopenharmony_ci 28328c2ecf20Sopenharmony_ciBUFFER_FNS(JDirty, journaled); 28338c2ecf20Sopenharmony_ciTAS_BUFFER_FNS(JDirty, journaled); 28348c2ecf20Sopenharmony_ciBUFFER_FNS(JDirty_wait, journal_dirty); 28358c2ecf20Sopenharmony_ciTAS_BUFFER_FNS(JDirty_wait, journal_dirty); 28368c2ecf20Sopenharmony_ciBUFFER_FNS(JNew, journal_new); 28378c2ecf20Sopenharmony_ciTAS_BUFFER_FNS(JNew, journal_new); 28388c2ecf20Sopenharmony_ciBUFFER_FNS(JPrepared, journal_prepared); 28398c2ecf20Sopenharmony_ciTAS_BUFFER_FNS(JPrepared, journal_prepared); 28408c2ecf20Sopenharmony_ciBUFFER_FNS(JRestore_dirty, journal_restore_dirty); 28418c2ecf20Sopenharmony_ciTAS_BUFFER_FNS(JRestore_dirty, journal_restore_dirty); 28428c2ecf20Sopenharmony_ciBUFFER_FNS(JTest, journal_test); 28438c2ecf20Sopenharmony_ciTAS_BUFFER_FNS(JTest, journal_test); 28448c2ecf20Sopenharmony_ci 28458c2ecf20Sopenharmony_ci/* transaction handle which is passed around for all journal calls */ 28468c2ecf20Sopenharmony_cistruct reiserfs_transaction_handle { 28478c2ecf20Sopenharmony_ci /* 28488c2ecf20Sopenharmony_ci * super for this FS when journal_begin was called. saves calls to 28498c2ecf20Sopenharmony_ci * reiserfs_get_super also used by nested transactions to make 28508c2ecf20Sopenharmony_ci * sure they are nesting on the right FS _must_ be first 28518c2ecf20Sopenharmony_ci * in the handle 28528c2ecf20Sopenharmony_ci */ 28538c2ecf20Sopenharmony_ci struct super_block *t_super; 28548c2ecf20Sopenharmony_ci 28558c2ecf20Sopenharmony_ci int t_refcount; 28568c2ecf20Sopenharmony_ci int t_blocks_logged; /* number of blocks this writer has logged */ 28578c2ecf20Sopenharmony_ci int t_blocks_allocated; /* number of blocks this writer allocated */ 28588c2ecf20Sopenharmony_ci 28598c2ecf20Sopenharmony_ci /* sanity check, equals the current trans id */ 28608c2ecf20Sopenharmony_ci unsigned int t_trans_id; 28618c2ecf20Sopenharmony_ci 28628c2ecf20Sopenharmony_ci void *t_handle_save; /* save existing current->journal_info */ 28638c2ecf20Sopenharmony_ci 28648c2ecf20Sopenharmony_ci /* 28658c2ecf20Sopenharmony_ci * if new block allocation occurres, that block 28668c2ecf20Sopenharmony_ci * should be displaced from others 28678c2ecf20Sopenharmony_ci */ 28688c2ecf20Sopenharmony_ci unsigned displace_new_blocks:1; 28698c2ecf20Sopenharmony_ci 28708c2ecf20Sopenharmony_ci struct list_head t_list; 28718c2ecf20Sopenharmony_ci}; 28728c2ecf20Sopenharmony_ci 28738c2ecf20Sopenharmony_ci/* 28748c2ecf20Sopenharmony_ci * used to keep track of ordered and tail writes, attached to the buffer 28758c2ecf20Sopenharmony_ci * head through b_journal_head. 28768c2ecf20Sopenharmony_ci */ 28778c2ecf20Sopenharmony_cistruct reiserfs_jh { 28788c2ecf20Sopenharmony_ci struct reiserfs_journal_list *jl; 28798c2ecf20Sopenharmony_ci struct buffer_head *bh; 28808c2ecf20Sopenharmony_ci struct list_head list; 28818c2ecf20Sopenharmony_ci}; 28828c2ecf20Sopenharmony_ci 28838c2ecf20Sopenharmony_civoid reiserfs_free_jh(struct buffer_head *bh); 28848c2ecf20Sopenharmony_ciint reiserfs_add_tail_list(struct inode *inode, struct buffer_head *bh); 28858c2ecf20Sopenharmony_ciint reiserfs_add_ordered_list(struct inode *inode, struct buffer_head *bh); 28868c2ecf20Sopenharmony_ciint journal_mark_dirty(struct reiserfs_transaction_handle *, 28878c2ecf20Sopenharmony_ci struct buffer_head *bh); 28888c2ecf20Sopenharmony_ci 28898c2ecf20Sopenharmony_cistatic inline int reiserfs_file_data_log(struct inode *inode) 28908c2ecf20Sopenharmony_ci{ 28918c2ecf20Sopenharmony_ci if (reiserfs_data_log(inode->i_sb) || 28928c2ecf20Sopenharmony_ci (REISERFS_I(inode)->i_flags & i_data_log)) 28938c2ecf20Sopenharmony_ci return 1; 28948c2ecf20Sopenharmony_ci return 0; 28958c2ecf20Sopenharmony_ci} 28968c2ecf20Sopenharmony_ci 28978c2ecf20Sopenharmony_cistatic inline int reiserfs_transaction_running(struct super_block *s) 28988c2ecf20Sopenharmony_ci{ 28998c2ecf20Sopenharmony_ci struct reiserfs_transaction_handle *th = current->journal_info; 29008c2ecf20Sopenharmony_ci if (th && th->t_super == s) 29018c2ecf20Sopenharmony_ci return 1; 29028c2ecf20Sopenharmony_ci if (th && th->t_super == NULL) 29038c2ecf20Sopenharmony_ci BUG(); 29048c2ecf20Sopenharmony_ci return 0; 29058c2ecf20Sopenharmony_ci} 29068c2ecf20Sopenharmony_ci 29078c2ecf20Sopenharmony_cistatic inline int reiserfs_transaction_free_space(struct reiserfs_transaction_handle *th) 29088c2ecf20Sopenharmony_ci{ 29098c2ecf20Sopenharmony_ci return th->t_blocks_allocated - th->t_blocks_logged; 29108c2ecf20Sopenharmony_ci} 29118c2ecf20Sopenharmony_ci 29128c2ecf20Sopenharmony_cistruct reiserfs_transaction_handle *reiserfs_persistent_transaction(struct 29138c2ecf20Sopenharmony_ci super_block 29148c2ecf20Sopenharmony_ci *, 29158c2ecf20Sopenharmony_ci int count); 29168c2ecf20Sopenharmony_ciint reiserfs_end_persistent_transaction(struct reiserfs_transaction_handle *); 29178c2ecf20Sopenharmony_civoid reiserfs_vfs_truncate_file(struct inode *inode); 29188c2ecf20Sopenharmony_ciint reiserfs_commit_page(struct inode *inode, struct page *page, 29198c2ecf20Sopenharmony_ci unsigned from, unsigned to); 29208c2ecf20Sopenharmony_civoid reiserfs_flush_old_commits(struct super_block *); 29218c2ecf20Sopenharmony_ciint reiserfs_commit_for_inode(struct inode *); 29228c2ecf20Sopenharmony_ciint reiserfs_inode_needs_commit(struct inode *); 29238c2ecf20Sopenharmony_civoid reiserfs_update_inode_transaction(struct inode *); 29248c2ecf20Sopenharmony_civoid reiserfs_wait_on_write_block(struct super_block *s); 29258c2ecf20Sopenharmony_civoid reiserfs_block_writes(struct reiserfs_transaction_handle *th); 29268c2ecf20Sopenharmony_civoid reiserfs_allow_writes(struct super_block *s); 29278c2ecf20Sopenharmony_civoid reiserfs_check_lock_depth(struct super_block *s, char *caller); 29288c2ecf20Sopenharmony_ciint reiserfs_prepare_for_journal(struct super_block *, struct buffer_head *bh, 29298c2ecf20Sopenharmony_ci int wait); 29308c2ecf20Sopenharmony_civoid reiserfs_restore_prepared_buffer(struct super_block *, 29318c2ecf20Sopenharmony_ci struct buffer_head *bh); 29328c2ecf20Sopenharmony_ciint journal_init(struct super_block *, const char *j_dev_name, int old_format, 29338c2ecf20Sopenharmony_ci unsigned int); 29348c2ecf20Sopenharmony_ciint journal_release(struct reiserfs_transaction_handle *, struct super_block *); 29358c2ecf20Sopenharmony_ciint journal_release_error(struct reiserfs_transaction_handle *, 29368c2ecf20Sopenharmony_ci struct super_block *); 29378c2ecf20Sopenharmony_ciint journal_end(struct reiserfs_transaction_handle *); 29388c2ecf20Sopenharmony_ciint journal_end_sync(struct reiserfs_transaction_handle *); 29398c2ecf20Sopenharmony_ciint journal_mark_freed(struct reiserfs_transaction_handle *, 29408c2ecf20Sopenharmony_ci struct super_block *, b_blocknr_t blocknr); 29418c2ecf20Sopenharmony_ciint journal_transaction_should_end(struct reiserfs_transaction_handle *, int); 29428c2ecf20Sopenharmony_ciint reiserfs_in_journal(struct super_block *sb, unsigned int bmap_nr, 29438c2ecf20Sopenharmony_ci int bit_nr, int searchall, b_blocknr_t *next); 29448c2ecf20Sopenharmony_ciint journal_begin(struct reiserfs_transaction_handle *, 29458c2ecf20Sopenharmony_ci struct super_block *sb, unsigned long); 29468c2ecf20Sopenharmony_ciint journal_join_abort(struct reiserfs_transaction_handle *, 29478c2ecf20Sopenharmony_ci struct super_block *sb); 29488c2ecf20Sopenharmony_civoid reiserfs_abort_journal(struct super_block *sb, int errno); 29498c2ecf20Sopenharmony_civoid reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...); 29508c2ecf20Sopenharmony_ciint reiserfs_allocate_list_bitmaps(struct super_block *s, 29518c2ecf20Sopenharmony_ci struct reiserfs_list_bitmap *, unsigned int); 29528c2ecf20Sopenharmony_ci 29538c2ecf20Sopenharmony_civoid reiserfs_schedule_old_flush(struct super_block *s); 29548c2ecf20Sopenharmony_civoid reiserfs_cancel_old_flush(struct super_block *s); 29558c2ecf20Sopenharmony_civoid add_save_link(struct reiserfs_transaction_handle *th, 29568c2ecf20Sopenharmony_ci struct inode *inode, int truncate); 29578c2ecf20Sopenharmony_ciint remove_save_link(struct inode *inode, int truncate); 29588c2ecf20Sopenharmony_ci 29598c2ecf20Sopenharmony_ci/* objectid.c */ 29608c2ecf20Sopenharmony_ci__u32 reiserfs_get_unused_objectid(struct reiserfs_transaction_handle *th); 29618c2ecf20Sopenharmony_civoid reiserfs_release_objectid(struct reiserfs_transaction_handle *th, 29628c2ecf20Sopenharmony_ci __u32 objectid_to_release); 29638c2ecf20Sopenharmony_ciint reiserfs_convert_objectid_map_v1(struct super_block *); 29648c2ecf20Sopenharmony_ci 29658c2ecf20Sopenharmony_ci/* stree.c */ 29668c2ecf20Sopenharmony_ciint B_IS_IN_TREE(const struct buffer_head *); 29678c2ecf20Sopenharmony_ciextern void copy_item_head(struct item_head *to, 29688c2ecf20Sopenharmony_ci const struct item_head *from); 29698c2ecf20Sopenharmony_ci 29708c2ecf20Sopenharmony_ci/* first key is in cpu form, second - le */ 29718c2ecf20Sopenharmony_ciextern int comp_short_keys(const struct reiserfs_key *le_key, 29728c2ecf20Sopenharmony_ci const struct cpu_key *cpu_key); 29738c2ecf20Sopenharmony_ciextern void le_key2cpu_key(struct cpu_key *to, const struct reiserfs_key *from); 29748c2ecf20Sopenharmony_ci 29758c2ecf20Sopenharmony_ci/* both are in le form */ 29768c2ecf20Sopenharmony_ciextern int comp_le_keys(const struct reiserfs_key *, 29778c2ecf20Sopenharmony_ci const struct reiserfs_key *); 29788c2ecf20Sopenharmony_ciextern int comp_short_le_keys(const struct reiserfs_key *, 29798c2ecf20Sopenharmony_ci const struct reiserfs_key *); 29808c2ecf20Sopenharmony_ci 29818c2ecf20Sopenharmony_ci/* * get key version from on disk key - kludge */ 29828c2ecf20Sopenharmony_cistatic inline int le_key_version(const struct reiserfs_key *key) 29838c2ecf20Sopenharmony_ci{ 29848c2ecf20Sopenharmony_ci int type; 29858c2ecf20Sopenharmony_ci 29868c2ecf20Sopenharmony_ci type = offset_v2_k_type(&(key->u.k_offset_v2)); 29878c2ecf20Sopenharmony_ci if (type != TYPE_DIRECT && type != TYPE_INDIRECT 29888c2ecf20Sopenharmony_ci && type != TYPE_DIRENTRY) 29898c2ecf20Sopenharmony_ci return KEY_FORMAT_3_5; 29908c2ecf20Sopenharmony_ci 29918c2ecf20Sopenharmony_ci return KEY_FORMAT_3_6; 29928c2ecf20Sopenharmony_ci 29938c2ecf20Sopenharmony_ci} 29948c2ecf20Sopenharmony_ci 29958c2ecf20Sopenharmony_cistatic inline void copy_key(struct reiserfs_key *to, 29968c2ecf20Sopenharmony_ci const struct reiserfs_key *from) 29978c2ecf20Sopenharmony_ci{ 29988c2ecf20Sopenharmony_ci memcpy(to, from, KEY_SIZE); 29998c2ecf20Sopenharmony_ci} 30008c2ecf20Sopenharmony_ci 30018c2ecf20Sopenharmony_ciint comp_items(const struct item_head *stored_ih, const struct treepath *path); 30028c2ecf20Sopenharmony_ciconst struct reiserfs_key *get_rkey(const struct treepath *chk_path, 30038c2ecf20Sopenharmony_ci const struct super_block *sb); 30048c2ecf20Sopenharmony_ciint search_by_key(struct super_block *, const struct cpu_key *, 30058c2ecf20Sopenharmony_ci struct treepath *, int); 30068c2ecf20Sopenharmony_ci#define search_item(s,key,path) search_by_key (s, key, path, DISK_LEAF_NODE_LEVEL) 30078c2ecf20Sopenharmony_ciint search_for_position_by_key(struct super_block *sb, 30088c2ecf20Sopenharmony_ci const struct cpu_key *cpu_key, 30098c2ecf20Sopenharmony_ci struct treepath *search_path); 30108c2ecf20Sopenharmony_ciextern void decrement_bcount(struct buffer_head *bh); 30118c2ecf20Sopenharmony_civoid decrement_counters_in_path(struct treepath *search_path); 30128c2ecf20Sopenharmony_civoid pathrelse(struct treepath *search_path); 30138c2ecf20Sopenharmony_ciint reiserfs_check_path(struct treepath *p); 30148c2ecf20Sopenharmony_civoid pathrelse_and_restore(struct super_block *s, struct treepath *search_path); 30158c2ecf20Sopenharmony_ci 30168c2ecf20Sopenharmony_ciint reiserfs_insert_item(struct reiserfs_transaction_handle *th, 30178c2ecf20Sopenharmony_ci struct treepath *path, 30188c2ecf20Sopenharmony_ci const struct cpu_key *key, 30198c2ecf20Sopenharmony_ci struct item_head *ih, 30208c2ecf20Sopenharmony_ci struct inode *inode, const char *body); 30218c2ecf20Sopenharmony_ci 30228c2ecf20Sopenharmony_ciint reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, 30238c2ecf20Sopenharmony_ci struct treepath *path, 30248c2ecf20Sopenharmony_ci const struct cpu_key *key, 30258c2ecf20Sopenharmony_ci struct inode *inode, 30268c2ecf20Sopenharmony_ci const char *body, int paste_size); 30278c2ecf20Sopenharmony_ci 30288c2ecf20Sopenharmony_ciint reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, 30298c2ecf20Sopenharmony_ci struct treepath *path, 30308c2ecf20Sopenharmony_ci struct cpu_key *key, 30318c2ecf20Sopenharmony_ci struct inode *inode, 30328c2ecf20Sopenharmony_ci struct page *page, loff_t new_file_size); 30338c2ecf20Sopenharmony_ci 30348c2ecf20Sopenharmony_ciint reiserfs_delete_item(struct reiserfs_transaction_handle *th, 30358c2ecf20Sopenharmony_ci struct treepath *path, 30368c2ecf20Sopenharmony_ci const struct cpu_key *key, 30378c2ecf20Sopenharmony_ci struct inode *inode, struct buffer_head *un_bh); 30388c2ecf20Sopenharmony_ci 30398c2ecf20Sopenharmony_civoid reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th, 30408c2ecf20Sopenharmony_ci struct inode *inode, struct reiserfs_key *key); 30418c2ecf20Sopenharmony_ciint reiserfs_delete_object(struct reiserfs_transaction_handle *th, 30428c2ecf20Sopenharmony_ci struct inode *inode); 30438c2ecf20Sopenharmony_ciint reiserfs_do_truncate(struct reiserfs_transaction_handle *th, 30448c2ecf20Sopenharmony_ci struct inode *inode, struct page *, 30458c2ecf20Sopenharmony_ci int update_timestamps); 30468c2ecf20Sopenharmony_ci 30478c2ecf20Sopenharmony_ci#define i_block_size(inode) ((inode)->i_sb->s_blocksize) 30488c2ecf20Sopenharmony_ci#define file_size(inode) ((inode)->i_size) 30498c2ecf20Sopenharmony_ci#define tail_size(inode) (file_size (inode) & (i_block_size (inode) - 1)) 30508c2ecf20Sopenharmony_ci 30518c2ecf20Sopenharmony_ci#define tail_has_to_be_packed(inode) (have_large_tails ((inode)->i_sb)?\ 30528c2ecf20Sopenharmony_ci!STORE_TAIL_IN_UNFM_S1(file_size (inode), tail_size(inode), inode->i_sb->s_blocksize):have_small_tails ((inode)->i_sb)?!STORE_TAIL_IN_UNFM_S2(file_size (inode), tail_size(inode), inode->i_sb->s_blocksize):0 ) 30538c2ecf20Sopenharmony_ci 30548c2ecf20Sopenharmony_civoid padd_item(char *item, int total_length, int length); 30558c2ecf20Sopenharmony_ci 30568c2ecf20Sopenharmony_ci/* inode.c */ 30578c2ecf20Sopenharmony_ci/* args for the create parameter of reiserfs_get_block */ 30588c2ecf20Sopenharmony_ci#define GET_BLOCK_NO_CREATE 0 /* don't create new blocks or convert tails */ 30598c2ecf20Sopenharmony_ci#define GET_BLOCK_CREATE 1 /* add anything you need to find block */ 30608c2ecf20Sopenharmony_ci#define GET_BLOCK_NO_HOLE 2 /* return -ENOENT for file holes */ 30618c2ecf20Sopenharmony_ci#define GET_BLOCK_READ_DIRECT 4 /* read the tail if indirect item not found */ 30628c2ecf20Sopenharmony_ci#define GET_BLOCK_NO_IMUX 8 /* i_mutex is not held, don't preallocate */ 30638c2ecf20Sopenharmony_ci#define GET_BLOCK_NO_DANGLE 16 /* don't leave any transactions running */ 30648c2ecf20Sopenharmony_ci 30658c2ecf20Sopenharmony_civoid reiserfs_read_locked_inode(struct inode *inode, 30668c2ecf20Sopenharmony_ci struct reiserfs_iget_args *args); 30678c2ecf20Sopenharmony_ciint reiserfs_find_actor(struct inode *inode, void *p); 30688c2ecf20Sopenharmony_ciint reiserfs_init_locked_inode(struct inode *inode, void *p); 30698c2ecf20Sopenharmony_civoid reiserfs_evict_inode(struct inode *inode); 30708c2ecf20Sopenharmony_ciint reiserfs_write_inode(struct inode *inode, struct writeback_control *wbc); 30718c2ecf20Sopenharmony_ciint reiserfs_get_block(struct inode *inode, sector_t block, 30728c2ecf20Sopenharmony_ci struct buffer_head *bh_result, int create); 30738c2ecf20Sopenharmony_cistruct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid, 30748c2ecf20Sopenharmony_ci int fh_len, int fh_type); 30758c2ecf20Sopenharmony_cistruct dentry *reiserfs_fh_to_parent(struct super_block *sb, struct fid *fid, 30768c2ecf20Sopenharmony_ci int fh_len, int fh_type); 30778c2ecf20Sopenharmony_ciint reiserfs_encode_fh(struct inode *inode, __u32 * data, int *lenp, 30788c2ecf20Sopenharmony_ci struct inode *parent); 30798c2ecf20Sopenharmony_ci 30808c2ecf20Sopenharmony_ciint reiserfs_truncate_file(struct inode *, int update_timestamps); 30818c2ecf20Sopenharmony_civoid make_cpu_key(struct cpu_key *cpu_key, struct inode *inode, loff_t offset, 30828c2ecf20Sopenharmony_ci int type, int key_length); 30838c2ecf20Sopenharmony_civoid make_le_item_head(struct item_head *ih, const struct cpu_key *key, 30848c2ecf20Sopenharmony_ci int version, 30858c2ecf20Sopenharmony_ci loff_t offset, int type, int length, int entry_count); 30868c2ecf20Sopenharmony_cistruct inode *reiserfs_iget(struct super_block *s, const struct cpu_key *key); 30878c2ecf20Sopenharmony_ci 30888c2ecf20Sopenharmony_cistruct reiserfs_security_handle; 30898c2ecf20Sopenharmony_ciint reiserfs_new_inode(struct reiserfs_transaction_handle *th, 30908c2ecf20Sopenharmony_ci struct inode *dir, umode_t mode, 30918c2ecf20Sopenharmony_ci const char *symname, loff_t i_size, 30928c2ecf20Sopenharmony_ci struct dentry *dentry, struct inode *inode, 30938c2ecf20Sopenharmony_ci struct reiserfs_security_handle *security); 30948c2ecf20Sopenharmony_ci 30958c2ecf20Sopenharmony_civoid reiserfs_update_sd_size(struct reiserfs_transaction_handle *th, 30968c2ecf20Sopenharmony_ci struct inode *inode, loff_t size); 30978c2ecf20Sopenharmony_ci 30988c2ecf20Sopenharmony_cistatic inline void reiserfs_update_sd(struct reiserfs_transaction_handle *th, 30998c2ecf20Sopenharmony_ci struct inode *inode) 31008c2ecf20Sopenharmony_ci{ 31018c2ecf20Sopenharmony_ci reiserfs_update_sd_size(th, inode, inode->i_size); 31028c2ecf20Sopenharmony_ci} 31038c2ecf20Sopenharmony_ci 31048c2ecf20Sopenharmony_civoid sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode); 31058c2ecf20Sopenharmony_ciint reiserfs_setattr(struct dentry *dentry, struct iattr *attr); 31068c2ecf20Sopenharmony_ci 31078c2ecf20Sopenharmony_ciint __reiserfs_write_begin(struct page *page, unsigned from, unsigned len); 31088c2ecf20Sopenharmony_ci 31098c2ecf20Sopenharmony_ci/* namei.c */ 31108c2ecf20Sopenharmony_civoid set_de_name_and_namelen(struct reiserfs_dir_entry *de); 31118c2ecf20Sopenharmony_ciint search_by_entry_key(struct super_block *sb, const struct cpu_key *key, 31128c2ecf20Sopenharmony_ci struct treepath *path, struct reiserfs_dir_entry *de); 31138c2ecf20Sopenharmony_cistruct dentry *reiserfs_get_parent(struct dentry *); 31148c2ecf20Sopenharmony_ci 31158c2ecf20Sopenharmony_ci#ifdef CONFIG_REISERFS_PROC_INFO 31168c2ecf20Sopenharmony_ciint reiserfs_proc_info_init(struct super_block *sb); 31178c2ecf20Sopenharmony_ciint reiserfs_proc_info_done(struct super_block *sb); 31188c2ecf20Sopenharmony_ciint reiserfs_proc_info_global_init(void); 31198c2ecf20Sopenharmony_ciint reiserfs_proc_info_global_done(void); 31208c2ecf20Sopenharmony_ci 31218c2ecf20Sopenharmony_ci#define PROC_EXP( e ) e 31228c2ecf20Sopenharmony_ci 31238c2ecf20Sopenharmony_ci#define __PINFO( sb ) REISERFS_SB(sb) -> s_proc_info_data 31248c2ecf20Sopenharmony_ci#define PROC_INFO_MAX( sb, field, value ) \ 31258c2ecf20Sopenharmony_ci __PINFO( sb ).field = \ 31268c2ecf20Sopenharmony_ci max( REISERFS_SB( sb ) -> s_proc_info_data.field, value ) 31278c2ecf20Sopenharmony_ci#define PROC_INFO_INC( sb, field ) ( ++ ( __PINFO( sb ).field ) ) 31288c2ecf20Sopenharmony_ci#define PROC_INFO_ADD( sb, field, val ) ( __PINFO( sb ).field += ( val ) ) 31298c2ecf20Sopenharmony_ci#define PROC_INFO_BH_STAT( sb, bh, level ) \ 31308c2ecf20Sopenharmony_ci PROC_INFO_INC( sb, sbk_read_at[ ( level ) ] ); \ 31318c2ecf20Sopenharmony_ci PROC_INFO_ADD( sb, free_at[ ( level ) ], B_FREE_SPACE( bh ) ); \ 31328c2ecf20Sopenharmony_ci PROC_INFO_ADD( sb, items_at[ ( level ) ], B_NR_ITEMS( bh ) ) 31338c2ecf20Sopenharmony_ci#else 31348c2ecf20Sopenharmony_cistatic inline int reiserfs_proc_info_init(struct super_block *sb) 31358c2ecf20Sopenharmony_ci{ 31368c2ecf20Sopenharmony_ci return 0; 31378c2ecf20Sopenharmony_ci} 31388c2ecf20Sopenharmony_ci 31398c2ecf20Sopenharmony_cistatic inline int reiserfs_proc_info_done(struct super_block *sb) 31408c2ecf20Sopenharmony_ci{ 31418c2ecf20Sopenharmony_ci return 0; 31428c2ecf20Sopenharmony_ci} 31438c2ecf20Sopenharmony_ci 31448c2ecf20Sopenharmony_cistatic inline int reiserfs_proc_info_global_init(void) 31458c2ecf20Sopenharmony_ci{ 31468c2ecf20Sopenharmony_ci return 0; 31478c2ecf20Sopenharmony_ci} 31488c2ecf20Sopenharmony_ci 31498c2ecf20Sopenharmony_cistatic inline int reiserfs_proc_info_global_done(void) 31508c2ecf20Sopenharmony_ci{ 31518c2ecf20Sopenharmony_ci return 0; 31528c2ecf20Sopenharmony_ci} 31538c2ecf20Sopenharmony_ci 31548c2ecf20Sopenharmony_ci#define PROC_EXP( e ) 31558c2ecf20Sopenharmony_ci#define VOID_V ( ( void ) 0 ) 31568c2ecf20Sopenharmony_ci#define PROC_INFO_MAX( sb, field, value ) VOID_V 31578c2ecf20Sopenharmony_ci#define PROC_INFO_INC( sb, field ) VOID_V 31588c2ecf20Sopenharmony_ci#define PROC_INFO_ADD( sb, field, val ) VOID_V 31598c2ecf20Sopenharmony_ci#define PROC_INFO_BH_STAT(sb, bh, n_node_level) VOID_V 31608c2ecf20Sopenharmony_ci#endif 31618c2ecf20Sopenharmony_ci 31628c2ecf20Sopenharmony_ci/* dir.c */ 31638c2ecf20Sopenharmony_ciextern const struct inode_operations reiserfs_dir_inode_operations; 31648c2ecf20Sopenharmony_ciextern const struct inode_operations reiserfs_symlink_inode_operations; 31658c2ecf20Sopenharmony_ciextern const struct inode_operations reiserfs_special_inode_operations; 31668c2ecf20Sopenharmony_ciextern const struct file_operations reiserfs_dir_operations; 31678c2ecf20Sopenharmony_ciint reiserfs_readdir_inode(struct inode *, struct dir_context *); 31688c2ecf20Sopenharmony_ci 31698c2ecf20Sopenharmony_ci/* tail_conversion.c */ 31708c2ecf20Sopenharmony_ciint direct2indirect(struct reiserfs_transaction_handle *, struct inode *, 31718c2ecf20Sopenharmony_ci struct treepath *, struct buffer_head *, loff_t); 31728c2ecf20Sopenharmony_ciint indirect2direct(struct reiserfs_transaction_handle *, struct inode *, 31738c2ecf20Sopenharmony_ci struct page *, struct treepath *, const struct cpu_key *, 31748c2ecf20Sopenharmony_ci loff_t, char *); 31758c2ecf20Sopenharmony_civoid reiserfs_unmap_buffer(struct buffer_head *); 31768c2ecf20Sopenharmony_ci 31778c2ecf20Sopenharmony_ci/* file.c */ 31788c2ecf20Sopenharmony_ciextern const struct inode_operations reiserfs_file_inode_operations; 31798c2ecf20Sopenharmony_ciextern const struct file_operations reiserfs_file_operations; 31808c2ecf20Sopenharmony_ciextern const struct address_space_operations reiserfs_address_space_operations; 31818c2ecf20Sopenharmony_ci 31828c2ecf20Sopenharmony_ci/* fix_nodes.c */ 31838c2ecf20Sopenharmony_ci 31848c2ecf20Sopenharmony_ciint fix_nodes(int n_op_mode, struct tree_balance *tb, 31858c2ecf20Sopenharmony_ci struct item_head *ins_ih, const void *); 31868c2ecf20Sopenharmony_civoid unfix_nodes(struct tree_balance *); 31878c2ecf20Sopenharmony_ci 31888c2ecf20Sopenharmony_ci/* prints.c */ 31898c2ecf20Sopenharmony_civoid __reiserfs_panic(struct super_block *s, const char *id, 31908c2ecf20Sopenharmony_ci const char *function, const char *fmt, ...) 31918c2ecf20Sopenharmony_ci __attribute__ ((noreturn)); 31928c2ecf20Sopenharmony_ci#define reiserfs_panic(s, id, fmt, args...) \ 31938c2ecf20Sopenharmony_ci __reiserfs_panic(s, id, __func__, fmt, ##args) 31948c2ecf20Sopenharmony_civoid __reiserfs_error(struct super_block *s, const char *id, 31958c2ecf20Sopenharmony_ci const char *function, const char *fmt, ...); 31968c2ecf20Sopenharmony_ci#define reiserfs_error(s, id, fmt, args...) \ 31978c2ecf20Sopenharmony_ci __reiserfs_error(s, id, __func__, fmt, ##args) 31988c2ecf20Sopenharmony_civoid reiserfs_info(struct super_block *s, const char *fmt, ...); 31998c2ecf20Sopenharmony_civoid reiserfs_debug(struct super_block *s, int level, const char *fmt, ...); 32008c2ecf20Sopenharmony_civoid print_indirect_item(struct buffer_head *bh, int item_num); 32018c2ecf20Sopenharmony_civoid store_print_tb(struct tree_balance *tb); 32028c2ecf20Sopenharmony_civoid print_cur_tb(char *mes); 32038c2ecf20Sopenharmony_civoid print_de(struct reiserfs_dir_entry *de); 32048c2ecf20Sopenharmony_civoid print_bi(struct buffer_info *bi, char *mes); 32058c2ecf20Sopenharmony_ci#define PRINT_LEAF_ITEMS 1 /* print all items */ 32068c2ecf20Sopenharmony_ci#define PRINT_DIRECTORY_ITEMS 2 /* print directory items */ 32078c2ecf20Sopenharmony_ci#define PRINT_DIRECT_ITEMS 4 /* print contents of direct items */ 32088c2ecf20Sopenharmony_civoid print_block(struct buffer_head *bh, ...); 32098c2ecf20Sopenharmony_civoid print_bmap(struct super_block *s, int silent); 32108c2ecf20Sopenharmony_civoid print_bmap_block(int i, char *data, int size, int silent); 32118c2ecf20Sopenharmony_ci/*void print_super_block (struct super_block * s, char * mes);*/ 32128c2ecf20Sopenharmony_civoid print_objectid_map(struct super_block *s); 32138c2ecf20Sopenharmony_civoid print_block_head(struct buffer_head *bh, char *mes); 32148c2ecf20Sopenharmony_civoid check_leaf(struct buffer_head *bh); 32158c2ecf20Sopenharmony_civoid check_internal(struct buffer_head *bh); 32168c2ecf20Sopenharmony_civoid print_statistics(struct super_block *s); 32178c2ecf20Sopenharmony_cichar *reiserfs_hashname(int code); 32188c2ecf20Sopenharmony_ci 32198c2ecf20Sopenharmony_ci/* lbalance.c */ 32208c2ecf20Sopenharmony_ciint leaf_move_items(int shift_mode, struct tree_balance *tb, int mov_num, 32218c2ecf20Sopenharmony_ci int mov_bytes, struct buffer_head *Snew); 32228c2ecf20Sopenharmony_ciint leaf_shift_left(struct tree_balance *tb, int shift_num, int shift_bytes); 32238c2ecf20Sopenharmony_ciint leaf_shift_right(struct tree_balance *tb, int shift_num, int shift_bytes); 32248c2ecf20Sopenharmony_civoid leaf_delete_items(struct buffer_info *cur_bi, int last_first, int first, 32258c2ecf20Sopenharmony_ci int del_num, int del_bytes); 32268c2ecf20Sopenharmony_civoid leaf_insert_into_buf(struct buffer_info *bi, int before, 32278c2ecf20Sopenharmony_ci struct item_head * const inserted_item_ih, 32288c2ecf20Sopenharmony_ci const char * const inserted_item_body, 32298c2ecf20Sopenharmony_ci int zeros_number); 32308c2ecf20Sopenharmony_civoid leaf_paste_in_buffer(struct buffer_info *bi, int pasted_item_num, 32318c2ecf20Sopenharmony_ci int pos_in_item, int paste_size, 32328c2ecf20Sopenharmony_ci const char * const body, int zeros_number); 32338c2ecf20Sopenharmony_civoid leaf_cut_from_buffer(struct buffer_info *bi, int cut_item_num, 32348c2ecf20Sopenharmony_ci int pos_in_item, int cut_size); 32358c2ecf20Sopenharmony_civoid leaf_paste_entries(struct buffer_info *bi, int item_num, int before, 32368c2ecf20Sopenharmony_ci int new_entry_count, struct reiserfs_de_head *new_dehs, 32378c2ecf20Sopenharmony_ci const char *records, int paste_size); 32388c2ecf20Sopenharmony_ci/* ibalance.c */ 32398c2ecf20Sopenharmony_ciint balance_internal(struct tree_balance *, int, int, struct item_head *, 32408c2ecf20Sopenharmony_ci struct buffer_head **); 32418c2ecf20Sopenharmony_ci 32428c2ecf20Sopenharmony_ci/* do_balance.c */ 32438c2ecf20Sopenharmony_civoid do_balance_mark_leaf_dirty(struct tree_balance *tb, 32448c2ecf20Sopenharmony_ci struct buffer_head *bh, int flag); 32458c2ecf20Sopenharmony_ci#define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty 32468c2ecf20Sopenharmony_ci#define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty 32478c2ecf20Sopenharmony_ci 32488c2ecf20Sopenharmony_civoid do_balance(struct tree_balance *tb, struct item_head *ih, 32498c2ecf20Sopenharmony_ci const char *body, int flag); 32508c2ecf20Sopenharmony_civoid reiserfs_invalidate_buffer(struct tree_balance *tb, 32518c2ecf20Sopenharmony_ci struct buffer_head *bh); 32528c2ecf20Sopenharmony_ci 32538c2ecf20Sopenharmony_ciint get_left_neighbor_position(struct tree_balance *tb, int h); 32548c2ecf20Sopenharmony_ciint get_right_neighbor_position(struct tree_balance *tb, int h); 32558c2ecf20Sopenharmony_civoid replace_key(struct tree_balance *tb, struct buffer_head *, int, 32568c2ecf20Sopenharmony_ci struct buffer_head *, int); 32578c2ecf20Sopenharmony_civoid make_empty_node(struct buffer_info *); 32588c2ecf20Sopenharmony_cistruct buffer_head *get_FEB(struct tree_balance *); 32598c2ecf20Sopenharmony_ci 32608c2ecf20Sopenharmony_ci/* bitmap.c */ 32618c2ecf20Sopenharmony_ci 32628c2ecf20Sopenharmony_ci/* 32638c2ecf20Sopenharmony_ci * structure contains hints for block allocator, and it is a container for 32648c2ecf20Sopenharmony_ci * arguments, such as node, search path, transaction_handle, etc. 32658c2ecf20Sopenharmony_ci */ 32668c2ecf20Sopenharmony_cistruct __reiserfs_blocknr_hint { 32678c2ecf20Sopenharmony_ci /* inode passed to allocator, if we allocate unf. nodes */ 32688c2ecf20Sopenharmony_ci struct inode *inode; 32698c2ecf20Sopenharmony_ci 32708c2ecf20Sopenharmony_ci sector_t block; /* file offset, in blocks */ 32718c2ecf20Sopenharmony_ci struct in_core_key key; 32728c2ecf20Sopenharmony_ci 32738c2ecf20Sopenharmony_ci /* 32748c2ecf20Sopenharmony_ci * search path, used by allocator to deternine search_start by 32758c2ecf20Sopenharmony_ci * various ways 32768c2ecf20Sopenharmony_ci */ 32778c2ecf20Sopenharmony_ci struct treepath *path; 32788c2ecf20Sopenharmony_ci 32798c2ecf20Sopenharmony_ci /* 32808c2ecf20Sopenharmony_ci * transaction handle is needed to log super blocks 32818c2ecf20Sopenharmony_ci * and bitmap blocks changes 32828c2ecf20Sopenharmony_ci */ 32838c2ecf20Sopenharmony_ci struct reiserfs_transaction_handle *th; 32848c2ecf20Sopenharmony_ci 32858c2ecf20Sopenharmony_ci b_blocknr_t beg, end; 32868c2ecf20Sopenharmony_ci 32878c2ecf20Sopenharmony_ci /* 32888c2ecf20Sopenharmony_ci * a field used to transfer search start value (block number) 32898c2ecf20Sopenharmony_ci * between different block allocator procedures 32908c2ecf20Sopenharmony_ci * (determine_search_start() and others) 32918c2ecf20Sopenharmony_ci */ 32928c2ecf20Sopenharmony_ci b_blocknr_t search_start; 32938c2ecf20Sopenharmony_ci 32948c2ecf20Sopenharmony_ci /* 32958c2ecf20Sopenharmony_ci * is set in determine_prealloc_size() function, 32968c2ecf20Sopenharmony_ci * used by underlayed function that do actual allocation 32978c2ecf20Sopenharmony_ci */ 32988c2ecf20Sopenharmony_ci int prealloc_size; 32998c2ecf20Sopenharmony_ci 33008c2ecf20Sopenharmony_ci /* 33018c2ecf20Sopenharmony_ci * the allocator uses different polices for getting disk 33028c2ecf20Sopenharmony_ci * space for formatted/unformatted blocks with/without preallocation 33038c2ecf20Sopenharmony_ci */ 33048c2ecf20Sopenharmony_ci unsigned formatted_node:1; 33058c2ecf20Sopenharmony_ci unsigned preallocate:1; 33068c2ecf20Sopenharmony_ci}; 33078c2ecf20Sopenharmony_ci 33088c2ecf20Sopenharmony_citypedef struct __reiserfs_blocknr_hint reiserfs_blocknr_hint_t; 33098c2ecf20Sopenharmony_ci 33108c2ecf20Sopenharmony_ciint reiserfs_parse_alloc_options(struct super_block *, char *); 33118c2ecf20Sopenharmony_civoid reiserfs_init_alloc_options(struct super_block *s); 33128c2ecf20Sopenharmony_ci 33138c2ecf20Sopenharmony_ci/* 33148c2ecf20Sopenharmony_ci * given a directory, this will tell you what packing locality 33158c2ecf20Sopenharmony_ci * to use for a new object underneat it. The locality is returned 33168c2ecf20Sopenharmony_ci * in disk byte order (le). 33178c2ecf20Sopenharmony_ci */ 33188c2ecf20Sopenharmony_ci__le32 reiserfs_choose_packing(struct inode *dir); 33198c2ecf20Sopenharmony_ci 33208c2ecf20Sopenharmony_civoid show_alloc_options(struct seq_file *seq, struct super_block *s); 33218c2ecf20Sopenharmony_ciint reiserfs_init_bitmap_cache(struct super_block *sb); 33228c2ecf20Sopenharmony_civoid reiserfs_free_bitmap_cache(struct super_block *sb); 33238c2ecf20Sopenharmony_civoid reiserfs_cache_bitmap_metadata(struct super_block *sb, struct buffer_head *bh, struct reiserfs_bitmap_info *info); 33248c2ecf20Sopenharmony_cistruct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb, unsigned int bitmap); 33258c2ecf20Sopenharmony_ciint is_reusable(struct super_block *s, b_blocknr_t block, int bit_value); 33268c2ecf20Sopenharmony_civoid reiserfs_free_block(struct reiserfs_transaction_handle *th, struct inode *, 33278c2ecf20Sopenharmony_ci b_blocknr_t, int for_unformatted); 33288c2ecf20Sopenharmony_ciint reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *, b_blocknr_t *, int, 33298c2ecf20Sopenharmony_ci int); 33308c2ecf20Sopenharmony_cistatic inline int reiserfs_new_form_blocknrs(struct tree_balance *tb, 33318c2ecf20Sopenharmony_ci b_blocknr_t * new_blocknrs, 33328c2ecf20Sopenharmony_ci int amount_needed) 33338c2ecf20Sopenharmony_ci{ 33348c2ecf20Sopenharmony_ci reiserfs_blocknr_hint_t hint = { 33358c2ecf20Sopenharmony_ci .th = tb->transaction_handle, 33368c2ecf20Sopenharmony_ci .path = tb->tb_path, 33378c2ecf20Sopenharmony_ci .inode = NULL, 33388c2ecf20Sopenharmony_ci .key = tb->key, 33398c2ecf20Sopenharmony_ci .block = 0, 33408c2ecf20Sopenharmony_ci .formatted_node = 1 33418c2ecf20Sopenharmony_ci }; 33428c2ecf20Sopenharmony_ci return reiserfs_allocate_blocknrs(&hint, new_blocknrs, amount_needed, 33438c2ecf20Sopenharmony_ci 0); 33448c2ecf20Sopenharmony_ci} 33458c2ecf20Sopenharmony_ci 33468c2ecf20Sopenharmony_cistatic inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle 33478c2ecf20Sopenharmony_ci *th, struct inode *inode, 33488c2ecf20Sopenharmony_ci b_blocknr_t * new_blocknrs, 33498c2ecf20Sopenharmony_ci struct treepath *path, 33508c2ecf20Sopenharmony_ci sector_t block) 33518c2ecf20Sopenharmony_ci{ 33528c2ecf20Sopenharmony_ci reiserfs_blocknr_hint_t hint = { 33538c2ecf20Sopenharmony_ci .th = th, 33548c2ecf20Sopenharmony_ci .path = path, 33558c2ecf20Sopenharmony_ci .inode = inode, 33568c2ecf20Sopenharmony_ci .block = block, 33578c2ecf20Sopenharmony_ci .formatted_node = 0, 33588c2ecf20Sopenharmony_ci .preallocate = 0 33598c2ecf20Sopenharmony_ci }; 33608c2ecf20Sopenharmony_ci return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0); 33618c2ecf20Sopenharmony_ci} 33628c2ecf20Sopenharmony_ci 33638c2ecf20Sopenharmony_ci#ifdef REISERFS_PREALLOCATE 33648c2ecf20Sopenharmony_cistatic inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle 33658c2ecf20Sopenharmony_ci *th, struct inode *inode, 33668c2ecf20Sopenharmony_ci b_blocknr_t * new_blocknrs, 33678c2ecf20Sopenharmony_ci struct treepath *path, 33688c2ecf20Sopenharmony_ci sector_t block) 33698c2ecf20Sopenharmony_ci{ 33708c2ecf20Sopenharmony_ci reiserfs_blocknr_hint_t hint = { 33718c2ecf20Sopenharmony_ci .th = th, 33728c2ecf20Sopenharmony_ci .path = path, 33738c2ecf20Sopenharmony_ci .inode = inode, 33748c2ecf20Sopenharmony_ci .block = block, 33758c2ecf20Sopenharmony_ci .formatted_node = 0, 33768c2ecf20Sopenharmony_ci .preallocate = 1 33778c2ecf20Sopenharmony_ci }; 33788c2ecf20Sopenharmony_ci return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0); 33798c2ecf20Sopenharmony_ci} 33808c2ecf20Sopenharmony_ci 33818c2ecf20Sopenharmony_civoid reiserfs_discard_prealloc(struct reiserfs_transaction_handle *th, 33828c2ecf20Sopenharmony_ci struct inode *inode); 33838c2ecf20Sopenharmony_civoid reiserfs_discard_all_prealloc(struct reiserfs_transaction_handle *th); 33848c2ecf20Sopenharmony_ci#endif 33858c2ecf20Sopenharmony_ci 33868c2ecf20Sopenharmony_ci/* hashes.c */ 33878c2ecf20Sopenharmony_ci__u32 keyed_hash(const signed char *msg, int len); 33888c2ecf20Sopenharmony_ci__u32 yura_hash(const signed char *msg, int len); 33898c2ecf20Sopenharmony_ci__u32 r5_hash(const signed char *msg, int len); 33908c2ecf20Sopenharmony_ci 33918c2ecf20Sopenharmony_ci#define reiserfs_set_le_bit __set_bit_le 33928c2ecf20Sopenharmony_ci#define reiserfs_test_and_set_le_bit __test_and_set_bit_le 33938c2ecf20Sopenharmony_ci#define reiserfs_clear_le_bit __clear_bit_le 33948c2ecf20Sopenharmony_ci#define reiserfs_test_and_clear_le_bit __test_and_clear_bit_le 33958c2ecf20Sopenharmony_ci#define reiserfs_test_le_bit test_bit_le 33968c2ecf20Sopenharmony_ci#define reiserfs_find_next_zero_le_bit find_next_zero_bit_le 33978c2ecf20Sopenharmony_ci 33988c2ecf20Sopenharmony_ci/* 33998c2ecf20Sopenharmony_ci * sometimes reiserfs_truncate may require to allocate few new blocks 34008c2ecf20Sopenharmony_ci * to perform indirect2direct conversion. People probably used to 34018c2ecf20Sopenharmony_ci * think, that truncate should work without problems on a filesystem 34028c2ecf20Sopenharmony_ci * without free disk space. They may complain that they can not 34038c2ecf20Sopenharmony_ci * truncate due to lack of free disk space. This spare space allows us 34048c2ecf20Sopenharmony_ci * to not worry about it. 500 is probably too much, but it should be 34058c2ecf20Sopenharmony_ci * absolutely safe 34068c2ecf20Sopenharmony_ci */ 34078c2ecf20Sopenharmony_ci#define SPARE_SPACE 500 34088c2ecf20Sopenharmony_ci 34098c2ecf20Sopenharmony_ci/* prototypes from ioctl.c */ 34108c2ecf20Sopenharmony_cilong reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 34118c2ecf20Sopenharmony_cilong reiserfs_compat_ioctl(struct file *filp, 34128c2ecf20Sopenharmony_ci unsigned int cmd, unsigned long arg); 34138c2ecf20Sopenharmony_ciint reiserfs_unpack(struct inode *inode, struct file *filp); 3414