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