source: mainline/uspace/srv/fs/minixfs/mfs.h@ a4726cb

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a4726cb was e03d545, checked in by Maurizio Lombardi <m.lombardi85@…>, 14 years ago

Minor fixes to minixfs:

  • Do not check the value of nlinks in the mfs_destroy() function
  • Rename the mfs_put_inode() function to mfs_put_inode_core()
  • Read the entire superblock when mounting the fs image
  • 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 link_t link;
134 service_id_t service_id;
135 struct mfs_sb_info *sbi;
136 unsigned open_nodes_cnt;
137};
138
139/*MinixFS node in core*/
140struct mfs_node {
141 struct mfs_ino_info *ino_i;
142 struct mfs_instance *instance;
143 unsigned refcnt;
144 fs_node_t *fsnode;
145 link_t link;
146};
147
148/*mfs_ops.c*/
149extern vfs_out_ops_t mfs_ops;
150extern libfs_ops_t mfs_libfs_ops;
151
152extern int
153mfs_global_init(void);
154
155/*mfs_inode.c*/
156extern int
157mfs_get_inode(struct mfs_instance *inst, struct mfs_ino_info **ino_i,
158 fs_index_t index);
159
160extern int
161mfs_put_inode_core(struct mfs_node *mnode);
162
163extern int
164mfs_inode_shrink(struct mfs_node *mnode, size_t size_shrink);
165
166/*mfs_rw.c*/
167extern int
168mfs_read_map(uint32_t *b, const struct mfs_node *mnode, const uint32_t pos);
169
170extern int
171mfs_write_map(struct mfs_node *mnode, uint32_t pos, uint32_t new_zone,
172 uint32_t *old_zone);
173
174extern int
175mfs_prune_ind_zones(struct mfs_node *mnode, size_t new_size);
176
177/*mfs_dentry.c*/
178extern int
179mfs_read_dentry(struct mfs_node *mnode,
180 struct mfs_dentry_info *d_info, unsigned index);
181
182extern int
183mfs_write_dentry(struct mfs_dentry_info *d_info);
184
185extern int
186mfs_remove_dentry(struct mfs_node *mnode, const char *d_name);
187
188extern int
189mfs_insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum);
190
191/*mfs_balloc.c*/
192extern int
193mfs_alloc_inode(struct mfs_instance *inst, uint32_t *inum);
194
195extern int
196mfs_free_inode(struct mfs_instance *inst, uint32_t inum);
197
198extern int
199mfs_alloc_zone(struct mfs_instance *inst, uint32_t *zone);
200
201extern int
202mfs_free_zone(struct mfs_instance *inst, uint32_t zone);
203
204/*mfs_utils.c*/
205extern uint16_t
206conv16(bool native, uint16_t n);
207
208extern uint32_t
209conv32(bool native, uint32_t n);
210
211extern uint64_t
212conv64(bool native, uint64_t n);
213
214#endif
215
216/**
217 * @}
218 */
219
Note: See TracBrowser for help on using the repository browser.