Changeset 1765 in MondoRescue for branches/2.2.5/mindi-busybox/libbb/mtab.c


Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (17 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/libbb/mtab.c

    r821 r1765  
    55 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
    66 *
    7  * This program is free software; you can redistribute it and/or modify
    8  * it under the terms of the GNU General Public License as published by
    9  * the Free Software Foundation; either version 2 of the License, or
    10  * (at your option) any later version.
    11  *
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    15  * General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program; if not, write to the Free Software
    19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
     7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    208 */
    219
    22 #include <stdlib.h>
    23 #include <unistd.h>
    24 #include <errno.h>
    25 #include <string.h>
    26 #include <stdio.h>
    2710#include <mntent.h>
    2811#include "libbb.h"
    2912
    30 #define MTAB_MAX_ENTRIES 40
    31 
    32 #ifdef CONFIG_FEATURE_MTAB_SUPPORT
     13#if ENABLE_FEATURE_MTAB_SUPPORT
    3314void erase_mtab(const char *name)
    3415{
    35     struct mntent entries[MTAB_MAX_ENTRIES];
    36     int count = 0;
    37     FILE *mountTable = setmntent(bb_path_mtab_file, "r");
     16    struct mntent *entries = NULL;
     17    int i, count = 0;
     18    FILE *mountTable;
    3819    struct mntent *m;
    3920
    40     /* Check if reading the mtab file failed */
    41     if (mountTable == 0
    42             /* Bummer.  fall back on trying the /proc filesystem */
    43             && (mountTable = setmntent("/proc/mounts", "r")) == 0) {
     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) {
    4425        bb_perror_msg(bb_path_mtab_file);
    4526        return;
    4627    }
    4728
    48     while (((m = getmntent(mountTable)) != 0) && (count < MTAB_MAX_ENTRIES))
    49     {
    50         entries[count].mnt_fsname = strdup(m->mnt_fsname);
    51         entries[count].mnt_dir = strdup(m->mnt_dir);
    52         entries[count].mnt_type = strdup(m->mnt_type);
    53         entries[count].mnt_opts = strdup(m->mnt_opts);
    54         entries[count].mnt_freq = m->mnt_freq;
    55         entries[count].mnt_passno = m->mnt_passno;
    56         count++;
     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;
    5738    }
    5839    endmntent(mountTable);
    59     if ((mountTable = setmntent(bb_path_mtab_file, "w"))) {
    60         int i;
    6140
     41    mountTable = setmntent(bb_path_mtab_file, "w");
     42    if (mountTable) {
    6243        for (i = 0; i < count; i++) {
    63             int result = (strcmp(entries[i].mnt_fsname, name) == 0
    64                           || strcmp(entries[i].mnt_dir, name) == 0);
    65 
    66             if (result)
    67                 continue;
    68             else
     44            if (strcmp(entries[i].mnt_fsname, name) != 0
     45             && strcmp(entries[i].mnt_dir, name) != 0)
    6946                addmntent(mountTable, &entries[i]);
    7047        }
Note: See TracChangeset for help on using the changeset viewer.