[1ffbbc1] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Maurizio Lombardi
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - 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 | * - 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 | /** @addtogroup fs
|
---|
| 30 | * @{
|
---|
[8a49fed] | 31 | */
|
---|
[1ffbbc1] | 32 |
|
---|
| 33 | #ifndef _MFS_H_
|
---|
| 34 | #define _MFS_H_
|
---|
| 35 |
|
---|
[86d0b4b3] | 36 | #include <minix.h>
|
---|
[668f1949] | 37 | #include <macros.h>
|
---|
[953a823] | 38 | #include <libblock.h>
|
---|
[3b08178] | 39 | #include <libfs.h>
|
---|
[953a823] | 40 | #include <adt/list.h>
|
---|
[2874547] | 41 | #include <malloc.h>
|
---|
| 42 | #include <mem.h>
|
---|
| 43 | #include <stdio.h>
|
---|
| 44 | #include <errno.h>
|
---|
| 45 | #include <assert.h>
|
---|
[1ffbbc1] | 46 | #include "../../vfs/vfs.h"
|
---|
| 47 |
|
---|
[ac28650] | 48 | #define NAME "mfs"
|
---|
| 49 |
|
---|
[c955be91] | 50 | //#define DEBUG_MODE
|
---|
[92dd5c8] | 51 |
|
---|
[bd64680] | 52 | #define min(a, b) ((a) < (b) ? (a) : (b))
|
---|
| 53 |
|
---|
[92dd5c8] | 54 | #ifdef DEBUG_MODE
|
---|
| 55 | #define mfsdebug(...) printf(__VA_ARGS__)
|
---|
| 56 | #else
|
---|
| 57 | #define mfsdebug(...)
|
---|
| 58 | #endif
|
---|
| 59 |
|
---|
[3b08178] | 60 | #ifdef _MAIN
|
---|
| 61 | #define GLOBAL
|
---|
| 62 | #else
|
---|
| 63 | #define GLOBAL extern
|
---|
| 64 | #endif
|
---|
| 65 |
|
---|
[adddd75] | 66 | #define on_error(r, inst) do { \
|
---|
| 67 | if (r != EOK) inst; \
|
---|
| 68 | }while(0)
|
---|
| 69 |
|
---|
[3b08178] | 70 | GLOBAL fs_reg_t mfs_reg;
|
---|
| 71 |
|
---|
[152610a8] | 72 | typedef uint32_t bitchunk_t;
|
---|
| 73 |
|
---|
[fde8a276] | 74 | typedef enum {
|
---|
| 75 | BMAP_ZONE,
|
---|
| 76 | BMAP_INODE
|
---|
| 77 | } bmap_id_t;
|
---|
| 78 |
|
---|
[82650385] | 79 | typedef enum {
|
---|
| 80 | MFS_VERSION_V1 = 1,
|
---|
| 81 | MFS_VERSION_V2,
|
---|
| 82 | MFS_VERSION_V3
|
---|
| 83 | } mfs_version_t;
|
---|
| 84 |
|
---|
[953a823] | 85 | /*Generic MinixFS superblock*/
|
---|
| 86 | struct mfs_sb_info {
|
---|
| 87 | uint32_t ninodes;
|
---|
| 88 | uint32_t nzones;
|
---|
| 89 | unsigned long ibmap_blocks;
|
---|
| 90 | unsigned long zbmap_blocks;
|
---|
| 91 | unsigned long firstdatazone;
|
---|
| 92 | int log2_zone_size;
|
---|
| 93 | int block_size;
|
---|
| 94 | uint32_t max_file_size;
|
---|
| 95 | uint16_t magic;
|
---|
| 96 | uint16_t state;
|
---|
[7a96476] | 97 |
|
---|
| 98 | /*The following fields do not exist on disk but only in memory*/
|
---|
| 99 | unsigned long itable_size;
|
---|
| 100 | mfs_version_t fs_version;
|
---|
| 101 | int ino_per_block;
|
---|
[07dcec5] | 102 | size_t dirsize;
|
---|
[10eb754] | 103 | int itable_off;
|
---|
[bd64680] | 104 | unsigned max_name_len;
|
---|
[953a823] | 105 | bool long_names;
|
---|
| 106 | bool native;
|
---|
[ef76d72] | 107 | unsigned isearch;
|
---|
| 108 | unsigned zsearch;
|
---|
[953a823] | 109 | };
|
---|
| 110 |
|
---|
[155f792] | 111 | /*Generic MinixFS inode*/
|
---|
| 112 | struct mfs_ino_info {
|
---|
[8a49fed] | 113 | uint16_t i_mode;
|
---|
| 114 | uint16_t i_nlinks;
|
---|
| 115 | int16_t i_uid;
|
---|
| 116 | uint16_t i_gid;
|
---|
| 117 | size_t i_size;
|
---|
| 118 | int32_t i_atime;
|
---|
| 119 | int32_t i_mtime;
|
---|
| 120 | int32_t i_ctime;
|
---|
| 121 | /*Block numbers for direct zones*/
|
---|
| 122 | uint32_t i_dzone[V2_NR_DIRECT_ZONES];
|
---|
| 123 | /*Block numbers for indirect zones*/
|
---|
| 124 | uint32_t i_izone[V2_NR_INDIRECT_ZONES];
|
---|
[54caa41b] | 125 |
|
---|
[7a96476] | 126 | /*The following fields do not exist on disk but only in memory*/
|
---|
[54caa41b] | 127 | bool dirty;
|
---|
[41202a9] | 128 | fs_index_t index;
|
---|
[54caa41b] | 129 | };
|
---|
| 130 |
|
---|
| 131 | /*Generic MFS directory entry*/
|
---|
| 132 | struct mfs_dentry_info {
|
---|
| 133 | uint32_t d_inum;
|
---|
[07dcec5] | 134 | char d_name[MFS3_MAX_NAME_LEN + 1];
|
---|
[54caa41b] | 135 |
|
---|
[7a96476] | 136 | /*The following fields do not exist on disk but only in memory*/
|
---|
[c4eeb2f] | 137 |
|
---|
| 138 | /*Index of the dentry in the list*/
|
---|
[87d4422] | 139 | unsigned index;
|
---|
| 140 | /*Pointer to the node at witch the dentry belongs*/
|
---|
| 141 | struct mfs_node *node;
|
---|
[155f792] | 142 | };
|
---|
| 143 |
|
---|
[953a823] | 144 | struct mfs_instance {
|
---|
| 145 | link_t link;
|
---|
| 146 | devmap_handle_t handle;
|
---|
| 147 | struct mfs_sb_info *sbi;
|
---|
[ee257b2] | 148 | unsigned open_nodes_cnt;
|
---|
[953a823] | 149 | };
|
---|
| 150 |
|
---|
[e54ba607] | 151 | /*MinixFS node in core*/
|
---|
| 152 | struct mfs_node {
|
---|
[155f792] | 153 | struct mfs_ino_info *ino_i;
|
---|
[e54ba607] | 154 | struct mfs_instance *instance;
|
---|
[ee257b2] | 155 | unsigned refcnt;
|
---|
| 156 | fs_node_t *fsnode;
|
---|
| 157 | link_t link;
|
---|
[e54ba607] | 158 | };
|
---|
| 159 |
|
---|
[f213ae7] | 160 | /*mfs_ops.c*/
|
---|
[1ffbbc1] | 161 | extern void mfs_mounted(ipc_callid_t rid, ipc_call_t *request);
|
---|
[3b08178] | 162 | extern void mfs_mount(ipc_callid_t rid, ipc_call_t *request);
|
---|
[54caa41b] | 163 | extern void mfs_lookup(ipc_callid_t rid, ipc_call_t *request);
|
---|
[44c0f5b] | 164 | extern int mfs_instance_get(devmap_handle_t handle,
|
---|
[8a49fed] | 165 | struct mfs_instance **instance);
|
---|
[1ffbbc1] | 166 |
|
---|
[0d6ab10] | 167 | extern void mfs_stat(ipc_callid_t rid, ipc_call_t *request);
|
---|
[e700970] | 168 | extern void mfs_close(ipc_callid_t rid, ipc_call_t *request);
|
---|
| 169 | extern void mfs_open_node(ipc_callid_t rid, ipc_call_t *request);
|
---|
[0d6ab10] | 170 |
|
---|
[668f1949] | 171 | extern void
|
---|
| 172 | mfs_read(ipc_callid_t rid, ipc_call_t *request);
|
---|
| 173 |
|
---|
[bb7e8382] | 174 | extern void
|
---|
| 175 | mfs_write(ipc_callid_t rid, ipc_call_t *request);
|
---|
[668f1949] | 176 |
|
---|
[8a49fed] | 177 | extern void
|
---|
| 178 | mfs_truncate(ipc_callid_t rid, ipc_call_t *request);
|
---|
| 179 |
|
---|
[d8af1bd] | 180 | extern void
|
---|
| 181 | mfs_destroy(ipc_callid_t rid, ipc_call_t *request);
|
---|
| 182 |
|
---|
[51db5aeb] | 183 | extern void
|
---|
| 184 | mfs_unmounted(ipc_callid_t rid, ipc_call_t *request);
|
---|
| 185 |
|
---|
| 186 | extern void
|
---|
| 187 | mfs_unmount(ipc_callid_t rid, ipc_call_t *request);
|
---|
| 188 |
|
---|
| 189 | extern void
|
---|
| 190 | mfs_sync(ipc_callid_t rid, ipc_call_t *request);
|
---|
| 191 |
|
---|
[ee257b2] | 192 | extern int
|
---|
| 193 | mfs_global_init(void);
|
---|
| 194 |
|
---|
[f213ae7] | 195 | /*mfs_inode.c*/
|
---|
[8a49fed] | 196 | extern int
|
---|
[c922bc7] | 197 | get_inode(struct mfs_instance *inst, struct mfs_ino_info **ino_i,
|
---|
[8a49fed] | 198 | fs_index_t index);
|
---|
[f213ae7] | 199 |
|
---|
[10eb754] | 200 | extern int
|
---|
| 201 | put_inode(struct mfs_node *mnode);
|
---|
| 202 |
|
---|
[8a49fed] | 203 | extern int
|
---|
| 204 | inode_shrink(struct mfs_node *mnode, size_t size_shrink);
|
---|
| 205 |
|
---|
[2bbbfd3] | 206 | /*mfs_rw.c*/
|
---|
| 207 | extern int
|
---|
| 208 | read_map(uint32_t *b, const struct mfs_node *mnode, const uint32_t pos);
|
---|
| 209 |
|
---|
| 210 | extern int
|
---|
| 211 | write_map(struct mfs_node *mnode, uint32_t pos, uint32_t new_zone,
|
---|
[8a49fed] | 212 | uint32_t *old_zone);
|
---|
[2bbbfd3] | 213 |
|
---|
[1878386] | 214 | extern int
|
---|
| 215 | prune_ind_zones(struct mfs_node *mnode, size_t new_size);
|
---|
| 216 |
|
---|
[54caa41b] | 217 | /*mfs_dentry.c*/
|
---|
[488f7ed] | 218 | extern int
|
---|
[18eb736] | 219 | read_dentry(struct mfs_node *mnode,
|
---|
[e80c2ff] | 220 | struct mfs_dentry_info *d_info, unsigned index);
|
---|
[54caa41b] | 221 |
|
---|
[87d4422] | 222 | extern int
|
---|
| 223 | write_dentry(struct mfs_dentry_info *d_info);
|
---|
| 224 |
|
---|
[c955be91] | 225 | extern int
|
---|
| 226 | remove_dentry(struct mfs_node *mnode, const char *d_name);
|
---|
| 227 |
|
---|
[8a49fed] | 228 | extern int
|
---|
[13ab195] | 229 | insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum);
|
---|
[07dcec5] | 230 |
|
---|
[ba5beaf] | 231 | /*mfs_balloc.c*/
|
---|
| 232 | extern int
|
---|
[70ac0af] | 233 | mfs_alloc_inode(struct mfs_instance *inst, uint32_t *inum);
|
---|
[2cf95e8] | 234 |
|
---|
| 235 | extern int
|
---|
[70ac0af] | 236 | mfs_free_inode(struct mfs_instance *inst, uint32_t inum);
|
---|
| 237 |
|
---|
| 238 | extern int
|
---|
| 239 | mfs_alloc_zone(struct mfs_instance *inst, uint32_t *zone);
|
---|
| 240 |
|
---|
| 241 | extern int
|
---|
| 242 | mfs_free_zone(struct mfs_instance *inst, uint32_t zone);
|
---|
[ba5beaf] | 243 |
|
---|
[88be951e] | 244 | /*mfs_utils.c*/
|
---|
| 245 | extern uint16_t
|
---|
| 246 | conv16(bool native, uint16_t n);
|
---|
| 247 |
|
---|
| 248 | extern uint32_t
|
---|
| 249 | conv32(bool native, uint32_t n);
|
---|
| 250 |
|
---|
| 251 | extern uint64_t
|
---|
| 252 | conv64(bool native, uint64_t n);
|
---|
| 253 |
|
---|
[1ffbbc1] | 254 | #endif
|
---|
| 255 |
|
---|
| 256 | /**
|
---|
| 257 | * @}
|
---|
[8a49fed] | 258 | */
|
---|
[1ffbbc1] | 259 |
|
---|