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 file_fsync /* default fsync */
34 };
35
36 /*
37 * directories can handle most operations...
38 */
39 struct inode_operations minix_dir_inode_operations = {
40 &minix_dir_operations, /* default directory file-ops */
41 minix_create, /* create */
42 minix_lookup, /* lookup */
43 minix_link, /* link */
44 minix_unlink, /* unlink */
45 minix_symlink, /* symlink */
46 minix_mkdir, /* mkdir */
47 minix_rmdir, /* rmdir */
48 minix_mknod, /* mknod */
49 minix_rename, /* rename */
50 NULL, /* readlink */
51 NULL, /* follow_link */
52 NULL, /* bmap */
53 minix_truncate, /* truncate */
54 NULL /* permission */
55 };
56
57 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)
*/
58 struct dirent * dirent, int count)
59 {
60 unsigned int offset,i;
61 char c;
62 struct buffer_head * bh;
63 struct minix_dir_entry * de;
64 struct minix_sb_info * info;
65
66 if (!inode || !inode->i_sb || !S_ISDIR(inode->i_mode))
67 return -EBADF;
68 info = &inode->i_sb->u.minix_sb;
69 if (filp->f_pos & (info->s_dirsize - 1))
70 return -EBADF;
71 while (filp->f_pos < inode->i_size) {
72 offset = filp->f_pos & 1023;
73 bh = minix_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
74 if (!bh) {
75 filp->f_pos += 1024-offset;
76 continue;
77 }
78 while (offset < 1024 && filp->f_pos < inode->i_size) {
79 de = (struct minix_dir_entry *) (offset + bh->b_data);
80 offset += info->s_dirsize;
81 filp->f_pos += info->s_dirsize;
82 if (de->inode) {
83 for (i = 0; i < info->s_namelen; i++)
84 if ((c = de->name[i]) != 0)
85 put_fs_byte(c,i+dirent->d_name);
86 else
87 break;
88 if (i) {
89 put_fs_long(de->inode,&dirent->d_ino);
90 put_fs_byte(0,i+dirent->d_name);
91 put_fs_word(i,&dirent->d_reclen);
92 brelse(bh);
93 return i;
94 }
95 }
96 }
97 brelse(bh);
98 }
99 return 0;
100 }