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