diff options
Diffstat (limited to 'fs/udf/dir.c')
| -rw-r--r-- | fs/udf/dir.c | 272 |
1 files changed, 104 insertions, 168 deletions
diff --git a/fs/udf/dir.c b/fs/udf/dir.c index f5222527fe3..a012c51caff 100644 --- a/fs/udf/dir.c +++ b/fs/udf/dir.c @@ -30,234 +30,170 @@ #include <linux/errno.h> #include <linux/mm.h> #include <linux/slab.h> -#include <linux/smp_lock.h> #include <linux/buffer_head.h> #include "udf_i.h" #include "udf_sb.h" -/* Prototypes for file operations */ -static int udf_readdir(struct file *, void *, filldir_t); -static int do_udf_readdir(struct inode *, struct file *, filldir_t, void *); -/* readdir and lookup functions */ - -struct file_operations udf_dir_operations = { - .read = generic_read_dir, - .readdir = udf_readdir, - .ioctl = udf_ioctl, - .fsync = udf_fsync_file, -}; - -/* - * udf_readdir - * - * PURPOSE - * Read a directory entry. - * - * DESCRIPTION - * Optional - sys_getdents() will return -ENOTDIR if this routine is not - * available. - * - * Refer to sys_getdents() in fs/readdir.c - * sys_getdents() -> . - * - * PRE-CONDITIONS - * filp Pointer to directory file. - * buf Pointer to directory entry buffer. - * filldir Pointer to filldir function. - * - * POST-CONDITIONS - * <return> >=0 on success. - * - * HISTORY - * July 1, 1997 - Andrew E. Mileski - * Written, tested, and released. - */ - -int udf_readdir(struct file *filp, void *dirent, filldir_t filldir) -{ - struct inode *dir = filp->f_dentry->d_inode; - int result; - - lock_kernel(); - - if ( filp->f_pos == 0 ) - { - if (filldir(dirent, ".", 1, filp->f_pos, dir->i_ino, DT_DIR) < 0) - { - unlock_kernel(); - return 0; - } - filp->f_pos ++; - } - - result = do_udf_readdir(dir, filp, filldir, dirent); - unlock_kernel(); - return result; -} - -static int -do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *dirent) +static int udf_readdir(struct file *file, struct dir_context *ctx) { - struct udf_fileident_bh fibh; - struct fileIdentDesc *fi=NULL; + 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; int block, iblock; - loff_t nf_pos = filp->f_pos - 1; + loff_t nf_pos; int flen; - char fname[UDF_NAME_LEN]; - char *nameptr; + unsigned char *fname = NULL; + unsigned char *nameptr; uint16_t liu; uint8_t lfi; - loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2; - struct buffer_head * bh = NULL, * tmp, * bha[16]; - kernel_lb_addr bloc, eloc; - uint32_t extoffset, elen, offset; - int i, num; - unsigned int dt_type; - + 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} }; + + if (ctx->pos == 0) { + if (!dir_emit_dot(file, ctx)) + return 0; + ctx->pos = 1; + } + nf_pos = (ctx->pos - 1) << 2; if (nf_pos >= size) - return 0; + goto out; - if (nf_pos == 0) - nf_pos = (udf_ext0_offset(dir) >> 2); + fname = kmalloc(UDF_NAME_LEN, GFP_NOFS); + if (!fname) { + ret = -ENOMEM; + goto out; + } - fibh.soffset = fibh.eoffset = (nf_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2; - if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) - fibh.sbh = fibh.ebh = NULL; - else if (inode_bmap(dir, nf_pos >> (dir->i_sb->s_blocksize_bits - 2), - &bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30)) - { - offset >>= dir->i_sb->s_blocksize_bits; - block = udf_get_lb_pblock(dir->i_sb, eloc, offset); - if ((++offset << dir->i_sb->s_blocksize_bits) < elen) - { - if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT) - extoffset -= sizeof(short_ad); - else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG) - extoffset -= sizeof(long_ad); + if (nf_pos == 0) + nf_pos = udf_ext0_offset(dir); + + fibh.soffset = fibh.eoffset = nf_pos & (dir->i_sb->s_blocksize - 1); + if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { + if (inode_bmap(dir, nf_pos >> dir->i_sb->s_blocksize_bits, + &epos, &eloc, &elen, &offset) + != (EXT_RECORDED_ALLOCATED >> 30)) { + ret = -ENOENT; + goto out; } - else + block = udf_get_lb_pblock(dir->i_sb, &eloc, offset); + if ((++offset << dir->i_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(dir->i_sb, block))) - { - udf_release_data(bh); - return -EIO; + if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) { + ret = -EIO; + goto out; } - - if (!(offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9))-1))) - { + + if (!(offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) { i = 16 >> (dir->i_sb->s_blocksize_bits - 9); - if (i+offset > (elen >> dir->i_sb->s_blocksize_bits)) - i = (elen >> dir->i_sb->s_blocksize_bits)-offset; - for (num=0; i>0; i--) - { - block = udf_get_lb_pblock(dir->i_sb, eloc, offset+i); + if (i + offset > (elen >> dir->i_sb->s_blocksize_bits)) + i = (elen >> dir->i_sb->s_blocksize_bits) - offset; + for (num = 0; i > 0; i--) { + block = udf_get_lb_pblock(dir->i_sb, &eloc, offset + i); tmp = udf_tgetblk(dir->i_sb, block); if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp)) bha[num++] = tmp; else brelse(tmp); } - if (num) - { + if (num) { ll_rw_block(READA, num, bha); - for (i=0; i<num; i++) + for (i = 0; i < num; i++) brelse(bha[i]); } } } - else - { - udf_release_data(bh); - return -ENOENT; - } - while ( nf_pos < size ) - { - filp->f_pos = nf_pos + 1; + while (nf_pos < size) { + struct kernel_lb_addr tloc; - fi = udf_fileident_read(dir, &nf_pos, &fibh, &cfi, &bloc, &extoffset, &eloc, &elen, &offset, &bh); + ctx->pos = (nf_pos >> 2) + 1; + fi = udf_fileident_read(dir, &nf_pos, &fibh, &cfi, &epos, &eloc, + &elen, &offset); if (!fi) - { - if (fibh.sbh != fibh.ebh) - udf_release_data(fibh.ebh); - udf_release_data(fibh.sbh); - udf_release_data(bh); - return 0; - } + goto out; liu = le16_to_cpu(cfi.lengthOfImpUse); lfi = cfi.lengthFileIdent; - if (fibh.sbh == fibh.ebh) + if (fibh.sbh == fibh.ebh) { nameptr = fi->fileIdent + liu; - else - { + } else { int poffset; /* Unpaded ending offset */ poffset = fibh.soffset + sizeof(struct fileIdentDesc) + liu + lfi; - if (poffset >= lfi) + if (poffset >= lfi) { nameptr = (char *)(fibh.ebh->b_data + poffset - lfi); - else - { + } else { nameptr = fname; - memcpy(nameptr, fi->fileIdent + liu, lfi - poffset); - memcpy(nameptr + lfi - poffset, fibh.ebh->b_data, poffset); + memcpy(nameptr, fi->fileIdent + liu, + lfi - poffset); + memcpy(nameptr + lfi - poffset, + fibh.ebh->b_data, poffset); } } - if ( (cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) != 0 ) - { - if ( !UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE) ) + if ((cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) { + if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE)) continue; } - - if ( (cfi.fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0 ) - { - if ( !UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE) ) + + if ((cfi.fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) { + if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE)) continue; } - if ( cfi.fileCharacteristics & FID_FILE_CHAR_PARENT ) - { - iblock = parent_ino(filp->f_dentry); - flen = 2; - memcpy(fname, "..", flen); - dt_type = DT_DIR; + if (cfi.fileCharacteristics & FID_FILE_CHAR_PARENT) { + if (!dir_emit_dotdot(file, ctx)) + goto out; + continue; } - else - { - kernel_lb_addr tloc = lelb_to_cpu(cfi.icb.extLocation); - iblock = udf_get_lb_pblock(dir->i_sb, tloc, 0); - flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi); - dt_type = DT_UNKNOWN; - } + flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi); + if (!flen) + continue; - if (flen) - { - if (filldir(dirent, fname, flen, filp->f_pos, iblock, dt_type) < 0) - { - if (fibh.sbh != fibh.ebh) - udf_release_data(fibh.ebh); - udf_release_data(fibh.sbh); - udf_release_data(bh); - return 0; - } - } + tloc = lelb_to_cpu(cfi.icb.extLocation); + iblock = udf_get_lb_pblock(dir->i_sb, &tloc, 0); + if (!dir_emit(ctx, fname, flen, iblock, DT_UNKNOWN)) + goto out; } /* end while */ - filp->f_pos = nf_pos + 1; + ctx->pos = (nf_pos >> 2) + 1; +out: if (fibh.sbh != fibh.ebh) - udf_release_data(fibh.ebh); - udf_release_data(fibh.sbh); - udf_release_data(bh); + brelse(fibh.ebh); + brelse(fibh.sbh); + brelse(epos.bh); + kfree(fname); - return 0; + return ret; } + +/* readdir and lookup functions */ +const struct file_operations udf_dir_operations = { + .llseek = generic_file_llseek, + .read = generic_read_dir, + .iterate = udf_readdir, + .unlocked_ioctl = udf_ioctl, + .fsync = generic_file_fsync, +}; |
