Sync usage with man page.
[netbsd-mini2440.git] / sys / fs / sysvbfs / bfs.h
blob408c3e6ba28cf827a0e4f177675db5a15bd1db31
1 /* $NetBSD: bfs.h,v 1.4 2007/12/25 18:33:44 perry Exp $ */
3 /*-
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
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.
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_
35 * Boot File System
37 * +----------
38 * |bfs_super_block (512byte)
39 * | 1 sector
40 * |
41 * +----------
42 * |bfs_inode (64byte) * 8
43 * | . 1 sector
44 * |bfs_inode
45 * +---------- <--- bfs_super_block.header.data_start
46 * |DATA BLOCK
47 * | .
48 * | .
49 * |
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
58 #define BFS_BSIZE 512
59 #define BFS_BSHIFT 9
61 struct bfs_super_block_header {
62 uint32_t magic;
63 uint32_t data_start_byte;
64 uint32_t data_end_byte;
65 } __packed;
67 struct bfs_compaction {
68 uint32_t from;
69 uint32_t to;
70 uint32_t from_backup;
71 uint32_t to_backup;
72 } __packed;
74 struct bfs_fileattr {
75 uint32_t type;
76 uint32_t mode;
77 int32_t uid;
78 int32_t gid;
79 uint32_t nlink;
80 int32_t atime;
81 int32_t mtime;
82 int32_t ctime;
83 int32_t padding[4];
84 } __packed; /* 48byte */
86 struct bfs_inode {
87 uint16_t number; /* 0 */
88 int16_t padding;
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;
98 char fsname[6];
99 char volume[6];
100 int32_t padding[118];
101 } __packed;
103 struct bfs_dirent {
104 uint16_t inode;
105 char name[BFS_FILENAME_MAXLEN];
106 } __packed; /* 16byte */
108 #if defined _KERNEL || defined _STANDALONE
109 /* Software definition */
110 struct sector_io_ops;
111 struct bfs {
112 int start_sector;
113 /* Super block */
114 struct bfs_super_block *super_block;
115 size_t super_block_size;
117 /* Data block */
118 uint32_t data_start, data_end;
120 /* Inode */
121 struct bfs_inode *inode;
122 int n_inode;
123 int max_inode;
125 /* root directory */
126 struct bfs_dirent *dirent;
127 size_t dirent_size;
128 int n_dirent;
129 int max_dirent;
130 struct bfs_inode *root_inode;
132 /* Sector I/O operation */
133 struct sector_io_ops *io;
135 bool debug;
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 *,
154 size_t *);
155 size_t bfs_file_size(const struct bfs_inode *);
156 bool bfs_dump(const struct bfs *);
158 /* filesystem ops */
159 struct vnode;
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 *,
170 int *);
171 #endif /* _KERNEL || _STANDALONE */
172 #endif /* _FS_SYSVBFS_BFS_H_ */