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 109 110 111 112 113 114 115 116 117 118 119 120 121
|
/*
* linux/fs/ext/dir.c
*
* Copyright (C) 1992 Remy Card (card@masi.ibp.fr)
*
* from
*
* linux/fs/minix/dir.c
*
* Copyright (C) 1991, 1992 Linus Torvalds
*
* ext directory handling functions
*/
#include <asm/segment.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/ext_fs.h>
#include <linux/stat.h>
static int ext_dir_read(struct inode * inode, struct file * filp, char * buf, int count)
{
return -EISDIR;
}
static int ext_readdir(struct inode *, struct file *, void *, filldir_t);
static struct file_operations ext_dir_operations = {
NULL, /* lseek - default */
ext_dir_read, /* read */
NULL, /* write - bad */
ext_readdir, /* readdir */
NULL, /* select - default */
NULL, /* ioctl - default */
NULL, /* mmap */
NULL, /* no special open code */
NULL, /* no special release code */
file_fsync /* fsync */
};
/*
* directories can handle most operations...
*/
struct inode_operations ext_dir_inode_operations = {
&ext_dir_operations, /* default directory file-ops */
ext_create, /* create */
ext_lookup, /* lookup */
ext_link, /* link */
ext_unlink, /* unlink */
ext_symlink, /* symlink */
ext_mkdir, /* mkdir */
ext_rmdir, /* rmdir */
ext_mknod, /* mknod */
ext_rename, /* rename */
NULL, /* readlink */
NULL, /* follow_link */
NULL, /* readpage */
NULL, /* writepage */
NULL, /* bmap */
ext_truncate, /* truncate */
NULL /* permission */
};
static int ext_readdir(struct inode * inode, struct file * filp,
void * dirent, filldir_t filldir)
{
int error;
unsigned int i;
off_t offset;
struct buffer_head * bh;
struct ext_dir_entry * de;
if (!inode || !S_ISDIR(inode->i_mode))
return -EBADF;
if ((filp->f_pos & 7) != 0)
return -EBADF;
error = 0;
while (!error && filp->f_pos < inode->i_size) {
offset = filp->f_pos & 1023;
bh = ext_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
if (!bh) {
filp->f_pos += 1024-offset;
continue;
}
for (i = 0; i < 1024 && i < offset; ) {
de = (struct ext_dir_entry *) (bh->b_data + i);
if (!de->rec_len)
break;
i += de->rec_len;
}
offset = i;
de = (struct ext_dir_entry *) (offset + bh->b_data);
while (offset < 1024 && filp->f_pos < inode->i_size) {
if (de->rec_len < 8 || de->rec_len % 8 != 0 ||
de->rec_len < de->name_len + 8 ||
(de->rec_len + (off_t) filp->f_pos - 1) / 1024 > ((off_t) filp->f_pos / 1024)) {
printk ("ext_readdir: bad dir entry, skipping\n");
printk ("dev=%s, dir=%ld, "
"offset=%ld, rec_len=%d, name_len=%d\n",
kdevname(inode->i_dev), inode->i_ino,
offset, de->rec_len, de->name_len);
filp->f_pos += 1024-offset;
if (filp->f_pos > inode->i_size)
filp->f_pos = inode->i_size;
continue;
}
if (de->inode) {
error = filldir(dirent, de->name, de->name_len, filp->f_pos, de->inode);
if (error)
break;
}
offset += de->rec_len;
filp->f_pos += de->rec_len;
((char *) de) += de->rec_len;
}
brelse(bh);
}
return 0;
}
|