4 * Copyright (c) 1999 Al Smith
7 #include <linux/efs_fs.h>
9 static int efs_readdir(struct file *, void *, filldir_t);
11 struct file_operations efs_dir_operations = {
12 read: generic_read_dir,
16 struct inode_operations efs_dir_inode_operations = {
20 static int efs_readdir(struct file *filp, void *dirent, filldir_t filldir) {
21 struct inode *inode = filp->f_dentry->d_inode;
22 struct buffer_head *bh;
24 struct efs_dir *dirblock;
25 struct efs_dentry *dirslot;
31 if (inode->i_size & (EFS_DIRBSIZE-1))
32 printk(KERN_WARNING "EFS: WARNING: readdir(): directory size not a multiple of EFS_DIRBSIZE\n");
34 /* work out where this entry can be found */
35 block = filp->f_pos >> EFS_DIRBSIZE_BITS;
37 /* each block contains at most 256 slots */
38 slot = filp->f_pos & 0xff;
40 /* look at all blocks */
41 while (block < inode->i_blocks) {
42 /* read the dir block */
43 bh = sb_bread(inode->i_sb, efs_bmap(inode, block));
46 printk(KERN_ERR "EFS: readdir(): failed to read dir block %d\n", block);
50 dirblock = (struct efs_dir *) bh->b_data;
52 if (be16_to_cpu(dirblock->magic) != EFS_DIRBLK_MAGIC) {
53 printk(KERN_ERR "EFS: readdir(): invalid directory block\n");
58 while (slot < dirblock->slots) {
59 if (dirblock->space[slot] == 0) {
64 dirslot = (struct efs_dentry *) (((char *) bh->b_data) + EFS_SLOTAT(dirblock, slot));
66 inodenum = be32_to_cpu(dirslot->inode);
67 namelen = dirslot->namelen;
68 nameptr = dirslot->name;
71 printk(KERN_DEBUG "EFS: readdir(): block %d slot %d/%d: inode %u, name \"%s\", namelen %u\n", block, slot, dirblock->slots-1, inodenum, nameptr, namelen);
74 /* found the next entry */
75 filp->f_pos = (block << EFS_DIRBSIZE_BITS) | slot;
77 /* copy filename and data in dirslot */
78 filldir(dirent, nameptr, namelen, filp->f_pos, inodenum, DT_UNKNOWN);
81 if (nameptr - (char *) dirblock + namelen > EFS_DIRBSIZE) {
82 printk(KERN_WARNING "EFS: directory entry %d exceeds directory block\n", slot);
87 /* store position of next slot */
88 if (++slot == dirblock->slots) {
93 filp->f_pos = (block << EFS_DIRBSIZE_BITS) | slot;
104 filp->f_pos = (block << EFS_DIRBSIZE_BITS) | slot;