/[baselayout]/trunk/src/mountinfo.c
Gentoo

Diff of /trunk/src/mountinfo.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2771 Revision 2784
31 31
32 32
33#if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__OpenBSD__) 33#if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__OpenBSD__)
34static char **find_mounts (regex_t *node_regex, regex_t *skip_node_regex, 34static char **find_mounts (regex_t *node_regex, regex_t *skip_node_regex,
35 regex_t *fstype_regex, regex_t *skip_fstype_regex, 35 regex_t *fstype_regex, regex_t *skip_fstype_regex,
36 char **mounts, bool list_nodes, bool list_fstype) 36 char **mounts, bool node, bool fstype)
37{ 37{
38 struct statfs *mnts; 38 struct statfs *mnts;
39 int nmnts; 39 int nmnts;
40 int i; 40 int i;
41 char **list = NULL; 41 char **list = NULL;
68 } 68 }
69 if (! found) 69 if (! found)
70 continue; 70 continue;
71 } 71 }
72 72
73 list = rc_strlist_addsortc (list, list_nodes ? 73 list = rc_strlist_addsortc (list, node ?
74 mnts[i].f_mntfromname : 74 mnts[i].f_mntfromname :
75 list_fstype ? mnts[i].f_fstypename : 75 fstype ? mnts[i].f_fstypename :
76 mnts[i].f_mntonname); 76 mnts[i].f_mntonname);
77 } 77 }
78 78
79 return (list); 79 return (list);
80} 80}
81 81
82#elif defined (__linux__) 82#elif defined (__linux__)
83static char **find_mounts (regex_t *node_regex, regex_t *skip_node_regex, 83static char **find_mounts (regex_t *node_regex, regex_t *skip_node_regex,
84 regex_t *fstype_regex, regex_t *skip_fstype_regex, 84 regex_t *fstype_regex, regex_t *skip_fstype_regex,
85 char **mounts, bool list_nodes, bool list_fstype) 85 char **mounts, bool node, bool fstype)
86{ 86{
87 FILE *fp; 87 FILE *fp;
88 char buffer[PATH_MAX * 3]; 88 char buffer[PATH_MAX * 3];
89 char *p; 89 char *p;
90 char *from; 90 char *from;
91 char *to; 91 char *to;
92 char *fstype; 92 char *fst;
93 char **list = NULL; 93 char **list = NULL;
94 94
95 if ((fp = fopen ("/proc/mounts", "r")) == NULL) 95 if ((fp = fopen ("/proc/mounts", "r")) == NULL)
96 eerrorx ("getmntinfo: %s", strerror (errno)); 96 eerrorx ("getmntinfo: %s", strerror (errno));
97 97
104 if (skip_node_regex && 104 if (skip_node_regex &&
105 regexec (skip_node_regex, from, 0, NULL, 0) == 0) 105 regexec (skip_node_regex, from, 0, NULL, 0) == 0)
106 continue; 106 continue;
107 107
108 to = strsep (&p, " "); 108 to = strsep (&p, " ");
109 fstype = strsep (&p, " "); 109 fst = strsep (&p, " ");
110 /* Skip the really silly rootfs */ 110 /* Skip the really silly rootfs */
111 if (strcmp (fstype, "rootfs") == 0) 111 if (strcmp (fst, "rootfs") == 0)
112 continue; 112 continue;
113 if (fstype_regex && 113 if (fstype_regex &&
114 regexec (fstype_regex, fstype, 0, NULL, 0) != 0) 114 regexec (fstype_regex, fst, 0, NULL, 0) != 0)
115 continue; 115 continue;
116 if (skip_fstype_regex && 116 if (skip_fstype_regex &&
117 regexec (skip_fstype_regex, fstype, 0, NULL, 0) == 0) 117 regexec (skip_fstype_regex, fst, 0, NULL, 0) == 0)
118 continue; 118 continue;
119 119
120 if (mounts) { 120 if (mounts) {
121 bool found = false; 121 bool found = false;
122 int j; 122 int j;
128 } 128 }
129 if (! found) 129 if (! found)
130 continue; 130 continue;
131 } 131 }
132 132
133 list = rc_strlist_addsortc (list, 133 list = rc_strlist_addsortc (list, node ? from : fstype ? fst : to);
134 list_nodes ?
135 list_fstype ? fstype :
136 from : to);
137 } 134 }
138 fclose (fp); 135 fclose (fp);
139 136
140 return (list); 137 return (list);
141} 138}
166 { "skip-fstype-regex", 1, NULL, 'F'}, 163 { "skip-fstype-regex", 1, NULL, 'F'},
167 { "node-regex", 1, NULL, 'n'}, 164 { "node-regex", 1, NULL, 'n'},
168 { "skip-node-regex", 1, NULL, 'N'}, 165 { "skip-node-regex", 1, NULL, 'N'},
169 { "point-regex", 1, NULL, 'p'}, 166 { "point-regex", 1, NULL, 'p'},
170 { "skip-point-regex", 1, NULL, 'P'}, 167 { "skip-point-regex", 1, NULL, 'P'},
171 { "list-nodes", 0, NULL, 'o'}, 168 { "node", 0, NULL, 'o'},
172 { "list-fstype", 0, NULL, 's'}, 169 { "fstype", 0, NULL, 's'},
173 longopts_COMMON 170 longopts_COMMON
174 { NULL, 0, NULL, 0} 171 { NULL, 0, NULL, 0}
175}; 172};
176#include "_usage.c" 173#include "_usage.c"
177 174
183 regex_t *point_regex = NULL; 180 regex_t *point_regex = NULL;
184 regex_t *skip_fstype_regex = NULL; 181 regex_t *skip_fstype_regex = NULL;
185 regex_t *skip_node_regex = NULL; 182 regex_t *skip_node_regex = NULL;
186 regex_t *skip_point_regex = NULL; 183 regex_t *skip_point_regex = NULL;
187 char **nodes = NULL; 184 char **nodes = NULL;
188 char *node; 185 char *n;
189 bool list_nodes = false; 186 bool node = false;
190 bool list_fstype = false; 187 bool fstype = false;
191 char **mounts = NULL; 188 char **mounts = NULL;
192 int opt; 189 int opt;
193 int result; 190 int result;
194 191
195#define DO_REG(_var) \ 192#define DO_REG(_var) \
217 break; 214 break;
218 case 'P': 215 case 'P':
219 DO_REG (skip_point_regex); 216 DO_REG (skip_point_regex);
220 break; 217 break;
221 case 'o': 218 case 'o':
222 list_nodes = true; 219 node = true;
223 list_fstype = false; 220 fstype = false;
224 break; 221 break;
225 case 's': 222 case 's':
226 list_nodes = false; 223 node = false;
227 list_fstype = true; 224 fstype = true;
228 break; 225 break;
229 226
230 case_RC_COMMON_GETOPT 227 case_RC_COMMON_GETOPT
231 } 228 }
232 } 229 }
237 mounts = rc_strlist_add (mounts, argv[optind++]); 234 mounts = rc_strlist_add (mounts, argv[optind++]);
238 } 235 }
239 236
240 nodes = find_mounts (node_regex, skip_node_regex, 237 nodes = find_mounts (node_regex, skip_node_regex,
241 fstype_regex, skip_fstype_regex, 238 fstype_regex, skip_fstype_regex,
242 mounts, list_nodes, list_fstype); 239 mounts, node, fstype);
243 240
244 if (node_regex) 241 if (node_regex)
245 regfree (node_regex); 242 regfree (node_regex);
246 if (skip_node_regex) 243 if (skip_node_regex)
247 regfree (skip_node_regex); 244 regfree (skip_node_regex);
251 regfree (skip_fstype_regex); 248 regfree (skip_fstype_regex);
252 249
253 rc_strlist_reverse (nodes); 250 rc_strlist_reverse (nodes);
254 251
255 result = EXIT_FAILURE; 252 result = EXIT_FAILURE;
256 STRLIST_FOREACH (nodes, node, i) { 253 STRLIST_FOREACH (nodes, n, i) {
257 if (point_regex && regexec (point_regex, node, 0, NULL, 0) != 0) 254 if (point_regex && regexec (point_regex, n, 0, NULL, 0) != 0)
258 continue; 255 continue;
259 if (skip_point_regex && regexec (skip_point_regex, node, 0, NULL, 0) == 0) 256 if (skip_point_regex && regexec (skip_point_regex, n, 0, NULL, 0) == 0)
260 continue; 257 continue;
261 printf ("%s\n", node); 258 printf ("%s\n", n);
262 result = EXIT_SUCCESS; 259 result = EXIT_SUCCESS;
263 } 260 }
264 rc_strlist_free (nodes); 261 rc_strlist_free (nodes);
265 262
266 if (point_regex) 263 if (point_regex)

Legend:
Removed from v.2771  
changed lines
  Added in v.2784

  ViewVC Help
Powered by ViewVC 1.1.20