[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>
|
---|
[953a823] | 37 | #include <libblock.h>
|
---|
[3b08178] | 38 | #include <libfs.h>
|
---|
[953a823] | 39 | #include <adt/list.h>
|
---|
[1ffbbc1] | 40 | #include "../../vfs/vfs.h"
|
---|
| 41 |
|
---|
[ac28650] | 42 | #define NAME "mfs"
|
---|
| 43 |
|
---|
[92dd5c8] | 44 | #define DEBUG_MODE
|
---|
| 45 |
|
---|
| 46 | #ifdef DEBUG_MODE
|
---|
| 47 | #define mfsdebug(...) printf(__VA_ARGS__)
|
---|
| 48 | #else
|
---|
| 49 | #define mfsdebug(...)
|
---|
| 50 | #endif
|
---|
| 51 |
|
---|
[3b08178] | 52 | #ifdef _MAIN
|
---|
| 53 | #define GLOBAL
|
---|
| 54 | #else
|
---|
| 55 | #define GLOBAL extern
|
---|
| 56 | #endif
|
---|
| 57 |
|
---|
| 58 | GLOBAL fs_reg_t mfs_reg;
|
---|
| 59 |
|
---|
[fde8a276] | 60 | typedef enum {
|
---|
| 61 | BMAP_ZONE,
|
---|
| 62 | BMAP_INODE
|
---|
| 63 | } bmap_id_t;
|
---|
| 64 |
|
---|
[82650385] | 65 | typedef enum {
|
---|
| 66 | MFS_VERSION_V1 = 1,
|
---|
| 67 | MFS_VERSION_V2,
|
---|
| 68 | MFS_VERSION_V3
|
---|
| 69 | } mfs_version_t;
|
---|
| 70 |
|
---|
[953a823] | 71 | /*Generic MinixFS superblock*/
|
---|
| 72 | struct mfs_sb_info {
|
---|
| 73 | uint32_t ninodes;
|
---|
| 74 | uint32_t nzones;
|
---|
| 75 | unsigned long ibmap_blocks;
|
---|
| 76 | unsigned long zbmap_blocks;
|
---|
| 77 | unsigned long firstdatazone;
|
---|
| 78 | int log2_zone_size;
|
---|
| 79 | int block_size;
|
---|
| 80 | uint32_t max_file_size;
|
---|
| 81 | uint16_t magic;
|
---|
| 82 | uint16_t state;
|
---|
[7a96476] | 83 |
|
---|
| 84 | /*The following fields do not exist on disk but only in memory*/
|
---|
| 85 | unsigned long itable_size;
|
---|
| 86 | mfs_version_t fs_version;
|
---|
| 87 | int ino_per_block;
|
---|
| 88 | int dirsize;
|
---|
[953a823] | 89 | bool long_names;
|
---|
| 90 | bool native;
|
---|
[ef76d72] | 91 | unsigned isearch;
|
---|
| 92 | unsigned zsearch;
|
---|
[953a823] | 93 | };
|
---|
| 94 |
|
---|
[155f792] | 95 | /*Generic MinixFS inode*/
|
---|
| 96 | struct mfs_ino_info {
|
---|
| 97 | uint16_t i_mode;
|
---|
| 98 | uint16_t i_nlinks;
|
---|
| 99 | int16_t i_uid;
|
---|
| 100 | uint16_t i_gid;
|
---|
| 101 | int32_t i_size;
|
---|
| 102 | int32_t i_atime;
|
---|
| 103 | int32_t i_mtime;
|
---|
| 104 | int32_t i_ctime;
|
---|
| 105 | /*Block numbers for direct zones*/
|
---|
| 106 | uint32_t i_dzone[V2_NR_DIRECT_ZONES];
|
---|
| 107 | /*Block numbers for indirect zones*/
|
---|
| 108 | uint32_t i_izone[V2_NR_INDIRECT_ZONES];
|
---|
[54caa41b] | 109 |
|
---|
[7a96476] | 110 | /*The following fields do not exist on disk but only in memory*/
|
---|
[54caa41b] | 111 | bool dirty;
|
---|
[41202a9] | 112 | fs_index_t index;
|
---|
[54caa41b] | 113 | };
|
---|
| 114 |
|
---|
| 115 | /*Generic MFS directory entry*/
|
---|
| 116 | struct mfs_dentry_info {
|
---|
| 117 | uint32_t d_inum;
|
---|
| 118 | char d_name[MFS3_MAX_NAME_LEN];
|
---|
| 119 |
|
---|
[7a96476] | 120 | /*The following fields do not exist on disk but only in memory*/
|
---|
[54caa41b] | 121 | bool dirty;
|
---|
[155f792] | 122 | };
|
---|
| 123 |
|
---|
[953a823] | 124 | struct mfs_instance {
|
---|
| 125 | link_t link;
|
---|
| 126 | devmap_handle_t handle;
|
---|
| 127 | struct mfs_sb_info *sbi;
|
---|
| 128 | };
|
---|
| 129 |
|
---|
[e54ba607] | 130 | /*MinixFS node in core*/
|
---|
| 131 | struct mfs_node {
|
---|
[155f792] | 132 | struct mfs_ino_info *ino_i;
|
---|
[e54ba607] | 133 | struct mfs_instance *instance;
|
---|
| 134 | };
|
---|
| 135 |
|
---|
[f213ae7] | 136 | /*mfs_ops.c*/
|
---|
[1ffbbc1] | 137 | extern void mfs_mounted(ipc_callid_t rid, ipc_call_t *request);
|
---|
[3b08178] | 138 | extern void mfs_mount(ipc_callid_t rid, ipc_call_t *request);
|
---|
[54caa41b] | 139 | extern void mfs_lookup(ipc_callid_t rid, ipc_call_t *request);
|
---|
[44c0f5b] | 140 | extern int mfs_instance_get(devmap_handle_t handle,
|
---|
[3b08178] | 141 | struct mfs_instance **instance);
|
---|
[1ffbbc1] | 142 |
|
---|
[0d6ab10] | 143 | extern void mfs_stat(ipc_callid_t rid, ipc_call_t *request);
|
---|
| 144 |
|
---|
[f213ae7] | 145 | /*mfs_inode.c*/
|
---|
[ef76d72] | 146 | extern struct mfs_ino_info *
|
---|
| 147 | mfs_read_inode_raw(const struct mfs_instance *instance, uint16_t inum);
|
---|
| 148 |
|
---|
| 149 | extern struct mfs_ino_info *
|
---|
| 150 | mfs2_read_inode_raw(const struct mfs_instance *instance, uint32_t inum);
|
---|
[f213ae7] | 151 |
|
---|
[930baca] | 152 | /*mfs_read.c*/
|
---|
| 153 | int read_map(uint32_t *b, const struct mfs_node *mnode, const uint32_t pos);
|
---|
[df22c36] | 154 |
|
---|
[54caa41b] | 155 | /*mfs_dentry.c*/
|
---|
| 156 | extern struct mfs_dentry_info *
|
---|
| 157 | read_directory_entry(struct mfs_node *mnode, unsigned index);
|
---|
| 158 |
|
---|
[1ffbbc1] | 159 | #endif
|
---|
| 160 |
|
---|
| 161 | /**
|
---|
| 162 | * @}
|
---|
| 163 | */
|
---|
| 164 |
|
---|