1 /*
2 * linux/fs/minix/dir.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 *
6 * minix directory handling functions
7 */
8
9 #include <asm/segment.h>
10
11 #include <linux/errno.h>
12 #include <linux/fs.h>
13 #include <linux/minix_fs.h>
14 #include <linux/stat.h>
15
16 static int minix_dir_read(struct inode * inode, struct file * filp, char * buf, int count)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
17 {
18 return -EISDIR;
19 }
20
21 static int minix_readdir(struct inode *, struct file *, struct dirent *, int);
22
23 static struct file_operations minix_dir_operations = {
24 NULL, /* lseek - default */
25 minix_dir_read, /* read */
26 NULL, /* write - bad */
27 minix_readdir, /* readdir */
28 NULL, /* select - default */
29 NULL, /* ioctl - default */
30 NULL, /* mmap */
31 NULL, /* no special open code */
32 NULL /* no special release code */
33 };
34
35 /*
36 * directories can handle most operations...
37 */
38 struct inode_operations minix_dir_inode_operations = {
39 &minix_dir_operations, /* default directory file-ops */
40 minix_create, /* create */
41 minix_lookup, /* lookup */
42 minix_link, /* link */
43 minix_unlink, /* unlink */
44 minix_symlink, /* symlink */
45 minix_mkdir, /* mkdir */
46 minix_rmdir, /* rmdir */
47 minix_mknod, /* mknod */
48 minix_rename, /* rename */
49 NULL, /* readlink */
50 NULL, /* follow_link */
51 NULL, /* bmap */
52 minix_truncate /* truncate */
53 };
54
55 static int minix_readdir(struct inode * inode, struct file * filp,
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
56 struct dirent * dirent, int count)
57 {
58 unsigned int offset,i;
59 char c;
60 struct buffer_head * bh;
61 struct minix_dir_entry * de;
62
63 if (!inode || !S_ISDIR(inode->i_mode))
64 return -EBADF;
65 if (filp->f_pos & (sizeof (struct minix_dir_entry) - 1))
66 return -EBADF;
67 while (filp->f_pos < inode->i_size) {
68 offset = filp->f_pos & 1023;
69 bh = minix_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
70 if (!bh) {
71 filp->f_pos += 1024-offset;
72 continue;
73 }
74 de = (struct minix_dir_entry *) (offset + bh->b_data);
75 while (offset < 1024 && filp->f_pos < inode->i_size) {
76 offset += sizeof (struct minix_dir_entry);
77 filp->f_pos += sizeof (struct minix_dir_entry);
78 if (de->inode) {
79 for (i = 0; i < MINIX_NAME_LEN; i++)
80 if ((c = de->name[i]) != 0)
81 put_fs_byte(c,i+dirent->d_name);
82 else
83 break;
84 if (i) {
85 put_fs_long(de->inode,&dirent->d_ino);
86 put_fs_byte(0,i+dirent->d_name);
87 put_fs_word(i,&dirent->d_reclen);
88 brelse(bh);
89 return i;
90 }
91 }
92 de++;
93 }
94 brelse(bh);
95 }
96 return 0;
97 }