4 * (c) 1996 Hans-Joachim Widmaier - Rewritten
6 * (C) 1993 Ray Burr - Modified for Amiga FFS filesystem.
8 * (C) 1992 Eric Youngdale Modified for ISO 9660 filesystem.
10 * (C) 1991 Linus Torvalds - minix filesystem
12 * affs directory handling functions
18 static int affs_readdir(struct file
*, void *, filldir_t
);
20 struct file_operations affs_dir_operations
= {
21 .read
= generic_read_dir
,
22 .readdir
= affs_readdir
,
27 * directories can handle most operations...
29 struct inode_operations affs_dir_inode_operations
= {
30 .create
= affs_create
,
31 .lookup
= affs_lookup
,
33 .unlink
= affs_unlink
,
34 .symlink
= affs_symlink
,
37 .rename
= affs_rename
,
38 .setattr
= affs_notify_change
,
42 affs_readdir(struct file
*filp
, void *dirent
, filldir_t filldir
)
44 struct inode
*inode
= filp
->f_dentry
->d_inode
;
45 struct super_block
*sb
= inode
->i_sb
;
46 struct buffer_head
*dir_bh
;
47 struct buffer_head
*fh_bh
;
58 pr_debug("AFFS: readdir(ino=%lu,f_pos=%lx)\n",inode
->i_ino
,(unsigned long)filp
->f_pos
);
67 filp
->private_data
= (void *)0;
68 if (filldir(dirent
, ".", 1, f_pos
, inode
->i_ino
, DT_DIR
) < 0)
70 filp
->f_pos
= f_pos
= 1;
74 if (filldir(dirent
, "..", 2, f_pos
, parent_ino(filp
->f_dentry
), DT_DIR
) < 0)
76 filp
->f_pos
= f_pos
= 2;
81 chain_pos
= (f_pos
- 2) & 0xffff;
82 hash_pos
= (f_pos
- 2) >> 16;
83 if (chain_pos
== 0xffff) {
84 affs_warning(sb
, "readdir", "More than 65535 entries in chain");
87 filp
->f_pos
= ((hash_pos
<< 16) | chain_pos
) + 2;
89 dir_bh
= affs_bread(sb
, inode
->i_ino
);
93 /* If the directory hasn't changed since the last call to readdir(),
94 * we can jump directly to where we left off.
96 ino
= (u32
)(long)filp
->private_data
;
97 if (ino
&& filp
->f_version
== inode
->i_version
) {
98 pr_debug("AFFS: readdir() left off=%d\n", ino
);
102 ino
= be32_to_cpu(AFFS_HEAD(dir_bh
)->table
[hash_pos
]);
103 for (i
= 0; ino
&& i
< chain_pos
; i
++) {
104 fh_bh
= affs_bread(sb
, ino
);
106 affs_error(sb
, "readdir","Cannot read block %d", i
);
109 ino
= be32_to_cpu(AFFS_TAIL(sb
, fh_bh
)->hash_chain
);
117 for (; hash_pos
< AFFS_SB(sb
)->s_hashsize
; hash_pos
++) {
118 ino
= be32_to_cpu(AFFS_HEAD(dir_bh
)->table
[hash_pos
]);
121 f_pos
= (hash_pos
<< 16) + 2;
124 fh_bh
= affs_bread(sb
, ino
);
126 affs_error(sb
, "readdir","Cannot read block %d", ino
);
130 namelen
= min(AFFS_TAIL(sb
, fh_bh
)->name
[0], (u8
)30);
131 name
= AFFS_TAIL(sb
, fh_bh
)->name
+ 1;
132 pr_debug("AFFS: readdir(): filldir(\"%.*s\", ino=%u), hash=%d, f_pos=%x\n",
133 namelen
, name
, ino
, hash_pos
, f_pos
);
134 if (filldir(dirent
, name
, namelen
, f_pos
, ino
, DT_UNKNOWN
) < 0)
138 ino
= be32_to_cpu(AFFS_TAIL(sb
, fh_bh
)->hash_chain
);
145 filp
->f_version
= inode
->i_version
;
146 filp
->private_data
= (void *)(long)ino
;
152 affs_unlock_dir(inode
);
153 pr_debug("AFFS: readdir()=%d\n", stored
);