Home | History | Annotate | Line # | Download | only in sysvbfs
bfs.h revision 1.4.10.1
      1  1.4.10.1     yamt /*	$NetBSD: bfs.h,v 1.4.10.1 2008/05/16 02:25:21 yamt 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  *
     19       1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1  tsutsui  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1  tsutsui  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1  tsutsui  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1  tsutsui  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1  tsutsui  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1  tsutsui  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1  tsutsui  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1  tsutsui  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1  tsutsui  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1  tsutsui  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1  tsutsui  */
     31       1.1  tsutsui 
     32       1.1  tsutsui #ifndef _FS_SYSVBFS_BFS_H_
     33       1.1  tsutsui #define	_FS_SYSVBFS_BFS_H_
     34       1.1  tsutsui /*
     35       1.1  tsutsui  *   Boot File System
     36       1.1  tsutsui  *
     37       1.1  tsutsui  *	+----------
     38       1.1  tsutsui  *	|bfs_super_block (512byte)
     39       1.1  tsutsui  *	|				1 sector
     40       1.1  tsutsui  *	|
     41       1.1  tsutsui  *	+----------
     42       1.1  tsutsui  *	|bfs_inode (64byte) * 8
     43       1.1  tsutsui  *	|    .				1 sector
     44       1.1  tsutsui  *	|bfs_inode
     45       1.1  tsutsui  *	+----------  <--- bfs_super_block.header.data_start
     46       1.1  tsutsui  *	|DATA BLOCK
     47       1.1  tsutsui  *	|    .
     48       1.1  tsutsui  *	|    .
     49       1.1  tsutsui  *	|
     50       1.1  tsutsui  *	+----------  <--- bfs_super_block.header.data_end
     51       1.1  tsutsui  */
     52       1.1  tsutsui 
     53       1.1  tsutsui /* BFS specification */
     54       1.1  tsutsui #define	BFS_SECTOR		0	/* no offset */
     55       1.1  tsutsui #define	BFS_MAGIC		0x1badface
     56       1.1  tsutsui #define	BFS_FILENAME_MAXLEN	14
     57       1.1  tsutsui #define	BFS_ROOT_INODE		2
     58       1.1  tsutsui #define	BFS_BSIZE		512
     59       1.1  tsutsui #define	BFS_BSHIFT		9
     60       1.1  tsutsui 
     61       1.1  tsutsui struct bfs_super_block_header {
     62       1.1  tsutsui 	uint32_t magic;
     63       1.1  tsutsui 	uint32_t data_start_byte;
     64       1.1  tsutsui 	uint32_t data_end_byte;
     65       1.4    perry } __packed;
     66       1.1  tsutsui 
     67       1.1  tsutsui struct bfs_compaction {
     68       1.1  tsutsui 	uint32_t from;
     69       1.1  tsutsui 	uint32_t to;
     70       1.1  tsutsui 	uint32_t from_backup;
     71       1.1  tsutsui 	uint32_t to_backup;
     72       1.4    perry } __packed;
     73       1.1  tsutsui 
     74       1.1  tsutsui struct bfs_fileattr {
     75       1.1  tsutsui 	uint32_t type;
     76       1.1  tsutsui 	uint32_t mode;
     77       1.1  tsutsui 	int32_t uid;
     78       1.1  tsutsui 	int32_t gid;
     79       1.1  tsutsui 	uint32_t nlink;
     80       1.1  tsutsui 	int32_t atime;
     81       1.1  tsutsui 	int32_t mtime;
     82       1.1  tsutsui 	int32_t ctime;
     83       1.1  tsutsui 	int32_t padding[4];
     84       1.4    perry } __packed;	/* 48byte */
     85       1.1  tsutsui 
     86       1.1  tsutsui struct bfs_inode {
     87       1.1  tsutsui 	uint16_t number;		/*  0 */
     88       1.1  tsutsui 	int16_t padding;
     89       1.1  tsutsui 	uint32_t start_sector;		/*  4 */
     90       1.1  tsutsui 	uint32_t end_sector;		/*  8 */
     91       1.1  tsutsui 	uint32_t eof_offset_byte;	/* 12 (offset from super block start) */
     92       1.1  tsutsui 	struct bfs_fileattr attr;	/* 16 */
     93       1.4    perry } __packed;	/* 64byte */
     94       1.1  tsutsui 
     95       1.1  tsutsui struct bfs_super_block {
     96       1.1  tsutsui 	struct bfs_super_block_header header;
     97       1.1  tsutsui 	struct bfs_compaction compaction;
     98       1.2  tsutsui 	char fsname[6];
     99       1.2  tsutsui 	char volume[6];
    100       1.1  tsutsui 	int32_t padding[118];
    101       1.4    perry } __packed;
    102       1.1  tsutsui 
    103       1.1  tsutsui struct bfs_dirent {
    104       1.1  tsutsui 	uint16_t inode;
    105       1.2  tsutsui 	char name[BFS_FILENAME_MAXLEN];
    106       1.4    perry } __packed; /* 16byte */
    107       1.1  tsutsui 
    108       1.1  tsutsui #if defined _KERNEL || defined _STANDALONE
    109       1.1  tsutsui /* Software definition */
    110       1.1  tsutsui struct sector_io_ops;
    111       1.1  tsutsui struct bfs {
    112       1.1  tsutsui 	int start_sector;
    113       1.1  tsutsui 	/* Super block */
    114       1.1  tsutsui 	struct bfs_super_block *super_block;
    115       1.1  tsutsui 	size_t super_block_size;
    116       1.1  tsutsui 
    117       1.1  tsutsui 	/* Data block */
    118       1.1  tsutsui 	uint32_t data_start, data_end;
    119       1.1  tsutsui 
    120       1.1  tsutsui 	/* Inode */
    121       1.1  tsutsui 	struct bfs_inode *inode;
    122       1.1  tsutsui 	int n_inode;
    123       1.1  tsutsui 	int max_inode;
    124       1.1  tsutsui 
    125       1.1  tsutsui 	/* root directory */
    126       1.1  tsutsui 	struct bfs_dirent *dirent;
    127       1.1  tsutsui 	size_t dirent_size;
    128       1.1  tsutsui 	int n_dirent;
    129       1.1  tsutsui 	int max_dirent;
    130       1.1  tsutsui 	struct bfs_inode *root_inode;
    131       1.1  tsutsui 
    132       1.1  tsutsui 	/* Sector I/O operation */
    133       1.1  tsutsui 	struct sector_io_ops *io;
    134       1.1  tsutsui 
    135       1.3  thorpej 	bool debug;
    136       1.1  tsutsui };
    137       1.1  tsutsui 
    138       1.1  tsutsui struct sector_io_ops {
    139       1.3  thorpej 	bool (*read)(void *, uint8_t *, daddr_t);
    140       1.3  thorpej 	bool (*read_n)(void *, uint8_t *, daddr_t, int);
    141       1.3  thorpej 	bool (*write)(void *, uint8_t *, daddr_t);
    142       1.3  thorpej 	bool (*write_n)(void *, uint8_t *, daddr_t, int);
    143       1.1  tsutsui };
    144       1.1  tsutsui 
    145       1.3  thorpej int bfs_init2(struct bfs **, int, struct sector_io_ops *, bool);
    146       1.1  tsutsui void bfs_fini(struct bfs *);
    147       1.1  tsutsui int bfs_file_read(const struct bfs *, const char *, void *, size_t, size_t *);
    148       1.1  tsutsui int bfs_file_write(struct bfs *, const char *, void *, size_t);
    149       1.1  tsutsui int bfs_file_create(struct bfs *, const char *, void *,  size_t,
    150       1.1  tsutsui     const struct bfs_fileattr *);
    151       1.1  tsutsui int bfs_file_delete(struct bfs *, const char *);
    152       1.1  tsutsui int bfs_file_rename(struct bfs *, const char *, const char *);
    153       1.3  thorpej bool bfs_file_lookup(const struct bfs *, const char *, int *, int *,
    154       1.1  tsutsui     size_t *);
    155       1.1  tsutsui size_t bfs_file_size(const struct bfs_inode *);
    156       1.3  thorpej bool bfs_dump(const struct bfs *);
    157       1.1  tsutsui 
    158       1.1  tsutsui /* filesystem ops */
    159       1.1  tsutsui struct vnode;
    160       1.1  tsutsui int sysvbfs_bfs_init(struct bfs **, struct vnode *);
    161       1.1  tsutsui void sysvbfs_bfs_fini(struct bfs *);
    162       1.3  thorpej bool bfs_inode_lookup(const struct bfs *, ino_t, struct bfs_inode **);
    163       1.3  thorpej bool bfs_dirent_lookup_by_name(const struct bfs *, const char *,
    164       1.1  tsutsui     struct bfs_dirent **);
    165       1.3  thorpej bool bfs_dirent_lookup_by_inode(const struct bfs *, int,
    166       1.1  tsutsui     struct bfs_dirent **);
    167       1.1  tsutsui void bfs_inode_set_attr(const struct bfs *, struct bfs_inode *,
    168       1.1  tsutsui     const struct bfs_fileattr *attr);
    169       1.1  tsutsui int bfs_inode_alloc(const struct bfs *, struct bfs_inode **, int *,
    170       1.1  tsutsui     int *);
    171       1.1  tsutsui #endif /* _KERNEL || _STANDALONE */
    172       1.1  tsutsui #endif /* _FS_SYSVBFS_BFS_H_ */
    173