aboutsummaryrefslogtreecommitdiff
path: root/lib/libufs/libufs.h
diff options
context:
space:
mode:
authorJuli Mallett <jmallett@FreeBSD.org>2002-07-01 01:45:03 +0000
committerJuli Mallett <jmallett@FreeBSD.org>2002-07-01 01:45:03 +0000
commit20938dbf843569a50694a30c1fdf9c34d75bcbb8 (patch)
treed5ae23d585834242620eaad9e34fadb41eecfb56 /lib/libufs/libufs.h
parent101d16a80f3880cb09fbc0cc09d6b352bc885cad (diff)
downloadsrc-20938dbf843569a50694a30c1fdf9c34d75bcbb8.tar.gz
src-20938dbf843569a50694a30c1fdf9c34d75bcbb8.zip
Add libufs, a library for dealing with UFS filesystems from userland to
the build. It is here to compartmentalise functionality currently duplicated in many notable programs in the base system. It currently handles block reads and writes, as well as reading and writing of the filesystem superblock, and the reading/lookup of inode data. It supports both UFS and UFS2. I will be maintaining it, and porting programs to use it, however for now, it is simply being built as part of world.
Notes
Notes: svn path=/head/; revision=99193
Diffstat (limited to 'lib/libufs/libufs.h')
-rw-r--r--lib/libufs/libufs.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/lib/libufs/libufs.h b/lib/libufs/libufs.h
new file mode 100644
index 000000000000..0a5a67db4fa9
--- /dev/null
+++ b/lib/libufs/libufs.h
@@ -0,0 +1,104 @@
+/*
+ * 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$
+ */
+
+/*
+ * 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;
+#define d_fs d_sbunion.d_fs
+#define d_sb d_sbunion.d_sb
+};
+
+/*
+ * 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);
+
+/*
+ * 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 *);