4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * minix directory handling functions
9 #include <asm/segment.h>
11 #include <linux/errno.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
)
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 */
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 */
51 NULL
, /* follow_link */
53 minix_truncate
, /* truncate */
57 static int minix_readdir(struct inode
* inode
, struct file
* filp
,
58 struct dirent
* dirent
, int count
)
60 unsigned int offset
,i
;
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
))
68 info
= &inode
->i_sb
->u
.minix_sb
;
69 if (filp
->f_pos
& (info
->s_dirsize
- 1))
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);
75 filp
->f_pos
+= 1024-offset
;
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
;
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
);
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
);