This source file includes following definitions.
- msdos_dir_read
- msdos_readdir
1
2
3
4
5
6
7
8
9 #include <asm/segment.h>
10
11 #include <linux/fs.h>
12 #include <linux/msdos_fs.h>
13 #include <linux/errno.h>
14 #include <linux/stat.h>
15 #include <linux/string.h>
16
17 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
18 #define ROUND_UP(x) (((x)+3) & ~3)
19
20
21 #define PRINTK(X)
22
23 static int msdos_dir_read(struct inode * inode,struct file * filp, char * buf,int count)
24 {
25 return -EISDIR;
26 }
27
28 static struct file_operations msdos_dir_operations = {
29 NULL,
30 msdos_dir_read,
31 NULL,
32 msdos_readdir,
33 NULL,
34 NULL,
35 NULL,
36 NULL,
37 NULL,
38 file_fsync
39 };
40
41 struct inode_operations msdos_dir_inode_operations = {
42 &msdos_dir_operations,
43 msdos_create,
44 msdos_lookup,
45 NULL,
46 msdos_unlink,
47 NULL,
48 msdos_mkdir,
49 msdos_rmdir,
50 NULL,
51 msdos_rename,
52 NULL,
53 NULL,
54 msdos_bmap,
55 NULL,
56 NULL
57 };
58
59 int msdos_readdir(
60 struct inode *inode,
61 struct file *filp,
62 struct dirent *dirent,
63 int count)
64 {
65 int ino,i,i2,last;
66 char c,*walk;
67 struct buffer_head *bh;
68 struct msdos_dir_entry *de;
69
70 if (!inode || !S_ISDIR(inode->i_mode)) return -EBADF;
71 if (inode->i_ino == MSDOS_ROOT_INO) {
72
73 if (filp->f_pos == 2) filp->f_pos = 0;
74 else if (filp->f_pos < 2) {
75 walk = filp->f_pos++ ? ".." : ".";
76 for (i = 0; *walk; walk++)
77 put_fs_byte(*walk,dirent->d_name+i++);
78 put_fs_long(MSDOS_ROOT_INO,&dirent->d_ino);
79 put_fs_byte(0,dirent->d_name+i);
80 put_fs_word(i,&dirent->d_reclen);
81 return ROUND_UP(NAME_OFFSET(dirent) + i + 1);
82 }
83 }
84 if (filp->f_pos & (sizeof(struct msdos_dir_entry)-1)) return -ENOENT;
85 bh = NULL;
86 while ((ino = msdos_get_entry(inode,&filp->f_pos,&bh,&de)) > -1) {
87 if (!IS_FREE(de->name) && !(de->attr & ATTR_VOLUME)) {
88 char bufname[13];
89 char *ptname = bufname;
90 for (i = last = 0; i < 8; i++) {
91 if (!(c = de->name[i])) break;
92 if (c >= 'A' && c <= 'Z') c += 32;
93 if (c != ' ')
94 last = i+1;
95 ptname[i] = c;
96 }
97 i = last;
98 ptname[i] = '.';
99 i++;
100 for (i2 = 0; i2 < 3; i2++) {
101 if (!(c = de->ext[i2])) break;
102 if (c >= 'A' && c <= 'Z') c += 32;
103 if (c != ' ')
104 last = i+1;
105 ptname[i] = c;
106 i++;
107 }
108 if ((i = last) != 0) {
109 if (!strcmp(de->name,MSDOS_DOT))
110 ino = inode->i_ino;
111 else if (!strcmp(de->name,MSDOS_DOTDOT))
112 ino = msdos_parent_ino(inode,0);
113 bufname[i] = '\0';
114 put_fs_long(ino,&dirent->d_ino);
115 memcpy_tofs(dirent->d_name,bufname,i+1);
116 put_fs_word(i,&dirent->d_reclen);
117 PRINTK (("readdir avant brelse\n"));
118 brelse(bh);
119 PRINTK (("readdir retourne %d\n",i));
120 return ROUND_UP(NAME_OFFSET(dirent) + i + 1);
121 }
122 }
123 }
124 if (bh) brelse(bh);
125 return 0;
126 }