openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

vfs-int.h (5855B)


      1 /* $Id: //depot/blt/srv/vfs/vfs-int.h#11 $
      2 **
      3 ** Copyright 1999 Sidney Cammeresi.
      4 ** All rights reserved.
      5 **
      6 ** Redistribution and use in source and binary forms, with or without
      7 ** modification, are permitted provided that the following conditions
      8 ** are met:
      9 ** 1. Redistributions of source code must retain the above copyright
     10 **    notice, this list of conditions, and the following disclaimer.
     11 ** 2. Redistributions in binary form must reproduce the above copyright
     12 **    notice, this list of conditions, and the following disclaimer in the
     13 **    documentation and/or other materials provided with the distribution.
     14 ** 3. The name of the author may not be used to endorse or promote products
     15 **    derived from this software without specific prior written permission.
     16 **
     17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28 
     29 #ifndef _VFS_INT_H_
     30 #define _VFS_INT_H_
     31 
     32 
     33 #include <dirent.h>
     34 #include <sys/stat.h>
     35 
     36 #ifndef VFS_SANDBOX
     37 #include <blt/types.h>
     38 #include <blt/hash.h>
     39 #include <blt/qsem.h>
     40 #include <blt/vfs.h>
     41 #include <blt/syscall.h>
     42 #else
     43 #include "hash.h"
     44 #define MAX_FDS 256
     45 #endif
     46 
     47 struct fs_type
     48 {
     49 	char *name;
     50     struct vnode_ops *t_vops;
     51 	struct fs_type *next;
     52 };
     53 
     54 struct superblock
     55 {
     56 	char *sb_dev, *sb_dir;
     57 	struct vnode *sb_root;
     58 	struct vnode_ops *sb_vops;
     59 	void *sb_data;
     60 	hashtable_t *sb_vnode_cache;
     61 	struct superblock *sb_next;
     62 };
     63 
     64 /*
     65  * This stuff was mercilessly stolen from *Practical File System Design
     66  * With the Be File System* by Dominic Giampaolo.  According to rumours,
     67  * it is a lot like the way BeOS handles stuff internally.
     68  */
     69 
     70 /*
     71  * don't be alarmed by all of the voids; i've just not yet come to the
     72  * semantics of all of these yet.  patience, please.
     73  */
     74 struct vnode_ops
     75 {
     76 	int (*read_vnode) (struct vnode *vnode);
     77 	void (*drop_vnode) (struct vnode *vnode);
     78 	void (*remove_vnode) (void);
     79 	void (*secure_vnode) (void);
     80 	struct vnode *(*walk) (struct vnode *parent, const char *path);
     81 	void (*access) (void);
     82 
     83 	int (*mount) (struct superblock *sb, const char *data, int silent);
     84 	void (*unmount) (struct superblock *sb);
     85 	void (*initialise) (void);
     86 	void (*sync) (void);
     87 	void (*rfstat) (void);
     88 	void (*wfstat) (void);
     89 
     90 	void (*create) (void);
     91 	int (*mkdir) (struct vnode *parent, const char *name, mode_t mode);
     92 	void (*symlink) (void);
     93 	void (*link) (void);
     94 	void (*rename) (void);
     95 	void (*unlink) (void);
     96 	void (*rmdir) (void);
     97 	void (*readlink) (void);
     98 
     99 	int (*opendir) (struct vnode *dir, void **cookie);
    100 	void (*closedir) (struct vnode *dir, void *cookie);
    101 	void (*free_dircookie) (void *cookie);
    102 	int (*rewinddir) (struct vnode *dir, void *cookie);
    103 	int (*readdir) (struct vnode *vnode, struct dirent *dirent, void *cookie);
    104 
    105 	int (*open) (struct vnode *vnode, void **cookie);
    106 	int (*close) (struct vnode *vnode, void *cookie);
    107 	void (*free_cookie) (void *cookie);
    108 	int (*read) (struct vnode *vnode, char *buf, size_t count, off_t offset,
    109 		size_t *res, void *cookie);
    110 	void (*write) (struct vnode *vnode, const char *buf, size_t count,
    111 			void *cookie);
    112 	void (*ioctl) (void);
    113 	void (*setflags) (void);
    114 	int (*rstat) (struct vnode *vnode, struct stat *buf);
    115 	int (*wstat) (struct vnode *vnode, struct stat *buf);
    116 	void (*fsync) (void);
    117 
    118 	void (*open_attrdir) (void);
    119 	void (*close_attrdir) (void);
    120 	void (*free_attrdircookie) (void);
    121 	void (*rewind_attrdir) (void);
    122 	void (*read_attrdir) (void);
    123 	void (*read_attr) (void);
    124 	void (*write_attr) (void);
    125 	void (*remove_attr) (void);
    126 	void (*rename_attr) (void);
    127 	void (*stat_attr) (void);
    128 
    129 	void (*open_indexdir) (void);
    130 	void (*close_indexdir) (void);
    131 	void (*free_indexdircookie) (void);
    132 	void (*rewind_indexdir) (void);
    133 	void (*read_indexdir) (void);
    134 	void (*create_index) (void);
    135 	void (*remove_index) (void);
    136 	void (*rename_index) (void);
    137 	void (*stat_index) (void);
    138 
    139 	void (*open_query) (void);
    140 	void (*close_query) (void);
    141 	void (*free_query_cookie) (void);
    142 	void (*read_query) (void);
    143 };
    144 
    145 struct vnode
    146 {
    147 	unsigned long long v_vnid;
    148 	unsigned int v_refcount;
    149 	struct superblock *v_sb;
    150 	void *v_data;
    151 #ifndef VFS_SANDBOX
    152 	qsem_t *v_lock;
    153 #endif
    154 };
    155 
    156 struct ofile
    157 {
    158 	struct vnode *o_vnode;
    159 	void *o_cookie;
    160 	int area, offset, length, flags;
    161 	int o_pos;
    162 	void *dataptr;
    163 };
    164 
    165 struct fdarray
    166 {
    167 	struct ofile *ofile[MAX_FDS];
    168 };
    169 
    170 struct ioctx
    171 {
    172 	char *cwd;
    173 	struct fdarray fdarray;
    174 };
    175 
    176 struct client
    177 {
    178 	int in, out, filename_area;
    179 	struct ioctx ioctx;
    180 	char *nameptr;
    181 };
    182 
    183 /* functions for use by modules */
    184 int fs_register (struct fs_type *type);
    185 void fs_unregister (struct fs_type *type);
    186 
    187 /* utility functions */
    188 struct superblock *fs_find (const char *name);
    189 struct vnode *vget (struct superblock *super, int num);
    190 void vput (struct vnode *vnode);
    191 
    192 #ifndef VFS_SANDBOX
    193 vfs_res_t *vfs_openconn (int rport, int area);
    194 vfs_res_t *vfs_scroll_area (struct client *client, vfs_cmd_t *vc);
    195 vfs_res_t *vfs_opendir (struct client *client, vfs_cmd_t *vc);
    196 vfs_res_t *vfs_closedir (struct client *client, vfs_cmd_t *vc);
    197 #endif
    198 
    199 struct vfs_dirent_node
    200 {
    201 	struct dirent *dirent;
    202 	struct vfs_dirent_node *next;
    203 };
    204 
    205 extern struct fs_type *fs_drivers;
    206 extern struct superblock *mount_list;
    207 
    208 int vfs_mount (const char *dir, const char *type, int flags, const void *data);
    209 
    210 #endif
    211