source: MondoRescue/branches/2.2.5/mindi-busybox/libbb/mtab.c@ 1765

Last change on this file since 1765 was 1765, checked in by Bruno Cornec, 17 years ago

Update to busybox 1.7.2

File size: 1.4 KB
RevLine 
[821]1/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 *
[1765]7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
[821]8 */
9
10#include <mntent.h>
11#include "libbb.h"
12
[1765]13#if ENABLE_FEATURE_MTAB_SUPPORT
[821]14void erase_mtab(const char *name)
15{
[1765]16 struct mntent *entries = NULL;
17 int i, count = 0;
18 FILE *mountTable;
[821]19 struct mntent *m;
20
[1765]21 mountTable = setmntent(bb_path_mtab_file, "r");
22 /* Bummer. Fall back on trying the /proc filesystem */
23 if (!mountTable) mountTable = setmntent("/proc/mounts", "r");
24 if (!mountTable) {
[821]25 bb_perror_msg(bb_path_mtab_file);
26 return;
27 }
28
[1765]29 while ((m = getmntent(mountTable)) != 0) {
30 i = count++;
31 entries = xrealloc(entries, count * sizeof(entries[0]));
32 entries[i].mnt_fsname = xstrdup(m->mnt_fsname);
33 entries[i].mnt_dir = xstrdup(m->mnt_dir);
34 entries[i].mnt_type = xstrdup(m->mnt_type);
35 entries[i].mnt_opts = xstrdup(m->mnt_opts);
36 entries[i].mnt_freq = m->mnt_freq;
37 entries[i].mnt_passno = m->mnt_passno;
[821]38 }
39 endmntent(mountTable);
40
[1765]41 mountTable = setmntent(bb_path_mtab_file, "w");
42 if (mountTable) {
[821]43 for (i = 0; i < count; i++) {
[1765]44 if (strcmp(entries[i].mnt_fsname, name) != 0
45 && strcmp(entries[i].mnt_dir, name) != 0)
[821]46 addmntent(mountTable, &entries[i]);
47 }
48 endmntent(mountTable);
49 } else if (errno != EROFS)
50 bb_perror_msg(bb_path_mtab_file);
51}
52#endif
Note: See TracBrowser for help on using the repository browser.