This source file includes following definitions.
- minix_readdir
1
2
3
4
5
6
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_readdir(struct inode *, struct file *, struct dirent *, int);
17
18 static struct file_operations minix_dir_operations = {
19 NULL,
20 minix_file_read,
21 NULL,
22 minix_readdir,
23 NULL,
24 NULL,
25 NULL,
26 NULL
27 };
28
29
30
31
32 struct inode_operations minix_dir_inode_operations = {
33 &minix_dir_operations,
34 minix_create,
35 minix_lookup,
36 minix_link,
37 minix_unlink,
38 minix_symlink,
39 minix_mkdir,
40 minix_rmdir,
41 minix_mknod,
42 minix_rename,
43 NULL,
44 NULL,
45 minix_bmap,
46 minix_truncate
47 };
48
49 static int minix_readdir(struct inode * inode, struct file * filp,
50 struct dirent * dirent, int count)
51 {
52 unsigned int block,offset,i;
53 char c;
54 struct buffer_head * bh;
55 struct minix_dir_entry * de;
56
57 if (!inode || !S_ISDIR(inode->i_mode))
58 return -EBADF;
59 if (filp->f_pos & (sizeof (struct minix_dir_entry) - 1))
60 return -EBADF;
61 while (filp->f_pos < inode->i_size) {
62 offset = filp->f_pos & 1023;
63 block = minix_bmap(inode,(filp->f_pos)>>BLOCK_SIZE_BITS);
64 if (!block || !(bh = bread(inode->i_dev,block,BLOCK_SIZE))) {
65 filp->f_pos += 1024-offset;
66 continue;
67 }
68 de = (struct minix_dir_entry *) (offset + bh->b_data);
69 while (offset < 1024 && filp->f_pos < inode->i_size) {
70 offset += sizeof (struct minix_dir_entry);
71 filp->f_pos += sizeof (struct minix_dir_entry);
72 if (de->inode) {
73 for (i = 0; i < MINIX_NAME_LEN; i++)
74 if (c = de->name[i])
75 put_fs_byte(c,i+dirent->d_name);
76 else
77 break;
78 if (i) {
79 put_fs_long(de->inode,&dirent->d_ino);
80 put_fs_byte(0,i+dirent->d_name);
81 put_fs_word(i,&dirent->d_reclen);
82 brelse(bh);
83 return i;
84 }
85 }
86 de++;
87 }
88 brelse(bh);
89 }
90 return 0;
91 }