xref: /freebsd/lib/libufs/libufs.h (revision 3416500aef140042c64bc149cb1ec6620483bc44)
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 structures.
35  */
36 
37 /*
38  * userland ufs disk.
39  */
40 struct uufsd {
41 	const char *d_name;	/* disk name */
42 	int d_ufs;		/* decimal UFS version */
43 	int d_fd;		/* raw device file descriptor */
44 	long d_bsize;		/* device bsize */
45 	ufs2_daddr_t d_sblock;	/* superblock location */
46 	struct csum *d_sbcsum;	/* Superblock summary info */
47 	caddr_t d_inoblock;	/* inode block */
48 	uint32_t d_inomin;	/* low inode (not ino_t for ABI compat) */
49 	uint32_t d_inomax;	/* high inode (not ino_t for ABI compat) */
50 	union {
51 		struct fs d_fs;	/* filesystem information */
52 		char d_sb[MAXBSIZE];
53 				/* superblock as buffer */
54 	} d_sbunion;
55 	union {
56 		struct cg d_cg;	/* cylinder group */
57 		char d_buf[MAXBSIZE];
58 				/* cylinder group storage */
59 	} d_cgunion;
60 	int d_ccg;		/* current cylinder group */
61 	int d_lcg;		/* last cylinder group (in d_cg) */
62 	const char *d_error;	/* human readable disk error */
63 	int d_mine;		/* internal flags */
64 #define	d_fs	d_sbunion.d_fs
65 #define	d_sb	d_sbunion.d_sb
66 #define	d_cg	d_cgunion.d_cg
67 };
68 
69 /*
70  * libufs macros (internal, non-exported).
71  */
72 #ifdef	_LIBUFS
73 /*
74  * Trace steps through libufs, to be used at entry and erroneous return.
75  */
76 static inline void
77 ERROR(struct uufsd *u, const char *str)
78 {
79 
80 #ifdef	_LIBUFS_DEBUGGING
81 	if (str != NULL) {
82 		fprintf(stderr, "libufs: %s", str);
83 		if (errno != 0)
84 			fprintf(stderr, ": %s", strerror(errno));
85 		fprintf(stderr, "\n");
86 	}
87 #endif
88 	if (u != NULL)
89 		u->d_error = str;
90 }
91 #endif	/* _LIBUFS */
92 
93 __BEGIN_DECLS
94 
95 /*
96  * libufs prototypes.
97  */
98 
99 /*
100  * block.c
101  */
102 ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t);
103 ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t);
104 int berase(struct uufsd *, ufs2_daddr_t, ufs2_daddr_t);
105 
106 /*
107  * cgroup.c
108  */
109 ufs2_daddr_t cgballoc(struct uufsd *);
110 int cgbfree(struct uufsd *, ufs2_daddr_t, long);
111 ino_t cgialloc(struct uufsd *);
112 int cgread(struct uufsd *);
113 int cgread1(struct uufsd *, int);
114 int cgwrite(struct uufsd *);
115 int cgwrite1(struct uufsd *, int);
116 
117 /*
118  * inode.c
119  */
120 int getino(struct uufsd *, void **, ino_t, int *);
121 int putino(struct uufsd *);
122 
123 /*
124  * sblock.c
125  */
126 int sbread(struct uufsd *);
127 int sbwrite(struct uufsd *, int);
128 
129 /*
130  * type.c
131  */
132 int ufs_disk_close(struct uufsd *);
133 int ufs_disk_fillout(struct uufsd *, const char *);
134 int ufs_disk_fillout_blank(struct uufsd *, const char *);
135 int ufs_disk_write(struct uufsd *);
136 
137 /*
138  * ffs_subr.c
139  */
140 void	ffs_clrblock(struct fs *, u_char *, ufs1_daddr_t);
141 void	ffs_clusteracct(struct fs *, struct cg *, ufs1_daddr_t, int);
142 void	ffs_fragacct(struct fs *, int, int32_t [], int);
143 int	ffs_isblock(struct fs *, u_char *, ufs1_daddr_t);
144 int	ffs_isfreeblock(struct fs *, u_char *, ufs1_daddr_t);
145 void	ffs_setblock(struct fs *, u_char *, ufs1_daddr_t);
146 
147 __END_DECLS
148 
149 #endif	/* __LIBUFS_H__ */
150