Debian Codegraph @

src/plugins/fs.c

raw
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 <[email protected]>
18 */
19
20 #include <blockdev/utils.h>
21 #include <libmount/libmount.h>
22
23 #include <check_deps.h>
24 #include "fs.h"
25 #include "fs/common.h"
26
27 /**
28 * SECTION: fs
29 * @short_description: plugin for operations with file systems
30 * @title: FS
31 * @include: fs.h
32 *
33 * A plugin for operations with file systems
34 */
35
36 extern gboolean bd_fs_ext_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
37 extern gboolean bd_fs_xfs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
38 extern gboolean bd_fs_vfat_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
39 extern gboolean bd_fs_ntfs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
40 extern gboolean bd_fs_f2fs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
41 extern gboolean bd_fs_nilfs2_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
42 extern gboolean bd_fs_exfat_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
43 extern gboolean bd_fs_btrfs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
44 extern gboolean bd_fs_udf_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
45
46 /**
47 * bd_fs_error_quark: (skip)
48 */
49 GQuark bd_fs_error_quark (void)
50 {
51 return g_quark_from_static_string ("g-bd-fs-error-quark");
52 }
53
54 /**
55 * bd_fs_init:
56 *
57 * Initializes the plugin. **This function is called automatically by the
58 * library's initialization functions.**
59 *
60 */
61 gboolean bd_fs_init (void) {
62 /* tell libmount to honour the LIBMOUNT_DEBUG env var */
63 mnt_init_debug (0);
64
65 return TRUE;
66 }
67
68 /**
69 * bd_fs_close:
70 *
71 * Cleans up after the plugin. **This function is called automatically by the
72 * library's functions that unload it.**
73 *
74 */
75 void bd_fs_close (void) {
76 _fs_ext_reset_avail_deps ();
77 _fs_xfs_reset_avail_deps ();
78 _fs_vfat_reset_avail_deps ();
79 _fs_ntfs_reset_avail_deps ();
80 _fs_exfat_reset_avail_deps ();
81 _fs_btrfs_reset_avail_deps ();
82 _fs_udf_reset_avail_deps ();
83 _fs_f2fs_reset_avail_deps ();
84 _fs_nilfs_reset_avail_deps ();
85 }
86
87 /**
88 * bd_fs_is_tech_avail:
89 * @tech: the queried tech
90 * @mode: a bit mask of queried modes of operation (#BDFSTechMode) for @tech
91 * @error: (out) (optional): place to store error (details about why the @tech-@mode combination is not available)
92 *
93 * Returns: whether the @tech-@mode combination is available -- supported by the
94 * plugin implementation and having all the runtime dependencies available
95 */
96 gboolean bd_fs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error) {
97 if (tech == BD_FS_TECH_GENERIC || tech == BD_FS_TECH_MOUNT)
98 /* @mode is ignored, there are no special modes for GENERIC and MOUNT technologies */
99 /* generic features and mounting are supported by this plugin without any dependencies */
100 return TRUE;
101
102 if (tech > BD_FS_LAST_FS) {
103 g_set_error_literal (error, BD_FS_ERROR, BD_FS_ERROR_TECH_UNAVAIL, "Unknown technology");
104 return FALSE;
105 }
106
107 switch (tech) {
108 case BD_FS_TECH_EXT2:
109 case BD_FS_TECH_EXT3:
110 case BD_FS_TECH_EXT4:
111 return bd_fs_ext_is_tech_avail (tech, mode, error);
112 case BD_FS_TECH_XFS:
113 return bd_fs_xfs_is_tech_avail (tech, mode, error);
114 case BD_FS_TECH_VFAT:
115 return bd_fs_vfat_is_tech_avail (tech, mode, error);
116 case BD_FS_TECH_NTFS:
117 return bd_fs_ntfs_is_tech_avail (tech, mode, error);
118 case BD_FS_TECH_F2FS:
119 return bd_fs_f2fs_is_tech_avail (tech, mode, error);
120 case BD_FS_TECH_NILFS2:
121 return bd_fs_nilfs2_is_tech_avail (tech, mode, error);
122 case BD_FS_TECH_EXFAT:
123 return bd_fs_exfat_is_tech_avail (tech, mode, error);
124 case BD_FS_TECH_BTRFS:
125 return bd_fs_btrfs_is_tech_avail (tech, mode, error);
126 case BD_FS_TECH_UDF:
127 return bd_fs_udf_is_tech_avail (tech, mode, error);
128 /* coverity[dead_error_begin] */
129 default:
130 /* this should never be reached (see the comparison with LAST_FS
131 above), but better safe than sorry */
132 g_set_error_literal (error, BD_FS_ERROR, BD_FS_ERROR_TECH_UNAVAIL, "Unknown technology");
133 return FALSE;
134 }
135 }