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