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 *, struct dirent *, int);
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 struct dirent * dirent, int count)
66 {
67 unsigned int i;
68 off_t offset;
69 char c;
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 % 8 != 0)
76 return -EBADF;
77 while (filp->f_pos < inode->i_size) {
78 offset = filp->f_pos & 1023;
79 bh = ext_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
80 if (!bh) {
81 filp->f_pos += 1024-offset;
82 continue;
83 }
84 de = (struct ext_dir_entry *) (offset + bh->b_data);
85 while (offset < 1024 && filp->f_pos < inode->i_size) {
86 if (de->rec_len < 8 || de->rec_len % 8 != 0 ||
87 de->rec_len < de->name_len + 8 ||
88 (de->rec_len + (off_t) filp->f_pos - 1) / 1024 > ((off_t) filp->f_pos / 1024)) {
89 printk ("ext_readdir: bad dir entry, skipping\n");
90 printk ("dev=%d, dir=%ld, offset=%ld, rec_len=%d, name_len=%d\n",
91 inode->i_dev, inode->i_ino, offset, de->rec_len, de->name_len);
92 filp->f_pos += 1024-offset;
93 if (filp->f_pos > inode->i_size)
94 filp->f_pos = inode->i_size;
95 continue;
96 }
97 offset += de->rec_len;
98 filp->f_pos += de->rec_len;
99 if (de->inode) {
100 for (i = 0; i < de->name_len; i++)
101 if ((c = de->name[i]) != 0)
102 put_fs_byte(c,i+dirent->d_name);
103 else
104 break;
105 if (i) {
106 put_fs_long(de->inode,&dirent->d_ino);
107 put_fs_byte(0,i+dirent->d_name);
108 put_fs_word(i,&dirent->d_reclen);
109 brelse(bh);
110 return i;
111 }
112 }
113 de = (struct ext_dir_entry *) ((char *) de
114 + de->rec_len);
115 }
116 brelse(bh);
117 }
118 return 0;
119 }