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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [mm0/] [include/] [fs.h] - Blame information for rev 7

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

Line No. Rev Author Line
1 2 drasko
/*
2
 * VFS definitions.
3
 *
4
 * Copyright (C) 2007, 2008 Bahadir Balban.
5
 */
6
#ifndef __FS_H__
7
#define __FS_H__
8
 
9
#include <l4/lib/list.h>
10
#include <l4/macros.h>
11
#include <l4lib/types.h>
12
#include <stat.h>
13
#include <path.h>
14
 
15
typedef void (*vnode_op_t)(void);
16
typedef void (*file_op_t)(void);
17
 
18
struct dentry;
19
struct file;
20
struct file_system_type;
21
struct superblock;
22
struct vnode;
23
 
24
struct dentry_ops {
25
        int (*compare)(struct dentry *d, const char *n);
26
};
27
 
28
/* Operations that work on file content */
29
struct file_ops {
30
 
31
        /* Read a vnode's contents by page range */
32
        int (*read)(struct vnode *v, unsigned long pfn,
33
                    unsigned long npages, void *buf);
34
 
35
        /* Write a vnode's contents by page range */
36
        int (*write)(struct vnode *v, unsigned long pfn,
37
                    unsigned long npages, void *buf);
38
        file_op_t open;
39
        file_op_t close;
40
        file_op_t mmap;
41
        file_op_t lseek;
42
        file_op_t flush;
43
        file_op_t fsync;
44
};
45
 
46
/* Operations that work on vnode fields and associations between vnodes */
47
struct vnode_ops {
48
        vnode_op_t create;
49
        struct vnode *(*lookup)(struct vnode *root, struct pathdata *pdata,
50
                                const char *component);
51
        int (*readdir)(struct vnode *v);
52
        int (*filldir)(void *buf, struct vnode *v, int count);
53
        vnode_op_t link;
54
        vnode_op_t unlink;
55
        int (*mkdir)(struct vnode *parent, const char *name);
56
        struct vnode *(*mknod)(struct vnode *parent, const char *name,
57
                               unsigned int mode);
58
        vnode_op_t rmdir;
59
        vnode_op_t rename;
60
        vnode_op_t getattr;
61
        vnode_op_t setattr;
62
};
63
 
64
struct superblock_ops {
65
        int (*write_sb)(struct superblock *sb);
66
 
67
        /*
68
         * Given a vnum, reads the disk-inode and copies its data
69
         * into the vnode's generic fields
70
         */
71
        int (*read_vnode)(struct superblock *sb, struct vnode *v);
72
 
73
        /* Writes vnode's generic fields into the disk-inode structure */
74
        int (*write_vnode)(struct superblock *sb, struct vnode *v);
75
 
76
        /* Allocates a disk-inode along with a vnode, and associates the two */
77
        struct vnode *(*alloc_vnode)(struct superblock *sb);
78
 
79
        /* Frees the vnode and the corresponding on-disk inode */
80
        int (*free_vnode)(struct superblock *sb, struct vnode *v);
81
};
82
 
83
#define VFS_DNAME_MAX                   256
84
struct dentry {
85
        int refcnt;
86
        char name[VFS_DNAME_MAX];
87
        struct dentry *parent;          /* Parent dentry */
88
        struct link child;              /* List of dentries with same parent */
89
        struct link children;   /* List of children dentries */
90
        struct link vref;               /* For vnode's dirent reference list */
91
        struct link cache_list; /* Dentry cache reference */
92
        struct vnode *vnode;            /* The vnode associated with dentry */
93
        struct dentry_ops ops;
94
};
95
 
96
/*
97
 * Buffer that maintains directory content for a directory vnode. This is the
98
 * only vnode content that fs0 maintains. All other file data is in mm0 page
99
 * cache.
100
 */
101
struct dirbuf {
102
        unsigned long npages;
103
        int dirty;
104
        u8 *buffer;
105
};
106
 
107
/* Posix-style dirent format used by userspace. Returned by sys_readdir() */
108
#define DIRENT_NAME_MAX                 256
109
struct dirent {
110
        u32 inum;                       /* Inode number */
111
        u32 offset;                     /* Dentry offset in its buffer */
112
        u16 rlength;                    /* Record length */
113
        u8 type;                        /* Dir type */
114
        u8  name[DIRENT_NAME_MAX];      /* Name string */
115
} __attribute__((__packed__));
116
 
117
struct vnode {
118
        unsigned long vnum;             /* Filesystem-wide unique vnode id */
119
        int refcnt;                     /* Reference counter */
120
        int links;                      /* Number of hard links */
121
        struct superblock *sb;          /* Reference to superblock */
122
        struct vnode_ops ops;           /* Operations on this vnode */
123
        struct file_ops fops;           /* File-related operations on this vnode */
124
        struct link dentries;   /* Dirents that refer to this vnode */
125
        struct link cache_list; /* For adding the vnode to vnode cache */
126
        struct dirbuf dirbuf;           /* Only directory buffers are kept */
127
        u32 mode;                       /* Permissions and vnode type */
128
        u32 owner;                      /* Owner */
129
        u64 atime;                      /* Last access time */
130
        u64 mtime;                      /* Last content modification */
131
        u64 ctime;                      /* Last vnode modification */
132
        u64 size;                       /* Size of contents */
133
        void *inode;                    /* Ptr to fs-specific inode */
134
};
135
 
136
/* FS0 vfs specific macros */
137
 
138
/* Check if directory */
139
#define vfs_isdir(v)            S_ISDIR((v)->mode)
140
 
141
/* Set vnode type */
142
#define vfs_set_type(v, type)   {v->mode &= ~S_IFMT; v->mode |= S_IFMT & type; }
143
 
144
struct fstype_ops {
145
        struct superblock *(*get_superblock)(void *buf);
146
};
147
 
148
#define VFS_FSNAME_MAX                  256
149
struct file_system_type {
150
        char name[VFS_FSNAME_MAX];
151
        unsigned long magic;
152
        struct fstype_ops ops;
153
        struct link list;       /* Member of list of all fs types */
154
        struct link sblist; /* List of superblocks with this type */
155
};
156
struct superblock *get_superblock(void *buf);
157
 
158
struct superblock {
159
        u64 fssize;
160
        int fsidx;
161
        unsigned int blocksize;
162
        struct link list;
163
        struct file_system_type *fs;
164
        struct superblock_ops *ops;
165
        struct vnode *root;
166
        void *fs_super;
167
};
168
 
169
void vfs_mount_fs(struct superblock *sb);
170
 
171
extern struct dentry_ops generic_dentry_operations;
172
 
173
#endif /* __FS_H__ */

powered by: WebSVN 2.1.0

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