| 227 | } |
| 228 | |
| 229 | static MountTab |
| 230 | parse_mountinfo (int proc_fd, |
| 231 | const char *root_mount) |
| 232 | { |
| 233 | cleanup_free char *mountinfo = NULL; |
| 234 | cleanup_free MountInfoLine *lines = NULL; |
| 235 | cleanup_free MountInfoLine **by_id = NULL; |
| 236 | cleanup_mount_tab MountTab mount_tab = NULL; |
| 237 | MountInfo *end_tab; |
| 238 | int n_mounts; |
| 239 | char *line; |
| 240 | unsigned int i; |
| 241 | int max_id; |
| 242 | unsigned int n_lines; |
| 243 | int root; |
| 244 | |
| 245 | mountinfo = load_file_at (proc_fd, "self/mountinfo"); |
| 246 | if (mountinfo == NULL) |
| 247 | die_with_error ("Can't open /proc/self/mountinfo"); |
| 248 | |
| 249 | n_lines = count_lines (mountinfo); |
| 250 | lines = xcalloc (n_lines, sizeof (MountInfoLine)); |
| 251 | |
| 252 | max_id = 0; |
| 253 | line = mountinfo; |
| 254 | i = 0; |
| 255 | root = -1; |
| 256 | while (*line != 0) |
| 257 | { |
| 258 | int rc, consumed = 0; |
| 259 | unsigned int maj, min; |
| 260 | char *end; |
| 261 | char *rest; |
| 262 | char *mountpoint; |
| 263 | char *mountpoint_end; |
| 264 | char *options; |
| 265 | char *options_end; |
| 266 | char *next_line; |
| 267 | |
| 268 | assert (i < n_lines); |
| 269 | |
| 270 | end = strchr (line, '\n'); |
| 271 | if (end != NULL) |
| 272 | { |
| 273 | *end = 0; |
| 274 | next_line = end + 1; |
| 275 | } |
| 276 | else |
| 277 | next_line = line + strlen (line); |
| 278 | |
| 279 | rc = sscanf (line, "%d %d %u:%u %n", &lines[i].id, &lines[i].parent_id, &maj, &min, &consumed); |
| 280 | if (rc != 4) |
| 281 | die ("Can't parse mountinfo line"); |
| 282 | rest = line + consumed; |
| 283 | |
| 284 | rest = skip_token (rest, true); /* mountroot */ |
| 285 | mountpoint = rest; |
| 286 | rest = skip_token (rest, false); /* mountpoint */ |
no test coverage detected