Home | History | Annotate | Line # | Download | only in sysvbfs
bfs.h revision 1.4
      1 /*	$NetBSD: bfs.h,v 1.4 2007/12/25 18:33:44 perry Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2004 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by UCHIYAMA Yasushi.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #ifndef _FS_SYSVBFS_BFS_H_
     40 #define	_FS_SYSVBFS_BFS_H_
     41 /*
     42  *   Boot File System
     43  *
     44  *	+----------
     45  *	|bfs_super_block (512byte)
     46  *	|				1 sector
     47  *	|
     48  *	+----------
     49  *	|bfs_inode (64byte) * 8
     50  *	|    .				1 sector
     51  *	|bfs_inode
     52  *	+----------  <--- bfs_super_block.header.data_start
     53  *	|DATA BLOCK
     54  *	|    .
     55  *	|    .
     56  *	|
     57  *	+----------  <--- bfs_super_block.header.data_end
     58  */
     59 
     60 /* BFS specification */
     61 #define	BFS_SECTOR		0	/* no offset */
     62 #define	BFS_MAGIC		0x1badface
     63 #define	BFS_FILENAME_MAXLEN	14
     64 #define	BFS_ROOT_INODE		2
     65 #define	BFS_BSIZE		512
     66 #define	BFS_BSHIFT		9
     67 
     68 struct bfs_super_block_header {
     69 	uint32_t magic;
     70 	uint32_t data_start_byte;
     71 	uint32_t data_end_byte;
     72 } __packed;
     73 
     74 struct bfs_compaction {
     75 	uint32_t from;
     76 	uint32_t to;
     77 	uint32_t from_backup;
     78 	uint32_t to_backup;
     79 } __packed;
     80 
     81 struct bfs_fileattr {
     82 	uint32_t type;
     83 	uint32_t mode;
     84 	int32_t uid;
     85 	int32_t gid;
     86 	uint32_t nlink;
     87 	int32_t atime;
     88 	int32_t mtime;
     89 	int32_t ctime;
     90 	int32_t padding[4];
     91 } __packed;	/* 48byte */
     92 
     93 struct bfs_inode {
     94 	uint16_t number;		/*  0 */
     95 	int16_t padding;
     96 	uint32_t start_sector;		/*  4 */
     97 	uint32_t end_sector;		/*  8 */
     98 	uint32_t eof_offset_byte;	/* 12 (offset from super block start) */
     99 	struct bfs_fileattr attr;	/* 16 */
    100 } __packed;	/* 64byte */
    101 
    102 struct bfs_super_block {
    103 	struct bfs_super_block_header header;
    104 	struct bfs_compaction compaction;
    105 	char fsname[6];
    106 	char volume[6];
    107 	int32_t padding[118];
    108 } __packed;
    109 
    110 struct bfs_dirent {
    111 	uint16_t inode;
    112 	char name[BFS_FILENAME_MAXLEN];
    113 } __packed; /* 16byte */
    114 
    115 #if defined _KERNEL || defined _STANDALONE
    116 /* Software definition */
    117 struct sector_io_ops;
    118 struct bfs {
    119 	int start_sector;
    120 	/* Super block */
    121 	struct bfs_super_block *super_block;
    122 	size_t super_block_size;
    123 
    124 	/* Data block */
    125 	uint32_t data_start, data_end;
    126 
    127 	/* Inode */
    128 	struct bfs_inode *inode;
    129 	int n_inode;
    130 	int max_inode;
    131 
    132 	/* root directory */
    133 	struct bfs_dirent *dirent;
    134 	size_t dirent_size;
    135 	int n_dirent;
    136 	int max_dirent;
    137 	struct bfs_inode *root_inode;
    138 
    139 	/* Sector I/O operation */
    140 	struct sector_io_ops *io;
    141 
    142 	bool debug;
    143 };
    144 
    145 struct sector_io_ops {
    146 	bool (*read)(void *, uint8_t *, daddr_t);
    147 	bool (*read_n)(void *, uint8_t *, daddr_t, int);
    148 	bool (*write)(void *, uint8_t *, daddr_t);
    149 	bool (*write_n)(void *, uint8_t *, daddr_t, int);
    150 };
    151 
    152 int bfs_init2(struct bfs **, int, struct sector_io_ops *, bool);
    153 void bfs_fini(struct bfs *);
    154 int bfs_file_read(const struct bfs *, const char *, void *, size_t, size_t *);
    155 int bfs_file_write(struct bfs *, const char *, void *, size_t);
    156 int bfs_file_create(struct bfs *, const char *, void *,  size_t,
    157     const struct bfs_fileattr *);
    158 int bfs_file_delete(struct bfs *, const char *);
    159 int bfs_file_rename(struct bfs *, const char *, const char *);
    160 bool bfs_file_lookup(const struct bfs *, const char *, int *, int *,
    161     size_t *);
    162 size_t bfs_file_size(const struct bfs_inode *);
    163 bool bfs_dump(const struct bfs *);
    164 
    165 /* filesystem ops */
    166 struct vnode;
    167 int sysvbfs_bfs_init(struct bfs **, struct vnode *);
    168 void sysvbfs_bfs_fini(struct bfs *);
    169 bool bfs_inode_lookup(const struct bfs *, ino_t, struct bfs_inode **);
    170 bool bfs_dirent_lookup_by_name(const struct bfs *, const char *,
    171     struct bfs_dirent **);
    172 bool bfs_dirent_lookup_by_inode(const struct bfs *, int,
    173     struct bfs_dirent **);
    174 void bfs_inode_set_attr(const struct bfs *, struct bfs_inode *,
    175     const struct bfs_fileattr *attr);
    176 int bfs_inode_alloc(const struct bfs *, struct bfs_inode **, int *,
    177     int *);
    178 #endif /* _KERNEL || _STANDALONE */
    179 #endif /* _FS_SYSVBFS_BFS_H_ */
    180