file.c revision 87867
119304Speter/* 219304Speter * Copyright (c) 2000, Boris Popov 319304Speter * All rights reserved. 419304Speter * 519304Speter * Redistribution and use in source and binary forms, with or without 619304Speter * modification, are permitted provided that the following conditions 719304Speter * are met: 819304Speter * 1. Redistributions of source code must retain the above copyright 919304Speter * notice, this list of conditions and the following disclaimer. 1019304Speter * 2. Redistributions in binary form must reproduce the above copyright 1119304Speter * notice, this list of conditions and the following disclaimer in the 1219304Speter * documentation and/or other materials provided with the distribution. 13254225Speter * 3. All advertising materials mentioning features or use of this software 1419304Speter * must display the following acknowledgement: 1519304Speter * This product includes software developed by Boris Popov. 1619304Speter * 4. Neither the name of the author nor the names of any co-contributors 1719304Speter * may be used to endorse or promote products derived from this software 1819304Speter * without specific prior written permission. 1919304Speter * 2019304Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2119304Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2219304Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2319304Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2419304Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2519304Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2619304Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2719304Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2819304Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2919304Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3019304Speter * SUCH DAMAGE. 3119304Speter * 3219304Speter * $Id: file.c,v 1.2 2001/04/16 04:33:01 bp Exp $ 3319304Speter */ 3419304Speter#include <sys/param.h> 3519304Speter#include <sys/sysctl.h> 3619304Speter#include <sys/ioctl.h> 3719304Speter#include <sys/time.h> 38254225Speter#include <sys/mount.h> 3919304Speter#include <fcntl.h> 4019304Speter#include <ctype.h> 4119304Speter#include <errno.h> 4219304Speter#include <stdio.h> 4319304Speter#include <string.h> 4419304Speter#include <stdlib.h> 4519304Speter#include <pwd.h> 4619304Speter#include <grp.h> 4719304Speter#include <unistd.h> 4819304Speter 4919304Speter#include <netsmb/smb_lib.h> 5019304Speter#include <netsmb/smb_conn.h> 5119304Speter#include <cflib.h> 5219304Speter 5319304Speterint 5419304Spetersmb_read(struct smb_ctx *ctx, smbfh fh, off_t offset, size_t count, char *dst) 5519304Speter{ 5619304Speter struct smbioc_rw rwrq; 5719304Speter 5819304Speter rwrq.ioc_fh = fh; 5919304Speter rwrq.ioc_base = dst; 6019304Speter rwrq.ioc_cnt = count; 6119304Speter rwrq.ioc_offset = offset; 6219304Speter if (ioctl(ctx->ct_fd, SMBIOC_READ, &rwrq) == -1) 6319304Speter return -1; 6419304Speter return rwrq.ioc_cnt; 6519304Speter} 6619304Speter 67254225Speterint 6819304Spetersmb_write(struct smb_ctx *ctx, smbfh fh, off_t offset, size_t count, 6919304Speter const char *src) 7019304Speter{ 7119304Speter struct smbioc_rw rwrq; 7219304Speter 7319304Speter rwrq.ioc_fh = fh; 7419304Speter (const char*)rwrq.ioc_base = src; 7519304Speter rwrq.ioc_cnt = count; 7619304Speter rwrq.ioc_offset = offset; 7719304Speter if (ioctl(ctx->ct_fd, SMBIOC_WRITE, &rwrq) == -1) 7819304Speter return -1; 7919304Speter return rwrq.ioc_cnt; 8019304Speter} 8119304Speter