2015-03-28 22:24:04 +03:00
|
|
|
/* $NetBSD: bfs_sysvbfs.c,v 1.11 2015/03/28 19:24:05 maxv Exp $ */
|
2005-12-29 17:53:45 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2004 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by UCHIYAMA Yasushi.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``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 FOUNDATION OR CONTRIBUTORS
|
|
|
|
* 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>
|
|
|
|
|
2015-03-28 22:24:04 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: bfs_sysvbfs.c,v 1.11 2015/03/28 19:24:05 maxv Exp $");
|
2005-12-29 17:53:45 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/malloc.h>
|
2006-05-15 15:16:16 +04:00
|
|
|
#include <sys/kauth.h>
|
2005-12-29 17:53:45 +03:00
|
|
|
#include <fs/sysvbfs/bfs.h>
|
|
|
|
|
|
|
|
struct bc_io_ops {
|
|
|
|
struct sector_io_ops io;
|
|
|
|
struct vnode *vp;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t cred;
|
2005-12-29 17:53:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#define STATIC
|
|
|
|
|
2007-02-22 01:59:35 +03:00
|
|
|
STATIC bool bc_read_n(void *, uint8_t *, daddr_t, int);
|
|
|
|
STATIC bool bc_read(void *, uint8_t *, daddr_t);
|
|
|
|
STATIC bool bc_write_n(void *, uint8_t *, daddr_t, int);
|
|
|
|
STATIC bool bc_write(void *, uint8_t *, daddr_t);
|
2005-12-29 17:53:45 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
sysvbfs_bfs_init(struct bfs **bfsp, struct vnode *vp)
|
|
|
|
{
|
|
|
|
struct bc_io_ops *bio;
|
|
|
|
|
|
|
|
if ((bio = malloc(sizeof(*bio), M_TEMP, M_WAITOK | M_ZERO)) == NULL) {
|
|
|
|
printf("can't allocate I/O ops.\n");
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
bio->io.read = bc_read;
|
|
|
|
bio->io.read_n = bc_read_n;
|
|
|
|
bio->io.write = bc_write;
|
|
|
|
bio->io.write_n = bc_write_n;
|
|
|
|
bio->vp = vp;
|
|
|
|
bio->cred = NOCRED; /* sysvbfs layer check cred. */
|
|
|
|
|
2007-02-22 09:34:42 +03:00
|
|
|
return bfs_init2(bfsp, 0, (struct sector_io_ops *)bio, false);
|
2005-12-29 17:53:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sysvbfs_bfs_fini(struct bfs *bfs)
|
|
|
|
{
|
|
|
|
|
|
|
|
free(bfs->io, M_TEMP);
|
|
|
|
bfs_fini(bfs);
|
|
|
|
}
|
|
|
|
|
2007-02-22 01:59:35 +03:00
|
|
|
STATIC bool
|
2005-12-29 17:53:45 +03:00
|
|
|
bc_read_n(void *self, uint8_t *buf, daddr_t block, int count)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (!bc_read(self, buf, block))
|
2007-02-22 09:34:42 +03:00
|
|
|
return false;
|
2005-12-29 17:53:45 +03:00
|
|
|
buf += DEV_BSIZE;
|
|
|
|
block++;
|
|
|
|
}
|
|
|
|
|
2007-02-22 09:34:42 +03:00
|
|
|
return true;
|
2005-12-29 17:53:45 +03:00
|
|
|
}
|
|
|
|
|
2007-02-22 01:59:35 +03:00
|
|
|
STATIC bool
|
2005-12-29 17:53:45 +03:00
|
|
|
bc_read(void *self, uint8_t *buf, daddr_t block)
|
|
|
|
{
|
|
|
|
struct bc_io_ops *bio = self;
|
|
|
|
struct buf *bp = NULL;
|
|
|
|
|
2015-03-28 22:24:04 +03:00
|
|
|
if (bread(bio->vp, block, DEV_BSIZE, 0, &bp) != 0)
|
2005-12-29 17:53:45 +03:00
|
|
|
goto error_exit;
|
|
|
|
memcpy(buf, bp->b_data, DEV_BSIZE);
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(bp, 0);
|
2005-12-29 17:53:45 +03:00
|
|
|
|
2007-02-22 09:34:42 +03:00
|
|
|
return true;
|
2005-12-29 17:53:45 +03:00
|
|
|
error_exit:
|
2007-12-15 03:39:14 +03:00
|
|
|
printf("%s: block %lld read failed.\n", __func__,
|
2006-07-07 01:55:06 +04:00
|
|
|
(long long int)block);
|
2005-12-29 17:53:45 +03:00
|
|
|
|
|
|
|
if (bp != NULL)
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(bp, 0);
|
2007-02-22 09:34:42 +03:00
|
|
|
return false;
|
2005-12-29 17:53:45 +03:00
|
|
|
}
|
|
|
|
|
2007-02-22 01:59:35 +03:00
|
|
|
STATIC bool
|
2005-12-29 17:53:45 +03:00
|
|
|
bc_write_n(void *self, uint8_t *buf, daddr_t block, int count)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (!bc_write(self, buf, block))
|
2007-02-22 09:34:42 +03:00
|
|
|
return false;
|
2005-12-29 17:53:45 +03:00
|
|
|
buf += DEV_BSIZE;
|
|
|
|
block++;
|
|
|
|
}
|
|
|
|
|
2007-02-22 09:34:42 +03:00
|
|
|
return true;
|
2005-12-29 17:53:45 +03:00
|
|
|
}
|
|
|
|
|
2007-02-22 01:59:35 +03:00
|
|
|
STATIC bool
|
2005-12-29 17:53:45 +03:00
|
|
|
bc_write(void *self, uint8_t *buf, daddr_t block)
|
|
|
|
{
|
|
|
|
struct bc_io_ops *bio = self;
|
|
|
|
struct buf *bp;
|
|
|
|
|
|
|
|
#if 0
|
2007-12-15 03:39:14 +03:00
|
|
|
printf("%s: block=%lld\n", __func__, block);
|
2005-12-29 17:53:45 +03:00
|
|
|
#endif
|
|
|
|
if ((bp = getblk(bio->vp, block, DEV_BSIZE, 0, 0)) == 0) {
|
|
|
|
printf("getblk failed.\n");
|
2007-02-22 09:34:42 +03:00
|
|
|
return false;
|
2005-12-29 17:53:45 +03:00
|
|
|
}
|
|
|
|
memcpy(bp->b_data, buf, DEV_BSIZE);
|
|
|
|
|
|
|
|
if (bwrite(bp) != 0) {
|
|
|
|
printf("bwrite failed.\n");
|
2007-02-22 09:34:42 +03:00
|
|
|
return false;
|
2005-12-29 17:53:45 +03:00
|
|
|
}
|
|
|
|
|
2007-02-22 09:34:42 +03:00
|
|
|
return true;
|
2005-12-29 17:53:45 +03:00
|
|
|
}
|