Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / x68k / stand / boot_ufs / readufs.h
blob94b42aec3293554fe14f1598cc3611d8abb59d6d
1 /* $NetBSD: readufs.h,v 1.8 2005/12/11 12:19:44 christos Exp $ */
2 /* from Id: readufs.h,v 1.9 2003/10/15 14:16:58 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 int (*get_inode)(ino32_t ino, union ufs_dinode *dibuf);
76 /* superblock information */
77 u_int32_t bsize; /* fs block size */
78 u_int32_t nindir; /* # indirect per block */
79 u_int32_t fsbtodb; /* block -> sector shift count */
80 union {
81 #ifdef USE_FFS
82 struct {
83 daddr_t iblkno; /* inode-block offset */
84 int32_t old_cgoffset; /* cylinder group offset */
85 int32_t old_cgmask; /* cylinder group mask */
86 int32_t fragshift; /* block to fragmentation */
87 int32_t inopb; /* # inodes per block */
88 int32_t ipg; /* # inodes per group */
89 int32_t fpg; /* # inodes per group * frag */
90 int32_t magic; /* FS_UFSx_MAGIC */
91 } u_ffs;
92 #endif
93 #ifdef USE_LFS
94 struct {
95 u_int32_t version; /* LFS version # */
96 daddr_t idaddr; /* ifile inode disk address */
97 u_int32_t inopb; /* inodes per block (v1) */
98 /* inodes per frag (v2) */
99 u_int32_t ifpb; /* inode addrs / ifile block */
100 u_int32_t ioffset; /* start of inode in ifile */
101 /* (in sector) */
102 u_int32_t ibsize; /* size of inode block */
103 } u_lfs;
104 #endif
105 } fs_u;
108 extern struct ufs_info ufs_info;
109 #define ufs_get_inode(ino, di) ((*ufs_info.get_inode)((ino), (di)))
111 void RAW_READ(void *buf, daddr_t blkpos, size_t bytelen);
113 size_t ufs_read(union ufs_dinode *di, void *buf, unsigned off,
114 size_t count);
115 ino32_t ufs_lookup(ino32_t dirino, const char *fn);
116 ino32_t ufs_lookup_path(const char *path);
117 size_t ufs_load_file(void *buf, ino32_t dirino, const char *fn);
118 int ufs_init(void);
120 #ifdef USE_FFS
121 int try_ffs(void);
122 #endif
124 #ifdef USE_LFS
125 int try_lfs(void);
126 #endif
128 #ifdef DEBUG_WITH_STDIO
129 #include <fcntl.h>
130 #include <err.h>
131 #include <stdio.h>
132 #include <unistd.h>
133 #include <stdlib.h>
134 #endif
136 #ifdef __GNUC__
137 # ifndef alloca
138 # define alloca(n) __builtin_alloca(n)
139 # endif
140 # ifndef strcmp
141 # define strcmp(p, q) __builtin_strcmp(p, q)
142 # endif
143 #endif