00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00033 #ifndef VFS_VFS_H_
00034 #define VFS_VFS_H_
00035
00036 #include <async.h>
00037 #include <adt/list.h>
00038 #include <fibril_synch.h>
00039 #include <sys/types.h>
00040 #include <devmap.h>
00041 #include <bool.h>
00042 #include <ipc/vfs.h>
00043
00044 #ifndef dprintf
00045 #define dprintf(...)
00046 #endif
00047
00051 typedef struct {
00052 link_t fs_link;
00053 vfs_info_t vfs_info;
00054 fs_handle_t fs_handle;
00055 async_sess_t session;
00056 } fs_info_t;
00057
00061 #define VFS_PAIR \
00062 fs_handle_t fs_handle; \
00063 devmap_handle_t devmap_handle;
00064
00072 #define VFS_TRIPLET \
00073 VFS_PAIR; \
00074 fs_index_t index;
00075
00076 typedef struct {
00077 VFS_PAIR;
00078 } vfs_pair_t;
00079
00080 typedef struct {
00081 VFS_TRIPLET;
00082 } vfs_triplet_t;
00083
00084 typedef enum vfs_node_type {
00085 VFS_NODE_UNKNOWN,
00086 VFS_NODE_FILE,
00087 VFS_NODE_DIRECTORY,
00088 } vfs_node_type_t;
00089
00090 typedef struct {
00091 vfs_triplet_t triplet;
00092 vfs_node_type_t type;
00093 aoff64_t size;
00094 unsigned int lnkcnt;
00095 } vfs_lookup_res_t;
00096
00101 typedef struct {
00102 VFS_TRIPLET;
00108 unsigned refcnt;
00109
00111 unsigned lnkcnt;
00112
00113 link_t nh_link;
00115 vfs_node_type_t type;
00117 aoff64_t size;
00122 fibril_rwlock_t contents_rwlock;
00123 } vfs_node_t;
00124
00129 typedef struct {
00131 fibril_mutex_t lock;
00132
00133 vfs_node_t *node;
00134
00136 unsigned refcnt;
00137
00139 bool append;
00140
00142 aoff64_t pos;
00143 } vfs_file_t;
00144
00145 extern fibril_mutex_t nodes_mutex;
00146
00147 extern fibril_condvar_t fs_head_cv;
00148 extern fibril_mutex_t fs_head_lock;
00149 extern link_t fs_head;
00151 extern vfs_pair_t rootfs;
00154 typedef struct {
00155 link_t plb_link;
00156 unsigned index;
00157 size_t len;
00158 } plb_entry_t;
00159
00160 extern fibril_mutex_t plb_mutex;
00161 extern uint8_t *plb;
00162 extern link_t plb_head;
00164 #define MAX_MNTOPTS_LEN 256
00165
00167 extern fibril_rwlock_t namespace_rwlock;
00168
00169 extern int vfs_grab_phone(fs_handle_t);
00170 extern void vfs_release_phone(fs_handle_t, int);
00171
00172 extern fs_handle_t fs_name_to_handle(char *, bool);
00173 extern vfs_info_t *fs_handle_to_info(fs_handle_t);
00174
00175 extern int vfs_lookup_internal(char *, int, vfs_lookup_res_t *,
00176 vfs_pair_t *, ...);
00177 extern int vfs_open_node_internal(vfs_lookup_res_t *);
00178
00179 extern bool vfs_nodes_init(void);
00180 extern vfs_node_t *vfs_node_get(vfs_lookup_res_t *);
00181 extern void vfs_node_put(vfs_node_t *);
00182 extern void vfs_node_forget(vfs_node_t *);
00183 extern unsigned vfs_nodes_refcount_sum_get(fs_handle_t, devmap_handle_t);
00184
00185
00186 #define MAX_OPEN_FILES 128
00187
00188 extern void *vfs_client_data_create(void);
00189 extern void vfs_client_data_destroy(void *);
00190
00191 extern vfs_file_t *vfs_file_get(int);
00192 extern void vfs_file_put(vfs_file_t *);
00193 extern int vfs_fd_assign(vfs_file_t *, int);
00194 extern int vfs_fd_alloc(bool desc);
00195 extern int vfs_fd_free(int);
00196
00197 extern void vfs_node_addref(vfs_node_t *);
00198 extern void vfs_node_delref(vfs_node_t *);
00199
00200 extern void vfs_register(ipc_callid_t, ipc_call_t *);
00201 extern void vfs_mount(ipc_callid_t, ipc_call_t *);
00202 extern void vfs_unmount(ipc_callid_t, ipc_call_t *);
00203 extern void vfs_open(ipc_callid_t, ipc_call_t *);
00204 extern void vfs_open_node(ipc_callid_t, ipc_call_t *);
00205 extern void vfs_sync(ipc_callid_t, ipc_call_t *);
00206 extern void vfs_dup(ipc_callid_t, ipc_call_t *);
00207 extern void vfs_close(ipc_callid_t, ipc_call_t *);
00208 extern void vfs_read(ipc_callid_t, ipc_call_t *);
00209 extern void vfs_write(ipc_callid_t, ipc_call_t *);
00210 extern void vfs_seek(ipc_callid_t, ipc_call_t *);
00211 extern void vfs_truncate(ipc_callid_t, ipc_call_t *);
00212 extern void vfs_fstat(ipc_callid_t, ipc_call_t *);
00213 extern void vfs_stat(ipc_callid_t, ipc_call_t *);
00214 extern void vfs_mkdir(ipc_callid_t, ipc_call_t *);
00215 extern void vfs_unlink(ipc_callid_t, ipc_call_t *);
00216 extern void vfs_rename(ipc_callid_t, ipc_call_t *);
00217
00218 #endif
00219