1 /* $NetBSD: bfs.h,v 1.4 2007/12/25 18:33:44 perry Exp $ */
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #ifndef _FS_SYSVBFS_BFS_H_
33 #define _FS_SYSVBFS_BFS_H_
38 * |bfs_super_block (512byte)
42 * |bfs_inode (64byte) * 8
45 * +---------- <--- bfs_super_block.header.data_start
50 * +---------- <--- bfs_super_block.header.data_end
53 /* BFS specification */
54 #define BFS_SECTOR 0 /* no offset */
55 #define BFS_MAGIC 0x1badface
56 #define BFS_FILENAME_MAXLEN 14
57 #define BFS_ROOT_INODE 2
61 struct bfs_super_block_header
{
63 uint32_t data_start_byte
;
64 uint32_t data_end_byte
;
67 struct bfs_compaction
{
84 } __packed
; /* 48byte */
87 uint16_t number
; /* 0 */
89 uint32_t start_sector
; /* 4 */
90 uint32_t end_sector
; /* 8 */
91 uint32_t eof_offset_byte
; /* 12 (offset from super block start) */
92 struct bfs_fileattr attr
; /* 16 */
93 } __packed
; /* 64byte */
95 struct bfs_super_block
{
96 struct bfs_super_block_header header
;
97 struct bfs_compaction compaction
;
100 int32_t padding
[118];
105 char name
[BFS_FILENAME_MAXLEN
];
106 } __packed
; /* 16byte */
108 #if defined _KERNEL || defined _STANDALONE
109 /* Software definition */
110 struct sector_io_ops
;
114 struct bfs_super_block
*super_block
;
115 size_t super_block_size
;
118 uint32_t data_start
, data_end
;
121 struct bfs_inode
*inode
;
126 struct bfs_dirent
*dirent
;
130 struct bfs_inode
*root_inode
;
132 /* Sector I/O operation */
133 struct sector_io_ops
*io
;
138 struct sector_io_ops
{
139 bool (*read
)(void *, uint8_t *, daddr_t
);
140 bool (*read_n
)(void *, uint8_t *, daddr_t
, int);
141 bool (*write
)(void *, uint8_t *, daddr_t
);
142 bool (*write_n
)(void *, uint8_t *, daddr_t
, int);
145 int bfs_init2(struct bfs
**, int, struct sector_io_ops
*, bool);
146 void bfs_fini(struct bfs
*);
147 int bfs_file_read(const struct bfs
*, const char *, void *, size_t, size_t *);
148 int bfs_file_write(struct bfs
*, const char *, void *, size_t);
149 int bfs_file_create(struct bfs
*, const char *, void *, size_t,
150 const struct bfs_fileattr
*);
151 int bfs_file_delete(struct bfs
*, const char *);
152 int bfs_file_rename(struct bfs
*, const char *, const char *);
153 bool bfs_file_lookup(const struct bfs
*, const char *, int *, int *,
155 size_t bfs_file_size(const struct bfs_inode
*);
156 bool bfs_dump(const struct bfs
*);
160 int sysvbfs_bfs_init(struct bfs
**, struct vnode
*);
161 void sysvbfs_bfs_fini(struct bfs
*);
162 bool bfs_inode_lookup(const struct bfs
*, ino_t
, struct bfs_inode
**);
163 bool bfs_dirent_lookup_by_name(const struct bfs
*, const char *,
164 struct bfs_dirent
**);
165 bool bfs_dirent_lookup_by_inode(const struct bfs
*, int,
166 struct bfs_dirent
**);
167 void bfs_inode_set_attr(const struct bfs
*, struct bfs_inode
*,
168 const struct bfs_fileattr
*attr
);
169 int bfs_inode_alloc(const struct bfs
*, struct bfs_inode
**, int *,
171 #endif /* _KERNEL || _STANDALONE */
172 #endif /* _FS_SYSVBFS_BFS_H_ */