* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-0.99 / fs / minix / dir.c
blobf32a6837a4f35f642312169d2886f5f46dc4fcd6
1 /*
2 * linux/fs/minix/dir.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * minix directory handling functions
7 */
9 #include <asm/segment.h>
11 #include <linux/errno.h>
12 #include <linux/fs.h>
13 #include <linux/minix_fs.h>
14 #include <linux/stat.h>
16 static int minix_dir_read(struct inode * inode, struct file * filp, char * buf, int count)
18 return -EISDIR;
21 static int minix_readdir(struct inode *, struct file *, struct dirent *, int);
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 */
37 * directories can handle most operations...
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 */
57 static int minix_readdir(struct inode * inode, struct file * filp,
58 struct dirent * dirent, int count)
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;
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;
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;
97 brelse(bh);
99 return 0;