OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [ext/] [dir.c] - Blame information for rev 1628

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1628 jcastillo
/*
2
 *  linux/fs/ext/dir.c
3
 *
4
 *  Copyright (C) 1992 Remy Card (card@masi.ibp.fr)
5
 *
6
 *  from
7
 *
8
 *  linux/fs/minix/dir.c
9
 *
10
 *  Copyright (C) 1991, 1992 Linus Torvalds
11
 *
12
 *  ext directory handling functions
13
 */
14
 
15
#include <asm/segment.h>
16
 
17
#include <linux/errno.h>
18
#include <linux/kernel.h>
19
#include <linux/fs.h>
20
#include <linux/ext_fs.h>
21
#include <linux/stat.h>
22
 
23
static int ext_dir_read(struct inode * inode, struct file * filp, char * buf, int count)
24
{
25
        return -EISDIR;
26
}
27
 
28
static int ext_readdir(struct inode *, struct file *, void *, filldir_t);
29
 
30
static struct file_operations ext_dir_operations = {
31
        NULL,                   /* lseek - default */
32
        ext_dir_read,           /* read */
33
        NULL,                   /* write - bad */
34
        ext_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              /* fsync */
41
};
42
 
43
/*
44
 * directories can handle most operations...
45
 */
46
struct inode_operations ext_dir_inode_operations = {
47
        &ext_dir_operations,    /* default directory file-ops */
48
        ext_create,             /* create */
49
        ext_lookup,             /* lookup */
50
        ext_link,               /* link */
51
        ext_unlink,             /* unlink */
52
        ext_symlink,            /* symlink */
53
        ext_mkdir,              /* mkdir */
54
        ext_rmdir,              /* rmdir */
55
        ext_mknod,              /* mknod */
56
        ext_rename,             /* rename */
57
        NULL,                   /* readlink */
58
        NULL,                   /* follow_link */
59
        NULL,                   /* readpage */
60
        NULL,                   /* writepage */
61
        NULL,                   /* bmap */
62
        ext_truncate,           /* truncate */
63
        NULL                    /* permission */
64
};
65
 
66
static int ext_readdir(struct inode * inode, struct file * filp,
67
        void * dirent, filldir_t filldir)
68
{
69
        int error;
70
        unsigned int i;
71
        off_t offset;
72
        struct buffer_head * bh;
73
        struct ext_dir_entry * de;
74
 
75
        if (!inode || !S_ISDIR(inode->i_mode))
76
                return -EBADF;
77
        if ((filp->f_pos & 7) != 0)
78
                return -EBADF;
79
        error = 0;
80
        while (!error && filp->f_pos < inode->i_size) {
81
                offset = filp->f_pos & 1023;
82
                bh = ext_bread(inode,(filp->f_pos)>>BLOCK_SIZE_BITS,0);
83
                if (!bh) {
84
                        filp->f_pos += 1024-offset;
85
                        continue;
86
                }
87
                for (i = 0; i < 1024 && i < offset; ) {
88
                        de = (struct ext_dir_entry *) (bh->b_data + i);
89
                        if (!de->rec_len)
90
                                break;
91
                        i += de->rec_len;
92
                }
93
                offset = i;
94
                de = (struct ext_dir_entry *) (offset + bh->b_data);
95
                while (offset < 1024 && filp->f_pos < inode->i_size) {
96
                        if (de->rec_len < 8 || de->rec_len % 8 != 0 ||
97
                            de->rec_len < de->name_len + 8 ||
98
                            (de->rec_len + (off_t) filp->f_pos - 1) / 1024 > ((off_t) filp->f_pos / 1024)) {
99
                                printk ("ext_readdir: bad dir entry, skipping\n");
100
                                printk ("dev=%s, dir=%ld, "
101
                                    "offset=%ld, rec_len=%d, name_len=%d\n",
102
                                    kdevname(inode->i_dev), inode->i_ino,
103
                                    offset, de->rec_len, de->name_len);
104
                                filp->f_pos += 1024-offset;
105
                                if (filp->f_pos > inode->i_size)
106
                                        filp->f_pos = inode->i_size;
107
                                continue;
108
                        }
109
                        if (de->inode) {
110
                                error = filldir(dirent, de->name, de->name_len, filp->f_pos, de->inode);
111
                                if (error)
112
                                        break;
113
                        }
114
                        offset += de->rec_len;
115
                        filp->f_pos += de->rec_len;
116
                        ((char *) de) += de->rec_len;
117
                }
118
                brelse(bh);
119
        }
120
        return 0;
121
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.