LCOV - code coverage report
Current view: top level - plugins - fs.c (source / functions) Coverage Total Hit
Test: libblockdev Coverage Report Lines: 77.1 % 35 27
Test Date: 2026-01-23 09:12:16 Functions: 75.0 % 4 3
Legend: Lines: hit not hit

            Line data    Source code
       1              : /*
       2              :  * Copyright (C) 2016  Red Hat, Inc.
       3              :  *
       4              :  * This library is free software; you can redistribute it and/or
       5              :  * modify it under the terms of the GNU Lesser General Public
       6              :  * License as published by the Free Software Foundation; either
       7              :  * version 2.1 of the License, or (at your option) any later version.
       8              :  *
       9              :  * This library is distributed in the hope that it will be useful,
      10              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12              :  * Lesser General Public License for more details.
      13              :  *
      14              :  * You should have received a copy of the GNU Lesser General Public
      15              :  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
      16              :  *
      17              :  * Author: Vratislav Podzimek <vpodzime@redhat.com>
      18              :  */
      19              : 
      20              : #include <blockdev/utils.h>
      21              : #include <libmount/libmount.h>
      22              : 
      23              : #include <check_deps.h>
      24              : #include "fs.h"
      25              : 
      26              : /**
      27              :  * SECTION: fs
      28              :  * @short_description: plugin for operations with file systems
      29              :  * @title: FS
      30              :  * @include: fs.h
      31              :  *
      32              :  * A plugin for operations with file systems
      33              :  */
      34              : 
      35              : extern gboolean bd_fs_ext_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
      36              : extern gboolean bd_fs_xfs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
      37              : extern gboolean bd_fs_vfat_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
      38              : extern gboolean bd_fs_ntfs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
      39              : extern gboolean bd_fs_f2fs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
      40              : extern gboolean bd_fs_nilfs2_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
      41              : extern gboolean bd_fs_exfat_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
      42              : extern gboolean bd_fs_btrfs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
      43              : extern gboolean bd_fs_udf_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
      44              : 
      45              : /**
      46              :  * bd_fs_error_quark: (skip)
      47              :  */
      48            0 : GQuark bd_fs_error_quark (void)
      49              : {
      50            0 :     return g_quark_from_static_string ("g-bd-fs-error-quark");
      51              : }
      52              : 
      53              : /**
      54              :  * bd_fs_init:
      55              :  *
      56              :  * Initializes the plugin. **This function is called automatically by the
      57              :  * library's initialization functions.**
      58              :  *
      59              :  */
      60          102 : gboolean bd_fs_init (void) {
      61              :     /* tell libmount to honour the LIBMOUNT_DEBUG env var */
      62          102 :     mnt_init_debug (0);
      63              : 
      64          102 :     return TRUE;
      65              : }
      66              : 
      67              : /**
      68              :  * bd_fs_close:
      69              :  *
      70              :  * Cleans up after the plugin. **This function is called automatically by the
      71              :  * library's functions that unload it.**
      72              :  *
      73              :  */
      74          102 : void bd_fs_close (void) {
      75              :     /* nothing to do here */
      76          102 : }
      77              : 
      78              : /**
      79              :  * bd_fs_is_tech_avail:
      80              :  * @tech: the queried tech
      81              :  * @mode: a bit mask of queried modes of operation (#BDFSTechMode) for @tech
      82              :  * @error: (out) (optional): place to store error (details about why the @tech-@mode combination is not available)
      83              :  *
      84              :  * Returns: whether the @tech-@mode combination is available -- supported by the
      85              :  *          plugin implementation and having all the runtime dependencies available
      86              :  */
      87          624 : gboolean bd_fs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error) {
      88          624 :     if (tech == BD_FS_TECH_GENERIC || tech == BD_FS_TECH_MOUNT)
      89              :         /* @mode is ignored, there are no special modes for GENERIC and MOUNT technologies */
      90              :         /* generic features and mounting are supported by this plugin without any dependencies */
      91            0 :         return TRUE;
      92              : 
      93          624 :     if (tech > BD_FS_LAST_FS) {
      94            0 :         g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_TECH_UNAVAIL, "Unknown technology");
      95            0 :         return FALSE;
      96              :     }
      97              : 
      98          624 :     switch (tech) {
      99           21 :         case BD_FS_TECH_EXT2:
     100              :         case BD_FS_TECH_EXT3:
     101              :         case BD_FS_TECH_EXT4:
     102           21 :             return bd_fs_ext_is_tech_avail (tech, mode, error);
     103            8 :         case BD_FS_TECH_XFS:
     104            8 :             return bd_fs_xfs_is_tech_avail (tech, mode, error);
     105            9 :         case BD_FS_TECH_VFAT:
     106            9 :             return bd_fs_vfat_is_tech_avail (tech, mode, error);
     107          100 :         case BD_FS_TECH_NTFS:
     108          100 :             return bd_fs_ntfs_is_tech_avail (tech, mode, error);
     109          103 :         case BD_FS_TECH_F2FS:
     110          103 :             return bd_fs_f2fs_is_tech_avail (tech, mode, error);
     111           99 :         case BD_FS_TECH_NILFS2:
     112           99 :             return bd_fs_nilfs2_is_tech_avail (tech, mode, error);
     113          100 :         case BD_FS_TECH_EXFAT:
     114          100 :             return bd_fs_exfat_is_tech_avail (tech, mode, error);
     115           92 :         case BD_FS_TECH_BTRFS:
     116           92 :             return bd_fs_btrfs_is_tech_avail (tech, mode, error);
     117           92 :         case BD_FS_TECH_UDF:
     118           92 :             return bd_fs_udf_is_tech_avail (tech, mode, error);
     119              :         /* coverity[dead_error_begin] */
     120            0 :         default:
     121              :             /* this should never be reached (see the comparison with LAST_FS
     122              :                above), but better safe than sorry */
     123            0 :             g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_TECH_UNAVAIL, "Unknown technology");
     124            0 :             return FALSE;
     125              :     }
     126              : }
        

Generated by: LCOV version 2.0-1