smb_seek.c revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or http://www.opensolaris.org/os/licensing.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#pragma ident "%Z%%M% %I% %E% SMI"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The seek message is sent to set the current file pointer for FID.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This request should generally only be used by clients wishing to
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * find the size of a file, since all read and write requests include
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the read or write file position as part of the SMB. This request
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is inappropriate for large files, as the offsets specified are only
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 32 bits.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The CIFS/1.0 (1996) spec contains the following incomplete statement:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * "A seek which results in an Offset which can not be expressed
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * in 32 bits returns the least significant."
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * It would probably be a mistake to make an assumption about what this
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * statement means. So, for now, we return an error if the resultant
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file offset is beyond the 32-bit limit.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <smbsrv/smb_incl.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_com_seek
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Client Request Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ================================== =================================
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR WordCount; Count of parameter words = 4
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT Fid; File handle
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT Mode; Seek mode: 0, 1 or 2
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * LONG Offset; Relative offset
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT ByteCount; Count of data bytes = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The starting point of the seek is set by Mode:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 0 seek from start of file
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 1 seek from current current position
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 2 seek from end of file
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The "current position" reflects the offset plus data length specified in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the previous read, write or seek request, and the pointer set by this
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * command will be replaced by the offset specified in the next read, write
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * or seek command.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Server Response Description
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ================================== =================================
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * UCHAR WordCount; Count of parameter words = 2
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * ULONG Offset; Offset from start of file
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * USHORT ByteCount; Count of data bytes = 0
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The response returns the new file pointer in Offset, which is expressed
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * as the offset from the start of the file, and may be beyond the current
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * end of file. An attempt to seek before the start of the file sets the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * current file pointer to the start of the file.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_com_seek(struct smb_request *sr)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ushort_t mode;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int32_t off;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t off_ret;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int rc;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (smbsr_decode_vwv(sr, "wwl", &sr->smb_fid, &mode, &off) != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_decode_error(sr);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw sr->fid_ofile = smb_ofile_lookup_by_fid(sr->tid_tree, sr->smb_fid);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (sr->fid_ofile == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_raise_cifs_error(sr, NT_STATUS_INVALID_HANDLE,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ERRDOS, ERRbadfid);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (mode == SMB_SEEK_END) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) smb_set_file_size(sr);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smb_ofile_seek(sr->fid_ofile, mode, off, &off_ret);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_encode_result(sr, 2, 0, "blw", 2, off_ret, 0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (SDRC_NORMAL_REPLY);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc == EINVAL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_raise_error(sr, ERRDOS, ERRbadfunc);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc == EOVERFLOW) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_raise_error(sr, ERRSRV, ERRerror);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ASSERT(0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw smbsr_raise_error(sr, ERRSRV, ERRerror);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* NOTREACHED */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Although smbsr_raise_error() doesn't return and the compiler is
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * told so in smb_kproto.h it still has a problem if it doesn't
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * find here a return instruction with a value.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}