source: mainline/uspace/srv/fs/mfs/mfs.h@ 9ce2202b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9ce2202b was 5bf76c1, checked in by Jakub Jermar <jakub@…>, 14 years ago

Move the fs instance managing logic out of mfs to libfs.

  • Property mode set to 100644
File size: 5.1 KB
Line 
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
36#include <minix.h>
37#include <macros.h>
38#include <libblock.h>
39#include <libfs.h>
40#include <adt/list.h>
41#include <malloc.h>
42#include <mem.h>
43#include <stdio.h>
44#include <errno.h>
45#include <assert.h>
46#include "../../vfs/vfs.h"
47
48#define NAME "mfs"
49
50//#define DEBUG_MODE
51
52#define min(a, b) ((a) < (b) ? (a) : (b))
53
54#ifdef DEBUG_MODE
55#define mfsdebug(...) printf(__VA_ARGS__)
56#else
57#define mfsdebug(...)
58#endif
59
60typedef uint32_t bitchunk_t;
61
62typedef enum {
63 BMAP_ZONE,
64 BMAP_INODE
65} bmap_id_t;
66
67typedef enum {
68 MFS_VERSION_V1 = 1,
69 MFS_VERSION_V2,
70 MFS_VERSION_V3
71} mfs_version_t;
72
73/*Generic MinixFS superblock*/
74struct mfs_sb_info {
75 uint32_t ninodes;
76 uint32_t nzones;
77 unsigned long ibmap_blocks;
78 unsigned long zbmap_blocks;
79 unsigned long firstdatazone;
80 int log2_zone_size;
81 int block_size;
82 uint32_t max_file_size;
83 uint16_t magic;
84 uint16_t state;
85
86 /*The following fields do not exist on disk but only in memory*/
87 unsigned long itable_size;
88 mfs_version_t fs_version;
89 int ino_per_block;
90 size_t dirsize;
91 int itable_off;
92 unsigned max_name_len;
93 bool long_names;
94 bool native;
95 unsigned isearch;
96 unsigned zsearch;
97};
98
99/*Generic MinixFS inode*/
100struct mfs_ino_info {
101 uint16_t i_mode;
102 uint16_t i_nlinks;
103 int16_t i_uid;
104 uint16_t i_gid;
105 size_t i_size;
106 int32_t i_atime;
107 int32_t i_mtime;
108 int32_t i_ctime;
109 /*Block numbers for direct zones*/
110 uint32_t i_dzone[V2_NR_DIRECT_ZONES];
111 /*Block numbers for indirect zones*/
112 uint32_t i_izone[V2_NR_INDIRECT_ZONES];
113
114 /*The following fields do not exist on disk but only in memory*/
115 bool dirty;
116 fs_index_t index;
117};
118
119/*Generic MFS directory entry*/
120struct mfs_dentry_info {
121 uint32_t d_inum;
122 char d_name[MFS3_MAX_NAME_LEN + 1];
123
124 /*The following fields do not exist on disk but only in memory*/
125
126 /*Index of the dentry in the list*/
127 unsigned index;
128 /*Pointer to the node at witch the dentry belongs*/
129 struct mfs_node *node;
130};
131
132struct mfs_instance {
133 service_id_t service_id;
134 struct mfs_sb_info *sbi;
135 unsigned open_nodes_cnt;
136};
137
138/*MinixFS node in core*/
139struct mfs_node {
140 struct mfs_ino_info *ino_i;
141 struct mfs_instance *instance;
142 unsigned refcnt;
143 fs_node_t *fsnode;
144 link_t link;
145};
146
147/*mfs_ops.c*/
148extern vfs_out_ops_t mfs_ops;
149extern libfs_ops_t mfs_libfs_ops;
150
151extern int
152mfs_global_init(void);
153
154/*mfs_inode.c*/
155extern int
156mfs_get_inode(struct mfs_instance *inst, struct mfs_ino_info **ino_i,
157 fs_index_t index);
158
159extern int
160mfs_put_inode(struct mfs_node *mnode);
161
162extern int
163mfs_inode_shrink(struct mfs_node *mnode, size_t size_shrink);
164
165/*mfs_rw.c*/
166extern int
167mfs_read_map(uint32_t *b, const struct mfs_node *mnode, const uint32_t pos);
168
169extern int
170mfs_write_map(struct mfs_node *mnode, uint32_t pos, uint32_t new_zone,
171 uint32_t *old_zone);
172
173extern int
174mfs_prune_ind_zones(struct mfs_node *mnode, size_t new_size);
175
176/*mfs_dentry.c*/
177extern int
178mfs_read_dentry(struct mfs_node *mnode,
179 struct mfs_dentry_info *d_info, unsigned index);
180
181extern int
182mfs_write_dentry(struct mfs_dentry_info *d_info);
183
184extern int
185mfs_remove_dentry(struct mfs_node *mnode, const char *d_name);
186
187extern int
188mfs_insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum);
189
190/*mfs_balloc.c*/
191extern int
192mfs_alloc_inode(struct mfs_instance *inst, uint32_t *inum);
193
194extern int
195mfs_free_inode(struct mfs_instance *inst, uint32_t inum);
196
197extern int
198mfs_alloc_zone(struct mfs_instance *inst, uint32_t *zone);
199
200extern int
201mfs_free_zone(struct mfs_instance *inst, uint32_t zone);
202
203/*mfs_utils.c*/
204extern uint16_t
205conv16(bool native, uint16_t n);
206
207extern uint32_t
208conv32(bool native, uint32_t n);
209
210extern uint64_t
211conv64(bool native, uint64_t n);
212
213#endif
214
215/**
216 * @}
217 */
218
Note: See TracBrowser for help on using the repository browser.