Commit 3ee16670 authored by Jeff Mahoney's avatar Jeff Mahoney Committed by Linus Torvalds

reiserfs: fix usage of signed ints for block numbers

Do a quick signedness check for block numbers.  There are a number of places
where signed integers are used for block numbers, which limits the usable file
system size to 8 TiB.  The disk format, excepting a problem which will be
fixed in the following patch, supports file systems up to 16 TiB in size.
This patch cleans up those sites so that we can enable the full usable size.
Signed-off-by: default avatarJeff Mahoney <jeffm@suse.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6c57c2c8
...@@ -47,7 +47,9 @@ ...@@ -47,7 +47,9 @@
test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s)) test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s))
static inline void get_bit_address(struct super_block *s, static inline void get_bit_address(struct super_block *s,
b_blocknr_t block, int *bmap_nr, int *offset) b_blocknr_t block,
unsigned int *bmap_nr,
unsigned int *offset)
{ {
/* It is in the bitmap block number equal to the block /* It is in the bitmap block number equal to the block
* number divided by the number of bits in a block. */ * number divided by the number of bits in a block. */
...@@ -58,7 +60,7 @@ static inline void get_bit_address(struct super_block *s, ...@@ -58,7 +60,7 @@ static inline void get_bit_address(struct super_block *s,
int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value) int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
{ {
int bmap, offset; unsigned int bmap, offset;
if (block == 0 || block >= SB_BLOCK_COUNT(s)) { if (block == 0 || block >= SB_BLOCK_COUNT(s)) {
reiserfs_warning(s, reiserfs_warning(s,
...@@ -108,8 +110,8 @@ int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value) ...@@ -108,8 +110,8 @@ int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
/* searches in journal structures for a given block number (bmap, off). If block /* searches in journal structures for a given block number (bmap, off). If block
is found in reiserfs journal it suggests next free block candidate to test. */ is found in reiserfs journal it suggests next free block candidate to test. */
static inline int is_block_in_journal(struct super_block *s, int bmap, int static inline int is_block_in_journal(struct super_block *s, unsigned int bmap,
off, int *next) int off, int *next)
{ {
b_blocknr_t tmp; b_blocknr_t tmp;
...@@ -130,8 +132,8 @@ static inline int is_block_in_journal(struct super_block *s, int bmap, int ...@@ -130,8 +132,8 @@ static inline int is_block_in_journal(struct super_block *s, int bmap, int
/* it searches for a window of zero bits with given minimum and maximum lengths in one bitmap /* it searches for a window of zero bits with given minimum and maximum lengths in one bitmap
* block; */ * block; */
static int scan_bitmap_block(struct reiserfs_transaction_handle *th, static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
int bmap_n, int *beg, int boundary, int min, unsigned int bmap_n, int *beg, int boundary,
int max, int unfm) int min, int max, int unfm)
{ {
struct super_block *s = th->t_super; struct super_block *s = th->t_super;
struct reiserfs_bitmap_info *bi = &SB_AP_BITMAP(s)[bmap_n]; struct reiserfs_bitmap_info *bi = &SB_AP_BITMAP(s)[bmap_n];
...@@ -307,16 +309,16 @@ __le32 reiserfs_choose_packing(struct inode * dir) ...@@ -307,16 +309,16 @@ __le32 reiserfs_choose_packing(struct inode * dir)
* bitmap and place new blocks there. Returns number of allocated blocks. */ * bitmap and place new blocks there. Returns number of allocated blocks. */
static int scan_bitmap(struct reiserfs_transaction_handle *th, static int scan_bitmap(struct reiserfs_transaction_handle *th,
b_blocknr_t * start, b_blocknr_t finish, b_blocknr_t * start, b_blocknr_t finish,
int min, int max, int unfm, unsigned long file_block) int min, int max, int unfm, sector_t file_block)
{ {
int nr_allocated = 0; int nr_allocated = 0;
struct super_block *s = th->t_super; struct super_block *s = th->t_super;
/* find every bm and bmap and bmap_nr in this file, and change them all to bitmap_blocknr /* find every bm and bmap and bmap_nr in this file, and change them all to bitmap_blocknr
* - Hans, it is not a block number - Zam. */ * - Hans, it is not a block number - Zam. */
int bm, off; unsigned int bm, off;
int end_bm, end_off; unsigned int end_bm, end_off;
int off_max = s->s_blocksize << 3; unsigned int off_max = s->s_blocksize << 3;
BUG_ON(!th->t_trans_id); BUG_ON(!th->t_trans_id);
...@@ -383,7 +385,7 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th, ...@@ -383,7 +385,7 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
struct reiserfs_super_block *rs; struct reiserfs_super_block *rs;
struct buffer_head *sbh, *bmbh; struct buffer_head *sbh, *bmbh;
struct reiserfs_bitmap_info *apbi; struct reiserfs_bitmap_info *apbi;
int nr, offset; unsigned int nr, offset;
BUG_ON(!th->t_trans_id); BUG_ON(!th->t_trans_id);
......
...@@ -199,7 +199,7 @@ static inline void set_block_dev_mapped(struct buffer_head *bh, ...@@ -199,7 +199,7 @@ static inline void set_block_dev_mapped(struct buffer_head *bh,
// files which were created in the earlier version can not be longer, // files which were created in the earlier version can not be longer,
// than 2 gb // than 2 gb
// //
static int file_capable(struct inode *inode, long block) static int file_capable(struct inode *inode, sector_t block)
{ {
if (get_inode_item_key_version(inode) != KEY_FORMAT_3_5 || // it is new file. if (get_inode_item_key_version(inode) != KEY_FORMAT_3_5 || // it is new file.
block < (1 << (31 - inode->i_sb->s_blocksize_bits))) // old file, but 'block' is inside of 2gb block < (1 << (31 - inode->i_sb->s_blocksize_bits))) // old file, but 'block' is inside of 2gb
...@@ -242,7 +242,7 @@ static int restart_transaction(struct reiserfs_transaction_handle *th, ...@@ -242,7 +242,7 @@ static int restart_transaction(struct reiserfs_transaction_handle *th,
// Please improve the english/clarity in the comment above, as it is // Please improve the english/clarity in the comment above, as it is
// hard to understand. // hard to understand.
static int _get_block_create_0(struct inode *inode, long block, static int _get_block_create_0(struct inode *inode, sector_t block,
struct buffer_head *bh_result, int args) struct buffer_head *bh_result, int args)
{ {
INITIALIZE_PATH(path); INITIALIZE_PATH(path);
...@@ -250,7 +250,7 @@ static int _get_block_create_0(struct inode *inode, long block, ...@@ -250,7 +250,7 @@ static int _get_block_create_0(struct inode *inode, long block,
struct buffer_head *bh; struct buffer_head *bh;
struct item_head *ih, tmp_ih; struct item_head *ih, tmp_ih;
int fs_gen; int fs_gen;
int blocknr; b_blocknr_t blocknr;
char *p = NULL; char *p = NULL;
int chars; int chars;
int ret; int ret;
...@@ -569,7 +569,7 @@ static int convert_tail_for_hole(struct inode *inode, ...@@ -569,7 +569,7 @@ static int convert_tail_for_hole(struct inode *inode,
} }
static inline int _allocate_block(struct reiserfs_transaction_handle *th, static inline int _allocate_block(struct reiserfs_transaction_handle *th,
long block, sector_t block,
struct inode *inode, struct inode *inode,
b_blocknr_t * allocated_block_nr, b_blocknr_t * allocated_block_nr,
struct treepath *path, int flags) struct treepath *path, int flags)
......
...@@ -219,11 +219,12 @@ static void allocate_bitmap_nodes(struct super_block *p_s_sb) ...@@ -219,11 +219,12 @@ static void allocate_bitmap_nodes(struct super_block *p_s_sb)
} }
} }
static int set_bit_in_list_bitmap(struct super_block *p_s_sb, int block, static int set_bit_in_list_bitmap(struct super_block *p_s_sb,
b_blocknr_t block,
struct reiserfs_list_bitmap *jb) struct reiserfs_list_bitmap *jb)
{ {
int bmap_nr = block / (p_s_sb->s_blocksize << 3); unsigned int bmap_nr = block / (p_s_sb->s_blocksize << 3);
int bit_nr = block % (p_s_sb->s_blocksize << 3); unsigned int bit_nr = block % (p_s_sb->s_blocksize << 3);
if (!jb->bitmaps[bmap_nr]) { if (!jb->bitmaps[bmap_nr]) {
jb->bitmaps[bmap_nr] = get_bitmap_node(p_s_sb); jb->bitmaps[bmap_nr] = get_bitmap_node(p_s_sb);
...@@ -289,7 +290,7 @@ static int free_bitmap_nodes(struct super_block *p_s_sb) ...@@ -289,7 +290,7 @@ static int free_bitmap_nodes(struct super_block *p_s_sb)
*/ */
int reiserfs_allocate_list_bitmaps(struct super_block *p_s_sb, int reiserfs_allocate_list_bitmaps(struct super_block *p_s_sb,
struct reiserfs_list_bitmap *jb_array, struct reiserfs_list_bitmap *jb_array,
int bmap_nr) unsigned int bmap_nr)
{ {
int i; int i;
int failed = 0; int failed = 0;
...@@ -483,7 +484,7 @@ static inline struct reiserfs_journal_cnode *get_journal_hash_dev(struct ...@@ -483,7 +484,7 @@ static inline struct reiserfs_journal_cnode *get_journal_hash_dev(struct
** **
*/ */
int reiserfs_in_journal(struct super_block *p_s_sb, int reiserfs_in_journal(struct super_block *p_s_sb,
int bmap_nr, int bit_nr, int search_all, unsigned int bmap_nr, int bit_nr, int search_all,
b_blocknr_t * next_zero_bit) b_blocknr_t * next_zero_bit)
{ {
struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
...@@ -1013,7 +1014,7 @@ static int flush_commit_list(struct super_block *s, ...@@ -1013,7 +1014,7 @@ static int flush_commit_list(struct super_block *s,
struct reiserfs_journal_list *jl, int flushall) struct reiserfs_journal_list *jl, int flushall)
{ {
int i; int i;
int bn; b_blocknr_t bn;
struct buffer_head *tbh = NULL; struct buffer_head *tbh = NULL;
unsigned long trans_id = jl->j_trans_id; unsigned long trans_id = jl->j_trans_id;
struct reiserfs_journal *journal = SB_JOURNAL(s); struct reiserfs_journal *journal = SB_JOURNAL(s);
...@@ -2307,8 +2308,9 @@ static int journal_read_transaction(struct super_block *p_s_sb, ...@@ -2307,8 +2308,9 @@ static int journal_read_transaction(struct super_block *p_s_sb,
Right now it is only used from journal code. But later we might use it Right now it is only used from journal code. But later we might use it
from other places. from other places.
Note: Do not use journal_getblk/sb_getblk functions here! */ Note: Do not use journal_getblk/sb_getblk functions here! */
static struct buffer_head *reiserfs_breada(struct block_device *dev, int block, static struct buffer_head *reiserfs_breada(struct block_device *dev,
int bufsize, unsigned int max_block) b_blocknr_t block, int bufsize,
b_blocknr_t max_block)
{ {
struct buffer_head *bhlist[BUFNR]; struct buffer_head *bhlist[BUFNR];
unsigned int blocks = BUFNR; unsigned int blocks = BUFNR;
......
...@@ -559,7 +559,7 @@ static int is_tree_node(struct buffer_head *bh, int level) ...@@ -559,7 +559,7 @@ static int is_tree_node(struct buffer_head *bh, int level)
/* The function is NOT SCHEDULE-SAFE! */ /* The function is NOT SCHEDULE-SAFE! */
static void search_by_key_reada(struct super_block *s, static void search_by_key_reada(struct super_block *s,
struct buffer_head **bh, struct buffer_head **bh,
unsigned long *b, int num) b_blocknr_t *b, int num)
{ {
int i, j; int i, j;
...@@ -611,7 +611,7 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* ...@@ -611,7 +611,7 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /*
DISK_LEAF_NODE_LEVEL */ DISK_LEAF_NODE_LEVEL */
) )
{ {
int n_block_number; b_blocknr_t n_block_number;
int expected_level; int expected_level;
struct buffer_head *p_s_bh; struct buffer_head *p_s_bh;
struct path_element *p_s_last_element; struct path_element *p_s_last_element;
...@@ -619,7 +619,7 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* ...@@ -619,7 +619,7 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /*
int right_neighbor_of_leaf_node; int right_neighbor_of_leaf_node;
int fs_gen; int fs_gen;
struct buffer_head *reada_bh[SEARCH_BY_KEY_READA]; struct buffer_head *reada_bh[SEARCH_BY_KEY_READA];
unsigned long reada_blocks[SEARCH_BY_KEY_READA]; b_blocknr_t reada_blocks[SEARCH_BY_KEY_READA];
int reada_count = 0; int reada_count = 0;
#ifdef CONFIG_REISERFS_CHECK #ifdef CONFIG_REISERFS_CHECK
......
...@@ -1734,8 +1734,8 @@ int journal_end_sync(struct reiserfs_transaction_handle *, struct super_block *, ...@@ -1734,8 +1734,8 @@ int journal_end_sync(struct reiserfs_transaction_handle *, struct super_block *,
int journal_mark_freed(struct reiserfs_transaction_handle *, int journal_mark_freed(struct reiserfs_transaction_handle *,
struct super_block *, b_blocknr_t blocknr); struct super_block *, b_blocknr_t blocknr);
int journal_transaction_should_end(struct reiserfs_transaction_handle *, int); int journal_transaction_should_end(struct reiserfs_transaction_handle *, int);
int reiserfs_in_journal(struct super_block *p_s_sb, int bmap_nr, int bit_nr, int reiserfs_in_journal(struct super_block *p_s_sb, unsigned int bmap_nr,
int searchall, b_blocknr_t * next); int bit_nr, int searchall, b_blocknr_t *next);
int journal_begin(struct reiserfs_transaction_handle *, int journal_begin(struct reiserfs_transaction_handle *,
struct super_block *p_s_sb, unsigned long); struct super_block *p_s_sb, unsigned long);
int journal_join_abort(struct reiserfs_transaction_handle *, int journal_join_abort(struct reiserfs_transaction_handle *,
...@@ -1743,7 +1743,7 @@ int journal_join_abort(struct reiserfs_transaction_handle *, ...@@ -1743,7 +1743,7 @@ int journal_join_abort(struct reiserfs_transaction_handle *,
void reiserfs_journal_abort(struct super_block *sb, int errno); void reiserfs_journal_abort(struct super_block *sb, int errno);
void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...); void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...);
int reiserfs_allocate_list_bitmaps(struct super_block *s, int reiserfs_allocate_list_bitmaps(struct super_block *s,
struct reiserfs_list_bitmap *, int); struct reiserfs_list_bitmap *, unsigned int);
void add_save_link(struct reiserfs_transaction_handle *th, void add_save_link(struct reiserfs_transaction_handle *th,
struct inode *inode, int truncate); struct inode *inode, int truncate);
...@@ -2041,7 +2041,7 @@ struct buffer_head *get_FEB(struct tree_balance *); ...@@ -2041,7 +2041,7 @@ struct buffer_head *get_FEB(struct tree_balance *);
* arguments, such as node, search path, transaction_handle, etc. */ * arguments, such as node, search path, transaction_handle, etc. */
struct __reiserfs_blocknr_hint { struct __reiserfs_blocknr_hint {
struct inode *inode; /* inode passed to allocator, if we allocate unf. nodes */ struct inode *inode; /* inode passed to allocator, if we allocate unf. nodes */
long block; /* file offset, in blocks */ sector_t block; /* file offset, in blocks */
struct in_core_key key; struct in_core_key key;
struct treepath *path; /* search path, used by allocator to deternine search_start by struct treepath *path; /* search path, used by allocator to deternine search_start by
* various ways */ * various ways */
...@@ -2099,7 +2099,8 @@ static inline int reiserfs_new_form_blocknrs(struct tree_balance *tb, ...@@ -2099,7 +2099,8 @@ static inline int reiserfs_new_form_blocknrs(struct tree_balance *tb,
static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle
*th, struct inode *inode, *th, struct inode *inode,
b_blocknr_t * new_blocknrs, b_blocknr_t * new_blocknrs,
struct treepath *path, long block) struct treepath *path,
sector_t block)
{ {
reiserfs_blocknr_hint_t hint = { reiserfs_blocknr_hint_t hint = {
.th = th, .th = th,
...@@ -2116,7 +2117,8 @@ static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle ...@@ -2116,7 +2117,8 @@ static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle
static inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle static inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle
*th, struct inode *inode, *th, struct inode *inode,
b_blocknr_t * new_blocknrs, b_blocknr_t * new_blocknrs,
struct treepath *path, long block) struct treepath *path,
sector_t block)
{ {
reiserfs_blocknr_hint_t hint = { reiserfs_blocknr_hint_t hint = {
.th = th, .th = th,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment