]>
git.ipfire.org Git - collecty.git/blob - src/_collecty/utils.c
3 * Copyright (C) 2015 IPFire Team (www.ipfire.org)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "_collectymodule.h"
24 int _collecty_mountpoint_is_virtual(const struct mntent
* mp
) {
25 // Ignore all ramdisks
26 if (mp
->mnt_fsname
[0] != '/')
29 // Ignore network mounts
30 if (hasmntopt(mp
, "_netdev") != NULL
)
36 PyObject
* _collecty_get_mountpoints() {
37 FILE* fp
= setmntent(_PATH_MOUNTED
, "r");
41 PyObject
* list
= PyList_New(0);
44 struct mntent
* mountpoint
= getmntent(fp
);
46 if (!_collecty_mountpoint_is_virtual(mountpoint
)) {
47 // Create a tuple with the information of the mountpoint
48 PyObject
* mp
= PyTuple_New(4);
49 PyTuple_SET_ITEM(mp
, 0, PyUnicode_FromString(mountpoint
->mnt_fsname
));
50 PyTuple_SET_ITEM(mp
, 1, PyUnicode_FromString(mountpoint
->mnt_dir
));
51 PyTuple_SET_ITEM(mp
, 2, PyUnicode_FromString(mountpoint
->mnt_type
));
52 PyTuple_SET_ITEM(mp
, 3, PyUnicode_FromString(mountpoint
->mnt_opts
));
54 // Append the tuple to the list
55 r
= PyList_Append(list
, mp
);
60 // Move on to the next mountpoint
61 mountpoint
= getmntent(fp
);