custom message type for VM_INFO
[minix3.git] / sys / lib / libsa / minixfs3.h
blobd7436dc816f88a8285837d08caf993ca98651484
1 /* $NetBSD: minixfs3.h,v 1.5 2013/06/23 07:28:36 dholland Exp $ */
3 /*-
4 * Copyright (c) 2012
5 * Vrije Universiteit, Amsterdam, The Netherlands. All rights reserved.
7 * Author: Evgeniy Ivanov
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
19 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
31 #ifndef MINIX_FS_3_H
32 #define MINIX_FS_3_H
34 FS_DEF(minixfs3);
36 #if !defined(__minix)
37 typedef uint32_t zone_t;
38 typedef uint16_t zone1_t;
39 typedef uint32_t block_t;
40 #endif /* !defined(__minix) */
42 #define NR_DZONES 7 /* # direct zone numbers in an inode */
43 #define NR_TZONES 10 /* total # zone numbers in an inode */
44 #define NIADDR 2 /* Indirect addresses in inode */
46 struct mfs_dinode {
47 uint16_t mdi_mode; /* file type, protection, etc. */
48 uint16_t mdi_nlinks; /* how many links to this file */
49 int16_t mdi_uid; /* user id of the file's owner */
50 uint16_t mdi_gid; /* group number */
51 uint32_t mdi_size; /* current file size in bytes */
52 uint32_t mdi_atime; /* time of last access */
53 uint32_t mdi_mtime; /* when was file data last changed */
54 uint32_t mdi_ctime; /* when was inode itself changed */
55 zone_t mdi_zone[NR_TZONES]; /* zone numbers for direct, ind, and
56 dbl ind */
59 /* Maximum Minix MFS on-disk directory filename.
60 * MFS uses 'struct direct' to write and parse
61 * directory entries, so this can't be changed
62 * without breaking filesystems.
64 #define MFS_DIRSIZ 60
66 struct mfs_direct {
67 uint32_t mfsd_ino;
68 char mfsd_name[MFS_DIRSIZ];
69 } __packed;
71 struct mfs_sblock {
72 uint32_t mfs_ninodes; /* # usable inodes on the minor device */
73 zone1_t mfs_nzones; /* total device size, including bit maps etc */
74 int16_t mfs_imap_blocks; /* # of blocks used by inode bit map */
75 int16_t mfs_zmap_blocks; /* # of blocks used by zone bit map */
76 zone1_t mfs_firstdatazone_old;/* number of first data zone (small) */
77 int16_t mfs_log_zone_size; /* log2 of blocks/zone */
78 int16_t mfs_pad; /* try to avoid compiler-dependent padding */
79 int32_t mfs_max_size; /* maximum file size on this device */
80 zone_t mfs_zones; /* number of zones (replaces s_nzones in V2) */
81 int16_t mfs_magic; /* magic number to recognize super-blocks */
82 int16_t mfs_pad2; /* try to avoid compiler-dependent padding */
83 uint16_t mfs_block_size; /* block size in bytes. */
84 char mfs_disk_version; /* filesystem format sub-version */
86 /* The following items are only used when the super_block is in memory,
87 * mfs_inodes_per_block must be the firs one (see SBSIZE)
89 unsigned mfs_inodes_per_block; /* precalculated from magic number */
90 zone_t mfs_firstdatazone; /* number of first data zone (big) */
91 int32_t mfs_bshift; /* ``lblkno'' calc of logical blkno */
92 int32_t mfs_bmask; /* ``blkoff'' calc of blk offsets */
93 int64_t mfs_qbmask; /* ~fs_bmask - for use with quad size */
94 int32_t mfs_fsbtodb; /* fsbtodb and dbtofsb shift constant */
97 #define LOG_MINBSIZE 10
98 #define MINBSIZE (1 << LOG_MINBSIZE)
100 #define SUPER_MAGIC 0x4d5a /* magic # for MFSv3 file systems */
102 #define ROOT_INODE ((uint32_t) 1) /* inode number for root directory */
103 #define SUPER_BLOCK_OFF (1024) /* bytes offset */
104 #define START_BLOCK ((block_t) 2) /* first fs block (not counting SB) */
106 /* # bytes/dir entry */
107 #define DIR_ENTRY_SIZE sizeof(struct mfs_direct)
108 /* # dir entries/blk */
109 #define NR_DIR_ENTRIES(fs) ((fs)->mfs_block_size/DIR_ENTRY_SIZE)
110 /* mfs_sblock on-disk part size */
111 #define SBSIZE offsetof(struct mfs_sblock, mfs_inodes_per_block)
113 #define ZONE_NUM_SIZE sizeof(zone_t) /* # bytes in zone */
114 #define INODE_SIZE sizeof(struct mfs_dinode) /* bytes in dsk ino */
115 /* # zones/indir block */
116 #define MFS_NINDIR(fs) ((fs)->mfs_block_size/ZONE_NUM_SIZE)
118 #define NO_ZONE ((zone_t) 0) /* absence of a zone number */
119 #define NO_BLOCK ((block_t) 0) /* absence of a block number */
121 /* Turn file system block numbers into disk block addresses */
122 #define MFS_FSBTODB(fs, b) ((b) << (fs)->mfs_fsbtodb)
124 #define ino_to_fsba(fs, x) \
125 (((x) - 1) / (fs)->mfs_inodes_per_block + \
126 START_BLOCK + (fs)->mfs_imap_blocks + (fs)->mfs_zmap_blocks)
127 #define ino_to_fsbo(fs, x) (((x) - 1) % (fs)->mfs_inodes_per_block)
130 * MFS metadatas are stored in little-endian byte order. These macros
131 * helps reading theses metadatas.
133 #if BYTE_ORDER == LITTLE_ENDIAN
134 # define fs2h16(x) (x)
135 # define fs2h32(x) (x)
136 # define mfs_sbload(old, new) \
137 memcpy((new), (old), SBSIZE);
138 # define mfs_iload(old, new) \
139 memcpy((new),(old),sizeof(struct mfs_dinode))
140 #else
141 void minixfs3_sb_bswap(struct mfs_sblock *, struct mfs_sblock *);
142 void minixfs3_i_bswap(struct mfs_dinode *, struct mfs_dinode *);
143 # define fs2h16(x) bswap16(x)
144 # define fs2h32(x) bswap32(x)
145 # define mfs_sbload(old, new) minixfs3_sb_bswap((old), (new))
146 # define mfs_iload(old, new) minixfs3_i_bswap((old), (new))
147 #endif /* BYTE_ORDER == LITTLE_ENDIAN */
150 * The following macros optimize certain frequently calculated
151 * quantities by using shifts and masks in place of divisions
152 * modulos and multiplications.
154 #define mfs_blkoff(fs, loc) /* calculates (loc % fs->mfs_bsize) */ \
155 ((loc) & (fs)->mfs_qbmask)
156 #define mfs_lblkno(fs, loc) /* calculates (loc / fs->mfs_bsize) */ \
157 ((loc) >> (fs)->mfs_bshift)
159 /* Flag bits for i_mode in the inode. */
160 #define I_TYPE 0170000 /* this field gives inode type */
161 #define I_UNIX_SOCKET 0140000 /* unix domain socket */
162 #define I_SYMBOLIC_LINK 0120000 /* file is a symbolic link */
163 #define I_REGULAR 0100000 /* regular file, not dir or special */
164 #define I_BLOCK_SPECIAL 0060000 /* block special file */
165 #define I_DIRECTORY 0040000 /* file is a directory */
166 #define I_CHAR_SPECIAL 0020000 /* character special file */
167 #define I_NAMED_PIPE 0010000 /* named pipe (FIFO) */
168 #define I_SET_UID_BIT 0004000 /* set effective uid_t on exec */
169 #define I_SET_GID_BIT 0002000 /* set effective gid_t on exec */
170 #define I_SET_STCKY_BIT 0001000 /* sticky bit */
171 #define ALL_MODES 0007777 /* all bits for user, group and others */
172 #define RWX_MODES 0000777 /* mode bits for RWX only */
173 #define R_BIT 0000004 /* Rwx protection bit */
174 #define W_BIT 0000002 /* rWx protection bit */
175 #define X_BIT 0000001 /* rwX protection bit */
176 #define I_NOT_ALLOC 0000000 /* this inode is free */
178 #endif /* MINIX_FS_3_H */