|
|
1.1 root 1: /*
2: * linux/fs/msdos/dir.c
3: *
4: * Written 1992 by Werner Almesberger
5: *
6: * MS-DOS directory handling functions
7: */
8:
9: #include <asm/segment.h>
10:
11: #include <linux/sched.h>
12: #include <linux/fs.h>
13: #include <linux/msdos_fs.h>
14: #include <linux/errno.h>
15: #include <linux/stat.h>
16:
17: static int msdos_dummy_read(struct inode *inode,struct file *filp,char *buf,
18: int count);
19: static int msdos_readdir(struct inode *inode,struct file *filp,
20: struct dirent *dirent,int count);
21:
22:
23: static struct file_operations msdos_dir_operations = {
24: NULL, /* lseek - default */
25: msdos_dummy_read, /* read */
26: NULL, /* write - bad */
27: msdos_readdir, /* readdir */
28: NULL, /* select - default */
29: NULL, /* ioctl - default */
30: NULL, /* no special open code */
31: NULL /* no special release code */
32: };
33:
34: struct inode_operations msdos_dir_inode_operations = {
35: &msdos_dir_operations, /* default directory file-ops */
36: msdos_create, /* create */
37: msdos_lookup, /* lookup */
38: NULL, /* link */
39: msdos_unlink, /* unlink */
40: NULL, /* symlink */
41: msdos_mkdir, /* mkdir */
42: msdos_rmdir, /* rmdir */
43: NULL, /* mknod */
44: msdos_rename, /* rename */
45: NULL, /* readlink */
46: NULL, /* follow_link */
47: msdos_bmap, /* bmap */
48: NULL /* truncate */
49: };
50:
51:
52: /* So grep * doesn't complain in the presence of directories. */
53:
54: static int msdos_dummy_read(struct inode *inode,struct file *filp,char *buf,
55: int count)
56: {
57: static long last_warning = 0;
58:
59: if (CURRENT_TIME-last_warning >= 10) {
60: printk("COMPATIBILITY WARNING: reading a directory\r\n");
61: last_warning = CURRENT_TIME;
62: }
63: return 0;
64: }
65:
66:
67: static int msdos_readdir(struct inode *inode,struct file *filp,
68: struct dirent *dirent,int count)
69: {
70: int ino,i,i2,last;
71: char c,*walk;
72: struct buffer_head *bh;
73: struct msdos_dir_entry *de;
74:
75: if (!inode || !S_ISDIR(inode->i_mode)) return -EBADF;
76: if (inode->i_ino == MSDOS_ROOT_INO) {
77: /* Fake . and .. for the root directory. */
78: if (filp->f_pos == 2) filp->f_pos = 0;
79: else if (filp->f_pos < 2) {
80: walk = filp->f_pos++ ? ".." : ".";
81: for (i = 0; *walk; walk++)
82: put_fs_byte(*walk,dirent->d_name+i++);
83: put_fs_long(MSDOS_ROOT_INO,&dirent->d_ino);
84: put_fs_byte(0,dirent->d_name+i);
85: put_fs_word(i,&dirent->d_reclen);
86: return i;
87: }
88: }
89: if (filp->f_pos & (sizeof(struct msdos_dir_entry)-1)) return -ENOENT;
90: bh = NULL;
91: while ((ino = msdos_get_entry(inode,&filp->f_pos,&bh,&de)) > -1) {
92: if (de->name[0] && ((unsigned char *) (de->name))[0] !=
93: DELETED_FLAG && !(de->attr & ATTR_VOLUME)) {
94: for (i = last = 0; i < 8; i++) {
95: if (!(c = de->name[i])) break;
96: if (c >= 'A' && c <= 'Z') c += 32;
97: if (c != ' ') last = i+1;
98: put_fs_byte(c,i+dirent->d_name);
99: }
100: i = last;
101: if (de->ext[0] && de->ext[0] != ' ') {
102: put_fs_byte('.',i+dirent->d_name);
103: i++;
104: for (i2 = 0; i2 < 3; i2++) {
105: if (!(c = de->ext[i2])) break;
106: if (c >= 'A' && c <= 'Z') c += 32;
107: put_fs_byte(c,i+dirent->d_name);
108: i++;
109: if (c != ' ') last = i;
110: }
111: }
112: if (i = last) {
113: if (!strcmp(de->name,MSDOS_DOT))
114: ino = inode->i_ino;
115: else if (!strcmp(de->name,MSDOS_DOTDOT))
116: ino = msdos_parent_ino(inode,0);
117: put_fs_long(ino,&dirent->d_ino);
118: put_fs_byte(0,i+dirent->d_name);
119: put_fs_word(i,&dirent->d_reclen);
120: brelse(bh);
121: return i;
122: }
123: }
124: }
125: if (bh) brelse(bh);
126: return 0;
127: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.