Add facility to read one, or a string of, cylinger groups.

This commit is contained in:
Juli Mallett 2003-01-19 01:31:26 +00:00
parent 0f38d8d9aa
commit 22ec2ef3bb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=109509
4 changed files with 87 additions and 1 deletions

View File

@ -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)

72
lib/libufs/cgroup.c Normal file
View File

@ -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;
}

View File

@ -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
*/

View File

@ -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;