From 22ec2ef3bb873d7d4cb5c36da6a65069fa2ee871 Mon Sep 17 00:00:00 2001 From: Juli Mallett Date: Sun, 19 Jan 2003 01:31:26 +0000 Subject: [PATCH] Add facility to read one, or a string of, cylinger groups. --- lib/libufs/Makefile | 2 +- lib/libufs/cgroup.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ lib/libufs/libufs.h | 13 ++++++++ lib/libufs/type.c | 1 + 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 lib/libufs/cgroup.c diff --git a/lib/libufs/Makefile b/lib/libufs/Makefile index 0ac1a74611a6..f7a711d30735 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 000000000000..2948e618aeb6 --- /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 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +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 266f787421f6..996a4426bafa 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 @@ -97,6 +104,12 @@ __BEGIN_DECLS 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 */ diff --git a/lib/libufs/type.c b/lib/libufs/type.c index d3182d3f5403..ef07730f4fde 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;