187866Ssheldonh/*
287866Ssheldonh * Copyright (c) 2000, Boris Popov
387866Ssheldonh * All rights reserved.
487866Ssheldonh *
587866Ssheldonh * Redistribution and use in source and binary forms, with or without
687866Ssheldonh * modification, are permitted provided that the following conditions
787866Ssheldonh * are met:
887866Ssheldonh * 1. Redistributions of source code must retain the above copyright
987866Ssheldonh *    notice, this list of conditions and the following disclaimer.
1087866Ssheldonh * 2. Redistributions in binary form must reproduce the above copyright
1187866Ssheldonh *    notice, this list of conditions and the following disclaimer in the
1287866Ssheldonh *    documentation and/or other materials provided with the distribution.
1387866Ssheldonh * 3. All advertising materials mentioning features or use of this software
1487866Ssheldonh *    must display the following acknowledgement:
1587866Ssheldonh *    This product includes software developed by Boris Popov.
1687866Ssheldonh * 4. Neither the name of the author nor the names of any co-contributors
1787866Ssheldonh *    may be used to endorse or promote products derived from this software
1887866Ssheldonh *    without specific prior written permission.
1987866Ssheldonh *
2087866Ssheldonh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2187866Ssheldonh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2287866Ssheldonh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2387866Ssheldonh * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2487866Ssheldonh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2587866Ssheldonh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2687866Ssheldonh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2787866Ssheldonh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2887866Ssheldonh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2987866Ssheldonh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3087866Ssheldonh * SUCH DAMAGE.
3187866Ssheldonh *
3287866Ssheldonh * $Id: file.c,v 1.2 2001/04/16 04:33:01 bp Exp $
33132752Skan * $FreeBSD$
3487866Ssheldonh */
3587866Ssheldonh#include <sys/param.h>
3687866Ssheldonh#include <sys/sysctl.h>
3787866Ssheldonh#include <sys/ioctl.h>
3887866Ssheldonh#include <sys/time.h>
3987866Ssheldonh#include <sys/mount.h>
4087866Ssheldonh#include <fcntl.h>
4187866Ssheldonh#include <ctype.h>
4287866Ssheldonh#include <errno.h>
4387866Ssheldonh#include <stdio.h>
4487866Ssheldonh#include <string.h>
4587866Ssheldonh#include <stdlib.h>
4687866Ssheldonh#include <pwd.h>
4787866Ssheldonh#include <grp.h>
4887866Ssheldonh#include <unistd.h>
4987866Ssheldonh
5087866Ssheldonh#include <netsmb/smb_lib.h>
5187866Ssheldonh#include <netsmb/smb_conn.h>
5287866Ssheldonh#include <cflib.h>
5387866Ssheldonh
5487866Ssheldonhint
5587866Ssheldonhsmb_read(struct smb_ctx *ctx, smbfh fh, off_t offset, size_t count, char *dst)
5687866Ssheldonh{
5787866Ssheldonh	struct smbioc_rw rwrq;
5887866Ssheldonh
5987866Ssheldonh	rwrq.ioc_fh = fh;
6087866Ssheldonh	rwrq.ioc_base = dst;
6187866Ssheldonh	rwrq.ioc_cnt = count;
6287866Ssheldonh	rwrq.ioc_offset = offset;
6387866Ssheldonh	if (ioctl(ctx->ct_fd, SMBIOC_READ, &rwrq) == -1)
6487866Ssheldonh		return -1;
6587866Ssheldonh	return rwrq.ioc_cnt;
6687866Ssheldonh}
6787866Ssheldonh
6887866Ssheldonhint
6987866Ssheldonhsmb_write(struct smb_ctx *ctx, smbfh fh, off_t offset, size_t count,
7087866Ssheldonh	const char *src)
7187866Ssheldonh{
7287866Ssheldonh	struct smbioc_rw rwrq;
7387866Ssheldonh
7487866Ssheldonh	rwrq.ioc_fh = fh;
75132752Skan	rwrq.ioc_base = (char *)src;
7687866Ssheldonh	rwrq.ioc_cnt = count;
7787866Ssheldonh	rwrq.ioc_offset = offset;
7887866Ssheldonh	if (ioctl(ctx->ct_fd, SMBIOC_WRITE, &rwrq) == -1)
7987866Ssheldonh		return -1;
8087866Ssheldonh	return rwrq.ioc_cnt;
8187866Ssheldonh}
82