~ubuntu-branches/ubuntu/hoary/xfsprogs/hoary

« back to all changes in this revision

Viewing changes to growfs/explore.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2004-07-28 21:11:38 UTC
  • Revision ID: james.westby@ubuntu.com-20040728211138-0v4pdnunnp7na5lm
Tags: 2.6.20-1
* New upstream release.
* Fix xfs_io segfault on non-XFS files.  (closes: #260470)
* Fix packaging botch, deleted files included.  (closes: #260491)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of version 2 of the GNU General Public License as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it would be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
11
 *
 
12
 * Further, this software is distributed without any warranty that it is
 
13
 * free of the rightful claim of any third person regarding infringement
 
14
 * or the like.  Any license provided herein, whether implied or
 
15
 * otherwise, applies only to this software file.  Patent licenses, if
 
16
 * any, provided herein do not apply to combinations of this program with
 
17
 * other software, or any other product whatsoever.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License along
 
20
 * with this program; if not, write the Free Software Foundation, Inc., 59
 
21
 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
 
22
 *
 
23
 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
 
24
 * Mountain View, CA  94043, or:
 
25
 *
 
26
 * http://www.sgi.com
 
27
 *
 
28
 * For further information regarding this notice, see:
 
29
 *
 
30
 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
 
31
 */
 
32
 
 
33
#include <xfs/libxfs.h>
 
34
#include <mntent.h>
 
35
 
 
36
extern char     *fname;         /* mount point name */
 
37
extern char     *datadev;       /* data device name */
 
38
extern char     *logdev;        /*  log device name */
 
39
extern char     *rtdev;         /*   RT device name */
 
40
 
 
41
void
 
42
explore_mtab(char *mtab, char *mntpoint)
 
43
{
 
44
        struct mntent   *mnt;
 
45
        struct stat64   statuser;
 
46
        struct stat64   statmtab_dir;
 
47
        struct stat64   statmtab_dev;
 
48
        FILE            *mtp;
 
49
        char            *rtend;
 
50
        char            *logend;
 
51
        int             havedev;
 
52
 
 
53
        if (!mtab)
 
54
                mtab = MOUNTED;
 
55
 
 
56
        if ((mtp = setmntent(mtab, "r")) == NULL) {
 
57
                fprintf(stderr, _("%s: cannot access mount list %s: %s\n"),
 
58
                        progname, MOUNTED, strerror(errno));
 
59
                exit(1);
 
60
        }
 
61
        if (stat64(mntpoint, &statuser) < 0) {
 
62
                fprintf(stderr, _("%s: cannot access mount point %s: %s\n"),
 
63
                        progname, mntpoint, strerror(errno));
 
64
                exit(1);
 
65
        }
 
66
 
 
67
        while ((mnt = getmntent(mtp)) != NULL) {
 
68
                if (stat64(mnt->mnt_dir, &statmtab_dir) < 0) {
 
69
                        fprintf(stderr, _("%s: ignoring entry %s in %s: %s\n"),
 
70
                                progname, mnt->mnt_dir, mtab, strerror(errno));
 
71
                        continue;
 
72
                }
 
73
                havedev = (stat64(mnt->mnt_fsname, &statmtab_dev) != -1);
 
74
                if ( !((statuser.st_ino == statmtab_dir.st_ino &&
 
75
                                statuser.st_dev == statmtab_dir.st_dev) ||
 
76
                       (statuser.st_ino == statmtab_dev.st_ino &&
 
77
                                statuser.st_dev == statmtab_dev.st_dev &&
 
78
                                havedev)) )
 
79
                        continue;
 
80
                else if (strcmp(mnt->mnt_type, "xfs") != 0) {
 
81
                        fprintf(stderr, _("%s: %s is not an XFS filesystem\n"),
 
82
                                progname, mntpoint);
 
83
                        exit(1);
 
84
                }
 
85
                break;  /* we've found it */
 
86
        }
 
87
 
 
88
        if (mnt == NULL) {
 
89
                fprintf(stderr,
 
90
                _("%s: %s is not a mounted XFS filesystem, according to %s\n"),
 
91
                        progname, mntpoint, MOUNTED);
 
92
                exit(1);
 
93
        }
 
94
 
 
95
        /* find the data, log (logdev=), and realtime (rtdev=) devices */
 
96
        rtend = logend = NULL;
 
97
        fname = mnt->mnt_dir;
 
98
        datadev = mnt->mnt_fsname;
 
99
        if ((logdev = hasmntopt(mnt, "logdev="))) {
 
100
                logdev += 7;
 
101
                logend = strtok(logdev, " ,");
 
102
        }
 
103
        if ((rtdev = hasmntopt(mnt, "rtdev="))) {
 
104
                rtdev += 6;
 
105
                rtend = strtok(rtdev, " ,");
 
106
        }
 
107
 
 
108
        /* Do this only after we've finished processing mount options */
 
109
        if (logdev && logend != logdev)
 
110
                *logend = '\0'; /* terminate end of log device name */
 
111
        if (rtdev && rtend != rtdev)
 
112
                *rtend = '\0';  /* terminate end of rt device name */
 
113
 
 
114
        endmntent(mtp);
 
115
}