Skyld AV  0.6
On access virus scanning for Linux
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
listmounts.c
Go to the documentation of this file.
1 /*
2  * File: listmounts.c
3  *
4  * Copyright 2013 Heinrich Schuchardt <xypron.glpk@gmx.de>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 
25 #include <libmount/libmount.h>
26 #include <stdio.h>
27 #include "listmounts.h"
28 
29 static struct libmnt_context *cxt = NULL;
30 static struct libmnt_table *tb = NULL;
31 static struct libmnt_iter *itr = NULL;
32 
39  int ret = 1;
40  do {
41  cxt = mnt_new_context();
42  if (cxt == NULL) {
43  fprintf(stderr, "Cannot retrieve context.\n");
44  break;
45  }
46  if (mnt_context_get_mtab(cxt, &tb) || tb == NULL) {
47  fprintf(stderr, "Cannot parse mtab.\n");
48  break;
49  }
50  itr = mnt_new_iter(MNT_ITER_FORWARD);
51  ret = 0;
52  } while (0);
53  return ret;
54 }
55 
63 int listmountnext(const char **dir, const char **type) {
64  int ret = 1;
65  struct libmnt_fs *fs;
66  if (0 == mnt_table_next_fs(tb, itr, &fs)) {
67  *dir = mnt_fs_get_target(fs);
68  *type = mnt_fs_get_fstype(fs);
69  ret = 0;
70  }
71  return ret;
72 }
73 
78  if (itr) {
79  mnt_free_iter(itr);
80  itr = NULL;
81  };
82  if (cxt) {
83  mnt_free_context(cxt);
84  cxt = NULL;
85  }
86 }
int listmountinit()
Definition: listmounts.c:38
List mounts.
static struct libmnt_iter * itr
Definition: listmounts.c:31
static struct libmnt_context * cxt
Definition: listmounts.c:29
static struct libmnt_table * tb
Definition: listmounts.c:30
void listmountfinalize()
Definition: listmounts.c:77
int listmountnext(const char **dir, const char **type)
Definition: listmounts.c:63