diff options
author | Juli Mallett <jmallett@FreeBSD.org> | 2003-01-19 01:31:26 +0000 |
---|---|---|
committer | Juli Mallett <jmallett@FreeBSD.org> | 2003-01-19 01:31:26 +0000 |
commit | 22ec2ef3bb873d7d4cb5c36da6a65069fa2ee871 (patch) | |
tree | 46dc1db9007edc7cf4daa7a8c68bfcfaa1bf15ff | |
parent | 0f38d8d9aa5b98ad2adb300b6f5b600f570775c8 (diff) | |
download | src-22ec2ef3bb873d7d4cb5c36da6a65069fa2ee871.tar.gz src-22ec2ef3bb873d7d4cb5c36da6a65069fa2ee871.zip |
Add facility to read one, or a string of, cylinger groups.
Notes
Notes:
svn path=/head/; revision=109509
-rw-r--r-- | lib/libufs/Makefile | 2 | ||||
-rw-r--r-- | lib/libufs/cgroup.c | 72 | ||||
-rw-r--r-- | lib/libufs/libufs.h | 13 | ||||
-rw-r--r-- | lib/libufs/type.c | 1 |
4 files changed, 87 insertions, 1 deletions
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 <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 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 @@ -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 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; |