mkfs reloaded

* restored the zone>block stuff
* generalized the support for more-than-1-block bitmaps to also deal
  with big inodes maps in small blocks
* improved pexit() to printf-like syntax; also replaced pexit() with
  err() or errx() where there are no reference to proto lines
* unified the allocation of blocks to all use alloc_block() instead
  of raw malloc half of the time
* removed the V2_ d2_ etc. prefixes which are obscure and obsolete

While here, also
* used new-form definitions, and closer to KNF style in general
* used often-built-ins such as mem* or strncpy where relevant
* pruned a fair amount of constants which are irrelevant

Thanks to Thomas V. and Lionel who did a good amount of work with the
cross-compilation stuff and made that change to be much smoother.
This commit is contained in:
Antoine Leca 2013-04-26 20:54:22 +02:00 committed by Gerrit Code Review
parent 717425320f
commit 49fe5d1617
5 changed files with 738 additions and 742 deletions

View file

@ -1,23 +1,12 @@
#ifndef __MFS_CONST_H__
#define __MFS_CONST_H__
#ifndef _MKFS_MFS_CONST_H__
#define _MKFS_MFS_CONST_H__
/* Tables sizes */
#define V2_NR_DZONES 7 /* # direct zone numbers in a V2 inode */
#define V2_NR_TZONES 10 /* total # zone numbers in a V2 inode */
#define NR_INODES 512 /* # slots in "in core" inode table,
* should be more or less the same as
* NR_VNODES in vfs
*/
#define GETDENTS_BUFSIZ 257
#define INODE_HASH_LOG2 7 /* 2 based logarithm of the inode hash size */
#define INODE_HASH_SIZE ((unsigned long)1<<INODE_HASH_LOG2)
#define INODE_HASH_MASK (((unsigned long)1<<INODE_HASH_LOG2)-1)
/* Max. filename length */
#define MFS_NAME_MAX MFS_DIRSIZ
#define NR_DZONES 7 /* # direct zone numbers in a V2 inode */
#define NR_TZONES 10 /* total # zone numbers in a V2 inode */
#define MIN_BLOCK_SIZE 1024
#define DEFAULT_BLOCK_SIZE 4096
/* The type of sizeof may be (unsigned) long. Use the following macro for
* taking the sizes of small objects so that there are no surprises like
@ -25,71 +14,30 @@
*/
#define usizeof(t) ((unsigned) sizeof(t))
/* File system types. */
#define SUPER_MAGIC 0x137F /* magic number contained in super-block */
#define SUPER_REV 0x7F13 /* magic # when 68000 disk read on PC or vv */
#define SUPER_V2 0x2468 /* magic # for V2 file systems */
#define SUPER_V2_REV 0x6824 /* V2 magic written on PC, read on 68K or vv */
/* File system types: magic number contained in super-block. */
#define SUPER_V3 0x4d5a /* magic # for V3 file systems */
#define V1 1 /* version number of V1 file systems */
#define V2 2 /* version number of V2 file systems */
#define V3 3 /* version number of V3 file systems */
#define SUPER_MAGIC SUPER_V3
/* Miscellaneous constants */
#define SU_UID ((uid_t) 0) /* super_user's uid_t */
#define NORMAL 0 /* forces get_block to do disk read */
#define NO_READ 1 /* prevents get_block from doing disk read */
#define PREFETCH 2 /* tells get_block not to read or mark dev */
#define SU_UID ((uid_t) 0) /* super_user's uid_t */
#define SECTOR_SIZE 512
#define NO_BIT ((uint32_t) 0) /* returned by alloc_bit() to signal failure */
#define ROOT_INODE ((ino_t) 1) /* inode number for root directory */
#define LOOK_UP 0 /* tells search_dir to lookup string */
#define ENTER 1 /* tells search_dir to make dir entry */
#define DELETE 2 /* tells search_dir to delete entry */
#define IS_EMPTY 3 /* tells search_dir to ret. OK or ENOTEMPTY */
/* write_map() args */
#define WMAP_FREE (1 << 0)
#define IGN_PERM 0
#define CHK_PERM 1
#define BP_CLEAN 0 /* on-disk block and memory copies identical */
#define BP_DIRTY 1 /* on-disk block and memory copies differ */
#define IN_CLEAN 0 /* in-block inode and memory copies identical */
#define IN_DIRTY 1 /* in-block inode and memory copies differ */
#define ATIME 002 /* set if atime field needs updating */
#define CTIME 004 /* set if ctime field needs updating */
#define MTIME 010 /* set if mtime field needs updating */
#define BYTE_SWAP 0 /* tells conv2/conv4 to swap bytes */
#define END_OF_FILE (-104) /* eof detected */
#define ROOT_INODE ((ino_t) 1) /* inode number for root directory */
#define BOOT_BLOCK ((blkcnt_t) 0) /* block number of boot block */
#define BOOT_BLOCK ((blkcnt_t) 0) /* block number of boot block */
#define SUPER_BLOCK_BYTES (1024) /* bytes offset */
#define START_BLOCK ((blkcnt_t) 2) /* first block of FS (not counting SB) */
#define START_BLOCK ((blkcnt_t) 2) /* first block of FS (not counting SB) */
#define DIR_ENTRY_SIZE usizeof (struct direct) /* # bytes/dir entry */
#define NR_DIR_ENTRIES(b) ((b)/DIR_ENTRY_SIZE) /* # dir entries/blk */
#define SUPER_SIZE usizeof (struct super_block) /* super_block size */
#define FS_BITMAP_CHUNKS(b) ((b)/usizeof (uint32_t))/* # map chunks/blk */
#define FS_BITCHUNK_BITS (usizeof(uint32_t) * CHAR_BIT)
#define FS_BITMAP_CHUNKS(b) ((b)/usizeof(bitchunk_t)) /*# map chunks/blk*/
#define FS_BITCHUNK_BITS (usizeof(bitchunk_t) * CHAR_BIT)
#define FS_BITS_PER_BLOCK(b) (FS_BITMAP_CHUNKS(b) * FS_BITCHUNK_BITS)
/* Derived sizes pertaining to the V2 file system. */
#define V2_ZONE_NUM_SIZE usizeof (uint32_t) /* # bytes in V2 zone */
#define V2_INODE_SIZE usizeof (d2_inode) /* bytes in V2 dsk ino */
#define V2_INDIRECTS(b) ((b)/V2_ZONE_NUM_SIZE) /* # zones/indir block */
#define V2_INODES_PER_BLOCK(b) ((b)/V2_INODE_SIZE)/* # V2 dsk inodes/blk */
/* Derived sizes pertaining to the file system. */
#define ZONE_NUM_SIZE usizeof (zone_t) /* # bytes in zone */
#define INODE_SIZE usizeof (struct inode) /* bytes in dsk ino */
#define INDIRECTS(b) ((b)/ZONE_NUM_SIZE) /* # zones/indir block */
#define INODES_PER_BLOCK(b) ((b)/INODE_SIZE) /* # V2 dsk inodes/blk */
#define NUL(str,l,m) mfs_nul_f(__FILE__,__LINE__,(str), (l), (m))
#define _STATIC_BLOCK_SIZE 1024
#define _MIN_BLOCK_SIZE 1024
#define _MAX_BLOCK_SIZE 4096
#define DIR_ENTRY_SIZE usizeof(struct direct) /* # bytes/dir entry */
#define NR_DIR_ENTRIES(b) ((b)/DIR_ENTRY_SIZE) /* # dir entries/blk */
#endif

View file

@ -1,17 +1,16 @@
#ifndef _MFSDIR_H
#define _MFSDIR_H
#ifndef _MKFS_MFSDIR_H
#define _MKFS_MFSDIR_H
/* Maximum Minix MFS on-disk directory filename.
* MFS uses 'struct direct' to write and parse
* directory entries, so this can't be changed
* without breaking filesystems.
*/
#define MFS_DIRSIZ 60
struct direct {
uint32_t mfs_d_ino;
char mfs_d_name[MFS_DIRSIZ];
uint32_t d_ino;
char d_name[MFS_DIRSIZ];
} __packed;
#endif /* _MFSDIR_H */
#endif /* _MKFS_MFSDIR_H */

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,7 @@
#ifndef __MFS_SUPER_H__
#define __MFS_SUPER_H__
#ifndef _MKFS_MFS_SUPER_H__
#define _MKFS_MFS_SUPER_H__
/* Super block table. The root file system and every mounted file system
* has an entry here. The entry holds information about the sizes of the bit
/* Super block table. The entry holds information about the sizes of the bit
* maps and inodes. The s_ninodes field gives the number of inodes available
* for files and directories, including the root directory. Inode 0 is
* on the disk, but not used. Thus s_ninodes = 4 means that 5 bits will be
@ -17,11 +16,9 @@
* inodes (s_ninodes + 'inodes per block' - 1)/'inodes per block'
* unused whatever is needed to fill out the current zone
* data zones (s_zones - s_firstdatazone) << s_log_zone_size
*
* A super_block slot is free if s_dev == NO_DEV.
*/
EXTERN struct super_block {
struct super_block {
uint32_t s_ninodes; /* # usable inodes on the minor device */
uint16_t s_nzones; /* total device size, including bit maps etc */
int16_t s_imap_blocks; /* # of blocks used by inode bit map */
@ -35,38 +32,22 @@ EXTERN struct super_block {
/* The following items are valid on disk only for V3 and above */
/* The block size in bytes. Minimum MIN_BLOCK SIZE. SECTOR_SIZE
* multiple. If V1 or V2 filesystem, this should be
* initialised to STATIC_BLOCK_SIZE.
*/
int16_t s_pad2; /* try to avoid compiler-dependent padding */
/* The block size in bytes. Minimum MIN_BLOCK SIZE. SECTOR_SIZE multiple.*/
uint16_t s_block_size; /* block size in bytes. */
int8_t s_disk_version; /* filesystem format sub-version */
/* The following items are only used when the super_block is in memory.
* If this ever changes, i.e. more fields after s_disk_version has to go to
* disk, update LAST_ONDISK_FIELD in super.c as that controls which part of the
* struct is copied to and from disk.
* disk, update LAST_ONDISK_FIELD in servers/mfs/super.c as that controls
* which part of the struct is copied to and from disk.
*/
/* XXX padding inserted here... */
/*struct inode *s_isup;*/ /* inode for root dir of mounted file sys */
/*struct inode *s_imount;*/ /* inode mounted on */
unsigned s_inodes_per_block; /* precalculated from magic number */
uint32_t s_firstdatazone; /* number of first data zone (big) */
dev_t s_dev; /* whose super block is this? */
int32_t s_rd_only; /* set to 1 iff file sys mounted read only */
int32_t s_native; /* set to 1 iff not byte swapped file system */
int32_t s_version; /* file system version, zero means bad magic */
int32_t s_ndzones; /* # direct zones in an inode */
int32_t s_nindirs; /* # indirect zones per indirect block */
uint32_t s_isearch; /* inodes below this bit number are in use */
uint32_t s_zsearch; /* all zones below this bit number are in use*/
int8_t s_is_root;
} superblock;
#define IMAP 0 /* operating on the inode bit map */
#define ZMAP 1 /* operating on the zone bit map */
/* s_flags contents; undefined flags are guaranteed to be zero on disk
* (not counting future versions of mfs setting them!)
*/
@ -79,5 +60,15 @@ EXTERN struct super_block {
*/
#define MFSFLAG_MANDATORY_MASK 0xff00
#endif
/* The block size should be registered on disk, even
* multiple. If V1 or V2 filesystem, this should be
* initialised to STATIC_BLOCK_SIZE.
*/
#define MFS_SUPER_BLOCK_SIZE s_block_size
/* To keep the super block on disk clean, the MFS server only read/write up to
* and including this field:
*/
#define LAST_ONDISK_FIELD s_disk_version
#endif

View file

@ -1,34 +1,18 @@
#ifndef __MFS_TYPE_H__
#define __MFS_TYPE_H__
#ifndef _MKFS_MFS_TYPE_H__
#define _MKFS_MFS_TYPE_H__
/* Declaration of the V2 inode as it is on the disk (not in core). */
typedef struct { /* V2.x disk inode */
uint16_t d2_mode; /* file type, protection, etc. */
uint16_t d2_nlinks; /* how many links to this file. HACK! */
int16_t d2_uid; /* user id of the file's owner. */
uint16_t d2_gid; /* group number HACK! */
int32_t d2_size; /* current file size in bytes */
int32_t d2_atime; /* when was file data last accessed */
int32_t d2_mtime; /* when was file data last changed */
int32_t d2_ctime; /* when was inode data last changed */
uint32_t d2_zone[V2_NR_TZONES];/* block nums for direct, ind, and dbl ind */
} d2_inode;
struct buf {
/* Data portion of the buffer. */
union fsdata_u *bp;
/* Header portion of the buffer. */
struct buf *b_next; /* used to link all free bufs in a chain */
struct buf *b_prev; /* used to link all free bufs the other way */
struct buf *b_hash; /* used to link bufs on hash chains */
uint32_t b_blocknr; /* block number of its (minor) device */
dev_t b_dev; /* major | minor device where block resides */
char b_dirt; /* BP_CLEAN or BP_DIRTY */
char b_count; /* number of users of this buffer */
unsigned int b_bytes; /* Number of bytes allocated in bp */
/* The same structure is used for V3. */
struct inode { /* V2/V3 disk inode */
uint16_t i_mode; /* file type, protection, etc. */
uint16_t i_nlinks; /* how many links to this file. */
int16_t i_uid; /* user id of the file's owner. */
uint16_t i_gid; /* group number */
uint32_t i_size; /* current file size in bytes */
uint32_t i_atime; /* when was file data last accessed */
uint32_t i_mtime; /* when was file data last changed */
uint32_t i_ctime; /* when was inode data last changed */
uint32_t i_zone[NR_TZONES]; /* zone nums for direct, ind, and dbl ind */
};
#endif