libufs.h revision 105737
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: head/lib/libufs/libufs.h 105737 2002-10-22 19:25:58Z jmallett $
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	DEBUG(str)						\
42do {								\
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} while (0)
50#else	/* _LIBUFS_DEBUGGING */
51#define	DEBUG(str)	/* nil */
52#endif	/* _LIBUFS_DEBUGGING */
53#endif	/* _LIBUFS */
54
55/*
56 * libufs structures.
57 */
58
59/*
60 * userland ufs disk.
61 */
62struct uufsd {
63	const char *d_name;	/* disk name */
64	int d_ufs;		/* decimal UFS version */
65	int d_fd;		/* raw device file descriptor */
66	long d_bsize;		/* device bsize */
67	ufs2_daddr_t d_sblock;	/* superblock location */
68	caddr_t d_inoblock;	/* inode block */
69	ino_t d_inomin;		/* low inode */
70	ino_t d_inomax;		/* high inode */
71	union {
72		struct fs d_fs;	/* filesystem information */
73		char d_sb[MAXBSIZE];
74				/* superblock as buffer */
75	} d_sbunion;
76	const char *d_error;	/* human readable disk error */
77#define	d_fs	d_sbunion.d_fs
78#define	d_sb	d_sbunion.d_sb
79};
80
81__BEGIN_DECLS
82
83/*
84 * libufs prototypes.
85 */
86
87/*
88 * block.c
89 */
90ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t);
91ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t);
92
93/*
94 * error.c
95 */
96void libufs_printerror(struct uufsd *);
97
98/*
99 * inode.c
100 */
101int getino(struct uufsd *, void **, ino_t, int *);
102
103/*
104 * sblock.c
105 */
106int sbread(struct uufsd *);
107int sbwrite(struct uufsd *, int);
108
109/*
110 * type.c
111 */
112struct uufsd *ufs_disk_ctor(const char *);
113int ufs_disk_close(struct uufsd *);
114void ufs_disk_dtor(struct uufsd **);
115int ufs_disk_fillout(struct uufsd *, const char *);
116
117__END_DECLS
118
119#endif	/* __LIBUFS_H__ */
120