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