summaryrefslogtreecommitdiffstats
path: root/lib/libufs
diff options
context:
space:
mode:
authorjmallett <jmallett@FreeBSD.org>2003-01-19 01:31:26 +0000
committerjmallett <jmallett@FreeBSD.org>2003-01-19 01:31:26 +0000
commit445adec218a00bb504836130a49e8ae3e1aa2af1 (patch)
tree46dc1db9007edc7cf4daa7a8c68bfcfaa1bf15ff /lib/libufs
parent8af24a10fdd1ff689c2d91440dad34dd07112831 (diff)
downloadFreeBSD-src-445adec218a00bb504836130a49e8ae3e1aa2af1.zip
FreeBSD-src-445adec218a00bb504836130a49e8ae3e1aa2af1.tar.gz
Add facility to read one, or a string of, cylinger groups.
Diffstat (limited to 'lib/libufs')
-rw-r--r--lib/libufs/Makefile2
-rw-r--r--lib/libufs/cgroup.c72
-rw-r--r--lib/libufs/libufs.h13
-rw-r--r--lib/libufs/type.c1
4 files changed, 87 insertions, 1 deletions
diff --git a/lib/libufs/Makefile b/lib/libufs/Makefile
index 0ac1a74..f7a711d 100644
--- a/lib/libufs/Makefile
+++ b/lib/libufs/Makefile
@@ -1,7 +1,7 @@
# $FreeBSD$
LIB= ufs
-SRCS= block.c inode.c sblock.c type.c
+SRCS= block.c cgroup.c inode.c sblock.c type.c
INCS= libufs.h
CFLAGS+= -I${.CURDIR} -D_LIBUFS
.if defined(LIBUFS_DEBUG)
diff --git a/lib/libufs/cgroup.c b/lib/libufs/cgroup.c
new file mode 100644
index 0000000..2948e61
--- /dev/null
+++ b/lib/libufs/cgroup.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2003 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <sys/disklabel.h>
+#include <sys/stat.h>
+
+#include <ufs/ufs/ufsmount.h>
+#include <ufs/ufs/dinode.h>
+#include <ufs/ffs/fs.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <libufs.h>
+
+int
+cgread(struct uufsd *disk)
+{
+ return cgread1(disk, disk->d_ccg++);
+}
+
+int
+cgread1(struct uufsd *disk, int c)
+{
+ struct fs *fs;
+ off_t ccg;
+
+ fs = &disk->d_fs;
+
+ if (c >= fs->fs_ncg) {
+ return 0;
+ }
+ ccg = fsbtodb(fs, cgtod(fs, c)) * disk->d_bsize;
+ if (bread(disk, fsbtodb(fs, cgtod(fs, c)), disk->d_cgunion.d_buf,
+ fs->fs_bsize) == -1) {
+ ERROR(disk, "unable to read cylinder group");
+ return -1;
+ }
+ return 1;
+}
diff --git a/lib/libufs/libufs.h b/lib/libufs/libufs.h
index 266f787..996a442 100644
--- a/lib/libufs/libufs.h
+++ b/lib/libufs/libufs.h
@@ -79,10 +79,17 @@ struct uufsd {
char d_sb[MAXBSIZE];
/* superblock as buffer */
} d_sbunion;
+ union {
+ struct cg d_cg; /* cylinder group */
+ char d_buf[MAXBSIZE];
+ /* cylinder group storage */
+ } d_cgunion;
+ int d_ccg; /* current cylinder group */
const char *d_error; /* human readable disk error */
int d_mine; /* internal flags */
#define d_fs d_sbunion.d_fs
#define d_sb d_sbunion.d_sb
+#define d_cg d_cgunion.d_cg
};
__BEGIN_DECLS
@@ -98,6 +105,12 @@ ssize_t bread(struct uufsd *, ufs2_daddr_t, void *, size_t);
ssize_t bwrite(struct uufsd *, ufs2_daddr_t, const void *, size_t);
/*
+ * cgroup.c
+ */
+int cgread(struct uufsd *);
+int cgread1(struct uufsd *, int);
+
+/*
* inode.c
*/
int getino(struct uufsd *, void **, ino_t, int *);
diff --git a/lib/libufs/type.c b/lib/libufs/type.c
index d3182d3..ef07730 100644
--- a/lib/libufs/type.c
+++ b/lib/libufs/type.c
@@ -141,6 +141,7 @@ again: if (stat(name, &st) < 0) {
}
disk->d_bsize = 1;
+ disk->d_ccg = 0;
disk->d_fd = fd;
disk->d_inoblock = NULL;
disk->d_inomin = 0;
OpenPOWER on IntegriCloud