1*9f988b79SJean-Baptiste Boric /* $NetBSD: v7fs.h,v 1.2 2011/07/16 12:35:40 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 #ifndef _V7FS_H_ 33*9f988b79SJean-Baptiste Boric /* 7th Edition of Unix(PDP-11) Filesystem definition. */ 34*9f988b79SJean-Baptiste Boric #define _V7FS_H_ 35*9f988b79SJean-Baptiste Boric #include <sys/types.h> 36*9f988b79SJean-Baptiste Boric #ifndef _KERNEL 37*9f988b79SJean-Baptiste Boric #include <inttypes.h> 38*9f988b79SJean-Baptiste Boric #endif 39*9f988b79SJean-Baptiste Boric /* 40*9f988b79SJean-Baptiste Boric * V7 File System 41*9f988b79SJean-Baptiste Boric * 42*9f988b79SJean-Baptiste Boric * +------------------ 43*9f988b79SJean-Baptiste Boric * |Boot block (512byte) sector [0] 44*9f988b79SJean-Baptiste Boric * | 45*9f988b79SJean-Baptiste Boric * +------------------ 46*9f988b79SJean-Baptiste Boric * |Super block (512byte) sector [1] 47*9f988b79SJean-Baptiste Boric * | 48*9f988b79SJean-Baptiste Boric * +------------------ 49*9f988b79SJean-Baptiste Boric * |v7fs_inode(64byte sector [2] 50*9f988b79SJean-Baptiste Boric * . 51*9f988b79SJean-Baptiste Boric * . 52*9f988b79SJean-Baptiste Boric * | 53*9f988b79SJean-Baptiste Boric * +------------------ 54*9f988b79SJean-Baptiste Boric * |data block sector [datablock_start_sector] 55*9f988b79SJean-Baptiste Boric * | 56*9f988b79SJean-Baptiste Boric * . 57*9f988b79SJean-Baptiste Boric * . 58*9f988b79SJean-Baptiste Boric * | 59*9f988b79SJean-Baptiste Boric * +------------------ 60*9f988b79SJean-Baptiste Boric * <- [sector volume_size] 61*9f988b79SJean-Baptiste Boric * 62*9f988b79SJean-Baptiste Boric * | 63*9f988b79SJean-Baptiste Boric * +------------------ volume size. 64*9f988b79SJean-Baptiste Boric * 65*9f988b79SJean-Baptiste Boric * Max volume size is 8GB (24bit daddr_t) 66*9f988b79SJean-Baptiste Boric * Max file size is ~1GB 67*9f988b79SJean-Baptiste Boric * 68*9f988b79SJean-Baptiste Boric */ 69*9f988b79SJean-Baptiste Boric 70*9f988b79SJean-Baptiste Boric /* V7 type. */ 71*9f988b79SJean-Baptiste Boric typedef uint16_t v7fs_ino_t; 72*9f988b79SJean-Baptiste Boric typedef uint32_t v7fs_daddr_t; 73*9f988b79SJean-Baptiste Boric typedef int32_t v7fs_time_t; 74*9f988b79SJean-Baptiste Boric typedef uint32_t v7fs_off_t; 75*9f988b79SJean-Baptiste Boric typedef uint16_t v7fs_dev_t; 76*9f988b79SJean-Baptiste Boric typedef uint16_t v7fs_mode_t; 77*9f988b79SJean-Baptiste Boric #define V7FS_DADDR_MAX 0x00ffffff 78*9f988b79SJean-Baptiste Boric #define V7FS_INODE_MAX 0xffff 79*9f988b79SJean-Baptiste Boric 80*9f988b79SJean-Baptiste Boric #define V7FS_BSIZE 512 81*9f988b79SJean-Baptiste Boric #define V7FS_BSHIFT 9 82*9f988b79SJean-Baptiste Boric #define V7FS_ROUND_BSIZE(x) \ 83*9f988b79SJean-Baptiste Boric ((((x) + (V7FS_BSIZE - 1)) & ~(V7FS_BSIZE - 1))) 84*9f988b79SJean-Baptiste Boric #define V7FS_TRUNC_BSIZE(x) ((x) & ~(V7FS_BSIZE - 1)) 85*9f988b79SJean-Baptiste Boric 86*9f988b79SJean-Baptiste Boric #define V7FS_RESIDUE_BSIZE(x) \ 87*9f988b79SJean-Baptiste Boric ((x) - ((((x) - 1) >> V7FS_BSHIFT) << V7FS_BSHIFT)) 88*9f988b79SJean-Baptiste Boric 89*9f988b79SJean-Baptiste Boric /* Disk location. */ 90*9f988b79SJean-Baptiste Boric #define V7FS_BOOTBLOCK_SECTOR 0 91*9f988b79SJean-Baptiste Boric #define V7FS_SUPERBLOCK_SECTOR 1 92*9f988b79SJean-Baptiste Boric #define V7FS_ILIST_SECTOR 2 93*9f988b79SJean-Baptiste Boric 94*9f988b79SJean-Baptiste Boric /* Superblock */ 95*9f988b79SJean-Baptiste Boric /* cache. */ 96*9f988b79SJean-Baptiste Boric #define V7FS_MAX_FREEBLOCK 50 97*9f988b79SJean-Baptiste Boric #define V7FS_MAX_FREEINODE 100 98*9f988b79SJean-Baptiste Boric struct v7fs_superblock { 99*9f988b79SJean-Baptiste Boric /* [3 ... (datablock_start_sector-1)]are ilist */ 100*9f988b79SJean-Baptiste Boric uint16_t datablock_start_sector; 101*9f988b79SJean-Baptiste Boric v7fs_daddr_t volume_size; 102*9f988b79SJean-Baptiste Boric int16_t nfreeblock; /* # of freeblock in superblock cache. */ 103*9f988b79SJean-Baptiste Boric v7fs_daddr_t freeblock[V7FS_MAX_FREEBLOCK]; /* cache. */ 104*9f988b79SJean-Baptiste Boric int16_t nfreeinode; /* # of free inode in superblock cache. */ 105*9f988b79SJean-Baptiste Boric v7fs_ino_t freeinode[V7FS_MAX_FREEINODE]; /* cache. */ 106*9f988b79SJean-Baptiste Boric int8_t lock_freeblock; 107*9f988b79SJean-Baptiste Boric int8_t lock_freeinode; 108*9f988b79SJean-Baptiste Boric int8_t modified; 109*9f988b79SJean-Baptiste Boric int8_t readonly; 110*9f988b79SJean-Baptiste Boric v7fs_time_t update_time; 111*9f988b79SJean-Baptiste Boric v7fs_daddr_t total_freeblock; 112*9f988b79SJean-Baptiste Boric v7fs_ino_t total_freeinode; 113*9f988b79SJean-Baptiste Boric } __packed; 114*9f988b79SJean-Baptiste Boric 115*9f988b79SJean-Baptiste Boric /* Datablock */ 116*9f988b79SJean-Baptiste Boric #define V7FS_NADDR 13 117*9f988b79SJean-Baptiste Boric #define V7FS_NADDR_DIRECT 10 118*9f988b79SJean-Baptiste Boric #define V7FS_NADDR_INDEX1 10 119*9f988b79SJean-Baptiste Boric #define V7FS_NADDR_INDEX2 11 120*9f988b79SJean-Baptiste Boric #define V7FS_NADDR_INDEX3 12 121*9f988b79SJean-Baptiste Boric /* daddr index. */ 122*9f988b79SJean-Baptiste Boric #define V7FS_DADDR_PER_BLOCK (V7FS_BSIZE / sizeof(v7fs_daddr_t)) 123*9f988b79SJean-Baptiste Boric struct v7fs_freeblock { 124*9f988b79SJean-Baptiste Boric int16_t nfreeblock; 125*9f988b79SJean-Baptiste Boric v7fs_daddr_t freeblock[V7FS_MAX_FREEBLOCK]; 126*9f988b79SJean-Baptiste Boric } __packed; 127*9f988b79SJean-Baptiste Boric 128*9f988b79SJean-Baptiste Boric 129*9f988b79SJean-Baptiste Boric /* Dirent */ 130*9f988b79SJean-Baptiste Boric #define V7FS_NAME_MAX 14 131*9f988b79SJean-Baptiste Boric #define V7FS_PATH_MAX PATH_MAX /* No V7 limit. */ 132*9f988b79SJean-Baptiste Boric #define V7FS_LINK_MAX LINK_MAX /* No V7 limit. */ 133*9f988b79SJean-Baptiste Boric struct v7fs_dirent { 134*9f988b79SJean-Baptiste Boric v7fs_ino_t inode_number; 135*9f988b79SJean-Baptiste Boric char name[V7FS_NAME_MAX]; 136*9f988b79SJean-Baptiste Boric } __packed; /*16byte */ 137*9f988b79SJean-Baptiste Boric 138*9f988b79SJean-Baptiste Boric /* Inode */ 139*9f988b79SJean-Baptiste Boric #define V7FS_BALBLK_INODE 1 /* monument */ 140*9f988b79SJean-Baptiste Boric #define V7FS_ROOT_INODE 2 141*9f988b79SJean-Baptiste Boric #define V7FS_MAX_INODE(s) \ 142*9f988b79SJean-Baptiste Boric (((s)->datablock_start_sector - V7FS_ILIST_SECTOR) * \ 143*9f988b79SJean-Baptiste Boric V7FS_BSIZE / sizeof(struct v7fs_inode_diskimage)) 144*9f988b79SJean-Baptiste Boric #define V7FS_INODE_PER_BLOCK \ 145*9f988b79SJean-Baptiste Boric (V7FS_BSIZE / sizeof(struct v7fs_inode_diskimage)) 146*9f988b79SJean-Baptiste Boric #define V7FS_ILISTBLK_MAX (V7FS_INODE_MAX / V7FS_INODE_PER_BLOCK) 147*9f988b79SJean-Baptiste Boric 148*9f988b79SJean-Baptiste Boric struct v7fs_inode_diskimage { 149*9f988b79SJean-Baptiste Boric int16_t mode; 150*9f988b79SJean-Baptiste Boric int16_t nlink; /* [DIR] # of child directories. [REG] link count. */ 151*9f988b79SJean-Baptiste Boric int16_t uid; 152*9f988b79SJean-Baptiste Boric int16_t gid; 153*9f988b79SJean-Baptiste Boric v7fs_off_t filesize; /* byte */ 154*9f988b79SJean-Baptiste Boric #define V7FS_DINODE_ADDR_LEN 40 155*9f988b79SJean-Baptiste Boric /* 39 used; 13 addresses of 3 byte each. */ 156*9f988b79SJean-Baptiste Boric uint8_t addr[V7FS_DINODE_ADDR_LEN]; 157*9f988b79SJean-Baptiste Boric /*for device node: addr[0] is major << 8 | minor. */ 158*9f988b79SJean-Baptiste Boric v7fs_time_t atime; 159*9f988b79SJean-Baptiste Boric v7fs_time_t mtime; 160*9f988b79SJean-Baptiste Boric v7fs_time_t ctime; 161*9f988b79SJean-Baptiste Boric } __packed; /*64byte */ 162*9f988b79SJean-Baptiste Boric 163*9f988b79SJean-Baptiste Boric /* File type */ 164*9f988b79SJean-Baptiste Boric #define V7FS_IFMT 0170000 /* File type mask */ 165*9f988b79SJean-Baptiste Boric #define V7FS_IFCHR 0020000 /* charcter device */ 166*9f988b79SJean-Baptiste Boric #define V7FS_IFDIR 0040000 /* directory */ 167*9f988b79SJean-Baptiste Boric #define V7FS_IFBLK 0060000 /* block device */ 168*9f988b79SJean-Baptiste Boric #define V7FS_IFREG 0100000 /* file. */ 169*9f988b79SJean-Baptiste Boric /* Obsoleted file type. */ 170*9f988b79SJean-Baptiste Boric #define V7FS_IFMPC 0030000 /* multiplexed char special */ 171*9f988b79SJean-Baptiste Boric #define V7FS_IFMPB 0070000 /* multiplexed block special */ 172*9f988b79SJean-Baptiste Boric /* Don't apear original V7 filesystem. Found at 2.10BSD. */ 173*9f988b79SJean-Baptiste Boric #define V7FSBSD_IFLNK 0120000 /* symbolic link */ 174*9f988b79SJean-Baptiste Boric #define V7FSBSD_IFSOCK 0140000 /* socket */ 175*9f988b79SJean-Baptiste Boric /* Don't apear original V7 filesystem. NetBSD. */ 176*9f988b79SJean-Baptiste Boric #define V7FSBSD_IFFIFO 0010000 /* Named pipe. */ 177*9f988b79SJean-Baptiste Boric 178*9f988b79SJean-Baptiste Boric #define V7FSBSD_MAXSYMLINKLEN V7FS_BSIZE 179*9f988b79SJean-Baptiste Boric 180*9f988b79SJean-Baptiste Boric #endif /*!_V7FS_H_ */ 181