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