mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
[readdir] convert f2fs
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
8f29843a51
commit
6f7f231e7b
2 changed files with 22 additions and 35 deletions
|
@ -349,18 +349,17 @@ static int cramfs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
||||||
/*
|
/*
|
||||||
* Read a cramfs directory entry.
|
* Read a cramfs directory entry.
|
||||||
*/
|
*/
|
||||||
static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
|
static int cramfs_readdir(struct file *file, struct dir_context *ctx)
|
||||||
{
|
{
|
||||||
struct inode *inode = file_inode(filp);
|
struct inode *inode = file_inode(file);
|
||||||
struct super_block *sb = inode->i_sb;
|
struct super_block *sb = inode->i_sb;
|
||||||
char *buf;
|
char *buf;
|
||||||
unsigned int offset;
|
unsigned int offset;
|
||||||
int copied;
|
|
||||||
|
|
||||||
/* Offset within the thing. */
|
/* Offset within the thing. */
|
||||||
offset = filp->f_pos;
|
if (ctx->pos >= inode->i_size)
|
||||||
if (offset >= inode->i_size)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
offset = ctx->pos;
|
||||||
/* Directory entries are always 4-byte aligned */
|
/* Directory entries are always 4-byte aligned */
|
||||||
if (offset & 3)
|
if (offset & 3)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -369,14 +368,13 @@ static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
copied = 0;
|
|
||||||
while (offset < inode->i_size) {
|
while (offset < inode->i_size) {
|
||||||
struct cramfs_inode *de;
|
struct cramfs_inode *de;
|
||||||
unsigned long nextoffset;
|
unsigned long nextoffset;
|
||||||
char *name;
|
char *name;
|
||||||
ino_t ino;
|
ino_t ino;
|
||||||
umode_t mode;
|
umode_t mode;
|
||||||
int namelen, error;
|
int namelen;
|
||||||
|
|
||||||
mutex_lock(&read_mutex);
|
mutex_lock(&read_mutex);
|
||||||
de = cramfs_read(sb, OFFSET(inode) + offset, sizeof(*de)+CRAMFS_MAXPATHLEN);
|
de = cramfs_read(sb, OFFSET(inode) + offset, sizeof(*de)+CRAMFS_MAXPATHLEN);
|
||||||
|
@ -402,13 +400,10 @@ static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
|
||||||
break;
|
break;
|
||||||
namelen--;
|
namelen--;
|
||||||
}
|
}
|
||||||
error = filldir(dirent, buf, namelen, offset, ino, mode >> 12);
|
if (!dir_emit(ctx, buf, namelen, ino, mode >> 12))
|
||||||
if (error)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
offset = nextoffset;
|
ctx->pos = offset = nextoffset;
|
||||||
filp->f_pos = offset;
|
|
||||||
copied++;
|
|
||||||
}
|
}
|
||||||
kfree(buf);
|
kfree(buf);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -547,7 +542,7 @@ static const struct address_space_operations cramfs_aops = {
|
||||||
static const struct file_operations cramfs_directory_operations = {
|
static const struct file_operations cramfs_directory_operations = {
|
||||||
.llseek = generic_file_llseek,
|
.llseek = generic_file_llseek,
|
||||||
.read = generic_read_dir,
|
.read = generic_read_dir,
|
||||||
.readdir = cramfs_readdir,
|
.iterate = cramfs_readdir,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct inode_operations cramfs_dir_inode_operations = {
|
static const struct inode_operations cramfs_dir_inode_operations = {
|
||||||
|
|
|
@ -591,24 +591,19 @@ bool f2fs_empty_dir(struct inode *dir)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int f2fs_readdir(struct file *file, void *dirent, filldir_t filldir)
|
static int f2fs_readdir(struct file *file, struct dir_context *ctx)
|
||||||
{
|
{
|
||||||
unsigned long pos = file->f_pos;
|
|
||||||
struct inode *inode = file_inode(file);
|
struct inode *inode = file_inode(file);
|
||||||
unsigned long npages = dir_blocks(inode);
|
unsigned long npages = dir_blocks(inode);
|
||||||
unsigned char *types = NULL;
|
|
||||||
unsigned int bit_pos = 0, start_bit_pos = 0;
|
unsigned int bit_pos = 0, start_bit_pos = 0;
|
||||||
int over = 0;
|
|
||||||
struct f2fs_dentry_block *dentry_blk = NULL;
|
struct f2fs_dentry_block *dentry_blk = NULL;
|
||||||
struct f2fs_dir_entry *de = NULL;
|
struct f2fs_dir_entry *de = NULL;
|
||||||
struct page *dentry_page = NULL;
|
struct page *dentry_page = NULL;
|
||||||
unsigned int n = 0;
|
unsigned int n = ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK);
|
||||||
unsigned char d_type = DT_UNKNOWN;
|
unsigned char d_type = DT_UNKNOWN;
|
||||||
int slots;
|
int slots;
|
||||||
|
|
||||||
types = f2fs_filetype_table;
|
bit_pos = ((unsigned long)ctx->pos % NR_DENTRY_IN_BLOCK);
|
||||||
bit_pos = (pos % NR_DENTRY_IN_BLOCK);
|
|
||||||
n = (pos / NR_DENTRY_IN_BLOCK);
|
|
||||||
|
|
||||||
for ( ; n < npages; n++) {
|
for ( ; n < npages; n++) {
|
||||||
dentry_page = get_lock_data_page(inode, n);
|
dentry_page = get_lock_data_page(inode, n);
|
||||||
|
@ -618,31 +613,28 @@ static int f2fs_readdir(struct file *file, void *dirent, filldir_t filldir)
|
||||||
start_bit_pos = bit_pos;
|
start_bit_pos = bit_pos;
|
||||||
dentry_blk = kmap(dentry_page);
|
dentry_blk = kmap(dentry_page);
|
||||||
while (bit_pos < NR_DENTRY_IN_BLOCK) {
|
while (bit_pos < NR_DENTRY_IN_BLOCK) {
|
||||||
d_type = DT_UNKNOWN;
|
|
||||||
bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap,
|
bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap,
|
||||||
NR_DENTRY_IN_BLOCK,
|
NR_DENTRY_IN_BLOCK,
|
||||||
bit_pos);
|
bit_pos);
|
||||||
if (bit_pos >= NR_DENTRY_IN_BLOCK)
|
if (bit_pos >= NR_DENTRY_IN_BLOCK)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
ctx->pos += bit_pos - start_bit_pos;
|
||||||
de = &dentry_blk->dentry[bit_pos];
|
de = &dentry_blk->dentry[bit_pos];
|
||||||
if (types && de->file_type < F2FS_FT_MAX)
|
if (de->file_type < F2FS_FT_MAX)
|
||||||
d_type = types[de->file_type];
|
d_type = f2fs_filetype_table[de->file_type];
|
||||||
|
else
|
||||||
over = filldir(dirent,
|
d_type = DT_UNKNOWN;
|
||||||
|
if (!dir_emit(ctx,
|
||||||
dentry_blk->filename[bit_pos],
|
dentry_blk->filename[bit_pos],
|
||||||
le16_to_cpu(de->name_len),
|
le16_to_cpu(de->name_len),
|
||||||
(n * NR_DENTRY_IN_BLOCK) + bit_pos,
|
le32_to_cpu(de->ino), d_type))
|
||||||
le32_to_cpu(de->ino), d_type);
|
|
||||||
if (over) {
|
|
||||||
file->f_pos += bit_pos - start_bit_pos;
|
|
||||||
goto success;
|
goto success;
|
||||||
}
|
|
||||||
slots = GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
|
slots = GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
|
||||||
bit_pos += slots;
|
bit_pos += slots;
|
||||||
}
|
}
|
||||||
bit_pos = 0;
|
bit_pos = 0;
|
||||||
file->f_pos = (n + 1) * NR_DENTRY_IN_BLOCK;
|
ctx->pos = (n + 1) * NR_DENTRY_IN_BLOCK;
|
||||||
kunmap(dentry_page);
|
kunmap(dentry_page);
|
||||||
f2fs_put_page(dentry_page, 1);
|
f2fs_put_page(dentry_page, 1);
|
||||||
dentry_page = NULL;
|
dentry_page = NULL;
|
||||||
|
@ -659,7 +651,7 @@ success:
|
||||||
const struct file_operations f2fs_dir_operations = {
|
const struct file_operations f2fs_dir_operations = {
|
||||||
.llseek = generic_file_llseek,
|
.llseek = generic_file_llseek,
|
||||||
.read = generic_read_dir,
|
.read = generic_read_dir,
|
||||||
.readdir = f2fs_readdir,
|
.iterate = f2fs_readdir,
|
||||||
.fsync = f2fs_sync_file,
|
.fsync = f2fs_sync_file,
|
||||||
.unlocked_ioctl = f2fs_ioctl,
|
.unlocked_ioctl = f2fs_ioctl,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue