| [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 | * @{
|
|---|
| 31 | */
|
|---|
| 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>
|
|---|
| [1ffbbc1] | 41 | #include "../../vfs/vfs.h"
|
|---|
| 42 |
|
|---|
| [ac28650] | 43 | #define NAME "mfs"
|
|---|
| 44 |
|
|---|
| [92dd5c8] | 45 | #define DEBUG_MODE
|
|---|
| 46 |
|
|---|
| [bd64680] | 47 | #define min(a, b) ((a) < (b) ? (a) : (b))
|
|---|
| 48 |
|
|---|
| [92dd5c8] | 49 | #ifdef DEBUG_MODE
|
|---|
| 50 | #define mfsdebug(...) printf(__VA_ARGS__)
|
|---|
| 51 | #else
|
|---|
| 52 | #define mfsdebug(...)
|
|---|
| 53 | #endif
|
|---|
| 54 |
|
|---|
| [3b08178] | 55 | #ifdef _MAIN
|
|---|
| 56 | #define GLOBAL
|
|---|
| 57 | #else
|
|---|
| 58 | #define GLOBAL extern
|
|---|
| 59 | #endif
|
|---|
| 60 |
|
|---|
| 61 | GLOBAL fs_reg_t mfs_reg;
|
|---|
| 62 |
|
|---|
| [152610a8] | 63 | typedef uint32_t bitchunk_t;
|
|---|
| 64 |
|
|---|
| [fde8a276] | 65 | typedef enum {
|
|---|
| 66 | BMAP_ZONE,
|
|---|
| 67 | BMAP_INODE
|
|---|
| 68 | } bmap_id_t;
|
|---|
| 69 |
|
|---|
| [82650385] | 70 | typedef enum {
|
|---|
| 71 | MFS_VERSION_V1 = 1,
|
|---|
| 72 | MFS_VERSION_V2,
|
|---|
| 73 | MFS_VERSION_V3
|
|---|
| 74 | } mfs_version_t;
|
|---|
| 75 |
|
|---|
| [953a823] | 76 | /*Generic MinixFS superblock*/
|
|---|
| 77 | struct mfs_sb_info {
|
|---|
| 78 | uint32_t ninodes;
|
|---|
| 79 | uint32_t nzones;
|
|---|
| 80 | unsigned long ibmap_blocks;
|
|---|
| 81 | unsigned long zbmap_blocks;
|
|---|
| 82 | unsigned long firstdatazone;
|
|---|
| 83 | int log2_zone_size;
|
|---|
| 84 | int block_size;
|
|---|
| 85 | uint32_t max_file_size;
|
|---|
| 86 | uint16_t magic;
|
|---|
| 87 | uint16_t state;
|
|---|
| [7a96476] | 88 |
|
|---|
| 89 | /*The following fields do not exist on disk but only in memory*/
|
|---|
| 90 | unsigned long itable_size;
|
|---|
| 91 | mfs_version_t fs_version;
|
|---|
| 92 | int ino_per_block;
|
|---|
| [07dcec5] | 93 | size_t dirsize;
|
|---|
| [10eb754] | 94 | int itable_off;
|
|---|
| [bd64680] | 95 | unsigned max_name_len;
|
|---|
| [953a823] | 96 | bool long_names;
|
|---|
| 97 | bool native;
|
|---|
| [ef76d72] | 98 | unsigned isearch;
|
|---|
| 99 | unsigned zsearch;
|
|---|
| [953a823] | 100 | };
|
|---|
| 101 |
|
|---|
| [155f792] | 102 | /*Generic MinixFS inode*/
|
|---|
| 103 | struct mfs_ino_info {
|
|---|
| 104 | uint16_t i_mode;
|
|---|
| 105 | uint16_t i_nlinks;
|
|---|
| 106 | int16_t i_uid;
|
|---|
| 107 | uint16_t i_gid;
|
|---|
| [ce45f19] | 108 | size_t i_size;
|
|---|
| [155f792] | 109 | int32_t i_atime;
|
|---|
| 110 | int32_t i_mtime;
|
|---|
| 111 | int32_t i_ctime;
|
|---|
| 112 | /*Block numbers for direct zones*/
|
|---|
| 113 | uint32_t i_dzone[V2_NR_DIRECT_ZONES];
|
|---|
| 114 | /*Block numbers for indirect zones*/
|
|---|
| 115 | uint32_t i_izone[V2_NR_INDIRECT_ZONES];
|
|---|
| [54caa41b] | 116 |
|
|---|
| [7a96476] | 117 | /*The following fields do not exist on disk but only in memory*/
|
|---|
| [54caa41b] | 118 | bool dirty;
|
|---|
| [41202a9] | 119 | fs_index_t index;
|
|---|
| [54caa41b] | 120 | };
|
|---|
| 121 |
|
|---|
| 122 | /*Generic MFS directory entry*/
|
|---|
| 123 | struct mfs_dentry_info {
|
|---|
| 124 | uint32_t d_inum;
|
|---|
| [07dcec5] | 125 | char d_name[MFS3_MAX_NAME_LEN + 1];
|
|---|
| [54caa41b] | 126 |
|
|---|
| [7a96476] | 127 | /*The following fields do not exist on disk but only in memory*/
|
|---|
| [c4eeb2f] | 128 |
|
|---|
| 129 | /*Index of the dentry in the list*/
|
|---|
| [87d4422] | 130 | unsigned index;
|
|---|
| 131 | /*Pointer to the node at witch the dentry belongs*/
|
|---|
| 132 | struct mfs_node *node;
|
|---|
| [155f792] | 133 | };
|
|---|
| 134 |
|
|---|
| [953a823] | 135 | struct mfs_instance {
|
|---|
| 136 | link_t link;
|
|---|
| 137 | devmap_handle_t handle;
|
|---|
| 138 | struct mfs_sb_info *sbi;
|
|---|
| 139 | };
|
|---|
| 140 |
|
|---|
| [e54ba607] | 141 | /*MinixFS node in core*/
|
|---|
| 142 | struct mfs_node {
|
|---|
| [155f792] | 143 | struct mfs_ino_info *ino_i;
|
|---|
| [e54ba607] | 144 | struct mfs_instance *instance;
|
|---|
| 145 | };
|
|---|
| 146 |
|
|---|
| [f213ae7] | 147 | /*mfs_ops.c*/
|
|---|
| [1ffbbc1] | 148 | extern void mfs_mounted(ipc_callid_t rid, ipc_call_t *request);
|
|---|
| [3b08178] | 149 | extern void mfs_mount(ipc_callid_t rid, ipc_call_t *request);
|
|---|
| [54caa41b] | 150 | extern void mfs_lookup(ipc_callid_t rid, ipc_call_t *request);
|
|---|
| [44c0f5b] | 151 | extern int mfs_instance_get(devmap_handle_t handle,
|
|---|
| [3b08178] | 152 | struct mfs_instance **instance);
|
|---|
| [1ffbbc1] | 153 |
|
|---|
| [0d6ab10] | 154 | extern void mfs_stat(ipc_callid_t rid, ipc_call_t *request);
|
|---|
| 155 |
|
|---|
| [668f1949] | 156 | extern void
|
|---|
| 157 | mfs_read(ipc_callid_t rid, ipc_call_t *request);
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| [f213ae7] | 160 | /*mfs_inode.c*/
|
|---|
| [c922bc7] | 161 | int
|
|---|
| 162 | get_inode(struct mfs_instance *inst, struct mfs_ino_info **ino_i,
|
|---|
| 163 | fs_index_t index);
|
|---|
| [f213ae7] | 164 |
|
|---|
| [10eb754] | 165 | extern int
|
|---|
| 166 | put_inode(struct mfs_node *mnode);
|
|---|
| 167 |
|
|---|
| [7bd68e6] | 168 | int
|
|---|
| [f9329cf] | 169 | inode_grow(struct mfs_node *mnode, size_t size_grow);
|
|---|
| [7bd68e6] | 170 |
|
|---|
| [2bbbfd3] | 171 | /*mfs_rw.c*/
|
|---|
| 172 | extern int
|
|---|
| 173 | read_map(uint32_t *b, const struct mfs_node *mnode, const uint32_t pos);
|
|---|
| 174 |
|
|---|
| 175 | extern int
|
|---|
| 176 | write_map(struct mfs_node *mnode, uint32_t pos, uint32_t new_zone,
|
|---|
| 177 | uint32_t *old_zone);
|
|---|
| 178 |
|
|---|
| 179 | extern int
|
|---|
| 180 | free_zone(struct mfs_node *mnode, const uint32_t zone);
|
|---|
| [df22c36] | 181 |
|
|---|
| [54caa41b] | 182 | /*mfs_dentry.c*/
|
|---|
| 183 | extern struct mfs_dentry_info *
|
|---|
| 184 | read_directory_entry(struct mfs_node *mnode, unsigned index);
|
|---|
| 185 |
|
|---|
| [87d4422] | 186 | extern int
|
|---|
| 187 | write_dentry(struct mfs_dentry_info *d_info);
|
|---|
| 188 |
|
|---|
| [07dcec5] | 189 | int
|
|---|
| [13ab195] | 190 | insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum);
|
|---|
| [07dcec5] | 191 |
|
|---|
| [ba5beaf] | 192 | /*mfs_balloc.c*/
|
|---|
| 193 | extern int
|
|---|
| [2cf95e8] | 194 | mfs_alloc_bit(struct mfs_instance *inst, uint32_t *idx, bmap_id_t bid);
|
|---|
| 195 |
|
|---|
| 196 | extern int
|
|---|
| 197 | mfs_free_bit(struct mfs_instance *inst, uint32_t idx, bmap_id_t bid);
|
|---|
| [ba5beaf] | 198 |
|
|---|
| [1ffbbc1] | 199 | #endif
|
|---|
| 200 |
|
|---|
| 201 | /**
|
|---|
| 202 | * @}
|
|---|
| 203 | */
|
|---|
| 204 |
|
|---|