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