diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-20 02:38:48 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-20 02:38:48 +0000 |
commit | b9f5d59893ee664a6b59f321a540ea63c5dccd40 (patch) | |
tree | bd827aec8896c8c9eefdbfb43974c82c8efa5a44 | |
parent | f31c3b677d588795b18f02a6b8de22057bfab4af (diff) | |
download | busybox-w32-b9f5d59893ee664a6b59f321a540ea63c5dccd40.tar.gz busybox-w32-b9f5d59893ee664a6b59f321a540ea63c5dccd40.tar.bz2 busybox-w32-b9f5d59893ee664a6b59f321a540ea63c5dccd40.zip |
fsck: use getmntent_r instead of open-coded parsing. By Vladimir
function old new delta
create_fs_device 125 158 +33
parse_word 41 - -41
parse_escape 55 - -55
fsck_main 2246 1893 -353
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/1 up/down: 33/-449) Total: -416 bytes
-rw-r--r-- | e2fsprogs/fsck.c | 133 |
1 files changed, 17 insertions, 116 deletions
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c index 86c78d881..3c4dabc48 100644 --- a/e2fsprogs/fsck.c +++ b/e2fsprogs/fsck.c | |||
@@ -280,9 +280,11 @@ static struct fs_info *create_fs_device(const char *device, const char *mntpnt, | |||
280 | fs = xzalloc(sizeof(*fs)); | 280 | fs = xzalloc(sizeof(*fs)); |
281 | fs->device = xstrdup(device); | 281 | fs->device = xstrdup(device); |
282 | fs->mountpt = xstrdup(mntpnt); | 282 | fs->mountpt = xstrdup(mntpnt); |
283 | if (strchr(type, ',')) | ||
284 | type = (char *)"auto"; | ||
283 | fs->type = xstrdup(type); | 285 | fs->type = xstrdup(type); |
284 | fs->opts = xstrdup(opts ? opts : ""); | 286 | fs->opts = xstrdup(opts ? opts : ""); |
285 | fs->passno = passno; | 287 | fs->passno = passno < 0 ? 1 : passno; |
286 | /*fs->flags = 0; */ | 288 | /*fs->flags = 0; */ |
287 | /*fs->next = NULL; */ | 289 | /*fs->next = NULL; */ |
288 | 290 | ||
@@ -295,130 +297,29 @@ static struct fs_info *create_fs_device(const char *device, const char *mntpnt, | |||
295 | return fs; | 297 | return fs; |
296 | } | 298 | } |
297 | 299 | ||
298 | static void strip_line(char *line) | ||
299 | { | ||
300 | char *p = line + strlen(line) - 1; | ||
301 | |||
302 | while (*line) { | ||
303 | if (*p != '\n' && *p != '\r') | ||
304 | break; | ||
305 | *p-- = '\0'; | ||
306 | } | ||
307 | } | ||
308 | |||
309 | static char *parse_word(char **buf) | ||
310 | { | ||
311 | char *word, *next; | ||
312 | |||
313 | word = *buf; | ||
314 | if (*word == '\0') | ||
315 | return NULL; | ||
316 | |||
317 | word = skip_whitespace(word); | ||
318 | next = skip_non_whitespace(word); | ||
319 | if (*next) | ||
320 | *next++ = '\0'; | ||
321 | *buf = next; | ||
322 | return word; | ||
323 | } | ||
324 | |||
325 | static void parse_escape(char *word) | ||
326 | { | ||
327 | char *q, c; | ||
328 | const char *p; | ||
329 | |||
330 | if (!word) | ||
331 | return; | ||
332 | |||
333 | for (p = q = word; *p; q++) { | ||
334 | c = *p++; | ||
335 | if (c != '\\') { | ||
336 | *q = c; | ||
337 | } else { | ||
338 | *q = bb_process_escape_sequence(&p); | ||
339 | } | ||
340 | } | ||
341 | *q = '\0'; | ||
342 | } | ||
343 | |||
344 | static int parse_fstab_line(char *line, struct fs_info **ret_fs) | ||
345 | { | ||
346 | char *device, *mntpnt, *type, *opts, *passno, *cp; | ||
347 | struct fs_info *fs; | ||
348 | |||
349 | *ret_fs = NULL; | ||
350 | strip_line(line); | ||
351 | *strchrnul(line, '#') = '\0'; /* Ignore everything after comment */ | ||
352 | cp = line; | ||
353 | |||
354 | device = parse_word(&cp); | ||
355 | if (!device) return 0; /* Allow blank lines */ | ||
356 | mntpnt = parse_word(&cp); | ||
357 | type = parse_word(&cp); | ||
358 | opts = parse_word(&cp); | ||
359 | /*freq =*/ parse_word(&cp); | ||
360 | passno = parse_word(&cp); | ||
361 | |||
362 | if (!mntpnt || !type) | ||
363 | return -1; | ||
364 | |||
365 | parse_escape(device); | ||
366 | parse_escape(mntpnt); | ||
367 | parse_escape(type); | ||
368 | parse_escape(opts); | ||
369 | parse_escape(passno); | ||
370 | |||
371 | if (strchr(type, ',')) | ||
372 | type = NULL; | ||
373 | |||
374 | fs = create_fs_device(device, mntpnt, type ? type : "auto", opts, | ||
375 | (passno ? atoi(passno) : -1)); | ||
376 | *ret_fs = fs; | ||
377 | return 0; | ||
378 | } | ||
379 | |||
380 | /* Load the filesystem database from /etc/fstab */ | 300 | /* Load the filesystem database from /etc/fstab */ |
381 | static void load_fs_info(const char *filename) | 301 | static void load_fs_info(const char *filename) |
382 | { | 302 | { |
383 | FILE *f; | 303 | FILE *fstab; |
384 | int lineno = 0; | 304 | struct mntent mte; |
385 | int old_fstab = 1; | ||
386 | struct fs_info *fs; | 305 | struct fs_info *fs; |
387 | 306 | ||
388 | f = fopen_or_warn(filename, "r"); | 307 | fstab = setmntent(filename, "r"); |
389 | if (f == NULL) { | 308 | if (!fstab) { |
309 | bb_perror_msg("cannot read %s", filename); | ||
390 | return; | 310 | return; |
391 | } | 311 | } |
392 | while (1) { | ||
393 | int r; | ||
394 | char *buf = xmalloc_fgetline(f); | ||
395 | if (!buf) break; | ||
396 | r = parse_fstab_line(buf, &fs); | ||
397 | free(buf); | ||
398 | lineno++; | ||
399 | if (r < 0) { | ||
400 | bb_error_msg("WARNING: bad format " | ||
401 | "on line %d of %s", lineno, filename); | ||
402 | continue; | ||
403 | } | ||
404 | if (!fs) | ||
405 | continue; | ||
406 | if (fs->passno < 0) | ||
407 | fs->passno = 0; | ||
408 | else | ||
409 | old_fstab = 0; | ||
410 | } | ||
411 | fclose(f); | ||
412 | 312 | ||
413 | if (old_fstab) { | 313 | // Loop through entries |
414 | fputs("\007" | 314 | while (getmntent_r(fstab, &mte, bb_common_bufsiz1, COMMON_BUFSIZE)) { |
415 | "WARNING: Your /etc/fstab does not contain the fsck passno field.\n" | 315 | //bb_info_msg("CREATE[%s][%s][%s][%s][%d]", mte.mnt_fsname, mte.mnt_dir, |
416 | "I will kludge around things for you, but you should fix\n" | 316 | // mte.mnt_type, mte.mnt_opts, |
417 | "your /etc/fstab file as soon as you can.\n\n", stderr); | 317 | // mte.mnt_passno); |
418 | for (fs = filesys_info; fs; fs = fs->next) { | 318 | fs = create_fs_device(mte.mnt_fsname, mte.mnt_dir, |
419 | fs->passno = 1; | 319 | mte.mnt_type, mte.mnt_opts, |
420 | } | 320 | mte.mnt_passno); |
421 | } | 321 | } |
322 | endmntent(fstab); | ||
422 | } | 323 | } |
423 | 324 | ||
424 | /* Lookup filesys in /etc/fstab and return the corresponding entry. */ | 325 | /* Lookup filesys in /etc/fstab and return the corresponding entry. */ |