0001
0002
0003
0004
0005
0006
0007 #include <linux/reiserfs_fs.h>
0008
0009 #include <linux/slab.h>
0010 #include <linux/interrupt.h>
0011 #include <linux/sched.h>
0012 #include <linux/bug.h>
0013 #include <linux/workqueue.h>
0014 #include <asm/unaligned.h>
0015 #include <linux/bitops.h>
0016 #include <linux/proc_fs.h>
0017 #include <linux/buffer_head.h>
0018
0019
0020 #define REISERFS_IOC32_UNPACK _IOW(0xCD, 1, int)
0021 #define REISERFS_IOC32_GETVERSION FS_IOC32_GETVERSION
0022 #define REISERFS_IOC32_SETVERSION FS_IOC32_SETVERSION
0023
0024 struct reiserfs_journal_list;
0025
0026
0027 typedef enum {
0028
0029
0030
0031
0032 i_item_key_version_mask = 0x0001,
0033
0034
0035
0036
0037
0038 i_stat_data_version_mask = 0x0002,
0039
0040
0041 i_pack_on_close_mask = 0x0004,
0042
0043
0044 i_nopack_mask = 0x0008,
0045
0046
0047
0048
0049
0050
0051 i_link_saved_unlink_mask = 0x0010,
0052 i_link_saved_truncate_mask = 0x0020,
0053
0054 i_has_xattr_dir = 0x0040,
0055 i_data_log = 0x0080,
0056 } reiserfs_inode_flags;
0057
0058 struct reiserfs_inode_info {
0059 __u32 i_key[4];
0060
0061
0062
0063
0064
0065 __u32 i_flags;
0066
0067
0068 __u32 i_first_direct_byte;
0069
0070
0071 __u32 i_attrs;
0072
0073
0074 int i_prealloc_block;
0075 int i_prealloc_count;
0076
0077
0078 struct list_head i_prealloc_list;
0079
0080
0081
0082
0083
0084 unsigned new_packing_locality:1;
0085
0086
0087
0088
0089
0090
0091 unsigned int i_trans_id;
0092
0093 struct reiserfs_journal_list *i_jl;
0094 atomic_t openers;
0095 struct mutex tailpack;
0096 #ifdef CONFIG_REISERFS_FS_XATTR
0097 struct rw_semaphore i_xattr_sem;
0098 #endif
0099 #ifdef CONFIG_QUOTA
0100 struct dquot *i_dquot[MAXQUOTAS];
0101 #endif
0102
0103 struct inode vfs_inode;
0104 };
0105
0106 typedef enum {
0107 reiserfs_attrs_cleared = 0x00000001,
0108 } reiserfs_super_block_flags;
0109
0110
0111
0112
0113
0114 #define sb_block_count(sbp) (le32_to_cpu((sbp)->s_v1.s_block_count))
0115 #define set_sb_block_count(sbp,v) ((sbp)->s_v1.s_block_count = cpu_to_le32(v))
0116 #define sb_free_blocks(sbp) (le32_to_cpu((sbp)->s_v1.s_free_blocks))
0117 #define set_sb_free_blocks(sbp,v) ((sbp)->s_v1.s_free_blocks = cpu_to_le32(v))
0118 #define sb_root_block(sbp) (le32_to_cpu((sbp)->s_v1.s_root_block))
0119 #define set_sb_root_block(sbp,v) ((sbp)->s_v1.s_root_block = cpu_to_le32(v))
0120
0121 #define sb_jp_journal_1st_block(sbp) \
0122 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_1st_block))
0123 #define set_sb_jp_journal_1st_block(sbp,v) \
0124 ((sbp)->s_v1.s_journal.jp_journal_1st_block = cpu_to_le32(v))
0125 #define sb_jp_journal_dev(sbp) \
0126 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_dev))
0127 #define set_sb_jp_journal_dev(sbp,v) \
0128 ((sbp)->s_v1.s_journal.jp_journal_dev = cpu_to_le32(v))
0129 #define sb_jp_journal_size(sbp) \
0130 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_size))
0131 #define set_sb_jp_journal_size(sbp,v) \
0132 ((sbp)->s_v1.s_journal.jp_journal_size = cpu_to_le32(v))
0133 #define sb_jp_journal_trans_max(sbp) \
0134 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_trans_max))
0135 #define set_sb_jp_journal_trans_max(sbp,v) \
0136 ((sbp)->s_v1.s_journal.jp_journal_trans_max = cpu_to_le32(v))
0137 #define sb_jp_journal_magic(sbp) \
0138 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_magic))
0139 #define set_sb_jp_journal_magic(sbp,v) \
0140 ((sbp)->s_v1.s_journal.jp_journal_magic = cpu_to_le32(v))
0141 #define sb_jp_journal_max_batch(sbp) \
0142 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_max_batch))
0143 #define set_sb_jp_journal_max_batch(sbp,v) \
0144 ((sbp)->s_v1.s_journal.jp_journal_max_batch = cpu_to_le32(v))
0145 #define sb_jp_jourmal_max_commit_age(sbp) \
0146 (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_max_commit_age))
0147 #define set_sb_jp_journal_max_commit_age(sbp,v) \
0148 ((sbp)->s_v1.s_journal.jp_journal_max_commit_age = cpu_to_le32(v))
0149
0150 #define sb_blocksize(sbp) (le16_to_cpu((sbp)->s_v1.s_blocksize))
0151 #define set_sb_blocksize(sbp,v) ((sbp)->s_v1.s_blocksize = cpu_to_le16(v))
0152 #define sb_oid_maxsize(sbp) (le16_to_cpu((sbp)->s_v1.s_oid_maxsize))
0153 #define set_sb_oid_maxsize(sbp,v) ((sbp)->s_v1.s_oid_maxsize = cpu_to_le16(v))
0154 #define sb_oid_cursize(sbp) (le16_to_cpu((sbp)->s_v1.s_oid_cursize))
0155 #define set_sb_oid_cursize(sbp,v) ((sbp)->s_v1.s_oid_cursize = cpu_to_le16(v))
0156 #define sb_umount_state(sbp) (le16_to_cpu((sbp)->s_v1.s_umount_state))
0157 #define set_sb_umount_state(sbp,v) ((sbp)->s_v1.s_umount_state = cpu_to_le16(v))
0158 #define sb_fs_state(sbp) (le16_to_cpu((sbp)->s_v1.s_fs_state))
0159 #define set_sb_fs_state(sbp,v) ((sbp)->s_v1.s_fs_state = cpu_to_le16(v))
0160 #define sb_hash_function_code(sbp) \
0161 (le32_to_cpu((sbp)->s_v1.s_hash_function_code))
0162 #define set_sb_hash_function_code(sbp,v) \
0163 ((sbp)->s_v1.s_hash_function_code = cpu_to_le32(v))
0164 #define sb_tree_height(sbp) (le16_to_cpu((sbp)->s_v1.s_tree_height))
0165 #define set_sb_tree_height(sbp,v) ((sbp)->s_v1.s_tree_height = cpu_to_le16(v))
0166 #define sb_bmap_nr(sbp) (le16_to_cpu((sbp)->s_v1.s_bmap_nr))
0167 #define set_sb_bmap_nr(sbp,v) ((sbp)->s_v1.s_bmap_nr = cpu_to_le16(v))
0168 #define sb_version(sbp) (le16_to_cpu((sbp)->s_v1.s_version))
0169 #define set_sb_version(sbp,v) ((sbp)->s_v1.s_version = cpu_to_le16(v))
0170
0171 #define sb_mnt_count(sbp) (le16_to_cpu((sbp)->s_mnt_count))
0172 #define set_sb_mnt_count(sbp, v) ((sbp)->s_mnt_count = cpu_to_le16(v))
0173
0174 #define sb_reserved_for_journal(sbp) \
0175 (le16_to_cpu((sbp)->s_v1.s_reserved_for_journal))
0176 #define set_sb_reserved_for_journal(sbp,v) \
0177 ((sbp)->s_v1.s_reserved_for_journal = cpu_to_le16(v))
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207 #define JOURNAL_BLOCK_SIZE 4096
0208 #define JOURNAL_MAX_CNODE 1500
0209 #define JOURNAL_HASH_SIZE 8192
0210
0211
0212 #define JOURNAL_NUM_BITMAPS 5
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224 struct reiserfs_journal_cnode {
0225 struct buffer_head *bh;
0226 struct super_block *sb;
0227
0228
0229 __u32 blocknr;
0230
0231 unsigned long state;
0232
0233
0234 struct reiserfs_journal_list *jlist;
0235
0236 struct reiserfs_journal_cnode *next;
0237 struct reiserfs_journal_cnode *prev;
0238 struct reiserfs_journal_cnode *hprev;
0239 struct reiserfs_journal_cnode *hnext;
0240 };
0241
0242 struct reiserfs_bitmap_node {
0243 int id;
0244 char *data;
0245 struct list_head list;
0246 };
0247
0248 struct reiserfs_list_bitmap {
0249 struct reiserfs_journal_list *journal_list;
0250 struct reiserfs_bitmap_node **bitmaps;
0251 };
0252
0253
0254
0255
0256
0257
0258
0259
0260 struct reiserfs_journal_list {
0261 unsigned long j_start;
0262 unsigned long j_state;
0263 unsigned long j_len;
0264 atomic_t j_nonzerolen;
0265 atomic_t j_commit_left;
0266
0267
0268 atomic_t j_older_commits_done;
0269
0270 struct mutex j_commit_mutex;
0271 unsigned int j_trans_id;
0272 time64_t j_timestamp;
0273 struct reiserfs_list_bitmap *j_list_bitmap;
0274 struct buffer_head *j_commit_bh;
0275 struct reiserfs_journal_cnode *j_realblock;
0276 struct reiserfs_journal_cnode *j_freedlist;
0277
0278 struct list_head j_list;
0279
0280
0281
0282
0283
0284 struct list_head j_working_list;
0285
0286
0287 struct list_head j_tail_bh_list;
0288
0289
0290 struct list_head j_bh_list;
0291 int j_refcount;
0292 };
0293
0294 struct reiserfs_journal {
0295 struct buffer_head **j_ap_blocks;
0296
0297 struct reiserfs_journal_cnode *j_last;
0298
0299
0300 struct reiserfs_journal_cnode *j_first;
0301
0302 struct block_device *j_dev_bd;
0303 fmode_t j_dev_mode;
0304
0305
0306 int j_1st_reserved_block;
0307
0308 unsigned long j_state;
0309 unsigned int j_trans_id;
0310 unsigned long j_mount_id;
0311
0312
0313 unsigned long j_start;
0314 unsigned long j_len;
0315
0316
0317 unsigned long j_len_alloc;
0318
0319 atomic_t j_wcount;
0320
0321
0322 unsigned long j_bcount;
0323
0324
0325 unsigned long j_first_unflushed_offset;
0326
0327
0328 unsigned j_last_flush_trans_id;
0329
0330 struct buffer_head *j_header_bh;
0331
0332 time64_t j_trans_start_time;
0333 struct mutex j_mutex;
0334 struct mutex j_flush_mutex;
0335
0336
0337 wait_queue_head_t j_join_wait;
0338
0339 atomic_t j_jlock;
0340 int j_list_bitmap_index;
0341
0342
0343 int j_must_wait;
0344
0345
0346 int j_next_full_flush;
0347
0348
0349 int j_next_async_flush;
0350
0351 int j_cnode_used;
0352 int j_cnode_free;
0353
0354
0355 unsigned int j_trans_max;
0356
0357
0358 unsigned int j_max_batch;
0359
0360
0361 unsigned int j_max_commit_age;
0362
0363
0364 unsigned int j_max_trans_age;
0365
0366
0367 unsigned int j_default_max_commit_age;
0368
0369 struct reiserfs_journal_cnode *j_cnode_free_list;
0370
0371
0372 struct reiserfs_journal_cnode *j_cnode_free_orig;
0373
0374 struct reiserfs_journal_list *j_current_jl;
0375 int j_free_bitmap_nodes;
0376 int j_used_bitmap_nodes;
0377
0378 int j_num_lists;
0379 int j_num_work_lists;
0380
0381
0382 unsigned int j_last_flush_id;
0383
0384
0385 unsigned int j_last_commit_id;
0386
0387 struct list_head j_bitmap_nodes;
0388 struct list_head j_dirty_buffers;
0389 spinlock_t j_dirty_buffers_lock;
0390
0391
0392 struct list_head j_journal_list;
0393
0394
0395 struct list_head j_working_list;
0396
0397
0398 struct reiserfs_journal_cnode *j_hash_table[JOURNAL_HASH_SIZE];
0399
0400
0401 struct reiserfs_journal_cnode *j_list_hash_table[JOURNAL_HASH_SIZE];
0402
0403
0404 struct reiserfs_list_bitmap j_list_bitmap[JOURNAL_NUM_BITMAPS];
0405
0406
0407 struct list_head j_prealloc_list;
0408 int j_persistent_trans;
0409 unsigned long j_max_trans_size;
0410 unsigned long j_max_batch_size;
0411
0412 int j_errno;
0413
0414
0415 struct delayed_work j_work;
0416 struct super_block *j_work_sb;
0417 atomic_t j_async_throttle;
0418 };
0419
0420 enum journal_state_bits {
0421 J_WRITERS_BLOCKED = 1,
0422 J_WRITERS_QUEUED,
0423 J_ABORTED,
0424 };
0425
0426
0427 #define JOURNAL_DESC_MAGIC "ReIsErLB"
0428
0429 typedef __u32(*hashf_t) (const signed char *, int);
0430
0431 struct reiserfs_bitmap_info {
0432 __u32 free_count;
0433 };
0434
0435 struct proc_dir_entry;
0436
0437 #if defined( CONFIG_PROC_FS ) && defined( CONFIG_REISERFS_PROC_INFO )
0438 typedef unsigned long int stat_cnt_t;
0439 typedef struct reiserfs_proc_info_data {
0440 spinlock_t lock;
0441 int exiting;
0442 int max_hash_collisions;
0443
0444 stat_cnt_t breads;
0445 stat_cnt_t bread_miss;
0446 stat_cnt_t search_by_key;
0447 stat_cnt_t search_by_key_fs_changed;
0448 stat_cnt_t search_by_key_restarted;
0449
0450 stat_cnt_t insert_item_restarted;
0451 stat_cnt_t paste_into_item_restarted;
0452 stat_cnt_t cut_from_item_restarted;
0453 stat_cnt_t delete_solid_item_restarted;
0454 stat_cnt_t delete_item_restarted;
0455
0456 stat_cnt_t leaked_oid;
0457 stat_cnt_t leaves_removable;
0458
0459
0460
0461
0462
0463 stat_cnt_t balance_at[5];
0464
0465 stat_cnt_t sbk_read_at[5];
0466 stat_cnt_t sbk_fs_changed[5];
0467 stat_cnt_t sbk_restarted[5];
0468 stat_cnt_t items_at[5];
0469 stat_cnt_t free_at[5];
0470 stat_cnt_t can_node_be_removed[5];
0471 long int lnum[5];
0472 long int rnum[5];
0473 long int lbytes[5];
0474 long int rbytes[5];
0475 stat_cnt_t get_neighbors[5];
0476 stat_cnt_t get_neighbors_restart[5];
0477 stat_cnt_t need_l_neighbor[5];
0478 stat_cnt_t need_r_neighbor[5];
0479
0480 stat_cnt_t free_block;
0481 struct __scan_bitmap_stats {
0482 stat_cnt_t call;
0483 stat_cnt_t wait;
0484 stat_cnt_t bmap;
0485 stat_cnt_t retry;
0486 stat_cnt_t in_journal_hint;
0487 stat_cnt_t in_journal_nohint;
0488 stat_cnt_t stolen;
0489 } scan_bitmap;
0490 struct __journal_stats {
0491 stat_cnt_t in_journal;
0492 stat_cnt_t in_journal_bitmap;
0493 stat_cnt_t in_journal_reusable;
0494 stat_cnt_t lock_journal;
0495 stat_cnt_t lock_journal_wait;
0496 stat_cnt_t journal_being;
0497 stat_cnt_t journal_relock_writers;
0498 stat_cnt_t journal_relock_wcount;
0499 stat_cnt_t mark_dirty;
0500 stat_cnt_t mark_dirty_already;
0501 stat_cnt_t mark_dirty_notjournal;
0502 stat_cnt_t restore_prepared;
0503 stat_cnt_t prepare;
0504 stat_cnt_t prepare_retry;
0505 } journal;
0506 } reiserfs_proc_info_data_t;
0507 #else
0508 typedef struct reiserfs_proc_info_data {
0509 } reiserfs_proc_info_data_t;
0510 #endif
0511
0512
0513 #define REISERFS_MAXQUOTAS 2
0514
0515
0516 struct reiserfs_sb_info {
0517
0518 struct buffer_head *s_sbh;
0519
0520
0521 struct reiserfs_super_block *s_rs;
0522 struct reiserfs_bitmap_info *s_ap_bitmap;
0523
0524
0525 struct reiserfs_journal *s_journal;
0526
0527 unsigned short s_mount_state;
0528
0529
0530 struct mutex lock;
0531
0532
0533 struct task_struct *lock_owner;
0534
0535
0536 int lock_depth;
0537
0538 struct workqueue_struct *commit_wq;
0539
0540
0541 void (*end_io_handler) (struct buffer_head *, int);
0542
0543
0544
0545
0546
0547 hashf_t s_hash_function;
0548
0549
0550 unsigned long s_mount_opt;
0551
0552
0553 struct {
0554
0555 unsigned long bits;
0556
0557
0558
0559
0560
0561 unsigned long large_file_size;
0562
0563 int border;
0564
0565
0566
0567
0568
0569 int preallocmin;
0570
0571
0572
0573
0574
0575
0576 int preallocsize;
0577 } s_alloc_options;
0578
0579
0580 wait_queue_head_t s_wait;
0581
0582 atomic_t s_generation_counter;
0583
0584
0585 unsigned long s_properties;
0586
0587
0588 int s_disk_reads;
0589 int s_disk_writes;
0590 int s_fix_nodes;
0591 int s_do_balance;
0592 int s_unneeded_left_neighbor;
0593 int s_good_search_by_key_reada;
0594 int s_bmaps;
0595 int s_bmaps_without_search;
0596 int s_direct2indirect;
0597 int s_indirect2direct;
0598
0599
0600
0601
0602
0603
0604 int s_is_unlinked_ok;
0605
0606 reiserfs_proc_info_data_t s_proc_info_data;
0607 struct proc_dir_entry *procdir;
0608
0609
0610 int reserved_blocks;
0611
0612
0613
0614 spinlock_t bitmap_lock;
0615 struct dentry *priv_root;
0616 struct dentry *xattr_root;
0617 int j_errno;
0618
0619 int work_queued;
0620 struct delayed_work old_work;
0621 spinlock_t old_work_lock;
0622
0623 #ifdef CONFIG_QUOTA
0624 char *s_qf_names[REISERFS_MAXQUOTAS];
0625 int s_jquota_fmt;
0626 #endif
0627 char *s_jdev;
0628 #ifdef CONFIG_REISERFS_CHECK
0629
0630
0631
0632
0633
0634
0635
0636 struct tree_balance *cur_tb;
0637 #endif
0638 };
0639
0640
0641 #define REISERFS_3_5 0
0642 #define REISERFS_3_6 1
0643 #define REISERFS_OLD_FORMAT 2
0644
0645
0646 enum reiserfs_mount_options {
0647
0648 REISERFS_LARGETAIL,
0649
0650
0651
0652
0653 REISERFS_SMALLTAIL,
0654
0655
0656 REPLAYONLY,
0657
0658
0659
0660
0661
0662
0663 REISERFS_CONVERT,
0664
0665
0666
0667
0668
0669
0670
0671
0672
0673
0674
0675 FORCE_TEA_HASH,
0676 FORCE_RUPASOV_HASH,
0677 FORCE_R5_HASH,
0678 FORCE_HASH_DETECT,
0679
0680 REISERFS_DATA_LOG,
0681 REISERFS_DATA_ORDERED,
0682 REISERFS_DATA_WRITEBACK,
0683
0684
0685
0686
0687
0688
0689
0690 REISERFS_NO_BORDER,
0691 REISERFS_NO_UNHASHED_RELOCATION,
0692 REISERFS_HASHED_RELOCATION,
0693 REISERFS_ATTRS,
0694 REISERFS_XATTRS_USER,
0695 REISERFS_POSIXACL,
0696 REISERFS_EXPOSE_PRIVROOT,
0697 REISERFS_BARRIER_NONE,
0698 REISERFS_BARRIER_FLUSH,
0699
0700
0701 REISERFS_ERROR_PANIC,
0702 REISERFS_ERROR_RO,
0703 REISERFS_ERROR_CONTINUE,
0704
0705 REISERFS_USRQUOTA,
0706 REISERFS_GRPQUOTA,
0707
0708 REISERFS_TEST1,
0709 REISERFS_TEST2,
0710 REISERFS_TEST3,
0711 REISERFS_TEST4,
0712 REISERFS_UNSUPPORTED_OPT,
0713 };
0714
0715 #define reiserfs_r5_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_R5_HASH))
0716 #define reiserfs_rupasov_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_RUPASOV_HASH))
0717 #define reiserfs_tea_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_TEA_HASH))
0718 #define reiserfs_hash_detect(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_HASH_DETECT))
0719 #define reiserfs_no_border(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_NO_BORDER))
0720 #define reiserfs_no_unhashed_relocation(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_NO_UNHASHED_RELOCATION))
0721 #define reiserfs_hashed_relocation(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_HASHED_RELOCATION))
0722 #define reiserfs_test4(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TEST4))
0723
0724 #define have_large_tails(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_LARGETAIL))
0725 #define have_small_tails(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_SMALLTAIL))
0726 #define replay_only(s) (REISERFS_SB(s)->s_mount_opt & (1 << REPLAYONLY))
0727 #define reiserfs_attrs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ATTRS))
0728 #define old_format_only(s) (REISERFS_SB(s)->s_properties & (1 << REISERFS_3_5))
0729 #define convert_reiserfs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_CONVERT))
0730 #define reiserfs_data_log(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_LOG))
0731 #define reiserfs_data_ordered(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_ORDERED))
0732 #define reiserfs_data_writeback(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_WRITEBACK))
0733 #define reiserfs_xattrs_user(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_XATTRS_USER))
0734 #define reiserfs_posixacl(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_POSIXACL))
0735 #define reiserfs_expose_privroot(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_EXPOSE_PRIVROOT))
0736 #define reiserfs_xattrs_optional(s) (reiserfs_xattrs_user(s) || reiserfs_posixacl(s))
0737 #define reiserfs_barrier_none(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_BARRIER_NONE))
0738 #define reiserfs_barrier_flush(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_BARRIER_FLUSH))
0739
0740 #define reiserfs_error_panic(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_PANIC))
0741 #define reiserfs_error_ro(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_RO))
0742
0743 void reiserfs_file_buffer(struct buffer_head *bh, int list);
0744 extern struct file_system_type reiserfs_fs_type;
0745 int reiserfs_resize(struct super_block *, unsigned long);
0746
0747 #define CARRY_ON 0
0748 #define SCHEDULE_OCCURRED 1
0749
0750 #define SB_BUFFER_WITH_SB(s) (REISERFS_SB(s)->s_sbh)
0751 #define SB_JOURNAL(s) (REISERFS_SB(s)->s_journal)
0752 #define SB_JOURNAL_1st_RESERVED_BLOCK(s) (SB_JOURNAL(s)->j_1st_reserved_block)
0753 #define SB_JOURNAL_LEN_FREE(s) (SB_JOURNAL(s)->j_journal_len_free)
0754 #define SB_AP_BITMAP(s) (REISERFS_SB(s)->s_ap_bitmap)
0755
0756 #define SB_DISK_JOURNAL_HEAD(s) (SB_JOURNAL(s)->j_header_bh->)
0757
0758 #define reiserfs_is_journal_aborted(journal) (unlikely (__reiserfs_is_journal_aborted (journal)))
0759 static inline int __reiserfs_is_journal_aborted(struct reiserfs_journal
0760 *journal)
0761 {
0762 return test_bit(J_ABORTED, &journal->j_state);
0763 }
0764
0765
0766
0767
0768
0769
0770 void reiserfs_write_lock(struct super_block *s);
0771 void reiserfs_write_unlock(struct super_block *s);
0772 int __must_check reiserfs_write_unlock_nested(struct super_block *s);
0773 void reiserfs_write_lock_nested(struct super_block *s, int depth);
0774
0775 #ifdef CONFIG_REISERFS_CHECK
0776 void reiserfs_lock_check_recursive(struct super_block *s);
0777 #else
0778 static inline void reiserfs_lock_check_recursive(struct super_block *s) { }
0779 #endif
0780
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792
0793
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808 static inline void reiserfs_mutex_lock_safe(struct mutex *m,
0809 struct super_block *s)
0810 {
0811 int depth;
0812
0813 depth = reiserfs_write_unlock_nested(s);
0814 mutex_lock(m);
0815 reiserfs_write_lock_nested(s, depth);
0816 }
0817
0818 static inline void
0819 reiserfs_mutex_lock_nested_safe(struct mutex *m, unsigned int subclass,
0820 struct super_block *s)
0821 {
0822 int depth;
0823
0824 depth = reiserfs_write_unlock_nested(s);
0825 mutex_lock_nested(m, subclass);
0826 reiserfs_write_lock_nested(s, depth);
0827 }
0828
0829 static inline void
0830 reiserfs_down_read_safe(struct rw_semaphore *sem, struct super_block *s)
0831 {
0832 int depth;
0833 depth = reiserfs_write_unlock_nested(s);
0834 down_read(sem);
0835 reiserfs_write_lock_nested(s, depth);
0836 }
0837
0838
0839
0840
0841
0842 static inline void reiserfs_cond_resched(struct super_block *s)
0843 {
0844 if (need_resched()) {
0845 int depth;
0846
0847 depth = reiserfs_write_unlock_nested(s);
0848 schedule();
0849 reiserfs_write_lock_nested(s, depth);
0850 }
0851 }
0852
0853 struct fid;
0854
0855
0856
0857
0858
0859
0860
0861
0862
0863
0864
0865
0866
0867
0868
0869
0870
0871
0872
0873
0874
0875
0876
0877
0878 #define USE_INODE_GENERATION_COUNTER
0879
0880 #define REISERFS_PREALLOCATE
0881 #define DISPLACE_NEW_PACKING_LOCALITIES
0882 #define PREALLOCATION_SIZE 9
0883
0884
0885 #define _ROUND_UP(x,n) (((x)+(n)-1u) & ~((n)-1u))
0886
0887
0888
0889
0890
0891
0892 #define ROUND_UP(x) _ROUND_UP(x,8LL)
0893
0894
0895
0896
0897
0898 #define REISERFS_DEBUG_CODE 5
0899
0900 void __reiserfs_warning(struct super_block *s, const char *id,
0901 const char *func, const char *fmt, ...);
0902 #define reiserfs_warning(s, id, fmt, args...) \
0903 __reiserfs_warning(s, id, __func__, fmt, ##args)
0904
0905
0906
0907 #define __RASSERT(cond, scond, format, args...) \
0908 do { \
0909 if (!(cond)) \
0910 reiserfs_panic(NULL, "assertion failure", "(" #cond ") at " \
0911 __FILE__ ":%i:%s: " format "\n", \
0912 __LINE__, __func__ , ##args); \
0913 } while (0)
0914
0915 #define RASSERT(cond, format, args...) __RASSERT(cond, #cond, format, ##args)
0916
0917 #if defined( CONFIG_REISERFS_CHECK )
0918 #define RFALSE(cond, format, args...) __RASSERT(!(cond), "!(" #cond ")", format, ##args)
0919 #else
0920 #define RFALSE( cond, format, args... ) do {;} while( 0 )
0921 #endif
0922
0923 #define CONSTF __attribute_const__
0924
0925
0926
0927
0928
0929
0930
0931
0932
0933
0934
0935
0936
0937 #define UNSET_HASH 0
0938 #define TEA_HASH 1
0939 #define YURA_HASH 2
0940 #define R5_HASH 3
0941 #define DEFAULT_HASH R5_HASH
0942
0943 struct journal_params {
0944
0945 __le32 jp_journal_1st_block;
0946
0947
0948 __le32 jp_journal_dev;
0949
0950
0951 __le32 jp_journal_size;
0952
0953
0954 __le32 jp_journal_trans_max;
0955
0956
0957
0958
0959
0960 __le32 jp_journal_magic;
0961
0962
0963 __le32 jp_journal_max_batch;
0964
0965
0966 __le32 jp_journal_max_commit_age;
0967
0968
0969 __le32 jp_journal_max_trans_age;
0970 };
0971
0972
0973 struct reiserfs_super_block_v1 {
0974 __le32 s_block_count;
0975 __le32 s_free_blocks;
0976 __le32 s_root_block;
0977 struct journal_params s_journal;
0978 __le16 s_blocksize;
0979
0980
0981 __le16 s_oid_maxsize;
0982 __le16 s_oid_cursize;
0983
0984
0985 __le16 s_umount_state;
0986
0987
0988
0989
0990
0991 char s_magic[10];
0992
0993
0994
0995
0996
0997 __le16 s_fs_state;
0998
0999
1000
1001
1002 __le32 s_hash_function_code;
1003 __le16 s_tree_height;
1004
1005
1006
1007
1008
1009 __le16 s_bmap_nr;
1010
1011
1012
1013
1014 __le16 s_version;
1015
1016
1017
1018
1019
1020 __le16 s_reserved_for_journal;
1021 } __attribute__ ((__packed__));
1022
1023 #define SB_SIZE_V1 (sizeof(struct reiserfs_super_block_v1))
1024
1025
1026 struct reiserfs_super_block {
1027 struct reiserfs_super_block_v1 s_v1;
1028 __le32 s_inode_generation;
1029
1030
1031 __le32 s_flags;
1032
1033 unsigned char s_uuid[16];
1034 unsigned char s_label[16];
1035 __le16 s_mnt_count;
1036 __le16 s_max_mnt_count;
1037 __le32 s_lastcheck;
1038 __le32 s_check_interval;
1039
1040
1041
1042
1043 char s_unused[76];
1044 } __attribute__ ((__packed__));
1045
1046 #define SB_SIZE (sizeof(struct reiserfs_super_block))
1047
1048 #define REISERFS_VERSION_1 0
1049 #define REISERFS_VERSION_2 2
1050
1051
1052 #define SB_DISK_SUPER_BLOCK(s) (REISERFS_SB(s)->s_rs)
1053 #define SB_V1_DISK_SUPER_BLOCK(s) (&(SB_DISK_SUPER_BLOCK(s)->s_v1))
1054 #define SB_BLOCKSIZE(s) \
1055 le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_blocksize))
1056 #define SB_BLOCK_COUNT(s) \
1057 le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_block_count))
1058 #define SB_FREE_BLOCKS(s) \
1059 le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_free_blocks))
1060 #define SB_REISERFS_MAGIC(s) \
1061 (SB_V1_DISK_SUPER_BLOCK(s)->s_magic)
1062 #define SB_ROOT_BLOCK(s) \
1063 le32_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_root_block))
1064 #define SB_TREE_HEIGHT(s) \
1065 le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height))
1066 #define SB_REISERFS_STATE(s) \
1067 le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state))
1068 #define SB_VERSION(s) le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_version))
1069 #define SB_BMAP_NR(s) le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr))
1070
1071 #define PUT_SB_BLOCK_COUNT(s, val) \
1072 do { SB_V1_DISK_SUPER_BLOCK(s)->s_block_count = cpu_to_le32(val); } while (0)
1073 #define PUT_SB_FREE_BLOCKS(s, val) \
1074 do { SB_V1_DISK_SUPER_BLOCK(s)->s_free_blocks = cpu_to_le32(val); } while (0)
1075 #define PUT_SB_ROOT_BLOCK(s, val) \
1076 do { SB_V1_DISK_SUPER_BLOCK(s)->s_root_block = cpu_to_le32(val); } while (0)
1077 #define PUT_SB_TREE_HEIGHT(s, val) \
1078 do { SB_V1_DISK_SUPER_BLOCK(s)->s_tree_height = cpu_to_le16(val); } while (0)
1079 #define PUT_SB_REISERFS_STATE(s, val) \
1080 do { SB_V1_DISK_SUPER_BLOCK(s)->s_umount_state = cpu_to_le16(val); } while (0)
1081 #define PUT_SB_VERSION(s, val) \
1082 do { SB_V1_DISK_SUPER_BLOCK(s)->s_version = cpu_to_le16(val); } while (0)
1083 #define PUT_SB_BMAP_NR(s, val) \
1084 do { SB_V1_DISK_SUPER_BLOCK(s)->s_bmap_nr = cpu_to_le16 (val); } while (0)
1085
1086 #define SB_ONDISK_JP(s) (&SB_V1_DISK_SUPER_BLOCK(s)->s_journal)
1087 #define SB_ONDISK_JOURNAL_SIZE(s) \
1088 le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_size))
1089 #define SB_ONDISK_JOURNAL_1st_BLOCK(s) \
1090 le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_1st_block))
1091 #define SB_ONDISK_JOURNAL_DEVICE(s) \
1092 le32_to_cpu ((SB_ONDISK_JP(s)->jp_journal_dev))
1093 #define SB_ONDISK_RESERVED_FOR_JOURNAL(s) \
1094 le16_to_cpu ((SB_V1_DISK_SUPER_BLOCK(s)->s_reserved_for_journal))
1095
1096 #define is_block_in_log_or_reserved_area(s, block) \
1097 block >= SB_JOURNAL_1st_RESERVED_BLOCK(s) \
1098 && block < SB_JOURNAL_1st_RESERVED_BLOCK(s) + \
1099 ((!is_reiserfs_jr(SB_DISK_SUPER_BLOCK(s)) ? \
1100 SB_ONDISK_JOURNAL_SIZE(s) + 1 : SB_ONDISK_RESERVED_FOR_JOURNAL(s)))
1101
1102 int is_reiserfs_3_5(struct reiserfs_super_block *rs);
1103 int is_reiserfs_3_6(struct reiserfs_super_block *rs);
1104 int is_reiserfs_jr(struct reiserfs_super_block *rs);
1105
1106
1107
1108
1109
1110
1111
1112
1113 #define REISERFS_DISK_OFFSET_IN_BYTES (64 * 1024)
1114 #define REISERFS_FIRST_BLOCK unused_define
1115 #define REISERFS_JOURNAL_OFFSET_IN_BYTES REISERFS_DISK_OFFSET_IN_BYTES
1116
1117
1118 #define REISERFS_OLD_DISK_OFFSET_IN_BYTES (8 * 1024)
1119
1120
1121 #define CARRY_ON 0
1122 #define REPEAT_SEARCH -1
1123 #define IO_ERROR -2
1124 #define NO_DISK_SPACE -3
1125 #define NO_BALANCING_NEEDED (-4)
1126 #define NO_MORE_UNUSED_CONTIGUOUS_BLOCKS (-5)
1127 #define QUOTA_EXCEEDED -6
1128
1129 typedef __u32 b_blocknr_t;
1130 typedef __le32 unp_t;
1131
1132 struct unfm_nodeinfo {
1133 unp_t unfm_nodenum;
1134 unsigned short unfm_freespace;
1135 };
1136
1137
1138 #define KEY_FORMAT_3_5 0
1139 #define KEY_FORMAT_3_6 1
1140
1141
1142 #define STAT_DATA_V1 0
1143 #define STAT_DATA_V2 1
1144
1145 static inline struct reiserfs_inode_info *REISERFS_I(const struct inode *inode)
1146 {
1147 return container_of(inode, struct reiserfs_inode_info, vfs_inode);
1148 }
1149
1150 static inline struct reiserfs_sb_info *REISERFS_SB(const struct super_block *sb)
1151 {
1152 return sb->s_fs_info;
1153 }
1154
1155
1156
1157
1158
1159 static inline __u32 reiserfs_bmap_count(struct super_block *sb)
1160 {
1161 return (SB_BLOCK_COUNT(sb) - 1) / (sb->s_blocksize * 8) + 1;
1162 }
1163
1164 static inline int bmap_would_wrap(unsigned bmap_nr)
1165 {
1166 return bmap_nr > ((1LL << 16) - 1);
1167 }
1168
1169 extern const struct xattr_handler *reiserfs_xattr_handlers[];
1170
1171
1172
1173
1174
1175 #define get_inode_item_key_version( inode ) \
1176 ((REISERFS_I(inode)->i_flags & i_item_key_version_mask) ? KEY_FORMAT_3_6 : KEY_FORMAT_3_5)
1177
1178 #define set_inode_item_key_version( inode, version ) \
1179 ({ if((version)==KEY_FORMAT_3_6) \
1180 REISERFS_I(inode)->i_flags |= i_item_key_version_mask; \
1181 else \
1182 REISERFS_I(inode)->i_flags &= ~i_item_key_version_mask; })
1183
1184 #define get_inode_sd_version(inode) \
1185 ((REISERFS_I(inode)->i_flags & i_stat_data_version_mask) ? STAT_DATA_V2 : STAT_DATA_V1)
1186
1187 #define set_inode_sd_version(inode, version) \
1188 ({ if((version)==STAT_DATA_V2) \
1189 REISERFS_I(inode)->i_flags |= i_stat_data_version_mask; \
1190 else \
1191 REISERFS_I(inode)->i_flags &= ~i_stat_data_version_mask; })
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205 #define STORE_TAIL_IN_UNFM_S1(n_file_size,n_tail_size,n_block_size) \
1206 (\
1207 (!(n_tail_size)) || \
1208 (((n_tail_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) || \
1209 ( (n_file_size) >= (n_block_size) * 4 ) || \
1210 ( ( (n_file_size) >= (n_block_size) * 3 ) && \
1211 ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size))/4) ) || \
1212 ( ( (n_file_size) >= (n_block_size) * 2 ) && \
1213 ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size))/2) ) || \
1214 ( ( (n_file_size) >= (n_block_size) ) && \
1215 ( (n_tail_size) >= (MAX_DIRECT_ITEM_LEN(n_block_size) * 3)/4) ) ) \
1216 )
1217
1218
1219
1220
1221
1222
1223
1224 #define STORE_TAIL_IN_UNFM_S2(n_file_size,n_tail_size,n_block_size) \
1225 (\
1226 (!(n_tail_size)) || \
1227 (((n_file_size) > MAX_DIRECT_ITEM_LEN(n_block_size)) ) \
1228 )
1229
1230
1231
1232
1233 #define REISERFS_VALID_FS 1
1234 #define REISERFS_ERROR_FS 2
1235
1236
1237
1238
1239 #define TYPE_STAT_DATA 0
1240 #define TYPE_INDIRECT 1
1241 #define TYPE_DIRECT 2
1242 #define TYPE_DIRENTRY 3
1243 #define TYPE_MAXTYPE 3
1244 #define TYPE_ANY 15
1245
1246
1247
1248
1249
1250
1251 struct offset_v1 {
1252 __le32 k_offset;
1253 __le32 k_uniqueness;
1254 } __attribute__ ((__packed__));
1255
1256 struct offset_v2 {
1257 __le64 v;
1258 } __attribute__ ((__packed__));
1259
1260 static inline __u16 offset_v2_k_type(const struct offset_v2 *v2)
1261 {
1262 __u8 type = le64_to_cpu(v2->v) >> 60;
1263 return (type <= TYPE_MAXTYPE) ? type : TYPE_ANY;
1264 }
1265
1266 static inline void set_offset_v2_k_type(struct offset_v2 *v2, int type)
1267 {
1268 v2->v =
1269 (v2->v & cpu_to_le64(~0ULL >> 4)) | cpu_to_le64((__u64) type << 60);
1270 }
1271
1272 static inline loff_t offset_v2_k_offset(const struct offset_v2 *v2)
1273 {
1274 return le64_to_cpu(v2->v) & (~0ULL >> 4);
1275 }
1276
1277 static inline void set_offset_v2_k_offset(struct offset_v2 *v2, loff_t offset)
1278 {
1279 offset &= (~0ULL >> 4);
1280 v2->v = (v2->v & cpu_to_le64(15ULL << 60)) | cpu_to_le64(offset);
1281 }
1282
1283
1284
1285
1286
1287 struct reiserfs_key {
1288
1289 __le32 k_dir_id;
1290
1291 __le32 k_objectid;
1292 union {
1293 struct offset_v1 k_offset_v1;
1294 struct offset_v2 k_offset_v2;
1295 } __attribute__ ((__packed__)) u;
1296 } __attribute__ ((__packed__));
1297
1298 struct in_core_key {
1299
1300 __u32 k_dir_id;
1301 __u32 k_objectid;
1302 __u64 k_offset;
1303 __u8 k_type;
1304 };
1305
1306 struct cpu_key {
1307 struct in_core_key on_disk_key;
1308 int version;
1309
1310 int key_length;
1311 };
1312
1313
1314
1315
1316
1317
1318
1319 #define REISERFS_FULL_KEY_LEN 4
1320 #define REISERFS_SHORT_KEY_LEN 2
1321
1322
1323 #define FIRST_GREATER 1
1324 #define SECOND_GREATER -1
1325 #define KEYS_IDENTICAL 0
1326 #define KEY_FOUND 1
1327 #define KEY_NOT_FOUND 0
1328
1329 #define KEY_SIZE (sizeof(struct reiserfs_key))
1330
1331
1332 #define ITEM_FOUND 1
1333 #define ITEM_NOT_FOUND 0
1334 #define ENTRY_FOUND 1
1335 #define ENTRY_NOT_FOUND 0
1336 #define DIRECTORY_NOT_FOUND -1
1337 #define REGULAR_FILE_FOUND -2
1338 #define DIRECTORY_FOUND -3
1339 #define BYTE_FOUND 1
1340 #define BYTE_NOT_FOUND 0
1341 #define FILE_NOT_FOUND -1
1342
1343 #define POSITION_FOUND 1
1344 #define POSITION_NOT_FOUND 0
1345
1346
1347 #define NAME_FOUND 1
1348 #define NAME_NOT_FOUND 0
1349 #define GOTO_PREVIOUS_ITEM 2
1350 #define NAME_FOUND_INVISIBLE 3
1351
1352
1353
1354
1355
1356
1357
1358
1359 struct item_head {
1360
1361
1362
1363
1364 struct reiserfs_key ih_key;
1365 union {
1366
1367
1368
1369
1370
1371
1372
1373
1374 __le16 ih_free_space_reserved;
1375
1376
1377
1378
1379
1380 __le16 ih_entry_count;
1381 } __attribute__ ((__packed__)) u;
1382 __le16 ih_item_len;
1383
1384
1385 __le16 ih_item_location;
1386
1387
1388
1389
1390
1391 __le16 ih_version;
1392 } __attribute__ ((__packed__));
1393
1394 #define IH_SIZE (sizeof(struct item_head))
1395
1396 #define ih_free_space(ih) le16_to_cpu((ih)->u.ih_free_space_reserved)
1397 #define ih_version(ih) le16_to_cpu((ih)->ih_version)
1398 #define ih_entry_count(ih) le16_to_cpu((ih)->u.ih_entry_count)
1399 #define ih_location(ih) le16_to_cpu((ih)->ih_item_location)
1400 #define ih_item_len(ih) le16_to_cpu((ih)->ih_item_len)
1401
1402 #define put_ih_free_space(ih, val) do { (ih)->u.ih_free_space_reserved = cpu_to_le16(val); } while(0)
1403 #define put_ih_version(ih, val) do { (ih)->ih_version = cpu_to_le16(val); } while (0)
1404 #define put_ih_entry_count(ih, val) do { (ih)->u.ih_entry_count = cpu_to_le16(val); } while (0)
1405 #define put_ih_location(ih, val) do { (ih)->ih_item_location = cpu_to_le16(val); } while (0)
1406 #define put_ih_item_len(ih, val) do { (ih)->ih_item_len = cpu_to_le16(val); } while (0)
1407
1408 #define unreachable_item(ih) (ih_version(ih) & (1 << 15))
1409
1410 #define get_ih_free_space(ih) (ih_version (ih) == KEY_FORMAT_3_6 ? 0 : ih_free_space (ih))
1411 #define set_ih_free_space(ih,val) put_ih_free_space((ih), ((ih_version(ih) == KEY_FORMAT_3_6) ? 0 : (val)))
1412
1413
1414
1415
1416
1417
1418
1419
1420 #define get_block_num(p, i) get_unaligned_le32((p) + (i))
1421 #define put_block_num(p, i, v) put_unaligned_le32((v), (p) + (i))
1422
1423
1424 #define V1_SD_UNIQUENESS 0
1425 #define V1_INDIRECT_UNIQUENESS 0xfffffffe
1426 #define V1_DIRECT_UNIQUENESS 0xffffffff
1427 #define V1_DIRENTRY_UNIQUENESS 500
1428 #define V1_ANY_UNIQUENESS 555
1429
1430
1431 static inline int uniqueness2type(__u32 uniqueness) CONSTF;
1432 static inline int uniqueness2type(__u32 uniqueness)
1433 {
1434 switch ((int)uniqueness) {
1435 case V1_SD_UNIQUENESS:
1436 return TYPE_STAT_DATA;
1437 case V1_INDIRECT_UNIQUENESS:
1438 return TYPE_INDIRECT;
1439 case V1_DIRECT_UNIQUENESS:
1440 return TYPE_DIRECT;
1441 case V1_DIRENTRY_UNIQUENESS:
1442 return TYPE_DIRENTRY;
1443 case V1_ANY_UNIQUENESS:
1444 default:
1445 return TYPE_ANY;
1446 }
1447 }
1448
1449 static inline __u32 type2uniqueness(int type) CONSTF;
1450 static inline __u32 type2uniqueness(int type)
1451 {
1452 switch (type) {
1453 case TYPE_STAT_DATA:
1454 return V1_SD_UNIQUENESS;
1455 case TYPE_INDIRECT:
1456 return V1_INDIRECT_UNIQUENESS;
1457 case TYPE_DIRECT:
1458 return V1_DIRECT_UNIQUENESS;
1459 case TYPE_DIRENTRY:
1460 return V1_DIRENTRY_UNIQUENESS;
1461 case TYPE_ANY:
1462 default:
1463 return V1_ANY_UNIQUENESS;
1464 }
1465 }
1466
1467
1468
1469
1470
1471
1472 static inline loff_t le_key_k_offset(int version,
1473 const struct reiserfs_key *key)
1474 {
1475 return (version == KEY_FORMAT_3_5) ?
1476 le32_to_cpu(key->u.k_offset_v1.k_offset) :
1477 offset_v2_k_offset(&(key->u.k_offset_v2));
1478 }
1479
1480 static inline loff_t le_ih_k_offset(const struct item_head *ih)
1481 {
1482 return le_key_k_offset(ih_version(ih), &(ih->ih_key));
1483 }
1484
1485 static inline loff_t le_key_k_type(int version, const struct reiserfs_key *key)
1486 {
1487 if (version == KEY_FORMAT_3_5) {
1488 loff_t val = le32_to_cpu(key->u.k_offset_v1.k_uniqueness);
1489 return uniqueness2type(val);
1490 } else
1491 return offset_v2_k_type(&(key->u.k_offset_v2));
1492 }
1493
1494 static inline loff_t le_ih_k_type(const struct item_head *ih)
1495 {
1496 return le_key_k_type(ih_version(ih), &(ih->ih_key));
1497 }
1498
1499 static inline void set_le_key_k_offset(int version, struct reiserfs_key *key,
1500 loff_t offset)
1501 {
1502 if (version == KEY_FORMAT_3_5)
1503 key->u.k_offset_v1.k_offset = cpu_to_le32(offset);
1504 else
1505 set_offset_v2_k_offset(&key->u.k_offset_v2, offset);
1506 }
1507
1508 static inline void add_le_key_k_offset(int version, struct reiserfs_key *key,
1509 loff_t offset)
1510 {
1511 set_le_key_k_offset(version, key,
1512 le_key_k_offset(version, key) + offset);
1513 }
1514
1515 static inline void add_le_ih_k_offset(struct item_head *ih, loff_t offset)
1516 {
1517 add_le_key_k_offset(ih_version(ih), &(ih->ih_key), offset);
1518 }
1519
1520 static inline void set_le_ih_k_offset(struct item_head *ih, loff_t offset)
1521 {
1522 set_le_key_k_offset(ih_version(ih), &(ih->ih_key), offset);
1523 }
1524
1525 static inline void set_le_key_k_type(int version, struct reiserfs_key *key,
1526 int type)
1527 {
1528 if (version == KEY_FORMAT_3_5) {
1529 type = type2uniqueness(type);
1530 key->u.k_offset_v1.k_uniqueness = cpu_to_le32(type);
1531 } else
1532 set_offset_v2_k_type(&key->u.k_offset_v2, type);
1533 }
1534
1535 static inline void set_le_ih_k_type(struct item_head *ih, int type)
1536 {
1537 set_le_key_k_type(ih_version(ih), &(ih->ih_key), type);
1538 }
1539
1540 static inline int is_direntry_le_key(int version, struct reiserfs_key *key)
1541 {
1542 return le_key_k_type(version, key) == TYPE_DIRENTRY;
1543 }
1544
1545 static inline int is_direct_le_key(int version, struct reiserfs_key *key)
1546 {
1547 return le_key_k_type(version, key) == TYPE_DIRECT;
1548 }
1549
1550 static inline int is_indirect_le_key(int version, struct reiserfs_key *key)
1551 {
1552 return le_key_k_type(version, key) == TYPE_INDIRECT;
1553 }
1554
1555 static inline int is_statdata_le_key(int version, struct reiserfs_key *key)
1556 {
1557 return le_key_k_type(version, key) == TYPE_STAT_DATA;
1558 }
1559
1560
1561 static inline int is_direntry_le_ih(struct item_head *ih)
1562 {
1563 return is_direntry_le_key(ih_version(ih), &ih->ih_key);
1564 }
1565
1566 static inline int is_direct_le_ih(struct item_head *ih)
1567 {
1568 return is_direct_le_key(ih_version(ih), &ih->ih_key);
1569 }
1570
1571 static inline int is_indirect_le_ih(struct item_head *ih)
1572 {
1573 return is_indirect_le_key(ih_version(ih), &ih->ih_key);
1574 }
1575
1576 static inline int is_statdata_le_ih(struct item_head *ih)
1577 {
1578 return is_statdata_le_key(ih_version(ih), &ih->ih_key);
1579 }
1580
1581
1582 static inline loff_t cpu_key_k_offset(const struct cpu_key *key)
1583 {
1584 return key->on_disk_key.k_offset;
1585 }
1586
1587 static inline loff_t cpu_key_k_type(const struct cpu_key *key)
1588 {
1589 return key->on_disk_key.k_type;
1590 }
1591
1592 static inline void set_cpu_key_k_offset(struct cpu_key *key, loff_t offset)
1593 {
1594 key->on_disk_key.k_offset = offset;
1595 }
1596
1597 static inline void set_cpu_key_k_type(struct cpu_key *key, int type)
1598 {
1599 key->on_disk_key.k_type = type;
1600 }
1601
1602 static inline void cpu_key_k_offset_dec(struct cpu_key *key)
1603 {
1604 key->on_disk_key.k_offset--;
1605 }
1606
1607 #define is_direntry_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRENTRY)
1608 #define is_direct_cpu_key(key) (cpu_key_k_type (key) == TYPE_DIRECT)
1609 #define is_indirect_cpu_key(key) (cpu_key_k_type (key) == TYPE_INDIRECT)
1610 #define is_statdata_cpu_key(key) (cpu_key_k_type (key) == TYPE_STAT_DATA)
1611
1612
1613 #define is_direntry_cpu_ih(ih) (is_direntry_cpu_key (&((ih)->ih_key)))
1614 #define is_direct_cpu_ih(ih) (is_direct_cpu_key (&((ih)->ih_key)))
1615 #define is_indirect_cpu_ih(ih) (is_indirect_cpu_key (&((ih)->ih_key)))
1616 #define is_statdata_cpu_ih(ih) (is_statdata_cpu_key (&((ih)->ih_key)))
1617
1618 #define I_K_KEY_IN_ITEM(ih, key, n_blocksize) \
1619 (!COMP_SHORT_KEYS(ih, key) && \
1620 I_OFF_BYTE_IN_ITEM(ih, k_offset(key), n_blocksize))
1621
1622
1623 #define MAX_ITEM_LEN(block_size) (block_size - BLKH_SIZE - IH_SIZE)
1624 #define MIN_ITEM_LEN 1
1625
1626
1627 #define REISERFS_ROOT_OBJECTID 2
1628 #define REISERFS_ROOT_PARENT_OBJECTID 1
1629
1630 extern struct reiserfs_key root_key;
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645 struct block_head {
1646 __le16 blk_level;
1647 __le16 blk_nr_item;
1648 __le16 blk_free_space;
1649 __le16 blk_reserved;
1650
1651
1652
1653 struct reiserfs_key blk_right_delim_key;
1654 };
1655
1656 #define BLKH_SIZE (sizeof(struct block_head))
1657 #define blkh_level(p_blkh) (le16_to_cpu((p_blkh)->blk_level))
1658 #define blkh_nr_item(p_blkh) (le16_to_cpu((p_blkh)->blk_nr_item))
1659 #define blkh_free_space(p_blkh) (le16_to_cpu((p_blkh)->blk_free_space))
1660 #define blkh_reserved(p_blkh) (le16_to_cpu((p_blkh)->blk_reserved))
1661 #define set_blkh_level(p_blkh,val) ((p_blkh)->blk_level = cpu_to_le16(val))
1662 #define set_blkh_nr_item(p_blkh,val) ((p_blkh)->blk_nr_item = cpu_to_le16(val))
1663 #define set_blkh_free_space(p_blkh,val) ((p_blkh)->blk_free_space = cpu_to_le16(val))
1664 #define set_blkh_reserved(p_blkh,val) ((p_blkh)->blk_reserved = cpu_to_le16(val))
1665 #define blkh_right_delim_key(p_blkh) ((p_blkh)->blk_right_delim_key)
1666 #define set_blkh_right_delim_key(p_blkh,val) ((p_blkh)->blk_right_delim_key = val)
1667
1668
1669
1670
1671
1672
1673
1674 #define FREE_LEVEL 0
1675
1676 #define DISK_LEAF_NODE_LEVEL 1
1677
1678
1679
1680
1681
1682 #define B_BLK_HEAD(bh) ((struct block_head *)((bh)->b_data))
1683
1684 #define B_NR_ITEMS(bh) (blkh_nr_item(B_BLK_HEAD(bh)))
1685 #define B_LEVEL(bh) (blkh_level(B_BLK_HEAD(bh)))
1686 #define B_FREE_SPACE(bh) (blkh_free_space(B_BLK_HEAD(bh)))
1687
1688 #define PUT_B_NR_ITEMS(bh, val) do { set_blkh_nr_item(B_BLK_HEAD(bh), val); } while (0)
1689 #define PUT_B_LEVEL(bh, val) do { set_blkh_level(B_BLK_HEAD(bh), val); } while (0)
1690 #define PUT_B_FREE_SPACE(bh, val) do { set_blkh_free_space(B_BLK_HEAD(bh), val); } while (0)
1691
1692
1693 #define B_PRIGHT_DELIM_KEY(bh) (&(blk_right_delim_key(B_BLK_HEAD(bh))))
1694
1695
1696 #define B_IS_ITEMS_LEVEL(bh) (B_LEVEL(bh) == DISK_LEAF_NODE_LEVEL)
1697
1698
1699 #define B_IS_KEYS_LEVEL(bh) (B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL \
1700 && B_LEVEL(bh) <= MAX_HEIGHT)
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710 struct stat_data_v1 {
1711 __le16 sd_mode;
1712 __le16 sd_nlink;
1713 __le16 sd_uid;
1714 __le16 sd_gid;
1715 __le32 sd_size;
1716 __le32 sd_atime;
1717 __le32 sd_mtime;
1718
1719
1720
1721
1722
1723 __le32 sd_ctime;
1724 union {
1725 __le32 sd_rdev;
1726 __le32 sd_blocks;
1727 } __attribute__ ((__packed__)) u;
1728
1729
1730
1731
1732
1733
1734
1735
1736 __le32 sd_first_direct_byte;
1737 } __attribute__ ((__packed__));
1738
1739 #define SD_V1_SIZE (sizeof(struct stat_data_v1))
1740 #define stat_data_v1(ih) (ih_version (ih) == KEY_FORMAT_3_5)
1741 #define sd_v1_mode(sdp) (le16_to_cpu((sdp)->sd_mode))
1742 #define set_sd_v1_mode(sdp,v) ((sdp)->sd_mode = cpu_to_le16(v))
1743 #define sd_v1_nlink(sdp) (le16_to_cpu((sdp)->sd_nlink))
1744 #define set_sd_v1_nlink(sdp,v) ((sdp)->sd_nlink = cpu_to_le16(v))
1745 #define sd_v1_uid(sdp) (le16_to_cpu((sdp)->sd_uid))
1746 #define set_sd_v1_uid(sdp,v) ((sdp)->sd_uid = cpu_to_le16(v))
1747 #define sd_v1_gid(sdp) (le16_to_cpu((sdp)->sd_gid))
1748 #define set_sd_v1_gid(sdp,v) ((sdp)->sd_gid = cpu_to_le16(v))
1749 #define sd_v1_size(sdp) (le32_to_cpu((sdp)->sd_size))
1750 #define set_sd_v1_size(sdp,v) ((sdp)->sd_size = cpu_to_le32(v))
1751 #define sd_v1_atime(sdp) (le32_to_cpu((sdp)->sd_atime))
1752 #define set_sd_v1_atime(sdp,v) ((sdp)->sd_atime = cpu_to_le32(v))
1753 #define sd_v1_mtime(sdp) (le32_to_cpu((sdp)->sd_mtime))
1754 #define set_sd_v1_mtime(sdp,v) ((sdp)->sd_mtime = cpu_to_le32(v))
1755 #define sd_v1_ctime(sdp) (le32_to_cpu((sdp)->sd_ctime))
1756 #define set_sd_v1_ctime(sdp,v) ((sdp)->sd_ctime = cpu_to_le32(v))
1757 #define sd_v1_rdev(sdp) (le32_to_cpu((sdp)->u.sd_rdev))
1758 #define set_sd_v1_rdev(sdp,v) ((sdp)->u.sd_rdev = cpu_to_le32(v))
1759 #define sd_v1_blocks(sdp) (le32_to_cpu((sdp)->u.sd_blocks))
1760 #define set_sd_v1_blocks(sdp,v) ((sdp)->u.sd_blocks = cpu_to_le32(v))
1761 #define sd_v1_first_direct_byte(sdp) \
1762 (le32_to_cpu((sdp)->sd_first_direct_byte))
1763 #define set_sd_v1_first_direct_byte(sdp,v) \
1764 ((sdp)->sd_first_direct_byte = cpu_to_le32(v))
1765
1766
1767
1768
1769
1770
1771
1772 #define REISERFS_IMMUTABLE_FL FS_IMMUTABLE_FL
1773 #define REISERFS_APPEND_FL FS_APPEND_FL
1774 #define REISERFS_SYNC_FL FS_SYNC_FL
1775 #define REISERFS_NOATIME_FL FS_NOATIME_FL
1776 #define REISERFS_NODUMP_FL FS_NODUMP_FL
1777 #define REISERFS_SECRM_FL FS_SECRM_FL
1778 #define REISERFS_UNRM_FL FS_UNRM_FL
1779 #define REISERFS_COMPR_FL FS_COMPR_FL
1780 #define REISERFS_NOTAIL_FL FS_NOTAIL_FL
1781
1782
1783 #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL | \
1784 REISERFS_SYNC_FL | \
1785 REISERFS_NOATIME_FL | \
1786 REISERFS_NODUMP_FL | \
1787 REISERFS_SECRM_FL | \
1788 REISERFS_COMPR_FL | \
1789 REISERFS_NOTAIL_FL )
1790
1791
1792
1793
1794
1795 struct stat_data {
1796 __le16 sd_mode;
1797 __le16 sd_attrs;
1798 __le32 sd_nlink;
1799 __le64 sd_size;
1800 __le32 sd_uid;
1801 __le32 sd_gid;
1802 __le32 sd_atime;
1803 __le32 sd_mtime;
1804
1805
1806
1807
1808
1809 __le32 sd_ctime;
1810 __le32 sd_blocks;
1811 union {
1812 __le32 sd_rdev;
1813 __le32 sd_generation;
1814 } __attribute__ ((__packed__)) u;
1815 } __attribute__ ((__packed__));
1816
1817
1818 #define SD_SIZE (sizeof(struct stat_data))
1819 #define SD_V2_SIZE SD_SIZE
1820 #define stat_data_v2(ih) (ih_version (ih) == KEY_FORMAT_3_6)
1821 #define sd_v2_mode(sdp) (le16_to_cpu((sdp)->sd_mode))
1822 #define set_sd_v2_mode(sdp,v) ((sdp)->sd_mode = cpu_to_le16(v))
1823
1824
1825 #define sd_v2_nlink(sdp) (le32_to_cpu((sdp)->sd_nlink))
1826 #define set_sd_v2_nlink(sdp,v) ((sdp)->sd_nlink = cpu_to_le32(v))
1827 #define sd_v2_size(sdp) (le64_to_cpu((sdp)->sd_size))
1828 #define set_sd_v2_size(sdp,v) ((sdp)->sd_size = cpu_to_le64(v))
1829 #define sd_v2_uid(sdp) (le32_to_cpu((sdp)->sd_uid))
1830 #define set_sd_v2_uid(sdp,v) ((sdp)->sd_uid = cpu_to_le32(v))
1831 #define sd_v2_gid(sdp) (le32_to_cpu((sdp)->sd_gid))
1832 #define set_sd_v2_gid(sdp,v) ((sdp)->sd_gid = cpu_to_le32(v))
1833 #define sd_v2_atime(sdp) (le32_to_cpu((sdp)->sd_atime))
1834 #define set_sd_v2_atime(sdp,v) ((sdp)->sd_atime = cpu_to_le32(v))
1835 #define sd_v2_mtime(sdp) (le32_to_cpu((sdp)->sd_mtime))
1836 #define set_sd_v2_mtime(sdp,v) ((sdp)->sd_mtime = cpu_to_le32(v))
1837 #define sd_v2_ctime(sdp) (le32_to_cpu((sdp)->sd_ctime))
1838 #define set_sd_v2_ctime(sdp,v) ((sdp)->sd_ctime = cpu_to_le32(v))
1839 #define sd_v2_blocks(sdp) (le32_to_cpu((sdp)->sd_blocks))
1840 #define set_sd_v2_blocks(sdp,v) ((sdp)->sd_blocks = cpu_to_le32(v))
1841 #define sd_v2_rdev(sdp) (le32_to_cpu((sdp)->u.sd_rdev))
1842 #define set_sd_v2_rdev(sdp,v) ((sdp)->u.sd_rdev = cpu_to_le32(v))
1843 #define sd_v2_generation(sdp) (le32_to_cpu((sdp)->u.sd_generation))
1844 #define set_sd_v2_generation(sdp,v) ((sdp)->u.sd_generation = cpu_to_le32(v))
1845 #define sd_v2_attrs(sdp) (le16_to_cpu((sdp)->sd_attrs))
1846 #define set_sd_v2_attrs(sdp,v) ((sdp)->sd_attrs = cpu_to_le16(v))
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865 #define SD_OFFSET 0
1866 #define SD_UNIQUENESS 0
1867 #define DOT_OFFSET 1
1868 #define DOT_DOT_OFFSET 2
1869 #define DIRENTRY_UNIQUENESS 500
1870
1871 #define FIRST_ITEM_OFFSET 1
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885 struct reiserfs_de_head {
1886 __le32 deh_offset;
1887
1888
1889
1890
1891
1892 __le32 deh_dir_id;
1893
1894
1895 __le32 deh_objectid;
1896 __le16 deh_location;
1897
1898
1899
1900
1901
1902 __le16 deh_state;
1903 } __attribute__ ((__packed__));
1904 #define DEH_SIZE sizeof(struct reiserfs_de_head)
1905 #define deh_offset(p_deh) (le32_to_cpu((p_deh)->deh_offset))
1906 #define deh_dir_id(p_deh) (le32_to_cpu((p_deh)->deh_dir_id))
1907 #define deh_objectid(p_deh) (le32_to_cpu((p_deh)->deh_objectid))
1908 #define deh_location(p_deh) (le16_to_cpu((p_deh)->deh_location))
1909 #define deh_state(p_deh) (le16_to_cpu((p_deh)->deh_state))
1910
1911 #define put_deh_offset(p_deh,v) ((p_deh)->deh_offset = cpu_to_le32((v)))
1912 #define put_deh_dir_id(p_deh,v) ((p_deh)->deh_dir_id = cpu_to_le32((v)))
1913 #define put_deh_objectid(p_deh,v) ((p_deh)->deh_objectid = cpu_to_le32((v)))
1914 #define put_deh_location(p_deh,v) ((p_deh)->deh_location = cpu_to_le16((v)))
1915 #define put_deh_state(p_deh,v) ((p_deh)->deh_state = cpu_to_le16((v)))
1916
1917
1918 #define EMPTY_DIR_SIZE \
1919 (DEH_SIZE * 2 + ROUND_UP (sizeof(".") - 1) + ROUND_UP (sizeof("..") - 1))
1920
1921
1922 #define EMPTY_DIR_SIZE_V1 (DEH_SIZE * 2 + 3)
1923
1924 #define DEH_Statdata 0
1925 #define DEH_Visible 2
1926
1927
1928 #if BITS_PER_LONG == 64 || defined(__s390__) || defined(__hppa__)
1929 # define ADDR_UNALIGNED_BITS (3)
1930 #endif
1931
1932
1933
1934
1935
1936
1937 #ifdef ADDR_UNALIGNED_BITS
1938
1939 # define aligned_address(addr) ((void *)((long)(addr) & ~((1UL << ADDR_UNALIGNED_BITS) - 1)))
1940 # define unaligned_offset(addr) (((int)((long)(addr) & ((1 << ADDR_UNALIGNED_BITS) - 1))) << 3)
1941
1942 # define set_bit_unaligned(nr, addr) \
1943 __test_and_set_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))
1944 # define clear_bit_unaligned(nr, addr) \
1945 __test_and_clear_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))
1946 # define test_bit_unaligned(nr, addr) \
1947 test_bit_le((nr) + unaligned_offset(addr), aligned_address(addr))
1948
1949 #else
1950
1951 # define set_bit_unaligned(nr, addr) __test_and_set_bit_le(nr, addr)
1952 # define clear_bit_unaligned(nr, addr) __test_and_clear_bit_le(nr, addr)
1953 # define test_bit_unaligned(nr, addr) test_bit_le(nr, addr)
1954
1955 #endif
1956
1957 #define mark_de_with_sd(deh) set_bit_unaligned (DEH_Statdata, &((deh)->deh_state))
1958 #define mark_de_without_sd(deh) clear_bit_unaligned (DEH_Statdata, &((deh)->deh_state))
1959 #define mark_de_visible(deh) set_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1960 #define mark_de_hidden(deh) clear_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1961
1962 #define de_with_sd(deh) test_bit_unaligned (DEH_Statdata, &((deh)->deh_state))
1963 #define de_visible(deh) test_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1964 #define de_hidden(deh) !test_bit_unaligned (DEH_Visible, &((deh)->deh_state))
1965
1966 extern void make_empty_dir_item_v1(char *body, __le32 dirid, __le32 objid,
1967 __le32 par_dirid, __le32 par_objid);
1968 extern void make_empty_dir_item(char *body, __le32 dirid, __le32 objid,
1969 __le32 par_dirid, __le32 par_objid);
1970
1971
1972 #define REISERFS_MAX_NAME(block_size) 255
1973
1974
1975
1976
1977
1978
1979
1980
1981 struct reiserfs_dir_entry {
1982 struct buffer_head *de_bh;
1983 int de_item_num;
1984 struct item_head *de_ih;
1985 int de_entry_num;
1986 struct reiserfs_de_head *de_deh;
1987 int de_entrylen;
1988 int de_namelen;
1989 char *de_name;
1990 unsigned long *de_gen_number_bit_string;
1991
1992 __u32 de_dir_id;
1993 __u32 de_objectid;
1994
1995 struct cpu_key de_entry_key;
1996 };
1997
1998
1999
2000
2001
2002
2003
2004 #define B_I_DEH_ENTRY_FILE_NAME(bh, ih, deh) \
2005 (ih_item_body(bh, ih) + deh_location(deh))
2006
2007
2008 #define I_DEH_N_ENTRY_FILE_NAME_LENGTH(ih,deh,entry_num) \
2009 (I_DEH_N_ENTRY_LENGTH (ih, deh, entry_num) - (de_with_sd (deh) ? SD_SIZE : 0))
2010
2011
2012 #define GET_HASH_VALUE(offset) ((offset) & 0x7fffff80LL)
2013
2014 #define GET_GENERATION_NUMBER(offset) ((offset) & 0x7fLL)
2015 #define MAX_GENERATION_NUMBER 127
2016
2017 #define SET_GENERATION_NUMBER(offset,gen_number) (GET_HASH_VALUE(offset)|(gen_number))
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035 struct disk_child {
2036 __le32 dc_block_number;
2037 __le16 dc_size;
2038 __le16 dc_reserved;
2039 };
2040
2041 #define DC_SIZE (sizeof(struct disk_child))
2042 #define dc_block_number(dc_p) (le32_to_cpu((dc_p)->dc_block_number))
2043 #define dc_size(dc_p) (le16_to_cpu((dc_p)->dc_size))
2044 #define put_dc_block_number(dc_p, val) do { (dc_p)->dc_block_number = cpu_to_le32(val); } while(0)
2045 #define put_dc_size(dc_p, val) do { (dc_p)->dc_size = cpu_to_le16(val); } while(0)
2046
2047
2048 #define B_N_CHILD(bh, n_pos) ((struct disk_child *)\
2049 ((bh)->b_data + BLKH_SIZE + B_NR_ITEMS(bh) * KEY_SIZE + DC_SIZE * (n_pos)))
2050
2051
2052 #define B_N_CHILD_NUM(bh, n_pos) (dc_block_number(B_N_CHILD(bh, n_pos)))
2053 #define PUT_B_N_CHILD_NUM(bh, n_pos, val) \
2054 (put_dc_block_number(B_N_CHILD(bh, n_pos), val))
2055
2056
2057
2058 #define MAX_CHILD_SIZE(bh) ((int)( (bh)->b_size - BLKH_SIZE ))
2059
2060
2061 #define B_CHILD_SIZE(cur) (MAX_CHILD_SIZE(cur)-(B_FREE_SPACE(cur)))
2062
2063
2064 #define MAX_NR_KEY(bh) ( (MAX_CHILD_SIZE(bh)-DC_SIZE)/(KEY_SIZE+DC_SIZE) )
2065 #define MIN_NR_KEY(bh) (MAX_NR_KEY(bh)/2)
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084 struct path_element {
2085
2086 struct buffer_head *pe_buffer;
2087
2088 int pe_position;
2089 };
2090
2091
2092
2093
2094
2095 #define MAX_HEIGHT 5
2096
2097
2098 #define EXTENDED_MAX_HEIGHT 7
2099
2100
2101 #define FIRST_PATH_ELEMENT_OFFSET 2
2102
2103
2104 #define ILLEGAL_PATH_ELEMENT_OFFSET 1
2105
2106
2107 #define MAX_FEB_SIZE 6
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128 #define PATH_READA 0x1
2129 #define PATH_READA_BACK 0x2
2130
2131 struct treepath {
2132 int path_length;
2133 int reada;
2134
2135 struct path_element path_elements[EXTENDED_MAX_HEIGHT];
2136 int pos_in_item;
2137 };
2138
2139 #define pos_in_item(path) ((path)->pos_in_item)
2140
2141 #define INITIALIZE_PATH(var) \
2142 struct treepath var = {.path_length = ILLEGAL_PATH_ELEMENT_OFFSET, .reada = 0,}
2143
2144
2145 #define PATH_OFFSET_PELEMENT(path, n_offset) ((path)->path_elements + (n_offset))
2146
2147
2148 #define PATH_OFFSET_PBUFFER(path, n_offset) (PATH_OFFSET_PELEMENT(path, n_offset)->pe_buffer)
2149
2150
2151 #define PATH_OFFSET_POSITION(path, n_offset) (PATH_OFFSET_PELEMENT(path, n_offset)->pe_position)
2152
2153 #define PATH_PLAST_BUFFER(path) (PATH_OFFSET_PBUFFER((path), (path)->path_length))
2154
2155
2156
2157
2158
2159
2160 #define PATH_LAST_POSITION(path) (PATH_OFFSET_POSITION((path), (path)->path_length))
2161
2162
2163
2164
2165
2166
2167
2168 #define PATH_H_PBUFFER(path, h) \
2169 PATH_OFFSET_PBUFFER(path, path->path_length - (h))
2170
2171
2172 #define PATH_H_PPARENT(path, h) PATH_H_PBUFFER(path, (h) + 1)
2173
2174 #define PATH_H_POSITION(path, h) \
2175 PATH_OFFSET_POSITION(path, path->path_length - (h))
2176
2177
2178 #define PATH_H_B_ITEM_ORDER(path, h) PATH_H_POSITION(path, h + 1)
2179
2180 #define PATH_H_PATH_OFFSET(path, n_h) ((path)->path_length - (n_h))
2181
2182 static inline void *reiserfs_node_data(const struct buffer_head *bh)
2183 {
2184 return bh->b_data + sizeof(struct block_head);
2185 }
2186
2187
2188 static inline struct reiserfs_key *internal_key(struct buffer_head *bh,
2189 int item_num)
2190 {
2191 struct reiserfs_key *key = reiserfs_node_data(bh);
2192
2193 return &key[item_num];
2194 }
2195
2196
2197 static inline struct item_head *item_head(const struct buffer_head *bh,
2198 int item_num)
2199 {
2200 struct item_head *ih = reiserfs_node_data(bh);
2201
2202 return &ih[item_num];
2203 }
2204
2205
2206 static inline struct reiserfs_key *leaf_key(const struct buffer_head *bh,
2207 int item_num)
2208 {
2209 return &item_head(bh, item_num)->ih_key;
2210 }
2211
2212 static inline void *ih_item_body(const struct buffer_head *bh,
2213 const struct item_head *ih)
2214 {
2215 return bh->b_data + ih_location(ih);
2216 }
2217
2218
2219 static inline void *item_body(const struct buffer_head *bh, int item_num)
2220 {
2221 return ih_item_body(bh, item_head(bh, item_num));
2222 }
2223
2224 static inline struct item_head *tp_item_head(const struct treepath *path)
2225 {
2226 return item_head(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION(path));
2227 }
2228
2229 static inline void *tp_item_body(const struct treepath *path)
2230 {
2231 return item_body(PATH_PLAST_BUFFER(path), PATH_LAST_POSITION(path));
2232 }
2233
2234 #define get_last_bh(path) PATH_PLAST_BUFFER(path)
2235 #define get_item_pos(path) PATH_LAST_POSITION(path)
2236 #define item_moved(ih,path) comp_items(ih, path)
2237 #define path_changed(ih,path) comp_items (ih, path)
2238
2239
2240
2241 #define B_I_DEH(bh, ih) ((struct reiserfs_de_head *)(ih_item_body(bh, ih)))
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251 static inline int entry_length(const struct buffer_head *bh,
2252 const struct item_head *ih, int pos_in_item)
2253 {
2254 struct reiserfs_de_head *deh;
2255
2256 deh = B_I_DEH(bh, ih) + pos_in_item;
2257 if (pos_in_item)
2258 return deh_location(deh - 1) - deh_location(deh);
2259
2260 return ih_item_len(ih) - deh_location(deh);
2261 }
2262
2263
2264
2265
2266
2267
2268 #define UNFM_P_SIZE (sizeof(unp_t))
2269 #define UNFM_P_SHIFT 2
2270
2271
2272 #define INODE_PKEY(inode) ((struct reiserfs_key *)(REISERFS_I(inode)->i_key))
2273
2274 #define MAX_UL_INT 0xffffffff
2275 #define MAX_INT 0x7ffffff
2276 #define MAX_US_INT 0xffff
2277
2278
2279 static inline loff_t max_reiserfs_offset(struct inode *inode)
2280 {
2281 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_5)
2282 return (loff_t) U32_MAX;
2283
2284 return (loff_t) ((~(__u64) 0) >> 4);
2285 }
2286
2287 #define MAX_KEY_OBJECTID MAX_UL_INT
2288
2289 #define MAX_B_NUM MAX_UL_INT
2290 #define MAX_FC_NUM MAX_US_INT
2291
2292
2293 #define REISERFS_LINK_MAX (MAX_US_INT - 1000)
2294
2295
2296
2297
2298
2299 #define REISERFS_KERNEL_MEM 0
2300 #define REISERFS_USER_MEM 1
2301
2302 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
2303 #define get_generation(s) atomic_read (&fs_generation(s))
2304 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
2305 #define __fs_changed(gen,s) (gen != get_generation (s))
2306 #define fs_changed(gen,s) \
2307 ({ \
2308 reiserfs_cond_resched(s); \
2309 __fs_changed(gen, s); \
2310 })
2311
2312
2313
2314
2315
2316 #define VI_TYPE_LEFT_MERGEABLE 1
2317 #define VI_TYPE_RIGHT_MERGEABLE 2
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334 struct virtual_item {
2335 int vi_index;
2336 unsigned short vi_type;
2337
2338
2339 unsigned short vi_item_len;
2340
2341 struct item_head *vi_ih;
2342 const char *vi_item;
2343 const void *vi_new_data;
2344 void *vi_uarea;
2345 };
2346
2347 struct virtual_node {
2348
2349 char *vn_free_ptr;
2350
2351 unsigned short vn_nr_item;
2352
2353
2354
2355
2356
2357 short vn_size;
2358
2359
2360 short vn_mode;
2361
2362 short vn_affected_item_num;
2363 short vn_pos_in_item;
2364
2365
2366 struct item_head *vn_ins_ih;
2367 const void *vn_data;
2368
2369
2370 struct virtual_item *vn_vi;
2371 };
2372
2373
2374 struct direntry_uarea {
2375 int flags;
2376 __u16 entry_count;
2377 __u16 entry_sizes[1];
2378 } __attribute__ ((__packed__));
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398 #define MAX_FREE_BLOCK 7
2399
2400
2401 #define MAX_AMOUNT_NEEDED 2
2402
2403
2404 struct tree_balance {
2405 int tb_mode;
2406 int need_balance_dirty;
2407 struct super_block *tb_sb;
2408 struct reiserfs_transaction_handle *transaction_handle;
2409 struct treepath *tb_path;
2410
2411
2412 struct buffer_head *L[MAX_HEIGHT];
2413
2414
2415 struct buffer_head *R[MAX_HEIGHT];
2416
2417
2418 struct buffer_head *FL[MAX_HEIGHT];
2419
2420
2421 struct buffer_head *FR[MAX_HEIGHT];
2422
2423 struct buffer_head *CFL[MAX_HEIGHT];
2424
2425
2426 struct buffer_head *CFR[MAX_HEIGHT];
2427
2428
2429
2430
2431
2432 struct buffer_head *FEB[MAX_FEB_SIZE];
2433 struct buffer_head *used[MAX_FEB_SIZE];
2434 struct buffer_head *thrown[MAX_FEB_SIZE];
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444 int lnum[MAX_HEIGHT];
2445
2446
2447 int rnum[MAX_HEIGHT];
2448
2449
2450
2451
2452
2453 int lkey[MAX_HEIGHT];
2454
2455
2456 int rkey[MAX_HEIGHT];
2457
2458
2459
2460
2461
2462 int insert_size[MAX_HEIGHT];
2463
2464
2465
2466
2467
2468
2469
2470 int blknum[MAX_HEIGHT];
2471
2472
2473
2474
2475 int cur_blknum;
2476
2477
2478 int s0num;
2479
2480
2481
2482
2483
2484
2485 int lbytes;
2486
2487
2488
2489
2490
2491
2492 int rbytes;
2493
2494
2495
2496
2497
2498
2499 int item_pos;
2500
2501
2502 struct buffer_head *S_new[2];
2503
2504
2505
2506
2507
2508 int snum[2];
2509
2510
2511
2512
2513
2514 int sbytes[2];
2515
2516 int pos_in_item;
2517 int zeroes_num;
2518
2519
2520
2521
2522
2523 struct buffer_head *buf_to_free[MAX_FREE_BLOCK];
2524
2525
2526
2527
2528
2529 char *vn_buf;
2530
2531 int vn_buf_size;
2532
2533
2534 struct virtual_node *tb_vn;
2535
2536
2537
2538
2539
2540 int fs_gen;
2541
2542 #ifdef DISPLACE_NEW_PACKING_LOCALITIES
2543
2544
2545
2546
2547 struct in_core_key key;
2548 #endif
2549 };
2550
2551
2552
2553
2554 #define M_INSERT 'i'
2555
2556
2557
2558
2559 #define M_PASTE 'p'
2560
2561 #define M_DELETE 'd'
2562
2563 #define M_CUT 'c'
2564
2565
2566 #define M_INTERNAL 'n'
2567
2568
2569
2570
2571
2572 #define M_SKIP_BALANCING 's'
2573 #define M_CONVERT 'v'
2574
2575
2576 #define LEAF_FROM_S_TO_L 0
2577 #define LEAF_FROM_S_TO_R 1
2578 #define LEAF_FROM_R_TO_L 2
2579 #define LEAF_FROM_L_TO_R 3
2580 #define LEAF_FROM_S_TO_SNEW 4
2581
2582 #define FIRST_TO_LAST 0
2583 #define LAST_TO_FIRST 1
2584
2585
2586
2587
2588
2589 struct buffer_info {
2590 struct tree_balance *tb;
2591 struct buffer_head *bi_bh;
2592 struct buffer_head *bi_parent;
2593 int bi_position;
2594 };
2595
2596 static inline struct super_block *sb_from_tb(struct tree_balance *tb)
2597 {
2598 return tb ? tb->tb_sb : NULL;
2599 }
2600
2601 static inline struct super_block *sb_from_bi(struct buffer_info *bi)
2602 {
2603 return bi ? sb_from_tb(bi->tb) : NULL;
2604 }
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626 struct item_operations {
2627 int (*bytes_number) (struct item_head * ih, int block_size);
2628 void (*decrement_key) (struct cpu_key *);
2629 int (*is_left_mergeable) (struct reiserfs_key * ih,
2630 unsigned long bsize);
2631 void (*print_item) (struct item_head *, char *item);
2632 void (*check_item) (struct item_head *, char *item);
2633
2634 int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
2635 int is_affected, int insert_size);
2636 int (*check_left) (struct virtual_item * vi, int free,
2637 int start_skip, int end_skip);
2638 int (*check_right) (struct virtual_item * vi, int free);
2639 int (*part_size) (struct virtual_item * vi, int from, int to);
2640 int (*unit_num) (struct virtual_item * vi);
2641 void (*print_vi) (struct virtual_item * vi);
2642 };
2643
2644 extern struct item_operations *item_ops[TYPE_ANY + 1];
2645
2646 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
2647 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
2648 #define op_print_item(ih,item) item_ops[le_ih_k_type (ih)]->print_item (ih, item)
2649 #define op_check_item(ih,item) item_ops[le_ih_k_type (ih)]->check_item (ih, item)
2650 #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)
2651 #define op_check_left(vi,free,start_skip,end_skip) item_ops[(vi)->vi_index]->check_left (vi, free, start_skip, end_skip)
2652 #define op_check_right(vi,free) item_ops[(vi)->vi_index]->check_right (vi, free)
2653 #define op_part_size(vi,from,to) item_ops[(vi)->vi_index]->part_size (vi, from, to)
2654 #define op_unit_num(vi) item_ops[(vi)->vi_index]->unit_num (vi)
2655 #define op_print_vi(vi) item_ops[(vi)->vi_index]->print_vi (vi)
2656
2657 #define COMP_SHORT_KEYS comp_short_keys
2658
2659
2660 #define I_UNFM_NUM(ih) (ih_item_len(ih) / UNFM_P_SIZE)
2661
2662
2663
2664
2665
2666 #define I_POS_UNFM_SIZE(ih,pos,size) (((pos) == I_UNFM_NUM(ih) - 1 ) ? (size) - ih_free_space(ih) : (size))
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676 #define B_I_STAT_DATA(bh, ih) ( (struct stat_data * )((bh)->b_data + ih_location(ih)) )
2677
2678
2679 #define MAX_DIRECT_ITEM_LEN(size) ((size) - BLKH_SIZE - 2*IH_SIZE - SD_SIZE - UNFM_P_SIZE)
2680
2681
2682
2683
2684
2685
2686 #define B_I_POS_UNFM_POINTER(bh, ih, pos) \
2687 le32_to_cpu(*(((unp_t *)ih_item_body(bh, ih)) + (pos)))
2688 #define PUT_B_I_POS_UNFM_POINTER(bh, ih, pos, val) \
2689 (*(((unp_t *)ih_item_body(bh, ih)) + (pos)) = cpu_to_le32(val))
2690
2691 struct reiserfs_iget_args {
2692 __u32 objectid;
2693 __u32 dirid;
2694 };
2695
2696
2697
2698
2699
2700 #define get_journal_desc_magic(bh) (bh->b_data + bh->b_size - 12)
2701
2702 #define journal_trans_half(blocksize) \
2703 ((blocksize - sizeof (struct reiserfs_journal_desc) + sizeof (__u32) - 12) / sizeof (__u32))
2704
2705
2706
2707
2708 struct reiserfs_journal_desc {
2709 __le32 j_trans_id;
2710
2711
2712 __le32 j_len;
2713
2714 __le32 j_mount_id;
2715 __le32 j_realblock[1];
2716 };
2717
2718 #define get_desc_trans_id(d) le32_to_cpu((d)->j_trans_id)
2719 #define get_desc_trans_len(d) le32_to_cpu((d)->j_len)
2720 #define get_desc_mount_id(d) le32_to_cpu((d)->j_mount_id)
2721
2722 #define set_desc_trans_id(d,val) do { (d)->j_trans_id = cpu_to_le32 (val); } while (0)
2723 #define set_desc_trans_len(d,val) do { (d)->j_len = cpu_to_le32 (val); } while (0)
2724 #define set_desc_mount_id(d,val) do { (d)->j_mount_id = cpu_to_le32 (val); } while (0)
2725
2726
2727 struct reiserfs_journal_commit {
2728 __le32 j_trans_id;
2729 __le32 j_len;
2730 __le32 j_realblock[1];
2731 };
2732
2733 #define get_commit_trans_id(c) le32_to_cpu((c)->j_trans_id)
2734 #define get_commit_trans_len(c) le32_to_cpu((c)->j_len)
2735 #define get_commit_mount_id(c) le32_to_cpu((c)->j_mount_id)
2736
2737 #define set_commit_trans_id(c,val) do { (c)->j_trans_id = cpu_to_le32 (val); } while (0)
2738 #define set_commit_trans_len(c,val) do { (c)->j_len = cpu_to_le32 (val); } while (0)
2739
2740
2741
2742
2743
2744
2745
2746 struct reiserfs_journal_header {
2747
2748 __le32 j_last_flush_trans_id;
2749
2750
2751 __le32 j_first_unflushed_offset;
2752
2753 __le32 j_mount_id;
2754 struct journal_params jh_journal;
2755 };
2756
2757
2758 #define JOURNAL_BLOCK_COUNT 8192
2759
2760
2761 #define JOURNAL_TRANS_MAX_DEFAULT 1024
2762 #define JOURNAL_TRANS_MIN_DEFAULT 256
2763
2764
2765
2766
2767
2768 #define JOURNAL_MAX_BATCH_DEFAULT 900
2769 #define JOURNAL_MIN_RATIO 2
2770 #define JOURNAL_MAX_COMMIT_AGE 30
2771 #define JOURNAL_MAX_TRANS_AGE 30
2772 #define JOURNAL_PER_BALANCE_CNT (3 * (MAX_HEIGHT-2) + 9)
2773 #define JOURNAL_BLOCKS_PER_OBJECT(sb) (JOURNAL_PER_BALANCE_CNT * 3 + \
2774 2 * (REISERFS_QUOTA_INIT_BLOCKS(sb) + \
2775 REISERFS_QUOTA_TRANS_BLOCKS(sb)))
2776
2777 #ifdef CONFIG_QUOTA
2778 #define REISERFS_QUOTA_OPTS ((1 << REISERFS_USRQUOTA) | (1 << REISERFS_GRPQUOTA))
2779
2780 #define REISERFS_QUOTA_TRANS_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? 2 : 0)
2781
2782 #define REISERFS_QUOTA_INIT_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? \
2783 (DQUOT_INIT_ALLOC*(JOURNAL_PER_BALANCE_CNT+2)+DQUOT_INIT_REWRITE+1) : 0)
2784
2785 #define REISERFS_QUOTA_DEL_BLOCKS(s) (REISERFS_SB(s)->s_mount_opt & REISERFS_QUOTA_OPTS ? \
2786 (DQUOT_DEL_ALLOC*(JOURNAL_PER_BALANCE_CNT+2)+DQUOT_DEL_REWRITE+1) : 0)
2787 #else
2788 #define REISERFS_QUOTA_TRANS_BLOCKS(s) 0
2789 #define REISERFS_QUOTA_INIT_BLOCKS(s) 0
2790 #define REISERFS_QUOTA_DEL_BLOCKS(s) 0
2791 #endif
2792
2793
2794
2795
2796
2797
2798
2799
2800 #define REISERFS_MIN_BITMAP_NODES 10
2801 #define REISERFS_MAX_BITMAP_NODES 100
2802
2803
2804 #define JBH_HASH_SHIFT 13
2805 #define JBH_HASH_MASK 8191
2806
2807 #define _jhashfn(sb,block) \
2808 (((unsigned long)sb>>L1_CACHE_SHIFT) ^ \
2809 (((block)<<(JBH_HASH_SHIFT - 6)) ^ ((block) >> 13) ^ ((block) << (JBH_HASH_SHIFT - 12))))
2810 #define journal_hash(t,sb,block) ((t)[_jhashfn((sb),(block)) & JBH_HASH_MASK])
2811
2812
2813 #define journal_find_get_block(s, block) __find_get_block(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)
2814 #define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)
2815 #define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize)
2816
2817 enum reiserfs_bh_state_bits {
2818 BH_JDirty = BH_PrivateStart,
2819 BH_JDirty_wait,
2820
2821
2822
2823
2824 BH_JNew,
2825 BH_JPrepared,
2826 BH_JRestore_dirty,
2827 BH_JTest,
2828 };
2829
2830 BUFFER_FNS(JDirty, journaled);
2831 TAS_BUFFER_FNS(JDirty, journaled);
2832 BUFFER_FNS(JDirty_wait, journal_dirty);
2833 TAS_BUFFER_FNS(JDirty_wait, journal_dirty);
2834 BUFFER_FNS(JNew, journal_new);
2835 TAS_BUFFER_FNS(JNew, journal_new);
2836 BUFFER_FNS(JPrepared, journal_prepared);
2837 TAS_BUFFER_FNS(JPrepared, journal_prepared);
2838 BUFFER_FNS(JRestore_dirty, journal_restore_dirty);
2839 TAS_BUFFER_FNS(JRestore_dirty, journal_restore_dirty);
2840 BUFFER_FNS(JTest, journal_test);
2841 TAS_BUFFER_FNS(JTest, journal_test);
2842
2843
2844 struct reiserfs_transaction_handle {
2845
2846
2847
2848
2849
2850
2851 struct super_block *t_super;
2852
2853 int t_refcount;
2854 int t_blocks_logged;
2855 int t_blocks_allocated;
2856
2857
2858 unsigned int t_trans_id;
2859
2860 void *t_handle_save;
2861
2862
2863
2864
2865
2866 unsigned displace_new_blocks:1;
2867
2868 struct list_head t_list;
2869 };
2870
2871
2872
2873
2874
2875 struct reiserfs_jh {
2876 struct reiserfs_journal_list *jl;
2877 struct buffer_head *bh;
2878 struct list_head list;
2879 };
2880
2881 void reiserfs_free_jh(struct buffer_head *bh);
2882 int reiserfs_add_tail_list(struct inode *inode, struct buffer_head *bh);
2883 int reiserfs_add_ordered_list(struct inode *inode, struct buffer_head *bh);
2884 int journal_mark_dirty(struct reiserfs_transaction_handle *,
2885 struct buffer_head *bh);
2886
2887 static inline int reiserfs_file_data_log(struct inode *inode)
2888 {
2889 if (reiserfs_data_log(inode->i_sb) ||
2890 (REISERFS_I(inode)->i_flags & i_data_log))
2891 return 1;
2892 return 0;
2893 }
2894
2895 static inline int reiserfs_transaction_running(struct super_block *s)
2896 {
2897 struct reiserfs_transaction_handle *th = current->journal_info;
2898 if (th && th->t_super == s)
2899 return 1;
2900 if (th && th->t_super == NULL)
2901 BUG();
2902 return 0;
2903 }
2904
2905 static inline int reiserfs_transaction_free_space(struct reiserfs_transaction_handle *th)
2906 {
2907 return th->t_blocks_allocated - th->t_blocks_logged;
2908 }
2909
2910 struct reiserfs_transaction_handle *reiserfs_persistent_transaction(struct
2911 super_block
2912 *,
2913 int count);
2914 int reiserfs_end_persistent_transaction(struct reiserfs_transaction_handle *);
2915 void reiserfs_vfs_truncate_file(struct inode *inode);
2916 int reiserfs_commit_page(struct inode *inode, struct page *page,
2917 unsigned from, unsigned to);
2918 void reiserfs_flush_old_commits(struct super_block *);
2919 int reiserfs_commit_for_inode(struct inode *);
2920 int reiserfs_inode_needs_commit(struct inode *);
2921 void reiserfs_update_inode_transaction(struct inode *);
2922 void reiserfs_wait_on_write_block(struct super_block *s);
2923 void reiserfs_block_writes(struct reiserfs_transaction_handle *th);
2924 void reiserfs_allow_writes(struct super_block *s);
2925 void reiserfs_check_lock_depth(struct super_block *s, char *caller);
2926 int reiserfs_prepare_for_journal(struct super_block *, struct buffer_head *bh,
2927 int wait);
2928 void reiserfs_restore_prepared_buffer(struct super_block *,
2929 struct buffer_head *bh);
2930 int journal_init(struct super_block *, const char *j_dev_name, int old_format,
2931 unsigned int);
2932 int journal_release(struct reiserfs_transaction_handle *, struct super_block *);
2933 int journal_release_error(struct reiserfs_transaction_handle *,
2934 struct super_block *);
2935 int journal_end(struct reiserfs_transaction_handle *);
2936 int journal_end_sync(struct reiserfs_transaction_handle *);
2937 int journal_mark_freed(struct reiserfs_transaction_handle *,
2938 struct super_block *, b_blocknr_t blocknr);
2939 int journal_transaction_should_end(struct reiserfs_transaction_handle *, int);
2940 int reiserfs_in_journal(struct super_block *sb, unsigned int bmap_nr,
2941 int bit_nr, int searchall, b_blocknr_t *next);
2942 int journal_begin(struct reiserfs_transaction_handle *,
2943 struct super_block *sb, unsigned long);
2944 int journal_join_abort(struct reiserfs_transaction_handle *,
2945 struct super_block *sb);
2946 void reiserfs_abort_journal(struct super_block *sb, int errno);
2947 void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...);
2948 int reiserfs_allocate_list_bitmaps(struct super_block *s,
2949 struct reiserfs_list_bitmap *, unsigned int);
2950
2951 void reiserfs_schedule_old_flush(struct super_block *s);
2952 void reiserfs_cancel_old_flush(struct super_block *s);
2953 void add_save_link(struct reiserfs_transaction_handle *th,
2954 struct inode *inode, int truncate);
2955 int remove_save_link(struct inode *inode, int truncate);
2956
2957
2958 __u32 reiserfs_get_unused_objectid(struct reiserfs_transaction_handle *th);
2959 void reiserfs_release_objectid(struct reiserfs_transaction_handle *th,
2960 __u32 objectid_to_release);
2961 int reiserfs_convert_objectid_map_v1(struct super_block *);
2962
2963
2964 int B_IS_IN_TREE(const struct buffer_head *);
2965 extern void copy_item_head(struct item_head *to,
2966 const struct item_head *from);
2967
2968
2969 extern int comp_short_keys(const struct reiserfs_key *le_key,
2970 const struct cpu_key *cpu_key);
2971 extern void le_key2cpu_key(struct cpu_key *to, const struct reiserfs_key *from);
2972
2973
2974 extern int comp_le_keys(const struct reiserfs_key *,
2975 const struct reiserfs_key *);
2976 extern int comp_short_le_keys(const struct reiserfs_key *,
2977 const struct reiserfs_key *);
2978
2979
2980 static inline int le_key_version(const struct reiserfs_key *key)
2981 {
2982 int type;
2983
2984 type = offset_v2_k_type(&(key->u.k_offset_v2));
2985 if (type != TYPE_DIRECT && type != TYPE_INDIRECT
2986 && type != TYPE_DIRENTRY)
2987 return KEY_FORMAT_3_5;
2988
2989 return KEY_FORMAT_3_6;
2990
2991 }
2992
2993 static inline void copy_key(struct reiserfs_key *to,
2994 const struct reiserfs_key *from)
2995 {
2996 memcpy(to, from, KEY_SIZE);
2997 }
2998
2999 int comp_items(const struct item_head *stored_ih, const struct treepath *path);
3000 const struct reiserfs_key *get_rkey(const struct treepath *chk_path,
3001 const struct super_block *sb);
3002 int search_by_key(struct super_block *, const struct cpu_key *,
3003 struct treepath *, int);
3004 #define search_item(s,key,path) search_by_key (s, key, path, DISK_LEAF_NODE_LEVEL)
3005 int search_for_position_by_key(struct super_block *sb,
3006 const struct cpu_key *cpu_key,
3007 struct treepath *search_path);
3008 extern void decrement_bcount(struct buffer_head *bh);
3009 void decrement_counters_in_path(struct treepath *search_path);
3010 void pathrelse(struct treepath *search_path);
3011 int reiserfs_check_path(struct treepath *p);
3012 void pathrelse_and_restore(struct super_block *s, struct treepath *search_path);
3013
3014 int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
3015 struct treepath *path,
3016 const struct cpu_key *key,
3017 struct item_head *ih,
3018 struct inode *inode, const char *body);
3019
3020 int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th,
3021 struct treepath *path,
3022 const struct cpu_key *key,
3023 struct inode *inode,
3024 const char *body, int paste_size);
3025
3026 int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
3027 struct treepath *path,
3028 struct cpu_key *key,
3029 struct inode *inode,
3030 struct page *page, loff_t new_file_size);
3031
3032 int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
3033 struct treepath *path,
3034 const struct cpu_key *key,
3035 struct inode *inode, struct buffer_head *un_bh);
3036
3037 void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
3038 struct inode *inode, struct reiserfs_key *key);
3039 int reiserfs_delete_object(struct reiserfs_transaction_handle *th,
3040 struct inode *inode);
3041 int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
3042 struct inode *inode, struct page *,
3043 int update_timestamps);
3044
3045 #define i_block_size(inode) ((inode)->i_sb->s_blocksize)
3046 #define file_size(inode) ((inode)->i_size)
3047 #define tail_size(inode) (file_size (inode) & (i_block_size (inode) - 1))
3048
3049 #define tail_has_to_be_packed(inode) (have_large_tails ((inode)->i_sb)?\
3050 !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 )
3051
3052 void padd_item(char *item, int total_length, int length);
3053
3054
3055
3056 #define GET_BLOCK_NO_CREATE 0
3057 #define GET_BLOCK_CREATE 1
3058 #define GET_BLOCK_NO_HOLE 2
3059 #define GET_BLOCK_READ_DIRECT 4
3060 #define GET_BLOCK_NO_IMUX 8
3061 #define GET_BLOCK_NO_DANGLE 16
3062
3063 void reiserfs_read_locked_inode(struct inode *inode,
3064 struct reiserfs_iget_args *args);
3065 int reiserfs_find_actor(struct inode *inode, void *p);
3066 int reiserfs_init_locked_inode(struct inode *inode, void *p);
3067 void reiserfs_evict_inode(struct inode *inode);
3068 int reiserfs_write_inode(struct inode *inode, struct writeback_control *wbc);
3069 int reiserfs_get_block(struct inode *inode, sector_t block,
3070 struct buffer_head *bh_result, int create);
3071 struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid,
3072 int fh_len, int fh_type);
3073 struct dentry *reiserfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3074 int fh_len, int fh_type);
3075 int reiserfs_encode_fh(struct inode *inode, __u32 * data, int *lenp,
3076 struct inode *parent);
3077
3078 int reiserfs_truncate_file(struct inode *, int update_timestamps);
3079 void make_cpu_key(struct cpu_key *cpu_key, struct inode *inode, loff_t offset,
3080 int type, int key_length);
3081 void make_le_item_head(struct item_head *ih, const struct cpu_key *key,
3082 int version,
3083 loff_t offset, int type, int length, int entry_count);
3084 struct inode *reiserfs_iget(struct super_block *s, const struct cpu_key *key);
3085
3086 struct reiserfs_security_handle;
3087 int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
3088 struct inode *dir, umode_t mode,
3089 const char *symname, loff_t i_size,
3090 struct dentry *dentry, struct inode *inode,
3091 struct reiserfs_security_handle *security);
3092
3093 void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,
3094 struct inode *inode, loff_t size);
3095
3096 static inline void reiserfs_update_sd(struct reiserfs_transaction_handle *th,
3097 struct inode *inode)
3098 {
3099 reiserfs_update_sd_size(th, inode, inode->i_size);
3100 }
3101
3102 void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
3103 int reiserfs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
3104 struct iattr *attr);
3105
3106 int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
3107
3108
3109 void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
3110 int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
3111 struct treepath *path, struct reiserfs_dir_entry *de);
3112 struct dentry *reiserfs_get_parent(struct dentry *);
3113
3114 #ifdef CONFIG_REISERFS_PROC_INFO
3115 int reiserfs_proc_info_init(struct super_block *sb);
3116 int reiserfs_proc_info_done(struct super_block *sb);
3117 int reiserfs_proc_info_global_init(void);
3118 int reiserfs_proc_info_global_done(void);
3119
3120 #define PROC_EXP( e ) e
3121
3122 #define __PINFO( sb ) REISERFS_SB(sb) -> s_proc_info_data
3123 #define PROC_INFO_MAX( sb, field, value ) \
3124 __PINFO( sb ).field = \
3125 max( REISERFS_SB( sb ) -> s_proc_info_data.field, value )
3126 #define PROC_INFO_INC( sb, field ) ( ++ ( __PINFO( sb ).field ) )
3127 #define PROC_INFO_ADD( sb, field, val ) ( __PINFO( sb ).field += ( val ) )
3128 #define PROC_INFO_BH_STAT( sb, bh, level ) \
3129 PROC_INFO_INC( sb, sbk_read_at[ ( level ) ] ); \
3130 PROC_INFO_ADD( sb, free_at[ ( level ) ], B_FREE_SPACE( bh ) ); \
3131 PROC_INFO_ADD( sb, items_at[ ( level ) ], B_NR_ITEMS( bh ) )
3132 #else
3133 static inline int reiserfs_proc_info_init(struct super_block *sb)
3134 {
3135 return 0;
3136 }
3137
3138 static inline int reiserfs_proc_info_done(struct super_block *sb)
3139 {
3140 return 0;
3141 }
3142
3143 static inline int reiserfs_proc_info_global_init(void)
3144 {
3145 return 0;
3146 }
3147
3148 static inline int reiserfs_proc_info_global_done(void)
3149 {
3150 return 0;
3151 }
3152
3153 #define PROC_EXP( e )
3154 #define VOID_V ( ( void ) 0 )
3155 #define PROC_INFO_MAX( sb, field, value ) VOID_V
3156 #define PROC_INFO_INC( sb, field ) VOID_V
3157 #define PROC_INFO_ADD( sb, field, val ) VOID_V
3158 #define PROC_INFO_BH_STAT(sb, bh, n_node_level) VOID_V
3159 #endif
3160
3161
3162 extern const struct inode_operations reiserfs_dir_inode_operations;
3163 extern const struct inode_operations reiserfs_symlink_inode_operations;
3164 extern const struct inode_operations reiserfs_special_inode_operations;
3165 extern const struct file_operations reiserfs_dir_operations;
3166 int reiserfs_readdir_inode(struct inode *, struct dir_context *);
3167
3168
3169 int direct2indirect(struct reiserfs_transaction_handle *, struct inode *,
3170 struct treepath *, struct buffer_head *, loff_t);
3171 int indirect2direct(struct reiserfs_transaction_handle *, struct inode *,
3172 struct page *, struct treepath *, const struct cpu_key *,
3173 loff_t, char *);
3174 void reiserfs_unmap_buffer(struct buffer_head *);
3175
3176
3177 extern const struct inode_operations reiserfs_file_inode_operations;
3178 extern const struct file_operations reiserfs_file_operations;
3179 extern const struct address_space_operations reiserfs_address_space_operations;
3180
3181
3182
3183 int fix_nodes(int n_op_mode, struct tree_balance *tb,
3184 struct item_head *ins_ih, const void *);
3185 void unfix_nodes(struct tree_balance *);
3186
3187
3188 void __reiserfs_panic(struct super_block *s, const char *id,
3189 const char *function, const char *fmt, ...)
3190 __attribute__ ((noreturn));
3191 #define reiserfs_panic(s, id, fmt, args...) \
3192 __reiserfs_panic(s, id, __func__, fmt, ##args)
3193 void __reiserfs_error(struct super_block *s, const char *id,
3194 const char *function, const char *fmt, ...);
3195 #define reiserfs_error(s, id, fmt, args...) \
3196 __reiserfs_error(s, id, __func__, fmt, ##args)
3197 void reiserfs_info(struct super_block *s, const char *fmt, ...);
3198 void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...);
3199 void print_indirect_item(struct buffer_head *bh, int item_num);
3200 void store_print_tb(struct tree_balance *tb);
3201 void print_cur_tb(char *mes);
3202 void print_de(struct reiserfs_dir_entry *de);
3203 void print_bi(struct buffer_info *bi, char *mes);
3204 #define PRINT_LEAF_ITEMS 1
3205 #define PRINT_DIRECTORY_ITEMS 2
3206 #define PRINT_DIRECT_ITEMS 4
3207 void print_block(struct buffer_head *bh, ...);
3208 void print_bmap(struct super_block *s, int silent);
3209 void print_bmap_block(int i, char *data, int size, int silent);
3210
3211 void print_objectid_map(struct super_block *s);
3212 void print_block_head(struct buffer_head *bh, char *mes);
3213 void check_leaf(struct buffer_head *bh);
3214 void check_internal(struct buffer_head *bh);
3215 void print_statistics(struct super_block *s);
3216 char *reiserfs_hashname(int code);
3217
3218
3219 int leaf_move_items(int shift_mode, struct tree_balance *tb, int mov_num,
3220 int mov_bytes, struct buffer_head *Snew);
3221 int leaf_shift_left(struct tree_balance *tb, int shift_num, int shift_bytes);
3222 int leaf_shift_right(struct tree_balance *tb, int shift_num, int shift_bytes);
3223 void leaf_delete_items(struct buffer_info *cur_bi, int last_first, int first,
3224 int del_num, int del_bytes);
3225 void leaf_insert_into_buf(struct buffer_info *bi, int before,
3226 struct item_head * const inserted_item_ih,
3227 const char * const inserted_item_body,
3228 int zeros_number);
3229 void leaf_paste_in_buffer(struct buffer_info *bi, int pasted_item_num,
3230 int pos_in_item, int paste_size,
3231 const char * const body, int zeros_number);
3232 void leaf_cut_from_buffer(struct buffer_info *bi, int cut_item_num,
3233 int pos_in_item, int cut_size);
3234 void leaf_paste_entries(struct buffer_info *bi, int item_num, int before,
3235 int new_entry_count, struct reiserfs_de_head *new_dehs,
3236 const char *records, int paste_size);
3237
3238 int balance_internal(struct tree_balance *, int, int, struct item_head *,
3239 struct buffer_head **);
3240
3241
3242 void do_balance_mark_leaf_dirty(struct tree_balance *tb,
3243 struct buffer_head *bh, int flag);
3244 #define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty
3245 #define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty
3246
3247 void do_balance(struct tree_balance *tb, struct item_head *ih,
3248 const char *body, int flag);
3249 void reiserfs_invalidate_buffer(struct tree_balance *tb,
3250 struct buffer_head *bh);
3251
3252 int get_left_neighbor_position(struct tree_balance *tb, int h);
3253 int get_right_neighbor_position(struct tree_balance *tb, int h);
3254 void replace_key(struct tree_balance *tb, struct buffer_head *, int,
3255 struct buffer_head *, int);
3256 void make_empty_node(struct buffer_info *);
3257 struct buffer_head *get_FEB(struct tree_balance *);
3258
3259
3260
3261
3262
3263
3264
3265 struct __reiserfs_blocknr_hint {
3266
3267 struct inode *inode;
3268
3269 sector_t block;
3270 struct in_core_key key;
3271
3272
3273
3274
3275
3276 struct treepath *path;
3277
3278
3279
3280
3281
3282 struct reiserfs_transaction_handle *th;
3283
3284 b_blocknr_t beg, end;
3285
3286
3287
3288
3289
3290
3291 b_blocknr_t search_start;
3292
3293
3294
3295
3296
3297 int prealloc_size;
3298
3299
3300
3301
3302
3303 unsigned formatted_node:1;
3304 unsigned preallocate:1;
3305 };
3306
3307 typedef struct __reiserfs_blocknr_hint reiserfs_blocknr_hint_t;
3308
3309 int reiserfs_parse_alloc_options(struct super_block *, char *);
3310 void reiserfs_init_alloc_options(struct super_block *s);
3311
3312
3313
3314
3315
3316
3317 __le32 reiserfs_choose_packing(struct inode *dir);
3318
3319 void show_alloc_options(struct seq_file *seq, struct super_block *s);
3320 int reiserfs_init_bitmap_cache(struct super_block *sb);
3321 void reiserfs_free_bitmap_cache(struct super_block *sb);
3322 void reiserfs_cache_bitmap_metadata(struct super_block *sb, struct buffer_head *bh, struct reiserfs_bitmap_info *info);
3323 struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb, unsigned int bitmap);
3324 int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value);
3325 void reiserfs_free_block(struct reiserfs_transaction_handle *th, struct inode *,
3326 b_blocknr_t, int for_unformatted);
3327 int reiserfs_allocate_blocknrs(reiserfs_blocknr_hint_t *, b_blocknr_t *, int,
3328 int);
3329 static inline int reiserfs_new_form_blocknrs(struct tree_balance *tb,
3330 b_blocknr_t * new_blocknrs,
3331 int amount_needed)
3332 {
3333 reiserfs_blocknr_hint_t hint = {
3334 .th = tb->transaction_handle,
3335 .path = tb->tb_path,
3336 .inode = NULL,
3337 .key = tb->key,
3338 .block = 0,
3339 .formatted_node = 1
3340 };
3341 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, amount_needed,
3342 0);
3343 }
3344
3345 static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle
3346 *th, struct inode *inode,
3347 b_blocknr_t * new_blocknrs,
3348 struct treepath *path,
3349 sector_t block)
3350 {
3351 reiserfs_blocknr_hint_t hint = {
3352 .th = th,
3353 .path = path,
3354 .inode = inode,
3355 .block = block,
3356 .formatted_node = 0,
3357 .preallocate = 0
3358 };
3359 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0);
3360 }
3361
3362 #ifdef REISERFS_PREALLOCATE
3363 static inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle
3364 *th, struct inode *inode,
3365 b_blocknr_t * new_blocknrs,
3366 struct treepath *path,
3367 sector_t block)
3368 {
3369 reiserfs_blocknr_hint_t hint = {
3370 .th = th,
3371 .path = path,
3372 .inode = inode,
3373 .block = block,
3374 .formatted_node = 0,
3375 .preallocate = 1
3376 };
3377 return reiserfs_allocate_blocknrs(&hint, new_blocknrs, 1, 0);
3378 }
3379
3380 void reiserfs_discard_prealloc(struct reiserfs_transaction_handle *th,
3381 struct inode *inode);
3382 void reiserfs_discard_all_prealloc(struct reiserfs_transaction_handle *th);
3383 #endif
3384
3385
3386 __u32 keyed_hash(const signed char *msg, int len);
3387 __u32 yura_hash(const signed char *msg, int len);
3388 __u32 r5_hash(const signed char *msg, int len);
3389
3390 #define reiserfs_set_le_bit __set_bit_le
3391 #define reiserfs_test_and_set_le_bit __test_and_set_bit_le
3392 #define reiserfs_clear_le_bit __clear_bit_le
3393 #define reiserfs_test_and_clear_le_bit __test_and_clear_bit_le
3394 #define reiserfs_test_le_bit test_bit_le
3395 #define reiserfs_find_next_zero_le_bit find_next_zero_bit_le
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406 #define SPARE_SPACE 500
3407
3408
3409 int reiserfs_fileattr_get(struct dentry *dentry, struct fileattr *fa);
3410 int reiserfs_fileattr_set(struct user_namespace *mnt_userns,
3411 struct dentry *dentry, struct fileattr *fa);
3412 long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
3413 long reiserfs_compat_ioctl(struct file *filp,
3414 unsigned int cmd, unsigned long arg);
3415 int reiserfs_unpack(struct inode *inode);