aboutsummaryrefslogtreecommitdiffstats
path: root/fs/udf/namei.c
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2008-02-08 07:20:50 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-08 12:22:36 -0500
commitaf793295bf9ee92660f5e77d337b0493cea3f9b9 (patch)
tree139f7dd09dbfcae1f98c3af52638e94a52ed5560 /fs/udf/namei.c
parent32a8f24dd75c2be34606e77414afba7bc6b5b366 (diff)
udf: cleanup directory offset handling
Position in directory returned by readdir is offset of directory entry divided by four (don't ask me why). Make this conversion only when reading f_pos from userspace / writing it there and internally work in bytes. It makes things more easily readable and also fixes a bug (we forgot to divide length of the entry by 4 when advancing f_pos in udf_add_entry()). Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/udf/namei.c')
-rw-r--r--fs/udf/namei.c39
1 files changed, 17 insertions, 22 deletions
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 4bf83d570456..dacd8f4cea8a 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -160,14 +160,13 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
160 struct extent_position epos = {}; 160 struct extent_position epos = {};
161 struct udf_inode_info *dinfo = UDF_I(dir); 161 struct udf_inode_info *dinfo = UDF_I(dir);
162 162
163 size = (udf_ext0_offset(dir) + dir->i_size) >> 2; 163 size = udf_ext0_offset(dir) + dir->i_size;
164 f_pos = (udf_ext0_offset(dir) >> 2); 164 f_pos = udf_ext0_offset(dir);
165 165
166 fibh->soffset = fibh->eoffset = 166 fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
167 (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
168 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) 167 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
169 fibh->sbh = fibh->ebh = NULL; 168 fibh->sbh = fibh->ebh = NULL;
170 else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 169 else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits,
171 &epos, &eloc, &elen, &offset) == 170 &epos, &eloc, &elen, &offset) ==
172 (EXT_RECORDED_ALLOCATED >> 30)) { 171 (EXT_RECORDED_ALLOCATED >> 30)) {
173 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 172 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
@@ -189,7 +188,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
189 return NULL; 188 return NULL;
190 } 189 }
191 190
192 while ((f_pos < size)) { 191 while (f_pos < size) {
193 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, 192 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
194 &elen, &offset); 193 &elen, &offset);
195 if (!fi) { 194 if (!fi) {
@@ -342,7 +341,7 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
342 loff_t f_pos; 341 loff_t f_pos;
343 int flen; 342 int flen;
344 char *nameptr; 343 char *nameptr;
345 loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2; 344 loff_t size = udf_ext0_offset(dir) + dir->i_size;
346 int nfidlen; 345 int nfidlen;
347 uint8_t lfi; 346 uint8_t lfi;
348 uint16_t liu; 347 uint16_t liu;
@@ -370,14 +369,13 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
370 369
371 nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3; 370 nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3;
372 371
373 f_pos = (udf_ext0_offset(dir) >> 2); 372 f_pos = udf_ext0_offset(dir);
374 373
375 fibh->soffset = fibh->eoffset = 374 fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
376 (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
377 dinfo = UDF_I(dir); 375 dinfo = UDF_I(dir);
378 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) 376 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
379 fibh->sbh = fibh->ebh = NULL; 377 fibh->sbh = fibh->ebh = NULL;
380 else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 378 else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits,
381 &epos, &eloc, &elen, &offset) == 379 &epos, &eloc, &elen, &offset) ==
382 (EXT_RECORDED_ALLOCATED >> 30)) { 380 (EXT_RECORDED_ALLOCATED >> 30)) {
383 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 381 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
@@ -405,7 +403,7 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
405 goto add; 403 goto add;
406 } 404 }
407 405
408 while ((f_pos < size)) { 406 while (f_pos < size) {
409 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc, 407 fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
410 &elen, &offset); 408 &elen, &offset);
411 409
@@ -484,7 +482,7 @@ add:
484 epos.bh = NULL; 482 epos.bh = NULL;
485 fibh->soffset -= udf_ext0_offset(dir); 483 fibh->soffset -= udf_ext0_offset(dir);
486 fibh->eoffset -= udf_ext0_offset(dir); 484 fibh->eoffset -= udf_ext0_offset(dir);
487 f_pos -= (udf_ext0_offset(dir) >> 2); 485 f_pos -= udf_ext0_offset(dir);
488 if (fibh->sbh != fibh->ebh) 486 if (fibh->sbh != fibh->ebh)
489 brelse(fibh->ebh); 487 brelse(fibh->ebh);
490 brelse(fibh->sbh); 488 brelse(fibh->sbh);
@@ -537,8 +535,7 @@ add:
537 block = eloc.logicalBlockNum + ((elen - 1) >> 535 block = eloc.logicalBlockNum + ((elen - 1) >>
538 dir->i_sb->s_blocksize_bits); 536 dir->i_sb->s_blocksize_bits);
539 fibh->ebh = udf_bread(dir, 537 fibh->ebh = udf_bread(dir,
540 f_pos >> (dir->i_sb->s_blocksize_bits - 2), 538 f_pos >> dir->i_sb->s_blocksize_bits, 1, err);
541 1, err);
542 if (!fibh->ebh) { 539 if (!fibh->ebh) {
543 brelse(epos.bh); 540 brelse(epos.bh);
544 brelse(fibh->sbh); 541 brelse(fibh->sbh);
@@ -775,7 +772,7 @@ static int empty_dir(struct inode *dir)
775 struct fileIdentDesc *fi, cfi; 772 struct fileIdentDesc *fi, cfi;
776 struct udf_fileident_bh fibh; 773 struct udf_fileident_bh fibh;
777 loff_t f_pos; 774 loff_t f_pos;
778 loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2; 775 loff_t size = udf_ext0_offset(dir) + dir->i_size;
779 int block; 776 int block;
780 kernel_lb_addr eloc; 777 kernel_lb_addr eloc;
781 uint32_t elen; 778 uint32_t elen;
@@ -783,14 +780,12 @@ static int empty_dir(struct inode *dir)
783 struct extent_position epos = {}; 780 struct extent_position epos = {};
784 struct udf_inode_info *dinfo = UDF_I(dir); 781 struct udf_inode_info *dinfo = UDF_I(dir);
785 782
786 f_pos = (udf_ext0_offset(dir) >> 2); 783 f_pos = udf_ext0_offset(dir);
787 784 fibh.soffset = fibh.eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
788 fibh.soffset = fibh.eoffset =
789 (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
790 785
791 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) 786 if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
792 fibh.sbh = fibh.ebh = NULL; 787 fibh.sbh = fibh.ebh = NULL;
793 else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 788 else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits,
794 &epos, &eloc, &elen, &offset) == 789 &epos, &eloc, &elen, &offset) ==
795 (EXT_RECORDED_ALLOCATED >> 30)) { 790 (EXT_RECORDED_ALLOCATED >> 30)) {
796 block = udf_get_lb_pblock(dir->i_sb, eloc, offset); 791 block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
@@ -812,7 +807,7 @@ static int empty_dir(struct inode *dir)
812 return 0; 807 return 0;
813 } 808 }
814 809
815 while ((f_pos < size)) { 810 while (f_pos < size) {
816 fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc, 811 fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc,
817 &elen, &offset); 812 &elen, &offset);
818 if (!fi) { 813 if (!fi) {