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 */
5 * Written in 1999, 2002, 2003 by ITOH Yasufumi (itohy@NetBSD.org).
10 #include <sys/param.h>
11 #include <ufs/ufs/dinode.h>
12 #include <ufs/ufs/dir.h>
19 struct ufs1_dinode di1
;
22 struct ufs2_dinode di2
;
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) */
31 # define di_common di1
32 #elif defined USE_UFS2
33 # define di_common di2
36 /* for fields of same names and different locations */
37 #if !(defined(USE_UFS1) && defined(USE_UFS2))
39 # define di_thisver di1
42 # define di_thisver di2
46 /* this is a size hack */
47 #if defined(USE_UFS1) && defined(USE_UFS2)
48 # define DI_SIZE(di) ((di)->di1.di_size)
50 # define DI_SIZE(di) ((di)->di_thisver.di_size)
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
69 #if defined(USE_UFS1) && defined(USE_UFS2)
71 UFSTYPE_UFS1
, UFSTYPE_UFS2
75 int (*get_inode
)(ino32_t ino
, union ufs_dinode
*dibuf
);
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 */
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 */
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 */
104 u_int32_t ibsize
; /* size of inode block */
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)))
119 # define ufs_get_inode(ino, di) (get_ffs_inode((ino), (di)))
122 # define ufs_get_inode(ino, di) (get_lfs_inode((ino), (di)))
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
,
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
);
143 #ifdef DEBUG_WITH_STDIO
153 # define alloca(n) __builtin_alloca(n)
156 # define strcmp(p, q) __builtin_strcmp(p, q)