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 ext_truncate,
61 NULL
62 };
63
64 static int ext_readdir(struct inode * inode, struct file * filp,
65 void * dirent, filldir_t filldir)
66 {
67 int error;
68 unsigned int i;
69 off_t offset;
70 struct buffer_head * bh;
71 struct ext_dir_entry * de;
72
73 if (!inode || !S_ISDIR(inode->i_mode))
74 return -EBADF;
75 if ((filp->f_pos & 7) != 0)
76 return -EBADF;
77 error = 0;
78 while (!error && filp->f_pos < inode->i_size) {
79 offset = filp->f_pos & 1023;
80 bh = ext_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
81 if (!bh) {
82 filp->f_pos += 1024-offset;
83 continue;
84 }
85 for (i = 0; i < 1024 && i < offset; ) {
86 de = (struct ext_dir_entry *) (bh->b_data + i);
87 if (!de->rec_len)
88 break;
89 i += de->rec_len;
90 }
91 offset = i;
92 de = (struct ext_dir_entry *) (offset + bh->b_data);
93 while (offset < 1024 && filp->f_pos < inode->i_size) {
94 if (de->rec_len < 8 || de->rec_len % 8 != 0 ||
95 de->rec_len < de->name_len + 8 ||
96 (de->rec_len + (off_t) filp->f_pos - 1) / 1024 > ((off_t) filp->f_pos / 1024)) {
97 printk ("ext_readdir: bad dir entry, skipping\n");
98 printk ("dev=%s, dir=%ld, "
99 "offset=%ld, rec_len=%d, name_len=%d\n",
100 kdevname(inode->i_dev), inode->i_ino,
101 offset, de->rec_len, de->name_len);
102 filp->f_pos += 1024-offset;
103 if (filp->f_pos > inode->i_size)
104 filp->f_pos = inode->i_size;
105 continue;
106 }
107 if (de->inode) {
108 error = filldir(dirent, de->name, de->name_len, filp->f_pos, de->inode);
109 if (error)
110 break;
111 }
112 offset += de->rec_len;
113 filp->f_pos += de->rec_len;
114 ((char *) de) += de->rec_len;
115 }
116 brelse(bh);
117 }
118 return 0;
119 }