xref: /freebsd/lib/libufs/libufs.h (revision 8fc257994d0ce2396196d7a06d50d20c8015f4b7)
1 /*
2  * Copyright (c) 2002 Juli Mallett.  All rights reserved.
3  *
4  * This software was written by Juli Mallett <jmallett@FreeBSD.org> for the
5  * FreeBSD project.  Redistribution and use in source and binary forms, with
6  * or without modification, are permitted provided that the following
7  * conditions are met:
8  *
9  * 1. Redistribution of source code must retain the above copyright notice,
10  *    this list of conditions and the following disclaimer.
11  * 2. Redistribution in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 #ifndef	__LIBUFS_H__
31 #define	__LIBUFS_H__
32 
33 /*
34  * libufs macros (internal, non-exported).
35  */
36 #ifdef	_LIBUFS
37 #ifdef	_LIBUFS_DEBUGGING
38 /*
39  * Trace steps through libufs, to be used at entry and erroneous return.
40  */
41 #define	ERROR(uufsd, str)					\
42 do {								\
43 	fprintf(stderr, "libufs in %s", __func__);		\
44 	if (str != NULL)					\
45 		fprintf(stderr, ": %s", str);			\
46 	if (errno)						\
47 		fprintf(stderr, ": %s", strerror(errno));	\
48 	fprintf(stderr, "\n");					\
49 	if ((uufsd) != NULL)					\
50 		(uufsd)->d_error = str;				\
51 } while (0)
52 #else	/* _LIBUFS_DEBUGGING */
53 #define	ERROR(uufsd, str)					\
54 do {								\
55 	if ((uufsd) != NULL)					\
56 		(uufsd)->d_error = str;				\
57 } while (0)
58 #endif	/* _LIBUFS_DEBUGGING */
59 #endif	/* _LIBUFS */
60 
61 /*
62  * libufs structures.
63  */
64 
65 /*
66  * userland ufs disk.
67  */
68 struct uufsd {
69 	const char *d_name;	/* disk name */
70 	int d_ufs;		/* decimal UFS version */
71 	int d_fd;		/* raw device file descriptor */
72 	long d_bsize;		/* device bsize */
73 	ufs2_daddr_t d_sblock;	/* superblock location */
74 	struct csum *d_sbcsum;	/* Superblock summary info */
75 	caddr_t d_inoblock;	/* inode block */
76 	ino_t d_inomin;		/* low inode */
77 	ino_t d_inomax;		/* high inode */
78 	union {
79 		struct fs d_fs;	/* filesystem information */
80 		char d_sb[MAXBSIZE];
81 				/* superblock as buffer */
82 	} d_sbunion;
83 	union {
84 		struct cg d_cg;	/* cylinder group */
85 		char d_buf[MAXBSIZE];
86 				/* cylinder group storage */
87 	} d_cgunion;
88 	int d_ccg;		/* current cylinder group */
89 	int d_lcg;		/* last cylinder group (in d_cg) */
90 	const char *d_error;	/* human readable disk error */
91 	int d_mine;		/* internal flags */
92 #define	d_fs	d_sbunion.d_fs
93 #define	d_sb	d_sbunion.d_sb
94 #define	d_cg	d_cgunion.d_cg
95 };
96 
97 __BEGIN_DECLS
98 
99 /*
100  * libufs prototypes.
101  */
102 
103 /*
104  * block.c
105  */
106 ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t);
107 ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t);
108 int berase(struct uufsd *, ufs2_daddr_t, ufs2_daddr_t);
109 
110 /*
111  * cgroup.c
112  */
113 ufs2_daddr_t cgballoc(struct uufsd *);
114 int cgbfree(struct uufsd *, ufs2_daddr_t, long);
115 ino_t cgialloc(struct uufsd *);
116 int cgread(struct uufsd *);
117 int cgread1(struct uufsd *, int);
118 int cgwrite(struct uufsd *);
119 int cgwrite1(struct uufsd *, int);
120 
121 /*
122  * inode.c
123  */
124 int getino(struct uufsd *, void **, ino_t, int *);
125 int putino(struct uufsd *);
126 
127 /*
128  * sblock.c
129  */
130 int sbread(struct uufsd *);
131 int sbwrite(struct uufsd *, int);
132 
133 /*
134  * type.c
135  */
136 int ufs_disk_close(struct uufsd *);
137 int ufs_disk_fillout(struct uufsd *, const char *);
138 int ufs_disk_fillout_blank(struct uufsd *, const char *);
139 int ufs_disk_write(struct uufsd *);
140 
141 /*
142  * ffs_subr.c
143  */
144 void	ffs_clrblock(struct fs *, u_char *, ufs1_daddr_t);
145 void	ffs_clusteracct(struct fs *, struct cg *, ufs1_daddr_t, int);
146 void	ffs_fragacct(struct fs *, int, int32_t [], int);
147 int	ffs_isblock(struct fs *, u_char *, ufs1_daddr_t);
148 int	ffs_isfreeblock(struct fs *, u_char *, ufs1_daddr_t);
149 void	ffs_setblock(struct fs *, u_char *, ufs1_daddr_t);
150 
151 __END_DECLS
152 
153 #endif	/* __LIBUFS_H__ */
154