v7fs_impl.h revision 1.1 1 1.1 uch /* $NetBSD: v7fs_impl.h,v 1.1 2011/06/27 11:52:25 uch Exp $ */
2 1.1 uch
3 1.1 uch /*-
4 1.1 uch * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 1.1 uch * All rights reserved.
6 1.1 uch *
7 1.1 uch * This code is derived from software contributed to The NetBSD Foundation
8 1.1 uch * by UCHIYAMA Yasushi.
9 1.1 uch *
10 1.1 uch * Redistribution and use in source and binary forms, with or without
11 1.1 uch * modification, are permitted provided that the following conditions
12 1.1 uch * are met:
13 1.1 uch * 1. Redistributions of source code must retain the above copyright
14 1.1 uch * notice, this list of conditions and the following disclaimer.
15 1.1 uch * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 uch * notice, this list of conditions and the following disclaimer in the
17 1.1 uch * documentation and/or other materials provided with the distribution.
18 1.1 uch *
19 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 uch * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 uch * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 uch * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 uch * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 uch * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 uch * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 uch * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 uch * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 uch * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 uch * POSSIBILITY OF SUCH DAMAGE.
30 1.1 uch */
31 1.1 uch
32 1.1 uch /* V7FS implementation. */
33 1.1 uch #ifndef _V7FS_IMPL_H_
34 1.1 uch #define _V7FS_IMPL_H_
35 1.1 uch
36 1.1 uch #ifndef _KERNEL
37 1.1 uch #include <stdbool.h>
38 1.1 uch #include <assert.h>
39 1.1 uch #define KDASSERT(x) assert(x)
40 1.1 uch #endif
41 1.1 uch
42 1.1 uch struct block_io_ops {
43 1.1 uch void *cookie;
44 1.1 uch bool (*drive)(void *, uint8_t);
45 1.1 uch bool (*read)(void *, uint8_t *, daddr_t);
46 1.1 uch bool (*read_n)(void *, uint8_t *, daddr_t, int);
47 1.1 uch bool (*write)(void *, uint8_t *, daddr_t);
48 1.1 uch bool (*write_n)(void *, uint8_t *, daddr_t, int);
49 1.1 uch };
50 1.1 uch
51 1.1 uch #ifdef V7FS_EI
52 1.1 uch struct endian_conversion_ops {
53 1.1 uch uint32_t (*conv32)(uint32_t);
54 1.1 uch uint16_t (*conv16)(uint16_t);
55 1.1 uch /* For daddr packing */
56 1.1 uch v7fs_daddr_t (*conv24read)(uint8_t *);
57 1.1 uch void (*conv24write)(v7fs_daddr_t, uint8_t *);
58 1.1 uch };
59 1.1 uch #endif
60 1.1 uch #ifdef _KERNEL
61 1.1 uch #define V7FS_LOCK
62 1.1 uch #endif
63 1.1 uch #ifdef V7FS_LOCK
64 1.1 uch struct lock_ops {
65 1.1 uch void *cookie;
66 1.1 uch void (*lock)(void*);
67 1.1 uch void (*unlock)(void *);
68 1.1 uch };
69 1.1 uch #define SUPERB_LOCK(x) ((x)->sb_lock.lock((x)->sb_lock.cookie))
70 1.1 uch #define SUPERB_UNLOCK(x) ((x)->sb_lock.unlock((x)->sb_lock.cookie))
71 1.1 uch #define ILIST_LOCK(x) ((x)->ilist_lock.lock((x)->ilist_lock.cookie))
72 1.1 uch #define ILIST_UNLOCK(x) ((x)->ilist_lock.unlock((x)->ilist_lock.cookie))
73 1.1 uch #define MEM_LOCK(x) ((x)->mem_lock.lock((x)->mem_lock.cookie))
74 1.1 uch #define MEM_UNLOCK(x) ((x)->mem_lock.unlock((x)->mem_lock.cookie))
75 1.1 uch #else /*V7FS_LOCK */
76 1.1 uch #define SUPERB_LOCK(x) ((void)0)
77 1.1 uch #define SUPERB_UNLOCK(x) ((void)0)
78 1.1 uch #define ILIST_LOCK(x) ((void)0)
79 1.1 uch #define ILIST_UNLOCK(x) ((void)0)
80 1.1 uch #define MEM_LOCK(x) ((void)0)
81 1.1 uch #define MEM_UNLOCK(x) ((void)0)
82 1.1 uch #endif /*V7FS_LOCK */
83 1.1 uch
84 1.1 uch struct v7fs_stat {
85 1.1 uch int32_t total_blocks;
86 1.1 uch int32_t free_blocks;
87 1.1 uch int32_t total_inode;
88 1.1 uch int32_t free_inode;
89 1.1 uch int32_t total_files;
90 1.1 uch };
91 1.1 uch
92 1.1 uch struct v7fs_fileattr {
93 1.1 uch int16_t uid;
94 1.1 uch int16_t gid;
95 1.1 uch v7fs_mode_t mode;
96 1.1 uch v7fs_dev_t device;
97 1.1 uch v7fs_time_t ctime;
98 1.1 uch v7fs_time_t mtime;
99 1.1 uch v7fs_time_t atime;
100 1.1 uch };
101 1.1 uch
102 1.1 uch struct v7fs_self {
103 1.1 uch #define V7FS_SELF_NSCRATCH 3
104 1.1 uch uint8_t scratch[V7FS_SELF_NSCRATCH][V7FS_BSIZE];
105 1.1 uch int scratch_free; /* free block bitmap. */
106 1.1 uch int scratch_remain; /* for statistic */
107 1.1 uch struct block_io_ops io;
108 1.1 uch #ifdef V7FS_EI
109 1.1 uch struct endian_conversion_ops val;
110 1.1 uch #endif
111 1.1 uch #ifdef V7FS_LOCK
112 1.1 uch /* in-core superblock access. (freeblock/freeinode) split? -uch */
113 1.1 uch struct lock_ops sb_lock;
114 1.1 uch struct lock_ops ilist_lock; /* disk ilist access. */
115 1.1 uch struct lock_ops mem_lock; /* work memory allocation lock. */
116 1.1 uch #endif
117 1.1 uch struct v7fs_superblock superblock;
118 1.1 uch struct v7fs_stat stat;
119 1.1 uch int endian;
120 1.1 uch };
121 1.1 uch
122 1.1 uch struct v7fs_mount_device {
123 1.1 uch union {
124 1.1 uch void *vnode; /* NetBSD kernel */
125 1.1 uch int fd; /* NetBSD newfs,fsck */
126 1.1 uch const char *filename;/* misc test */
127 1.1 uch } device;
128 1.1 uch daddr_t sectors; /*total size in sector. */
129 1.1 uch int endian;
130 1.1 uch };
131 1.1 uch
132 1.1 uch #define V7FS_ITERATOR_BREAK (-1)
133 1.1 uch #define V7FS_ITERATOR_END (-2)
134 1.1 uch #define V7FS_ITERATOR_ERROR (-3)
135 1.1 uch __BEGIN_DECLS
136 1.1 uch int v7fs_io_init(struct v7fs_self **, const struct v7fs_mount_device *, size_t);
137 1.1 uch void v7fs_io_fini(struct v7fs_self *);
138 1.1 uch void *scratch_read(struct v7fs_self *, daddr_t);
139 1.1 uch void scratch_free(struct v7fs_self *, void *);
140 1.1 uch int scratch_remain(const struct v7fs_self *);
141 1.1 uch __END_DECLS
142 1.1 uch
143 1.1 uch #if 0
144 1.1 uch #define V7FS_IO_DEBUG
145 1.1 uch #define V7FS_SUPERBLOCK_DEBUG
146 1.1 uch #define V7FS_DATABLOCK_DEBUG
147 1.1 uch #define V7FS_INODE_DEBUG
148 1.1 uch #define V7FS_DIRENT_DEBUG
149 1.1 uch #define V7FS_FILE_DEBUG
150 1.1 uch #define V7FS_VFSOPS_DEBUG
151 1.1 uch #define V7FS_VNOPS_DEBUG
152 1.1 uch #endif
153 1.1 uch
154 1.1 uch #endif /*!_V7FS_IMPL_H_ */
155