mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 20:07:46 +09:00
udf: Convert udf_readdir() to new directory iteration
[ Upstream commit 7cd7a36ab4 ]
Convert udf_readdir() to new directory iteration functions.
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
9616d00140
commit
31f1ca5c4f
148
fs/udf/dir.c
148
fs/udf/dir.c
@@ -39,26 +39,13 @@
|
|||||||
static int udf_readdir(struct file *file, struct dir_context *ctx)
|
static int udf_readdir(struct file *file, struct dir_context *ctx)
|
||||||
{
|
{
|
||||||
struct inode *dir = file_inode(file);
|
struct inode *dir = file_inode(file);
|
||||||
struct udf_inode_info *iinfo = UDF_I(dir);
|
|
||||||
struct udf_fileident_bh fibh = { .sbh = NULL, .ebh = NULL};
|
|
||||||
struct fileIdentDesc *fi = NULL;
|
|
||||||
struct fileIdentDesc cfi;
|
|
||||||
udf_pblk_t block, iblock;
|
|
||||||
loff_t nf_pos, emit_pos = 0;
|
loff_t nf_pos, emit_pos = 0;
|
||||||
int flen;
|
int flen;
|
||||||
unsigned char *fname = NULL, *copy_name = NULL;
|
unsigned char *fname = NULL;
|
||||||
unsigned char *nameptr;
|
int ret = 0;
|
||||||
uint16_t liu;
|
|
||||||
uint8_t lfi;
|
|
||||||
loff_t size = udf_ext0_offset(dir) + dir->i_size;
|
|
||||||
struct buffer_head *tmp, *bha[16];
|
|
||||||
struct kernel_lb_addr eloc;
|
|
||||||
uint32_t elen;
|
|
||||||
sector_t offset;
|
|
||||||
int i, num, ret = 0;
|
|
||||||
struct extent_position epos = { NULL, 0, {0, 0} };
|
|
||||||
struct super_block *sb = dir->i_sb;
|
struct super_block *sb = dir->i_sb;
|
||||||
bool pos_valid = false;
|
bool pos_valid = false;
|
||||||
|
struct udf_fileident_iter iter;
|
||||||
|
|
||||||
if (ctx->pos == 0) {
|
if (ctx->pos == 0) {
|
||||||
if (!dir_emit_dot(file, ctx))
|
if (!dir_emit_dot(file, ctx))
|
||||||
@@ -66,7 +53,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
|
|||||||
ctx->pos = 1;
|
ctx->pos = 1;
|
||||||
}
|
}
|
||||||
nf_pos = (ctx->pos - 1) << 2;
|
nf_pos = (ctx->pos - 1) << 2;
|
||||||
if (nf_pos >= size)
|
if (nf_pos >= dir->i_size)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -90,138 +77,57 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nf_pos == 0)
|
for (ret = udf_fiiter_init(&iter, dir, nf_pos);
|
||||||
nf_pos = udf_ext0_offset(dir);
|
!ret && iter.pos < dir->i_size;
|
||||||
|
ret = udf_fiiter_advance(&iter)) {
|
||||||
fibh.soffset = fibh.eoffset = nf_pos & (sb->s_blocksize - 1);
|
|
||||||
if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
|
|
||||||
if (inode_bmap(dir, nf_pos >> sb->s_blocksize_bits,
|
|
||||||
&epos, &eloc, &elen, &offset)
|
|
||||||
!= (EXT_RECORDED_ALLOCATED >> 30)) {
|
|
||||||
ret = -ENOENT;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
block = udf_get_lb_pblock(sb, &eloc, offset);
|
|
||||||
if ((++offset << sb->s_blocksize_bits) < elen) {
|
|
||||||
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
|
|
||||||
epos.offset -= sizeof(struct short_ad);
|
|
||||||
else if (iinfo->i_alloc_type ==
|
|
||||||
ICBTAG_FLAG_AD_LONG)
|
|
||||||
epos.offset -= sizeof(struct long_ad);
|
|
||||||
} else {
|
|
||||||
offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(fibh.sbh = fibh.ebh = udf_tread(sb, block))) {
|
|
||||||
ret = -EIO;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(offset & ((16 >> (sb->s_blocksize_bits - 9)) - 1))) {
|
|
||||||
i = 16 >> (sb->s_blocksize_bits - 9);
|
|
||||||
if (i + offset > (elen >> sb->s_blocksize_bits))
|
|
||||||
i = (elen >> sb->s_blocksize_bits) - offset;
|
|
||||||
for (num = 0; i > 0; i--) {
|
|
||||||
block = udf_get_lb_pblock(sb, &eloc, offset + i);
|
|
||||||
tmp = udf_tgetblk(sb, block);
|
|
||||||
if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp))
|
|
||||||
bha[num++] = tmp;
|
|
||||||
else
|
|
||||||
brelse(tmp);
|
|
||||||
}
|
|
||||||
if (num) {
|
|
||||||
bh_readahead_batch(num, bha, REQ_RAHEAD);
|
|
||||||
for (i = 0; i < num; i++)
|
|
||||||
brelse(bha[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (nf_pos < size) {
|
|
||||||
struct kernel_lb_addr tloc;
|
struct kernel_lb_addr tloc;
|
||||||
loff_t cur_pos = nf_pos;
|
udf_pblk_t iblock;
|
||||||
|
|
||||||
/* Update file position only if we got past the current one */
|
|
||||||
if (nf_pos >= emit_pos) {
|
|
||||||
ctx->pos = (nf_pos >> 2) + 1;
|
|
||||||
pos_valid = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
fi = udf_fileident_read(dir, &nf_pos, &fibh, &cfi, &epos, &eloc,
|
|
||||||
&elen, &offset);
|
|
||||||
if (!fi)
|
|
||||||
goto out;
|
|
||||||
/* Still not at offset where user asked us to read from? */
|
/* Still not at offset where user asked us to read from? */
|
||||||
if (cur_pos < emit_pos)
|
if (iter.pos < emit_pos)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
liu = le16_to_cpu(cfi.lengthOfImpUse);
|
/* Update file position only if we got past the current one */
|
||||||
lfi = cfi.lengthFileIdent;
|
pos_valid = true;
|
||||||
|
ctx->pos = (iter.pos >> 2) + 1;
|
||||||
|
|
||||||
if (fibh.sbh == fibh.ebh) {
|
if (iter.fi.fileCharacteristics & FID_FILE_CHAR_DELETED) {
|
||||||
nameptr = udf_get_fi_ident(fi);
|
|
||||||
} else {
|
|
||||||
int poffset; /* Unpaded ending offset */
|
|
||||||
|
|
||||||
poffset = fibh.soffset + sizeof(struct fileIdentDesc) + liu + lfi;
|
|
||||||
|
|
||||||
if (poffset >= lfi) {
|
|
||||||
nameptr = (char *)(fibh.ebh->b_data + poffset - lfi);
|
|
||||||
} else {
|
|
||||||
if (!copy_name) {
|
|
||||||
copy_name = kmalloc(UDF_NAME_LEN,
|
|
||||||
GFP_NOFS);
|
|
||||||
if (!copy_name) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nameptr = copy_name;
|
|
||||||
memcpy(nameptr, udf_get_fi_ident(fi),
|
|
||||||
lfi - poffset);
|
|
||||||
memcpy(nameptr + lfi - poffset,
|
|
||||||
fibh.ebh->b_data, poffset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
|
|
||||||
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE))
|
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cfi.fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) {
|
if (iter.fi.fileCharacteristics & FID_FILE_CHAR_HIDDEN) {
|
||||||
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE))
|
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfi.fileCharacteristics & FID_FILE_CHAR_PARENT) {
|
if (iter.fi.fileCharacteristics & FID_FILE_CHAR_PARENT) {
|
||||||
if (!dir_emit_dotdot(file, ctx))
|
if (!dir_emit_dotdot(file, ctx))
|
||||||
goto out;
|
goto out_iter;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN);
|
flen = udf_get_filename(sb, iter.name,
|
||||||
|
iter.fi.lengthFileIdent, fname, UDF_NAME_LEN);
|
||||||
if (flen < 0)
|
if (flen < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
tloc = lelb_to_cpu(cfi.icb.extLocation);
|
tloc = lelb_to_cpu(iter.fi.icb.extLocation);
|
||||||
iblock = udf_get_lb_pblock(sb, &tloc, 0);
|
iblock = udf_get_lb_pblock(sb, &tloc, 0);
|
||||||
if (!dir_emit(ctx, fname, flen, iblock, DT_UNKNOWN))
|
if (!dir_emit(ctx, fname, flen, iblock, DT_UNKNOWN))
|
||||||
goto out;
|
goto out_iter;
|
||||||
} /* end while */
|
}
|
||||||
|
|
||||||
ctx->pos = (nf_pos >> 2) + 1;
|
|
||||||
pos_valid = true;
|
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
ctx->pos = (iter.pos >> 2) + 1;
|
||||||
|
pos_valid = true;
|
||||||
|
}
|
||||||
|
out_iter:
|
||||||
|
udf_fiiter_release(&iter);
|
||||||
out:
|
out:
|
||||||
if (pos_valid)
|
if (pos_valid)
|
||||||
file->f_version = inode_query_iversion(dir);
|
file->f_version = inode_query_iversion(dir);
|
||||||
if (fibh.sbh != fibh.ebh)
|
|
||||||
brelse(fibh.ebh);
|
|
||||||
brelse(fibh.sbh);
|
|
||||||
brelse(epos.bh);
|
|
||||||
kfree(fname);
|
kfree(fname);
|
||||||
kfree(copy_name);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user