LCOV - code coverage report
Current view: top level - libgfs2 - device_geometry.c (source / functions) Coverage Total Hit
Test: gfs2-utils.info Lines: 47.6 % 42 20
Test Date: 2024-03-07 16:24:06 Functions: 100.0 % 2 2

            Line data    Source code
       1              : #include "clusterautoconfig.h"
       2              : 
       3              : #include <stdio.h>
       4              : #include <stdlib.h>
       5              : #include <string.h>
       6              : #include <stdint.h>
       7              : #include <inttypes.h>
       8              : #include <sys/types.h>
       9              : #include <sys/stat.h>
      10              : #include <fcntl.h>
      11              : #include <unistd.h>
      12              : #include <errno.h>
      13              : #include <sys/ioctl.h>
      14              : #include <sys/mount.h>
      15              : 
      16              : #include "libgfs2.h"
      17              : 
      18              : #ifndef BLKROGET
      19              : #define BLKROGET _IO(0x12, 94) /* ro */
      20              : #endif
      21              : #ifndef BLKRAGET
      22              : #define BLKRAGET _IO(0x12, 99) /* ra_pages */
      23              : #endif
      24              : #ifndef BLKSSZGET
      25              : #define BLKSSZGET _IO(0x12,104)   /* logical_block_size */
      26              : #endif
      27              : #ifndef BLKBSZGET
      28              : #define BLKBSZGET _IOR(0x12, 112, size_t) /* soft_block_size */
      29              : #endif
      30              : #ifndef BLKIOMIN
      31              : #define BLKIOMIN _IO(0x12,120)    /* minimum_io_size */
      32              : #endif
      33              : #ifndef BLKIOOPT
      34              : #define BLKIOOPT _IO(0x12,121)    /* optimal_io_size */
      35              : #endif
      36              : #ifndef BLKALIGNOFF
      37              : #define BLKALIGNOFF _IO(0x12,122) /* alignment_offset */
      38              : #endif
      39              : #ifndef BLKPBSZGET
      40              : #define BLKPBSZGET _IO(0x12,123)  /* physical_block_size */
      41              : #endif
      42              : 
      43         4532 : int lgfs2_get_dev_info(int fd, struct lgfs2_dev_info *i)
      44              : {
      45              :         int ret;
      46         4532 :         int ro = 0;
      47              :         off_t off;
      48              : 
      49         4532 :         memset(i, 0, sizeof(*i));
      50              : 
      51         4532 :         ret = fstat(fd, &i->stat);
      52         4532 :         if (ret < 0)
      53            0 :                 return ret;
      54              : 
      55         4532 :         switch (i->stat.st_mode & S_IFMT) {
      56         4532 :         case S_IFREG:
      57         4532 :                 i->size = i->stat.st_size;
      58         4532 :                 ret = fcntl(fd, F_GETFL, 0);
      59         4532 :                 if ((ret & O_ACCMODE) == O_RDONLY)
      60           43 :                         i->readonly = 1;
      61         4532 :                 i->io_optimal_size = i->stat.st_blksize;
      62         4532 :                 goto size_check;
      63            0 :         case S_IFBLK:
      64            0 :                 break;
      65            0 :         default:
      66            0 :                 errno = ENOTBLK;
      67            0 :                 return -1;
      68              :         }
      69              : 
      70            0 :         ioctl(fd, BLKRAGET, &i->ra_pages);
      71            0 :         ioctl(fd, BLKBSZGET, &i->soft_block_size);
      72            0 :         ioctl(fd, BLKSSZGET, &i->logical_block_size);
      73            0 :         ioctl(fd, BLKIOMIN, &i->io_min_size);
      74            0 :         ioctl(fd, BLKIOOPT, &i->io_optimal_size);
      75            0 :         ioctl(fd, BLKPBSZGET, &i->physical_block_size);
      76            0 :         ioctl(fd, BLKALIGNOFF, &i->io_align_offset);
      77            0 :         ioctl(fd, BLKROGET, &ro);
      78            0 :         if (ro)
      79            0 :                 i->readonly = 1;
      80            0 :         off = lseek(fd, 0, SEEK_END);
      81            0 :         if (off < 0)
      82            0 :                 return -1;
      83            0 :         i->size = off;
      84              : 
      85         4532 : size_check:
      86         4532 :         if (i->size < (1 << 20)) {
      87            0 :                 errno = ENOSPC;
      88            0 :                 return -1;
      89              :         }
      90              : 
      91         4532 :         return 0;
      92              : }
      93              : 
      94              : /**
      95              :  * fix_device_geometry - round off address and lengths and convert to FS blocks
      96              :  * @sdp: The super block
      97              :  *
      98              :  */
      99              : 
     100         4476 : void lgfs2_fix_device_geometry(struct lgfs2_sbd *sdp)
     101              : {
     102         4476 :         struct lgfs2_device *device = &sdp->device;
     103              : 
     104         4476 :         device->length = sdp->dinfo.size / sdp->sd_bsize;
     105         4476 : }
        

Generated by: LCOV version 2.0-1