-
Notifications
You must be signed in to change notification settings - Fork 0
/
mountinfo.c
130 lines (94 loc) · 2.92 KB
/
mountinfo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Stef Bon <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "global-defines.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <errno.h>
#include <stdbool.h>
#include <strings.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <fcntl.h>
#include <pthread.h>
#include <glib.h>
#include "beventloop.h"
#include "mountinfo.h"
#include "utils.h"
#include "logging.h"
static struct mountentry_s *rootmount=NULL;
static unsigned long uniquectr=1;
static pthread_mutex_t ctr_mutex=PTHREAD_MUTEX_INITIALIZER;
static unsigned long generation=0;
unsigned long get_uniquectr()
{
unsigned long result=0;
pthread_mutex_lock(&ctr_mutex);
result=uniquectr;
uniquectr++;
pthread_mutex_unlock(&ctr_mutex);
return result;
}
unsigned long generation_id()
{
return generation;
}
void increase_generation_id()
{
generation++;
}
/* compare entries
* if b is "bigger" then a this function returns a positive value (+1)
* if a is "bigger" then it returns -1
* if equal: 0
the first item to compare: mountpoint
the second : mountsource
the third : filesystem
*/
int compare_mount_entries(struct mountentry_s *a, struct mountentry_s *b)
{
int diff=0;
logoutput("compare_mount_entries: compare %s:%s:%s with %s:%s:%s", a->source, a->mountpoint, a->fs, b->source, b->mountpoint, b->fs);
diff=g_strcmp0(a->mountpoint, b->mountpoint);
if (diff==0) {
diff=g_strcmp0(a->source, b->source);
if (diff==0) diff=g_strcmp0(a->fs, b->fs);
}
return diff;
}
void check_mounted_by_autofs(struct mountentry_s *mountentry)
{
// struct mountentry_s *parent=mountentry->parent;
// if (parent) {
// if (strcmp(parent->fs, "autofs")==0) mountentry->flags|=MOUNTENTRY_FLAG_BY_AUTOFS;
// }
}
void set_rootmount(struct mountentry_s *mountentry)
{
rootmount=mountentry;
}
struct mountentry_s *get_rootmount()
{
return rootmount;
}
struct mountentry_s *get_containing_mountentry(struct list_element_s *list)
{
if (! list) return NULL;
return (struct mountentry_s *) ( ((char *) list) - offsetof(struct mountentry_s, list));
}