LCOV - code coverage report
Current view: top level - source4/ntvfs/posix - pvfs_read.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 35 43 81.4 %
Date: 2024-02-28 12:06:22 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    POSIX NTVFS backend - read
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2004
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             :    
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             :    
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "vfs_posix.h"
      24             : #include "lib/events/events.h"
      25             : 
      26             : /*
      27             :   read from a file
      28             : */
      29       35704 : NTSTATUS pvfs_read(struct ntvfs_module_context *ntvfs,
      30             :                    struct ntvfs_request *req, union smb_read *rd)
      31             : {
      32       35704 :         struct pvfs_state *pvfs = talloc_get_type(ntvfs->private_data,
      33             :                                   struct pvfs_state);
      34           0 :         ssize_t ret;
      35           0 :         struct pvfs_file *f;
      36           0 :         NTSTATUS status;
      37           0 :         uint32_t maxcnt;
      38           0 :         uint32_t mask;
      39             : 
      40       35704 :         if (rd->generic.level != RAW_READ_READX) {
      41         334 :                 return ntvfs_map_read(ntvfs, req, rd);
      42             :         }
      43             : 
      44       35370 :         f = pvfs_find_fd(pvfs, req, rd->readx.in.file.ntvfs);
      45       35370 :         if (!f) {
      46           0 :                 return NT_STATUS_INVALID_HANDLE;
      47             :         }
      48             : 
      49       35370 :         if (f->handle->fd == -1) {
      50           4 :                 return NT_STATUS_INVALID_DEVICE_REQUEST;
      51             :         }
      52             : 
      53       35366 :         mask = SEC_FILE_READ_DATA;
      54       35366 :         if (rd->readx.in.read_for_execute) {
      55       16679 :                 mask |= SEC_FILE_EXECUTE;
      56             :         }
      57       35366 :         if (!(f->access_mask & mask)) {
      58       12641 :                 return NT_STATUS_ACCESS_DENIED;
      59             :         }
      60             : 
      61       22725 :         maxcnt = rd->readx.in.maxcnt;
      62       22725 :         if (maxcnt > 2*UINT16_MAX && req->ctx->protocol < PROTOCOL_SMB2_02) {
      63           0 :                 DEBUG(3,(__location__ ": Invalid SMB maxcnt 0x%x\n", maxcnt));
      64           0 :                 return NT_STATUS_INVALID_PARAMETER;
      65             :         }
      66             : 
      67       22725 :         status = pvfs_check_lock(pvfs, f, req->smbpid, 
      68             :                                  rd->readx.in.offset,
      69             :                                  maxcnt,
      70             :                                  READ_LOCK);
      71       22725 :         if (!NT_STATUS_IS_OK(status)) {
      72          14 :                 return status;
      73             :         }
      74             : 
      75       22711 :         if (f->handle->name->stream_name) {
      76          18 :                 ret = pvfs_stream_read(pvfs, f->handle, 
      77          18 :                                        rd->readx.out.data, maxcnt, rd->readx.in.offset);
      78             :         } else {
      79       22693 :                 ret = pread(f->handle->fd, 
      80       22693 :                             rd->readx.out.data, 
      81             :                             maxcnt,
      82       22693 :                             rd->readx.in.offset);
      83             :         }
      84       22711 :         if (ret == -1) {
      85           6 :                 return pvfs_map_errno(pvfs, errno);
      86             :         }
      87             : 
      88             :         /* only SMB2 honors mincnt */
      89       22705 :         if (req->ctx->protocol >= PROTOCOL_SMB2_02) {
      90         251 :                 if (rd->readx.in.mincnt > ret ||
      91           8 :                     (ret == 0 && maxcnt > 0)) {
      92           9 :                         return NT_STATUS_END_OF_FILE;
      93             :                 }
      94             :         }
      95             : 
      96       22696 :         f->handle->position = f->handle->seek_offset = rd->readx.in.offset + ret;
      97             : 
      98       22696 :         rd->readx.out.nread = ret;
      99       22696 :         rd->readx.out.remaining = 0xFFFF;
     100       22696 :         rd->readx.out.compaction_mode = 0; 
     101             : 
     102       22696 :         return NT_STATUS_OK;
     103             : }

Generated by: LCOV version 1.14