This source file includes following definitions.
- ext_dir_read
- ext_readdir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #include <asm/segment.h>
16
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
19 #include <linux/fs.h>
20 #include <linux/ext_fs.h>
21 #include <linux/stat.h>
22
23 static int ext_dir_read(struct inode * inode, struct file * filp, char * buf, int count)
24 {
25 return -EISDIR;
26 }
27
28 static int ext_readdir(struct inode *, struct file *, void *, filldir_t);
29
30 static struct file_operations ext_dir_operations = {
31 NULL,
32 ext_dir_read,
33 NULL,
34 ext_readdir,
35 NULL,
36 NULL,
37 NULL,
38 NULL,
39 NULL,
40 file_fsync
41 };
42
43
44
45
46 struct inode_operations ext_dir_inode_operations = {
47 &ext_dir_operations,
48 ext_create,
49 ext_lookup,
50 ext_link,
51 ext_unlink,
52 ext_symlink,
53 ext_mkdir,
54 ext_rmdir,
55 ext_mknod,
56 ext_rename,
57 NULL,
58 NULL,
59 NULL,
60 NULL,
61 NULL,
62 ext_truncate,
63 NULL
64 };
65
66 static int ext_readdir(struct inode * inode, struct file * filp,
67 void * dirent, filldir_t filldir)
68 {
69 int error;
70 unsigned int i;
71 off_t offset;
72 struct buffer_head * bh;
73 struct ext_dir_entry * de;
74
75 if (!inode || !S_ISDIR(inode->i_mode))
76 return -EBADF;
77 if ((filp->f_pos & 7) != 0)
78 return -EBADF;
79 error = 0;
80 while (!error && filp->f_pos < inode->i_size) {
81 offset = filp->f_pos & 1023;
82 bh = ext_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
83 if (!bh) {
84 filp->f_pos += 1024-offset;
85 continue;
86 }
87 for (i = 0; i < 1024 && i < offset; ) {
88 de = (struct ext_dir_entry *) (bh->b_data + i);
89 if (!de->rec_len)
90 break;
91 i += de->rec_len;
92 }
93 offset = i;
94 de = (struct ext_dir_entry *) (offset + bh->b_data);
95 while (offset < 1024 && filp->f_pos < inode->i_size) {
96 if (de->rec_len < 8 || de->rec_len % 8 != 0 ||
97 de->rec_len < de->name_len + 8 ||
98 (de->rec_len + (off_t) filp->f_pos - 1) / 1024 > ((off_t) filp->f_pos / 1024)) {
99 printk ("ext_readdir: bad dir entry, skipping\n");
100 printk ("dev=%s, dir=%ld, "
101 "offset=%ld, rec_len=%d, name_len=%d\n",
102 kdevname(inode->i_dev), inode->i_ino,
103 offset, de->rec_len, de->name_len);
104 filp->f_pos += 1024-offset;
105 if (filp->f_pos > inode->i_size)
106 filp->f_pos = inode->i_size;
107 continue;
108 }
109 if (de->inode) {
110 error = filldir(dirent, de->name, de->name_len, filp->f_pos, de->inode);
111 if (error)
112 break;
113 }
114 offset += de->rec_len;
115 filp->f_pos += de->rec_len;
116 ((char *) de) += de->rec_len;
117 }
118 brelse(bh);
119 }
120 return 0;
121 }