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/*
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
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
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#include <smbsrv/smb_kproto.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 */
7b59d02d2a384be9a08087b14defadd214b3c1ddjbsmb_sdrc_t
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_pre_seek(smb_request_t *sr)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb{
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb DTRACE_SMB_1(op__Seek__start, smb_request_t *, sr);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_SUCCESS);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb}
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbvoid
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_post_seek(smb_request_t *sr)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb{
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb DTRACE_SMB_1(op__Seek__done, smb_request_t *, sr);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb}
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_sdrc_t
faa1795a28a5c712eed6d0a3f84d98c368a316c6jbsmb_com_seek(smb_request_t *sr)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ushort_t mode;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int32_t off;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t off_ret;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int rc;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (smbsr_decode_vwv(sr, "wwl", &sr->smb_fid, &mode, &off) != 0)
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_ERROR);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego smbsr_lookup_file(sr);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (sr->fid_ofile == NULL) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_ERROR);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States sr->user_cr = smb_ofile_getcred(sr->fid_ofile);
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if ((rc = smb_ofile_seek(sr->fid_ofile, mode, off, &off_ret)) != 0) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as if (rc == EINVAL) {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, 0, ERRDOS, ERRbadfunc);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_ERROR);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as } else {
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as smbsr_error(sr, 0, ERRSRV, ERRerror);
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_ERROR);
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (smbsr_encode_result(sr, 2, 0, "blw", 2, off_ret, 0))
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_ERROR);
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb return (SDRC_SUCCESS);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}