/** * __vxfs_iget - generic find inode facility * @sbp: VFS superblock * @ino: inode number * @ilistp: inode list * * Description: * Search the for inode number @ino in the filesystem * described by @sbp. Use the specified inode table (@ilistp). * Returns the matching VxFS inode on success, else a NULL pointer. */ static struct vxfs_inode_info * __vxfs_iget(ino_t ino, struct inode *ilistp) { struct page *pp; u_long offset; offset = (ino % (PAGE_SIZE / VXFS_ISIZE)) * VXFS_ISIZE; pp = vxfs_get_page(ilistp->i_mapping, ino * VXFS_ISIZE / PAGE_SIZE); if (!IS_ERR(pp)) { struct vxfs_inode_info *vip; struct vxfs_dinode *dip; caddr_t kaddr = (char *)page_address(pp); if (!(vip = kmem_cache_alloc(vxfs_inode_cachep, SLAB_KERNEL))) goto fail; dip = (struct vxfs_dinode *)(kaddr + offset); memcpy(vip, dip, sizeof(*vip)); #ifdef DIAGNOSTIC vxfs_dumpi(vip, ino); #endif vxfs_put_page(pp); return (vip); } printk(KERN_WARNING "vxfs: error on page %p\n", pp); return NULL; fail: printk(KERN_WARNING "vxfs: unable to read inode %ld\n", ino); vxfs_put_page(pp); return NULL; }
/** * vxfs_find_entry - find a mathing directory entry for a dentry * @ip: directory inode * @dp: dentry for which we want to find a direct * @ppp: gets filled with the page the return value sits in * * Description: * vxfs_find_entry finds a &struct vxfs_direct for the VFS directory * cache entry @dp. @ppp will be filled with the page the return * value resides in. * * Returns: * The wanted direct on success, else a NULL pointer. */ static struct vxfs_direct * vxfs_find_entry(struct inode *ip, struct dentry *dp, struct page **ppp) { u_long npages, page, nblocks, pblocks, block; u_long bsize = ip->i_sb->s_blocksize; const char *name = dp->d_name.name; int namelen = dp->d_name.len; npages = dir_pages(ip); nblocks = dir_blocks(ip); pblocks = VXFS_BLOCK_PER_PAGE(ip->i_sb); for (page = 0; page < npages; page++) { caddr_t kaddr; struct page *pp; pp = vxfs_get_page(ip->i_mapping, page); if (IS_ERR(pp)) continue; kaddr = (caddr_t)page_address(pp); for (block = 0; block <= nblocks && block <= pblocks; block++) { caddr_t baddr, limit; struct vxfs_dirblk *dbp; struct vxfs_direct *de; baddr = kaddr + (block * bsize); limit = baddr + bsize - VXFS_DIRLEN(1); dbp = (struct vxfs_dirblk *)baddr; de = (struct vxfs_direct *)(baddr + VXFS_DIRBLKOV(dbp)); for (; (caddr_t)de <= limit; de = vxfs_next_entry(de)) { if (!de->d_reclen) break; if (!de->d_ino) continue; if (vxfs_match(namelen, name, de)) { *ppp = pp; return (de); } } } vxfs_put_page(pp); } return NULL; }
/** * vxfs_readdir - read a directory * @fp: the directory to read * @retp: return buffer * @filler: filldir callback * * Description: * vxfs_readdir fills @retp with directory entries from @fp * using the VFS supplied callback @filler. * * Returns: * Zero. */ static int vxfs_readdir(struct file *fp, void *retp, filldir_t filler) { struct inode *ip = fp->f_path.dentry->d_inode; struct super_block *sbp = ip->i_sb; u_long bsize = sbp->s_blocksize; u_long page, npages, block, pblocks, nblocks, offset; loff_t pos; switch ((long)fp->f_pos) { case 0: if (filler(retp, ".", 1, fp->f_pos, ip->i_ino, DT_DIR) < 0) goto out; fp->f_pos++; /* fallthrough */ case 1: if (filler(retp, "..", 2, fp->f_pos, VXFS_INO(ip)->vii_dotdot, DT_DIR) < 0) goto out; fp->f_pos++; /* fallthrough */ } pos = fp->f_pos - 2; if (pos > VXFS_DIRROUND(ip->i_size)) return 0; npages = dir_pages(ip); nblocks = dir_blocks(ip); pblocks = VXFS_BLOCK_PER_PAGE(sbp); page = pos >> PAGE_CACHE_SHIFT; offset = pos & ~PAGE_CACHE_MASK; block = (u_long)(pos >> sbp->s_blocksize_bits) % pblocks; for (; page < npages; page++, block = 0) { caddr_t kaddr; struct page *pp; pp = vxfs_get_page(ip->i_mapping, page); if (IS_ERR(pp)) continue; kaddr = (caddr_t)page_address(pp); for (; block <= nblocks && block <= pblocks; block++) { caddr_t baddr, limit; struct vxfs_dirblk *dbp; struct vxfs_direct *de; baddr = kaddr + (block * bsize); limit = baddr + bsize - VXFS_DIRLEN(1); dbp = (struct vxfs_dirblk *)baddr; de = (struct vxfs_direct *) (offset ? (kaddr + offset) : (baddr + VXFS_DIRBLKOV(dbp))); for (; (caddr_t)de <= limit; de = vxfs_next_entry(de)) { int over; if (!de->d_reclen) break; if (!de->d_ino) continue; offset = (caddr_t)de - kaddr; over = filler(retp, de->d_name, de->d_namelen, ((page << PAGE_CACHE_SHIFT) | offset) + 2, de->d_ino, DT_UNKNOWN); if (over) { vxfs_put_page(pp); goto done; } } offset = 0; } vxfs_put_page(pp); offset = 0; } done: fp->f_pos = ((page << PAGE_CACHE_SHIFT) | offset) + 2; out: return 0; }
/** * vxfs_readdir - read a directory * @fp: the directory to read * @retp: return buffer * @filler: filldir callback * * Description: * vxfs_readdir fills @retp with directory entries from @fp * using the VFS supplied callback @filler. * * Returns: * Zero. */ static int vxfs_readdir(struct file *fp, struct dir_context *ctx) { struct inode *ip = file_inode(fp); struct super_block *sbp = ip->i_sb; u_long bsize = sbp->s_blocksize; u_long page, npages, block, pblocks, nblocks, offset; loff_t pos; if (ctx->pos == 0) { if (!dir_emit_dot(fp, ctx)) return 0; ctx->pos = 1; } if (ctx->pos == 1) { if (!dir_emit(ctx, "..", 2, VXFS_INO(ip)->vii_dotdot, DT_DIR)) return 0; ctx->pos = 2; } pos = ctx->pos - 2; if (pos > VXFS_DIRROUND(ip->i_size)) return 0; npages = dir_pages(ip); nblocks = dir_blocks(ip); pblocks = VXFS_BLOCK_PER_PAGE(sbp); page = pos >> PAGE_CACHE_SHIFT; offset = pos & ~PAGE_CACHE_MASK; block = (u_long)(pos >> sbp->s_blocksize_bits) % pblocks; for (; page < npages; page++, block = 0) { char *kaddr; struct page *pp; pp = vxfs_get_page(ip->i_mapping, page); if (IS_ERR(pp)) continue; kaddr = (char *)page_address(pp); for (; block <= nblocks && block <= pblocks; block++) { char *baddr, *limit; struct vxfs_dirblk *dbp; struct vxfs_direct *de; baddr = kaddr + (block * bsize); limit = baddr + bsize - VXFS_DIRLEN(1); dbp = (struct vxfs_dirblk *)baddr; de = (struct vxfs_direct *) (offset ? (kaddr + offset) : (baddr + VXFS_DIRBLKOV(dbp))); for (; (char *)de <= limit; de = vxfs_next_entry(de)) { if (!de->d_reclen) break; if (!de->d_ino) continue; offset = (char *)de - kaddr; ctx->pos = ((page << PAGE_CACHE_SHIFT) | offset) + 2; if (!dir_emit(ctx, de->d_name, de->d_namelen, de->d_ino, DT_UNKNOWN)) { vxfs_put_page(pp); return 0; } } offset = 0; } vxfs_put_page(pp); offset = 0; } ctx->pos = ((page << PAGE_CACHE_SHIFT) | offset) + 2; return 0; }