source: mainline/uspace/srv/fs/mfs/mfs.h@ 76da580a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 76da580a 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
RevLine 
[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 * @{
[8a49fed]31 */
[1ffbbc1]32
33#ifndef _MFS_H_
34#define _MFS_H_
35
[86d0b4b3]36#include <minix.h>
[668f1949]37#include <macros.h>
[953a823]38#include <libblock.h>
[3b08178]39#include <libfs.h>
[953a823]40#include <adt/list.h>
[2874547]41#include <malloc.h>
42#include <mem.h>
43#include <stdio.h>
44#include <errno.h>
45#include <assert.h>
[1ffbbc1]46#include "../../vfs/vfs.h"
47
[ac28650]48#define NAME "mfs"
49
[c955be91]50//#define DEBUG_MODE
[92dd5c8]51
[bd64680]52#define min(a, b) ((a) < (b) ? (a) : (b))
53
[92dd5c8]54#ifdef DEBUG_MODE
55#define mfsdebug(...) printf(__VA_ARGS__)
56#else
57#define mfsdebug(...)
58#endif
59
[152610a8]60typedef uint32_t bitchunk_t;
61
[fde8a276]62typedef enum {
63 BMAP_ZONE,
64 BMAP_INODE
65} bmap_id_t;
66
[82650385]67typedef enum {
68 MFS_VERSION_V1 = 1,
69 MFS_VERSION_V2,
70 MFS_VERSION_V3
71} mfs_version_t;
72
[953a823]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;
[7a96476]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;
[07dcec5]90 size_t dirsize;
[10eb754]91 int itable_off;
[bd64680]92 unsigned max_name_len;
[953a823]93 bool long_names;
94 bool native;
[ef76d72]95 unsigned isearch;
96 unsigned zsearch;
[953a823]97};
98
[155f792]99/*Generic MinixFS inode*/
100struct mfs_ino_info {
[8a49fed]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];
[54caa41b]113
[7a96476]114 /*The following fields do not exist on disk but only in memory*/
[54caa41b]115 bool dirty;
[41202a9]116 fs_index_t index;
[54caa41b]117};
118
119/*Generic MFS directory entry*/
120struct mfs_dentry_info {
121 uint32_t d_inum;
[07dcec5]122 char d_name[MFS3_MAX_NAME_LEN + 1];
[54caa41b]123
[7a96476]124 /*The following fields do not exist on disk but only in memory*/
[c4eeb2f]125
126 /*Index of the dentry in the list*/
[87d4422]127 unsigned index;
128 /*Pointer to the node at witch the dentry belongs*/
129 struct mfs_node *node;
[155f792]130};
131
[953a823]132struct mfs_instance {
[03bc76a]133 service_id_t service_id;
[953a823]134 struct mfs_sb_info *sbi;
[ee257b2]135 unsigned open_nodes_cnt;
[953a823]136};
137
[e54ba607]138/*MinixFS node in core*/
139struct mfs_node {
[155f792]140 struct mfs_ino_info *ino_i;
[e54ba607]141 struct mfs_instance *instance;
[ee257b2]142 unsigned refcnt;
143 fs_node_t *fsnode;
144 link_t link;
[e54ba607]145};
146
[f213ae7]147/*mfs_ops.c*/
[03bc76a]148extern vfs_out_ops_t mfs_ops;
149extern libfs_ops_t mfs_libfs_ops;
[51db5aeb]150
[ee257b2]151extern int
152mfs_global_init(void);
153
[f213ae7]154/*mfs_inode.c*/
[8a49fed]155extern int
[3a5ee6c]156mfs_get_inode(struct mfs_instance *inst, struct mfs_ino_info **ino_i,
[8a49fed]157 fs_index_t index);
[f213ae7]158
[10eb754]159extern int
[5f509cc]160mfs_put_inode(struct mfs_node *mnode);
[10eb754]161
[8a49fed]162extern int
[3a5ee6c]163mfs_inode_shrink(struct mfs_node *mnode, size_t size_shrink);
[8a49fed]164
[2bbbfd3]165/*mfs_rw.c*/
166extern int
[3a5ee6c]167mfs_read_map(uint32_t *b, const struct mfs_node *mnode, const uint32_t pos);
[2bbbfd3]168
169extern int
[3a5ee6c]170mfs_write_map(struct mfs_node *mnode, uint32_t pos, uint32_t new_zone,
[8a49fed]171 uint32_t *old_zone);
[2bbbfd3]172
[1878386]173extern int
[3a5ee6c]174mfs_prune_ind_zones(struct mfs_node *mnode, size_t new_size);
[1878386]175
[54caa41b]176/*mfs_dentry.c*/
[488f7ed]177extern int
[3a5ee6c]178mfs_read_dentry(struct mfs_node *mnode,
[e80c2ff]179 struct mfs_dentry_info *d_info, unsigned index);
[54caa41b]180
[87d4422]181extern int
[3a5ee6c]182mfs_write_dentry(struct mfs_dentry_info *d_info);
[87d4422]183
[c955be91]184extern int
[3a5ee6c]185mfs_remove_dentry(struct mfs_node *mnode, const char *d_name);
[c955be91]186
[8a49fed]187extern int
[3a5ee6c]188mfs_insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum);
[07dcec5]189
[ba5beaf]190/*mfs_balloc.c*/
191extern int
[70ac0af]192mfs_alloc_inode(struct mfs_instance *inst, uint32_t *inum);
[2cf95e8]193
194extern int
[70ac0af]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);
[ba5beaf]202
[88be951e]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
[1ffbbc1]213#endif
214
215/**
216 * @}
[8a49fed]217 */
[1ffbbc1]218
Note: See TracBrowser for help on using the repository browser.