1 /*
2 * linux/fs/sysv/dir.c
3 *
4 * minix/dir.c
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 *
7 * coh/dir.c
8 * Copyright (C) 1993 Pascal Haible, Bruno Haible
9 *
10 * sysv/dir.c
11 * Copyright (C) 1993 Bruno Haible
12 *
13 * SystemV/Coherent directory handling functions
14 */
15
16 #include <asm/segment.h>
17
18 #include <linux/errno.h>
19 #include <linux/fs.h>
20 #include <linux/sysv_fs.h>
21 #include <linux/stat.h>
22
23 static int sysv_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)
*/
24 {
25 return -EISDIR;
26 }
27
28 static int sysv_readdir(struct inode *, struct file *, struct dirent *, int);
29
30 static struct file_operations sysv_dir_operations = {
31 NULL, /* lseek - default */
32 sysv_dir_read, /* read */
33 NULL, /* write - bad */
34 sysv_readdir, /* readdir */
35 NULL, /* select - default */
36 NULL, /* ioctl - default */
37 NULL, /* mmap */
38 NULL, /* no special open code */
39 NULL, /* no special release code */
40 file_fsync /* default fsync */
41 };
42
43 /*
44 * directories can handle most operations...
45 */
46 struct inode_operations sysv_dir_inode_operations = {
47 &sysv_dir_operations, /* default directory file-ops */
48 sysv_create, /* create */
49 sysv_lookup, /* lookup */
50 sysv_link, /* link */
51 sysv_unlink, /* unlink */
52 sysv_symlink, /* symlink */
53 sysv_mkdir, /* mkdir */
54 sysv_rmdir, /* rmdir */
55 sysv_mknod, /* mknod */
56 sysv_rename, /* rename */
57 NULL, /* readlink */
58 NULL, /* follow_link */
59 NULL, /* bmap */
60 sysv_truncate, /* truncate */
61 NULL /* permission */
62 };
63
64 static int sysv_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)
*/
65 struct dirent * dirent, int count)
66 {
67 struct super_block * sb;
68 unsigned int offset,i;
69 char c;
70 struct buffer_head * bh;
71 char* bh_data;
72 struct sysv_dir_entry * de;
73
74 if (!inode || !(sb = inode->i_sb) || !S_ISDIR(inode->i_mode))
75 return -EBADF;
76 if ((unsigned long)(filp->f_pos) % SYSV_DIRSIZE)
77 return -EBADF;
78 while (filp->f_pos < inode->i_size) {
79 offset = filp->f_pos & sb->sv_block_size_1;
80 bh = sysv_file_bread(inode, filp->f_pos >> sb->sv_block_size_bits, 0, &bh_data);
81 if (!bh) {
82 filp->f_pos += sb->sv_block_size - offset;
83 continue;
84 }
85 while (offset < sb->sv_block_size && filp->f_pos < inode->i_size) {
86 de = (struct sysv_dir_entry *) (offset + bh_data);
87 offset += SYSV_DIRSIZE;
88 filp->f_pos += SYSV_DIRSIZE;
89 if (de->inode) {
90 for (i = 0; i < SYSV_NAMELEN; i++)
91 if ((c = de->name[i]) != 0)
92 put_fs_byte(c,i+dirent->d_name);
93 else
94 break;
95 if (i) {
96 if (de->inode > inode->i_sb->sv_ninodes)
97 printk("sysv_readdir: Bad inode number on dev 0x%04x, ino %ld, offset 0x%04lx: %d is out of range\n",
98 inode->i_dev, inode->i_ino, filp->f_pos - SYSV_DIRSIZE, de->inode);
99 put_fs_long(de->inode,&dirent->d_ino);
100 put_fs_byte(0,i+dirent->d_name);
101 put_fs_word(i,&dirent->d_reclen);
102 brelse(bh);
103 return i;
104 }
105 }
106 }
107 brelse(bh);
108 }
109 return 0;
110 }