No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hp700 / stand / xxboot / readufs.h
blob9326d5c11a919ef9c49b7b1fae289449f1053392
1 /* $NetBSD: readufs.h,v 1.3 2005/12/11 12:17:25 christos Exp $ */
2 /* from Id: readufs.h,v 1.10 2003/12/16 13:54:11 itohy Exp */
4 /*
5 * Written in 1999, 2002, 2003 by ITOH Yasufumi (itohy@NetBSD.org).
6 * Public domain.
7 */
9 #include <sys/types.h>
10 #include <sys/param.h>
11 #include <ufs/ufs/dinode.h>
12 #include <ufs/ufs/dir.h>
15 * UFS1 / UFS2
17 union ufs_dinode {
18 #ifdef USE_UFS1
19 struct ufs1_dinode di1;
20 #endif
21 #ifdef USE_UFS2
22 struct ufs2_dinode di2;
23 #endif
26 /* For more compact code and independence on 64-bit types and ops */
27 typedef uint32_t ino32_t;
29 /* short-cut for common fields (di_mode, di_nlink) */
30 #ifdef USE_UFS1
31 # define di_common di1
32 #elif defined USE_UFS2
33 # define di_common di2
34 #endif
36 /* for fields of same names and different locations */
37 #if !(defined(USE_UFS1) && defined(USE_UFS2))
38 # ifdef USE_UFS1
39 # define di_thisver di1
40 # endif
41 # ifdef USE_UFS2
42 # define di_thisver di2
43 # endif
44 #endif
46 /* this is a size hack */
47 #if defined(USE_UFS1) && defined(USE_UFS2)
48 # define DI_SIZE(di) ((di)->di1.di_size)
49 #else
50 # define DI_SIZE(di) ((di)->di_thisver.di_size)
51 #endif
52 /* and may break following fields on UFS2 */
53 #define di_gid di_gid__is_not_available
54 #define di_blksize di_blksize__is_not_available
57 * filesystem information
59 struct ufs_info {
60 enum ufs_fstype {
61 UFSTYPE_UNKNOWN
62 #ifdef USE_FFS
63 , UFSTYPE_FFS
64 #endif
65 #ifdef USE_LFS
66 , UFSTYPE_LFS
67 #endif
68 } fstype;
69 #if defined(USE_UFS1) && defined(USE_UFS2)
70 enum ufs_ufstype {
71 UFSTYPE_UFS1, UFSTYPE_UFS2
72 } ufstype;
73 #endif
74 #if 0
75 int (*get_inode)(ino32_t ino, union ufs_dinode *dibuf);
76 #endif
78 /* superblock information */
79 u_int32_t bsize; /* fs block size */
80 u_int32_t nindir; /* # indirect per block */
81 u_int32_t fsbtodb; /* block -> sector shift count */
82 union {
83 #ifdef USE_FFS
84 struct {
85 daddr_t iblkno; /* inode-block offset */
86 int32_t old_cgoffset; /* cylinder group offset */
87 int32_t old_cgmask; /* cylinder group mask */
88 int32_t fragshift; /* block to fragmentation */
89 int32_t inopb; /* # inodes per block */
90 int32_t ipg; /* # inodes per group */
91 int32_t fpg; /* # inodes per group * frag */
92 int32_t magic; /* FS_UFSx_MAGIC */
93 } u_ffs;
94 #endif
95 #ifdef USE_LFS
96 struct {
97 u_int32_t version; /* LFS version # */
98 daddr_t idaddr; /* ifile inode disk address */
99 u_int32_t inopb; /* inodes per block (v1) */
100 /* inodes per frag (v2) */
101 u_int32_t ifpb; /* inode addrs / ifile block */
102 u_int32_t ioffset; /* start of inode in ifile */
103 /* (in sector) */
104 u_int32_t ibsize; /* size of inode block */
105 } u_lfs;
106 #endif
107 } fs_u;
110 extern struct ufs_info ufs_info;
112 int get_ffs_inode(ino32_t ino, union ufs_dinode *dibuf);
113 int get_lfs_inode(ino32_t ino, union ufs_dinode *dibuf);
114 #if defined(USE_FFS) && defined(USE_LFS)
115 #define ufs_get_inode(ino, di) ((ufs_info.fstype == UFSTYPE_FFS) ? \
116 get_ffs_inode((ino), (di)) : get_lfs_inode((ino), (di)))
117 #else
118 # ifdef USE_FFS
119 # define ufs_get_inode(ino, di) (get_ffs_inode((ino), (di)))
120 # endif
121 # ifdef USE_LFS
122 # define ufs_get_inode(ino, di) (get_lfs_inode((ino), (di)))
123 # endif
124 #endif
126 void RAW_READ(void *buf, daddr_t blkpos, size_t bytelen);
128 size_t ufs_read(union ufs_dinode *di, void *buf, unsigned off,
129 size_t count);
130 ino32_t ufs_lookup(ino32_t dirino, const char *fn);
131 ino32_t ufs_lookup_path(const char *path);
132 size_t ufs_load_file(void *buf, ino32_t dirino, const char *fn);
133 int ufs_init(void);
135 #ifdef USE_FFS
136 int try_ffs(void);
137 #endif
139 #ifdef USE_LFS
140 int try_lfs(void);
141 #endif
143 #ifdef DEBUG_WITH_STDIO
144 #include <fcntl.h>
145 #include <err.h>
146 #include <stdio.h>
147 #include <unistd.h>
148 #include <stdlib.h>
149 #endif
151 #ifdef __GNUC__
152 # ifndef alloca
153 # define alloca(n) __builtin_alloca(n)
154 # endif
155 # ifndef strcmp
156 # define strcmp(p, q) __builtin_strcmp(p, q)
157 # endif
158 #endif