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 const struct file_operations affs_dir_operations
= {
21 .read
= generic_read_dir
,
22 .llseek
= generic_file_llseek
,
23 .readdir
= affs_readdir
,
24 .fsync
= affs_file_fsync
,
28 * directories can handle most operations...
30 const struct inode_operations affs_dir_inode_operations
= {
31 .create
= affs_create
,
32 .lookup
= affs_lookup
,
34 .unlink
= affs_unlink
,
35 .symlink
= affs_symlink
,
38 .rename
= affs_rename
,
39 .setattr
= affs_notify_change
,
43 affs_readdir(struct file
*filp
, void *dirent
, filldir_t filldir
)
45 struct inode
*inode
= file_inode(filp
);
46 struct super_block
*sb
= inode
->i_sb
;
47 struct buffer_head
*dir_bh
;
48 struct buffer_head
*fh_bh
;
59 pr_debug("AFFS: readdir(ino=%lu,f_pos=%lx)\n",inode
->i_ino
,(unsigned long)filp
->f_pos
);
68 filp
->private_data
= (void *)0;
69 if (filldir(dirent
, ".", 1, f_pos
, inode
->i_ino
, DT_DIR
) < 0)
71 filp
->f_pos
= f_pos
= 1;
75 if (filldir(dirent
, "..", 2, f_pos
, parent_ino(filp
->f_path
.dentry
), DT_DIR
) < 0)
77 filp
->f_pos
= f_pos
= 2;
82 chain_pos
= (f_pos
- 2) & 0xffff;
83 hash_pos
= (f_pos
- 2) >> 16;
84 if (chain_pos
== 0xffff) {
85 affs_warning(sb
, "readdir", "More than 65535 entries in chain");
88 filp
->f_pos
= ((hash_pos
<< 16) | chain_pos
) + 2;
90 dir_bh
= affs_bread(sb
, inode
->i_ino
);
94 /* If the directory hasn't changed since the last call to readdir(),
95 * we can jump directly to where we left off.
97 ino
= (u32
)(long)filp
->private_data
;
98 if (ino
&& filp
->f_version
== inode
->i_version
) {
99 pr_debug("AFFS: readdir() left off=%d\n", ino
);
103 ino
= be32_to_cpu(AFFS_HEAD(dir_bh
)->table
[hash_pos
]);
104 for (i
= 0; ino
&& i
< chain_pos
; i
++) {
105 fh_bh
= affs_bread(sb
, ino
);
107 affs_error(sb
, "readdir","Cannot read block %d", i
);
110 ino
= be32_to_cpu(AFFS_TAIL(sb
, fh_bh
)->hash_chain
);
118 for (; hash_pos
< AFFS_SB(sb
)->s_hashsize
; hash_pos
++) {
119 ino
= be32_to_cpu(AFFS_HEAD(dir_bh
)->table
[hash_pos
]);
122 f_pos
= (hash_pos
<< 16) + 2;
125 fh_bh
= affs_bread(sb
, ino
);
127 affs_error(sb
, "readdir","Cannot read block %d", ino
);
131 namelen
= min(AFFS_TAIL(sb
, fh_bh
)->name
[0], (u8
)30);
132 name
= AFFS_TAIL(sb
, fh_bh
)->name
+ 1;
133 pr_debug("AFFS: readdir(): filldir(\"%.*s\", ino=%u), hash=%d, f_pos=%x\n",
134 namelen
, name
, ino
, hash_pos
, f_pos
);
135 if (filldir(dirent
, name
, namelen
, f_pos
, ino
, DT_UNKNOWN
) < 0)
139 ino
= be32_to_cpu(AFFS_TAIL(sb
, fh_bh
)->hash_chain
);
146 filp
->f_version
= inode
->i_version
;
147 filp
->private_data
= (void *)(long)ino
;
153 affs_unlock_dir(inode
);
154 pr_debug("AFFS: readdir()=%d\n", stored
);