2 * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2.1
6 * as published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
18 #include "../fs-state.h"
21 find_overlay_mount(char *overlay)
23 FILE *fp = fopen("/proc/mounts", "r");
24 static char line[256];
30 while (ret && fgets(line, sizeof(line), fp))
31 if (!strncmp(line, overlay, strlen(overlay)))
42 FILE *fp = fopen("/proc/mounts", "r");
43 static char line[256];
49 while (fgets(line, sizeof(line), fp)) {
50 char *s, *t = strstr(line, " ");
76 find_mount_point(char *block, char *fs)
78 FILE *fp = fopen("/proc/mounts", "r");
79 static char line[256];
80 int len = strlen(block);
86 while (fgets(line, sizeof(line), fp)) {
87 if (!strncmp(line, block, len)) {
88 char *p = &line[len + 1];
89 char *t = strstr(p, " ");
99 if (fs && strncmp(t, fs, strlen(fs))) {
101 fprintf(stderr, "block is mounted with wrong fs\n");
116 find_mtd_index(char *name)
118 FILE *fp = fopen("/proc/mtd", "r");
119 static char line[256];
125 while (!index && fgets(line, sizeof(line), fp)) {
126 if (strstr(line, name)) {
127 char *eol = strstr(line, ":");
143 find_mtd_block(char *name, char *part, int plen)
145 char *index = find_mtd_index(name);
150 snprintf(part, plen, "/dev/mtdblock%s", index);
156 find_mtd_char(char *name, char *part, int plen)
158 char *index = find_mtd_index(name);
163 snprintf(part, plen, "/dev/mtd%s", index);
169 find_filesystem(char *fs)
171 FILE *fp = fopen("/proc/filesystems", "r");
172 static char line[256];
176 fprintf(stderr, "opening /proc/filesystems failed: %s\n", strerror(errno));
180 while (ret && fgets(line, sizeof(line), fp))
181 if (strstr(line, fs))