This source file includes following definitions.
- isofs_readdir
1
2
3
4
5
6
7
8
9
10
11 #include <linux/errno.h>
12
13 #include <asm/segment.h>
14
15 #include <linux/fs.h>
16 #include <linux/iso_fs.h>
17 #include <linux/kernel.h>
18 #include <linux/stat.h>
19 #include <linux/string.h>
20 #include <linux/mm.h>
21 #include <linux/malloc.h>
22
23 static int isofs_readdir(struct inode *, struct file *, struct dirent *, int);
24
25 static struct file_operations isofs_dir_operations = {
26 NULL,
27 NULL,
28 NULL,
29 isofs_readdir,
30 NULL,
31 NULL,
32 NULL,
33 NULL,
34 NULL
35 };
36
37
38
39
40 struct inode_operations isofs_dir_inode_operations = {
41 &isofs_dir_operations,
42 NULL,
43 isofs_lookup,
44 NULL,
45 NULL,
46 NULL,
47 NULL,
48 NULL,
49 NULL,
50 NULL,
51 NULL,
52 NULL,
53 isofs_bmap,
54 NULL,
55 NULL
56 };
57
58
59
60
61
62 struct lookup_cache cache = {0,};
63
64 static int isofs_readdir(struct inode * inode, struct file * filp,
65 struct dirent * dirent, int count)
66 {
67 unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
68 unsigned char bufbits = ISOFS_BUFFER_BITS(inode);
69 unsigned int block,offset,i, j;
70 char c = 0;
71 int inode_number;
72 struct buffer_head * bh;
73 void * cpnt = NULL;
74 unsigned int old_offset;
75 int dlen, rrflag;
76 char * dpnt;
77 struct iso_directory_record * de;
78
79 if (!inode || !S_ISDIR(inode->i_mode))
80 return -EBADF;
81
82 offset = filp->f_pos & (bufsize - 1);
83 block = isofs_bmap(inode,filp->f_pos>>bufbits);
84 if (!block || !(bh = bread(inode->i_dev,block,bufsize)))
85 return 0;
86
87 while (filp->f_pos < inode->i_size) {
88 #ifdef DEBUG
89 printk("Block, offset: %x %x %x\n",
90 block, offset, filp->f_pos);
91 #endif
92 de = (struct iso_directory_record *) (bh->b_data + offset);
93 inode_number = (block << bufbits) + (offset & (bufsize - 1));
94
95
96
97
98
99 if (*((unsigned char *) de) == 0) {
100 brelse(bh);
101 offset = 0;
102 filp->f_pos = ((filp->f_pos & ~(ISOFS_BLOCK_SIZE - 1))
103 + ISOFS_BLOCK_SIZE);
104 block = isofs_bmap(inode,(filp->f_pos)>>bufbits);
105 if (!block
106 || !(bh = bread(inode->i_dev,block,bufsize)))
107 return 0;
108 continue;
109 }
110
111
112
113
114
115
116 old_offset = offset;
117 offset += *((unsigned char *) de);
118 filp->f_pos += *((unsigned char *) de);
119
120 if (offset >= bufsize) {
121 cpnt = kmalloc(1 << ISOFS_BLOCK_BITS, GFP_KERNEL);
122 memcpy(cpnt, bh->b_data, bufsize);
123 de = (struct iso_directory_record *)
124 ((char *)cpnt + old_offset);
125 brelse(bh);
126 offset = filp->f_pos & (bufsize - 1);
127 block = isofs_bmap(inode,(filp->f_pos)>> bufbits);
128 if (!block
129 || !(bh = bread(inode->i_dev,block,bufsize))) {
130 kfree_s(cpnt, 1 << ISOFS_BLOCK_BITS);
131 return 0;
132 };
133 memcpy((char *)cpnt+bufsize, bh->b_data, bufsize);
134 }
135
136
137
138 rrflag = 0;
139 i = 1;
140 if (de->name_len[0] == 1 && de->name[0] == 0) {
141 put_fs_byte('.',dirent->d_name);
142 inode_number = inode->i_ino;
143 dpnt = ".";
144 }
145
146
147
148 else if (de->name_len[0] == 1 && de->name[0] == 1) {
149 put_fs_byte('.',dirent->d_name);
150 put_fs_byte('.',dirent->d_name+1);
151 i = 2;
152 dpnt = "..";
153 if((inode->i_sb->u.isofs_sb.s_firstdatazone
154 << bufbits) != inode->i_ino)
155 inode_number = inode->u.isofs_i.i_backlink;
156 else
157 inode_number = inode->i_ino;
158
159
160 if(inode_number == -1) {
161 inode_number =
162 isofs_lookup_grandparent(inode,
163 find_rock_ridge_relocation(de, inode));
164 if(inode_number == -1){
165 printk("Backlink not properly set.\n");
166 goto out;
167 };
168 }
169 }
170
171
172
173
174 else {
175 dlen = de->name_len[0];
176 dpnt = de->name;
177 i = dlen;
178 rrflag = get_rock_ridge_filename(de, &dpnt, &dlen, inode);
179 if (rrflag) {
180 if (rrflag == -1) {
181 if (cpnt) {
182 kfree_s(cpnt, 1 << ISOFS_BLOCK_BITS);
183 cpnt = NULL;
184 };
185 continue;
186 };
187 i = dlen;
188 }
189 else
190 if(inode->i_sb->u.isofs_sb.s_mapping == 'n')
191 for (i = 0; i < dlen && i < NAME_MAX; i++) {
192 if (!(c = dpnt[i])) break;
193 if (c >= 'A' && c <= 'Z') c |= 0x20;
194 if (c == ';' && i == dlen-2 && de->name[i+1] == '1')
195 break;
196 if (c == ';') c = '.';
197 dpnt[i] = c;
198 };
199
200 for(j=0; j<i; j++)
201 put_fs_byte(dpnt[j],j+dirent->d_name);
202 };
203 #if 0
204 printk("Nchar: %d\n",i);
205 #endif
206
207 if (i && i+1 < sizeof(cache.filename)) {
208 cache.ino = inode_number;
209 cache.dir = inode->i_ino;
210 cache.dev = inode->i_dev;
211 strncpy(cache.filename, dpnt, i);
212 cache.dlen = dlen;
213 };
214
215 if (rrflag) kfree(dpnt);
216 if (cpnt) {
217 kfree_s(cpnt, 1 << ISOFS_BLOCK_BITS);
218 cpnt = NULL;
219 };
220
221 if (i) {
222 put_fs_long(inode_number, &dirent->d_ino);
223 put_fs_byte(0,i+dirent->d_name);
224 put_fs_word(i,&dirent->d_reclen);
225 brelse(bh);
226 return i;
227 }
228 }
229
230
231 out:
232 if (cpnt)
233 kfree_s(cpnt, 1 << ISOFS_BLOCK_BITS);
234 brelse(bh);
235 return 0;
236 }
237
238
239