Skip to content

Commit 60448b1

Browse files
jankaraLinus Torvalds
authored andcommitted
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: Jan Kara <jack@suse.cz> Acked-by: Christoph Hellwig <hch@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 277866a commit 60448b1

6 files changed

Lines changed: 38 additions & 35 deletions

File tree

‎fs/udf/dir.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d
113113
loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
114114
struct buffer_head * bh = NULL, * tmp, * bha[16];
115115
kernel_lb_addr bloc, eloc;
116-
uint32_t extoffset, elen, offset;
116+
uint32_t extoffset, elen;
117+
sector_t offset;
117118
int i, num;
118119
unsigned int dt_type;
119120

@@ -129,7 +130,6 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d
129130
else if (inode_bmap(dir, nf_pos >> (dir->i_sb->s_blocksize_bits - 2),
130131
&bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
131132
{
132-
offset >>= dir->i_sb->s_blocksize_bits;
133133
block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
134134
if ((++offset << dir->i_sb->s_blocksize_bits) < elen)
135135
{

‎fs/udf/directory.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ udf_fileident_read(struct inode *dir, loff_t *nf_pos,
7777
struct fileIdentDesc *cfi,
7878
kernel_lb_addr *bloc, uint32_t *extoffset,
7979
kernel_lb_addr *eloc, uint32_t *elen,
80-
uint32_t *offset, struct buffer_head **bh)
80+
sector_t *offset, struct buffer_head **bh)
8181
{
8282
struct fileIdentDesc *fi;
8383
int i, num, block;

‎fs/udf/inode.c‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ MODULE_LICENSE("GPL");
4949
static mode_t udf_convert_permissions(struct fileEntry *);
5050
static int udf_update_inode(struct inode *, int);
5151
static void udf_fill_inode(struct inode *, struct buffer_head *);
52-
static struct buffer_head *inode_getblk(struct inode *, long, int *,
52+
static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
5353
long *, int *);
5454
static int8_t udf_insert_aext(struct inode *, kernel_lb_addr, int,
5555
kernel_lb_addr, uint32_t, struct buffer_head *);
@@ -354,7 +354,7 @@ udf_getblk(struct inode *inode, long block, int create, int *err)
354354
return NULL;
355355
}
356356

357-
static struct buffer_head * inode_getblk(struct inode * inode, long block,
357+
static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
358358
int *err, long *phys, int *new)
359359
{
360360
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,
364364
uint32_t elen = 0;
365365
kernel_lb_addr eloc, pbloc, cbloc, nbloc;
366366
int c = 1;
367-
uint64_t lbcount = 0, b_off = 0;
368-
uint32_t newblocknum, newblock, offset = 0;
367+
loff_t lbcount = 0, b_off = 0;
368+
uint32_t newblocknum, newblock;
369+
sector_t offset = 0;
369370
int8_t etype;
370371
int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum;
371372
char lastblock = 0;
372373

373374
pextoffset = cextoffset = nextoffset = udf_file_entry_alloc_offset(inode);
374-
b_off = (uint64_t)block << inode->i_sb->s_blocksize_bits;
375+
b_off = (loff_t)block << inode->i_sb->s_blocksize_bits;
375376
pbloc = cbloc = nbloc = UDF_I_LOCATION(inode);
376377

377378
/* 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
19481949
return (elen >> 30);
19491950
}
19501951

1951-
int8_t inode_bmap(struct inode *inode, int block, kernel_lb_addr *bloc, uint32_t *extoffset,
1952-
kernel_lb_addr *eloc, uint32_t *elen, uint32_t *offset, struct buffer_head **bh)
1952+
int8_t inode_bmap(struct inode *inode, sector_t block, kernel_lb_addr *bloc, uint32_t *extoffset,
1953+
kernel_lb_addr *eloc, uint32_t *elen, sector_t *offset, struct buffer_head **bh)
19531954
{
1954-
uint64_t lbcount = 0, bcount = (uint64_t)block << inode->i_sb->s_blocksize_bits;
1955+
loff_t lbcount = 0, bcount = (loff_t)block << inode->i_sb->s_blocksize_bits;
19551956
int8_t etype;
19561957

19571958
if (block < 0)
@@ -1968,29 +1969,30 @@ int8_t inode_bmap(struct inode *inode, int block, kernel_lb_addr *bloc, uint32_t
19681969
{
19691970
if ((etype = udf_next_aext(inode, bloc, extoffset, eloc, elen, bh, 1)) == -1)
19701971
{
1971-
*offset = bcount - lbcount;
1972+
*offset = (bcount - lbcount) >> inode->i_sb->s_blocksize_bits;
19721973
UDF_I_LENEXTENTS(inode) = lbcount;
19731974
return -1;
19741975
}
19751976
lbcount += *elen;
19761977
} while (lbcount <= bcount);
19771978

1978-
*offset = bcount + *elen - lbcount;
1979+
*offset = (bcount + *elen - lbcount) >> inode->i_sb->s_blocksize_bits;
19791980

19801981
return etype;
19811982
}
19821983

1983-
long udf_block_map(struct inode *inode, long block)
1984+
long udf_block_map(struct inode *inode, sector_t block)
19841985
{
19851986
kernel_lb_addr eloc, bloc;
1986-
uint32_t offset, extoffset, elen;
1987+
uint32_t extoffset, elen;
1988+
sector_t offset;
19871989
struct buffer_head *bh = NULL;
19881990
int ret;
19891991

19901992
lock_kernel();
19911993

19921994
if (inode_bmap(inode, block, &bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
1993-
ret = udf_get_lb_pblock(inode->i_sb, eloc, offset >> inode->i_sb->s_blocksize_bits);
1995+
ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
19941996
else
19951997
ret = 0;
19961998

‎fs/udf/namei.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ udf_find_entry(struct inode *dir, struct dentry *dentry,
156156
uint16_t liu;
157157
loff_t size;
158158
kernel_lb_addr bloc, eloc;
159-
uint32_t extoffset, elen, offset;
159+
uint32_t extoffset, elen;
160+
sector_t offset;
160161
struct buffer_head *bh = NULL;
161162

162163
size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
@@ -168,7 +169,6 @@ udf_find_entry(struct inode *dir, struct dentry *dentry,
168169
else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
169170
&bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
170171
{
171-
offset >>= dir->i_sb->s_blocksize_bits;
172172
block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
173173
if ((++offset << dir->i_sb->s_blocksize_bits) < elen)
174174
{
@@ -354,7 +354,8 @@ udf_add_entry(struct inode *dir, struct dentry *dentry,
354354
uint16_t liu;
355355
int block;
356356
kernel_lb_addr bloc, eloc;
357-
uint32_t extoffset, elen, offset;
357+
uint32_t extoffset, elen;
358+
sector_t offset;
358359
struct buffer_head *bh = NULL;
359360

360361
sb = dir->i_sb;
@@ -386,7 +387,6 @@ udf_add_entry(struct inode *dir, struct dentry *dentry,
386387
else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
387388
&bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
388389
{
389-
offset >>= dir->i_sb->s_blocksize_bits;
390390
block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
391391
if ((++offset << dir->i_sb->s_blocksize_bits) < elen)
392392
{
@@ -782,7 +782,8 @@ static int empty_dir(struct inode *dir)
782782
loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
783783
int block;
784784
kernel_lb_addr bloc, eloc;
785-
uint32_t extoffset, elen, offset;
785+
uint32_t extoffset, elen;
786+
sector_t offset;
786787
struct buffer_head *bh = NULL;
787788

788789
f_pos = (udf_ext0_offset(dir) >> 2);
@@ -794,7 +795,6 @@ static int empty_dir(struct inode *dir)
794795
else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
795796
&bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
796797
{
797-
offset >>= dir->i_sb->s_blocksize_bits;
798798
block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
799799
if ((++offset << dir->i_sb->s_blocksize_bits) < elen)
800800
{

‎fs/udf/truncate.c‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,10 @@ void udf_discard_prealloc(struct inode * inode)
125125
void udf_truncate_extents(struct inode * inode)
126126
{
127127
kernel_lb_addr bloc, eloc, neloc = { 0, 0 };
128-
uint32_t extoffset, elen, offset, nelen = 0, lelen = 0, lenalloc;
128+
uint32_t extoffset, elen, nelen = 0, lelen = 0, lenalloc;
129129
int8_t etype;
130-
int first_block = inode->i_size >> inode->i_sb->s_blocksize_bits;
130+
sector_t first_block = inode->i_size >> inode->i_sb->s_blocksize_bits, offset;
131+
loff_t byte_offset;
131132
struct buffer_head *bh = NULL;
132133
int adsize;
133134

@@ -139,14 +140,14 @@ void udf_truncate_extents(struct inode * inode)
139140
adsize = 0;
140141

141142
etype = inode_bmap(inode, first_block, &bloc, &extoffset, &eloc, &elen, &offset, &bh);
142-
offset += (inode->i_size & (inode->i_sb->s_blocksize - 1));
143+
byte_offset = (offset << inode->i_sb->s_blocksize_bits) + (inode->i_size & (inode->i_sb->s_blocksize-1));
143144
if (etype != -1)
144145
{
145146
extoffset -= adsize;
146-
extent_trunc(inode, bloc, extoffset, eloc, etype, elen, bh, offset);
147+
extent_trunc(inode, bloc, extoffset, eloc, etype, elen, bh, byte_offset);
147148
extoffset += adsize;
148149

149-
if (offset)
150+
if (byte_offset)
150151
lenalloc = extoffset;
151152
else
152153
lenalloc = extoffset - adsize;
@@ -237,7 +238,7 @@ void udf_truncate_extents(struct inode * inode)
237238
}
238239
else if (inode->i_size)
239240
{
240-
if (offset)
241+
if (byte_offset)
241242
{
242243
/*
243244
* OK, there is not extent covering inode->i_size and
@@ -248,7 +249,7 @@ void udf_truncate_extents(struct inode * inode)
248249
(bh && extoffset == sizeof(struct allocExtDesc))) {
249250
/* File has no extents at all! */
250251
memset(&eloc, 0x00, sizeof(kernel_lb_addr));
251-
elen = EXT_NOT_RECORDED_NOT_ALLOCATED | offset;
252+
elen = EXT_NOT_RECORDED_NOT_ALLOCATED | byte_offset;
252253
udf_add_aext(inode, &bloc, &extoffset, eloc, elen, &bh, 1);
253254
}
254255
else {
@@ -257,15 +258,15 @@ void udf_truncate_extents(struct inode * inode)
257258
if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
258259
{
259260
extoffset -= adsize;
260-
elen = EXT_NOT_RECORDED_NOT_ALLOCATED | (elen + offset);
261+
elen = EXT_NOT_RECORDED_NOT_ALLOCATED | (elen + byte_offset);
261262
udf_write_aext(inode, bloc, &extoffset, eloc, elen, bh, 0);
262263
}
263264
else if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
264265
{
265266
kernel_lb_addr neloc = { 0, 0 };
266267
extoffset -= adsize;
267268
nelen = EXT_NOT_RECORDED_NOT_ALLOCATED |
268-
((elen + offset + inode->i_sb->s_blocksize - 1) &
269+
((elen + byte_offset + inode->i_sb->s_blocksize - 1) &
269270
~(inode->i_sb->s_blocksize - 1));
270271
udf_write_aext(inode, bloc, &extoffset, neloc, nelen, bh, 1);
271272
udf_add_aext(inode, &bloc, &extoffset, eloc, (etype << 30) | elen, &bh, 1);
@@ -281,7 +282,7 @@ void udf_truncate_extents(struct inode * inode)
281282
udf_write_aext(inode, bloc, &extoffset, eloc, elen, bh, 1);
282283
}
283284
memset(&eloc, 0x00, sizeof(kernel_lb_addr));
284-
elen = EXT_NOT_RECORDED_NOT_ALLOCATED | offset;
285+
elen = EXT_NOT_RECORDED_NOT_ALLOCATED | byte_offset;
285286
udf_add_aext(inode, &bloc, &extoffset, eloc, elen, &bh, 1);
286287
}
287288
}

‎fs/udf/udfdecl.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ extern void udf_read_inode(struct inode *);
9898
extern void udf_delete_inode(struct inode *);
9999
extern void udf_clear_inode(struct inode *);
100100
extern int udf_write_inode(struct inode *, int);
101-
extern long udf_block_map(struct inode *, long);
102-
extern int8_t inode_bmap(struct inode *, int, kernel_lb_addr *, uint32_t *, kernel_lb_addr *, uint32_t *, uint32_t *, struct buffer_head **);
101+
extern long udf_block_map(struct inode *, sector_t);
102+
extern int8_t inode_bmap(struct inode *, sector_t, kernel_lb_addr *, uint32_t *, kernel_lb_addr *, uint32_t *, sector_t *, struct buffer_head **);
103103
extern int8_t udf_add_aext(struct inode *, kernel_lb_addr *, int *, kernel_lb_addr, uint32_t, struct buffer_head **, int);
104104
extern int8_t udf_write_aext(struct inode *, kernel_lb_addr, int *, kernel_lb_addr, uint32_t, struct buffer_head *, int);
105105
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_
151151
extern int udf_fsync_file(struct file *, struct dentry *, int);
152152

153153
/* directory.c */
154-
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 **);
154+
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 **);
155155
extern struct fileIdentDesc * udf_get_fileident(void * buffer, int bufsize, int * offset);
156156
extern long_ad * udf_get_filelongad(uint8_t *, int, int *, int);
157157
extern short_ad * udf_get_fileshortad(uint8_t *, int, int *, int);

0 commit comments

Comments
 (0)