LCOV - code coverage report
Current view: top level - source3/lib - file_id.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 40 42 95.2 %
Date: 2021-09-23 10:06:22 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    file_id structure handling
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2007
       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 "lib/file_id.h"
      24             : 
      25             : /*
      26             :   return True if two file_id structures are equal
      27             :  */
      28    40843365 : bool file_id_equal(const struct file_id *id1, const struct file_id *id2)
      29             : {
      30    41216378 :         return id1->inode == id2->inode && id1->devid == id2->devid &&
      31      373013 :             id1->extid == id2->extid;
      32             : }
      33             : 
      34    40257583 : char *file_id_str_buf(struct file_id fid, struct file_id_buf *dst)
      35             : {
      36    40257583 :         snprintf(dst->buf,
      37             :                  sizeof(dst->buf),
      38             :                  "%"PRIu64":%"PRIu64":%"PRIu64,
      39             :                  fid.devid,
      40             :                  fid.inode,
      41             :                  fid.extid);
      42    40257583 :         return dst->buf;
      43             : }
      44             : 
      45             : /*
      46             :   push a 16 byte version of a file id into a buffer.  This ignores the extid
      47             :   and is needed when dev/inodes are stored in persistent storage (tdbs).
      48             :  */
      49    50359871 : void push_file_id_16(char *buf, const struct file_id *id)
      50             : {
      51    50359871 :         SIVAL(buf,  0, id->devid&0xFFFFFFFF);
      52    50359871 :         SIVAL(buf,  4, id->devid>>32);
      53    50359871 :         SIVAL(buf,  8, id->inode&0xFFFFFFFF);
      54    50359871 :         SIVAL(buf, 12, id->inode>>32);
      55    50359871 : }
      56             : 
      57             : /*
      58             :   push a 24 byte version of a file id into a buffer
      59             :  */
      60           4 : void push_file_id_24(char *buf, const struct file_id *id)
      61             : {
      62           4 :         SIVAL(buf,  0, id->devid&0xFFFFFFFF);
      63           4 :         SIVAL(buf,  4, id->devid>>32);
      64           4 :         SIVAL(buf,  8, id->inode&0xFFFFFFFF);
      65           4 :         SIVAL(buf, 12, id->inode>>32);
      66           4 :         SIVAL(buf, 16, id->extid&0xFFFFFFFF);
      67           4 :         SIVAL(buf, 20, id->extid>>32);
      68           4 : }
      69             : 
      70             : /*
      71             :   pull a 24 byte version of a file id from a buffer
      72             :  */
      73           4 : void pull_file_id_24(const char *buf, struct file_id *id)
      74             : {
      75           4 :         ZERO_STRUCTP(id);
      76           4 :         id->devid  = IVAL(buf,  0);
      77           4 :         id->devid |= ((uint64_t)IVAL(buf,4))<<32;
      78           4 :         id->inode  = IVAL(buf,  8);
      79           4 :         id->inode |= ((uint64_t)IVAL(buf,12))<<32;
      80           4 :         id->extid  = IVAL(buf,  16);
      81           4 :         id->extid |= ((uint64_t)IVAL(buf,20))<<32;
      82           4 : }
      83             : 
      84     1316328 : uint64_t make_file_id_from_itime(const struct stat_ex *st)
      85             : {
      86     1316328 :         struct timespec itime = st->st_ex_itime;
      87     1316328 :         ino_t ino = st->st_ex_ino;
      88             :         uint64_t file_id_low;
      89             :         uint64_t file_id;
      90             : 
      91     1316328 :         if (st->st_ex_iflags & ST_EX_IFLAG_CALCULATED_ITIME) {
      92           0 :                 return ino;
      93             :         }
      94             : 
      95     1316328 :         round_timespec_to_nttime(&itime);
      96             : 
      97     1316328 :         file_id_low = itime.tv_nsec;
      98     1316328 :         if (file_id_low == 0) {
      99             :                 /*
     100             :                  * This could be by coincidence, but more likely the filesystem
     101             :                  * is only giving us seconds granularity. We need more fine
     102             :                  * grained granularity for the File-ID, so combine with the
     103             :                  * inode number.
     104             :                  */
     105           0 :                 file_id_low = ino & ((1 << 30) - 1);
     106             :         }
     107             : 
     108             :         /*
     109             :          * Set the high bit so ideally File-IDs based on inode numbers and
     110             :          * File-IDs based on Birth Time use disjoint ranges, given inodes never
     111             :          * have the high bit set.
     112             :          */
     113     1316328 :         file_id = ((uint64_t)1) << 63;
     114     1316328 :         file_id |= (uint64_t)itime.tv_sec << 30;
     115     1316328 :         file_id |= file_id_low;
     116             : 
     117     1316328 :         return file_id;
     118             : }

Generated by: LCOV version 1.13