source: mainline/uspace/srv/fs/mfs/mfs.h@ f066a87

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

Cstyle and clutter removal

  • Property mode set to 100644
File size: 5.9 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>
[f73b291]38#include <block.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>
[1eaa3cf]46#include <stdbool.h>
[61042de]47#include <macros.h>
[1ffbbc1]48#include "../../vfs/vfs.h"
49
[ac28650]50#define NAME "mfs"
51
[50a01a9]52/* #define DEBUG_MODE */
[92dd5c8]53
54#ifdef DEBUG_MODE
55#define mfsdebug(...) printf(__VA_ARGS__)
56#else
57#define mfsdebug(...)
58#endif
59
[b2c96093]60#define MFS_BMAP_START_BLOCK(sbi, bid) \
61 ((bid) == BMAP_ZONE ? 2 + (sbi)->ibmap_blocks : 2)
62
63#define MFS_BMAP_SIZE_BITS(sbi, bid) \
64 ((bid) == BMAP_ZONE ? (sbi)->nzones - (sbi)->firstdatazone - 1 : \
65 (sbi)->ninodes - 1)
66
67#define MFS_BMAP_SIZE_BLOCKS(sbi, bid) \
68 ((bid) == BMAP_ZONE ? (sbi)->zbmap_blocks : (sbi)->ibmap_blocks)
69
[152610a8]70typedef uint32_t bitchunk_t;
71
[fde8a276]72typedef enum {
73 BMAP_ZONE,
74 BMAP_INODE
75} bmap_id_t;
76
[82650385]77typedef enum {
78 MFS_VERSION_V1 = 1,
79 MFS_VERSION_V2,
80 MFS_VERSION_V3
81} mfs_version_t;
82
[50a01a9]83/* Generic MinixFS superblock */
[953a823]84struct mfs_sb_info {
85 uint32_t ninodes;
86 uint32_t nzones;
87 unsigned long ibmap_blocks;
88 unsigned long zbmap_blocks;
89 unsigned long firstdatazone;
90 int log2_zone_size;
91 int block_size;
92 uint32_t max_file_size;
93 uint16_t magic;
94 uint16_t state;
[7a96476]95
[50a01a9]96 /* The following fields do not exist on disk but only in memory */
[7a96476]97 unsigned long itable_size;
98 mfs_version_t fs_version;
99 int ino_per_block;
[07dcec5]100 size_t dirsize;
[10eb754]101 int itable_off;
[bd64680]102 unsigned max_name_len;
[953a823]103 bool long_names;
104 bool native;
[ef76d72]105 unsigned isearch;
106 unsigned zsearch;
[1eaa3cf]107
[fd7dbbb]108 /* Indicates wether if the cached number of free zones
109 * is to be considered valid or not.
110 */
[1eaa3cf]111 bool nfree_zones_valid;
[fd7dbbb]112 /* Cached number of free zones, used to avoid to scan
113 * the whole bitmap every time the mfs_free_block_count()
114 * is invoked.
115 */
[1eaa3cf]116 unsigned nfree_zones;
[953a823]117};
118
[50a01a9]119/* Generic MinixFS inode */
[155f792]120struct mfs_ino_info {
[8a49fed]121 uint16_t i_mode;
122 uint16_t i_nlinks;
123 int16_t i_uid;
124 uint16_t i_gid;
125 size_t i_size;
126 int32_t i_atime;
127 int32_t i_mtime;
128 int32_t i_ctime;
[50a01a9]129 /* Block numbers for direct zones */
[8a49fed]130 uint32_t i_dzone[V2_NR_DIRECT_ZONES];
[50a01a9]131 /* Block numbers for indirect zones */
[8a49fed]132 uint32_t i_izone[V2_NR_INDIRECT_ZONES];
[54caa41b]133
[50a01a9]134 /* The following fields do not exist on disk but only in memory */
[54caa41b]135 bool dirty;
[41202a9]136 fs_index_t index;
[54caa41b]137};
138
[50a01a9]139/* Generic MFS directory entry */
[54caa41b]140struct mfs_dentry_info {
141 uint32_t d_inum;
[07dcec5]142 char d_name[MFS3_MAX_NAME_LEN + 1];
[54caa41b]143
[50a01a9]144 /* The following fields do not exist on disk but only in memory */
[c4eeb2f]145
[50a01a9]146 /* Index of the dentry in the list */
[87d4422]147 unsigned index;
[50a01a9]148 /* Pointer to the node at witch the dentry belongs */
[87d4422]149 struct mfs_node *node;
[155f792]150};
151
[953a823]152struct mfs_instance {
[03bc76a]153 service_id_t service_id;
[953a823]154 struct mfs_sb_info *sbi;
[ee257b2]155 unsigned open_nodes_cnt;
[953a823]156};
157
[50a01a9]158/* MinixFS node in core */
[e54ba607]159struct mfs_node {
[155f792]160 struct mfs_ino_info *ino_i;
[e54ba607]161 struct mfs_instance *instance;
[ee257b2]162 unsigned refcnt;
163 fs_node_t *fsnode;
[062d900]164 ht_link_t link;
[e54ba607]165};
166
[50a01a9]167/* mfs_ops.c */
[03bc76a]168extern vfs_out_ops_t mfs_ops;
169extern libfs_ops_t mfs_libfs_ops;
[51db5aeb]170
[ee257b2]171extern int
172mfs_global_init(void);
173
[50a01a9]174/* mfs_inode.c */
[8a49fed]175extern int
[3a5ee6c]176mfs_get_inode(struct mfs_instance *inst, struct mfs_ino_info **ino_i,
[802f0b7]177 fs_index_t index);
[f213ae7]178
[10eb754]179extern int
[5f509cc]180mfs_put_inode(struct mfs_node *mnode);
[10eb754]181
[8a49fed]182extern int
[3a5ee6c]183mfs_inode_shrink(struct mfs_node *mnode, size_t size_shrink);
[8a49fed]184
[50a01a9]185/* mfs_rw.c */
[2bbbfd3]186extern int
[3a5ee6c]187mfs_read_map(uint32_t *b, const struct mfs_node *mnode, const uint32_t pos);
[2bbbfd3]188
189extern int
[3a5ee6c]190mfs_write_map(struct mfs_node *mnode, uint32_t pos, uint32_t new_zone,
[802f0b7]191 uint32_t *old_zone);
[2bbbfd3]192
[1878386]193extern int
[3a5ee6c]194mfs_prune_ind_zones(struct mfs_node *mnode, size_t new_size);
[1878386]195
[50a01a9]196/* mfs_dentry.c */
[488f7ed]197extern int
[3a5ee6c]198mfs_read_dentry(struct mfs_node *mnode,
[802f0b7]199 struct mfs_dentry_info *d_info, unsigned index);
[54caa41b]200
[87d4422]201extern int
[3a5ee6c]202mfs_write_dentry(struct mfs_dentry_info *d_info);
[87d4422]203
[c955be91]204extern int
[3a5ee6c]205mfs_remove_dentry(struct mfs_node *mnode, const char *d_name);
[c955be91]206
[8a49fed]207extern int
[3a5ee6c]208mfs_insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum);
[07dcec5]209
[50a01a9]210/* mfs_balloc.c */
[ba5beaf]211extern int
[70ac0af]212mfs_alloc_inode(struct mfs_instance *inst, uint32_t *inum);
[2cf95e8]213
214extern int
[70ac0af]215mfs_free_inode(struct mfs_instance *inst, uint32_t inum);
216
217extern int
218mfs_alloc_zone(struct mfs_instance *inst, uint32_t *zone);
219
220extern int
221mfs_free_zone(struct mfs_instance *inst, uint32_t zone);
[ba5beaf]222
[b2c96093]223extern int
224mfs_count_free_zones(struct mfs_instance *inst, uint32_t *zones);
225
226extern int
227mfs_count_free_inodes(struct mfs_instance *inst, uint32_t *inodes);
228
229
[50a01a9]230/* mfs_utils.c */
[88be951e]231extern uint16_t
232conv16(bool native, uint16_t n);
233
234extern uint32_t
235conv32(bool native, uint32_t n);
236
237extern uint64_t
238conv64(bool native, uint64_t n);
239
[1ffbbc1]240#endif
241
242/**
243 * @}
[8a49fed]244 */
[1ffbbc1]245
Note: See TracBrowser for help on using the repository browser.