LCOV - code coverage report
Current view: top level - source3/smbd - fd_handle.c (source / functions) Hit Total Coverage
Test: coverage report for master 6248eab5 Lines: 40 43 93.0 %
Date: 2021-08-25 13:27:56 Functions: 14 14 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    fd_handle structure handling
       4             :    Copyright (C) Ralph Boehme 2020
       5             : 
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             : 
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "fd_handle.h"
      21             : #include "fd_handle_private.h"
      22             : 
      23    10640748 : struct fd_handle *fd_handle_create(TALLOC_CTX *mem_ctx)
      24             : {
      25    10640748 :         struct fd_handle *fh = NULL;
      26             : 
      27    10640748 :         fh = talloc_zero(mem_ctx, struct fd_handle);
      28    10640748 :         if (fh == NULL) {
      29           0 :                 return NULL;
      30             :         }
      31    10640748 :         fh->fd = -1;
      32    10640748 :         return fh;
      33             : }
      34             : 
      35    21049820 : size_t fh_get_refcount(struct fd_handle *fh)
      36             : {
      37    21049820 :         return fh->ref_count;
      38             : }
      39             : 
      40    10580622 : void fh_set_refcount(struct fd_handle *fh, size_t ref_count)
      41             : {
      42    10580622 :         fh->ref_count = ref_count;
      43    10580622 : }
      44             : 
      45       25195 : uint64_t fh_get_position_information(struct fd_handle *fh)
      46             : {
      47       25195 :         return fh->position_information;
      48             : }
      49             : 
      50       15026 : void fh_set_position_information(struct fd_handle *fh, uint64_t posinfo)
      51             : {
      52       15026 :         fh->position_information = posinfo;
      53       15026 : }
      54             : 
      55       15920 : off_t fh_get_pos(struct fd_handle *fh)
      56             : {
      57       15920 :         return fh->pos;
      58             : }
      59             : 
      60      154318 : void fh_set_pos(struct fd_handle *fh, off_t pos)
      61             : {
      62      154318 :         fh->pos = pos;
      63      154318 : }
      64             : 
      65      434546 : uint32_t fh_get_private_options(struct fd_handle *fh)
      66             : {
      67      434546 :         return fh->private_options;
      68             : }
      69             : 
      70      454471 : void fh_set_private_options(struct fd_handle *fh, uint32_t private_options)
      71             : {
      72      454471 :         fh->private_options = private_options;
      73      454471 : }
      74             : 
      75     1657856 : uint64_t fh_get_gen_id(struct fd_handle *fh)
      76             : {
      77     1657856 :         return fh->gen_id;
      78             : }
      79             : 
      80    10580396 : void fh_set_gen_id(struct fd_handle *fh, uint64_t gen_id)
      81             : {
      82    10580396 :         fh->gen_id = gen_id;
      83    10580396 : }
      84             : 
      85             : /****************************************************************************
      86             :  Helper functions for working with fsp->fh->fd
      87             : ****************************************************************************/
      88             : 
      89     2576080 : int fsp_get_io_fd(const struct files_struct *fsp)
      90             : {
      91     2576080 :         if (fsp->fsp_flags.is_pathref) {
      92           0 :                 DBG_ERR("fsp [%s] is a path referencing fsp\n",
      93             :                         fsp_str_dbg(fsp));
      94             : #ifdef DEVELOPER
      95           0 :                 smb_panic("fsp is a pathref");
      96             : #endif
      97             :                 return -1;
      98             :         }
      99             : 
     100     2576080 :         return fsp->fh->fd;
     101             : }
     102             : 
     103   100157623 : int fsp_get_pathref_fd(const struct files_struct *fsp)
     104             : {
     105   100157623 :         return fsp->fh->fd;
     106             : }
     107             : 
     108    46141650 : void fsp_set_fd(struct files_struct *fsp, int fd)
     109             : {
     110             :         /*
     111             :          * Deliberatly allow setting an fd if the existing fd is the
     112             :          * same. This happens if a VFS module assigns the fd to
     113             :          * fsp->fh->fd in its openat VFS function. The canonical place
     114             :          * where the assignment is done is in fd_open(), but some VFS
     115             :          * modules do it anyway.
     116             :          */
     117             : 
     118    46141650 :         SMB_ASSERT(fsp->fh->fd == -1 ||
     119             :                    fsp->fh->fd == fd ||
     120             :                    fd == -1 ||
     121             :                    fd == AT_FDCWD);
     122             : 
     123    46141650 :         fsp->fh->fd = fd;
     124    46141650 : }

Generated by: LCOV version 1.13