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

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

Add the mfs_write() function implementation.

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