[BACK]Return to bfs_sysvbfs.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / fs / sysvbfs

File: [cvs.NetBSD.org] / src / sys / fs / sysvbfs / bfs_sysvbfs.c (download)

Revision 1.11, Sat Mar 28 19:24:05 2015 UTC (6 years ago) by maxv
Branch: MAIN
CVS Tags: tls-maxphys-base-20171202, thorpej-futex-base, thorpej-futex, thorpej-cfargs-base, thorpej-cfargs, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, nick-nhusb-base-20170825, nick-nhusb-base-20170204, nick-nhusb-base-20161204, nick-nhusb-base-20161004, nick-nhusb-base-20160907, nick-nhusb-base-20160529, nick-nhusb-base-20160422, nick-nhusb-base-20160319, nick-nhusb-base-20151226, nick-nhusb-base-20150921, nick-nhusb-base-20150606, nick-nhusb-base-20150406, netbsd-9-base, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, matt-nb8-mediatek-base, matt-nb8-mediatek, localcount-20160914, jdolecek-ncq-base, jdolecek-ncq, isaki-audio2-base, isaki-audio2, is-mlppp-base, is-mlppp, bouyer-xenpvh-base2, bouyer-xenpvh-base1, bouyer-xenpvh-base, bouyer-xenpvh, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, ad-namecache-base3, ad-namecache-base2, ad-namecache-base1, ad-namecache-base, ad-namecache, HEAD
Changes since 1.10: +3 -3 lines

Remove the 'cred' argument from bread(). Remove a now unused var in
ffs_snapshot.c. Update the man page accordingly.

ok hannken@

/*	$NetBSD: bfs_sysvbfs.c,v 1.11 2015/03/28 19:24:05 maxv Exp $	*/

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

__KERNEL_RCSID(0, "$NetBSD: bfs_sysvbfs.c,v 1.11 2015/03/28 19:24:05 maxv Exp $");

#include <sys/param.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/buf.h>
#include <sys/malloc.h>
#include <sys/kauth.h>
#include <fs/sysvbfs/bfs.h>

struct bc_io_ops {
	struct sector_io_ops io;
	struct vnode *vp;
	kauth_cred_t cred;
};

#define	STATIC

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

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

	return bfs_init2(bfsp, 0, (struct sector_io_ops *)bio, false);
}

void
sysvbfs_bfs_fini(struct bfs *bfs)
{

	free(bfs->io, M_TEMP);
	bfs_fini(bfs);
}

STATIC bool
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))
			return false;
		buf += DEV_BSIZE;
		block++;
	}

	return true;
}

STATIC bool
bc_read(void *self, uint8_t *buf, daddr_t block)
{
	struct bc_io_ops *bio = self;
	struct buf *bp = NULL;

	if (bread(bio->vp, block, DEV_BSIZE, 0, &bp) != 0)
		goto error_exit;
	memcpy(buf, bp->b_data, DEV_BSIZE);
	brelse(bp, 0);

	return true;
 error_exit:
	printf("%s: block %lld read failed.\n", __func__, 
	    (long long int)block);

	if (bp != NULL)
		brelse(bp, 0);
	return false;
}

STATIC bool
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))
			return false;
		buf += DEV_BSIZE;
		block++;
	}

	return true;
}

STATIC bool
bc_write(void *self, uint8_t *buf, daddr_t block)
{
	struct bc_io_ops *bio = self;
	struct buf *bp;

#if 0
	printf("%s: block=%lld\n", __func__, block);
#endif
	if ((bp = getblk(bio->vp, block, DEV_BSIZE, 0, 0)) == 0) {
		printf("getblk failed.\n");
		return false;
	}
	memcpy(bp->b_data, buf, DEV_BSIZE);

	if (bwrite(bp) != 0) {
		printf("bwrite failed.\n");
		return false;
	}

	return true;
}