aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--fs/udf/directory.c7
-rw-r--r--fs/udf/inode.c8
-rw-r--r--fs/udf/namei.c39
3 files changed, 24 insertions, 30 deletions
diff --git a/fs/udf/directory.c b/fs/udf/directory.c
index be16d7698a8c..2820f8fcf4cc 100644
--- a/fs/udf/directory.c
+++ b/fs/udf/directory.c
@@ -95,7 +95,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos,
95 if (!fi) 95 if (!fi)
96 return NULL; 96 return NULL;
97 97
98 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); 98 *nf_pos += fibh->eoffset - fibh->soffset;
99 99
100 memcpy((uint8_t *)cfi, (uint8_t *)fi, 100 memcpy((uint8_t *)cfi, (uint8_t *)fi,
101 sizeof(struct fileIdentDesc)); 101 sizeof(struct fileIdentDesc));
@@ -157,7 +157,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos,
157 if (!fi) 157 if (!fi)
158 return NULL; 158 return NULL;
159 159
160 *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2); 160 *nf_pos += fibh->eoffset - fibh->soffset;
161 161
162 if (fibh->eoffset <= dir->i_sb->s_blocksize) { 162 if (fibh->eoffset <= dir->i_sb->s_blocksize) {
163 memcpy((uint8_t *)cfi, (uint8_t *)fi, 163 memcpy((uint8_t *)cfi, (uint8_t *)fi,
@@ -197,8 +197,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos,
197 cfi->lengthFileIdent + 197 cfi->lengthFileIdent +
198 le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3; 198 le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3;
199 199
200 *nf_pos += (fi_len - (fibh->eoffset - fibh->soffset)) 200 *nf_pos += fi_len - (fibh->eoffset - fibh->soffset);
201 >> 2;
202 fibh->eoffset = fibh->soffset + fi_len; 201 fibh->eoffset = fibh->soffset + fi_len;
203 } else { 202 } else {
204 memcpy((uint8_t *)cfi, (uint8_t *)fi, 203 memcpy((uint8_t *)cfi, (uint8_t *)fi,
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 3483274fb5ba..f792681f2f73 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -219,8 +219,8 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
219 struct extent_position epos; 219 struct extent_position epos;
220 220
221 struct udf_fileident_bh sfibh, dfibh; 221 struct udf_fileident_bh sfibh, dfibh;
222 loff_t f_pos = udf_ext0_offset(inode) >> 2; 222 loff_t f_pos = udf_ext0_offset(inode);
223 int size = (udf_ext0_offset(inode) + inode->i_size) >> 2; 223 int size = udf_ext0_offset(inode) + inode->i_size;
224 struct fileIdentDesc cfi, *sfi, *dfi; 224 struct fileIdentDesc cfi, *sfi, *dfi;
225 struct udf_inode_info *iinfo = UDF_I(inode); 225 struct udf_inode_info *iinfo = UDF_I(inode);
226 226
@@ -256,11 +256,11 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
256 mark_buffer_dirty_inode(dbh, inode); 256 mark_buffer_dirty_inode(dbh, inode);
257 257
258 sfibh.soffset = sfibh.eoffset = 258 sfibh.soffset = sfibh.eoffset =
259 (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2; 259 f_pos & (inode->i_sb->s_blocksize - 1);
260 sfibh.sbh = sfibh.ebh = NULL; 260 sfibh.sbh = sfibh.ebh = NULL;
261 dfibh.soffset = dfibh.eoffset = 0; 261 dfibh.soffset = dfibh.eoffset = 0;
262 dfibh.sbh = dfibh.ebh = dbh; 262 dfibh.sbh = dfibh.ebh = dbh;
263 while ((f_pos < size)) { 263 while (f_pos < size) {
264 iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB; 264 iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
265 sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, 265 sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL,
266 NULL, NULL, NULL); 266 NULL, NULL, NULL);
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) {