···3737#include <linux/time.h>3838#include <linux/slab.h>3939#include <linux/string.h>4040-#include <linux/reiserfs_fs.h>4040+#include "reiserfs.h"4141#include <linux/buffer_head.h>42424343/* To make any changes in the tree we find a node, that contains item
···55#include <asm/uaccess.h>66#include <linux/string.h>77#include <linux/time.h>88-#include <linux/reiserfs_fs.h>88+#include "reiserfs.h"99#include <linux/buffer_head.h>10101111/* this is one and only function that is used outside (do_balance.c) */
···55#include <asm/uaccess.h>66#include <linux/string.h>77#include <linux/time.h>88-#include <linux/reiserfs_fs.h>88+#include "reiserfs.h"99#include <linux/buffer_head.h>10101111/* these are used in do_balance.c */
···55#include <linux/string.h>66#include <linux/random.h>77#include <linux/time.h>88-#include <linux/reiserfs_fs.h>88+#include "reiserfs.h"991010// find where objectid map starts1111#define objectid_map(s,rs) (old_format_only (s) ? \
+2-2
fs/reiserfs/prints.c
···4455#include <linux/time.h>66#include <linux/fs.h>77-#include <linux/reiserfs_fs.h>77+#include "reiserfs.h"88#include <linux/string.h>99#include <linux/buffer_head.h>1010···329329 Numbering scheme for panic used by Vladimir and Anatoly( Hans completely ignores this scheme, and considers it330330 pointless complexity):331331332332- panics in reiserfs_fs.h have numbers from 1000 to 1999332332+ panics in reiserfs.h have numbers from 1000 to 1999333333 super.c 2000 to 2999334334 preserve.c (unused) 3000 to 3999335335 bitmap.c 4000 to 4999
···11+/*22+ * Copyright 1996, 1997, 1998 Hans Reiser, see reiserfs/README for licensing and copyright details33+ */44+55+#include <linux/reiserfs_fs.h>66+77+#include <linux/slab.h>88+#include <linux/interrupt.h>99+#include <linux/sched.h>1010+#include <linux/workqueue.h>1111+#include <asm/unaligned.h>1212+#include <linux/bitops.h>1313+#include <linux/proc_fs.h>1414+#include <linux/buffer_head.h>1515+#include <linux/reiserfs_fs_i.h>1616+#include <linux/reiserfs_fs_sb.h>1717+1818+/* the 32 bit compat definitions with int argument */1919+#define REISERFS_IOC32_UNPACK _IOW(0xCD, 1, int)2020+#define REISERFS_IOC32_GETFLAGS FS_IOC32_GETFLAGS2121+#define REISERFS_IOC32_SETFLAGS FS_IOC32_SETFLAGS2222+#define REISERFS_IOC32_GETVERSION FS_IOC32_GETVERSION2323+#define REISERFS_IOC32_SETVERSION FS_IOC32_SETVERSION2424+2525+/*2626+ * Locking primitives. The write lock is a per superblock2727+ * special mutex that has properties close to the Big Kernel Lock2828+ * which was used in the previous locking scheme.2929+ */3030+void reiserfs_write_lock(struct super_block *s);3131+void reiserfs_write_unlock(struct super_block *s);3232+int reiserfs_write_lock_once(struct super_block *s);3333+void reiserfs_write_unlock_once(struct super_block *s, int lock_depth);3434+3535+#ifdef CONFIG_REISERFS_CHECK3636+void reiserfs_lock_check_recursive(struct super_block *s);3737+#else3838+static inline void reiserfs_lock_check_recursive(struct super_block *s) { }3939+#endif4040+4141+/*4242+ * Several mutexes depend on the write lock.4343+ * However sometimes we want to relax the write lock while we hold4444+ * these mutexes, according to the release/reacquire on schedule()4545+ * properties of the Bkl that were used.4646+ * Reiserfs performances and locking were based on this scheme.4747+ * Now that the write lock is a mutex and not the bkl anymore, doing so4848+ * may result in a deadlock:4949+ *5050+ * A acquire write_lock5151+ * A acquire j_commit_mutex5252+ * A release write_lock and wait for something5353+ * B acquire write_lock5454+ * B can't acquire j_commit_mutex and sleep5555+ * A can't acquire write lock anymore5656+ * deadlock5757+ *5858+ * What we do here is avoiding such deadlock by playing the same game5959+ * than the Bkl: if we can't acquire a mutex that depends on the write lock,6060+ * we release the write lock, wait a bit and then retry.6161+ *6262+ * The mutexes concerned by this hack are:6363+ * - The commit mutex of a journal list6464+ * - The flush mutex6565+ * - The journal lock6666+ * - The inode mutex6767+ */6868+static inline void reiserfs_mutex_lock_safe(struct mutex *m,6969+ struct super_block *s)7070+{7171+ reiserfs_lock_check_recursive(s);7272+ reiserfs_write_unlock(s);7373+ mutex_lock(m);7474+ reiserfs_write_lock(s);7575+}7676+7777+static inline void7878+reiserfs_mutex_lock_nested_safe(struct mutex *m, unsigned int subclass,7979+ struct super_block *s)8080+{8181+ reiserfs_lock_check_recursive(s);8282+ reiserfs_write_unlock(s);8383+ mutex_lock_nested(m, subclass);8484+ reiserfs_write_lock(s);8585+}8686+8787+static inline void8888+reiserfs_down_read_safe(struct rw_semaphore *sem, struct super_block *s)8989+{9090+ reiserfs_lock_check_recursive(s);9191+ reiserfs_write_unlock(s);9292+ down_read(sem);9393+ reiserfs_write_lock(s);9494+}9595+9696+/*9797+ * When we schedule, we usually want to also release the write lock,9898+ * according to the previous bkl based locking scheme of reiserfs.9999+ */100100+static inline void reiserfs_cond_resched(struct super_block *s)101101+{102102+ if (need_resched()) {103103+ reiserfs_write_unlock(s);104104+ schedule();105105+ reiserfs_write_lock(s);106106+ }107107+}108108+109109+struct fid;110110+111111+/* in reading the #defines, it may help to understand that they employ112112+ the following abbreviations:113113+114114+ B = Buffer115115+ I = Item header116116+ H = Height within the tree (should be changed to LEV)117117+ N = Number of the item in the node118118+ STAT = stat data119119+ DEH = Directory Entry Header120120+ EC = Entry Count121121+ E = Entry number122122+ UL = Unsigned Long123123+ BLKH = BLocK Header124124+ UNFM = UNForMatted node125125+ DC = Disk Child126126+ P = Path127127+128128+ These #defines are named by concatenating these abbreviations,129129+ where first comes the arguments, and last comes the return value,130130+ of the macro.131131+132132+*/133133+134134+#define USE_INODE_GENERATION_COUNTER135135+136136+#define REISERFS_PREALLOCATE137137+#define DISPLACE_NEW_PACKING_LOCALITIES138138+#define PREALLOCATION_SIZE 9139139+140140+/* n must be power of 2 */141141+#define _ROUND_UP(x,n) (((x)+(n)-1u) & ~((n)-1u))142142+143143+// to be ok for alpha and others we have to align structures to 8 byte144144+// boundary.145145+// FIXME: do not change 4 by anything else: there is code which relies on that146146+#define ROUND_UP(x) _ROUND_UP(x,8LL)147147+148148+/* debug levels. Right now, CONFIG_REISERFS_CHECK means print all debug149149+** messages.150150+*/151151+#define REISERFS_DEBUG_CODE 5 /* extra messages to help find/debug errors */152152+153153+void __reiserfs_warning(struct super_block *s, const char *id,154154+ const char *func, const char *fmt, ...);155155+#define reiserfs_warning(s, id, fmt, args...) \156156+ __reiserfs_warning(s, id, __func__, fmt, ##args)157157+/* assertions handling */158158+159159+/** always check a condition and panic if it's false. */160160+#define __RASSERT(cond, scond, format, args...) \161161+do { \162162+ if (!(cond)) \163163+ reiserfs_panic(NULL, "assertion failure", "(" #cond ") at " \164164+ __FILE__ ":%i:%s: " format "\n", \165165+ in_interrupt() ? -1 : task_pid_nr(current), \166166+ __LINE__, __func__ , ##args); \167167+} while (0)168168+169169+#define RASSERT(cond, format, args...) __RASSERT(cond, #cond, format, ##args)170170+171171+#if defined( CONFIG_REISERFS_CHECK )172172+#define RFALSE(cond, format, args...) __RASSERT(!(cond), "!(" #cond ")", format, ##args)173173+#else174174+#define RFALSE( cond, format, args... ) do {;} while( 0 )175175+#endif176176+177177+#define CONSTF __attribute_const__178178+/*179179+ * Disk Data Structures180180+ */181181+182182+/***************************************************************************/183183+/* SUPER BLOCK */184184+/***************************************************************************/185185+186186+/*187187+ * Structure of super block on disk, a version of which in RAM is often accessed as REISERFS_SB(s)->s_rs188188+ * the version in RAM is part of a larger structure containing fields never written to disk.189189+ */190190+#define UNSET_HASH 0 // read_super will guess about, what hash names191191+ // in directories were sorted with192192+#define TEA_HASH 1193193+#define YURA_HASH 2194194+#define R5_HASH 3195195+#define DEFAULT_HASH R5_HASH196196+197197+struct journal_params {198198+ __le32 jp_journal_1st_block; /* where does journal start from on its199199+ * device */200200+ __le32 jp_journal_dev; /* journal device st_rdev */201201+ __le32 jp_journal_size; /* size of the journal */202202+ __le32 jp_journal_trans_max; /* max number of blocks in a transaction. */203203+ __le32 jp_journal_magic; /* random value made on fs creation (this204204+ * was sb_journal_block_count) */205205+ __le32 jp_journal_max_batch; /* max number of blocks to batch into a206206+ * trans */207207+ __le32 jp_journal_max_commit_age; /* in seconds, how old can an async208208+ * commit be */209209+ __le32 jp_journal_max_trans_age; /* in seconds, how old can a transaction210210+ * be */211211+};212212+213213+/* this is the super from 3.5.X, where X >= 10 */214214+struct reiserfs_super_block_v1 {215215+ __le32 s_block_count; /* blocks count */216216+ __le32 s_free_blocks; /* free blocks count */217217+ __le32 s_root_block; /* root block number */218218+ struct journal_params s_journal;219219+ __le16 s_blocksize; /* block size */220220+ __le16 s_oid_maxsize; /* max size of object id array, see221221+ * get_objectid() commentary */222222+ __le16 s_oid_cursize; /* current size of object id array */223223+ __le16 s_umount_state; /* this is set to 1 when filesystem was224224+ * umounted, to 2 - when not */225225+ char s_magic[10]; /* reiserfs magic string indicates that226226+ * file system is reiserfs:227227+ * "ReIsErFs" or "ReIsEr2Fs" or "ReIsEr3Fs" */228228+ __le16 s_fs_state; /* it is set to used by fsck to mark which229229+ * phase of rebuilding is done */230230+ __le32 s_hash_function_code; /* indicate, what hash function is being use231231+ * to sort names in a directory*/232232+ __le16 s_tree_height; /* height of disk tree */233233+ __le16 s_bmap_nr; /* amount of bitmap blocks needed to address234234+ * each block of file system */235235+ __le16 s_version; /* this field is only reliable on filesystem236236+ * with non-standard journal */237237+ __le16 s_reserved_for_journal; /* size in blocks of journal area on main238238+ * device, we need to keep after239239+ * making fs with non-standard journal */240240+} __attribute__ ((__packed__));241241+242242+#define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1))243243+244244+/* this is the on disk super block */245245+struct reiserfs_super_block {246246+ struct reiserfs_super_block_v1 s_v1;247247+ __le32 s_inode_generation;248248+ __le32 s_flags; /* Right now used only by inode-attributes, if enabled */249249+ unsigned char s_uuid[16]; /* filesystem unique identifier */250250+ unsigned char s_label[16]; /* filesystem volume label */251251+ __le16 s_mnt_count; /* Count of mounts since last fsck */252252+ __le16 s_max_mnt_count; /* Maximum mounts before check */253253+ __le32 s_lastcheck; /* Timestamp of last fsck */254254+ __le32 s_check_interval; /* Interval between checks */255255+ char s_unused[76]; /* zero filled by mkreiserfs and256256+ * reiserfs_convert_objectid_map_v1()257257+ * so any additions must be updated258258+ * there as well. */259259+} __attribute__ ((__packed__));260260+261261+#define SB_SIZE (sizeof(struct reiserfs_super_block))262262+263263+#define REISERFS_VERSION_1 0264264+#define REISERFS_VERSION_2 2265265+266266+// on-disk super block fields converted to cpu form267267+#define SB_DISK_SUPER_BLOCK(s) (REISERFS_SB(s)->s_rs)268268+#define SB_V1_DISK_SUPER_BLOCK(s) (&(SB_DISK_SUPER_BLOCK(s)->s_v1))269269+#define SB_BLOCKSIZE(s) \270270+ le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_blocksize))271271+#define SB_BLOCK_COUNT(s) \272272+ le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_block_count))273273+#define SB_FREE_BLOCKS(s) \274274+ le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_free_blocks))275275+#define SB_REISERFS_MAGIC(s) \276276+ (SB_V1_DISK_SUPER_BLOCK(s)->s_magic)277277+#define SB_ROOT_BLOCK(s) \278278+ le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_root_block))279279+#define SB_TREE_HEIGHT(s) \280280+ le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height))281281+#define SB_REISERFS_STATE(s) \282282+ le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state))283283+#define SB_VERSION(s) le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_version))284284+#define SB_BMAP_NR(s) le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr))285285+286286+#define PUT_SB_BLOCK_COUNT(s, val) \287287+ do { SB_V1_DISK_SUPER_BLOCK(s)->s_block_count = cpu_to_le32(val); } while (0)288288+#define PUT_SB_FREE_BLOCKS(s, val) \289289+ do { SB_V1_DISK_SUPER_BLOCK(s)->s_free_blocks = cpu_to_le32(val); } while (0)290290+#define PUT_SB_ROOT_BLOCK(s, val) \291291+ do { SB_V1_DISK_SUPER_BLOCK(s)->s_root_block = cpu_to_le32(val); } while (0)292292+#define PUT_SB_TREE_HEIGHT(s, val) \293293+ do { SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height = cpu_to_le16(val); } while (0)294294+#define PUT_SB_REISERFS_STATE(s, val) \295295+ do { SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state = cpu_to_le16(val); } while (0)296296+#define PUT_SB_VERSION(s, val) \297297+ do { SB_V1_DISK_SUPER_BLOCK(s)->s_version = cpu_to_le16(val); } while (0)298298+#define PUT_SB_BMAP_NR(s, val) \299299+ do { SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr = cpu_to_le16 (val); } while (0)300300+301301+#define SB_ONDISK_JP(s) (&SB_V1_DISK_SUPER_BLOCK(s)->s_journal)302302+#define SB_ONDISK_JOURNAL_SIZE(s) \303303+ le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_size))304304+#define SB_ONDISK_JOURNAL_1st_BLOCK(s) \305305+ le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_1st_block))306306+#define SB_ONDISK_JOURNAL_DEVICE(s) \307307+ le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_dev))308308+#define SB_ONDISK_RESERVED_FOR_JOURNAL(s) \309309+ le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_reserved_for_journal))310310+311311+#define is_block_in_log_or_reserved_area(s, block) \312312+ block >= SB_JOURNAL_1st_RESERVED_BLOCK(s) \313313+ && block < SB_JOURNAL_1st_RESERVED_BLOCK(s) + \314314+ ((!is_reiserfs_jr(SB_DISK_SUPER_BLOCK(s)) ? \315315+ SB_ONDISK_JOURNAL_SIZE(s) + 1 : SB_ONDISK_RESERVED_FOR_JOURNAL(s)))316316+317317+int is_reiserfs_3_5(struct reiserfs_super_block *rs);318318+int is_reiserfs_3_6(struct reiserfs_super_block *rs);319319+int is_reiserfs_jr(struct reiserfs_super_block *rs);320320+321321+/* ReiserFS leaves the first 64k unused, so that partition labels have322322+ enough space. If someone wants to write a fancy bootloader that323323+ needs more than 64k, let us know, and this will be increased in size.324324+ This number must be larger than than the largest block size on any325325+ platform, or code will break. -Hans */326326+#define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024)327327+#define REISERFS_FIRST_BLOCK unused_define328328+#define REISERFS_JOURNAL_OFFSET_IN_BYTES REISERFS_DISK_OFFSET_IN_BYTES329329+330330+/* the spot for the super in versions 3.5 - 3.5.10 (inclusive) */331331+#define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024)332332+333333+/* reiserfs internal error code (used by search_by_key and fix_nodes)) */334334+#define CARRY_ON 0335335+#define REPEAT_SEARCH -1336336+#define IO_ERROR -2337337+#define NO_DISK_SPACE -3338338+#define NO_BALANCING_NEEDED (-4)339339+#define NO_MORE_UNUSED_CONTIGUOUS_BLOCKS (-5)340340+#define QUOTA_EXCEEDED -6341341+342342+typedef __u32 b_blocknr_t;343343+typedef __le32 unp_t;344344+345345+struct unfm_nodeinfo {346346+ unp_t unfm_nodenum;347347+ unsigned short unfm_freespace;348348+};349349+350350+/* there are two formats of keys: 3.5 and 3.6351351+ */352352+#define KEY_FORMAT_3_5 0353353+#define KEY_FORMAT_3_6 1354354+355355+/* there are two stat datas */356356+#define STAT_DATA_V1 0357357+#define STAT_DATA_V2 1358358+359359+static inline struct reiserfs_inode_info *REISERFS_I(const struct inode *inode)360360+{361361+ return container_of(inode, struct reiserfs_inode_info, vfs_inode);362362+}363363+364364+static inline struct reiserfs_sb_info *REISERFS_SB(const struct super_block *sb)365365+{366366+ return sb->s_fs_info;367367+}368368+369369+/* Don't trust REISERFS_SB(sb)->s_bmap_nr, it's a u16370370+ * which overflows on large file systems. */371371+static inline __u32 reiserfs_bmap_count(struct super_block *sb)372372+{373373+ return (SB_BLOCK_COUNT(sb) - 1) / (sb->s_blocksize * 8) + 1;374374+}375375+376376+static inline int bmap_would_wrap(unsigned bmap_nr)377377+{378378+ return bmap_nr > ((1LL << 16) - 1);379379+}380380+381381+/** this says about version of key of all items (but stat data) the382382+ object consists of */383383+#define get_inode_item_key_version( inode ) \384384+ ((REISERFS_I(inode)->i_flags & i_item_key_version_mask) ? KEY_FORMAT_3_6 : KEY_FORMAT_3_5)385385+386386+#define set_inode_item_key_version( inode, version ) \387387+ ({ if((version)==KEY_FORMAT_3_6) \388388+ REISERFS_I(inode)->i_flags |= i_item_key_version_mask; \389389+ else \390390+ REISERFS_I(inode)->i_flags &= ~i_item_key_version_mask; })391391+392392+#define get_inode_sd_version(inode) \393393+ ((REISERFS_I(inode)->i_flags & i_stat_data_version_mask) ? STAT_DATA_V2 : STAT_DATA_V1)394394+395395+#define set_inode_sd_version(inode, version) \396396+ ({ if((version)==STAT_DATA_V2) \397397+ REISERFS_I(inode)->i_flags |= i_stat_data_version_mask; \398398+ else \399399+ REISERFS_I(inode)->i_flags &= ~i_stat_data_version_mask; })400400+401401+/* This is an aggressive tail suppression policy, I am hoping it402402+ improves our benchmarks. The principle behind it is that percentage403403+ space saving is what matters, not absolute space saving. This is404404+ non-intuitive, but it helps to understand it if you consider that the405405+ cost to access 4 blocks is not much more than the cost to access 1406406+ block, if you have to do a seek and rotate. A tail risks a407407+ non-linear disk access that is significant as a percentage of total408408+ time cost for a 4 block file and saves an amount of space that is409409+ less significant as a percentage of space, or so goes the hypothesis.410410+ -Hans */411411+#define STORE_TAIL_IN_UNFM_S1(n_file_size,n_tail_size,n_block_size) \412412+(\413413+ (!(n_tail_size)) || \414414+ (((n_tail_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) || \415415+ ( (n_file_size) >= (n_block_size) * 4 ) || \416416+ ( ( (n_file_size) >= (n_block_size) * 3 ) && \417417+ ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size))/4) ) || \418418+ ( ( (n_file_size) >= (n_block_size) * 2 ) && \419419+ ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size))/2) ) || \420420+ ( ( (n_file_size) >= (n_block_size) ) && \421421+ ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size) * 3)/4) ) ) \422422+)423423+424424+/* Another strategy for tails, this one means only create a tail if all the425425+ file would fit into one DIRECT item.426426+ Primary intention for this one is to increase performance by decreasing427427+ seeking.428428+*/429429+#define STORE_TAIL_IN_UNFM_S2(n_file_size,n_tail_size,n_block_size) \430430+(\431431+ (!(n_tail_size)) || \432432+ (((n_file_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) ) \433433+)434434+435435+/*436436+ * values for s_umount_state field437437+ */438438+#define REISERFS_VALID_FS 1439439+#define REISERFS_ERROR_FS 2440440+441441+//442442+// there are 5 item types currently443443+//444444+#define TYPE_STAT_DATA 0445445+#define TYPE_INDIRECT 1446446+#define TYPE_DIRECT 2447447+#define TYPE_DIRENTRY 3448448+#define TYPE_MAXTYPE 3449449+#define TYPE_ANY 15 // FIXME: comment is required450450+451451+/***************************************************************************/452452+/* KEY & ITEM HEAD */453453+/***************************************************************************/454454+455455+//456456+// directories use this key as well as old files457457+//458458+struct offset_v1 {459459+ __le32 k_offset;460460+ __le32 k_uniqueness;461461+} __attribute__ ((__packed__));462462+463463+struct offset_v2 {464464+ __le64 v;465465+} __attribute__ ((__packed__));466466+467467+static inline __u16 offset_v2_k_type(const struct offset_v2 *v2)468468+{469469+ __u8 type = le64_to_cpu(v2->v) >> 60;470470+ return (type <= TYPE_MAXTYPE) ? type : TYPE_ANY;471471+}472472+473473+static inline void set_offset_v2_k_type(struct offset_v2 *v2, int type)474474+{475475+ v2->v =476476+ (v2->v & cpu_to_le64(~0ULL >> 4)) | cpu_to_le64((__u64) type << 60);477477+}478478+479479+static inline loff_t offset_v2_k_offset(const struct offset_v2 *v2)480480+{481481+ return le64_to_cpu(v2->v) & (~0ULL >> 4);482482+}483483+484484+static inline void set_offset_v2_k_offset(struct offset_v2 *v2, loff_t offset)485485+{486486+ offset &= (~0ULL >> 4);487487+ v2->v = (v2->v & cpu_to_le64(15ULL << 60)) | cpu_to_le64(offset);488488+}489489+490490+/* Key of an item determines its location in the S+tree, and491491+ is composed of 4 components */492492+struct reiserfs_key {493493+ __le32 k_dir_id; /* packing locality: by default parent494494+ directory object id */495495+ __le32 k_objectid; /* object identifier */496496+ union {497497+ struct offset_v1 k_offset_v1;498498+ struct offset_v2 k_offset_v2;499499+ } __attribute__ ((__packed__)) u;500500+} __attribute__ ((__packed__));501501+502502+struct in_core_key {503503+ __u32 k_dir_id; /* packing locality: by default parent504504+ directory object id */505505+ __u32 k_objectid; /* object identifier */506506+ __u64 k_offset;507507+ __u8 k_type;508508+};509509+510510+struct cpu_key {511511+ struct in_core_key on_disk_key;512512+ int version;513513+ int key_length; /* 3 in all cases but direct2indirect and514514+ indirect2direct conversion */515515+};516516+517517+/* Our function for comparing keys can compare keys of different518518+ lengths. It takes as a parameter the length of the keys it is to519519+ compare. These defines are used in determining what is to be passed520520+ to it as that parameter. */521521+#define REISERFS_FULL_KEY_LEN 4522522+#define REISERFS_SHORT_KEY_LEN 2523523+524524+/* The result of the key compare */525525+#define FIRST_GREATER 1526526+#define SECOND_GREATER -1527527+#define KEYS_IDENTICAL 0528528+#define KEY_FOUND 1529529+#define KEY_NOT_FOUND 0530530+531531+#define KEY_SIZE (sizeof(struct reiserfs_key))532532+#define SHORT_KEY_SIZE (sizeof (__u32) + sizeof (__u32))533533+534534+/* return values for search_by_key and clones */535535+#define ITEM_FOUND 1536536+#define ITEM_NOT_FOUND 0537537+#define ENTRY_FOUND 1538538+#define ENTRY_NOT_FOUND 0539539+#define DIRECTORY_NOT_FOUND -1540540+#define REGULAR_FILE_FOUND -2541541+#define DIRECTORY_FOUND -3542542+#define BYTE_FOUND 1543543+#define BYTE_NOT_FOUND 0544544+#define FILE_NOT_FOUND -1545545+546546+#define POSITION_FOUND 1547547+#define POSITION_NOT_FOUND 0548548+549549+// return values for reiserfs_find_entry and search_by_entry_key550550+#define NAME_FOUND 1551551+#define NAME_NOT_FOUND 0552552+#define GOTO_PREVIOUS_ITEM 2553553+#define NAME_FOUND_INVISIBLE 3554554+555555+/* Everything in the filesystem is stored as a set of items. The556556+ item head contains the key of the item, its free space (for557557+ indirect items) and specifies the location of the item itself558558+ within the block. */559559+560560+struct item_head {561561+ /* Everything in the tree is found by searching for it based on562562+ * its key.*/563563+ struct reiserfs_key ih_key;564564+ union {565565+ /* The free space in the last unformatted node of an566566+ indirect item if this is an indirect item. This567567+ equals 0xFFFF iff this is a direct item or stat data568568+ item. Note that the key, not this field, is used to569569+ determine the item type, and thus which field this570570+ union contains. */571571+ __le16 ih_free_space_reserved;572572+ /* Iff this is a directory item, this field equals the573573+ number of directory entries in the directory item. */574574+ __le16 ih_entry_count;575575+ } __attribute__ ((__packed__)) u;576576+ __le16 ih_item_len; /* total size of the item body */577577+ __le16 ih_item_location; /* an offset to the item body578578+ * within the block */579579+ __le16 ih_version; /* 0 for all old items, 2 for new580580+ ones. Highest bit is set by fsck581581+ temporary, cleaned after all582582+ done */583583+} __attribute__ ((__packed__));584584+/* size of item header */585585+#define IH_SIZE (sizeof(struct item_head))586586+587587+#define ih_free_space(ih) le16_to_cpu((ih)->u.ih_free_space_reserved)588588+#define ih_version(ih) le16_to_cpu((ih)->ih_version)589589+#define ih_entry_count(ih) le16_to_cpu((ih)->u.ih_entry_count)590590+#define ih_location(ih) le16_to_cpu((ih)->ih_item_location)591591+#define ih_item_len(ih) le16_to_cpu((ih)->ih_item_len)592592+593593+#define put_ih_free_space(ih, val) do { (ih)->u.ih_free_space_reserved = cpu_to_le16(val); } while(0)594594+#define put_ih_version(ih, val) do { (ih)->ih_version = cpu_to_le16(val); } while (0)595595+#define put_ih_entry_count(ih, val) do { (ih)->u.ih_entry_count = cpu_to_le16(val); } while (0)596596+#define put_ih_location(ih, val) do { (ih)->ih_item_location = cpu_to_le16(val); } while (0)597597+#define put_ih_item_len(ih, val) do { (ih)->ih_item_len = cpu_to_le16(val); } while (0)598598+599599+#define unreachable_item(ih) (ih_version(ih) & (1 << 15))600600+601601+#define get_ih_free_space(ih) (ih_version (ih) == KEY_FORMAT_3_6 ? 0 : ih_free_space (ih))602602+#define set_ih_free_space(ih,val) put_ih_free_space((ih), ((ih_version(ih) == KEY_FORMAT_3_6) ? 0 : (val)))603603+604604+/* these operate on indirect items, where you've got an array of ints605605+** at a possibly unaligned location. These are a noop on ia32606606+** 607607+** p is the array of __u32, i is the index into the array, v is the value608608+** to store there.609609+*/610610+#define get_block_num(p, i) get_unaligned_le32((p) + (i))611611+#define put_block_num(p, i, v) put_unaligned_le32((v), (p) + (i))612612+613613+//614614+// in old version uniqueness field shows key type615615+//616616+#define V1_SD_UNIQUENESS 0617617+#define V1_INDIRECT_UNIQUENESS 0xfffffffe618618+#define V1_DIRECT_UNIQUENESS 0xffffffff619619+#define V1_DIRENTRY_UNIQUENESS 500620620+#define V1_ANY_UNIQUENESS 555 // FIXME: comment is required621621+622622+//623623+// here are conversion routines624624+//625625+static inline int uniqueness2type(__u32 uniqueness) CONSTF;626626+static inline int uniqueness2type(__u32 uniqueness)627627+{628628+ switch ((int)uniqueness) {629629+ case V1_SD_UNIQUENESS:630630+ return TYPE_STAT_DATA;631631+ case V1_INDIRECT_UNIQUENESS:632632+ return TYPE_INDIRECT;633633+ case V1_DIRECT_UNIQUENESS:634634+ return TYPE_DIRECT;635635+ case V1_DIRENTRY_UNIQUENESS:636636+ return TYPE_DIRENTRY;637637+ case V1_ANY_UNIQUENESS:638638+ default:639639+ return TYPE_ANY;640640+ }641641+}642642+643643+static inline __u32 type2uniqueness(int type) CONSTF;644644+static inline __u32 type2uniqueness(int type)645645+{646646+ switch (type) {647647+ case TYPE_STAT_DATA:648648+ return V1_SD_UNIQUENESS;649649+ case TYPE_INDIRECT:650650+ return V1_INDIRECT_UNIQUENESS;651651+ case TYPE_DIRECT:652652+ return V1_DIRECT_UNIQUENESS;653653+ case TYPE_DIRENTRY:654654+ return V1_DIRENTRY_UNIQUENESS;655655+ case TYPE_ANY:656656+ default:657657+ return V1_ANY_UNIQUENESS;658658+ }659659+}660660+661661+//662662+// key is pointer to on disk key which is stored in le, result is cpu,663663+// there is no way to get version of object from key, so, provide664664+// version to these defines665665+//666666+static inline loff_t le_key_k_offset(int version,667667+ const struct reiserfs_key *key)668668+{669669+ return (version == KEY_FORMAT_3_5) ?670670+ le32_to_cpu(key->u.k_offset_v1.k_offset) :671671+ offset_v2_k_offset(&(key->u.k_offset_v2));672672+}673673+674674+static inline loff_t le_ih_k_offset(const struct item_head *ih)675675+{676676+ return le_key_k_offset(ih_version(ih), &(ih->ih_key));677677+}678678+679679+static inline loff_t le_key_k_type(int version, const struct reiserfs_key *key)680680+{681681+ return (version == KEY_FORMAT_3_5) ?682682+ uniqueness2type(le32_to_cpu(key->u.k_offset_v1.k_uniqueness)) :683683+ offset_v2_k_type(&(key->u.k_offset_v2));684684+}685685+686686+static inline loff_t le_ih_k_type(const struct item_head *ih)687687+{688688+ return le_key_k_type(ih_version(ih), &(ih->ih_key));689689+}690690+691691+static inline void set_le_key_k_offset(int version, struct reiserfs_key *key,692692+ loff_t offset)693693+{694694+ (version == KEY_FORMAT_3_5) ? (void)(key->u.k_offset_v1.k_offset = cpu_to_le32(offset)) : /* jdm check */695695+ (void)(set_offset_v2_k_offset(&(key->u.k_offset_v2), offset));696696+}697697+698698+static inline void set_le_ih_k_offset(struct item_head *ih, loff_t offset)699699+{700700+ set_le_key_k_offset(ih_version(ih), &(ih->ih_key), offset);701701+}702702+703703+static inline void set_le_key_k_type(int version, struct reiserfs_key *key,704704+ int type)705705+{706706+ (version == KEY_FORMAT_3_5) ?707707+ (void)(key->u.k_offset_v1.k_uniqueness =708708+ cpu_to_le32(type2uniqueness(type)))709709+ : (void)(set_offset_v2_k_type(&(key->u.k_offset_v2), type));710710+}711711+712712+static inline void set_le_ih_k_type(struct item_head *ih, int type)713713+{714714+ set_le_key_k_type(ih_version(ih), &(ih->ih_key), type);715715+}716716+717717+static inline int is_direntry_le_key(int version, struct reiserfs_key *key)718718+{719719+ return le_key_k_type(version, key) == TYPE_DIRENTRY;720720+}721721+722722+static inline int is_direct_le_key(int version, struct reiserfs_key *key)723723+{724724+ return le_key_k_type(version, key) == TYPE_DIRECT;725725+}726726+727727+static inline int is_indirect_le_key(int version, struct reiserfs_key *key)728728+{729729+ return le_key_k_type(version, key) == TYPE_INDIRECT;730730+}731731+732732+static inline int is_statdata_le_key(int version, struct reiserfs_key *key)733733+{734734+ return le_key_k_type(version, key) == TYPE_STAT_DATA;735735+}736736+737737+//738738+// item header has version.739739+//740740+static inline int is_direntry_le_ih(struct item_head *ih)741741+{742742+ return is_direntry_le_key(ih_version(ih), &ih->ih_key);743743+}744744+745745+static inline int is_direct_le_ih(struct item_head *ih)746746+{747747+ return is_direct_le_key(ih_version(ih), &ih->ih_key);748748+}749749+750750+static inline int is_indirect_le_ih(struct item_head *ih)751751+{752752+ return is_indirect_le_key(ih_version(ih), &ih->ih_key);753753+}754754+755755+static inline int is_statdata_le_ih(struct item_head *ih)756756+{757757+ return is_statdata_le_key(ih_version(ih), &ih->ih_key);758758+}759759+760760+//761761+// key is pointer to cpu key, result is cpu762762+//763763+static inline loff_t cpu_key_k_offset(const struct cpu_key *key)764764+{765765+ return key->on_disk_key.k_offset;766766+}767767+768768+static inline loff_t cpu_key_k_type(const struct cpu_key *key)769769+{770770+ return key->on_disk_key.k_type;771771+}772772+773773+static inline void set_cpu_key_k_offset(struct cpu_key *key, loff_t offset)774774+{775775+ key->on_disk_key.k_offset = offset;776776+}777777+778778+static inline void set_cpu_key_k_type(struct cpu_key *key, int type)779779+{780780+ key->on_disk_key.k_type = type;781781+}782782+783783+static inline void cpu_key_k_offset_dec(struct cpu_key *key)784784+{785785+ key->on_disk_key.k_offset--;786786+}787787+788788+#define is_direntry_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRENTRY)789789+#define is_direct_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRECT)790790+#define is_indirect_cpu_key(key) (cpu_key_k_type (key) == TYPE_INDIRECT)791791+#define is_statdata_cpu_key(key) (cpu_key_k_type (key) == TYPE_STAT_DATA)792792+793793+/* are these used ? */794794+#define is_direntry_cpu_ih(ih) (is_direntry_cpu_key (&((ih)->ih_key)))795795+#define is_direct_cpu_ih(ih) (is_direct_cpu_key (&((ih)->ih_key)))796796+#define is_indirect_cpu_ih(ih) (is_indirect_cpu_key (&((ih)->ih_key)))797797+#define is_statdata_cpu_ih(ih) (is_statdata_cpu_key (&((ih)->ih_key)))798798+799799+#define I_K_KEY_IN_ITEM(ih, key, n_blocksize) \800800+ (!COMP_SHORT_KEYS(ih, key) && \801801+ I_OFF_BYTE_IN_ITEM(ih, k_offset(key), n_blocksize))802802+803803+/* maximal length of item */804804+#define MAX_ITEM_LEN(block_size) (block_size - BLKH_SIZE - IH_SIZE)805805+#define MIN_ITEM_LEN 1806806+807807+/* object identifier for root dir */808808+#define REISERFS_ROOT_OBJECTID 2809809+#define REISERFS_ROOT_PARENT_OBJECTID 1810810+811811+extern struct reiserfs_key root_key;812812+813813+/* 814814+ * Picture represents a leaf of the S+tree815815+ * ______________________________________________________816816+ * | | Array of | | |817817+ * |Block | Object-Item | F r e e | Objects- |818818+ * | head | Headers | S p a c e | Items |819819+ * |______|_______________|___________________|___________|820820+ */821821+822822+/* Header of a disk block. More precisely, header of a formatted leaf823823+ or internal node, and not the header of an unformatted node. */824824+struct block_head {825825+ __le16 blk_level; /* Level of a block in the tree. */826826+ __le16 blk_nr_item; /* Number of keys/items in a block. */827827+ __le16 blk_free_space; /* Block free space in bytes. */828828+ __le16 blk_reserved;829829+ /* dump this in v4/planA */830830+ struct reiserfs_key blk_right_delim_key; /* kept only for compatibility */831831+};832832+833833+#define BLKH_SIZE (sizeof(struct block_head))834834+#define blkh_level(p_blkh) (le16_to_cpu((p_blkh)->blk_level))835835+#define blkh_nr_item(p_blkh) (le16_to_cpu((p_blkh)->blk_nr_item))836836+#define blkh_free_space(p_blkh) (le16_to_cpu((p_blkh)->blk_free_space))837837+#define blkh_reserved(p_blkh) (le16_to_cpu((p_blkh)->blk_reserved))838838+#define set_blkh_level(p_blkh,val) ((p_blkh)->blk_level = cpu_to_le16(val))839839+#define set_blkh_nr_item(p_blkh,val) ((p_blkh)->blk_nr_item = cpu_to_le16(val))840840+#define set_blkh_free_space(p_blkh,val) ((p_blkh)->blk_free_space = cpu_to_le16(val))841841+#define set_blkh_reserved(p_blkh,val) ((p_blkh)->blk_reserved = cpu_to_le16(val))842842+#define blkh_right_delim_key(p_blkh) ((p_blkh)->blk_right_delim_key)843843+#define set_blkh_right_delim_key(p_blkh,val) ((p_blkh)->blk_right_delim_key = val)844844+845845+/*846846+ * values for blk_level field of the struct block_head847847+ */848848+849849+#define FREE_LEVEL 0 /* when node gets removed from the tree its850850+ blk_level is set to FREE_LEVEL. It is then851851+ used to see whether the node is still in the852852+ tree */853853+854854+#define DISK_LEAF_NODE_LEVEL 1 /* Leaf node level. */855855+856856+/* Given the buffer head of a formatted node, resolve to the block head of that node. */857857+#define B_BLK_HEAD(bh) ((struct block_head *)((bh)->b_data))858858+/* Number of items that are in buffer. */859859+#define B_NR_ITEMS(bh) (blkh_nr_item(B_BLK_HEAD(bh)))860860+#define B_LEVEL(bh) (blkh_level(B_BLK_HEAD(bh)))861861+#define B_FREE_SPACE(bh) (blkh_free_space(B_BLK_HEAD(bh)))862862+863863+#define PUT_B_NR_ITEMS(bh, val) do { set_blkh_nr_item(B_BLK_HEAD(bh), val); } while (0)864864+#define PUT_B_LEVEL(bh, val) do { set_blkh_level(B_BLK_HEAD(bh), val); } while (0)865865+#define PUT_B_FREE_SPACE(bh, val) do { set_blkh_free_space(B_BLK_HEAD(bh), val); } while (0)866866+867867+/* Get right delimiting key. -- little endian */868868+#define B_PRIGHT_DELIM_KEY(bh) (&(blk_right_delim_key(B_BLK_HEAD(bh))))869869+870870+/* Does the buffer contain a disk leaf. */871871+#define B_IS_ITEMS_LEVEL(bh) (B_LEVEL(bh) == DISK_LEAF_NODE_LEVEL)872872+873873+/* Does the buffer contain a disk internal node */874874+#define B_IS_KEYS_LEVEL(bh) (B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL \875875+ && B_LEVEL(bh) <= MAX_HEIGHT)876876+877877+/***************************************************************************/878878+/* STAT DATA */879879+/***************************************************************************/880880+881881+//882882+// old stat data is 32 bytes long. We are going to distinguish new one by883883+// different size884884+//885885+struct stat_data_v1 {886886+ __le16 sd_mode; /* file type, permissions */887887+ __le16 sd_nlink; /* number of hard links */888888+ __le16 sd_uid; /* owner */889889+ __le16 sd_gid; /* group */890890+ __le32 sd_size; /* file size */891891+ __le32 sd_atime; /* time of last access */892892+ __le32 sd_mtime; /* time file was last modified */893893+ __le32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */894894+ union {895895+ __le32 sd_rdev;896896+ __le32 sd_blocks; /* number of blocks file uses */897897+ } __attribute__ ((__packed__)) u;898898+ __le32 sd_first_direct_byte; /* first byte of file which is stored899899+ in a direct item: except that if it900900+ equals 1 it is a symlink and if it901901+ equals ~(__u32)0 there is no902902+ direct item. The existence of this903903+ field really grates on me. Let's904904+ replace it with a macro based on905905+ sd_size and our tail suppression906906+ policy. Someday. -Hans */907907+} __attribute__ ((__packed__));908908+909909+#define SD_V1_SIZE (sizeof(struct stat_data_v1))910910+#define stat_data_v1(ih) (ih_version (ih) == KEY_FORMAT_3_5)911911+#define sd_v1_mode(sdp) (le16_to_cpu((sdp)->sd_mode))912912+#define set_sd_v1_mode(sdp,v) ((sdp)->sd_mode = cpu_to_le16(v))913913+#define sd_v1_nlink(sdp) (le16_to_cpu((sdp)->sd_nlink))914914+#define set_sd_v1_nlink(sdp,v) ((sdp)->sd_nlink = cpu_to_le16(v))915915+#define sd_v1_uid(sdp) (le16_to_cpu((sdp)->sd_uid))916916+#define set_sd_v1_uid(sdp,v) ((sdp)->sd_uid = cpu_to_le16(v))917917+#define sd_v1_gid(sdp) (le16_to_cpu((sdp)->sd_gid))918918+#define set_sd_v1_gid(sdp,v) ((sdp)->sd_gid = cpu_to_le16(v))919919+#define sd_v1_size(sdp) (le32_to_cpu((sdp)->sd_size))920920+#define set_sd_v1_size(sdp,v) ((sdp)->sd_size = cpu_to_le32(v))921921+#define sd_v1_atime(sdp) (le32_to_cpu((sdp)->sd_atime))922922+#define set_sd_v1_atime(sdp,v) ((sdp)->sd_atime = cpu_to_le32(v))923923+#define sd_v1_mtime(sdp) (le32_to_cpu((sdp)->sd_mtime))924924+#define set_sd_v1_mtime(sdp,v) ((sdp)->sd_mtime = cpu_to_le32(v))925925+#define sd_v1_ctime(sdp) (le32_to_cpu((sdp)->sd_ctime))926926+#define set_sd_v1_ctime(sdp,v) ((sdp)->sd_ctime = cpu_to_le32(v))927927+#define sd_v1_rdev(sdp) (le32_to_cpu((sdp)->u.sd_rdev))928928+#define set_sd_v1_rdev(sdp,v) ((sdp)->u.sd_rdev = cpu_to_le32(v))929929+#define sd_v1_blocks(sdp) (le32_to_cpu((sdp)->u.sd_blocks))930930+#define set_sd_v1_blocks(sdp,v) ((sdp)->u.sd_blocks = cpu_to_le32(v))931931+#define sd_v1_first_direct_byte(sdp) \932932+ (le32_to_cpu((sdp)->sd_first_direct_byte))933933+#define set_sd_v1_first_direct_byte(sdp,v) \934934+ ((sdp)->sd_first_direct_byte = cpu_to_le32(v))935935+936936+/* inode flags stored in sd_attrs (nee sd_reserved) */937937+938938+/* we want common flags to have the same values as in ext2,939939+ so chattr(1) will work without problems */940940+#define REISERFS_IMMUTABLE_FL FS_IMMUTABLE_FL941941+#define REISERFS_APPEND_FL FS_APPEND_FL942942+#define REISERFS_SYNC_FL FS_SYNC_FL943943+#define REISERFS_NOATIME_FL FS_NOATIME_FL944944+#define REISERFS_NODUMP_FL FS_NODUMP_FL945945+#define REISERFS_SECRM_FL FS_SECRM_FL946946+#define REISERFS_UNRM_FL FS_UNRM_FL947947+#define REISERFS_COMPR_FL FS_COMPR_FL948948+#define REISERFS_NOTAIL_FL FS_NOTAIL_FL949949+950950+/* persistent flags that file inherits from the parent directory */951951+#define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL | \952952+ REISERFS_SYNC_FL | \953953+ REISERFS_NOATIME_FL | \954954+ REISERFS_NODUMP_FL | \955955+ REISERFS_SECRM_FL | \956956+ REISERFS_COMPR_FL | \957957+ REISERFS_NOTAIL_FL )958958+959959+/* Stat Data on disk (reiserfs version of UFS disk inode minus the960960+ address blocks) */961961+struct stat_data {962962+ __le16 sd_mode; /* file type, permissions */963963+ __le16 sd_attrs; /* persistent inode flags */964964+ __le32 sd_nlink; /* number of hard links */965965+ __le64 sd_size; /* file size */966966+ __le32 sd_uid; /* owner */967967+ __le32 sd_gid; /* group */968968+ __le32 sd_atime; /* time of last access */969969+ __le32 sd_mtime; /* time file was last modified */970970+ __le32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */971971+ __le32 sd_blocks;972972+ union {973973+ __le32 sd_rdev;974974+ __le32 sd_generation;975975+ //__le32 sd_first_direct_byte;976976+ /* first byte of file which is stored in a977977+ direct item: except that if it equals 1978978+ it is a symlink and if it equals979979+ ~(__u32)0 there is no direct item. The980980+ existence of this field really grates981981+ on me. Let's replace it with a macro982982+ based on sd_size and our tail983983+ suppression policy? */984984+ } __attribute__ ((__packed__)) u;985985+} __attribute__ ((__packed__));986986+//987987+// this is 44 bytes long988988+//989989+#define SD_SIZE (sizeof(struct stat_data))990990+#define SD_V2_SIZE SD_SIZE991991+#define stat_data_v2(ih) (ih_version (ih) == KEY_FORMAT_3_6)992992+#define sd_v2_mode(sdp) (le16_to_cpu((sdp)->sd_mode))993993+#define set_sd_v2_mode(sdp,v) ((sdp)->sd_mode = cpu_to_le16(v))994994+/* sd_reserved */995995+/* set_sd_reserved */996996+#define sd_v2_nlink(sdp) (le32_to_cpu((sdp)->sd_nlink))997997+#define set_sd_v2_nlink(sdp,v) ((sdp)->sd_nlink = cpu_to_le32(v))998998+#define sd_v2_size(sdp) (le64_to_cpu((sdp)->sd_size))999999+#define set_sd_v2_size(sdp,v) ((sdp)->sd_size = cpu_to_le64(v))10001000+#define sd_v2_uid(sdp) (le32_to_cpu((sdp)->sd_uid))10011001+#define set_sd_v2_uid(sdp,v) ((sdp)->sd_uid = cpu_to_le32(v))10021002+#define sd_v2_gid(sdp) (le32_to_cpu((sdp)->sd_gid))10031003+#define set_sd_v2_gid(sdp,v) ((sdp)->sd_gid = cpu_to_le32(v))10041004+#define sd_v2_atime(sdp) (le32_to_cpu((sdp)->sd_atime))10051005+#define set_sd_v2_atime(sdp,v) ((sdp)->sd_atime = cpu_to_le32(v))10061006+#define sd_v2_mtime(sdp) (le32_to_cpu((sdp)->sd_mtime))10071007+#define set_sd_v2_mtime(sdp,v) ((sdp)->sd_mtime = cpu_to_le32(v))10081008+#define sd_v2_ctime(sdp) (le32_to_cpu((sdp)->sd_ctime))10091009+#define set_sd_v2_ctime(sdp,v) ((sdp)->sd_ctime = cpu_to_le32(v))10101010+#define sd_v2_blocks(sdp) (le32_to_cpu((sdp)->sd_blocks))10111011+#define set_sd_v2_blocks(sdp,v) ((sdp)->sd_blocks = cpu_to_le32(v))10121012+#define sd_v2_rdev(sdp) (le32_to_cpu((sdp)->u.sd_rdev))10131013+#define set_sd_v2_rdev(sdp,v) ((sdp)->u.sd_rdev = cpu_to_le32(v))10141014+#define sd_v2_generation(sdp) (le32_to_cpu((sdp)->u.sd_generation))10151015+#define set_sd_v2_generation(sdp,v) ((sdp)->u.sd_generation = cpu_to_le32(v))10161016+#define sd_v2_attrs(sdp) (le16_to_cpu((sdp)->sd_attrs))10171017+#define set_sd_v2_attrs(sdp,v) ((sdp)->sd_attrs = cpu_to_le16(v))10181018+10191019+/***************************************************************************/10201020+/* DIRECTORY STRUCTURE */10211021+/***************************************************************************/10221022+/* 10231023+ Picture represents the structure of directory items10241024+ ________________________________________________10251025+ | Array of | | | | | |10261026+ | directory |N-1| N-2 | .... | 1st |0th|10271027+ | entry headers | | | | | |10281028+ |_______________|___|_____|________|_______|___|10291029+ <---- directory entries ------>10301030+10311031+ First directory item has k_offset component 1. We store "." and ".."10321032+ in one item, always, we never split "." and ".." into differing10331033+ items. This makes, among other things, the code for removing10341034+ directories simpler. */10351035+#define SD_OFFSET 010361036+#define SD_UNIQUENESS 010371037+#define DOT_OFFSET 110381038+#define DOT_DOT_OFFSET 210391039+#define DIRENTRY_UNIQUENESS 50010401040+10411041+/* */10421042+#define FIRST_ITEM_OFFSET 110431043+10441044+/*10451045+ Q: How to get key of object pointed to by entry from entry? 10461046+10471047+ A: Each directory entry has its header. This header has deh_dir_id and deh_objectid fields, those are key10481048+ of object, entry points to */10491049+10501050+/* NOT IMPLEMENTED: 10511051+ Directory will someday contain stat data of object */10521052+10531053+struct reiserfs_de_head {10541054+ __le32 deh_offset; /* third component of the directory entry key */10551055+ __le32 deh_dir_id; /* objectid of the parent directory of the object, that is referenced10561056+ by directory entry */10571057+ __le32 deh_objectid; /* objectid of the object, that is referenced by directory entry */10581058+ __le16 deh_location; /* offset of name in the whole item */10591059+ __le16 deh_state; /* whether 1) entry contains stat data (for future), and 2) whether10601060+ entry is hidden (unlinked) */10611061+} __attribute__ ((__packed__));10621062+#define DEH_SIZE sizeof(struct reiserfs_de_head)10631063+#define deh_offset(p_deh) (le32_to_cpu((p_deh)->deh_offset))10641064+#define deh_dir_id(p_deh) (le32_to_cpu((p_deh)->deh_dir_id))10651065+#define deh_objectid(p_deh) (le32_to_cpu((p_deh)->deh_objectid))10661066+#define deh_location(p_deh) (le16_to_cpu((p_deh)->deh_location))10671067+#define deh_state(p_deh) (le16_to_cpu((p_deh)->deh_state))10681068+10691069+#define put_deh_offset(p_deh,v) ((p_deh)->deh_offset = cpu_to_le32((v)))10701070+#define put_deh_dir_id(p_deh,v) ((p_deh)->deh_dir_id = cpu_to_le32((v)))10711071+#define put_deh_objectid(p_deh,v) ((p_deh)->deh_objectid = cpu_to_le32((v)))10721072+#define put_deh_location(p_deh,v) ((p_deh)->deh_location = cpu_to_le16((v)))10731073+#define put_deh_state(p_deh,v) ((p_deh)->deh_state = cpu_to_le16((v)))10741074+10751075+/* empty directory contains two entries "." and ".." and their headers */10761076+#define EMPTY_DIR_SIZE \10771077+(DEH_SIZE * 2 + ROUND_UP (strlen (".")) + ROUND_UP (strlen ("..")))10781078+10791079+/* old format directories have this size when empty */10801080+#define EMPTY_DIR_SIZE_V1 (DEH_SIZE * 2 + 3)10811081+10821082+#define DEH_Statdata 0 /* not used now */10831083+#define DEH_Visible 210841084+10851085+/* 64 bit systems (and the S/390) need to be aligned explicitly -jdm */10861086+#if BITS_PER_LONG == 64 || defined(__s390__) || defined(__hppa__)10871087+# define ADDR_UNALIGNED_BITS (3)10881088+#endif10891089+10901090+/* These are only used to manipulate deh_state.10911091+ * Because of this, we'll use the ext2_ bit routines,10921092+ * since they are little endian */10931093+#ifdef ADDR_UNALIGNED_BITS10941094+10951095+# define aligned_address(addr) ((void *)((long)(addr) & ~((1UL << ADDR_UNALIGNED_BITS) - 1)))10961096+# define unaligned_offset(addr) (((int)((long)(addr) & ((1 << ADDR_UNALIGNED_BITS) - 1))) << 3)10971097+10981098+# define set_bit_unaligned(nr, addr) \10991099+ __test_and_set_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))11001100+# define clear_bit_unaligned(nr, addr) \11011101+ __test_and_clear_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))11021102+# define test_bit_unaligned(nr, addr) \11031103+ test_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))11041104+11051105+#else11061106+11071107+# define set_bit_unaligned(nr, addr) __test_and_set_bit_le(nr, addr)11081108+# define clear_bit_unaligned(nr, addr) __test_and_clear_bit_le(nr, addr)11091109+# define test_bit_unaligned(nr, addr) test_bit_le(nr, addr)11101110+11111111+#endif11121112+11131113+#define mark_de_with_sd(deh) set_bit_unaligned (DEH_Statdata, &((deh)->deh_state))11141114+#define mark_de_without_sd(deh) clear_bit_unaligned (DEH_Statdata, &((deh)->deh_state))11151115+#define mark_de_visible(deh) set_bit_unaligned (DEH_Visible, &((deh)->deh_state))11161116+#define mark_de_hidden(deh) clear_bit_unaligned (DEH_Visible, &((deh)->deh_state))11171117+11181118+#define de_with_sd(deh) test_bit_unaligned (DEH_Statdata, &((deh)->deh_state))11191119+#define de_visible(deh) test_bit_unaligned (DEH_Visible, &((deh)->deh_state))11201120+#define de_hidden(deh) !test_bit_unaligned (DEH_Visible, &((deh)->deh_state))11211121+11221122+extern void make_empty_dir_item_v1(char *body, __le32 dirid, __le32 objid,11231123+ __le32 par_dirid, __le32 par_objid);11241124+extern void make_empty_dir_item(char *body, __le32 dirid, __le32 objid,11251125+ __le32 par_dirid, __le32 par_objid);11261126+11271127+/* array of the entry headers */11281128+ /* get item body */11291129+#define B_I_PITEM(bh,ih) ( (bh)->b_data + ih_location(ih) )11301130+#define B_I_DEH(bh,ih) ((struct reiserfs_de_head *)(B_I_PITEM(bh,ih)))11311131+11321132+/* length of the directory entry in directory item. This define11331133+ calculates length of i-th directory entry using directory entry11341134+ locations from dir entry head. When it calculates length of 0-th11351135+ directory entry, it uses length of whole item in place of entry11361136+ location of the non-existent following entry in the calculation.11371137+ See picture above.*/11381138+/*11391139+#define I_DEH_N_ENTRY_LENGTH(ih,deh,i) \11401140+((i) ? (deh_location((deh)-1) - deh_location((deh))) : (ih_item_len((ih)) - deh_location((deh))))11411141+*/11421142+static inline int entry_length(const struct buffer_head *bh,11431143+ const struct item_head *ih, int pos_in_item)11441144+{11451145+ struct reiserfs_de_head *deh;11461146+11471147+ deh = B_I_DEH(bh, ih) + pos_in_item;11481148+ if (pos_in_item)11491149+ return deh_location(deh - 1) - deh_location(deh);11501150+11511151+ return ih_item_len(ih) - deh_location(deh);11521152+}11531153+11541154+/* number of entries in the directory item, depends on ENTRY_COUNT being at the start of directory dynamic data. */11551155+#define I_ENTRY_COUNT(ih) (ih_entry_count((ih)))11561156+11571157+/* name by bh, ih and entry_num */11581158+#define B_I_E_NAME(bh,ih,entry_num) ((char *)(bh->b_data + ih_location(ih) + deh_location(B_I_DEH(bh,ih)+(entry_num))))11591159+11601160+// two entries per block (at least)11611161+#define REISERFS_MAX_NAME(block_size) 25511621162+11631163+/* this structure is used for operations on directory entries. It is11641164+ not a disk structure. */11651165+/* When reiserfs_find_entry or search_by_entry_key find directory11661166+ entry, they return filled reiserfs_dir_entry structure */11671167+struct reiserfs_dir_entry {11681168+ struct buffer_head *de_bh;11691169+ int de_item_num;11701170+ struct item_head *de_ih;11711171+ int de_entry_num;11721172+ struct reiserfs_de_head *de_deh;11731173+ int de_entrylen;11741174+ int de_namelen;11751175+ char *de_name;11761176+ unsigned long *de_gen_number_bit_string;11771177+11781178+ __u32 de_dir_id;11791179+ __u32 de_objectid;11801180+11811181+ struct cpu_key de_entry_key;11821182+};11831183+11841184+/* these defines are useful when a particular member of a reiserfs_dir_entry is needed */11851185+11861186+/* pointer to file name, stored in entry */11871187+#define B_I_DEH_ENTRY_FILE_NAME(bh,ih,deh) (B_I_PITEM (bh, ih) + deh_location(deh))11881188+11891189+/* length of name */11901190+#define I_DEH_N_ENTRY_FILE_NAME_LENGTH(ih,deh,entry_num) \11911191+(I_DEH_N_ENTRY_LENGTH (ih, deh, entry_num) - (de_with_sd (deh) ? SD_SIZE : 0))11921192+11931193+/* hash value occupies bits from 7 up to 30 */11941194+#define GET_HASH_VALUE(offset) ((offset) & 0x7fffff80LL)11951195+/* generation number occupies 7 bits starting from 0 up to 6 */11961196+#define GET_GENERATION_NUMBER(offset) ((offset) & 0x7fLL)11971197+#define MAX_GENERATION_NUMBER 12711981198+11991199+#define SET_GENERATION_NUMBER(offset,gen_number) (GET_HASH_VALUE(offset)|(gen_number))12001200+12011201+/*12021202+ * Picture represents an internal node of the reiserfs tree12031203+ * ______________________________________________________12041204+ * | | Array of | Array of | Free |12051205+ * |block | keys | pointers | space |12061206+ * | head | N | N+1 | |12071207+ * |______|_______________|___________________|___________|12081208+ */12091209+12101210+/***************************************************************************/12111211+/* DISK CHILD */12121212+/***************************************************************************/12131213+/* Disk child pointer: The pointer from an internal node of the tree12141214+ to a node that is on disk. */12151215+struct disk_child {12161216+ __le32 dc_block_number; /* Disk child's block number. */12171217+ __le16 dc_size; /* Disk child's used space. */12181218+ __le16 dc_reserved;12191219+};12201220+12211221+#define DC_SIZE (sizeof(struct disk_child))12221222+#define dc_block_number(dc_p) (le32_to_cpu((dc_p)->dc_block_number))12231223+#define dc_size(dc_p) (le16_to_cpu((dc_p)->dc_size))12241224+#define put_dc_block_number(dc_p, val) do { (dc_p)->dc_block_number = cpu_to_le32(val); } while(0)12251225+#define put_dc_size(dc_p, val) do { (dc_p)->dc_size = cpu_to_le16(val); } while(0)12261226+12271227+/* Get disk child by buffer header and position in the tree node. */12281228+#define B_N_CHILD(bh, n_pos) ((struct disk_child *)\12291229+((bh)->b_data + BLKH_SIZE + B_NR_ITEMS(bh) * KEY_SIZE + DC_SIZE * (n_pos)))12301230+12311231+/* Get disk child number by buffer header and position in the tree node. */12321232+#define B_N_CHILD_NUM(bh, n_pos) (dc_block_number(B_N_CHILD(bh, n_pos)))12331233+#define PUT_B_N_CHILD_NUM(bh, n_pos, val) \12341234+ (put_dc_block_number(B_N_CHILD(bh, n_pos), val))12351235+12361236+ /* maximal value of field child_size in structure disk_child */12371237+ /* child size is the combined size of all items and their headers */12381238+#define MAX_CHILD_SIZE(bh) ((int)( (bh)->b_size - BLKH_SIZE ))12391239+12401240+/* amount of used space in buffer (not including block head) */12411241+#define B_CHILD_SIZE(cur) (MAX_CHILD_SIZE(cur)-(B_FREE_SPACE(cur)))12421242+12431243+/* max and min number of keys in internal node */12441244+#define MAX_NR_KEY(bh) ( (MAX_CHILD_SIZE(bh)-DC_SIZE)/(KEY_SIZE+DC_SIZE) )12451245+#define MIN_NR_KEY(bh) (MAX_NR_KEY(bh)/2)12461246+12471247+/***************************************************************************/12481248+/* PATH STRUCTURES AND DEFINES */12491249+/***************************************************************************/12501250+12511251+/* Search_by_key fills up the path from the root to the leaf as it descends the tree looking for the12521252+ key. It uses reiserfs_bread to try to find buffers in the cache given their block number. If it12531253+ does not find them in the cache it reads them from disk. For each node search_by_key finds using12541254+ reiserfs_bread it then uses bin_search to look through that node. bin_search will find the12551255+ position of the block_number of the next node if it is looking through an internal node. If it12561256+ is looking through a leaf node bin_search will find the position of the item which has key either12571257+ equal to given key, or which is the maximal key less than the given key. */12581258+12591259+struct path_element {12601260+ struct buffer_head *pe_buffer; /* Pointer to the buffer at the path in the tree. */12611261+ int pe_position; /* Position in the tree node which is placed in the */12621262+ /* buffer above. */12631263+};12641264+12651265+#define MAX_HEIGHT 5 /* maximal height of a tree. don't change this without changing JOURNAL_PER_BALANCE_CNT */12661266+#define EXTENDED_MAX_HEIGHT 7 /* Must be equals MAX_HEIGHT + FIRST_PATH_ELEMENT_OFFSET */12671267+#define FIRST_PATH_ELEMENT_OFFSET 2 /* Must be equal to at least 2. */12681268+12691269+#define ILLEGAL_PATH_ELEMENT_OFFSET 1 /* Must be equal to FIRST_PATH_ELEMENT_OFFSET - 1 */12701270+#define MAX_FEB_SIZE 6 /* this MUST be MAX_HEIGHT + 1. See about FEB below */12711271+12721272+/* We need to keep track of who the ancestors of nodes are. When we12731273+ perform a search we record which nodes were visited while12741274+ descending the tree looking for the node we searched for. This list12751275+ of nodes is called the path. This information is used while12761276+ performing balancing. Note that this path information may become12771277+ invalid, and this means we must check it when using it to see if it12781278+ is still valid. You'll need to read search_by_key and the comments12791279+ in it, especially about decrement_counters_in_path(), to understand12801280+ this structure. 12811281+12821282+Paths make the code so much harder to work with and debug.... An12831283+enormous number of bugs are due to them, and trying to write or modify12841284+code that uses them just makes my head hurt. They are based on an12851285+excessive effort to avoid disturbing the precious VFS code.:-( The12861286+gods only know how we are going to SMP the code that uses them.12871287+znodes are the way! */12881288+12891289+#define PATH_READA 0x1 /* do read ahead */12901290+#define PATH_READA_BACK 0x2 /* read backwards */12911291+12921292+struct treepath {12931293+ int path_length; /* Length of the array above. */12941294+ int reada;12951295+ struct path_element path_elements[EXTENDED_MAX_HEIGHT]; /* Array of the path elements. */12961296+ int pos_in_item;12971297+};12981298+12991299+#define pos_in_item(path) ((path)->pos_in_item)13001300+13011301+#define INITIALIZE_PATH(var) \13021302+struct treepath var = {.path_length = ILLEGAL_PATH_ELEMENT_OFFSET, .reada = 0,}13031303+13041304+/* Get path element by path and path position. */13051305+#define PATH_OFFSET_PELEMENT(path, n_offset) ((path)->path_elements + (n_offset))13061306+13071307+/* Get buffer header at the path by path and path position. */13081308+#define PATH_OFFSET_PBUFFER(path, n_offset) (PATH_OFFSET_PELEMENT(path, n_offset)->pe_buffer)13091309+13101310+/* Get position in the element at the path by path and path position. */13111311+#define PATH_OFFSET_POSITION(path, n_offset) (PATH_OFFSET_PELEMENT(path, n_offset)->pe_position)13121312+13131313+#define PATH_PLAST_BUFFER(path) (PATH_OFFSET_PBUFFER((path), (path)->path_length))13141314+ /* you know, to the person who didn't13151315+ write this the macro name does not13161316+ at first suggest what it does.13171317+ Maybe POSITION_FROM_PATH_END? Or13181318+ maybe we should just focus on13191319+ dumping paths... -Hans */13201320+#define PATH_LAST_POSITION(path) (PATH_OFFSET_POSITION((path), (path)->path_length))13211321+13221322+#define PATH_PITEM_HEAD(path) B_N_PITEM_HEAD(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION(path))13231323+13241324+/* in do_balance leaf has h == 0 in contrast with path structure,13251325+ where root has level == 0. That is why we need these defines */13261326+#define PATH_H_PBUFFER(path, h) PATH_OFFSET_PBUFFER (path, path->path_length - (h)) /* tb->S[h] */13271327+#define PATH_H_PPARENT(path, h) PATH_H_PBUFFER (path, (h) + 1) /* tb->F[h] or tb->S[0]->b_parent */13281328+#define PATH_H_POSITION(path, h) PATH_OFFSET_POSITION (path, path->path_length - (h))13291329+#define PATH_H_B_ITEM_ORDER(path, h) PATH_H_POSITION(path, h + 1) /* tb->S[h]->b_item_order */13301330+13311331+#define PATH_H_PATH_OFFSET(path, n_h) ((path)->path_length - (n_h))13321332+13331333+#define get_last_bh(path) PATH_PLAST_BUFFER(path)13341334+#define get_ih(path) PATH_PITEM_HEAD(path)13351335+#define get_item_pos(path) PATH_LAST_POSITION(path)13361336+#define get_item(path) ((void *)B_N_PITEM(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION (path)))13371337+#define item_moved(ih,path) comp_items(ih, path)13381338+#define path_changed(ih,path) comp_items (ih, path)13391339+13401340+/***************************************************************************/13411341+/* MISC */13421342+/***************************************************************************/13431343+13441344+/* Size of pointer to the unformatted node. */13451345+#define UNFM_P_SIZE (sizeof(unp_t))13461346+#define UNFM_P_SHIFT 213471347+13481348+// in in-core inode key is stored on le form13491349+#define INODE_PKEY(inode) ((struct reiserfs_key *)(REISERFS_I(inode)->i_key))13501350+13511351+#define MAX_UL_INT 0xffffffff13521352+#define MAX_INT 0x7ffffff13531353+#define MAX_US_INT 0xffff13541354+13551355+// reiserfs version 2 has max offset 60 bits. Version 1 - 32 bit offset13561356+#define U32_MAX (~(__u32)0)13571357+13581358+static inline loff_t max_reiserfs_offset(struct inode *inode)13591359+{13601360+ if (get_inode_item_key_version(inode) == KEY_FORMAT_3_5)13611361+ return (loff_t) U32_MAX;13621362+13631363+ return (loff_t) ((~(__u64) 0) >> 4);13641364+}13651365+13661366+/*#define MAX_KEY_UNIQUENESS MAX_UL_INT*/13671367+#define MAX_KEY_OBJECTID MAX_UL_INT13681368+13691369+#define MAX_B_NUM MAX_UL_INT13701370+#define MAX_FC_NUM MAX_US_INT13711371+13721372+/* the purpose is to detect overflow of an unsigned short */13731373+#define REISERFS_LINK_MAX (MAX_US_INT - 1000)13741374+13751375+/* The following defines are used in reiserfs_insert_item and reiserfs_append_item */13761376+#define REISERFS_KERNEL_MEM 0 /* reiserfs kernel memory mode */13771377+#define REISERFS_USER_MEM 1 /* reiserfs user memory mode */13781378+13791379+#define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)13801380+#define get_generation(s) atomic_read (&fs_generation(s))13811381+#define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)13821382+#define __fs_changed(gen,s) (gen != get_generation (s))13831383+#define fs_changed(gen,s) \13841384+({ \13851385+ reiserfs_cond_resched(s); \13861386+ __fs_changed(gen, s); \13871387+})13881388+13891389+/***************************************************************************/13901390+/* FIXATE NODES */13911391+/***************************************************************************/13921392+13931393+#define VI_TYPE_LEFT_MERGEABLE 113941394+#define VI_TYPE_RIGHT_MERGEABLE 213951395+13961396+/* To make any changes in the tree we always first find node, that13971397+ contains item to be changed/deleted or place to insert a new13981398+ item. We call this node S. To do balancing we need to decide what13991399+ we will shift to left/right neighbor, or to a new node, where new14001400+ item will be etc. To make this analysis simpler we build virtual14011401+ node. Virtual node is an array of items, that will replace items of14021402+ node S. (For instance if we are going to delete an item, virtual14031403+ node does not contain it). Virtual node keeps information about14041404+ item sizes and types, mergeability of first and last items, sizes14051405+ of all entries in directory item. We use this array of items when14061406+ calculating what we can shift to neighbors and how many nodes we14071407+ have to have if we do not any shiftings, if we shift to left/right14081408+ neighbor or to both. */14091409+struct virtual_item {14101410+ int vi_index; // index in the array of item operations14111411+ unsigned short vi_type; // left/right mergeability14121412+ unsigned short vi_item_len; /* length of item that it will have after balancing */14131413+ struct item_head *vi_ih;14141414+ const char *vi_item; // body of item (old or new)14151415+ const void *vi_new_data; // 0 always but paste mode14161416+ void *vi_uarea; // item specific area14171417+};14181418+14191419+struct virtual_node {14201420+ char *vn_free_ptr; /* this is a pointer to the free space in the buffer */14211421+ unsigned short vn_nr_item; /* number of items in virtual node */14221422+ short vn_size; /* size of node , that node would have if it has unlimited size and no balancing is performed */14231423+ short vn_mode; /* mode of balancing (paste, insert, delete, cut) */14241424+ short vn_affected_item_num;14251425+ short vn_pos_in_item;14261426+ struct item_head *vn_ins_ih; /* item header of inserted item, 0 for other modes */14271427+ const void *vn_data;14281428+ struct virtual_item *vn_vi; /* array of items (including a new one, excluding item to be deleted) */14291429+};14301430+14311431+/* used by directory items when creating virtual nodes */14321432+struct direntry_uarea {14331433+ int flags;14341434+ __u16 entry_count;14351435+ __u16 entry_sizes[1];14361436+} __attribute__ ((__packed__));14371437+14381438+/***************************************************************************/14391439+/* TREE BALANCE */14401440+/***************************************************************************/14411441+14421442+/* This temporary structure is used in tree balance algorithms, and14431443+ constructed as we go to the extent that its various parts are14441444+ needed. It contains arrays of nodes that can potentially be14451445+ involved in the balancing of node S, and parameters that define how14461446+ each of the nodes must be balanced. Note that in these algorithms14471447+ for balancing the worst case is to need to balance the current node14481448+ S and the left and right neighbors and all of their parents plus14491449+ create a new node. We implement S1 balancing for the leaf nodes14501450+ and S0 balancing for the internal nodes (S1 and S0 are defined in14511451+ our papers.)*/14521452+14531453+#define MAX_FREE_BLOCK 7 /* size of the array of buffers to free at end of do_balance */14541454+14551455+/* maximum number of FEB blocknrs on a single level */14561456+#define MAX_AMOUNT_NEEDED 214571457+14581458+/* someday somebody will prefix every field in this struct with tb_ */14591459+struct tree_balance {14601460+ int tb_mode;14611461+ int need_balance_dirty;14621462+ struct super_block *tb_sb;14631463+ struct reiserfs_transaction_handle *transaction_handle;14641464+ struct treepath *tb_path;14651465+ struct buffer_head *L[MAX_HEIGHT]; /* array of left neighbors of nodes in the path */14661466+ struct buffer_head *R[MAX_HEIGHT]; /* array of right neighbors of nodes in the path */14671467+ struct buffer_head *FL[MAX_HEIGHT]; /* array of fathers of the left neighbors */14681468+ struct buffer_head *FR[MAX_HEIGHT]; /* array of fathers of the right neighbors */14691469+ struct buffer_head *CFL[MAX_HEIGHT]; /* array of common parents of center node and its left neighbor */14701470+ struct buffer_head *CFR[MAX_HEIGHT]; /* array of common parents of center node and its right neighbor */14711471+14721472+ struct buffer_head *FEB[MAX_FEB_SIZE]; /* array of empty buffers. Number of buffers in array equals14731473+ cur_blknum. */14741474+ struct buffer_head *used[MAX_FEB_SIZE];14751475+ struct buffer_head *thrown[MAX_FEB_SIZE];14761476+ int lnum[MAX_HEIGHT]; /* array of number of items which must be14771477+ shifted to the left in order to balance the14781478+ current node; for leaves includes item that14791479+ will be partially shifted; for internal14801480+ nodes, it is the number of child pointers14811481+ rather than items. It includes the new item14821482+ being created. The code sometimes subtracts14831483+ one to get the number of wholly shifted14841484+ items for other purposes. */14851485+ int rnum[MAX_HEIGHT]; /* substitute right for left in comment above */14861486+ int lkey[MAX_HEIGHT]; /* array indexed by height h mapping the key delimiting L[h] and14871487+ S[h] to its item number within the node CFL[h] */14881488+ int rkey[MAX_HEIGHT]; /* substitute r for l in comment above */14891489+ int insert_size[MAX_HEIGHT]; /* the number of bytes by we are trying to add or remove from14901490+ S[h]. A negative value means removing. */14911491+ int blknum[MAX_HEIGHT]; /* number of nodes that will replace node S[h] after14921492+ balancing on the level h of the tree. If 0 then S is14931493+ being deleted, if 1 then S is remaining and no new nodes14941494+ are being created, if 2 or 3 then 1 or 2 new nodes is14951495+ being created */14961496+14971497+ /* fields that are used only for balancing leaves of the tree */14981498+ int cur_blknum; /* number of empty blocks having been already allocated */14991499+ int s0num; /* number of items that fall into left most node when S[0] splits */15001500+ int s1num; /* number of items that fall into first new node when S[0] splits */15011501+ int s2num; /* number of items that fall into second new node when S[0] splits */15021502+ int lbytes; /* number of bytes which can flow to the left neighbor from the left */15031503+ /* most liquid item that cannot be shifted from S[0] entirely */15041504+ /* if -1 then nothing will be partially shifted */15051505+ int rbytes; /* number of bytes which will flow to the right neighbor from the right */15061506+ /* most liquid item that cannot be shifted from S[0] entirely */15071507+ /* if -1 then nothing will be partially shifted */15081508+ int s1bytes; /* number of bytes which flow to the first new node when S[0] splits */15091509+ /* note: if S[0] splits into 3 nodes, then items do not need to be cut */15101510+ int s2bytes;15111511+ struct buffer_head *buf_to_free[MAX_FREE_BLOCK]; /* buffers which are to be freed after do_balance finishes by unfix_nodes */15121512+ char *vn_buf; /* kmalloced memory. Used to create15131513+ virtual node and keep map of15141514+ dirtied bitmap blocks */15151515+ int vn_buf_size; /* size of the vn_buf */15161516+ struct virtual_node *tb_vn; /* VN starts after bitmap of bitmap blocks */15171517+15181518+ int fs_gen; /* saved value of `reiserfs_generation' counter15191519+ see FILESYSTEM_CHANGED() macro in reiserfs_fs.h */15201520+#ifdef DISPLACE_NEW_PACKING_LOCALITIES15211521+ struct in_core_key key; /* key pointer, to pass to block allocator or15221522+ another low-level subsystem */15231523+#endif15241524+};15251525+15261526+/* These are modes of balancing */15271527+15281528+/* When inserting an item. */15291529+#define M_INSERT 'i'15301530+/* When inserting into (directories only) or appending onto an already15311531+ existent item. */15321532+#define M_PASTE 'p'15331533+/* When deleting an item. */15341534+#define M_DELETE 'd'15351535+/* When truncating an item or removing an entry from a (directory) item. */15361536+#define M_CUT 'c'15371537+15381538+/* used when balancing on leaf level skipped (in reiserfsck) */15391539+#define M_INTERNAL 'n'15401540+15411541+/* When further balancing is not needed, then do_balance does not need15421542+ to be called. */15431543+#define M_SKIP_BALANCING 's'15441544+#define M_CONVERT 'v'15451545+15461546+/* modes of leaf_move_items */15471547+#define LEAF_FROM_S_TO_L 015481548+#define LEAF_FROM_S_TO_R 115491549+#define LEAF_FROM_R_TO_L 215501550+#define LEAF_FROM_L_TO_R 315511551+#define LEAF_FROM_S_TO_SNEW 415521552+15531553+#define FIRST_TO_LAST 015541554+#define LAST_TO_FIRST 115551555+15561556+/* used in do_balance for passing parent of node information that has15571557+ been gotten from tb struct */15581558+struct buffer_info {15591559+ struct tree_balance *tb;15601560+ struct buffer_head *bi_bh;15611561+ struct buffer_head *bi_parent;15621562+ int bi_position;15631563+};15641564+15651565+static inline struct super_block *sb_from_tb(struct tree_balance *tb)15661566+{15671567+ return tb ? tb->tb_sb : NULL;15681568+}15691569+15701570+static inline struct super_block *sb_from_bi(struct buffer_info *bi)15711571+{15721572+ return bi ? sb_from_tb(bi->tb) : NULL;15731573+}15741574+15751575+/* there are 4 types of items: stat data, directory item, indirect, direct.15761576++-------------------+------------+--------------+------------+15771577+| | k_offset | k_uniqueness | mergeable? |15781578++-------------------+------------+--------------+------------+15791579+| stat data | 0 | 0 | no |15801580++-------------------+------------+--------------+------------+15811581+| 1st directory item| DOT_OFFSET |DIRENTRY_UNIQUENESS| no | 15821582+| non 1st directory | hash value | | yes |15831583+| item | | | |15841584++-------------------+------------+--------------+------------+15851585+| indirect item | offset + 1 |TYPE_INDIRECT | if this is not the first indirect item of the object15861586++-------------------+------------+--------------+------------+15871587+| direct item | offset + 1 |TYPE_DIRECT | if not this is not the first direct item of the object15881588++-------------------+------------+--------------+------------+15891589+*/15901590+15911591+struct item_operations {15921592+ int (*bytes_number) (struct item_head * ih, int block_size);15931593+ void (*decrement_key) (struct cpu_key *);15941594+ int (*is_left_mergeable) (struct reiserfs_key * ih,15951595+ unsigned long bsize);15961596+ void (*print_item) (struct item_head *, char *item);15971597+ void (*check_item) (struct item_head *, char *item);15981598+15991599+ int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,16001600+ int is_affected, int insert_size);16011601+ int (*check_left) (struct virtual_item * vi, int free,16021602+ int start_skip, int end_skip);16031603+ int (*check_right) (struct virtual_item * vi, int free);16041604+ int (*part_size) (struct virtual_item * vi, int from, int to);16051605+ int (*unit_num) (struct virtual_item * vi);16061606+ void (*print_vi) (struct virtual_item * vi);16071607+};16081608+16091609+extern struct item_operations *item_ops[TYPE_ANY + 1];16101610+16111611+#define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)16121612+#define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)16131613+#define op_print_item(ih,item) item_ops[le_ih_k_type (ih)]->print_item (ih, item)16141614+#define op_check_item(ih,item) item_ops[le_ih_k_type (ih)]->check_item (ih, item)16151615+#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)16161616+#define op_check_left(vi,free,start_skip,end_skip) item_ops[(vi)->vi_index]->check_left (vi, free, start_skip, end_skip)16171617+#define op_check_right(vi,free) item_ops[(vi)->vi_index]->check_right (vi, free)16181618+#define op_part_size(vi,from,to) item_ops[(vi)->vi_index]->part_size (vi, from, to)16191619+#define op_unit_num(vi) item_ops[(vi)->vi_index]->unit_num (vi)16201620+#define op_print_vi(vi) item_ops[(vi)->vi_index]->print_vi (vi)16211621+16221622+#define COMP_SHORT_KEYS comp_short_keys16231623+16241624+/* number of blocks pointed to by the indirect item */16251625+#define I_UNFM_NUM(ih) (ih_item_len(ih) / UNFM_P_SIZE)16261626+16271627+/* the used space within the unformatted node corresponding to pos within the item pointed to by ih */16281628+#define I_POS_UNFM_SIZE(ih,pos,size) (((pos) == I_UNFM_NUM(ih) - 1 ) ? (size) - ih_free_space(ih) : (size))16291629+16301630+/* number of bytes contained by the direct item or the unformatted nodes the indirect item points to */16311631+16321632+/* get the item header */16331633+#define B_N_PITEM_HEAD(bh,item_num) ( (struct item_head * )((bh)->b_data + BLKH_SIZE) + (item_num) )16341634+16351635+/* get key */16361636+#define B_N_PDELIM_KEY(bh,item_num) ( (struct reiserfs_key * )((bh)->b_data + BLKH_SIZE) + (item_num) )16371637+16381638+/* get the key */16391639+#define B_N_PKEY(bh,item_num) ( &(B_N_PITEM_HEAD(bh,item_num)->ih_key) )16401640+16411641+/* get item body */16421642+#define B_N_PITEM(bh,item_num) ( (bh)->b_data + ih_location(B_N_PITEM_HEAD((bh),(item_num))))16431643+16441644+/* get the stat data by the buffer header and the item order */16451645+#define B_N_STAT_DATA(bh,nr) \16461646+( (struct stat_data *)((bh)->b_data + ih_location(B_N_PITEM_HEAD((bh),(nr))) ) )16471647+16481648+ /* following defines use reiserfs buffer header and item header */16491649+16501650+/* get stat-data */16511651+#define B_I_STAT_DATA(bh, ih) ( (struct stat_data * )((bh)->b_data + ih_location(ih)) )16521652+16531653+// this is 3976 for size==409616541654+#define MAX_DIRECT_ITEM_LEN(size) ((size) - BLKH_SIZE - 2*IH_SIZE - SD_SIZE - UNFM_P_SIZE)16551655+16561656+/* indirect items consist of entries which contain blocknrs, pos16571657+ indicates which entry, and B_I_POS_UNFM_POINTER resolves to the16581658+ blocknr contained by the entry pos points to */16591659+#define B_I_POS_UNFM_POINTER(bh,ih,pos) le32_to_cpu(*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)))16601660+#define PUT_B_I_POS_UNFM_POINTER(bh,ih,pos, val) do {*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)) = cpu_to_le32(val); } while (0)16611661+16621662+struct reiserfs_iget_args {16631663+ __u32 objectid;16641664+ __u32 dirid;16651665+};16661666+16671667+/***************************************************************************/16681668+/* FUNCTION DECLARATIONS */16691669+/***************************************************************************/16701670+16711671+#define get_journal_desc_magic(bh) (bh->b_data + bh->b_size - 12)16721672+16731673+#define journal_trans_half(blocksize) \16741674+ ((blocksize - sizeof (struct reiserfs_journal_desc) + sizeof (__u32) - 12) / sizeof (__u32))16751675+16761676+/* journal.c see journal.c for all the comments here */16771677+16781678+/* first block written in a commit. */16791679+struct reiserfs_journal_desc {16801680+ __le32 j_trans_id; /* id of commit */16811681+ __le32 j_len; /* length of commit. len +1 is the commit block */16821682+ __le32 j_mount_id; /* mount id of this trans */16831683+ __le32 j_realblock[1]; /* real locations for each block */16841684+};16851685+16861686+#define get_desc_trans_id(d) le32_to_cpu((d)->j_trans_id)16871687+#define get_desc_trans_len(d) le32_to_cpu((d)->j_len)16881688+#define get_desc_mount_id(d) le32_to_cpu((d)->j_mount_id)16891689+16901690+#define set_desc_trans_id(d,val) do { (d)->j_trans_id = cpu_to_le32 (val); } while (0)16911691+#define set_desc_trans_len(d,val) do { (d)->j_len = cpu_to_le32 (val); } while (0)16921692+#define set_desc_mount_id(d,val) do { (d)->j_mount_id = cpu_to_le32 (val); } while (0)16931693+16941694+/* last block written in a commit */16951695+struct reiserfs_journal_commit {16961696+ __le32 j_trans_id; /* must match j_trans_id from the desc block */16971697+ __le32 j_len; /* ditto */16981698+ __le32 j_realblock[1]; /* real locations for each block */16991699+};17001700+17011701+#define get_commit_trans_id(c) le32_to_cpu((c)->j_trans_id)17021702+#define get_commit_trans_len(c) le32_to_cpu((c)->j_len)17031703+#define get_commit_mount_id(c) le32_to_cpu((c)->j_mount_id)17041704+17051705+#define set_commit_trans_id(c,val) do { (c)->j_trans_id = cpu_to_le32 (val); } while (0)17061706+#define set_commit_trans_len(c,val) do { (c)->j_len = cpu_to_le32 (val); } while (0)17071707+17081708+/* this header block gets written whenever a transaction is considered fully flushed, and is more recent than the17091709+** last fully flushed transaction. fully flushed means all the log blocks and all the real blocks are on disk,17101710+** and this transaction does not need to be replayed.17111711+*/17121712+struct reiserfs_journal_header {17131713+ __le32 j_last_flush_trans_id; /* id of last fully flushed transaction */17141714+ __le32 j_first_unflushed_offset; /* offset in the log of where to start replay after a crash */17151715+ __le32 j_mount_id;17161716+ /* 12 */ struct journal_params jh_journal;17171717+};17181718+17191719+/* biggest tunable defines are right here */17201720+#define JOURNAL_BLOCK_COUNT 8192 /* number of blocks in the journal */17211721+#define JOURNAL_TRANS_MAX_DEFAULT 1024 /* biggest possible single transaction, don't change for now (8/3/99) */17221722+#define JOURNAL_TRANS_MIN_DEFAULT 25617231723+#define JOURNAL_MAX_BATCH_DEFAULT 900 /* max blocks to batch into one transaction, don't make this any bigger than 900 */17241724+#define JOURNAL_MIN_RATIO 217251725+#define JOURNAL_MAX_COMMIT_AGE 3017261726+#define JOURNAL_MAX_TRANS_AGE 3017271727+#define JOURNAL_PER_BALANCE_CNT (3 * (MAX_HEIGHT-2) + 9)17281728+#define JOURNAL_BLOCKS_PER_OBJECT(sb) (JOURNAL_PER_BALANCE_CNT * 3 + \17291729+ 2 * (REISERFS_QUOTA_INIT_BLOCKS(sb) + \17301730+ REISERFS_QUOTA_TRANS_BLOCKS(sb)))17311731+17321732+#ifdef CONFIG_QUOTA17331733+#define REISERFS_QUOTA_OPTS ((1 << REISERFS_USRQUOTA) | (1 << REISERFS_GRPQUOTA))17341734+/* We need to update data and inode (atime) */17351735+#define REISERFS_QUOTA_TRANS_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? 2 : 0)17361736+/* 1 balancing, 1 bitmap, 1 data per write + stat data update */17371737+#define REISERFS_QUOTA_INIT_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? \17381738+(DQUOT_INIT_ALLOC*(JOURNAL_PER_BALANCE_CNT+2)+DQUOT_INIT_REWRITE+1) : 0)17391739+/* same as with INIT */17401740+#define REISERFS_QUOTA_DEL_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? \17411741+(DQUOT_DEL_ALLOC*(JOURNAL_PER_BALANCE_CNT+2)+DQUOT_DEL_REWRITE+1) : 0)17421742+#else17431743+#define REISERFS_QUOTA_TRANS_BLOCKS(s) 017441744+#define REISERFS_QUOTA_INIT_BLOCKS(s) 017451745+#define REISERFS_QUOTA_DEL_BLOCKS(s) 017461746+#endif17471747+17481748+/* both of these can be as low as 1, or as high as you want. The min is the17491749+** number of 4k bitmap nodes preallocated on mount. New nodes are allocated17501750+** as needed, and released when transactions are committed. On release, if 17511751+** the current number of nodes is > max, the node is freed, otherwise, 17521752+** it is put on a free list for faster use later.17531753+*/17541754+#define REISERFS_MIN_BITMAP_NODES 1017551755+#define REISERFS_MAX_BITMAP_NODES 10017561756+17571757+#define JBH_HASH_SHIFT 13 /* these are based on journal hash size of 8192 */17581758+#define JBH_HASH_MASK 819117591759+17601760+#define _jhashfn(sb,block) \17611761+ (((unsigned long)sb>>L1_CACHE_SHIFT) ^ \17621762+ (((block)<<(JBH_HASH_SHIFT - 6)) ^ ((block) >> 13) ^ ((block) << (JBH_HASH_SHIFT - 12))))17631763+#define journal_hash(t,sb,block) ((t)[_jhashfn((sb),(block)) & JBH_HASH_MASK])17641764+17651765+// We need these to make journal.c code more readable17661766+#define journal_find_get_block(s, block) __find_get_block(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)17671767+#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)17681768+#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)17691769+17701770+enum reiserfs_bh_state_bits {17711771+ BH_JDirty = BH_PrivateStart, /* buffer is in current transaction */17721772+ BH_JDirty_wait,17731773+ BH_JNew, /* disk block was taken off free list before17741774+ * being in a finished transaction, or17751775+ * written to disk. Can be reused immed. */17761776+ BH_JPrepared,17771777+ BH_JRestore_dirty,17781778+ BH_JTest, // debugging only will go away17791779+};17801780+17811781+BUFFER_FNS(JDirty, journaled);17821782+TAS_BUFFER_FNS(JDirty, journaled);17831783+BUFFER_FNS(JDirty_wait, journal_dirty);17841784+TAS_BUFFER_FNS(JDirty_wait, journal_dirty);17851785+BUFFER_FNS(JNew, journal_new);17861786+TAS_BUFFER_FNS(JNew, journal_new);17871787+BUFFER_FNS(JPrepared, journal_prepared);17881788+TAS_BUFFER_FNS(JPrepared, journal_prepared);17891789+BUFFER_FNS(JRestore_dirty, journal_restore_dirty);17901790+TAS_BUFFER_FNS(JRestore_dirty, journal_restore_dirty);17911791+BUFFER_FNS(JTest, journal_test);17921792+TAS_BUFFER_FNS(JTest, journal_test);17931793+17941794+/*17951795+** transaction handle which is passed around for all journal calls17961796+*/17971797+struct reiserfs_transaction_handle {17981798+ struct super_block *t_super; /* super for this FS when journal_begin was17991799+ called. saves calls to reiserfs_get_super18001800+ also used by nested transactions to make18011801+ sure they are nesting on the right FS18021802+ _must_ be first in the handle18031803+ */18041804+ int t_refcount;18051805+ int t_blocks_logged; /* number of blocks this writer has logged */18061806+ int t_blocks_allocated; /* number of blocks this writer allocated */18071807+ unsigned int t_trans_id; /* sanity check, equals the current trans id */18081808+ void *t_handle_save; /* save existing current->journal_info */18091809+ unsigned displace_new_blocks:1; /* if new block allocation occurres, that block18101810+ should be displaced from others */18111811+ struct list_head t_list;18121812+};18131813+18141814+/* used to keep track of ordered and tail writes, attached to the buffer18151815+ * head through b_journal_head.18161816+ */18171817+struct reiserfs_jh {18181818+ struct reiserfs_journal_list *jl;18191819+ struct buffer_head *bh;18201820+ struct list_head list;18211821+};18221822+18231823+void reiserfs_free_jh(struct buffer_head *bh);18241824+int reiserfs_add_tail_list(struct inode *inode, struct buffer_head *bh);18251825+int reiserfs_add_ordered_list(struct inode *inode, struct buffer_head *bh);18261826+int journal_mark_dirty(struct reiserfs_transaction_handle *,18271827+ struct super_block *, struct buffer_head *bh);18281828+18291829+static inline int reiserfs_file_data_log(struct inode *inode)18301830+{18311831+ if (reiserfs_data_log(inode->i_sb) ||18321832+ (REISERFS_I(inode)->i_flags & i_data_log))18331833+ return 1;18341834+ return 0;18351835+}18361836+18371837+static inline int reiserfs_transaction_running(struct super_block *s)18381838+{18391839+ struct reiserfs_transaction_handle *th = current->journal_info;18401840+ if (th && th->t_super == s)18411841+ return 1;18421842+ if (th && th->t_super == NULL)18431843+ BUG();18441844+ return 0;18451845+}18461846+18471847+static inline int reiserfs_transaction_free_space(struct reiserfs_transaction_handle *th)18481848+{18491849+ return th->t_blocks_allocated - th->t_blocks_logged;18501850+}18511851+18521852+struct reiserfs_transaction_handle *reiserfs_persistent_transaction(struct18531853+ super_block18541854+ *,18551855+ int count);18561856+int reiserfs_end_persistent_transaction(struct reiserfs_transaction_handle *);18571857+int reiserfs_commit_page(struct inode *inode, struct page *page,18581858+ unsigned from, unsigned to);18591859+int reiserfs_flush_old_commits(struct super_block *);18601860+int reiserfs_commit_for_inode(struct inode *);18611861+int reiserfs_inode_needs_commit(struct inode *);18621862+void reiserfs_update_inode_transaction(struct inode *);18631863+void reiserfs_wait_on_write_block(struct super_block *s);18641864+void reiserfs_block_writes(struct reiserfs_transaction_handle *th);18651865+void reiserfs_allow_writes(struct super_block *s);18661866+void reiserfs_check_lock_depth(struct super_block *s, char *caller);18671867+int reiserfs_prepare_for_journal(struct super_block *, struct buffer_head *bh,18681868+ int wait);18691869+void reiserfs_restore_prepared_buffer(struct super_block *,18701870+ struct buffer_head *bh);18711871+int journal_init(struct super_block *, const char *j_dev_name, int old_format,18721872+ unsigned int);18731873+int journal_release(struct reiserfs_transaction_handle *, struct super_block *);18741874+int journal_release_error(struct reiserfs_transaction_handle *,18751875+ struct super_block *);18761876+int journal_end(struct reiserfs_transaction_handle *, struct super_block *,18771877+ unsigned long);18781878+int journal_end_sync(struct reiserfs_transaction_handle *, struct super_block *,18791879+ unsigned long);18801880+int journal_mark_freed(struct reiserfs_transaction_handle *,18811881+ struct super_block *, b_blocknr_t blocknr);18821882+int journal_transaction_should_end(struct reiserfs_transaction_handle *, int);18831883+int reiserfs_in_journal(struct super_block *sb, unsigned int bmap_nr,18841884+ int bit_nr, int searchall, b_blocknr_t *next);18851885+int journal_begin(struct reiserfs_transaction_handle *,18861886+ struct super_block *sb, unsigned long);18871887+int journal_join_abort(struct reiserfs_transaction_handle *,18881888+ struct super_block *sb, unsigned long);18891889+void reiserfs_abort_journal(struct super_block *sb, int errno);18901890+void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...);18911891+int reiserfs_allocate_list_bitmaps(struct super_block *s,18921892+ struct reiserfs_list_bitmap *, unsigned int);18931893+18941894+void add_save_link(struct reiserfs_transaction_handle *th,18951895+ struct inode *inode, int truncate);18961896+int remove_save_link(struct inode *inode, int truncate);18971897+18981898+/* objectid.c */18991899+__u32 reiserfs_get_unused_objectid(struct reiserfs_transaction_handle *th);19001900+void reiserfs_release_objectid(struct reiserfs_transaction_handle *th,19011901+ __u32 objectid_to_release);19021902+int reiserfs_convert_objectid_map_v1(struct super_block *);19031903+19041904+/* stree.c */19051905+int B_IS_IN_TREE(const struct buffer_head *);19061906+extern void copy_item_head(struct item_head *to,19071907+ const struct item_head *from);19081908+19091909+// first key is in cpu form, second - le19101910+extern int comp_short_keys(const struct reiserfs_key *le_key,19111911+ const struct cpu_key *cpu_key);19121912+extern void le_key2cpu_key(struct cpu_key *to, const struct reiserfs_key *from);19131913+19141914+// both are in le form19151915+extern int comp_le_keys(const struct reiserfs_key *,19161916+ const struct reiserfs_key *);19171917+extern int comp_short_le_keys(const struct reiserfs_key *,19181918+ const struct reiserfs_key *);19191919+19201920+//19211921+// get key version from on disk key - kludge19221922+//19231923+static inline int le_key_version(const struct reiserfs_key *key)19241924+{19251925+ int type;19261926+19271927+ type = offset_v2_k_type(&(key->u.k_offset_v2));19281928+ if (type != TYPE_DIRECT && type != TYPE_INDIRECT19291929+ && type != TYPE_DIRENTRY)19301930+ return KEY_FORMAT_3_5;19311931+19321932+ return KEY_FORMAT_3_6;19331933+19341934+}19351935+19361936+static inline void copy_key(struct reiserfs_key *to,19371937+ const struct reiserfs_key *from)19381938+{19391939+ memcpy(to, from, KEY_SIZE);19401940+}19411941+19421942+int comp_items(const struct item_head *stored_ih, const struct treepath *path);19431943+const struct reiserfs_key *get_rkey(const struct treepath *chk_path,19441944+ const struct super_block *sb);19451945+int search_by_key(struct super_block *, const struct cpu_key *,19461946+ struct treepath *, int);19471947+#define search_item(s,key,path) search_by_key (s, key, path, DISK_LEAF_NODE_LEVEL)19481948+int search_for_position_by_key(struct super_block *sb,19491949+ const struct cpu_key *cpu_key,19501950+ struct treepath *search_path);19511951+extern void decrement_bcount(struct buffer_head *bh);19521952+void decrement_counters_in_path(struct treepath *search_path);19531953+void pathrelse(struct treepath *search_path);19541954+int reiserfs_check_path(struct treepath *p);19551955+void pathrelse_and_restore(struct super_block *s, struct treepath *search_path);19561956+19571957+int reiserfs_insert_item(struct reiserfs_transaction_handle *th,19581958+ struct treepath *path,19591959+ const struct cpu_key *key,19601960+ struct item_head *ih,19611961+ struct inode *inode, const char *body);19621962+19631963+int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th,19641964+ struct treepath *path,19651965+ const struct cpu_key *key,19661966+ struct inode *inode,19671967+ const char *body, int paste_size);19681968+19691969+int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,19701970+ struct treepath *path,19711971+ struct cpu_key *key,19721972+ struct inode *inode,19731973+ struct page *page, loff_t new_file_size);19741974+19751975+int reiserfs_delete_item(struct reiserfs_transaction_handle *th,19761976+ struct treepath *path,19771977+ const struct cpu_key *key,19781978+ struct inode *inode, struct buffer_head *un_bh);19791979+19801980+void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,19811981+ struct inode *inode, struct reiserfs_key *key);19821982+int reiserfs_delete_object(struct reiserfs_transaction_handle *th,19831983+ struct inode *inode);19841984+int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,19851985+ struct inode *inode, struct page *,19861986+ int update_timestamps);19871987+19881988+#define i_block_size(inode) ((inode)->i_sb->s_blocksize)19891989+#define file_size(inode) ((inode)->i_size)19901990+#define tail_size(inode) (file_size (inode) & (i_block_size (inode) - 1))19911991+19921992+#define tail_has_to_be_packed(inode) (have_large_tails ((inode)->i_sb)?\19931993+!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 )19941994+19951995+void padd_item(char *item, int total_length, int length);19961996+19971997+/* inode.c */19981998+/* args for the create parameter of reiserfs_get_block */19991999+#define GET_BLOCK_NO_CREATE 0 /* don't create new blocks or convert tails */20002000+#define GET_BLOCK_CREATE 1 /* add anything you need to find block */20012001+#define GET_BLOCK_NO_HOLE 2 /* return -ENOENT for file holes */20022002+#define GET_BLOCK_READ_DIRECT 4 /* read the tail if indirect item not found */20032003+#define GET_BLOCK_NO_IMUX 8 /* i_mutex is not held, don't preallocate */20042004+#define GET_BLOCK_NO_DANGLE 16 /* don't leave any transactions running */20052005+20062006+void reiserfs_read_locked_inode(struct inode *inode,20072007+ struct reiserfs_iget_args *args);20082008+int reiserfs_find_actor(struct inode *inode, void *p);20092009+int reiserfs_init_locked_inode(struct inode *inode, void *p);20102010+void reiserfs_evict_inode(struct inode *inode);20112011+int reiserfs_write_inode(struct inode *inode, struct writeback_control *wbc);20122012+int reiserfs_get_block(struct inode *inode, sector_t block,20132013+ struct buffer_head *bh_result, int create);20142014+struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid,20152015+ int fh_len, int fh_type);20162016+struct dentry *reiserfs_fh_to_parent(struct super_block *sb, struct fid *fid,20172017+ int fh_len, int fh_type);20182018+int reiserfs_encode_fh(struct dentry *dentry, __u32 * data, int *lenp,20192019+ int connectable);20202020+20212021+int reiserfs_truncate_file(struct inode *, int update_timestamps);20222022+void make_cpu_key(struct cpu_key *cpu_key, struct inode *inode, loff_t offset,20232023+ int type, int key_length);20242024+void make_le_item_head(struct item_head *ih, const struct cpu_key *key,20252025+ int version,20262026+ loff_t offset, int type, int length, int entry_count);20272027+struct inode *reiserfs_iget(struct super_block *s, const struct cpu_key *key);20282028+20292029+struct reiserfs_security_handle;20302030+int reiserfs_new_inode(struct reiserfs_transaction_handle *th,20312031+ struct inode *dir, umode_t mode,20322032+ const char *symname, loff_t i_size,20332033+ struct dentry *dentry, struct inode *inode,20342034+ struct reiserfs_security_handle *security);20352035+20362036+void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,20372037+ struct inode *inode, loff_t size);20382038+20392039+static inline void reiserfs_update_sd(struct reiserfs_transaction_handle *th,20402040+ struct inode *inode)20412041+{20422042+ reiserfs_update_sd_size(th, inode, inode->i_size);20432043+}20442044+20452045+void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);20462046+void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);20472047+int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);20482048+20492049+int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);20502050+20512051+/* namei.c */20522052+void set_de_name_and_namelen(struct reiserfs_dir_entry *de);20532053+int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,20542054+ struct treepath *path, struct reiserfs_dir_entry *de);20552055+struct dentry *reiserfs_get_parent(struct dentry *);20562056+20572057+#ifdef CONFIG_REISERFS_PROC_INFO20582058+int reiserfs_proc_info_init(struct super_block *sb);20592059+int reiserfs_proc_info_done(struct super_block *sb);20602060+int reiserfs_proc_info_global_init(void);20612061+int reiserfs_proc_info_global_done(void);20622062+20632063+#define PROC_EXP( e ) e20642064+20652065+#define __PINFO( sb ) REISERFS_SB(sb) -> s_proc_info_data20662066+#define PROC_INFO_MAX( sb, field, value ) \20672067+ __PINFO( sb ).field = \20682068+ max( REISERFS_SB( sb ) -> s_proc_info_data.field, value )20692069+#define PROC_INFO_INC( sb, field ) ( ++ ( __PINFO( sb ).field ) )20702070+#define PROC_INFO_ADD( sb, field, val ) ( __PINFO( sb ).field += ( val ) )20712071+#define PROC_INFO_BH_STAT( sb, bh, level ) \20722072+ PROC_INFO_INC( sb, sbk_read_at[ ( level ) ] ); \20732073+ PROC_INFO_ADD( sb, free_at[ ( level ) ], B_FREE_SPACE( bh ) ); \20742074+ PROC_INFO_ADD( sb, items_at[ ( level ) ], B_NR_ITEMS( bh ) )20752075+#else20762076+static inline int reiserfs_proc_info_init(struct super_block *sb)20772077+{20782078+ return 0;20792079+}20802080+20812081+static inline int reiserfs_proc_info_done(struct super_block *sb)20822082+{20832083+ return 0;20842084+}20852085+20862086+static inline int reiserfs_proc_info_global_init(void)20872087+{20882088+ return 0;20892089+}20902090+20912091+static inline int reiserfs_proc_info_global_done(void)20922092+{20932093+ return 0;20942094+}20952095+20962096+#define PROC_EXP( e )20972097+#define VOID_V ( ( void ) 0 )20982098+#define PROC_INFO_MAX( sb, field, value ) VOID_V20992099+#define PROC_INFO_INC( sb, field ) VOID_V21002100+#define PROC_INFO_ADD( sb, field, val ) VOID_V21012101+#define PROC_INFO_BH_STAT(sb, bh, n_node_level) VOID_V21022102+#endif21032103+21042104+/* dir.c */21052105+extern const struct inode_operations reiserfs_dir_inode_operations;21062106+extern const struct inode_operations reiserfs_symlink_inode_operations;21072107+extern const struct inode_operations reiserfs_special_inode_operations;21082108+extern const struct file_operations reiserfs_dir_operations;21092109+int reiserfs_readdir_dentry(struct dentry *, void *, filldir_t, loff_t *);21102110+21112111+/* tail_conversion.c */21122112+int direct2indirect(struct reiserfs_transaction_handle *, struct inode *,21132113+ struct treepath *, struct buffer_head *, loff_t);21142114+int indirect2direct(struct reiserfs_transaction_handle *, struct inode *,21152115+ struct page *, struct treepath *, const struct cpu_key *,21162116+ loff_t, char *);21172117+void reiserfs_unmap_buffer(struct buffer_head *);21182118+21192119+/* file.c */21202120+extern const struct inode_operations reiserfs_file_inode_operations;21212121+extern const struct file_operations reiserfs_file_operations;21222122+extern const struct address_space_operations reiserfs_address_space_operations;21232123+21242124+/* fix_nodes.c */21252125+21262126+int fix_nodes(int n_op_mode, struct tree_balance *tb,21272127+ struct item_head *ins_ih, const void *);21282128+void unfix_nodes(struct tree_balance *);21292129+21302130+/* prints.c */21312131+void __reiserfs_panic(struct super_block *s, const char *id,21322132+ const char *function, const char *fmt, ...)21332133+ __attribute__ ((noreturn));21342134+#define reiserfs_panic(s, id, fmt, args...) \21352135+ __reiserfs_panic(s, id, __func__, fmt, ##args)21362136+void __reiserfs_error(struct super_block *s, const char *id,21372137+ const char *function, const char *fmt, ...);21382138+#define reiserfs_error(s, id, fmt, args...) \21392139+ __reiserfs_error(s, id, __func__, fmt, ##args)21402140+void reiserfs_info(struct super_block *s, const char *fmt, ...);21412141+void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...);21422142+void print_indirect_item(struct buffer_head *bh, int item_num);21432143+void store_print_tb(struct tree_balance *tb);21442144+void print_cur_tb(char *mes);21452145+void print_de(struct reiserfs_dir_entry *de);21462146+void print_bi(struct buffer_info *bi, char *mes);21472147+#define PRINT_LEAF_ITEMS 1 /* print all items */21482148+#define PRINT_DIRECTORY_ITEMS 2 /* print directory items */21492149+#define PRINT_DIRECT_ITEMS 4 /* print contents of direct items */21502150+void print_block(struct buffer_head *bh, ...);21512151+void print_bmap(struct super_block *s, int silent);21522152+void print_bmap_block(int i, char *data, int size, int silent);21532153+/*void print_super_block (struct super_block * s, char * mes);*/21542154+void print_objectid_map(struct super_block *s);21552155+void print_block_head(struct buffer_head *bh, char *mes);21562156+void check_leaf(struct buffer_head *bh);21572157+void check_internal(struct buffer_head *bh);21582158+void print_statistics(struct super_block *s);21592159+char *reiserfs_hashname(int code);21602160+21612161+/* lbalance.c */21622162+int leaf_move_items(int shift_mode, struct tree_balance *tb, int mov_num,21632163+ int mov_bytes, struct buffer_head *Snew);21642164+int leaf_shift_left(struct tree_balance *tb, int shift_num, int shift_bytes);21652165+int leaf_shift_right(struct tree_balance *tb, int shift_num, int shift_bytes);21662166+void leaf_delete_items(struct buffer_info *cur_bi, int last_first, int first,21672167+ int del_num, int del_bytes);21682168+void leaf_insert_into_buf(struct buffer_info *bi, int before,21692169+ struct item_head *inserted_item_ih,21702170+ const char *inserted_item_body, int zeros_number);21712171+void leaf_paste_in_buffer(struct buffer_info *bi, int pasted_item_num,21722172+ int pos_in_item, int paste_size, const char *body,21732173+ int zeros_number);21742174+void leaf_cut_from_buffer(struct buffer_info *bi, int cut_item_num,21752175+ int pos_in_item, int cut_size);21762176+void leaf_paste_entries(struct buffer_info *bi, int item_num, int before,21772177+ int new_entry_count, struct reiserfs_de_head *new_dehs,21782178+ const char *records, int paste_size);21792179+/* ibalance.c */21802180+int balance_internal(struct tree_balance *, int, int, struct item_head *,21812181+ struct buffer_head **);21822182+21832183+/* do_balance.c */21842184+void do_balance_mark_leaf_dirty(struct tree_balance *tb,21852185+ struct buffer_head *bh, int flag);21862186+#define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty21872187+#define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty21882188+21892189+void do_balance(struct tree_balance *tb, struct item_head *ih,21902190+ const char *body, int flag);21912191+void reiserfs_invalidate_buffer(struct tree_balance *tb,21922192+ struct buffer_head *bh);21932193+21942194+int get_left_neighbor_position(struct tree_balance *tb, int h);21952195+int get_right_neighbor_position(struct tree_balance *tb, int h);21962196+void replace_key(struct tree_balance *tb, struct buffer_head *, int,21972197+ struct buffer_head *, int);21982198+void make_empty_node(struct buffer_info *);21992199+struct buffer_head *get_FEB(struct tree_balance *);22002200+22012201+/* bitmap.c */22022202+22032203+/* structure contains hints for block allocator, and it is a container for22042204+ * arguments, such as node, search path, transaction_handle, etc. */22052205+struct __reiserfs_blocknr_hint {22062206+ struct inode *inode; /* inode passed to allocator, if we allocate unf. nodes */22072207+ sector_t block; /* file offset, in blocks */22082208+ struct in_core_key key;22092209+ struct treepath *path; /* search path, used by allocator to deternine search_start by22102210+ * various ways */22112211+ struct reiserfs_transaction_handle *th; /* transaction handle is needed to log super blocks and22122212+ * bitmap blocks changes */22132213+ b_blocknr_t beg, end;22142214+ b_blocknr_t search_start; /* a field used to transfer search start value (block number)22152215+ * between different block allocator procedures22162216+ * (determine_search_start() and others) */22172217+ int prealloc_size; /* is set in determine_prealloc_size() function, used by underlayed22182218+ * function that do actual allocation */22192219+22202220+ unsigned formatted_node:1; /* the allocator uses different polices for getting disk space for22212221+ * formatted/unformatted blocks with/without preallocation */22222222+ unsigned preallocate:1;22232223+};22242224+22252225+typedef struct __reiserfs_blocknr_hint reiserfs_blocknr_hint_t;22262226+22272227+int reiserfs_parse_alloc_options(struct super_block *, char *);22282228+void reiserfs_init_alloc_options(struct super_block *s);22292229+22302230+/*22312231+ * given a directory, this will tell you what packing locality22322232+ * to use for a new object underneat it. The locality is returned22332233+ * in disk byte order (le).22342234+ */22352235+__le32 reiserfs_choose_packing(struct inode *dir);22362236+22372237+int reiserfs_init_bitmap_cache(struct super_block *sb);22382238+void reiserfs_free_bitmap_cache(struct super_block *sb);22392239+void reiserfs_cache_bitmap_metadata(struct super_block *sb, struct buffer_head *bh, struct reiserfs_bitmap_info *info);22402240+struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb, unsigned int bitmap);22412241+int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value);22422242+void reiserfs_free_block(struct reiserfs_transaction_handle *th, struct inode *,22432243+ b_blocknr_t, int for_unformatted);22442244+int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *, b_blocknr_t *, int,22452245+ int);22462246+static inline int reiserfs_new_form_blocknrs(struct tree_balance *tb,22472247+ b_blocknr_t * new_blocknrs,22482248+ int amount_needed)22492249+{22502250+ reiserfs_blocknr_hint_t hint = {22512251+ .th = tb->transaction_handle,22522252+ .path = tb->tb_path,22532253+ .inode = NULL,22542254+ .key = tb->key,22552255+ .block = 0,22562256+ .formatted_node = 122572257+ };22582258+ return reiserfs_allocate_blocknrs(&hint, new_blocknrs, amount_needed,22592259+ 0);22602260+}22612261+22622262+static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle22632263+ *th, struct inode *inode,22642264+ b_blocknr_t * new_blocknrs,22652265+ struct treepath *path,22662266+ sector_t block)22672267+{22682268+ reiserfs_blocknr_hint_t hint = {22692269+ .th = th,22702270+ .path = path,22712271+ .inode = inode,22722272+ .block = block,22732273+ .formatted_node = 0,22742274+ .preallocate = 022752275+ };22762276+ return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0);22772277+}22782278+22792279+#ifdef REISERFS_PREALLOCATE22802280+static inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle22812281+ *th, struct inode *inode,22822282+ b_blocknr_t * new_blocknrs,22832283+ struct treepath *path,22842284+ sector_t block)22852285+{22862286+ reiserfs_blocknr_hint_t hint = {22872287+ .th = th,22882288+ .path = path,22892289+ .inode = inode,22902290+ .block = block,22912291+ .formatted_node = 0,22922292+ .preallocate = 122932293+ };22942294+ return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0);22952295+}22962296+22972297+void reiserfs_discard_prealloc(struct reiserfs_transaction_handle *th,22982298+ struct inode *inode);22992299+void reiserfs_discard_all_prealloc(struct reiserfs_transaction_handle *th);23002300+#endif23012301+23022302+/* hashes.c */23032303+__u32 keyed_hash(const signed char *msg, int len);23042304+__u32 yura_hash(const signed char *msg, int len);23052305+__u32 r5_hash(const signed char *msg, int len);23062306+23072307+#define reiserfs_set_le_bit __set_bit_le23082308+#define reiserfs_test_and_set_le_bit __test_and_set_bit_le23092309+#define reiserfs_clear_le_bit __clear_bit_le23102310+#define reiserfs_test_and_clear_le_bit __test_and_clear_bit_le23112311+#define reiserfs_test_le_bit test_bit_le23122312+#define reiserfs_find_next_zero_le_bit find_next_zero_bit_le23132313+23142314+/* sometimes reiserfs_truncate may require to allocate few new blocks23152315+ to perform indirect2direct conversion. People probably used to23162316+ think, that truncate should work without problems on a filesystem23172317+ without free disk space. They may complain that they can not23182318+ truncate due to lack of free disk space. This spare space allows us23192319+ to not worry about it. 500 is probably too much, but it should be23202320+ absolutely safe */23212321+#define SPARE_SPACE 50023222322+23232323+/* prototypes from ioctl.c */23242324+long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);23252325+long reiserfs_compat_ioctl(struct file *filp,23262326+ unsigned int cmd, unsigned long arg);23272327+int reiserfs_unpack(struct inode *inode, struct file *filp);
···55#include <linux/time.h>66#include <linux/pagemap.h>77#include <linux/buffer_head.h>88-#include <linux/reiserfs_fs.h>88+#include "reiserfs.h"991010/* access to tail : when one is going to read tail it must make sure, that is not running.1111 direct2indirect and indirect2direct can not run concurrently */
+1-1
fs/reiserfs/xattr.c
···3333 * The xattrs themselves are protected by the xattr_sem.3434 */35353636-#include <linux/reiserfs_fs.h>3636+#include "reiserfs.h"3737#include <linux/capability.h>3838#include <linux/dcache.h>3939#include <linux/namei.h>
···11/*22 * Copyright 1996, 1997, 1998 Hans Reiser, see reiserfs/README for licensing and copyright details33 */44-55- /* this file has an amazingly stupid66- name, yura please fix it to be77- reiserfs.h, and merge all the rest88- of our .h files that are in this99- directory into it. */1010-114#ifndef _LINUX_REISER_FS_H125#define _LINUX_REISER_FS_H136147#include <linux/types.h>158#include <linux/magic.h>1616-1717-#ifdef __KERNEL__1818-#include <linux/slab.h>1919-#include <linux/interrupt.h>2020-#include <linux/sched.h>2121-#include <linux/workqueue.h>2222-#include <asm/unaligned.h>2323-#include <linux/bitops.h>2424-#include <linux/proc_fs.h>2525-#include <linux/buffer_head.h>2626-#include <linux/reiserfs_fs_i.h>2727-#include <linux/reiserfs_fs_sb.h>2828-#endif2993010/*3111 * include/linux/reiser_fs.h···2242#define REISERFS_IOC_SETFLAGS FS_IOC_SETFLAGS2343#define REISERFS_IOC_GETVERSION FS_IOC_GETVERSION2444#define REISERFS_IOC_SETVERSION FS_IOC_SETVERSION2525-2626-#ifdef __KERNEL__2727-/* the 32 bit compat definitions with int argument */2828-#define REISERFS_IOC32_UNPACK _IOW(0xCD, 1, int)2929-#define REISERFS_IOC32_GETFLAGS FS_IOC32_GETFLAGS3030-#define REISERFS_IOC32_SETFLAGS FS_IOC32_SETFLAGS3131-#define REISERFS_IOC32_GETVERSION FS_IOC32_GETVERSION3232-#define REISERFS_IOC32_SETVERSION FS_IOC32_SETVERSION3333-3434-/*3535- * Locking primitives. The write lock is a per superblock3636- * special mutex that has properties close to the Big Kernel Lock3737- * which was used in the previous locking scheme.3838- */3939-void reiserfs_write_lock(struct super_block *s);4040-void reiserfs_write_unlock(struct super_block *s);4141-int reiserfs_write_lock_once(struct super_block *s);4242-void reiserfs_write_unlock_once(struct super_block *s, int lock_depth);4343-4444-#ifdef CONFIG_REISERFS_CHECK4545-void reiserfs_lock_check_recursive(struct super_block *s);4646-#else4747-static inline void reiserfs_lock_check_recursive(struct super_block *s) { }4848-#endif4949-5050-/*5151- * Several mutexes depend on the write lock.5252- * However sometimes we want to relax the write lock while we hold5353- * these mutexes, according to the release/reacquire on schedule()5454- * properties of the Bkl that were used.5555- * Reiserfs performances and locking were based on this scheme.5656- * Now that the write lock is a mutex and not the bkl anymore, doing so5757- * may result in a deadlock:5858- *5959- * A acquire write_lock6060- * A acquire j_commit_mutex6161- * A release write_lock and wait for something6262- * B acquire write_lock6363- * B can't acquire j_commit_mutex and sleep6464- * A can't acquire write lock anymore6565- * deadlock6666- *6767- * What we do here is avoiding such deadlock by playing the same game6868- * than the Bkl: if we can't acquire a mutex that depends on the write lock,6969- * we release the write lock, wait a bit and then retry.7070- *7171- * The mutexes concerned by this hack are:7272- * - The commit mutex of a journal list7373- * - The flush mutex7474- * - The journal lock7575- * - The inode mutex7676- */7777-static inline void reiserfs_mutex_lock_safe(struct mutex *m,7878- struct super_block *s)7979-{8080- reiserfs_lock_check_recursive(s);8181- reiserfs_write_unlock(s);8282- mutex_lock(m);8383- reiserfs_write_lock(s);8484-}8585-8686-static inline void8787-reiserfs_mutex_lock_nested_safe(struct mutex *m, unsigned int subclass,8888- struct super_block *s)8989-{9090- reiserfs_lock_check_recursive(s);9191- reiserfs_write_unlock(s);9292- mutex_lock_nested(m, subclass);9393- reiserfs_write_lock(s);9494-}9595-9696-static inline void9797-reiserfs_down_read_safe(struct rw_semaphore *sem, struct super_block *s)9898-{9999- reiserfs_lock_check_recursive(s);100100- reiserfs_write_unlock(s);101101- down_read(sem);102102- reiserfs_write_lock(s);103103-}104104-105105-/*106106- * When we schedule, we usually want to also release the write lock,107107- * according to the previous bkl based locking scheme of reiserfs.108108- */109109-static inline void reiserfs_cond_resched(struct super_block *s)110110-{111111- if (need_resched()) {112112- reiserfs_write_unlock(s);113113- schedule();114114- reiserfs_write_lock(s);115115- }116116-}117117-118118-struct fid;119119-120120-/* in reading the #defines, it may help to understand that they employ121121- the following abbreviations:122122-123123- B = Buffer124124- I = Item header125125- H = Height within the tree (should be changed to LEV)126126- N = Number of the item in the node127127- STAT = stat data128128- DEH = Directory Entry Header129129- EC = Entry Count130130- E = Entry number131131- UL = Unsigned Long132132- BLKH = BLocK Header133133- UNFM = UNForMatted node134134- DC = Disk Child135135- P = Path136136-137137- These #defines are named by concatenating these abbreviations,138138- where first comes the arguments, and last comes the return value,139139- of the macro.140140-141141-*/142142-143143-#define USE_INODE_GENERATION_COUNTER144144-145145-#define REISERFS_PREALLOCATE146146-#define DISPLACE_NEW_PACKING_LOCALITIES147147-#define PREALLOCATION_SIZE 9148148-149149-/* n must be power of 2 */150150-#define _ROUND_UP(x,n) (((x)+(n)-1u) & ~((n)-1u))151151-152152-// to be ok for alpha and others we have to align structures to 8 byte153153-// boundary.154154-// FIXME: do not change 4 by anything else: there is code which relies on that155155-#define ROUND_UP(x) _ROUND_UP(x,8LL)156156-157157-/* debug levels. Right now, CONFIG_REISERFS_CHECK means print all debug158158-** messages.159159-*/160160-#define REISERFS_DEBUG_CODE 5 /* extra messages to help find/debug errors */161161-162162-void __reiserfs_warning(struct super_block *s, const char *id,163163- const char *func, const char *fmt, ...);164164-#define reiserfs_warning(s, id, fmt, args...) \165165- __reiserfs_warning(s, id, __func__, fmt, ##args)166166-/* assertions handling */167167-168168-/** always check a condition and panic if it's false. */169169-#define __RASSERT(cond, scond, format, args...) \170170-do { \171171- if (!(cond)) \172172- reiserfs_panic(NULL, "assertion failure", "(" #cond ") at " \173173- __FILE__ ":%i:%s: " format "\n", \174174- in_interrupt() ? -1 : task_pid_nr(current), \175175- __LINE__, __func__ , ##args); \176176-} while (0)177177-178178-#define RASSERT(cond, format, args...) __RASSERT(cond, #cond, format, ##args)179179-180180-#if defined( CONFIG_REISERFS_CHECK )181181-#define RFALSE(cond, format, args...) __RASSERT(!(cond), "!(" #cond ")", format, ##args)182182-#else183183-#define RFALSE( cond, format, args... ) do {;} while( 0 )184184-#endif185185-186186-#define CONSTF __attribute_const__187187-/*188188- * Disk Data Structures189189- */190190-191191-/***************************************************************************/192192-/* SUPER BLOCK */193193-/***************************************************************************/194194-195195-/*196196- * Structure of super block on disk, a version of which in RAM is often accessed as REISERFS_SB(s)->s_rs197197- * the version in RAM is part of a larger structure containing fields never written to disk.198198- */199199-#define UNSET_HASH 0 // read_super will guess about, what hash names200200- // in directories were sorted with201201-#define TEA_HASH 1202202-#define YURA_HASH 2203203-#define R5_HASH 3204204-#define DEFAULT_HASH R5_HASH205205-206206-struct journal_params {207207- __le32 jp_journal_1st_block; /* where does journal start from on its208208- * device */209209- __le32 jp_journal_dev; /* journal device st_rdev */210210- __le32 jp_journal_size; /* size of the journal */211211- __le32 jp_journal_trans_max; /* max number of blocks in a transaction. */212212- __le32 jp_journal_magic; /* random value made on fs creation (this213213- * was sb_journal_block_count) */214214- __le32 jp_journal_max_batch; /* max number of blocks to batch into a215215- * trans */216216- __le32 jp_journal_max_commit_age; /* in seconds, how old can an async217217- * commit be */218218- __le32 jp_journal_max_trans_age; /* in seconds, how old can a transaction219219- * be */220220-};221221-222222-/* this is the super from 3.5.X, where X >= 10 */223223-struct reiserfs_super_block_v1 {224224- __le32 s_block_count; /* blocks count */225225- __le32 s_free_blocks; /* free blocks count */226226- __le32 s_root_block; /* root block number */227227- struct journal_params s_journal;228228- __le16 s_blocksize; /* block size */229229- __le16 s_oid_maxsize; /* max size of object id array, see230230- * get_objectid() commentary */231231- __le16 s_oid_cursize; /* current size of object id array */232232- __le16 s_umount_state; /* this is set to 1 when filesystem was233233- * umounted, to 2 - when not */234234- char s_magic[10]; /* reiserfs magic string indicates that235235- * file system is reiserfs:236236- * "ReIsErFs" or "ReIsEr2Fs" or "ReIsEr3Fs" */237237- __le16 s_fs_state; /* it is set to used by fsck to mark which238238- * phase of rebuilding is done */239239- __le32 s_hash_function_code; /* indicate, what hash function is being use240240- * to sort names in a directory*/241241- __le16 s_tree_height; /* height of disk tree */242242- __le16 s_bmap_nr; /* amount of bitmap blocks needed to address243243- * each block of file system */244244- __le16 s_version; /* this field is only reliable on filesystem245245- * with non-standard journal */246246- __le16 s_reserved_for_journal; /* size in blocks of journal area on main247247- * device, we need to keep after248248- * making fs with non-standard journal */249249-} __attribute__ ((__packed__));250250-251251-#define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1))252252-253253-/* this is the on disk super block */254254-struct reiserfs_super_block {255255- struct reiserfs_super_block_v1 s_v1;256256- __le32 s_inode_generation;257257- __le32 s_flags; /* Right now used only by inode-attributes, if enabled */258258- unsigned char s_uuid[16]; /* filesystem unique identifier */259259- unsigned char s_label[16]; /* filesystem volume label */260260- __le16 s_mnt_count; /* Count of mounts since last fsck */261261- __le16 s_max_mnt_count; /* Maximum mounts before check */262262- __le32 s_lastcheck; /* Timestamp of last fsck */263263- __le32 s_check_interval; /* Interval between checks */264264- char s_unused[76]; /* zero filled by mkreiserfs and265265- * reiserfs_convert_objectid_map_v1()266266- * so any additions must be updated267267- * there as well. */268268-} __attribute__ ((__packed__));269269-270270-#define SB_SIZE (sizeof(struct reiserfs_super_block))271271-272272-#define REISERFS_VERSION_1 0273273-#define REISERFS_VERSION_2 2274274-275275-// on-disk super block fields converted to cpu form276276-#define SB_DISK_SUPER_BLOCK(s) (REISERFS_SB(s)->s_rs)277277-#define SB_V1_DISK_SUPER_BLOCK(s) (&(SB_DISK_SUPER_BLOCK(s)->s_v1))278278-#define SB_BLOCKSIZE(s) \279279- le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_blocksize))280280-#define SB_BLOCK_COUNT(s) \281281- le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_block_count))282282-#define SB_FREE_BLOCKS(s) \283283- le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_free_blocks))284284-#define SB_REISERFS_MAGIC(s) \285285- (SB_V1_DISK_SUPER_BLOCK(s)->s_magic)286286-#define SB_ROOT_BLOCK(s) \287287- le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_root_block))288288-#define SB_TREE_HEIGHT(s) \289289- le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height))290290-#define SB_REISERFS_STATE(s) \291291- le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state))292292-#define SB_VERSION(s) le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_version))293293-#define SB_BMAP_NR(s) le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr))294294-295295-#define PUT_SB_BLOCK_COUNT(s, val) \296296- do { SB_V1_DISK_SUPER_BLOCK(s)->s_block_count = cpu_to_le32(val); } while (0)297297-#define PUT_SB_FREE_BLOCKS(s, val) \298298- do { SB_V1_DISK_SUPER_BLOCK(s)->s_free_blocks = cpu_to_le32(val); } while (0)299299-#define PUT_SB_ROOT_BLOCK(s, val) \300300- do { SB_V1_DISK_SUPER_BLOCK(s)->s_root_block = cpu_to_le32(val); } while (0)301301-#define PUT_SB_TREE_HEIGHT(s, val) \302302- do { SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height = cpu_to_le16(val); } while (0)303303-#define PUT_SB_REISERFS_STATE(s, val) \304304- do { SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state = cpu_to_le16(val); } while (0)305305-#define PUT_SB_VERSION(s, val) \306306- do { SB_V1_DISK_SUPER_BLOCK(s)->s_version = cpu_to_le16(val); } while (0)307307-#define PUT_SB_BMAP_NR(s, val) \308308- do { SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr = cpu_to_le16 (val); } while (0)309309-310310-#define SB_ONDISK_JP(s) (&SB_V1_DISK_SUPER_BLOCK(s)->s_journal)311311-#define SB_ONDISK_JOURNAL_SIZE(s) \312312- le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_size))313313-#define SB_ONDISK_JOURNAL_1st_BLOCK(s) \314314- le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_1st_block))315315-#define SB_ONDISK_JOURNAL_DEVICE(s) \316316- le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_dev))317317-#define SB_ONDISK_RESERVED_FOR_JOURNAL(s) \318318- le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_reserved_for_journal))319319-320320-#define is_block_in_log_or_reserved_area(s, block) \321321- block >= SB_JOURNAL_1st_RESERVED_BLOCK(s) \322322- && block < SB_JOURNAL_1st_RESERVED_BLOCK(s) + \323323- ((!is_reiserfs_jr(SB_DISK_SUPER_BLOCK(s)) ? \324324- SB_ONDISK_JOURNAL_SIZE(s) + 1 : SB_ONDISK_RESERVED_FOR_JOURNAL(s)))325325-326326-int is_reiserfs_3_5(struct reiserfs_super_block *rs);327327-int is_reiserfs_3_6(struct reiserfs_super_block *rs);328328-int is_reiserfs_jr(struct reiserfs_super_block *rs);329329-330330-/* ReiserFS leaves the first 64k unused, so that partition labels have331331- enough space. If someone wants to write a fancy bootloader that332332- needs more than 64k, let us know, and this will be increased in size.333333- This number must be larger than than the largest block size on any334334- platform, or code will break. -Hans */335335-#define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024)336336-#define REISERFS_FIRST_BLOCK unused_define337337-#define REISERFS_JOURNAL_OFFSET_IN_BYTES REISERFS_DISK_OFFSET_IN_BYTES338338-339339-/* the spot for the super in versions 3.5 - 3.5.10 (inclusive) */340340-#define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024)341341-342342-/* reiserfs internal error code (used by search_by_key and fix_nodes)) */343343-#define CARRY_ON 0344344-#define REPEAT_SEARCH -1345345-#define IO_ERROR -2346346-#define NO_DISK_SPACE -3347347-#define NO_BALANCING_NEEDED (-4)348348-#define NO_MORE_UNUSED_CONTIGUOUS_BLOCKS (-5)349349-#define QUOTA_EXCEEDED -6350350-351351-typedef __u32 b_blocknr_t;352352-typedef __le32 unp_t;353353-354354-struct unfm_nodeinfo {355355- unp_t unfm_nodenum;356356- unsigned short unfm_freespace;357357-};358358-359359-/* there are two formats of keys: 3.5 and 3.6360360- */361361-#define KEY_FORMAT_3_5 0362362-#define KEY_FORMAT_3_6 1363363-364364-/* there are two stat datas */365365-#define STAT_DATA_V1 0366366-#define STAT_DATA_V2 1367367-368368-static inline struct reiserfs_inode_info *REISERFS_I(const struct inode *inode)369369-{370370- return container_of(inode, struct reiserfs_inode_info, vfs_inode);371371-}372372-373373-static inline struct reiserfs_sb_info *REISERFS_SB(const struct super_block *sb)374374-{375375- return sb->s_fs_info;376376-}377377-378378-/* Don't trust REISERFS_SB(sb)->s_bmap_nr, it's a u16379379- * which overflows on large file systems. */380380-static inline __u32 reiserfs_bmap_count(struct super_block *sb)381381-{382382- return (SB_BLOCK_COUNT(sb) - 1) / (sb->s_blocksize * 8) + 1;383383-}384384-385385-static inline int bmap_would_wrap(unsigned bmap_nr)386386-{387387- return bmap_nr > ((1LL << 16) - 1);388388-}389389-390390-/** this says about version of key of all items (but stat data) the391391- object consists of */392392-#define get_inode_item_key_version( inode ) \393393- ((REISERFS_I(inode)->i_flags & i_item_key_version_mask) ? KEY_FORMAT_3_6 : KEY_FORMAT_3_5)394394-395395-#define set_inode_item_key_version( inode, version ) \396396- ({ if((version)==KEY_FORMAT_3_6) \397397- REISERFS_I(inode)->i_flags |= i_item_key_version_mask; \398398- else \399399- REISERFS_I(inode)->i_flags &= ~i_item_key_version_mask; })400400-401401-#define get_inode_sd_version(inode) \402402- ((REISERFS_I(inode)->i_flags & i_stat_data_version_mask) ? STAT_DATA_V2 : STAT_DATA_V1)403403-404404-#define set_inode_sd_version(inode, version) \405405- ({ if((version)==STAT_DATA_V2) \406406- REISERFS_I(inode)->i_flags |= i_stat_data_version_mask; \407407- else \408408- REISERFS_I(inode)->i_flags &= ~i_stat_data_version_mask; })409409-410410-/* This is an aggressive tail suppression policy, I am hoping it411411- improves our benchmarks. The principle behind it is that percentage412412- space saving is what matters, not absolute space saving. This is413413- non-intuitive, but it helps to understand it if you consider that the414414- cost to access 4 blocks is not much more than the cost to access 1415415- block, if you have to do a seek and rotate. A tail risks a416416- non-linear disk access that is significant as a percentage of total417417- time cost for a 4 block file and saves an amount of space that is418418- less significant as a percentage of space, or so goes the hypothesis.419419- -Hans */420420-#define STORE_TAIL_IN_UNFM_S1(n_file_size,n_tail_size,n_block_size) \421421-(\422422- (!(n_tail_size)) || \423423- (((n_tail_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) || \424424- ( (n_file_size) >= (n_block_size) * 4 ) || \425425- ( ( (n_file_size) >= (n_block_size) * 3 ) && \426426- ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size))/4) ) || \427427- ( ( (n_file_size) >= (n_block_size) * 2 ) && \428428- ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size))/2) ) || \429429- ( ( (n_file_size) >= (n_block_size) ) && \430430- ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size) * 3)/4) ) ) \431431-)432432-433433-/* Another strategy for tails, this one means only create a tail if all the434434- file would fit into one DIRECT item.435435- Primary intention for this one is to increase performance by decreasing436436- seeking.437437-*/438438-#define STORE_TAIL_IN_UNFM_S2(n_file_size,n_tail_size,n_block_size) \439439-(\440440- (!(n_tail_size)) || \441441- (((n_file_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) ) \442442-)443443-444444-/*445445- * values for s_umount_state field446446- */447447-#define REISERFS_VALID_FS 1448448-#define REISERFS_ERROR_FS 2449449-450450-//451451-// there are 5 item types currently452452-//453453-#define TYPE_STAT_DATA 0454454-#define TYPE_INDIRECT 1455455-#define TYPE_DIRECT 2456456-#define TYPE_DIRENTRY 3457457-#define TYPE_MAXTYPE 3458458-#define TYPE_ANY 15 // FIXME: comment is required459459-460460-/***************************************************************************/461461-/* KEY & ITEM HEAD */462462-/***************************************************************************/463463-464464-//465465-// directories use this key as well as old files466466-//467467-struct offset_v1 {468468- __le32 k_offset;469469- __le32 k_uniqueness;470470-} __attribute__ ((__packed__));471471-472472-struct offset_v2 {473473- __le64 v;474474-} __attribute__ ((__packed__));475475-476476-static inline __u16 offset_v2_k_type(const struct offset_v2 *v2)477477-{478478- __u8 type = le64_to_cpu(v2->v) >> 60;479479- return (type <= TYPE_MAXTYPE) ? type : TYPE_ANY;480480-}481481-482482-static inline void set_offset_v2_k_type(struct offset_v2 *v2, int type)483483-{484484- v2->v =485485- (v2->v & cpu_to_le64(~0ULL >> 4)) | cpu_to_le64((__u64) type << 60);486486-}487487-488488-static inline loff_t offset_v2_k_offset(const struct offset_v2 *v2)489489-{490490- return le64_to_cpu(v2->v) & (~0ULL >> 4);491491-}492492-493493-static inline void set_offset_v2_k_offset(struct offset_v2 *v2, loff_t offset)494494-{495495- offset &= (~0ULL >> 4);496496- v2->v = (v2->v & cpu_to_le64(15ULL << 60)) | cpu_to_le64(offset);497497-}498498-499499-/* Key of an item determines its location in the S+tree, and500500- is composed of 4 components */501501-struct reiserfs_key {502502- __le32 k_dir_id; /* packing locality: by default parent503503- directory object id */504504- __le32 k_objectid; /* object identifier */505505- union {506506- struct offset_v1 k_offset_v1;507507- struct offset_v2 k_offset_v2;508508- } __attribute__ ((__packed__)) u;509509-} __attribute__ ((__packed__));510510-511511-struct in_core_key {512512- __u32 k_dir_id; /* packing locality: by default parent513513- directory object id */514514- __u32 k_objectid; /* object identifier */515515- __u64 k_offset;516516- __u8 k_type;517517-};518518-519519-struct cpu_key {520520- struct in_core_key on_disk_key;521521- int version;522522- int key_length; /* 3 in all cases but direct2indirect and523523- indirect2direct conversion */524524-};525525-526526-/* Our function for comparing keys can compare keys of different527527- lengths. It takes as a parameter the length of the keys it is to528528- compare. These defines are used in determining what is to be passed529529- to it as that parameter. */530530-#define REISERFS_FULL_KEY_LEN 4531531-#define REISERFS_SHORT_KEY_LEN 2532532-533533-/* The result of the key compare */534534-#define FIRST_GREATER 1535535-#define SECOND_GREATER -1536536-#define KEYS_IDENTICAL 0537537-#define KEY_FOUND 1538538-#define KEY_NOT_FOUND 0539539-540540-#define KEY_SIZE (sizeof(struct reiserfs_key))541541-#define SHORT_KEY_SIZE (sizeof (__u32) + sizeof (__u32))542542-543543-/* return values for search_by_key and clones */544544-#define ITEM_FOUND 1545545-#define ITEM_NOT_FOUND 0546546-#define ENTRY_FOUND 1547547-#define ENTRY_NOT_FOUND 0548548-#define DIRECTORY_NOT_FOUND -1549549-#define REGULAR_FILE_FOUND -2550550-#define DIRECTORY_FOUND -3551551-#define BYTE_FOUND 1552552-#define BYTE_NOT_FOUND 0553553-#define FILE_NOT_FOUND -1554554-555555-#define POSITION_FOUND 1556556-#define POSITION_NOT_FOUND 0557557-558558-// return values for reiserfs_find_entry and search_by_entry_key559559-#define NAME_FOUND 1560560-#define NAME_NOT_FOUND 0561561-#define GOTO_PREVIOUS_ITEM 2562562-#define NAME_FOUND_INVISIBLE 3563563-564564-/* Everything in the filesystem is stored as a set of items. The565565- item head contains the key of the item, its free space (for566566- indirect items) and specifies the location of the item itself567567- within the block. */568568-569569-struct item_head {570570- /* Everything in the tree is found by searching for it based on571571- * its key.*/572572- struct reiserfs_key ih_key;573573- union {574574- /* The free space in the last unformatted node of an575575- indirect item if this is an indirect item. This576576- equals 0xFFFF iff this is a direct item or stat data577577- item. Note that the key, not this field, is used to578578- determine the item type, and thus which field this579579- union contains. */580580- __le16 ih_free_space_reserved;581581- /* Iff this is a directory item, this field equals the582582- number of directory entries in the directory item. */583583- __le16 ih_entry_count;584584- } __attribute__ ((__packed__)) u;585585- __le16 ih_item_len; /* total size of the item body */586586- __le16 ih_item_location; /* an offset to the item body587587- * within the block */588588- __le16 ih_version; /* 0 for all old items, 2 for new589589- ones. Highest bit is set by fsck590590- temporary, cleaned after all591591- done */592592-} __attribute__ ((__packed__));593593-/* size of item header */594594-#define IH_SIZE (sizeof(struct item_head))595595-596596-#define ih_free_space(ih) le16_to_cpu((ih)->u.ih_free_space_reserved)597597-#define ih_version(ih) le16_to_cpu((ih)->ih_version)598598-#define ih_entry_count(ih) le16_to_cpu((ih)->u.ih_entry_count)599599-#define ih_location(ih) le16_to_cpu((ih)->ih_item_location)600600-#define ih_item_len(ih) le16_to_cpu((ih)->ih_item_len)601601-602602-#define put_ih_free_space(ih, val) do { (ih)->u.ih_free_space_reserved = cpu_to_le16(val); } while(0)603603-#define put_ih_version(ih, val) do { (ih)->ih_version = cpu_to_le16(val); } while (0)604604-#define put_ih_entry_count(ih, val) do { (ih)->u.ih_entry_count = cpu_to_le16(val); } while (0)605605-#define put_ih_location(ih, val) do { (ih)->ih_item_location = cpu_to_le16(val); } while (0)606606-#define put_ih_item_len(ih, val) do { (ih)->ih_item_len = cpu_to_le16(val); } while (0)607607-608608-#define unreachable_item(ih) (ih_version(ih) & (1 << 15))609609-610610-#define get_ih_free_space(ih) (ih_version (ih) == KEY_FORMAT_3_6 ? 0 : ih_free_space (ih))611611-#define set_ih_free_space(ih,val) put_ih_free_space((ih), ((ih_version(ih) == KEY_FORMAT_3_6) ? 0 : (val)))612612-613613-/* these operate on indirect items, where you've got an array of ints614614-** at a possibly unaligned location. These are a noop on ia32615615-** 616616-** p is the array of __u32, i is the index into the array, v is the value617617-** to store there.618618-*/619619-#define get_block_num(p, i) get_unaligned_le32((p) + (i))620620-#define put_block_num(p, i, v) put_unaligned_le32((v), (p) + (i))621621-622622-//623623-// in old version uniqueness field shows key type624624-//625625-#define V1_SD_UNIQUENESS 0626626-#define V1_INDIRECT_UNIQUENESS 0xfffffffe627627-#define V1_DIRECT_UNIQUENESS 0xffffffff628628-#define V1_DIRENTRY_UNIQUENESS 500629629-#define V1_ANY_UNIQUENESS 555 // FIXME: comment is required630630-631631-//632632-// here are conversion routines633633-//634634-static inline int uniqueness2type(__u32 uniqueness) CONSTF;635635-static inline int uniqueness2type(__u32 uniqueness)636636-{637637- switch ((int)uniqueness) {638638- case V1_SD_UNIQUENESS:639639- return TYPE_STAT_DATA;640640- case V1_INDIRECT_UNIQUENESS:641641- return TYPE_INDIRECT;642642- case V1_DIRECT_UNIQUENESS:643643- return TYPE_DIRECT;644644- case V1_DIRENTRY_UNIQUENESS:645645- return TYPE_DIRENTRY;646646- case V1_ANY_UNIQUENESS:647647- default:648648- return TYPE_ANY;649649- }650650-}651651-652652-static inline __u32 type2uniqueness(int type) CONSTF;653653-static inline __u32 type2uniqueness(int type)654654-{655655- switch (type) {656656- case TYPE_STAT_DATA:657657- return V1_SD_UNIQUENESS;658658- case TYPE_INDIRECT:659659- return V1_INDIRECT_UNIQUENESS;660660- case TYPE_DIRECT:661661- return V1_DIRECT_UNIQUENESS;662662- case TYPE_DIRENTRY:663663- return V1_DIRENTRY_UNIQUENESS;664664- case TYPE_ANY:665665- default:666666- return V1_ANY_UNIQUENESS;667667- }668668-}669669-670670-//671671-// key is pointer to on disk key which is stored in le, result is cpu,672672-// there is no way to get version of object from key, so, provide673673-// version to these defines674674-//675675-static inline loff_t le_key_k_offset(int version,676676- const struct reiserfs_key *key)677677-{678678- return (version == KEY_FORMAT_3_5) ?679679- le32_to_cpu(key->u.k_offset_v1.k_offset) :680680- offset_v2_k_offset(&(key->u.k_offset_v2));681681-}682682-683683-static inline loff_t le_ih_k_offset(const struct item_head *ih)684684-{685685- return le_key_k_offset(ih_version(ih), &(ih->ih_key));686686-}687687-688688-static inline loff_t le_key_k_type(int version, const struct reiserfs_key *key)689689-{690690- return (version == KEY_FORMAT_3_5) ?691691- uniqueness2type(le32_to_cpu(key->u.k_offset_v1.k_uniqueness)) :692692- offset_v2_k_type(&(key->u.k_offset_v2));693693-}694694-695695-static inline loff_t le_ih_k_type(const struct item_head *ih)696696-{697697- return le_key_k_type(ih_version(ih), &(ih->ih_key));698698-}699699-700700-static inline void set_le_key_k_offset(int version, struct reiserfs_key *key,701701- loff_t offset)702702-{703703- (version == KEY_FORMAT_3_5) ? (void)(key->u.k_offset_v1.k_offset = cpu_to_le32(offset)) : /* jdm check */704704- (void)(set_offset_v2_k_offset(&(key->u.k_offset_v2), offset));705705-}706706-707707-static inline void set_le_ih_k_offset(struct item_head *ih, loff_t offset)708708-{709709- set_le_key_k_offset(ih_version(ih), &(ih->ih_key), offset);710710-}711711-712712-static inline void set_le_key_k_type(int version, struct reiserfs_key *key,713713- int type)714714-{715715- (version == KEY_FORMAT_3_5) ?716716- (void)(key->u.k_offset_v1.k_uniqueness =717717- cpu_to_le32(type2uniqueness(type)))718718- : (void)(set_offset_v2_k_type(&(key->u.k_offset_v2), type));719719-}720720-721721-static inline void set_le_ih_k_type(struct item_head *ih, int type)722722-{723723- set_le_key_k_type(ih_version(ih), &(ih->ih_key), type);724724-}725725-726726-static inline int is_direntry_le_key(int version, struct reiserfs_key *key)727727-{728728- return le_key_k_type(version, key) == TYPE_DIRENTRY;729729-}730730-731731-static inline int is_direct_le_key(int version, struct reiserfs_key *key)732732-{733733- return le_key_k_type(version, key) == TYPE_DIRECT;734734-}735735-736736-static inline int is_indirect_le_key(int version, struct reiserfs_key *key)737737-{738738- return le_key_k_type(version, key) == TYPE_INDIRECT;739739-}740740-741741-static inline int is_statdata_le_key(int version, struct reiserfs_key *key)742742-{743743- return le_key_k_type(version, key) == TYPE_STAT_DATA;744744-}745745-746746-//747747-// item header has version.748748-//749749-static inline int is_direntry_le_ih(struct item_head *ih)750750-{751751- return is_direntry_le_key(ih_version(ih), &ih->ih_key);752752-}753753-754754-static inline int is_direct_le_ih(struct item_head *ih)755755-{756756- return is_direct_le_key(ih_version(ih), &ih->ih_key);757757-}758758-759759-static inline int is_indirect_le_ih(struct item_head *ih)760760-{761761- return is_indirect_le_key(ih_version(ih), &ih->ih_key);762762-}763763-764764-static inline int is_statdata_le_ih(struct item_head *ih)765765-{766766- return is_statdata_le_key(ih_version(ih), &ih->ih_key);767767-}768768-769769-//770770-// key is pointer to cpu key, result is cpu771771-//772772-static inline loff_t cpu_key_k_offset(const struct cpu_key *key)773773-{774774- return key->on_disk_key.k_offset;775775-}776776-777777-static inline loff_t cpu_key_k_type(const struct cpu_key *key)778778-{779779- return key->on_disk_key.k_type;780780-}781781-782782-static inline void set_cpu_key_k_offset(struct cpu_key *key, loff_t offset)783783-{784784- key->on_disk_key.k_offset = offset;785785-}786786-787787-static inline void set_cpu_key_k_type(struct cpu_key *key, int type)788788-{789789- key->on_disk_key.k_type = type;790790-}791791-792792-static inline void cpu_key_k_offset_dec(struct cpu_key *key)793793-{794794- key->on_disk_key.k_offset--;795795-}796796-797797-#define is_direntry_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRENTRY)798798-#define is_direct_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRECT)799799-#define is_indirect_cpu_key(key) (cpu_key_k_type (key) == TYPE_INDIRECT)800800-#define is_statdata_cpu_key(key) (cpu_key_k_type (key) == TYPE_STAT_DATA)801801-802802-/* are these used ? */803803-#define is_direntry_cpu_ih(ih) (is_direntry_cpu_key (&((ih)->ih_key)))804804-#define is_direct_cpu_ih(ih) (is_direct_cpu_key (&((ih)->ih_key)))805805-#define is_indirect_cpu_ih(ih) (is_indirect_cpu_key (&((ih)->ih_key)))806806-#define is_statdata_cpu_ih(ih) (is_statdata_cpu_key (&((ih)->ih_key)))807807-808808-#define I_K_KEY_IN_ITEM(ih, key, n_blocksize) \809809- (!COMP_SHORT_KEYS(ih, key) && \810810- I_OFF_BYTE_IN_ITEM(ih, k_offset(key), n_blocksize))811811-812812-/* maximal length of item */813813-#define MAX_ITEM_LEN(block_size) (block_size - BLKH_SIZE - IH_SIZE)814814-#define MIN_ITEM_LEN 1815815-816816-/* object identifier for root dir */817817-#define REISERFS_ROOT_OBJECTID 2818818-#define REISERFS_ROOT_PARENT_OBJECTID 1819819-820820-extern struct reiserfs_key root_key;821821-822822-/* 823823- * Picture represents a leaf of the S+tree824824- * ______________________________________________________825825- * | | Array of | | |826826- * |Block | Object-Item | F r e e | Objects- |827827- * | head | Headers | S p a c e | Items |828828- * |______|_______________|___________________|___________|829829- */830830-831831-/* Header of a disk block. More precisely, header of a formatted leaf832832- or internal node, and not the header of an unformatted node. */833833-struct block_head {834834- __le16 blk_level; /* Level of a block in the tree. */835835- __le16 blk_nr_item; /* Number of keys/items in a block. */836836- __le16 blk_free_space; /* Block free space in bytes. */837837- __le16 blk_reserved;838838- /* dump this in v4/planA */839839- struct reiserfs_key blk_right_delim_key; /* kept only for compatibility */840840-};841841-842842-#define BLKH_SIZE (sizeof(struct block_head))843843-#define blkh_level(p_blkh) (le16_to_cpu((p_blkh)->blk_level))844844-#define blkh_nr_item(p_blkh) (le16_to_cpu((p_blkh)->blk_nr_item))845845-#define blkh_free_space(p_blkh) (le16_to_cpu((p_blkh)->blk_free_space))846846-#define blkh_reserved(p_blkh) (le16_to_cpu((p_blkh)->blk_reserved))847847-#define set_blkh_level(p_blkh,val) ((p_blkh)->blk_level = cpu_to_le16(val))848848-#define set_blkh_nr_item(p_blkh,val) ((p_blkh)->blk_nr_item = cpu_to_le16(val))849849-#define set_blkh_free_space(p_blkh,val) ((p_blkh)->blk_free_space = cpu_to_le16(val))850850-#define set_blkh_reserved(p_blkh,val) ((p_blkh)->blk_reserved = cpu_to_le16(val))851851-#define blkh_right_delim_key(p_blkh) ((p_blkh)->blk_right_delim_key)852852-#define set_blkh_right_delim_key(p_blkh,val) ((p_blkh)->blk_right_delim_key = val)853853-854854-/*855855- * values for blk_level field of the struct block_head856856- */857857-858858-#define FREE_LEVEL 0 /* when node gets removed from the tree its859859- blk_level is set to FREE_LEVEL. It is then860860- used to see whether the node is still in the861861- tree */862862-863863-#define DISK_LEAF_NODE_LEVEL 1 /* Leaf node level. */864864-865865-/* Given the buffer head of a formatted node, resolve to the block head of that node. */866866-#define B_BLK_HEAD(bh) ((struct block_head *)((bh)->b_data))867867-/* Number of items that are in buffer. */868868-#define B_NR_ITEMS(bh) (blkh_nr_item(B_BLK_HEAD(bh)))869869-#define B_LEVEL(bh) (blkh_level(B_BLK_HEAD(bh)))870870-#define B_FREE_SPACE(bh) (blkh_free_space(B_BLK_HEAD(bh)))871871-872872-#define PUT_B_NR_ITEMS(bh, val) do { set_blkh_nr_item(B_BLK_HEAD(bh), val); } while (0)873873-#define PUT_B_LEVEL(bh, val) do { set_blkh_level(B_BLK_HEAD(bh), val); } while (0)874874-#define PUT_B_FREE_SPACE(bh, val) do { set_blkh_free_space(B_BLK_HEAD(bh), val); } while (0)875875-876876-/* Get right delimiting key. -- little endian */877877-#define B_PRIGHT_DELIM_KEY(bh) (&(blk_right_delim_key(B_BLK_HEAD(bh))))878878-879879-/* Does the buffer contain a disk leaf. */880880-#define B_IS_ITEMS_LEVEL(bh) (B_LEVEL(bh) == DISK_LEAF_NODE_LEVEL)881881-882882-/* Does the buffer contain a disk internal node */883883-#define B_IS_KEYS_LEVEL(bh) (B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL \884884- && B_LEVEL(bh) <= MAX_HEIGHT)885885-886886-/***************************************************************************/887887-/* STAT DATA */888888-/***************************************************************************/889889-890890-//891891-// old stat data is 32 bytes long. We are going to distinguish new one by892892-// different size893893-//894894-struct stat_data_v1 {895895- __le16 sd_mode; /* file type, permissions */896896- __le16 sd_nlink; /* number of hard links */897897- __le16 sd_uid; /* owner */898898- __le16 sd_gid; /* group */899899- __le32 sd_size; /* file size */900900- __le32 sd_atime; /* time of last access */901901- __le32 sd_mtime; /* time file was last modified */902902- __le32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */903903- union {904904- __le32 sd_rdev;905905- __le32 sd_blocks; /* number of blocks file uses */906906- } __attribute__ ((__packed__)) u;907907- __le32 sd_first_direct_byte; /* first byte of file which is stored908908- in a direct item: except that if it909909- equals 1 it is a symlink and if it910910- equals ~(__u32)0 there is no911911- direct item. The existence of this912912- field really grates on me. Let's913913- replace it with a macro based on914914- sd_size and our tail suppression915915- policy. Someday. -Hans */916916-} __attribute__ ((__packed__));917917-918918-#define SD_V1_SIZE (sizeof(struct stat_data_v1))919919-#define stat_data_v1(ih) (ih_version (ih) == KEY_FORMAT_3_5)920920-#define sd_v1_mode(sdp) (le16_to_cpu((sdp)->sd_mode))921921-#define set_sd_v1_mode(sdp,v) ((sdp)->sd_mode = cpu_to_le16(v))922922-#define sd_v1_nlink(sdp) (le16_to_cpu((sdp)->sd_nlink))923923-#define set_sd_v1_nlink(sdp,v) ((sdp)->sd_nlink = cpu_to_le16(v))924924-#define sd_v1_uid(sdp) (le16_to_cpu((sdp)->sd_uid))925925-#define set_sd_v1_uid(sdp,v) ((sdp)->sd_uid = cpu_to_le16(v))926926-#define sd_v1_gid(sdp) (le16_to_cpu((sdp)->sd_gid))927927-#define set_sd_v1_gid(sdp,v) ((sdp)->sd_gid = cpu_to_le16(v))928928-#define sd_v1_size(sdp) (le32_to_cpu((sdp)->sd_size))929929-#define set_sd_v1_size(sdp,v) ((sdp)->sd_size = cpu_to_le32(v))930930-#define sd_v1_atime(sdp) (le32_to_cpu((sdp)->sd_atime))931931-#define set_sd_v1_atime(sdp,v) ((sdp)->sd_atime = cpu_to_le32(v))932932-#define sd_v1_mtime(sdp) (le32_to_cpu((sdp)->sd_mtime))933933-#define set_sd_v1_mtime(sdp,v) ((sdp)->sd_mtime = cpu_to_le32(v))934934-#define sd_v1_ctime(sdp) (le32_to_cpu((sdp)->sd_ctime))935935-#define set_sd_v1_ctime(sdp,v) ((sdp)->sd_ctime = cpu_to_le32(v))936936-#define sd_v1_rdev(sdp) (le32_to_cpu((sdp)->u.sd_rdev))937937-#define set_sd_v1_rdev(sdp,v) ((sdp)->u.sd_rdev = cpu_to_le32(v))938938-#define sd_v1_blocks(sdp) (le32_to_cpu((sdp)->u.sd_blocks))939939-#define set_sd_v1_blocks(sdp,v) ((sdp)->u.sd_blocks = cpu_to_le32(v))940940-#define sd_v1_first_direct_byte(sdp) \941941- (le32_to_cpu((sdp)->sd_first_direct_byte))942942-#define set_sd_v1_first_direct_byte(sdp,v) \943943- ((sdp)->sd_first_direct_byte = cpu_to_le32(v))944944-945945-/* inode flags stored in sd_attrs (nee sd_reserved) */946946-947947-/* we want common flags to have the same values as in ext2,948948- so chattr(1) will work without problems */949949-#define REISERFS_IMMUTABLE_FL FS_IMMUTABLE_FL950950-#define REISERFS_APPEND_FL FS_APPEND_FL951951-#define REISERFS_SYNC_FL FS_SYNC_FL952952-#define REISERFS_NOATIME_FL FS_NOATIME_FL953953-#define REISERFS_NODUMP_FL FS_NODUMP_FL954954-#define REISERFS_SECRM_FL FS_SECRM_FL955955-#define REISERFS_UNRM_FL FS_UNRM_FL956956-#define REISERFS_COMPR_FL FS_COMPR_FL957957-#define REISERFS_NOTAIL_FL FS_NOTAIL_FL958958-959959-/* persistent flags that file inherits from the parent directory */960960-#define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL | \961961- REISERFS_SYNC_FL | \962962- REISERFS_NOATIME_FL | \963963- REISERFS_NODUMP_FL | \964964- REISERFS_SECRM_FL | \965965- REISERFS_COMPR_FL | \966966- REISERFS_NOTAIL_FL )967967-968968-/* Stat Data on disk (reiserfs version of UFS disk inode minus the969969- address blocks) */970970-struct stat_data {971971- __le16 sd_mode; /* file type, permissions */972972- __le16 sd_attrs; /* persistent inode flags */973973- __le32 sd_nlink; /* number of hard links */974974- __le64 sd_size; /* file size */975975- __le32 sd_uid; /* owner */976976- __le32 sd_gid; /* group */977977- __le32 sd_atime; /* time of last access */978978- __le32 sd_mtime; /* time file was last modified */979979- __le32 sd_ctime; /* time inode (stat data) was last changed (except changes to sd_atime and sd_mtime) */980980- __le32 sd_blocks;981981- union {982982- __le32 sd_rdev;983983- __le32 sd_generation;984984- //__le32 sd_first_direct_byte;985985- /* first byte of file which is stored in a986986- direct item: except that if it equals 1987987- it is a symlink and if it equals988988- ~(__u32)0 there is no direct item. The989989- existence of this field really grates990990- on me. Let's replace it with a macro991991- based on sd_size and our tail992992- suppression policy? */993993- } __attribute__ ((__packed__)) u;994994-} __attribute__ ((__packed__));995995-//996996-// this is 44 bytes long997997-//998998-#define SD_SIZE (sizeof(struct stat_data))999999-#define SD_V2_SIZE SD_SIZE10001000-#define stat_data_v2(ih) (ih_version (ih) == KEY_FORMAT_3_6)10011001-#define sd_v2_mode(sdp) (le16_to_cpu((sdp)->sd_mode))10021002-#define set_sd_v2_mode(sdp,v) ((sdp)->sd_mode = cpu_to_le16(v))10031003-/* sd_reserved */10041004-/* set_sd_reserved */10051005-#define sd_v2_nlink(sdp) (le32_to_cpu((sdp)->sd_nlink))10061006-#define set_sd_v2_nlink(sdp,v) ((sdp)->sd_nlink = cpu_to_le32(v))10071007-#define sd_v2_size(sdp) (le64_to_cpu((sdp)->sd_size))10081008-#define set_sd_v2_size(sdp,v) ((sdp)->sd_size = cpu_to_le64(v))10091009-#define sd_v2_uid(sdp) (le32_to_cpu((sdp)->sd_uid))10101010-#define set_sd_v2_uid(sdp,v) ((sdp)->sd_uid = cpu_to_le32(v))10111011-#define sd_v2_gid(sdp) (le32_to_cpu((sdp)->sd_gid))10121012-#define set_sd_v2_gid(sdp,v) ((sdp)->sd_gid = cpu_to_le32(v))10131013-#define sd_v2_atime(sdp) (le32_to_cpu((sdp)->sd_atime))10141014-#define set_sd_v2_atime(sdp,v) ((sdp)->sd_atime = cpu_to_le32(v))10151015-#define sd_v2_mtime(sdp) (le32_to_cpu((sdp)->sd_mtime))10161016-#define set_sd_v2_mtime(sdp,v) ((sdp)->sd_mtime = cpu_to_le32(v))10171017-#define sd_v2_ctime(sdp) (le32_to_cpu((sdp)->sd_ctime))10181018-#define set_sd_v2_ctime(sdp,v) ((sdp)->sd_ctime = cpu_to_le32(v))10191019-#define sd_v2_blocks(sdp) (le32_to_cpu((sdp)->sd_blocks))10201020-#define set_sd_v2_blocks(sdp,v) ((sdp)->sd_blocks = cpu_to_le32(v))10211021-#define sd_v2_rdev(sdp) (le32_to_cpu((sdp)->u.sd_rdev))10221022-#define set_sd_v2_rdev(sdp,v) ((sdp)->u.sd_rdev = cpu_to_le32(v))10231023-#define sd_v2_generation(sdp) (le32_to_cpu((sdp)->u.sd_generation))10241024-#define set_sd_v2_generation(sdp,v) ((sdp)->u.sd_generation = cpu_to_le32(v))10251025-#define sd_v2_attrs(sdp) (le16_to_cpu((sdp)->sd_attrs))10261026-#define set_sd_v2_attrs(sdp,v) ((sdp)->sd_attrs = cpu_to_le16(v))10271027-10281028-/***************************************************************************/10291029-/* DIRECTORY STRUCTURE */10301030-/***************************************************************************/10311031-/* 10321032- Picture represents the structure of directory items10331033- ________________________________________________10341034- | Array of | | | | | |10351035- | directory |N-1| N-2 | .... | 1st |0th|10361036- | entry headers | | | | | |10371037- |_______________|___|_____|________|_______|___|10381038- <---- directory entries ------>10391039-10401040- First directory item has k_offset component 1. We store "." and ".."10411041- in one item, always, we never split "." and ".." into differing10421042- items. This makes, among other things, the code for removing10431043- directories simpler. */10441044-#define SD_OFFSET 010451045-#define SD_UNIQUENESS 010461046-#define DOT_OFFSET 110471047-#define DOT_DOT_OFFSET 210481048-#define DIRENTRY_UNIQUENESS 50010491049-10501050-/* */10511051-#define FIRST_ITEM_OFFSET 110521052-10531053-/*10541054- Q: How to get key of object pointed to by entry from entry? 10551055-10561056- A: Each directory entry has its header. This header has deh_dir_id and deh_objectid fields, those are key10571057- of object, entry points to */10581058-10591059-/* NOT IMPLEMENTED: 10601060- Directory will someday contain stat data of object */10611061-10621062-struct reiserfs_de_head {10631063- __le32 deh_offset; /* third component of the directory entry key */10641064- __le32 deh_dir_id; /* objectid of the parent directory of the object, that is referenced10651065- by directory entry */10661066- __le32 deh_objectid; /* objectid of the object, that is referenced by directory entry */10671067- __le16 deh_location; /* offset of name in the whole item */10681068- __le16 deh_state; /* whether 1) entry contains stat data (for future), and 2) whether10691069- entry is hidden (unlinked) */10701070-} __attribute__ ((__packed__));10711071-#define DEH_SIZE sizeof(struct reiserfs_de_head)10721072-#define deh_offset(p_deh) (le32_to_cpu((p_deh)->deh_offset))10731073-#define deh_dir_id(p_deh) (le32_to_cpu((p_deh)->deh_dir_id))10741074-#define deh_objectid(p_deh) (le32_to_cpu((p_deh)->deh_objectid))10751075-#define deh_location(p_deh) (le16_to_cpu((p_deh)->deh_location))10761076-#define deh_state(p_deh) (le16_to_cpu((p_deh)->deh_state))10771077-10781078-#define put_deh_offset(p_deh,v) ((p_deh)->deh_offset = cpu_to_le32((v)))10791079-#define put_deh_dir_id(p_deh,v) ((p_deh)->deh_dir_id = cpu_to_le32((v)))10801080-#define put_deh_objectid(p_deh,v) ((p_deh)->deh_objectid = cpu_to_le32((v)))10811081-#define put_deh_location(p_deh,v) ((p_deh)->deh_location = cpu_to_le16((v)))10821082-#define put_deh_state(p_deh,v) ((p_deh)->deh_state = cpu_to_le16((v)))10831083-10841084-/* empty directory contains two entries "." and ".." and their headers */10851085-#define EMPTY_DIR_SIZE \10861086-(DEH_SIZE * 2 + ROUND_UP (strlen (".")) + ROUND_UP (strlen ("..")))10871087-10881088-/* old format directories have this size when empty */10891089-#define EMPTY_DIR_SIZE_V1 (DEH_SIZE * 2 + 3)10901090-10911091-#define DEH_Statdata 0 /* not used now */10921092-#define DEH_Visible 210931093-10941094-/* 64 bit systems (and the S/390) need to be aligned explicitly -jdm */10951095-#if BITS_PER_LONG == 64 || defined(__s390__) || defined(__hppa__)10961096-# define ADDR_UNALIGNED_BITS (3)10971097-#endif10981098-10991099-/* These are only used to manipulate deh_state.11001100- * Because of this, we'll use the ext2_ bit routines,11011101- * since they are little endian */11021102-#ifdef ADDR_UNALIGNED_BITS11031103-11041104-# define aligned_address(addr) ((void *)((long)(addr) & ~((1UL << ADDR_UNALIGNED_BITS) - 1)))11051105-# define unaligned_offset(addr) (((int)((long)(addr) & ((1 << ADDR_UNALIGNED_BITS) - 1))) << 3)11061106-11071107-# define set_bit_unaligned(nr, addr) \11081108- __test_and_set_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))11091109-# define clear_bit_unaligned(nr, addr) \11101110- __test_and_clear_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))11111111-# define test_bit_unaligned(nr, addr) \11121112- test_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))11131113-11141114-#else11151115-11161116-# define set_bit_unaligned(nr, addr) __test_and_set_bit_le(nr, addr)11171117-# define clear_bit_unaligned(nr, addr) __test_and_clear_bit_le(nr, addr)11181118-# define test_bit_unaligned(nr, addr) test_bit_le(nr, addr)11191119-11201120-#endif11211121-11221122-#define mark_de_with_sd(deh) set_bit_unaligned (DEH_Statdata, &((deh)->deh_state))11231123-#define mark_de_without_sd(deh) clear_bit_unaligned (DEH_Statdata, &((deh)->deh_state))11241124-#define mark_de_visible(deh) set_bit_unaligned (DEH_Visible, &((deh)->deh_state))11251125-#define mark_de_hidden(deh) clear_bit_unaligned (DEH_Visible, &((deh)->deh_state))11261126-11271127-#define de_with_sd(deh) test_bit_unaligned (DEH_Statdata, &((deh)->deh_state))11281128-#define de_visible(deh) test_bit_unaligned (DEH_Visible, &((deh)->deh_state))11291129-#define de_hidden(deh) !test_bit_unaligned (DEH_Visible, &((deh)->deh_state))11301130-11311131-extern void make_empty_dir_item_v1(char *body, __le32 dirid, __le32 objid,11321132- __le32 par_dirid, __le32 par_objid);11331133-extern void make_empty_dir_item(char *body, __le32 dirid, __le32 objid,11341134- __le32 par_dirid, __le32 par_objid);11351135-11361136-/* array of the entry headers */11371137- /* get item body */11381138-#define B_I_PITEM(bh,ih) ( (bh)->b_data + ih_location(ih) )11391139-#define B_I_DEH(bh,ih) ((struct reiserfs_de_head *)(B_I_PITEM(bh,ih)))11401140-11411141-/* length of the directory entry in directory item. This define11421142- calculates length of i-th directory entry using directory entry11431143- locations from dir entry head. When it calculates length of 0-th11441144- directory entry, it uses length of whole item in place of entry11451145- location of the non-existent following entry in the calculation.11461146- See picture above.*/11471147-/*11481148-#define I_DEH_N_ENTRY_LENGTH(ih,deh,i) \11491149-((i) ? (deh_location((deh)-1) - deh_location((deh))) : (ih_item_len((ih)) - deh_location((deh))))11501150-*/11511151-static inline int entry_length(const struct buffer_head *bh,11521152- const struct item_head *ih, int pos_in_item)11531153-{11541154- struct reiserfs_de_head *deh;11551155-11561156- deh = B_I_DEH(bh, ih) + pos_in_item;11571157- if (pos_in_item)11581158- return deh_location(deh - 1) - deh_location(deh);11591159-11601160- return ih_item_len(ih) - deh_location(deh);11611161-}11621162-11631163-/* number of entries in the directory item, depends on ENTRY_COUNT being at the start of directory dynamic data. */11641164-#define I_ENTRY_COUNT(ih) (ih_entry_count((ih)))11651165-11661166-/* name by bh, ih and entry_num */11671167-#define B_I_E_NAME(bh,ih,entry_num) ((char *)(bh->b_data + ih_location(ih) + deh_location(B_I_DEH(bh,ih)+(entry_num))))11681168-11691169-// two entries per block (at least)11701170-#define REISERFS_MAX_NAME(block_size) 25511711171-11721172-/* this structure is used for operations on directory entries. It is11731173- not a disk structure. */11741174-/* When reiserfs_find_entry or search_by_entry_key find directory11751175- entry, they return filled reiserfs_dir_entry structure */11761176-struct reiserfs_dir_entry {11771177- struct buffer_head *de_bh;11781178- int de_item_num;11791179- struct item_head *de_ih;11801180- int de_entry_num;11811181- struct reiserfs_de_head *de_deh;11821182- int de_entrylen;11831183- int de_namelen;11841184- char *de_name;11851185- unsigned long *de_gen_number_bit_string;11861186-11871187- __u32 de_dir_id;11881188- __u32 de_objectid;11891189-11901190- struct cpu_key de_entry_key;11911191-};11921192-11931193-/* these defines are useful when a particular member of a reiserfs_dir_entry is needed */11941194-11951195-/* pointer to file name, stored in entry */11961196-#define B_I_DEH_ENTRY_FILE_NAME(bh,ih,deh) (B_I_PITEM (bh, ih) + deh_location(deh))11971197-11981198-/* length of name */11991199-#define I_DEH_N_ENTRY_FILE_NAME_LENGTH(ih,deh,entry_num) \12001200-(I_DEH_N_ENTRY_LENGTH (ih, deh, entry_num) - (de_with_sd (deh) ? SD_SIZE : 0))12011201-12021202-/* hash value occupies bits from 7 up to 30 */12031203-#define GET_HASH_VALUE(offset) ((offset) & 0x7fffff80LL)12041204-/* generation number occupies 7 bits starting from 0 up to 6 */12051205-#define GET_GENERATION_NUMBER(offset) ((offset) & 0x7fLL)12061206-#define MAX_GENERATION_NUMBER 12712071207-12081208-#define SET_GENERATION_NUMBER(offset,gen_number) (GET_HASH_VALUE(offset)|(gen_number))12091209-12101210-/*12111211- * Picture represents an internal node of the reiserfs tree12121212- * ______________________________________________________12131213- * | | Array of | Array of | Free |12141214- * |block | keys | pointers | space |12151215- * | head | N | N+1 | |12161216- * |______|_______________|___________________|___________|12171217- */12181218-12191219-/***************************************************************************/12201220-/* DISK CHILD */12211221-/***************************************************************************/12221222-/* Disk child pointer: The pointer from an internal node of the tree12231223- to a node that is on disk. */12241224-struct disk_child {12251225- __le32 dc_block_number; /* Disk child's block number. */12261226- __le16 dc_size; /* Disk child's used space. */12271227- __le16 dc_reserved;12281228-};12291229-12301230-#define DC_SIZE (sizeof(struct disk_child))12311231-#define dc_block_number(dc_p) (le32_to_cpu((dc_p)->dc_block_number))12321232-#define dc_size(dc_p) (le16_to_cpu((dc_p)->dc_size))12331233-#define put_dc_block_number(dc_p, val) do { (dc_p)->dc_block_number = cpu_to_le32(val); } while(0)12341234-#define put_dc_size(dc_p, val) do { (dc_p)->dc_size = cpu_to_le16(val); } while(0)12351235-12361236-/* Get disk child by buffer header and position in the tree node. */12371237-#define B_N_CHILD(bh, n_pos) ((struct disk_child *)\12381238-((bh)->b_data + BLKH_SIZE + B_NR_ITEMS(bh) * KEY_SIZE + DC_SIZE * (n_pos)))12391239-12401240-/* Get disk child number by buffer header and position in the tree node. */12411241-#define B_N_CHILD_NUM(bh, n_pos) (dc_block_number(B_N_CHILD(bh, n_pos)))12421242-#define PUT_B_N_CHILD_NUM(bh, n_pos, val) \12431243- (put_dc_block_number(B_N_CHILD(bh, n_pos), val))12441244-12451245- /* maximal value of field child_size in structure disk_child */12461246- /* child size is the combined size of all items and their headers */12471247-#define MAX_CHILD_SIZE(bh) ((int)( (bh)->b_size - BLKH_SIZE ))12481248-12491249-/* amount of used space in buffer (not including block head) */12501250-#define B_CHILD_SIZE(cur) (MAX_CHILD_SIZE(cur)-(B_FREE_SPACE(cur)))12511251-12521252-/* max and min number of keys in internal node */12531253-#define MAX_NR_KEY(bh) ( (MAX_CHILD_SIZE(bh)-DC_SIZE)/(KEY_SIZE+DC_SIZE) )12541254-#define MIN_NR_KEY(bh) (MAX_NR_KEY(bh)/2)12551255-12561256-/***************************************************************************/12571257-/* PATH STRUCTURES AND DEFINES */12581258-/***************************************************************************/12591259-12601260-/* Search_by_key fills up the path from the root to the leaf as it descends the tree looking for the12611261- key. It uses reiserfs_bread to try to find buffers in the cache given their block number. If it12621262- does not find them in the cache it reads them from disk. For each node search_by_key finds using12631263- reiserfs_bread it then uses bin_search to look through that node. bin_search will find the12641264- position of the block_number of the next node if it is looking through an internal node. If it12651265- is looking through a leaf node bin_search will find the position of the item which has key either12661266- equal to given key, or which is the maximal key less than the given key. */12671267-12681268-struct path_element {12691269- struct buffer_head *pe_buffer; /* Pointer to the buffer at the path in the tree. */12701270- int pe_position; /* Position in the tree node which is placed in the */12711271- /* buffer above. */12721272-};12731273-12741274-#define MAX_HEIGHT 5 /* maximal height of a tree. don't change this without changing JOURNAL_PER_BALANCE_CNT */12751275-#define EXTENDED_MAX_HEIGHT 7 /* Must be equals MAX_HEIGHT + FIRST_PATH_ELEMENT_OFFSET */12761276-#define FIRST_PATH_ELEMENT_OFFSET 2 /* Must be equal to at least 2. */12771277-12781278-#define ILLEGAL_PATH_ELEMENT_OFFSET 1 /* Must be equal to FIRST_PATH_ELEMENT_OFFSET - 1 */12791279-#define MAX_FEB_SIZE 6 /* this MUST be MAX_HEIGHT + 1. See about FEB below */12801280-12811281-/* We need to keep track of who the ancestors of nodes are. When we12821282- perform a search we record which nodes were visited while12831283- descending the tree looking for the node we searched for. This list12841284- of nodes is called the path. This information is used while12851285- performing balancing. Note that this path information may become12861286- invalid, and this means we must check it when using it to see if it12871287- is still valid. You'll need to read search_by_key and the comments12881288- in it, especially about decrement_counters_in_path(), to understand12891289- this structure. 12901290-12911291-Paths make the code so much harder to work with and debug.... An12921292-enormous number of bugs are due to them, and trying to write or modify12931293-code that uses them just makes my head hurt. They are based on an12941294-excessive effort to avoid disturbing the precious VFS code.:-( The12951295-gods only know how we are going to SMP the code that uses them.12961296-znodes are the way! */12971297-12981298-#define PATH_READA 0x1 /* do read ahead */12991299-#define PATH_READA_BACK 0x2 /* read backwards */13001300-13011301-struct treepath {13021302- int path_length; /* Length of the array above. */13031303- int reada;13041304- struct path_element path_elements[EXTENDED_MAX_HEIGHT]; /* Array of the path elements. */13051305- int pos_in_item;13061306-};13071307-13081308-#define pos_in_item(path) ((path)->pos_in_item)13091309-13101310-#define INITIALIZE_PATH(var) \13111311-struct treepath var = {.path_length = ILLEGAL_PATH_ELEMENT_OFFSET, .reada = 0,}13121312-13131313-/* Get path element by path and path position. */13141314-#define PATH_OFFSET_PELEMENT(path, n_offset) ((path)->path_elements + (n_offset))13151315-13161316-/* Get buffer header at the path by path and path position. */13171317-#define PATH_OFFSET_PBUFFER(path, n_offset) (PATH_OFFSET_PELEMENT(path, n_offset)->pe_buffer)13181318-13191319-/* Get position in the element at the path by path and path position. */13201320-#define PATH_OFFSET_POSITION(path, n_offset) (PATH_OFFSET_PELEMENT(path, n_offset)->pe_position)13211321-13221322-#define PATH_PLAST_BUFFER(path) (PATH_OFFSET_PBUFFER((path), (path)->path_length))13231323- /* you know, to the person who didn't13241324- write this the macro name does not13251325- at first suggest what it does.13261326- Maybe POSITION_FROM_PATH_END? Or13271327- maybe we should just focus on13281328- dumping paths... -Hans */13291329-#define PATH_LAST_POSITION(path) (PATH_OFFSET_POSITION((path), (path)->path_length))13301330-13311331-#define PATH_PITEM_HEAD(path) B_N_PITEM_HEAD(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION(path))13321332-13331333-/* in do_balance leaf has h == 0 in contrast with path structure,13341334- where root has level == 0. That is why we need these defines */13351335-#define PATH_H_PBUFFER(path, h) PATH_OFFSET_PBUFFER (path, path->path_length - (h)) /* tb->S[h] */13361336-#define PATH_H_PPARENT(path, h) PATH_H_PBUFFER (path, (h) + 1) /* tb->F[h] or tb->S[0]->b_parent */13371337-#define PATH_H_POSITION(path, h) PATH_OFFSET_POSITION (path, path->path_length - (h))13381338-#define PATH_H_B_ITEM_ORDER(path, h) PATH_H_POSITION(path, h + 1) /* tb->S[h]->b_item_order */13391339-13401340-#define PATH_H_PATH_OFFSET(path, n_h) ((path)->path_length - (n_h))13411341-13421342-#define get_last_bh(path) PATH_PLAST_BUFFER(path)13431343-#define get_ih(path) PATH_PITEM_HEAD(path)13441344-#define get_item_pos(path) PATH_LAST_POSITION(path)13451345-#define get_item(path) ((void *)B_N_PITEM(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION (path)))13461346-#define item_moved(ih,path) comp_items(ih, path)13471347-#define path_changed(ih,path) comp_items (ih, path)13481348-13491349-/***************************************************************************/13501350-/* MISC */13511351-/***************************************************************************/13521352-13531353-/* Size of pointer to the unformatted node. */13541354-#define UNFM_P_SIZE (sizeof(unp_t))13551355-#define UNFM_P_SHIFT 213561356-13571357-// in in-core inode key is stored on le form13581358-#define INODE_PKEY(inode) ((struct reiserfs_key *)(REISERFS_I(inode)->i_key))13591359-13601360-#define MAX_UL_INT 0xffffffff13611361-#define MAX_INT 0x7ffffff13621362-#define MAX_US_INT 0xffff13631363-13641364-// reiserfs version 2 has max offset 60 bits. Version 1 - 32 bit offset13651365-#define U32_MAX (~(__u32)0)13661366-13671367-static inline loff_t max_reiserfs_offset(struct inode *inode)13681368-{13691369- if (get_inode_item_key_version(inode) == KEY_FORMAT_3_5)13701370- return (loff_t) U32_MAX;13711371-13721372- return (loff_t) ((~(__u64) 0) >> 4);13731373-}13741374-13751375-/*#define MAX_KEY_UNIQUENESS MAX_UL_INT*/13761376-#define MAX_KEY_OBJECTID MAX_UL_INT13771377-13781378-#define MAX_B_NUM MAX_UL_INT13791379-#define MAX_FC_NUM MAX_US_INT13801380-13811381-/* the purpose is to detect overflow of an unsigned short */13821382-#define REISERFS_LINK_MAX (MAX_US_INT - 1000)13831383-13841384-/* The following defines are used in reiserfs_insert_item and reiserfs_append_item */13851385-#define REISERFS_KERNEL_MEM 0 /* reiserfs kernel memory mode */13861386-#define REISERFS_USER_MEM 1 /* reiserfs user memory mode */13871387-13881388-#define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)13891389-#define get_generation(s) atomic_read (&fs_generation(s))13901390-#define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)13911391-#define __fs_changed(gen,s) (gen != get_generation (s))13921392-#define fs_changed(gen,s) \13931393-({ \13941394- reiserfs_cond_resched(s); \13951395- __fs_changed(gen, s); \13961396-})13971397-13981398-/***************************************************************************/13991399-/* FIXATE NODES */14001400-/***************************************************************************/14011401-14021402-#define VI_TYPE_LEFT_MERGEABLE 114031403-#define VI_TYPE_RIGHT_MERGEABLE 214041404-14051405-/* To make any changes in the tree we always first find node, that14061406- contains item to be changed/deleted or place to insert a new14071407- item. We call this node S. To do balancing we need to decide what14081408- we will shift to left/right neighbor, or to a new node, where new14091409- item will be etc. To make this analysis simpler we build virtual14101410- node. Virtual node is an array of items, that will replace items of14111411- node S. (For instance if we are going to delete an item, virtual14121412- node does not contain it). Virtual node keeps information about14131413- item sizes and types, mergeability of first and last items, sizes14141414- of all entries in directory item. We use this array of items when14151415- calculating what we can shift to neighbors and how many nodes we14161416- have to have if we do not any shiftings, if we shift to left/right14171417- neighbor or to both. */14181418-struct virtual_item {14191419- int vi_index; // index in the array of item operations14201420- unsigned short vi_type; // left/right mergeability14211421- unsigned short vi_item_len; /* length of item that it will have after balancing */14221422- struct item_head *vi_ih;14231423- const char *vi_item; // body of item (old or new)14241424- const void *vi_new_data; // 0 always but paste mode14251425- void *vi_uarea; // item specific area14261426-};14271427-14281428-struct virtual_node {14291429- char *vn_free_ptr; /* this is a pointer to the free space in the buffer */14301430- unsigned short vn_nr_item; /* number of items in virtual node */14311431- short vn_size; /* size of node , that node would have if it has unlimited size and no balancing is performed */14321432- short vn_mode; /* mode of balancing (paste, insert, delete, cut) */14331433- short vn_affected_item_num;14341434- short vn_pos_in_item;14351435- struct item_head *vn_ins_ih; /* item header of inserted item, 0 for other modes */14361436- const void *vn_data;14371437- struct virtual_item *vn_vi; /* array of items (including a new one, excluding item to be deleted) */14381438-};14391439-14401440-/* used by directory items when creating virtual nodes */14411441-struct direntry_uarea {14421442- int flags;14431443- __u16 entry_count;14441444- __u16 entry_sizes[1];14451445-} __attribute__ ((__packed__));14461446-14471447-/***************************************************************************/14481448-/* TREE BALANCE */14491449-/***************************************************************************/14501450-14511451-/* This temporary structure is used in tree balance algorithms, and14521452- constructed as we go to the extent that its various parts are14531453- needed. It contains arrays of nodes that can potentially be14541454- involved in the balancing of node S, and parameters that define how14551455- each of the nodes must be balanced. Note that in these algorithms14561456- for balancing the worst case is to need to balance the current node14571457- S and the left and right neighbors and all of their parents plus14581458- create a new node. We implement S1 balancing for the leaf nodes14591459- and S0 balancing for the internal nodes (S1 and S0 are defined in14601460- our papers.)*/14611461-14621462-#define MAX_FREE_BLOCK 7 /* size of the array of buffers to free at end of do_balance */14631463-14641464-/* maximum number of FEB blocknrs on a single level */14651465-#define MAX_AMOUNT_NEEDED 214661466-14671467-/* someday somebody will prefix every field in this struct with tb_ */14681468-struct tree_balance {14691469- int tb_mode;14701470- int need_balance_dirty;14711471- struct super_block *tb_sb;14721472- struct reiserfs_transaction_handle *transaction_handle;14731473- struct treepath *tb_path;14741474- struct buffer_head *L[MAX_HEIGHT]; /* array of left neighbors of nodes in the path */14751475- struct buffer_head *R[MAX_HEIGHT]; /* array of right neighbors of nodes in the path */14761476- struct buffer_head *FL[MAX_HEIGHT]; /* array of fathers of the left neighbors */14771477- struct buffer_head *FR[MAX_HEIGHT]; /* array of fathers of the right neighbors */14781478- struct buffer_head *CFL[MAX_HEIGHT]; /* array of common parents of center node and its left neighbor */14791479- struct buffer_head *CFR[MAX_HEIGHT]; /* array of common parents of center node and its right neighbor */14801480-14811481- struct buffer_head *FEB[MAX_FEB_SIZE]; /* array of empty buffers. Number of buffers in array equals14821482- cur_blknum. */14831483- struct buffer_head *used[MAX_FEB_SIZE];14841484- struct buffer_head *thrown[MAX_FEB_SIZE];14851485- int lnum[MAX_HEIGHT]; /* array of number of items which must be14861486- shifted to the left in order to balance the14871487- current node; for leaves includes item that14881488- will be partially shifted; for internal14891489- nodes, it is the number of child pointers14901490- rather than items. It includes the new item14911491- being created. The code sometimes subtracts14921492- one to get the number of wholly shifted14931493- items for other purposes. */14941494- int rnum[MAX_HEIGHT]; /* substitute right for left in comment above */14951495- int lkey[MAX_HEIGHT]; /* array indexed by height h mapping the key delimiting L[h] and14961496- S[h] to its item number within the node CFL[h] */14971497- int rkey[MAX_HEIGHT]; /* substitute r for l in comment above */14981498- int insert_size[MAX_HEIGHT]; /* the number of bytes by we are trying to add or remove from14991499- S[h]. A negative value means removing. */15001500- int blknum[MAX_HEIGHT]; /* number of nodes that will replace node S[h] after15011501- balancing on the level h of the tree. If 0 then S is15021502- being deleted, if 1 then S is remaining and no new nodes15031503- are being created, if 2 or 3 then 1 or 2 new nodes is15041504- being created */15051505-15061506- /* fields that are used only for balancing leaves of the tree */15071507- int cur_blknum; /* number of empty blocks having been already allocated */15081508- int s0num; /* number of items that fall into left most node when S[0] splits */15091509- int s1num; /* number of items that fall into first new node when S[0] splits */15101510- int s2num; /* number of items that fall into second new node when S[0] splits */15111511- int lbytes; /* number of bytes which can flow to the left neighbor from the left */15121512- /* most liquid item that cannot be shifted from S[0] entirely */15131513- /* if -1 then nothing will be partially shifted */15141514- int rbytes; /* number of bytes which will flow to the right neighbor from the right */15151515- /* most liquid item that cannot be shifted from S[0] entirely */15161516- /* if -1 then nothing will be partially shifted */15171517- int s1bytes; /* number of bytes which flow to the first new node when S[0] splits */15181518- /* note: if S[0] splits into 3 nodes, then items do not need to be cut */15191519- int s2bytes;15201520- struct buffer_head *buf_to_free[MAX_FREE_BLOCK]; /* buffers which are to be freed after do_balance finishes by unfix_nodes */15211521- char *vn_buf; /* kmalloced memory. Used to create15221522- virtual node and keep map of15231523- dirtied bitmap blocks */15241524- int vn_buf_size; /* size of the vn_buf */15251525- struct virtual_node *tb_vn; /* VN starts after bitmap of bitmap blocks */15261526-15271527- int fs_gen; /* saved value of `reiserfs_generation' counter15281528- see FILESYSTEM_CHANGED() macro in reiserfs_fs.h */15291529-#ifdef DISPLACE_NEW_PACKING_LOCALITIES15301530- struct in_core_key key; /* key pointer, to pass to block allocator or15311531- another low-level subsystem */15321532-#endif15331533-};15341534-15351535-/* These are modes of balancing */15361536-15371537-/* When inserting an item. */15381538-#define M_INSERT 'i'15391539-/* When inserting into (directories only) or appending onto an already15401540- existent item. */15411541-#define M_PASTE 'p'15421542-/* When deleting an item. */15431543-#define M_DELETE 'd'15441544-/* When truncating an item or removing an entry from a (directory) item. */15451545-#define M_CUT 'c'15461546-15471547-/* used when balancing on leaf level skipped (in reiserfsck) */15481548-#define M_INTERNAL 'n'15491549-15501550-/* When further balancing is not needed, then do_balance does not need15511551- to be called. */15521552-#define M_SKIP_BALANCING 's'15531553-#define M_CONVERT 'v'15541554-15551555-/* modes of leaf_move_items */15561556-#define LEAF_FROM_S_TO_L 015571557-#define LEAF_FROM_S_TO_R 115581558-#define LEAF_FROM_R_TO_L 215591559-#define LEAF_FROM_L_TO_R 315601560-#define LEAF_FROM_S_TO_SNEW 415611561-15621562-#define FIRST_TO_LAST 015631563-#define LAST_TO_FIRST 115641564-15651565-/* used in do_balance for passing parent of node information that has15661566- been gotten from tb struct */15671567-struct buffer_info {15681568- struct tree_balance *tb;15691569- struct buffer_head *bi_bh;15701570- struct buffer_head *bi_parent;15711571- int bi_position;15721572-};15731573-15741574-static inline struct super_block *sb_from_tb(struct tree_balance *tb)15751575-{15761576- return tb ? tb->tb_sb : NULL;15771577-}15781578-15791579-static inline struct super_block *sb_from_bi(struct buffer_info *bi)15801580-{15811581- return bi ? sb_from_tb(bi->tb) : NULL;15821582-}15831583-15841584-/* there are 4 types of items: stat data, directory item, indirect, direct.15851585-+-------------------+------------+--------------+------------+15861586-| | k_offset | k_uniqueness | mergeable? |15871587-+-------------------+------------+--------------+------------+15881588-| stat data | 0 | 0 | no |15891589-+-------------------+------------+--------------+------------+15901590-| 1st directory item| DOT_OFFSET |DIRENTRY_UNIQUENESS| no | 15911591-| non 1st directory | hash value | | yes |15921592-| item | | | |15931593-+-------------------+------------+--------------+------------+15941594-| indirect item | offset + 1 |TYPE_INDIRECT | if this is not the first indirect item of the object15951595-+-------------------+------------+--------------+------------+15961596-| direct item | offset + 1 |TYPE_DIRECT | if not this is not the first direct item of the object15971597-+-------------------+------------+--------------+------------+15981598-*/15991599-16001600-struct item_operations {16011601- int (*bytes_number) (struct item_head * ih, int block_size);16021602- void (*decrement_key) (struct cpu_key *);16031603- int (*is_left_mergeable) (struct reiserfs_key * ih,16041604- unsigned long bsize);16051605- void (*print_item) (struct item_head *, char *item);16061606- void (*check_item) (struct item_head *, char *item);16071607-16081608- int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,16091609- int is_affected, int insert_size);16101610- int (*check_left) (struct virtual_item * vi, int free,16111611- int start_skip, int end_skip);16121612- int (*check_right) (struct virtual_item * vi, int free);16131613- int (*part_size) (struct virtual_item * vi, int from, int to);16141614- int (*unit_num) (struct virtual_item * vi);16151615- void (*print_vi) (struct virtual_item * vi);16161616-};16171617-16181618-extern struct item_operations *item_ops[TYPE_ANY + 1];16191619-16201620-#define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)16211621-#define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)16221622-#define op_print_item(ih,item) item_ops[le_ih_k_type (ih)]->print_item (ih, item)16231623-#define op_check_item(ih,item) item_ops[le_ih_k_type (ih)]->check_item (ih, item)16241624-#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)16251625-#define op_check_left(vi,free,start_skip,end_skip) item_ops[(vi)->vi_index]->check_left (vi, free, start_skip, end_skip)16261626-#define op_check_right(vi,free) item_ops[(vi)->vi_index]->check_right (vi, free)16271627-#define op_part_size(vi,from,to) item_ops[(vi)->vi_index]->part_size (vi, from, to)16281628-#define op_unit_num(vi) item_ops[(vi)->vi_index]->unit_num (vi)16291629-#define op_print_vi(vi) item_ops[(vi)->vi_index]->print_vi (vi)16301630-16311631-#define COMP_SHORT_KEYS comp_short_keys16321632-16331633-/* number of blocks pointed to by the indirect item */16341634-#define I_UNFM_NUM(ih) (ih_item_len(ih) / UNFM_P_SIZE)16351635-16361636-/* the used space within the unformatted node corresponding to pos within the item pointed to by ih */16371637-#define I_POS_UNFM_SIZE(ih,pos,size) (((pos) == I_UNFM_NUM(ih) - 1 ) ? (size) - ih_free_space(ih) : (size))16381638-16391639-/* number of bytes contained by the direct item or the unformatted nodes the indirect item points to */16401640-16411641-/* get the item header */16421642-#define B_N_PITEM_HEAD(bh,item_num) ( (struct item_head * )((bh)->b_data + BLKH_SIZE) + (item_num) )16431643-16441644-/* get key */16451645-#define B_N_PDELIM_KEY(bh,item_num) ( (struct reiserfs_key * )((bh)->b_data + BLKH_SIZE) + (item_num) )16461646-16471647-/* get the key */16481648-#define B_N_PKEY(bh,item_num) ( &(B_N_PITEM_HEAD(bh,item_num)->ih_key) )16491649-16501650-/* get item body */16511651-#define B_N_PITEM(bh,item_num) ( (bh)->b_data + ih_location(B_N_PITEM_HEAD((bh),(item_num))))16521652-16531653-/* get the stat data by the buffer header and the item order */16541654-#define B_N_STAT_DATA(bh,nr) \16551655-( (struct stat_data *)((bh)->b_data + ih_location(B_N_PITEM_HEAD((bh),(nr))) ) )16561656-16571657- /* following defines use reiserfs buffer header and item header */16581658-16591659-/* get stat-data */16601660-#define B_I_STAT_DATA(bh, ih) ( (struct stat_data * )((bh)->b_data + ih_location(ih)) )16611661-16621662-// this is 3976 for size==409616631663-#define MAX_DIRECT_ITEM_LEN(size) ((size) - BLKH_SIZE - 2*IH_SIZE - SD_SIZE - UNFM_P_SIZE)16641664-16651665-/* indirect items consist of entries which contain blocknrs, pos16661666- indicates which entry, and B_I_POS_UNFM_POINTER resolves to the16671667- blocknr contained by the entry pos points to */16681668-#define B_I_POS_UNFM_POINTER(bh,ih,pos) le32_to_cpu(*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)))16691669-#define PUT_B_I_POS_UNFM_POINTER(bh,ih,pos, val) do {*(((unp_t *)B_I_PITEM(bh,ih)) + (pos)) = cpu_to_le32(val); } while (0)16701670-16711671-struct reiserfs_iget_args {16721672- __u32 objectid;16731673- __u32 dirid;16741674-};16751675-16761676-/***************************************************************************/16771677-/* FUNCTION DECLARATIONS */16781678-/***************************************************************************/16791679-16801680-#define get_journal_desc_magic(bh) (bh->b_data + bh->b_size - 12)16811681-16821682-#define journal_trans_half(blocksize) \16831683- ((blocksize - sizeof (struct reiserfs_journal_desc) + sizeof (__u32) - 12) / sizeof (__u32))16841684-16851685-/* journal.c see journal.c for all the comments here */16861686-16871687-/* first block written in a commit. */16881688-struct reiserfs_journal_desc {16891689- __le32 j_trans_id; /* id of commit */16901690- __le32 j_len; /* length of commit. len +1 is the commit block */16911691- __le32 j_mount_id; /* mount id of this trans */16921692- __le32 j_realblock[1]; /* real locations for each block */16931693-};16941694-16951695-#define get_desc_trans_id(d) le32_to_cpu((d)->j_trans_id)16961696-#define get_desc_trans_len(d) le32_to_cpu((d)->j_len)16971697-#define get_desc_mount_id(d) le32_to_cpu((d)->j_mount_id)16981698-16991699-#define set_desc_trans_id(d,val) do { (d)->j_trans_id = cpu_to_le32 (val); } while (0)17001700-#define set_desc_trans_len(d,val) do { (d)->j_len = cpu_to_le32 (val); } while (0)17011701-#define set_desc_mount_id(d,val) do { (d)->j_mount_id = cpu_to_le32 (val); } while (0)17021702-17031703-/* last block written in a commit */17041704-struct reiserfs_journal_commit {17051705- __le32 j_trans_id; /* must match j_trans_id from the desc block */17061706- __le32 j_len; /* ditto */17071707- __le32 j_realblock[1]; /* real locations for each block */17081708-};17091709-17101710-#define get_commit_trans_id(c) le32_to_cpu((c)->j_trans_id)17111711-#define get_commit_trans_len(c) le32_to_cpu((c)->j_len)17121712-#define get_commit_mount_id(c) le32_to_cpu((c)->j_mount_id)17131713-17141714-#define set_commit_trans_id(c,val) do { (c)->j_trans_id = cpu_to_le32 (val); } while (0)17151715-#define set_commit_trans_len(c,val) do { (c)->j_len = cpu_to_le32 (val); } while (0)17161716-17171717-/* this header block gets written whenever a transaction is considered fully flushed, and is more recent than the17181718-** last fully flushed transaction. fully flushed means all the log blocks and all the real blocks are on disk,17191719-** and this transaction does not need to be replayed.17201720-*/17211721-struct reiserfs_journal_header {17221722- __le32 j_last_flush_trans_id; /* id of last fully flushed transaction */17231723- __le32 j_first_unflushed_offset; /* offset in the log of where to start replay after a crash */17241724- __le32 j_mount_id;17251725- /* 12 */ struct journal_params jh_journal;17261726-};17271727-17281728-/* biggest tunable defines are right here */17291729-#define JOURNAL_BLOCK_COUNT 8192 /* number of blocks in the journal */17301730-#define JOURNAL_TRANS_MAX_DEFAULT 1024 /* biggest possible single transaction, don't change for now (8/3/99) */17311731-#define JOURNAL_TRANS_MIN_DEFAULT 25617321732-#define JOURNAL_MAX_BATCH_DEFAULT 900 /* max blocks to batch into one transaction, don't make this any bigger than 900 */17331733-#define JOURNAL_MIN_RATIO 217341734-#define JOURNAL_MAX_COMMIT_AGE 3017351735-#define JOURNAL_MAX_TRANS_AGE 3017361736-#define JOURNAL_PER_BALANCE_CNT (3 * (MAX_HEIGHT-2) + 9)17371737-#define JOURNAL_BLOCKS_PER_OBJECT(sb) (JOURNAL_PER_BALANCE_CNT * 3 + \17381738- 2 * (REISERFS_QUOTA_INIT_BLOCKS(sb) + \17391739- REISERFS_QUOTA_TRANS_BLOCKS(sb)))17401740-17411741-#ifdef CONFIG_QUOTA17421742-#define REISERFS_QUOTA_OPTS ((1 << REISERFS_USRQUOTA) | (1 << REISERFS_GRPQUOTA))17431743-/* We need to update data and inode (atime) */17441744-#define REISERFS_QUOTA_TRANS_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? 2 : 0)17451745-/* 1 balancing, 1 bitmap, 1 data per write + stat data update */17461746-#define REISERFS_QUOTA_INIT_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? \17471747-(DQUOT_INIT_ALLOC*(JOURNAL_PER_BALANCE_CNT+2)+DQUOT_INIT_REWRITE+1) : 0)17481748-/* same as with INIT */17491749-#define REISERFS_QUOTA_DEL_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? \17501750-(DQUOT_DEL_ALLOC*(JOURNAL_PER_BALANCE_CNT+2)+DQUOT_DEL_REWRITE+1) : 0)17511751-#else17521752-#define REISERFS_QUOTA_TRANS_BLOCKS(s) 017531753-#define REISERFS_QUOTA_INIT_BLOCKS(s) 017541754-#define REISERFS_QUOTA_DEL_BLOCKS(s) 017551755-#endif17561756-17571757-/* both of these can be as low as 1, or as high as you want. The min is the17581758-** number of 4k bitmap nodes preallocated on mount. New nodes are allocated17591759-** as needed, and released when transactions are committed. On release, if 17601760-** the current number of nodes is > max, the node is freed, otherwise, 17611761-** it is put on a free list for faster use later.17621762-*/17631763-#define REISERFS_MIN_BITMAP_NODES 1017641764-#define REISERFS_MAX_BITMAP_NODES 10017651765-17661766-#define JBH_HASH_SHIFT 13 /* these are based on journal hash size of 8192 */17671767-#define JBH_HASH_MASK 819117681768-17691769-#define _jhashfn(sb,block) \17701770- (((unsigned long)sb>>L1_CACHE_SHIFT) ^ \17711771- (((block)<<(JBH_HASH_SHIFT - 6)) ^ ((block) >> 13) ^ ((block) << (JBH_HASH_SHIFT - 12))))17721772-#define journal_hash(t,sb,block) ((t)[_jhashfn((sb),(block)) & JBH_HASH_MASK])17731773-17741774-// We need these to make journal.c code more readable17751775-#define journal_find_get_block(s, block) __find_get_block(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)17761776-#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)17771777-#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)17781778-17791779-enum reiserfs_bh_state_bits {17801780- BH_JDirty = BH_PrivateStart, /* buffer is in current transaction */17811781- BH_JDirty_wait,17821782- BH_JNew, /* disk block was taken off free list before17831783- * being in a finished transaction, or17841784- * written to disk. Can be reused immed. */17851785- BH_JPrepared,17861786- BH_JRestore_dirty,17871787- BH_JTest, // debugging only will go away17881788-};17891789-17901790-BUFFER_FNS(JDirty, journaled);17911791-TAS_BUFFER_FNS(JDirty, journaled);17921792-BUFFER_FNS(JDirty_wait, journal_dirty);17931793-TAS_BUFFER_FNS(JDirty_wait, journal_dirty);17941794-BUFFER_FNS(JNew, journal_new);17951795-TAS_BUFFER_FNS(JNew, journal_new);17961796-BUFFER_FNS(JPrepared, journal_prepared);17971797-TAS_BUFFER_FNS(JPrepared, journal_prepared);17981798-BUFFER_FNS(JRestore_dirty, journal_restore_dirty);17991799-TAS_BUFFER_FNS(JRestore_dirty, journal_restore_dirty);18001800-BUFFER_FNS(JTest, journal_test);18011801-TAS_BUFFER_FNS(JTest, journal_test);18021802-18031803-/*18041804-** transaction handle which is passed around for all journal calls18051805-*/18061806-struct reiserfs_transaction_handle {18071807- struct super_block *t_super; /* super for this FS when journal_begin was18081808- called. saves calls to reiserfs_get_super18091809- also used by nested transactions to make18101810- sure they are nesting on the right FS18111811- _must_ be first in the handle18121812- */18131813- int t_refcount;18141814- int t_blocks_logged; /* number of blocks this writer has logged */18151815- int t_blocks_allocated; /* number of blocks this writer allocated */18161816- unsigned int t_trans_id; /* sanity check, equals the current trans id */18171817- void *t_handle_save; /* save existing current->journal_info */18181818- unsigned displace_new_blocks:1; /* if new block allocation occurres, that block18191819- should be displaced from others */18201820- struct list_head t_list;18211821-};18221822-18231823-/* used to keep track of ordered and tail writes, attached to the buffer18241824- * head through b_journal_head.18251825- */18261826-struct reiserfs_jh {18271827- struct reiserfs_journal_list *jl;18281828- struct buffer_head *bh;18291829- struct list_head list;18301830-};18311831-18321832-void reiserfs_free_jh(struct buffer_head *bh);18331833-int reiserfs_add_tail_list(struct inode *inode, struct buffer_head *bh);18341834-int reiserfs_add_ordered_list(struct inode *inode, struct buffer_head *bh);18351835-int journal_mark_dirty(struct reiserfs_transaction_handle *,18361836- struct super_block *, struct buffer_head *bh);18371837-18381838-static inline int reiserfs_file_data_log(struct inode *inode)18391839-{18401840- if (reiserfs_data_log(inode->i_sb) ||18411841- (REISERFS_I(inode)->i_flags & i_data_log))18421842- return 1;18431843- return 0;18441844-}18451845-18461846-static inline int reiserfs_transaction_running(struct super_block *s)18471847-{18481848- struct reiserfs_transaction_handle *th = current->journal_info;18491849- if (th && th->t_super == s)18501850- return 1;18511851- if (th && th->t_super == NULL)18521852- BUG();18531853- return 0;18541854-}18551855-18561856-static inline int reiserfs_transaction_free_space(struct reiserfs_transaction_handle *th)18571857-{18581858- return th->t_blocks_allocated - th->t_blocks_logged;18591859-}18601860-18611861-struct reiserfs_transaction_handle *reiserfs_persistent_transaction(struct18621862- super_block18631863- *,18641864- int count);18651865-int reiserfs_end_persistent_transaction(struct reiserfs_transaction_handle *);18661866-int reiserfs_commit_page(struct inode *inode, struct page *page,18671867- unsigned from, unsigned to);18681868-int reiserfs_flush_old_commits(struct super_block *);18691869-int reiserfs_commit_for_inode(struct inode *);18701870-int reiserfs_inode_needs_commit(struct inode *);18711871-void reiserfs_update_inode_transaction(struct inode *);18721872-void reiserfs_wait_on_write_block(struct super_block *s);18731873-void reiserfs_block_writes(struct reiserfs_transaction_handle *th);18741874-void reiserfs_allow_writes(struct super_block *s);18751875-void reiserfs_check_lock_depth(struct super_block *s, char *caller);18761876-int reiserfs_prepare_for_journal(struct super_block *, struct buffer_head *bh,18771877- int wait);18781878-void reiserfs_restore_prepared_buffer(struct super_block *,18791879- struct buffer_head *bh);18801880-int journal_init(struct super_block *, const char *j_dev_name, int old_format,18811881- unsigned int);18821882-int journal_release(struct reiserfs_transaction_handle *, struct super_block *);18831883-int journal_release_error(struct reiserfs_transaction_handle *,18841884- struct super_block *);18851885-int journal_end(struct reiserfs_transaction_handle *, struct super_block *,18861886- unsigned long);18871887-int journal_end_sync(struct reiserfs_transaction_handle *, struct super_block *,18881888- unsigned long);18891889-int journal_mark_freed(struct reiserfs_transaction_handle *,18901890- struct super_block *, b_blocknr_t blocknr);18911891-int journal_transaction_should_end(struct reiserfs_transaction_handle *, int);18921892-int reiserfs_in_journal(struct super_block *sb, unsigned int bmap_nr,18931893- int bit_nr, int searchall, b_blocknr_t *next);18941894-int journal_begin(struct reiserfs_transaction_handle *,18951895- struct super_block *sb, unsigned long);18961896-int journal_join_abort(struct reiserfs_transaction_handle *,18971897- struct super_block *sb, unsigned long);18981898-void reiserfs_abort_journal(struct super_block *sb, int errno);18991899-void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...);19001900-int reiserfs_allocate_list_bitmaps(struct super_block *s,19011901- struct reiserfs_list_bitmap *, unsigned int);19021902-19031903-void add_save_link(struct reiserfs_transaction_handle *th,19041904- struct inode *inode, int truncate);19051905-int remove_save_link(struct inode *inode, int truncate);19061906-19071907-/* objectid.c */19081908-__u32 reiserfs_get_unused_objectid(struct reiserfs_transaction_handle *th);19091909-void reiserfs_release_objectid(struct reiserfs_transaction_handle *th,19101910- __u32 objectid_to_release);19111911-int reiserfs_convert_objectid_map_v1(struct super_block *);19121912-19131913-/* stree.c */19141914-int B_IS_IN_TREE(const struct buffer_head *);19151915-extern void copy_item_head(struct item_head *to,19161916- const struct item_head *from);19171917-19181918-// first key is in cpu form, second - le19191919-extern int comp_short_keys(const struct reiserfs_key *le_key,19201920- const struct cpu_key *cpu_key);19211921-extern void le_key2cpu_key(struct cpu_key *to, const struct reiserfs_key *from);19221922-19231923-// both are in le form19241924-extern int comp_le_keys(const struct reiserfs_key *,19251925- const struct reiserfs_key *);19261926-extern int comp_short_le_keys(const struct reiserfs_key *,19271927- const struct reiserfs_key *);19281928-19291929-//19301930-// get key version from on disk key - kludge19311931-//19321932-static inline int le_key_version(const struct reiserfs_key *key)19331933-{19341934- int type;19351935-19361936- type = offset_v2_k_type(&(key->u.k_offset_v2));19371937- if (type != TYPE_DIRECT && type != TYPE_INDIRECT19381938- && type != TYPE_DIRENTRY)19391939- return KEY_FORMAT_3_5;19401940-19411941- return KEY_FORMAT_3_6;19421942-19431943-}19441944-19451945-static inline void copy_key(struct reiserfs_key *to,19461946- const struct reiserfs_key *from)19471947-{19481948- memcpy(to, from, KEY_SIZE);19491949-}19501950-19511951-int comp_items(const struct item_head *stored_ih, const struct treepath *path);19521952-const struct reiserfs_key *get_rkey(const struct treepath *chk_path,19531953- const struct super_block *sb);19541954-int search_by_key(struct super_block *, const struct cpu_key *,19551955- struct treepath *, int);19561956-#define search_item(s,key,path) search_by_key (s, key, path, DISK_LEAF_NODE_LEVEL)19571957-int search_for_position_by_key(struct super_block *sb,19581958- const struct cpu_key *cpu_key,19591959- struct treepath *search_path);19601960-extern void decrement_bcount(struct buffer_head *bh);19611961-void decrement_counters_in_path(struct treepath *search_path);19621962-void pathrelse(struct treepath *search_path);19631963-int reiserfs_check_path(struct treepath *p);19641964-void pathrelse_and_restore(struct super_block *s, struct treepath *search_path);19651965-19661966-int reiserfs_insert_item(struct reiserfs_transaction_handle *th,19671967- struct treepath *path,19681968- const struct cpu_key *key,19691969- struct item_head *ih,19701970- struct inode *inode, const char *body);19711971-19721972-int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th,19731973- struct treepath *path,19741974- const struct cpu_key *key,19751975- struct inode *inode,19761976- const char *body, int paste_size);19771977-19781978-int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,19791979- struct treepath *path,19801980- struct cpu_key *key,19811981- struct inode *inode,19821982- struct page *page, loff_t new_file_size);19831983-19841984-int reiserfs_delete_item(struct reiserfs_transaction_handle *th,19851985- struct treepath *path,19861986- const struct cpu_key *key,19871987- struct inode *inode, struct buffer_head *un_bh);19881988-19891989-void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,19901990- struct inode *inode, struct reiserfs_key *key);19911991-int reiserfs_delete_object(struct reiserfs_transaction_handle *th,19921992- struct inode *inode);19931993-int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,19941994- struct inode *inode, struct page *,19951995- int update_timestamps);19961996-19971997-#define i_block_size(inode) ((inode)->i_sb->s_blocksize)19981998-#define file_size(inode) ((inode)->i_size)19991999-#define tail_size(inode) (file_size (inode) & (i_block_size (inode) - 1))20002000-20012001-#define tail_has_to_be_packed(inode) (have_large_tails ((inode)->i_sb)?\20022002-!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 )20032003-20042004-void padd_item(char *item, int total_length, int length);20052005-20062006-/* inode.c */20072007-/* args for the create parameter of reiserfs_get_block */20082008-#define GET_BLOCK_NO_CREATE 0 /* don't create new blocks or convert tails */20092009-#define GET_BLOCK_CREATE 1 /* add anything you need to find block */20102010-#define GET_BLOCK_NO_HOLE 2 /* return -ENOENT for file holes */20112011-#define GET_BLOCK_READ_DIRECT 4 /* read the tail if indirect item not found */20122012-#define GET_BLOCK_NO_IMUX 8 /* i_mutex is not held, don't preallocate */20132013-#define GET_BLOCK_NO_DANGLE 16 /* don't leave any transactions running */20142014-20152015-void reiserfs_read_locked_inode(struct inode *inode,20162016- struct reiserfs_iget_args *args);20172017-int reiserfs_find_actor(struct inode *inode, void *p);20182018-int reiserfs_init_locked_inode(struct inode *inode, void *p);20192019-void reiserfs_evict_inode(struct inode *inode);20202020-int reiserfs_write_inode(struct inode *inode, struct writeback_control *wbc);20212021-int reiserfs_get_block(struct inode *inode, sector_t block,20222022- struct buffer_head *bh_result, int create);20232023-struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid,20242024- int fh_len, int fh_type);20252025-struct dentry *reiserfs_fh_to_parent(struct super_block *sb, struct fid *fid,20262026- int fh_len, int fh_type);20272027-int reiserfs_encode_fh(struct dentry *dentry, __u32 * data, int *lenp,20282028- int connectable);20292029-20302030-int reiserfs_truncate_file(struct inode *, int update_timestamps);20312031-void make_cpu_key(struct cpu_key *cpu_key, struct inode *inode, loff_t offset,20322032- int type, int key_length);20332033-void make_le_item_head(struct item_head *ih, const struct cpu_key *key,20342034- int version,20352035- loff_t offset, int type, int length, int entry_count);20362036-struct inode *reiserfs_iget(struct super_block *s, const struct cpu_key *key);20372037-20382038-struct reiserfs_security_handle;20392039-int reiserfs_new_inode(struct reiserfs_transaction_handle *th,20402040- struct inode *dir, umode_t mode,20412041- const char *symname, loff_t i_size,20422042- struct dentry *dentry, struct inode *inode,20432043- struct reiserfs_security_handle *security);20442044-20452045-void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,20462046- struct inode *inode, loff_t size);20472047-20482048-static inline void reiserfs_update_sd(struct reiserfs_transaction_handle *th,20492049- struct inode *inode)20502050-{20512051- reiserfs_update_sd_size(th, inode, inode->i_size);20522052-}20532053-20542054-void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);20552055-void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);20562056-int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);20572057-20582058-int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);20592059-20602060-/* namei.c */20612061-void set_de_name_and_namelen(struct reiserfs_dir_entry *de);20622062-int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,20632063- struct treepath *path, struct reiserfs_dir_entry *de);20642064-struct dentry *reiserfs_get_parent(struct dentry *);20652065-20662066-#ifdef CONFIG_REISERFS_PROC_INFO20672067-int reiserfs_proc_info_init(struct super_block *sb);20682068-int reiserfs_proc_info_done(struct super_block *sb);20692069-int reiserfs_proc_info_global_init(void);20702070-int reiserfs_proc_info_global_done(void);20712071-20722072-#define PROC_EXP( e ) e20732073-20742074-#define __PINFO( sb ) REISERFS_SB(sb) -> s_proc_info_data20752075-#define PROC_INFO_MAX( sb, field, value ) \20762076- __PINFO( sb ).field = \20772077- max( REISERFS_SB( sb ) -> s_proc_info_data.field, value )20782078-#define PROC_INFO_INC( sb, field ) ( ++ ( __PINFO( sb ).field ) )20792079-#define PROC_INFO_ADD( sb, field, val ) ( __PINFO( sb ).field += ( val ) )20802080-#define PROC_INFO_BH_STAT( sb, bh, level ) \20812081- PROC_INFO_INC( sb, sbk_read_at[ ( level ) ] ); \20822082- PROC_INFO_ADD( sb, free_at[ ( level ) ], B_FREE_SPACE( bh ) ); \20832083- PROC_INFO_ADD( sb, items_at[ ( level ) ], B_NR_ITEMS( bh ) )20842084-#else20852085-static inline int reiserfs_proc_info_init(struct super_block *sb)20862086-{20872087- return 0;20882088-}20892089-20902090-static inline int reiserfs_proc_info_done(struct super_block *sb)20912091-{20922092- return 0;20932093-}20942094-20952095-static inline int reiserfs_proc_info_global_init(void)20962096-{20972097- return 0;20982098-}20992099-21002100-static inline int reiserfs_proc_info_global_done(void)21012101-{21022102- return 0;21032103-}21042104-21052105-#define PROC_EXP( e )21062106-#define VOID_V ( ( void ) 0 )21072107-#define PROC_INFO_MAX( sb, field, value ) VOID_V21082108-#define PROC_INFO_INC( sb, field ) VOID_V21092109-#define PROC_INFO_ADD( sb, field, val ) VOID_V21102110-#define PROC_INFO_BH_STAT(sb, bh, n_node_level) VOID_V21112111-#endif21122112-21132113-/* dir.c */21142114-extern const struct inode_operations reiserfs_dir_inode_operations;21152115-extern const struct inode_operations reiserfs_symlink_inode_operations;21162116-extern const struct inode_operations reiserfs_special_inode_operations;21172117-extern const struct file_operations reiserfs_dir_operations;21182118-int reiserfs_readdir_dentry(struct dentry *, void *, filldir_t, loff_t *);21192119-21202120-/* tail_conversion.c */21212121-int direct2indirect(struct reiserfs_transaction_handle *, struct inode *,21222122- struct treepath *, struct buffer_head *, loff_t);21232123-int indirect2direct(struct reiserfs_transaction_handle *, struct inode *,21242124- struct page *, struct treepath *, const struct cpu_key *,21252125- loff_t, char *);21262126-void reiserfs_unmap_buffer(struct buffer_head *);21272127-21282128-/* file.c */21292129-extern const struct inode_operations reiserfs_file_inode_operations;21302130-extern const struct file_operations reiserfs_file_operations;21312131-extern const struct address_space_operations reiserfs_address_space_operations;21322132-21332133-/* fix_nodes.c */21342134-21352135-int fix_nodes(int n_op_mode, struct tree_balance *tb,21362136- struct item_head *ins_ih, const void *);21372137-void unfix_nodes(struct tree_balance *);21382138-21392139-/* prints.c */21402140-void __reiserfs_panic(struct super_block *s, const char *id,21412141- const char *function, const char *fmt, ...)21422142- __attribute__ ((noreturn));21432143-#define reiserfs_panic(s, id, fmt, args...) \21442144- __reiserfs_panic(s, id, __func__, fmt, ##args)21452145-void __reiserfs_error(struct super_block *s, const char *id,21462146- const char *function, const char *fmt, ...);21472147-#define reiserfs_error(s, id, fmt, args...) \21482148- __reiserfs_error(s, id, __func__, fmt, ##args)21492149-void reiserfs_info(struct super_block *s, const char *fmt, ...);21502150-void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...);21512151-void print_indirect_item(struct buffer_head *bh, int item_num);21522152-void store_print_tb(struct tree_balance *tb);21532153-void print_cur_tb(char *mes);21542154-void print_de(struct reiserfs_dir_entry *de);21552155-void print_bi(struct buffer_info *bi, char *mes);21562156-#define PRINT_LEAF_ITEMS 1 /* print all items */21572157-#define PRINT_DIRECTORY_ITEMS 2 /* print directory items */21582158-#define PRINT_DIRECT_ITEMS 4 /* print contents of direct items */21592159-void print_block(struct buffer_head *bh, ...);21602160-void print_bmap(struct super_block *s, int silent);21612161-void print_bmap_block(int i, char *data, int size, int silent);21622162-/*void print_super_block (struct super_block * s, char * mes);*/21632163-void print_objectid_map(struct super_block *s);21642164-void print_block_head(struct buffer_head *bh, char *mes);21652165-void check_leaf(struct buffer_head *bh);21662166-void check_internal(struct buffer_head *bh);21672167-void print_statistics(struct super_block *s);21682168-char *reiserfs_hashname(int code);21692169-21702170-/* lbalance.c */21712171-int leaf_move_items(int shift_mode, struct tree_balance *tb, int mov_num,21722172- int mov_bytes, struct buffer_head *Snew);21732173-int leaf_shift_left(struct tree_balance *tb, int shift_num, int shift_bytes);21742174-int leaf_shift_right(struct tree_balance *tb, int shift_num, int shift_bytes);21752175-void leaf_delete_items(struct buffer_info *cur_bi, int last_first, int first,21762176- int del_num, int del_bytes);21772177-void leaf_insert_into_buf(struct buffer_info *bi, int before,21782178- struct item_head *inserted_item_ih,21792179- const char *inserted_item_body, int zeros_number);21802180-void leaf_paste_in_buffer(struct buffer_info *bi, int pasted_item_num,21812181- int pos_in_item, int paste_size, const char *body,21822182- int zeros_number);21832183-void leaf_cut_from_buffer(struct buffer_info *bi, int cut_item_num,21842184- int pos_in_item, int cut_size);21852185-void leaf_paste_entries(struct buffer_info *bi, int item_num, int before,21862186- int new_entry_count, struct reiserfs_de_head *new_dehs,21872187- const char *records, int paste_size);21882188-/* ibalance.c */21892189-int balance_internal(struct tree_balance *, int, int, struct item_head *,21902190- struct buffer_head **);21912191-21922192-/* do_balance.c */21932193-void do_balance_mark_leaf_dirty(struct tree_balance *tb,21942194- struct buffer_head *bh, int flag);21952195-#define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty21962196-#define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty21972197-21982198-void do_balance(struct tree_balance *tb, struct item_head *ih,21992199- const char *body, int flag);22002200-void reiserfs_invalidate_buffer(struct tree_balance *tb,22012201- struct buffer_head *bh);22022202-22032203-int get_left_neighbor_position(struct tree_balance *tb, int h);22042204-int get_right_neighbor_position(struct tree_balance *tb, int h);22052205-void replace_key(struct tree_balance *tb, struct buffer_head *, int,22062206- struct buffer_head *, int);22072207-void make_empty_node(struct buffer_info *);22082208-struct buffer_head *get_FEB(struct tree_balance *);22092209-22102210-/* bitmap.c */22112211-22122212-/* structure contains hints for block allocator, and it is a container for22132213- * arguments, such as node, search path, transaction_handle, etc. */22142214-struct __reiserfs_blocknr_hint {22152215- struct inode *inode; /* inode passed to allocator, if we allocate unf. nodes */22162216- sector_t block; /* file offset, in blocks */22172217- struct in_core_key key;22182218- struct treepath *path; /* search path, used by allocator to deternine search_start by22192219- * various ways */22202220- struct reiserfs_transaction_handle *th; /* transaction handle is needed to log super blocks and22212221- * bitmap blocks changes */22222222- b_blocknr_t beg, end;22232223- b_blocknr_t search_start; /* a field used to transfer search start value (block number)22242224- * between different block allocator procedures22252225- * (determine_search_start() and others) */22262226- int prealloc_size; /* is set in determine_prealloc_size() function, used by underlayed22272227- * function that do actual allocation */22282228-22292229- unsigned formatted_node:1; /* the allocator uses different polices for getting disk space for22302230- * formatted/unformatted blocks with/without preallocation */22312231- unsigned preallocate:1;22322232-};22332233-22342234-typedef struct __reiserfs_blocknr_hint reiserfs_blocknr_hint_t;22352235-22362236-int reiserfs_parse_alloc_options(struct super_block *, char *);22372237-void reiserfs_init_alloc_options(struct super_block *s);22382238-22392239-/*22402240- * given a directory, this will tell you what packing locality22412241- * to use for a new object underneat it. The locality is returned22422242- * in disk byte order (le).22432243- */22442244-__le32 reiserfs_choose_packing(struct inode *dir);22452245-22462246-int reiserfs_init_bitmap_cache(struct super_block *sb);22472247-void reiserfs_free_bitmap_cache(struct super_block *sb);22482248-void reiserfs_cache_bitmap_metadata(struct super_block *sb, struct buffer_head *bh, struct reiserfs_bitmap_info *info);22492249-struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb, unsigned int bitmap);22502250-int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value);22512251-void reiserfs_free_block(struct reiserfs_transaction_handle *th, struct inode *,22522252- b_blocknr_t, int for_unformatted);22532253-int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *, b_blocknr_t *, int,22542254- int);22552255-static inline int reiserfs_new_form_blocknrs(struct tree_balance *tb,22562256- b_blocknr_t * new_blocknrs,22572257- int amount_needed)22582258-{22592259- reiserfs_blocknr_hint_t hint = {22602260- .th = tb->transaction_handle,22612261- .path = tb->tb_path,22622262- .inode = NULL,22632263- .key = tb->key,22642264- .block = 0,22652265- .formatted_node = 122662266- };22672267- return reiserfs_allocate_blocknrs(&hint, new_blocknrs, amount_needed,22682268- 0);22692269-}22702270-22712271-static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle22722272- *th, struct inode *inode,22732273- b_blocknr_t * new_blocknrs,22742274- struct treepath *path,22752275- sector_t block)22762276-{22772277- reiserfs_blocknr_hint_t hint = {22782278- .th = th,22792279- .path = path,22802280- .inode = inode,22812281- .block = block,22822282- .formatted_node = 0,22832283- .preallocate = 022842284- };22852285- return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0);22862286-}22872287-22882288-#ifdef REISERFS_PREALLOCATE22892289-static inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle22902290- *th, struct inode *inode,22912291- b_blocknr_t * new_blocknrs,22922292- struct treepath *path,22932293- sector_t block)22942294-{22952295- reiserfs_blocknr_hint_t hint = {22962296- .th = th,22972297- .path = path,22982298- .inode = inode,22992299- .block = block,23002300- .formatted_node = 0,23012301- .preallocate = 123022302- };23032303- return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0);23042304-}23052305-23062306-void reiserfs_discard_prealloc(struct reiserfs_transaction_handle *th,23072307- struct inode *inode);23082308-void reiserfs_discard_all_prealloc(struct reiserfs_transaction_handle *th);23092309-#endif23102310-23112311-/* hashes.c */23122312-__u32 keyed_hash(const signed char *msg, int len);23132313-__u32 yura_hash(const signed char *msg, int len);23142314-__u32 r5_hash(const signed char *msg, int len);23152315-23162316-#define reiserfs_set_le_bit __set_bit_le23172317-#define reiserfs_test_and_set_le_bit __test_and_set_bit_le23182318-#define reiserfs_clear_le_bit __clear_bit_le23192319-#define reiserfs_test_and_clear_le_bit __test_and_clear_bit_le23202320-#define reiserfs_test_le_bit test_bit_le23212321-#define reiserfs_find_next_zero_le_bit find_next_zero_bit_le23222322-23232323-/* sometimes reiserfs_truncate may require to allocate few new blocks23242324- to perform indirect2direct conversion. People probably used to23252325- think, that truncate should work without problems on a filesystem23262326- without free disk space. They may complain that they can not23272327- truncate due to lack of free disk space. This spare space allows us23282328- to not worry about it. 500 is probably too much, but it should be23292329- absolutely safe */23302330-#define SPARE_SPACE 50023312331-23322332-/* prototypes from ioctl.c */23332333-long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);23342334-long reiserfs_compat_ioctl(struct file *filp,23352335- unsigned int cmd, unsigned long arg);23362336-int reiserfs_unpack(struct inode *inode, struct file *filp);23372337-23382338-#endif /* __KERNEL__ */233945234046#endif /* _LINUX_REISER_FS_H */