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