Commit 60448b1d authored by Jan Kara's avatar Jan Kara Committed by Linus Torvalds

udf: use sector_t and loff_t for file offsets

Use sector_t and loff_t for file offsets in UDF filesystem.  Otherwise an
overflow may occur for long files.  Also make inode_bmap() return offset in
the extent in number of blocks instead of number of bytes - for most
callers this is more convenient.
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Acked-by: default avatarChristoph Hellwig <hch@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 277866a0
...@@ -113,7 +113,8 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d ...@@ -113,7 +113,8 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d
loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2; loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
struct buffer_head * bh = NULL, * tmp, * bha[16]; struct buffer_head * bh = NULL, * tmp, * bha[16];
kernel_lb_addr bloc, eloc; kernel_lb_addr bloc, eloc;
uint32_t extoffset, elen, offset; uint32_t extoffset, elen;
sector_t offset;
int i, num; int i, num;
unsigned int dt_type; unsigned int dt_type;
...@@ -129,7 +130,6 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d ...@@ -129,7 +130,6 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d
else if (inode_bmap(dir, nf_pos >> (dir->i_sb->s_blocksize_bits - 2), else if (inode_bmap(dir, nf_pos >> (dir->i_sb->s_blocksize_bits - 2),
&bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30)) &bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
{ {
offset >>= dir->i_sb->s_blocksize_bits;
block = udf_get_lb_pblock(dir->i_sb, eloc, offset); block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
if ((++offset << dir->i_sb->s_blocksize_bits) < elen) if ((++offset << dir->i_sb->s_blocksize_bits) < elen)
{ {
......
...@@ -77,7 +77,7 @@ udf_fileident_read(struct inode *dir, loff_t *nf_pos, ...@@ -77,7 +77,7 @@ udf_fileident_read(struct inode *dir, loff_t *nf_pos,
struct fileIdentDesc *cfi, struct fileIdentDesc *cfi,
kernel_lb_addr *bloc, uint32_t *extoffset, kernel_lb_addr *bloc, uint32_t *extoffset,
kernel_lb_addr *eloc, uint32_t *elen, kernel_lb_addr *eloc, uint32_t *elen,
uint32_t *offset, struct buffer_head **bh) sector_t *offset, struct buffer_head **bh)
{ {
struct fileIdentDesc *fi; struct fileIdentDesc *fi;
int i, num, block; int i, num, block;
......
...@@ -49,7 +49,7 @@ MODULE_LICENSE("GPL"); ...@@ -49,7 +49,7 @@ MODULE_LICENSE("GPL");
static mode_t udf_convert_permissions(struct fileEntry *); static mode_t udf_convert_permissions(struct fileEntry *);
static int udf_update_inode(struct inode *, int); static int udf_update_inode(struct inode *, int);
static void udf_fill_inode(struct inode *, struct buffer_head *); static void udf_fill_inode(struct inode *, struct buffer_head *);
static struct buffer_head *inode_getblk(struct inode *, long, int *, static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
long *, int *); long *, int *);
static int8_t udf_insert_aext(struct inode *, kernel_lb_addr, int, static int8_t udf_insert_aext(struct inode *, kernel_lb_addr, int,
kernel_lb_addr, uint32_t, struct buffer_head *); kernel_lb_addr, uint32_t, struct buffer_head *);
...@@ -354,7 +354,7 @@ udf_getblk(struct inode *inode, long block, int create, int *err) ...@@ -354,7 +354,7 @@ udf_getblk(struct inode *inode, long block, int create, int *err)
return NULL; return NULL;
} }
static struct buffer_head * inode_getblk(struct inode * inode, long block, static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
int *err, long *phys, int *new) int *err, long *phys, int *new)
{ {
struct buffer_head *pbh = NULL, *cbh = NULL, *nbh = NULL, *result = NULL; struct buffer_head *pbh = NULL, *cbh = NULL, *nbh = NULL, *result = NULL;
...@@ -364,14 +364,15 @@ static struct buffer_head * inode_getblk(struct inode * inode, long block, ...@@ -364,14 +364,15 @@ static struct buffer_head * inode_getblk(struct inode * inode, long block,
uint32_t elen = 0; uint32_t elen = 0;
kernel_lb_addr eloc, pbloc, cbloc, nbloc; kernel_lb_addr eloc, pbloc, cbloc, nbloc;
int c = 1; int c = 1;
uint64_t lbcount = 0, b_off = 0; loff_t lbcount = 0, b_off = 0;
uint32_t newblocknum, newblock, offset = 0; uint32_t newblocknum, newblock;
sector_t offset = 0;
int8_t etype; int8_t etype;
int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum; int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum;
char lastblock = 0; char lastblock = 0;
pextoffset = cextoffset = nextoffset = udf_file_entry_alloc_offset(inode); pextoffset = cextoffset = nextoffset = udf_file_entry_alloc_offset(inode);
b_off = (uint64_t)block << inode->i_sb->s_blocksize_bits; b_off = (loff_t)block << inode->i_sb->s_blocksize_bits;
pbloc = cbloc = nbloc = UDF_I_LOCATION(inode); pbloc = cbloc = nbloc = UDF_I_LOCATION(inode);
/* find the extent which contains the block we are looking for. /* find the extent which contains the block we are looking for.
...@@ -1948,10 +1949,10 @@ int8_t udf_delete_aext(struct inode *inode, kernel_lb_addr nbloc, int nextoffset ...@@ -1948,10 +1949,10 @@ int8_t udf_delete_aext(struct inode *inode, kernel_lb_addr nbloc, int nextoffset
return (elen >> 30); return (elen >> 30);
} }
int8_t inode_bmap(struct inode *inode, int block, kernel_lb_addr *bloc, uint32_t *extoffset, int8_t inode_bmap(struct inode *inode, sector_t block, kernel_lb_addr *bloc, uint32_t *extoffset,
kernel_lb_addr *eloc, uint32_t *elen, uint32_t *offset, struct buffer_head **bh) kernel_lb_addr *eloc, uint32_t *elen, sector_t *offset, struct buffer_head **bh)
{ {
uint64_t lbcount = 0, bcount = (uint64_t)block << inode->i_sb->s_blocksize_bits; loff_t lbcount = 0, bcount = (loff_t)block << inode->i_sb->s_blocksize_bits;
int8_t etype; int8_t etype;
if (block < 0) if (block < 0)
...@@ -1968,29 +1969,30 @@ int8_t inode_bmap(struct inode *inode, int block, kernel_lb_addr *bloc, uint32_t ...@@ -1968,29 +1969,30 @@ int8_t inode_bmap(struct inode *inode, int block, kernel_lb_addr *bloc, uint32_t
{ {
if ((etype = udf_next_aext(inode, bloc, extoffset, eloc, elen, bh, 1)) == -1) if ((etype = udf_next_aext(inode, bloc, extoffset, eloc, elen, bh, 1)) == -1)
{ {
*offset = bcount - lbcount; *offset = (bcount - lbcount) >> inode->i_sb->s_blocksize_bits;
UDF_I_LENEXTENTS(inode) = lbcount; UDF_I_LENEXTENTS(inode) = lbcount;
return -1; return -1;
} }
lbcount += *elen; lbcount += *elen;
} while (lbcount <= bcount); } while (lbcount <= bcount);
*offset = bcount + *elen - lbcount; *offset = (bcount + *elen - lbcount) >> inode->i_sb->s_blocksize_bits;
return etype; return etype;
} }
long udf_block_map(struct inode *inode, long block) long udf_block_map(struct inode *inode, sector_t block)
{ {
kernel_lb_addr eloc, bloc; kernel_lb_addr eloc, bloc;
uint32_t offset, extoffset, elen; uint32_t extoffset, elen;
sector_t offset;
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
int ret; int ret;
lock_kernel(); lock_kernel();
if (inode_bmap(inode, block, &bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30)) if (inode_bmap(inode, block, &bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
ret = udf_get_lb_pblock(inode->i_sb, eloc, offset >> inode->i_sb->s_blocksize_bits); ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
else else
ret = 0; ret = 0;
......
...@@ -156,7 +156,8 @@ udf_find_entry(struct inode *dir, struct dentry *dentry, ...@@ -156,7 +156,8 @@ udf_find_entry(struct inode *dir, struct dentry *dentry,
uint16_t liu; uint16_t liu;
loff_t size; loff_t size;
kernel_lb_addr bloc, eloc; kernel_lb_addr bloc, eloc;
uint32_t extoffset, elen, offset; uint32_t extoffset, elen;
sector_t offset;
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
size = (udf_ext0_offset(dir) + dir->i_size) >> 2; size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
...@@ -168,7 +169,6 @@ udf_find_entry(struct inode *dir, struct dentry *dentry, ...@@ -168,7 +169,6 @@ udf_find_entry(struct inode *dir, struct dentry *dentry,
else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
&bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30)) &bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
{ {
offset >>= dir->i_sb->s_blocksize_bits;
block = udf_get_lb_pblock(dir->i_sb, eloc, offset); block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
if ((++offset << dir->i_sb->s_blocksize_bits) < elen) if ((++offset << dir->i_sb->s_blocksize_bits) < elen)
{ {
...@@ -354,7 +354,8 @@ udf_add_entry(struct inode *dir, struct dentry *dentry, ...@@ -354,7 +354,8 @@ udf_add_entry(struct inode *dir, struct dentry *dentry,
uint16_t liu; uint16_t liu;
int block; int block;
kernel_lb_addr bloc, eloc; kernel_lb_addr bloc, eloc;
uint32_t extoffset, elen, offset; uint32_t extoffset, elen;
sector_t offset;
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
sb = dir->i_sb; sb = dir->i_sb;
...@@ -386,7 +387,6 @@ udf_add_entry(struct inode *dir, struct dentry *dentry, ...@@ -386,7 +387,6 @@ udf_add_entry(struct inode *dir, struct dentry *dentry,
else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
&bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30)) &bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
{ {
offset >>= dir->i_sb->s_blocksize_bits;
block = udf_get_lb_pblock(dir->i_sb, eloc, offset); block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
if ((++offset << dir->i_sb->s_blocksize_bits) < elen) if ((++offset << dir->i_sb->s_blocksize_bits) < elen)
{ {
...@@ -782,7 +782,8 @@ static int empty_dir(struct inode *dir) ...@@ -782,7 +782,8 @@ static int empty_dir(struct inode *dir)
loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2; loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
int block; int block;
kernel_lb_addr bloc, eloc; kernel_lb_addr bloc, eloc;
uint32_t extoffset, elen, offset; uint32_t extoffset, elen;
sector_t offset;
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
f_pos = (udf_ext0_offset(dir) >> 2); f_pos = (udf_ext0_offset(dir) >> 2);
...@@ -794,7 +795,6 @@ static int empty_dir(struct inode *dir) ...@@ -794,7 +795,6 @@ static int empty_dir(struct inode *dir)
else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
&bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30)) &bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
{ {
offset >>= dir->i_sb->s_blocksize_bits;
block = udf_get_lb_pblock(dir->i_sb, eloc, offset); block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
if ((++offset << dir->i_sb->s_blocksize_bits) < elen) if ((++offset << dir->i_sb->s_blocksize_bits) < elen)
{ {
......
...@@ -125,9 +125,10 @@ void udf_discard_prealloc(struct inode * inode) ...@@ -125,9 +125,10 @@ void udf_discard_prealloc(struct inode * inode)
void udf_truncate_extents(struct inode * inode) void udf_truncate_extents(struct inode * inode)
{ {
kernel_lb_addr bloc, eloc, neloc = { 0, 0 }; kernel_lb_addr bloc, eloc, neloc = { 0, 0 };
uint32_t extoffset, elen, offset, nelen = 0, lelen = 0, lenalloc; uint32_t extoffset, elen, nelen = 0, lelen = 0, lenalloc;
int8_t etype; int8_t etype;
int first_block = inode->i_size >> inode->i_sb->s_blocksize_bits; sector_t first_block = inode->i_size >> inode->i_sb->s_blocksize_bits, offset;
loff_t byte_offset;
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
int adsize; int adsize;
...@@ -139,14 +140,14 @@ void udf_truncate_extents(struct inode * inode) ...@@ -139,14 +140,14 @@ void udf_truncate_extents(struct inode * inode)
adsize = 0; adsize = 0;
etype = inode_bmap(inode, first_block, &bloc, &extoffset, &eloc, &elen, &offset, &bh); etype = inode_bmap(inode, first_block, &bloc, &extoffset, &eloc, &elen, &offset, &bh);
offset += (inode->i_size & (inode->i_sb->s_blocksize - 1)); byte_offset = (offset << inode->i_sb->s_blocksize_bits) + (inode->i_size & (inode->i_sb->s_blocksize-1));
if (etype != -1) if (etype != -1)
{ {
extoffset -= adsize; extoffset -= adsize;
extent_trunc(inode, bloc, extoffset, eloc, etype, elen, bh, offset); extent_trunc(inode, bloc, extoffset, eloc, etype, elen, bh, byte_offset);
extoffset += adsize; extoffset += adsize;
if (offset) if (byte_offset)
lenalloc = extoffset; lenalloc = extoffset;
else else
lenalloc = extoffset - adsize; lenalloc = extoffset - adsize;
...@@ -237,7 +238,7 @@ void udf_truncate_extents(struct inode * inode) ...@@ -237,7 +238,7 @@ void udf_truncate_extents(struct inode * inode)
} }
else if (inode->i_size) else if (inode->i_size)
{ {
if (offset) if (byte_offset)
{ {
/* /*
* OK, there is not extent covering inode->i_size and * OK, there is not extent covering inode->i_size and
...@@ -248,7 +249,7 @@ void udf_truncate_extents(struct inode * inode) ...@@ -248,7 +249,7 @@ void udf_truncate_extents(struct inode * inode)
(bh && extoffset == sizeof(struct allocExtDesc))) { (bh && extoffset == sizeof(struct allocExtDesc))) {
/* File has no extents at all! */ /* File has no extents at all! */
memset(&eloc, 0x00, sizeof(kernel_lb_addr)); memset(&eloc, 0x00, sizeof(kernel_lb_addr));
elen = EXT_NOT_RECORDED_NOT_ALLOCATED | offset; elen = EXT_NOT_RECORDED_NOT_ALLOCATED | byte_offset;
udf_add_aext(inode, &bloc, &extoffset, eloc, elen, &bh, 1); udf_add_aext(inode, &bloc, &extoffset, eloc, elen, &bh, 1);
} }
else { else {
...@@ -257,7 +258,7 @@ void udf_truncate_extents(struct inode * inode) ...@@ -257,7 +258,7 @@ void udf_truncate_extents(struct inode * inode)
if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
{ {
extoffset -= adsize; extoffset -= adsize;
elen = EXT_NOT_RECORDED_NOT_ALLOCATED | (elen + offset); elen = EXT_NOT_RECORDED_NOT_ALLOCATED | (elen + byte_offset);
udf_write_aext(inode, bloc, &extoffset, eloc, elen, bh, 0); udf_write_aext(inode, bloc, &extoffset, eloc, elen, bh, 0);
} }
else if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) else if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
...@@ -265,7 +266,7 @@ void udf_truncate_extents(struct inode * inode) ...@@ -265,7 +266,7 @@ void udf_truncate_extents(struct inode * inode)
kernel_lb_addr neloc = { 0, 0 }; kernel_lb_addr neloc = { 0, 0 };
extoffset -= adsize; extoffset -= adsize;
nelen = EXT_NOT_RECORDED_NOT_ALLOCATED | nelen = EXT_NOT_RECORDED_NOT_ALLOCATED |
((elen + offset + inode->i_sb->s_blocksize - 1) & ((elen + byte_offset + inode->i_sb->s_blocksize - 1) &
~(inode->i_sb->s_blocksize - 1)); ~(inode->i_sb->s_blocksize - 1));
udf_write_aext(inode, bloc, &extoffset, neloc, nelen, bh, 1); udf_write_aext(inode, bloc, &extoffset, neloc, nelen, bh, 1);
udf_add_aext(inode, &bloc, &extoffset, eloc, (etype << 30) | elen, &bh, 1); udf_add_aext(inode, &bloc, &extoffset, eloc, (etype << 30) | elen, &bh, 1);
...@@ -281,7 +282,7 @@ void udf_truncate_extents(struct inode * inode) ...@@ -281,7 +282,7 @@ void udf_truncate_extents(struct inode * inode)
udf_write_aext(inode, bloc, &extoffset, eloc, elen, bh, 1); udf_write_aext(inode, bloc, &extoffset, eloc, elen, bh, 1);
} }
memset(&eloc, 0x00, sizeof(kernel_lb_addr)); memset(&eloc, 0x00, sizeof(kernel_lb_addr));
elen = EXT_NOT_RECORDED_NOT_ALLOCATED | offset; elen = EXT_NOT_RECORDED_NOT_ALLOCATED | byte_offset;
udf_add_aext(inode, &bloc, &extoffset, eloc, elen, &bh, 1); udf_add_aext(inode, &bloc, &extoffset, eloc, elen, &bh, 1);
} }
} }
......
...@@ -98,8 +98,8 @@ extern void udf_read_inode(struct inode *); ...@@ -98,8 +98,8 @@ extern void udf_read_inode(struct inode *);
extern void udf_delete_inode(struct inode *); extern void udf_delete_inode(struct inode *);
extern void udf_clear_inode(struct inode *); extern void udf_clear_inode(struct inode *);
extern int udf_write_inode(struct inode *, int); extern int udf_write_inode(struct inode *, int);
extern long udf_block_map(struct inode *, long); extern long udf_block_map(struct inode *, sector_t);
extern int8_t inode_bmap(struct inode *, int, kernel_lb_addr *, uint32_t *, kernel_lb_addr *, uint32_t *, uint32_t *, struct buffer_head **); extern int8_t inode_bmap(struct inode *, sector_t, kernel_lb_addr *, uint32_t *, kernel_lb_addr *, uint32_t *, sector_t *, struct buffer_head **);
extern int8_t udf_add_aext(struct inode *, kernel_lb_addr *, int *, kernel_lb_addr, uint32_t, struct buffer_head **, int); extern int8_t udf_add_aext(struct inode *, kernel_lb_addr *, int *, kernel_lb_addr, uint32_t, struct buffer_head **, int);
extern int8_t udf_write_aext(struct inode *, kernel_lb_addr, int *, kernel_lb_addr, uint32_t, struct buffer_head *, int); extern int8_t udf_write_aext(struct inode *, kernel_lb_addr, int *, kernel_lb_addr, uint32_t, struct buffer_head *, int);
extern int8_t udf_delete_aext(struct inode *, kernel_lb_addr, int, kernel_lb_addr, uint32_t, struct buffer_head *); extern int8_t udf_delete_aext(struct inode *, kernel_lb_addr, int, kernel_lb_addr, uint32_t, struct buffer_head *);
...@@ -151,7 +151,7 @@ extern int udf_new_block(struct super_block *, struct inode *, uint16_t, uint32_ ...@@ -151,7 +151,7 @@ extern int udf_new_block(struct super_block *, struct inode *, uint16_t, uint32_
extern int udf_fsync_file(struct file *, struct dentry *, int); extern int udf_fsync_file(struct file *, struct dentry *, int);
/* directory.c */ /* directory.c */
extern struct fileIdentDesc * udf_fileident_read(struct inode *, loff_t *, struct udf_fileident_bh *, struct fileIdentDesc *, kernel_lb_addr *, uint32_t *, kernel_lb_addr *, uint32_t *, uint32_t *, struct buffer_head **); extern struct fileIdentDesc * udf_fileident_read(struct inode *, loff_t *, struct udf_fileident_bh *, struct fileIdentDesc *, kernel_lb_addr *, uint32_t *, kernel_lb_addr *, uint32_t *, sector_t *, struct buffer_head **);
extern struct fileIdentDesc * udf_get_fileident(void * buffer, int bufsize, int * offset); extern struct fileIdentDesc * udf_get_fileident(void * buffer, int bufsize, int * offset);
extern long_ad * udf_get_filelongad(uint8_t *, int, int *, int); extern long_ad * udf_get_filelongad(uint8_t *, int, int *, int);
extern short_ad * udf_get_fileshortad(uint8_t *, int, int *, int); extern short_ad * udf_get_fileshortad(uint8_t *, int, int *, int);
......
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