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