1 /* $NetBSD: v7fs.h,v 1.2 2011/07/16 12:35:40 uch Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 /* 7th Edition of Unix(PDP-11) Filesystem definition. */
35 #include <sys/types.h>
43 * |Boot block (512byte) sector [0]
46 * |Super block (512byte) sector [1]
49 * |v7fs_inode(64byte sector [2]
54 * |data block sector [datablock_start_sector]
60 * <- [sector volume_size]
63 * +------------------ volume size.
65 * Max volume size is 8GB (24bit daddr_t)
66 * Max file size is ~1GB
71 typedef uint16_t v7fs_ino_t
;
72 typedef uint32_t v7fs_daddr_t
;
73 typedef int32_t v7fs_time_t
;
74 typedef uint32_t v7fs_off_t
;
75 typedef uint16_t v7fs_dev_t
;
76 typedef uint16_t v7fs_mode_t
;
77 #define V7FS_DADDR_MAX 0x00ffffff
78 #define V7FS_INODE_MAX 0xffff
80 #define V7FS_BSIZE 512
82 #define V7FS_ROUND_BSIZE(x) \
83 ((((x) + (V7FS_BSIZE - 1)) & ~(V7FS_BSIZE - 1)))
84 #define V7FS_TRUNC_BSIZE(x) ((x) & ~(V7FS_BSIZE - 1))
86 #define V7FS_RESIDUE_BSIZE(x) \
87 ((x) - ((((x) - 1) >> V7FS_BSHIFT) << V7FS_BSHIFT))
90 #define V7FS_BOOTBLOCK_SECTOR 0
91 #define V7FS_SUPERBLOCK_SECTOR 1
92 #define V7FS_ILIST_SECTOR 2
96 #define V7FS_MAX_FREEBLOCK 50
97 #define V7FS_MAX_FREEINODE 100
98 struct v7fs_superblock
{
99 /* [3 ... (datablock_start_sector-1)]are ilist */
100 uint16_t datablock_start_sector
;
101 v7fs_daddr_t volume_size
;
102 int16_t nfreeblock
; /* # of freeblock in superblock cache. */
103 v7fs_daddr_t freeblock
[V7FS_MAX_FREEBLOCK
]; /* cache. */
104 int16_t nfreeinode
; /* # of free inode in superblock cache. */
105 v7fs_ino_t freeinode
[V7FS_MAX_FREEINODE
]; /* cache. */
106 int8_t lock_freeblock
;
107 int8_t lock_freeinode
;
110 v7fs_time_t update_time
;
111 v7fs_daddr_t total_freeblock
;
112 v7fs_ino_t total_freeinode
;
116 #define V7FS_NADDR 13
117 #define V7FS_NADDR_DIRECT 10
118 #define V7FS_NADDR_INDEX1 10
119 #define V7FS_NADDR_INDEX2 11
120 #define V7FS_NADDR_INDEX3 12
122 #define V7FS_DADDR_PER_BLOCK (V7FS_BSIZE / sizeof(v7fs_daddr_t))
123 struct v7fs_freeblock
{
125 v7fs_daddr_t freeblock
[V7FS_MAX_FREEBLOCK
];
130 #define V7FS_NAME_MAX 14
131 #define V7FS_PATH_MAX PATH_MAX /* No V7 limit. */
132 #define V7FS_LINK_MAX LINK_MAX /* No V7 limit. */
134 v7fs_ino_t inode_number
;
135 char name
[V7FS_NAME_MAX
];
136 } __packed
; /*16byte */
139 #define V7FS_BALBLK_INODE 1 /* monument */
140 #define V7FS_ROOT_INODE 2
141 #define V7FS_MAX_INODE(s) \
142 (((s)->datablock_start_sector - V7FS_ILIST_SECTOR) * \
143 V7FS_BSIZE / sizeof(struct v7fs_inode_diskimage))
144 #define V7FS_INODE_PER_BLOCK \
145 (V7FS_BSIZE / sizeof(struct v7fs_inode_diskimage))
146 #define V7FS_ILISTBLK_MAX (V7FS_INODE_MAX / V7FS_INODE_PER_BLOCK)
148 struct v7fs_inode_diskimage
{
150 int16_t nlink
; /* [DIR] # of child directories. [REG] link count. */
153 v7fs_off_t filesize
; /* byte */
154 #define V7FS_DINODE_ADDR_LEN 40
155 /* 39 used; 13 addresses of 3 byte each. */
156 uint8_t addr
[V7FS_DINODE_ADDR_LEN
];
157 /*for device node: addr[0] is major << 8 | minor. */
161 } __packed
; /*64byte */
164 #define V7FS_IFMT 0170000 /* File type mask */
165 #define V7FS_IFCHR 0020000 /* charcter device */
166 #define V7FS_IFDIR 0040000 /* directory */
167 #define V7FS_IFBLK 0060000 /* block device */
168 #define V7FS_IFREG 0100000 /* file. */
169 /* Obsoleted file type. */
170 #define V7FS_IFMPC 0030000 /* multiplexed char special */
171 #define V7FS_IFMPB 0070000 /* multiplexed block special */
172 /* Don't apear original V7 filesystem. Found at 2.10BSD. */
173 #define V7FSBSD_IFLNK 0120000 /* symbolic link */
174 #define V7FSBSD_IFSOCK 0140000 /* socket */
175 /* Don't apear original V7 filesystem. NetBSD. */
176 #define V7FSBSD_IFFIFO 0010000 /* Named pipe. */
178 #define V7FSBSD_MAXSYMLINKLEN V7FS_BSIZE
180 #endif /*!_V7FS_H_ */