4 * Copyright (c) 1999 Al Smith
7 #include <linux/efs_fs.h>
9 static int efs_readdir(struct file
*, void *, filldir_t
);
11 static struct file_operations efs_dir_operations
= {
15 efs_readdir
, /* readdir */
24 NULL
, /* check_media_change */
28 extern int efs_get_block(struct inode
*, long, struct buffer_head
*, int);
30 struct inode_operations efs_dir_inode_operations
= {
31 &efs_dir_operations
, /* default directory file-ops */
33 efs_lookup
, /* lookup */
42 NULL
, /* follow_link */
43 efs_get_block
, /* get_block */
48 NULL
, /* permission */
53 static int efs_readdir(struct file
*filp
, void *dirent
, filldir_t filldir
) {
54 struct inode
*inode
= filp
->f_dentry
->d_inode
;
55 struct buffer_head
*bh
;
57 struct efs_dir
*dirblock
;
58 struct efs_dentry
*dirslot
;
64 if (!inode
|| !S_ISDIR(inode
->i_mode
))
67 if (inode
->i_size
& (EFS_DIRBSIZE
-1))
68 printk(KERN_WARNING
"EFS: WARNING: readdir(): directory size not a multiple of EFS_DIRBSIZE\n");
70 /* work out where this entry can be found */
71 block
= filp
->f_pos
>> EFS_DIRBSIZE_BITS
;
73 /* each block contains at most 256 slots */
74 slot
= filp
->f_pos
& 0xff;
76 /* look at all blocks */
77 while (block
< inode
->i_blocks
) {
78 /* read the dir block */
79 bh
= bread(inode
->i_dev
, efs_bmap(inode
, block
), EFS_DIRBSIZE
);
82 printk(KERN_ERR
"EFS: readdir(): failed to read dir block %d\n", block
);
86 dirblock
= (struct efs_dir
*) bh
->b_data
;
88 if (be16_to_cpu(dirblock
->magic
) != EFS_DIRBLK_MAGIC
) {
89 printk(KERN_ERR
"EFS: readdir(): invalid directory block\n");
94 while (slot
< dirblock
->slots
) {
95 if (dirblock
->space
[slot
] == 0) {
100 dirslot
= (struct efs_dentry
*) (((char *) bh
->b_data
) + EFS_SLOTAT(dirblock
, slot
));
102 inodenum
= be32_to_cpu(dirslot
->inode
);
103 namelen
= dirslot
->namelen
;
104 nameptr
= dirslot
->name
;
107 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
);
110 /* found the next entry */
111 filp
->f_pos
= (block
<< EFS_DIRBSIZE_BITS
) | slot
;
113 /* copy filename and data in dirslot */
114 filldir(dirent
, nameptr
, namelen
, filp
->f_pos
, inodenum
);
117 if (nameptr
- (char *) dirblock
+ namelen
> EFS_DIRBSIZE
) {
118 printk(KERN_WARNING
"EFS: directory entry %d exceeds directory block\n", slot
);
123 /* store position of next slot */
124 if (++slot
== dirblock
->slots
) {
129 filp
->f_pos
= (block
<< EFS_DIRBSIZE_BITS
) | slot
;
140 filp
->f_pos
= (block
<< EFS_DIRBSIZE_BITS
) | slot
;