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
131
132
133
134
135
136
137
138
139
140
141
|
/*
* Copyright (C) 2014 John Crispin <blogic@openwrt.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* 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.
*/
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "libfstools.h"
int
find_overlay_mount(char *overlay)
{
FILE *fp = fopen("/proc/mounts", "r");
static char line[256];
int ret = -1;
if(!fp)
return ret;
while (ret && fgets(line, sizeof(line), fp))
if (!strncmp(line, overlay, strlen(overlay)))
ret = 0;
fclose(fp);
return ret;
}
/*
* Find path of a device mounted to the given point.
*/
char*
find_mount(char *mp)
{
FILE *fp = fopen("/proc/mounts", "r");
static char line[256];
char *point = NULL;
if(!fp)
return NULL;
while (fgets(line, sizeof(line), fp)) {
char *s, *t = strstr(line, " ");
if (!t) {
fclose(fp);
return NULL;
}
*t = '\0';
t++;
s = strstr(t, " ");
if (!s) {
fclose(fp);
return NULL;
}
*s = '\0';
if (!strcmp(t, mp)) {
fclose(fp);
return line;
}
}
fclose(fp);
return point;
}
char*
find_mount_point(char *block, int mtd_only)
{
FILE *fp = fopen("/proc/mounts", "r");
static char line[256];
int len = strlen(block);
char *point = NULL;
if(!fp)
return NULL;
while (fgets(line, sizeof(line), fp)) {
if (!strncmp(line, block, len)) {
char *p = &line[len + 1];
char *t = strstr(p, " ");
if (!t) {
fclose(fp);
return NULL;
}
*t = '\0';
t++;
if (mtd_only &&
strncmp(t, "jffs2", 5) &&
strncmp(t, "ubifs", 5)) {
fclose(fp);
ULOG_ERR("block is mounted with wrong fs\n");
return NULL;
}
point = p;
break;
}
}
fclose(fp);
return point;
}
int
find_filesystem(char *fs)
{
FILE *fp = fopen("/proc/filesystems", "r");
static char line[256];
int ret = -1;
if (!fp) {
ULOG_ERR("opening /proc/filesystems failed: %s\n", strerror(errno));
goto out;
}
while (ret && fgets(line, sizeof(line), fp))
if (strstr(line, fs))
ret = 0;
fclose(fp);
out:
return ret;
}
|