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

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

Add insert_dentry() function to add a new directory entry to the parent dir.

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