summaryrefslogtreecommitdiffstats
path: root/lib/libufs/libufs.h
blob: 6f7dc7eea5d1732045517c8c5801f0fccb4be224 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * Copyright (c) 2002 Juli Mallett.  All rights reserved.
 *
 * This software was written by Juli Mallett <jmallett@FreeBSD.org> for the
 * FreeBSD project.  Redistribution and use in source and binary forms, with
 * or without modification, are permitted provided that the following
 * conditions are met:
 *
 * 1. Redistribution of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistribution in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#ifndef	__LIBUFS_H__
#define	__LIBUFS_H__

/*
 * libufs macros (internal, non-exported).
 */
#ifdef	_LIBUFS
#ifdef	_LIBUFS_DEBUGGING
/*
 * Trace steps through libufs, to be used at entry and erroneous return.
 */
#define	DEBUG(str)						\
do {								\
	fprintf(stderr, "libufs in %s", __func__);		\
	if (str != NULL)					\
		fprintf(stderr, ": %s", str);			\
	if (errno)						\
		fprintf(stderr, ": %s", strerror(errno));	\
	fprintf(stderr, "\n");					\
} while (0)
#else	/* _LIBUFS_DEBUGGING */
#define	DEBUG(str)	/* nil */
#endif	/* _LIBUFS_DEBUGGING */
#endif	/* _LIBUFS */

/*
 * libufs structures.
 */

/*
 * userland ufs disk.
 */
struct uufsd {
	const char *d_name;	/* disk name */
	int d_ufs;		/* decimal UFS version */
	int d_fd;		/* raw device file descriptor */
	long d_bsize;		/* device bsize */
	ufs2_daddr_t d_sblock;	/* superblock location */
	caddr_t d_inoblock;	/* inode block */
	ino_t d_inomin;		/* low inode */
	ino_t d_inomax;		/* high inode */
	union {
		struct fs d_fs;	/* filesystem information */
		char d_sb[MAXBSIZE];
				/* superblock as buffer */
	} d_sbunion;
	const char *d_error;	/* human readable disk error */
#define	d_fs	d_sbunion.d_fs
#define	d_sb	d_sbunion.d_sb
};

__BEGIN_DECLS

/*
 * libufs prototypes.
 */

/*
 * block.c
 */
ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t);
ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t);

/*
 * error.c
 */
void libufs_printerror(struct uufsd *);

/*
 * inode.c
 */
int getino(struct uufsd *, void **, ino_t, int *);

/*
 * sblock.c
 */
int sbread(struct uufsd *);
int sbwrite(struct uufsd *, int);

/*
 * type.c
 */
struct uufsd *ufs_disk_ctor(const char *);
int ufs_disk_close(struct uufsd *);
void ufs_disk_dtor(struct uufsd **);
int ufs_disk_fillout(struct uufsd *, const char *);

__END_DECLS

#endif	/* __LIBUFS_H__ */
OpenPOWER on IntegriCloud