Lines Matching refs:iter
19 static int udf_verify_fi(struct udf_fileident_iter *iter) in udf_verify_fi() argument
23 if (iter->fi.descTag.tagIdent != cpu_to_le16(TAG_IDENT_FID)) { in udf_verify_fi()
24 udf_err(iter->dir->i_sb, in udf_verify_fi()
26 iter->dir->i_ino, (unsigned long long)iter->pos, in udf_verify_fi()
27 le16_to_cpu(iter->fi.descTag.tagIdent)); in udf_verify_fi()
30 len = udf_dir_entry_len(&iter->fi); in udf_verify_fi()
31 if (le16_to_cpu(iter->fi.lengthOfImpUse) & 3) { in udf_verify_fi()
32 udf_err(iter->dir->i_sb, in udf_verify_fi()
34 iter->dir->i_ino, (unsigned long long)iter->pos); in udf_verify_fi()
42 if (len > 1 << iter->dir->i_blkbits) { in udf_verify_fi()
43 udf_err(iter->dir->i_sb, in udf_verify_fi()
45 iter->dir->i_ino, len, (unsigned long long)iter->pos); in udf_verify_fi()
48 if (iter->pos + len > iter->dir->i_size) { in udf_verify_fi()
49 udf_err(iter->dir->i_sb, in udf_verify_fi()
51 iter->dir->i_ino, (unsigned long long)iter->pos); in udf_verify_fi()
54 if (udf_dir_entry_len(&iter->fi) != in udf_verify_fi()
55 sizeof(struct tag) + le16_to_cpu(iter->fi.descTag.descCRCLength)) { in udf_verify_fi()
56 udf_err(iter->dir->i_sb, in udf_verify_fi()
58 iter->dir->i_ino, in udf_verify_fi()
59 (unsigned)le16_to_cpu(iter->fi.descTag.descCRCLength), in udf_verify_fi()
60 (unsigned)(udf_dir_entry_len(&iter->fi) - in udf_verify_fi()
67 static int udf_copy_fi(struct udf_fileident_iter *iter) in udf_copy_fi() argument
69 struct udf_inode_info *iinfo = UDF_I(iter->dir); in udf_copy_fi()
70 u32 blksize = 1 << iter->dir->i_blkbits; in udf_copy_fi()
75 if (iter->pos >= iter->dir->i_size) { in udf_copy_fi()
76 iter->name = NULL; in udf_copy_fi()
79 if (iter->dir->i_size < iter->pos + sizeof(struct fileIdentDesc)) { in udf_copy_fi()
80 udf_err(iter->dir->i_sb, in udf_copy_fi()
82 iter->dir->i_ino); in udf_copy_fi()
86 memcpy(&iter->fi, iinfo->i_data + iinfo->i_lenEAttr + iter->pos, in udf_copy_fi()
88 err = udf_verify_fi(iter); in udf_copy_fi()
91 iter->name = iinfo->i_data + iinfo->i_lenEAttr + iter->pos + in udf_copy_fi()
93 le16_to_cpu(iter->fi.lengthOfImpUse); in udf_copy_fi()
97 off = iter->pos & (blksize - 1); in udf_copy_fi()
99 memcpy(&iter->fi, iter->bh[0]->b_data + off, len); in udf_copy_fi()
101 memcpy((char *)(&iter->fi) + len, iter->bh[1]->b_data, in udf_copy_fi()
103 err = udf_verify_fi(iter); in udf_copy_fi()
109 le16_to_cpu(iter->fi.lengthOfImpUse); in udf_copy_fi()
110 if (off + udf_dir_entry_len(&iter->fi) <= blksize) { in udf_copy_fi()
111 iter->name = iter->bh[0]->b_data + nameoff; in udf_copy_fi()
113 iter->name = iter->bh[1]->b_data + (nameoff - blksize); in udf_copy_fi()
115 iter->name = iter->namebuf; in udf_copy_fi()
117 memcpy(iter->name, iter->bh[0]->b_data + nameoff, len); in udf_copy_fi()
118 memcpy(iter->name + len, iter->bh[1]->b_data, in udf_copy_fi()
119 iter->fi.lengthFileIdent - len); in udf_copy_fi()
125 static void udf_readahead_dir(struct udf_fileident_iter *iter) in udf_readahead_dir() argument
127 unsigned int ralen = 16 >> (iter->dir->i_blkbits - 9); in udf_readahead_dir()
132 if (iter->loffset & (ralen - 1)) in udf_readahead_dir()
135 if (iter->loffset + ralen > (iter->elen >> iter->dir->i_blkbits)) in udf_readahead_dir()
136 ralen = (iter->elen >> iter->dir->i_blkbits) - iter->loffset; in udf_readahead_dir()
139 blk = udf_get_lb_pblock(iter->dir->i_sb, &iter->eloc, in udf_readahead_dir()
140 iter->loffset + i); in udf_readahead_dir()
141 tmp = sb_getblk(iter->dir->i_sb, blk); in udf_readahead_dir()
154 static struct buffer_head *udf_fiiter_bread_blk(struct udf_fileident_iter *iter) in udf_fiiter_bread_blk() argument
158 udf_readahead_dir(iter); in udf_fiiter_bread_blk()
159 blk = udf_get_lb_pblock(iter->dir->i_sb, &iter->eloc, iter->loffset); in udf_fiiter_bread_blk()
160 return sb_bread(iter->dir->i_sb, blk); in udf_fiiter_bread_blk()
167 static int udf_fiiter_advance_blk(struct udf_fileident_iter *iter) in udf_fiiter_advance_blk() argument
172 iter->loffset++; in udf_fiiter_advance_blk()
173 if (iter->loffset < DIV_ROUND_UP(iter->elen, 1<<iter->dir->i_blkbits)) in udf_fiiter_advance_blk()
176 iter->loffset = 0; in udf_fiiter_advance_blk()
177 err = udf_next_aext(iter->dir, &iter->epos, &iter->eloc, in udf_fiiter_advance_blk()
178 &iter->elen, &etype, 1); in udf_fiiter_advance_blk()
182 if (iter->pos == iter->dir->i_size) { in udf_fiiter_advance_blk()
183 iter->elen = 0; in udf_fiiter_advance_blk()
186 udf_err(iter->dir->i_sb, in udf_fiiter_advance_blk()
188 (unsigned long long)iter->pos, iter->dir->i_ino); in udf_fiiter_advance_blk()
194 static int udf_fiiter_load_bhs(struct udf_fileident_iter *iter) in udf_fiiter_load_bhs() argument
196 int blksize = 1 << iter->dir->i_blkbits; in udf_fiiter_load_bhs()
197 int off = iter->pos & (blksize - 1); in udf_fiiter_load_bhs()
202 if (!iter->bh[0] && iter->elen) { in udf_fiiter_load_bhs()
203 iter->bh[0] = udf_fiiter_bread_blk(iter); in udf_fiiter_load_bhs()
204 if (!iter->bh[0]) { in udf_fiiter_load_bhs()
208 if (!buffer_uptodate(iter->bh[0])) { in udf_fiiter_load_bhs()
214 if (iter->pos >= iter->dir->i_size) in udf_fiiter_load_bhs()
219 fi = (struct fileIdentDesc *)(iter->bh[0]->b_data + off); in udf_fiiter_load_bhs()
223 err = udf_fiiter_advance_blk(iter); in udf_fiiter_load_bhs()
226 iter->bh[1] = udf_fiiter_bread_blk(iter); in udf_fiiter_load_bhs()
227 if (!iter->bh[1]) { in udf_fiiter_load_bhs()
231 if (!buffer_uptodate(iter->bh[1])) { in udf_fiiter_load_bhs()
238 brelse(iter->bh[0]); in udf_fiiter_load_bhs()
239 brelse(iter->bh[1]); in udf_fiiter_load_bhs()
240 iter->bh[0] = iter->bh[1] = NULL; in udf_fiiter_load_bhs()
244 int udf_fiiter_init(struct udf_fileident_iter *iter, struct inode *dir, in udf_fiiter_init() argument
251 iter->dir = dir; in udf_fiiter_init()
252 iter->bh[0] = iter->bh[1] = NULL; in udf_fiiter_init()
253 iter->pos = pos; in udf_fiiter_init()
254 iter->elen = 0; in udf_fiiter_init()
255 iter->epos.bh = NULL; in udf_fiiter_init()
256 iter->name = NULL; in udf_fiiter_init()
262 iter->namebuf = kmalloc(UDF_NAME_LEN_CS0, GFP_KERNEL | __GFP_NOFAIL); in udf_fiiter_init()
265 err = udf_copy_fi(iter); in udf_fiiter_init()
269 err = inode_bmap(dir, iter->pos >> dir->i_blkbits, &iter->epos, in udf_fiiter_init()
270 &iter->eloc, &iter->elen, &iter->loffset, &etype); in udf_fiiter_init()
280 err = udf_fiiter_load_bhs(iter); in udf_fiiter_init()
283 err = udf_copy_fi(iter); in udf_fiiter_init()
286 udf_fiiter_release(iter); in udf_fiiter_init()
290 int udf_fiiter_advance(struct udf_fileident_iter *iter) in udf_fiiter_advance() argument
293 int blksize = 1 << iter->dir->i_blkbits; in udf_fiiter_advance()
296 oldoff = iter->pos & (blksize - 1); in udf_fiiter_advance()
297 len = udf_dir_entry_len(&iter->fi); in udf_fiiter_advance()
298 iter->pos += len; in udf_fiiter_advance()
299 if (UDF_I(iter->dir)->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { in udf_fiiter_advance()
301 brelse(iter->bh[0]); in udf_fiiter_advance()
302 iter->bh[0] = NULL; in udf_fiiter_advance()
304 if (iter->bh[1]) { in udf_fiiter_advance()
305 iter->bh[0] = iter->bh[1]; in udf_fiiter_advance()
306 iter->bh[1] = NULL; in udf_fiiter_advance()
308 err = udf_fiiter_advance_blk(iter); in udf_fiiter_advance()
313 err = udf_fiiter_load_bhs(iter); in udf_fiiter_advance()
317 return udf_copy_fi(iter); in udf_fiiter_advance()
320 void udf_fiiter_release(struct udf_fileident_iter *iter) in udf_fiiter_release() argument
322 iter->dir = NULL; in udf_fiiter_release()
323 brelse(iter->bh[0]); in udf_fiiter_release()
324 brelse(iter->bh[1]); in udf_fiiter_release()
325 iter->bh[0] = iter->bh[1] = NULL; in udf_fiiter_release()
326 kfree(iter->namebuf); in udf_fiiter_release()
327 iter->namebuf = NULL; in udf_fiiter_release()
407 void udf_fiiter_write_fi(struct udf_fileident_iter *iter, uint8_t *impuse) in udf_fiiter_write_fi() argument
409 struct udf_inode_info *iinfo = UDF_I(iter->dir); in udf_fiiter_write_fi()
412 int blksize = 1 << iter->dir->i_blkbits; in udf_fiiter_write_fi()
414 off = iter->pos & (blksize - 1); in udf_fiiter_write_fi()
417 len1 = iter->dir->i_size; in udf_fiiter_write_fi()
419 buf1 = iter->bh[0]->b_data; in udf_fiiter_write_fi()
421 if (iter->bh[1]) { in udf_fiiter_write_fi()
422 buf2 = iter->bh[1]->b_data; in udf_fiiter_write_fi()
427 udf_copy_fi_to_bufs(buf1, len1, buf2, len2, off, &iter->fi, impuse, in udf_fiiter_write_fi()
428 iter->name == iter->namebuf ? iter->name : NULL); in udf_fiiter_write_fi()
431 mark_inode_dirty(iter->dir); in udf_fiiter_write_fi()
433 mark_buffer_dirty_inode(iter->bh[0], iter->dir); in udf_fiiter_write_fi()
434 if (iter->bh[1]) in udf_fiiter_write_fi()
435 mark_buffer_dirty_inode(iter->bh[1], iter->dir); in udf_fiiter_write_fi()
437 inode_inc_iversion(iter->dir); in udf_fiiter_write_fi()
440 void udf_fiiter_update_elen(struct udf_fileident_iter *iter, uint32_t new_elen) in udf_fiiter_update_elen() argument
442 struct udf_inode_info *iinfo = UDF_I(iter->dir); in udf_fiiter_update_elen()
443 int diff = new_elen - iter->elen; in udf_fiiter_update_elen()
446 if (!iter->elen) in udf_fiiter_update_elen()
448 iter->elen = new_elen; in udf_fiiter_update_elen()
450 iter->epos.offset -= sizeof(struct short_ad); in udf_fiiter_update_elen()
452 iter->epos.offset -= sizeof(struct long_ad); in udf_fiiter_update_elen()
453 udf_write_aext(iter->dir, &iter->epos, &iter->eloc, iter->elen, 1); in udf_fiiter_update_elen()
455 mark_inode_dirty(iter->dir); in udf_fiiter_update_elen()
459 int udf_fiiter_append_blk(struct udf_fileident_iter *iter) in udf_fiiter_append_blk() argument
461 struct udf_inode_info *iinfo = UDF_I(iter->dir); in udf_fiiter_append_blk()
462 int blksize = 1 << iter->dir->i_blkbits; in udf_fiiter_append_blk()
465 uint32_t old_elen = iter->elen; in udf_fiiter_append_blk()
473 udf_fiiter_update_elen(iter, ALIGN(iter->elen, blksize)); in udf_fiiter_append_blk()
476 block = iinfo->i_lenExtents >> iter->dir->i_blkbits; in udf_fiiter_append_blk()
477 bh = udf_bread(iter->dir, block, 1, &err); in udf_fiiter_append_blk()
479 udf_fiiter_update_elen(iter, old_elen); in udf_fiiter_append_blk()
482 err = inode_bmap(iter->dir, block, &iter->epos, &iter->eloc, &iter->elen, in udf_fiiter_append_blk()
483 &iter->loffset, &etype); in udf_fiiter_append_blk()
485 udf_err(iter->dir->i_sb, in udf_fiiter_append_blk()
487 (unsigned long long)block, iter->dir->i_ino); in udf_fiiter_append_blk()
490 if (!(iter->pos & (blksize - 1))) { in udf_fiiter_append_blk()
491 brelse(iter->bh[0]); in udf_fiiter_append_blk()
492 iter->bh[0] = bh; in udf_fiiter_append_blk()
494 iter->bh[1] = bh; in udf_fiiter_append_blk()