|
|
1.1 root 1: /*
2: * linux/fs/ext/dir.c
3: *
1.1.1.2 ! root 4: * Copyright (C) 1992 Remy Card ([email protected])
1.1 root 5: *
6: * from
7: *
8: * linux/fs/minix/dir.c
9: *
1.1.1.2 ! root 10: * Copyright (C) 1991, 1992 Linus Torvalds
1.1 root 11: *
12: * ext directory handling functions
13: */
14:
15: #include <asm/segment.h>
16:
1.1.1.2 ! root 17: #include <linux/errno.h>
1.1 root 18: #include <linux/fs.h>
19: #include <linux/ext_fs.h>
20: #include <linux/stat.h>
21:
22: static int ext_readdir(struct inode *, struct file *, struct dirent *, int);
23:
24: static struct file_operations ext_dir_operations = {
25: NULL, /* lseek - default */
26: NULL, /* read */
27: NULL, /* write - bad */
28: ext_readdir, /* readdir */
29: NULL, /* select - default */
30: NULL, /* ioctl - default */
31: NULL, /* no special open code */
32: NULL /* no special release code */
33: };
34:
35: /*
36: * directories can handle most operations...
37: */
38: struct inode_operations ext_dir_inode_operations = {
39: &ext_dir_operations, /* default directory file-ops */
40: ext_create, /* create */
41: ext_lookup, /* lookup */
42: ext_link, /* link */
43: ext_unlink, /* unlink */
44: ext_symlink, /* symlink */
45: ext_mkdir, /* mkdir */
46: ext_rmdir, /* rmdir */
47: ext_mknod, /* mknod */
48: ext_rename, /* rename */
49: NULL, /* readlink */
50: NULL, /* follow_link */
51: ext_bmap, /* bmap */
52: ext_truncate /* truncate */
53: };
54:
55: static int ext_readdir(struct inode * inode, struct file * filp,
56: struct dirent * dirent, int count)
57: {
58: unsigned int block,offset,i;
59: char c;
60: struct buffer_head * bh;
61: struct ext_dir_entry * de;
62:
63: if (!inode || !S_ISDIR(inode->i_mode))
64: return -EBADF;
65: /* if (filp->f_pos & (sizeof (struct ext_dir_entry) - 1))
66: return -EBADF; */
67: while (filp->f_pos < inode->i_size) {
68: offset = filp->f_pos & 1023;
69: block = ext_bmap(inode,(filp->f_pos)>>BLOCK_SIZE_BITS);
1.1.1.2 ! root 70: if (!block || !(bh = bread(inode->i_dev, block, BLOCK_SIZE))) {
1.1 root 71: filp->f_pos += 1024-offset;
72: continue;
73: }
74: de = (struct ext_dir_entry *) (offset + bh->b_data);
75: while (offset < 1024 && filp->f_pos < inode->i_size) {
76: offset += de->rec_len;
77: filp->f_pos += de->rec_len;
78: if (de->inode) {
79: for (i = 0; i < de->name_len; i++)
80: if (c = de->name[i])
81: put_fs_byte(c,i+dirent->d_name);
82: else
83: break;
84: if (i) {
85: put_fs_long(de->inode,&dirent->d_ino);
86: put_fs_byte(0,i+dirent->d_name);
87: put_fs_word(i,&dirent->d_reclen);
88: brelse(bh);
89: return i;
90: }
91: }
92: /* de++; */
93: de = (struct ext_dir_entry *) ((char *) de + de->rec_len);
94: }
95: brelse(bh);
96: }
97: return 0;
98: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.