This source file includes following definitions.
- xiafs_dir_read
- xiafs_readdir
1
2
3
4
5
6
7
8
9
10
11
12 #include <asm/segment.h>
13 #include <linux/sched.h>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/fs.h>
17 #include <linux/xia_fs.h>
18 #include <linux/stat.h>
19
20 #include "xiafs_mac.h"
21
22 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
23 #define ROUND_UP(x) (((x)+3) & ~3)
24
25 static int xiafs_dir_read(struct inode *, struct file *, char *, int);
26 static int xiafs_readdir(struct inode *, struct file *, struct dirent *, int);
27
28 static struct file_operations xiafs_dir_operations = {
29 NULL,
30 xiafs_dir_read,
31 NULL,
32 xiafs_readdir,
33 NULL,
34 NULL,
35 NULL,
36 NULL,
37 NULL,
38 file_fsync
39 };
40
41
42
43
44 struct inode_operations xiafs_dir_inode_operations = {
45 &xiafs_dir_operations,
46 xiafs_create,
47 xiafs_lookup,
48 xiafs_link,
49 xiafs_unlink,
50 xiafs_symlink,
51 xiafs_mkdir,
52 xiafs_rmdir,
53 xiafs_mknod,
54 xiafs_rename,
55 NULL,
56 NULL,
57 NULL,
58 xiafs_truncate,
59 NULL
60 };
61
62 static int xiafs_dir_read(struct inode * inode,
63 struct file * filp, char * buf, int count)
64 {
65 return -EISDIR;
66 }
67
68 static int xiafs_readdir(struct inode * inode,
69 struct file * filp, struct dirent * dirent, int count)
70 {
71 u_int offset, i,ret;
72 struct buffer_head * bh;
73 struct xiafs_direct * de;
74
75 if (!inode || !inode->i_sb || !S_ISDIR(inode->i_mode))
76 return -EBADF;
77 if (inode->i_size & (XIAFS_ZSIZE(inode->i_sb) - 1) )
78 return -EBADF;
79 ret = 0;
80 while (!ret && filp->f_pos < inode->i_size) {
81 offset = filp->f_pos & (XIAFS_ZSIZE(inode->i_sb) - 1);
82 bh = xiafs_bread(inode, filp->f_pos >> XIAFS_ZSIZE_BITS(inode->i_sb),0);
83 if (!bh) {
84 filp->f_pos += XIAFS_ZSIZE(inode->i_sb)-offset;
85 continue;
86 }
87 for (i = 0; i < XIAFS_ZSIZE(inode->i_sb) && i < offset; ) {
88 de = (struct xiafs_direct *) (bh->b_data + i);
89 if (!de->d_rec_len)
90 break;
91 i += de->d_rec_len;
92 }
93 offset = i;
94 de = (struct xiafs_direct *) (offset + bh->b_data);
95
96 while (!ret && offset < XIAFS_ZSIZE(inode->i_sb) && filp->f_pos < inode->i_size) {
97 if (de->d_ino > inode->i_sb->u.xiafs_sb.s_ninodes ||
98 de->d_rec_len < 12 ||
99 (char *)de+de->d_rec_len > XIAFS_ZSIZE(inode->i_sb)+bh->b_data ||
100 de->d_name_len < 1 || de->d_name_len + 8 > de->d_rec_len ||
101 de->d_name_len > _XIAFS_NAME_LEN ||
102 de->d_name[de->d_name_len] ) {
103 printk("XIA-FS: bad directory entry (%s %d)\n", WHERE_ERR);
104 brelse(bh);
105 return 0;
106 }
107 offset += de->d_rec_len;
108 filp->f_pos += de->d_rec_len;
109 if (de->d_ino) {
110 for (i = 0; i < de->d_name_len ; i++)
111 put_fs_byte(de->d_name[i],i+dirent->d_name);
112 put_fs_byte(0,i+dirent->d_name);
113 put_fs_long(de->d_ino,&dirent->d_ino);
114 put_fs_word(i,&dirent->d_reclen);
115 if (!IS_RDONLY (inode)) {
116 inode->i_atime=CURRENT_TIME;
117 inode->i_dirt=1;
118 }
119 ret = ROUND_UP(NAME_OFFSET(dirent)+i+1);
120 break;
121 }
122 de = (struct xiafs_direct *) (offset + bh->b_data);
123 }
124 brelse(bh);
125 if (offset > XIAFS_ZSIZE(inode->i_sb)) {
126 printk("XIA-FS: bad directory (%s %d)\n", WHERE_ERR);
127 return 0;
128 }
129 }
130 if (!IS_RDONLY (inode)) {
131 inode->i_atime=CURRENT_TIME;
132 inode->i_dirt=1;
133 }
134 return ret;
135 }