Print this page
    
NEX-1643 dtrace provider for smbsrv
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/uts/common/fs/smbsrv/smb_seek.c
          +++ new/usr/src/uts/common/fs/smbsrv/smb_seek.c
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  
    | 
      ↓ open down ↓ | 
    13 lines elided | 
    
      ↑ open up ↑ | 
  
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
       24 + *
       25 + * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
  24   26   */
  25   27  
  26   28  /*
  27   29   * The seek message is sent to set the current file pointer for FID.
  28   30   * This request should generally only be used by clients wishing to
  29   31   * find the size of a file, since all read and write requests include
  30   32   * the read or write file position as part of the SMB. This request
  31   33   * is inappropriate for large files, as the offsets specified are only
  32   34   * 32 bits.
  33   35   *
  34   36   * The CIFS/1.0 (1996) spec contains the following incomplete statement:
  35   37   *
  36   38   * "A seek which results in an Offset which can not be expressed
  37   39   *  in 32 bits returns the least significant."
  38   40   *
  39   41   * It would probably be a mistake to make an assumption about what this
  40   42   * statement means. So, for now, we return an error if the resultant
  41   43   * file offset is beyond the 32-bit limit.
  42   44   */
  43   45  
  44   46  #include <smbsrv/smb_kproto.h>
  45   47  
  46   48  
  47   49  /*
  48   50   * smb_com_seek
  49   51   *
  50   52   * Client Request                     Description
  51   53   * ================================== =================================
  52   54   * UCHAR WordCount;                   Count of parameter words = 4
  53   55   * USHORT Fid;                        File handle
  54   56   * USHORT Mode;                       Seek mode: 0, 1 or 2
  55   57   * LONG Offset;                       Relative offset
  56   58   * USHORT ByteCount;                  Count of data bytes = 0
  57   59   *
  58   60   * The starting point of the seek is set by Mode:
  59   61   *
  60   62   *      0  seek from start of file
  61   63   *      1  seek from current current position
  62   64   *      2  seek from end of file
  63   65   *
  64   66   * The "current position" reflects the offset plus data length specified in
  65   67   * the previous read, write or seek request, and the pointer set by this
  66   68   * command will be replaced by the offset specified in the next read, write
  67   69   * or seek command.
  68   70   *
  69   71   * Server Response                    Description
  70   72   * ================================== =================================
  71   73   * UCHAR WordCount;                   Count of parameter words = 2
  72   74   * ULONG Offset;                      Offset from start of file
  
    | 
      ↓ open down ↓ | 
    39 lines elided | 
    
      ↑ open up ↑ | 
  
  73   75   * USHORT ByteCount;                  Count of data bytes = 0
  74   76   *
  75   77   * The response returns the new file pointer in Offset, which is expressed
  76   78   * as the offset from the start of the file, and may be beyond the current
  77   79   * end of file. An attempt to seek before the start of the file sets the
  78   80   * current file pointer to the start of the file.
  79   81   */
  80   82  smb_sdrc_t
  81   83  smb_pre_seek(smb_request_t *sr)
  82   84  {
  83      -        DTRACE_SMB_1(op__Seek__start, smb_request_t *, sr);
       85 +        DTRACE_SMB_START(op__Seek, smb_request_t *, sr);
  84   86          return (SDRC_SUCCESS);
  85   87  }
  86   88  
  87   89  void
  88   90  smb_post_seek(smb_request_t *sr)
  89   91  {
  90      -        DTRACE_SMB_1(op__Seek__done, smb_request_t *, sr);
       92 +        DTRACE_SMB_DONE(op__Seek, smb_request_t *, sr);
  91   93  }
  92   94  
  93   95  smb_sdrc_t
  94   96  smb_com_seek(smb_request_t *sr)
  95   97  {
  96   98          ushort_t        mode;
  97   99          int32_t         off;
  98  100          uint32_t        off_ret;
  99  101          int             rc;
 100  102  
 101  103          if (smbsr_decode_vwv(sr, "wwl", &sr->smb_fid, &mode, &off) != 0)
 102  104                  return (SDRC_ERROR);
 103  105  
 104  106          smbsr_lookup_file(sr);
 105  107          if (sr->fid_ofile == NULL) {
 106  108                  smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
 107  109                  return (SDRC_ERROR);
 108  110          }
 109  111  
 110  112          sr->user_cr = smb_ofile_getcred(sr->fid_ofile);
 111  113  
 112  114          if ((rc = smb_ofile_seek(sr->fid_ofile, mode, off, &off_ret)) != 0) {
 113  115                  if (rc == EINVAL) {
 114  116                          smbsr_error(sr, 0, ERRDOS, ERRbadfunc);
 115  117                          return (SDRC_ERROR);
 116  118                  } else {
 117  119                          smbsr_error(sr, 0, ERRSRV, ERRerror);
 118  120                          return (SDRC_ERROR);
 119  121                  }
 120  122          }
 121  123  
 122  124          if (smbsr_encode_result(sr, 2, 0, "blw", 2, off_ret, 0))
 123  125                  return (SDRC_ERROR);
 124  126  
 125  127          return (SDRC_SUCCESS);
 126  128  }
  
    | 
      ↓ open down ↓ | 
    26 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX