1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*
* linux/fs/minix/dir.c
*
* Copyright (C) 1991, 1992 Linus Torvalds
*
* minix directory handling functions
*/
#include <asm/segment.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/minix_fs.h>
#include <linux/stat.h>
#define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
#define ROUND_UP(x) (((x)+3) & ~3)
static int minix_dir_read(struct inode * inode, struct file * filp, char * buf, int count)
{
return -EISDIR;
}
static int minix_readdir(struct inode *, struct file *, struct dirent *, int);
static struct file_operations minix_dir_operations = {
NULL, /* lseek - default */
minix_dir_read, /* read */
NULL, /* write - bad */
minix_readdir, /* readdir */
NULL, /* select - default */
NULL, /* ioctl - default */
NULL, /* mmap */
NULL, /* no special open code */
NULL, /* no special release code */
file_fsync /* default fsync */
};
/*
* directories can handle most operations...
*/
struct inode_operations minix_dir_inode_operations = {
&minix_dir_operations, /* default directory file-ops */
minix_create, /* create */
minix_lookup, /* lookup */
minix_link, /* link */
minix_unlink, /* unlink */
minix_symlink, /* symlink */
minix_mkdir, /* mkdir */
minix_rmdir, /* rmdir */
minix_mknod, /* mknod */
minix_rename, /* rename */
NULL, /* readlink */
NULL, /* follow_link */
NULL, /* bmap */
minix_truncate, /* truncate */
NULL /* permission */
};
static int minix_readdir(struct inode * inode, struct file * filp,
struct dirent * dirent, int count)
{
unsigned int offset,i,ret;
int version;
char c;
struct buffer_head * bh;
struct minix_dir_entry * de;
struct minix_sb_info * info;
if (!inode || !inode->i_sb || !S_ISDIR(inode->i_mode))
return -EBADF;
info = &inode->i_sb->u.minix_sb;
if (filp->f_pos & (info->s_dirsize - 1))
return -EBADF;
ret = 0;
while (!ret && filp->f_pos < inode->i_size) {
offset = filp->f_pos & 1023;
bh = minix_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
if (!bh) {
filp->f_pos += 1024-offset;
continue;
}
while (!ret && offset < 1024 && filp->f_pos < inode->i_size) {
de = (struct minix_dir_entry *) (offset + bh->b_data);
offset += info->s_dirsize;
filp->f_pos += info->s_dirsize;
retry:
if (de->inode) {
version = inode->i_version;
for (i = 0; i < info->s_namelen; i++)
if ((c = de->name[i]) != 0)
put_fs_byte(c,i+dirent->d_name);
else
break;
if (i) {
put_fs_long(de->inode,&dirent->d_ino);
put_fs_byte(0,i+dirent->d_name);
put_fs_word(i,&dirent->d_reclen);
if (version != inode->i_version)
goto retry;
ret = ROUND_UP(NAME_OFFSET(dirent)+i+1);
}
}
}
brelse(bh);
}
return ret;
}
|