]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - growfs/xfs_growfs.c
Merge whitespace changes over
[thirdparty/xfsprogs-dev.git] / growfs / xfs_growfs.c
index ab883cd51a982ceb6f54028b25e84f6e3557e568..c579e8111020ced81705587bd9c5e9097ccd757e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of version 2 of the GNU General Public License as
@@ -31,8 +31,7 @@
  */
 
 #include <libxfs.h>
-#include <mntent.h>
-#include <sys/ioctl.h>
+#include "explore.h"
 
 /*
  * When growing a filesystem, this is the most significant
 
 #define XFS_MAX_INODE_SIG_BITS 32
 
-static char    *fname;         /* mount point name */
-static char    *datadev;       /* data device name */
-static char    *logdev;        /*  log device name */
-static char    *rtdev;         /*   RT device name */
+char   *fname;         /* mount point name */
+char   *datadev;       /* data device name */
+char   *logdev;        /*  log device name */
+char   *rtdev;         /*   RT device name */
 
 static void
 usage(void)
 {
-       fprintf(stderr,
+       fprintf(stderr, _(
 "Usage: %s [options] mountpoint\n\n\
 Options:\n\
-        -d          grow data/metadata section\n\
-        -l          grow log section\n\
-        -r          grow realtime section\n\
-        -n          don't change anything, just show geometry\n\
-        -I          allow inode numbers to exceed %d significant bits\n\
-        -i          convert log from external to internal format\n\
-        -t          alternate location for mount table (/etc/mtab)\n\
-        -x          convert log from internal to external format\n\
-        -D size     grow data/metadata section to size blks\n\
-        -L size     grow/shrink log section to size blks\n\
-        -R size     grow realtime section to size blks\n\
-        -e size     set realtime extent size to size blks\n\
-        -m imaxpct  set inode max percent to imaxpct\n\
-        -V          print version information\n",
+       -d          grow data/metadata section\n\
+       -l          grow log section\n\
+       -r          grow realtime section\n\
+       -n          don't change anything, just show geometry\n\
+       -I          allow inode numbers to exceed %d significant bits\n\
+       -i          convert log from external to internal format\n\
+       -t          alternate location for mount table (/etc/mtab)\n\
+       -x          convert log from internal to external format\n\
+       -D size     grow data/metadata section to size blks\n\
+       -L size     grow/shrink log section to size blks\n\
+       -R size     grow realtime section to size blks\n\
+       -e size     set realtime extent size to size blks\n\
+       -m imaxpct  set inode max percent to imaxpct\n\
+       -V          print version information\n"),
                progname, XFS_MAX_INODE_SIG_BITS);
        exit(2);
 }
@@ -80,90 +79,28 @@ report_info(
        int             logversion,
        int             isint)
 {
-       printf("meta-data=%-22s isize=%-6d agcount=%d, agsize=%d blks\n"
-              "data     =%-22s bsize=%-6d blocks=%lld, imaxpct=%d\n"
-              "         =%-22s sunit=%-6d swidth=%d blks, unwritten=%d\n"
-              "naming   =version %-14d bsize=%-6d\n"
-              "log      =%-22s bsize=%-6d blocks=%d version=%d\n"
-              "         =%-22s sunit=%d blks\n"
-              "realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n",
-              mntpoint, geo.inodesize, geo.agcount, geo.agblocks,
-              "", geo.blocksize, (long long)geo.datablocks, geo.imaxpct,
-              "", geo.sunit, geo.swidth, unwritten,
-              dirversion, geo.dirblocksize,
-              isint ? "internal" : "external", geo.blocksize, geo.logblocks,
-              logversion,
-              "", geo.logsunit / geo.blocksize,
-              geo.rtblocks ? "external" : "none",
-              geo.rtextsize * geo.blocksize,
-              (long long)geo.rtblocks, (long long)geo.rtextents);
-}
-
-void
-explore_mtab(char *mtab, char *mntpoint)
-{
-       struct mntent   *mnt;
-       struct stat64   statuser;
-       struct stat64   statmtab;
-       FILE            *mtp;
-       char            *rtend;
-       char            *logend;
-
-       if ((mtp = setmntent(mtab, "r")) == NULL) {
-               fprintf(stderr, "%s: cannot access mount list %s: %s\n",
-                       progname, MOUNTED, strerror(errno));
-               exit(1);
-       }
-       if (stat64(mntpoint, &statuser) < 0) {
-               fprintf(stderr, "%s: cannot access mount point %s: %s\n",
-                       progname, mntpoint, strerror(errno));
-               exit(1);
-       }
-
-       while ((mnt = getmntent(mtp)) != NULL) {
-               if (stat64(mnt->mnt_dir, &statmtab) < 0) {
-                       fprintf(stderr, "%s: ignoring entry %s in %s: %s\n",
-                               progname, mnt->mnt_dir, mtab, strerror(errno));
-                       continue;
-               }
-               if (statuser.st_ino != statmtab.st_ino ||
-                               statuser.st_dev != statmtab.st_dev)
-                       continue;
-               else if (strcmp(mnt->mnt_type, "xfs") != 0) {
-                       fprintf(stderr, "%s: %s is not an XFS filesystem\n",
-                               progname, mntpoint);
-                       exit(1);
-               }
-               break;  /* we've found it */
-       }
-
-       if (mnt == NULL) {
-               fprintf(stderr,
-               "%s: %s is not a filesystem mount point, according to %s\n",
-                       progname, mntpoint, MOUNTED);
-               exit(1);
-       }
-
-       /* find the data, log (logdev=), and realtime (rtdev=) devices */
-       rtend = logend = NULL;
-       fname = mnt->mnt_dir;
-       datadev = mnt->mnt_fsname;
-       if ((logdev = hasmntopt(mnt, "logdev="))) {
-               logdev += 7;
-               logend = strtok(logdev, " ,");
-       }
-       if ((rtdev = hasmntopt(mnt, "rtdev="))) {
-               rtdev += 6;
-               rtend = strtok(rtdev, " ,");
-       }
-
-       /* Do this only after we've finished processing mount options */
-       if (logdev && logend != logdev)
-               *logend = '\0'; /* terminate end of log device name */
-       if (rtdev && rtend != rtdev)
-               *rtend = '\0';  /* terminate end of rt device name */
-
-       endmntent(mtp);
+       printf(_(
+           "meta-data=%-22s isize=%-6u agcount=%u, agsize=%u blks\n"
+           "         =%-22s sectsz=%-5u\n"
+           "data     =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
+           "         =%-22s sunit=%-6u swidth=%u blks, unwritten=%u\n"
+           "naming   =version %-14u bsize=%-6u\n"
+           "log      =%-22s bsize=%-6u blocks=%u, version=%u\n"
+           "         =%-22s sectsz=%-5u sunit=%u blks\n"
+           "realtime =%-22s extsz=%-6u blocks=%llu, rtextents=%llu\n"),
+
+               mntpoint, geo.inodesize, geo.agcount, geo.agblocks,
+               "", geo.sectsize,
+               "", geo.blocksize, (unsigned long long)geo.datablocks,
+                       geo.imaxpct,
+               "", geo.sunit, geo.swidth, unwritten,
+               dirversion, geo.dirblocksize,
+               isint ? _("internal") : _("external"), geo.blocksize,
+                       geo.logblocks, logversion,
+               "", geo.logsectsize, geo.logsunit / geo.blocksize,
+               geo.rtblocks ? _("external") : _("none"),
+               geo.rtextsize * geo.blocksize, (unsigned long long)geo.rtblocks,
+                       (unsigned long long)geo.rtextents);
 }
 
 int
@@ -197,15 +134,20 @@ main(int argc, char **argv)
        int                     xflag;  /* -x flag */
        libxfs_init_t           xi;     /* libxfs structure */
 
-       mtab = MOUNTED;
        progname = basename(argv[0]);
-       aflag = dflag = iflag = lflag = mflag = nflag = rflag = xflag = 0;
+       setlocale(LC_ALL, "");
+       bindtextdomain(PACKAGE, LOCALEDIR);
+       textdomain(PACKAGE);
+
+       mtab = NULL;
        maxpct = esize = 0;
        dsize = lsize = rsize = 0LL;
+       aflag = dflag = iflag = lflag = mflag = nflag = rflag = xflag = 0;
+
        while ((c = getopt(argc, argv, "dD:e:ilL:m:np:rR:t:xV")) != EOF) {
                switch (c) {
                case 'D':
-                       dsize = atoll(optarg);
+                       dsize = strtoll(optarg, NULL, 10);
                        /* fall through */
                case 'd':
                        dflag = 1;
@@ -218,7 +160,7 @@ main(int argc, char **argv)
                        lflag = iflag = 1;
                        break;
                case 'L':
-                       lsize = atoll(optarg);
+                       lsize = strtoll(optarg, NULL, 10);
                        /* fall through */
                case 'l':
                        lflag = 1;
@@ -234,7 +176,7 @@ main(int argc, char **argv)
                        progname = optarg;
                        break;
                case 'R':
-                       rsize = atoll(optarg);
+                       rsize = strtoll(optarg, NULL, 10);
                        /* fall through */
                case 'r':
                        rflag = 1;
@@ -246,7 +188,7 @@ main(int argc, char **argv)
                        lflag = xflag = 1;
                        break;
                case 'V':
-                       printf("%s version %s\n", progname, VERSION);
+                       printf(_("%s version %s\n"), progname, VERSION);
                        exit(0);
                case '?':
                default:
@@ -268,19 +210,26 @@ main(int argc, char **argv)
                return 1;
        }
 
+       if (!platform_test_xfs_fd(ffd)) {
+               fprintf(stderr, _("%s: specified file "
+                       "[\"%s\"] is not on an XFS filesystem\n"),
+                       progname, fname);
+               exit(1);
+       }
+
        /* get the current filesystem size & geometry */
-       if (ioctl(ffd, XFS_IOC_FSGEOMETRY, &geo) < 0) {
+       if (xfsctl(fname, ffd, XFS_IOC_FSGEOMETRY, &geo) < 0) {
                /*
-                * OK, new ioctl barfed - back off and try earlier version
+                * OK, new xfsctl barfed - back off and try earlier version
                 * as we're probably running an older kernel version.
-                * Only field added in the v2 geometry ioctl is "logsunit"
+                * Only field added in the v2 geometry xfsctl is "logsunit"
                 * so we'll zero that out for later display (as zero).
                 */
-               geo.logsunit = 1;       /* 1 BB */
-               if (ioctl(ffd, XFS_IOC_FSGEOMETRY_V1, &geo) < 0) {
-                       fprintf(stderr,
+               geo.logsunit = 0;
+               if (xfsctl(fname, ffd, XFS_IOC_FSGEOMETRY_V1, &geo) < 0) {
+                       fprintf(stderr, _(
                                "%s: cannot determine geometry of filesystem"
-                               " mounted at %s: %s\n",
+                               " mounted at %s: %s\n"),
                                progname, fname, strerror(errno));
                        exit(1);
                }
@@ -291,7 +240,7 @@ main(int argc, char **argv)
        logversion = geo.flags & XFS_FSOP_GEOM_FLAGS_LOGV2 ? 2 : 1;
 
        if (nflag) {
-               report_info(geo, fname, unwritten, dirversion, logversion, 
+               report_info(geo, fname, unwritten, dirversion, logversion,
                                isint);
                exit(0);
        }
@@ -312,17 +261,18 @@ main(int argc, char **argv)
 
        /* check we got the info for all the sections we are trying to modify */
        if (!xi.ddev) {
-               fprintf(stderr, "%s: failed to access data device for %s\n",
+               fprintf(stderr, _("%s: failed to access data device for %s\n"),
                        progname, fname);
                exit(1);
        }
        if (lflag && !isint && !xi.logdev) {
-               fprintf(stderr, "%s: failed to access external log for %s\n",
+               fprintf(stderr, _("%s: failed to access external log for %s\n"),
                        progname, fname);
                exit(1);
        }
        if (rflag && !xi.rtdev) {
-               fprintf(stderr, "%s: failed to access realtime device for %s\n",
+               fprintf(stderr,
+                       _("%s: failed to access realtime device for %s\n"),
                        progname, fname);
                exit(1);
        }
@@ -340,7 +290,7 @@ main(int argc, char **argv)
         * so if we have (size % 2), on any partition, we can't get
         * to the last 512 bytes.  Just chop it down by a block.
         */
-       
+
        ddsize -= (ddsize % 2);
        dlsize -= (dlsize % 2);
        drsize -= (drsize % 2);
@@ -355,40 +305,40 @@ main(int argc, char **argv)
                if (!dsize)
                        dsize = ddsize / (geo.blocksize / BBSIZE);
                else if (dsize > ddsize / (geo.blocksize / BBSIZE)) {
-                       fprintf(stderr,
-                               "data size %lld too large, maximum is %lld\n",
+                       fprintf(stderr, _(
+                               "data size %lld too large, maximum is %lld\n"),
                                (long long)dsize,
                                (long long)(ddsize/(geo.blocksize/BBSIZE)));
                        error = 1;
                }
 
-               new_agcount = dsize / geo.agblocks 
+               new_agcount = dsize / geo.agblocks
                           + (dsize % geo.agblocks != 0);
 
                if (!error && dsize < geo.datablocks) {
-                       fprintf(stderr, "data size %lld too small,"
-                               " old size is %lld\n",
+                       fprintf(stderr, _("data size %lld too small,"
+                               " old size is %lld\n"),
                                (long long)dsize, (long long)geo.datablocks);
                        error = 1;
                } else if (!error &&
                           dsize == geo.datablocks && maxpct == geo.imaxpct) {
                        if (dflag)
-                               fprintf(stderr,
-                                       "data size unchanged, skipping\n");
+                               fprintf(stderr, _(
+                                       "data size unchanged, skipping\n"));
                        if (mflag)
-                               fprintf(stderr,
-                                       "inode max pct unchanged, skipping\n");
+                               fprintf(stderr, _(
+                                       "inode max pct unchanged, skipping\n"));
                } else if (!error && !nflag) {
                        in.newblocks = (__u64)dsize;
                        in.imaxpct = (__u32)maxpct;
-                       if (ioctl(ffd, XFS_IOC_FSGROWFSDATA, &in) < 0) {
+                       if (xfsctl(fname, ffd, XFS_IOC_FSGROWFSDATA, &in) < 0) {
                                if (errno == EWOULDBLOCK)
-                                       fprintf(stderr,
-                                "%s: growfs operation in progress already\n",
+                                       fprintf(stderr, _(
+                                "%s: growfs operation in progress already\n"),
                                                progname);
                                else
-                                       fprintf(stderr,
-                               "%s: ioctl failed - XFS_IOC_FSGROWFSDATA: %s\n",
+                                       fprintf(stderr, _(
+                               "%s: XFS_IOC_FSGROWFSDATA xfsctl failed: %s\n"),
                                                progname, strerror(errno));
                                error = 1;
                        }
@@ -403,35 +353,35 @@ main(int argc, char **argv)
                if (!rsize)
                        rsize = drsize / (geo.blocksize / BBSIZE);
                else if (rsize > drsize / (geo.blocksize / BBSIZE)) {
-                       fprintf(stderr,
-                       "realtime size %lld too large, maximum is %lld\n",
+                       fprintf(stderr, _(
+                       "realtime size %lld too large, maximum is %lld\n"),
                                rsize, drsize / (geo.blocksize / BBSIZE));
                        error = 1;
                }
                if (!error && rsize < geo.rtblocks) {
-                       fprintf(stderr,
-                       "realtime size %lld too small, old size is %lld\n",
+                       fprintf(stderr, _(
+                       "realtime size %lld too small, old size is %lld\n"),
                                (long long)rsize, (long long)geo.rtblocks);
                        error = 1;
                } else if (!error && rsize == geo.rtblocks) {
                        if (rflag)
-                               fprintf(stderr,
-                                       "realtime size unchanged, skipping\n");
+                               fprintf(stderr, _(
+                                       "realtime size unchanged, skipping\n"));
                } else if (!error && !nflag) {
                        in.newblocks = (__u64)rsize;
                        in.extsize = (__u32)esize;
-                       if (ioctl(ffd, XFS_IOC_FSGROWFSRT, &in) < 0) {
+                       if (xfsctl(fname, ffd, XFS_IOC_FSGROWFSRT, &in) < 0) {
                                if (errno == EWOULDBLOCK)
-                                       fprintf(stderr,
-                               "%s: growfs operation in progress already\n",
+                                       fprintf(stderr, _(
+                               "%s: growfs operation in progress already\n"),
                                                progname);
                                else if (errno == ENOSYS)
-                                       fprintf(stderr,
-                               "%s: realtime growth not implemented\n",
+                                       fprintf(stderr, _(
+                               "%s: realtime growth not implemented\n"),
                                                progname);
                                else
-                                       fprintf(stderr,
-                               "%s: ioctl failed - XFS_IOC_FSGROWFSRT: %s\n",
+                                       fprintf(stderr, _(
+                               "%s: XFS_IOC_FSGROWFSRT xfsctl failed: %s\n"),
                                                progname, strerror(errno));
                                error = 1;
                        }
@@ -447,54 +397,55 @@ main(int argc, char **argv)
                        in.isint = 1;
                else if (xflag)
                        in.isint = 0;
-               else 
+               else
                        in.isint = xi.logBBsize == 0;
                if (lsize == geo.logblocks && (in.isint == isint)) {
                        if (lflag)
                                fprintf(stderr,
-                                       "log size unchanged, skipping\n");
+                                       _("log size unchanged, skipping\n"));
                } else if (!nflag) {
                        in.newblocks = (__u32)lsize;
-                       if (ioctl(ffd, XFS_IOC_FSGROWFSLOG, &in) < 0) {
+                       if (xfsctl(fname, ffd, XFS_IOC_FSGROWFSLOG, &in) < 0) {
                                if (errno == EWOULDBLOCK)
                                        fprintf(stderr,
-                               "%s: growfs operation in progress already\n",
+                               _("%s: growfs operation in progress already\n"),
                                                progname);
                                else if (errno == ENOSYS)
                                        fprintf(stderr,
-                               "%s: log growth not supported yet\n", progname);
+                               _("%s: log growth not supported yet\n"),
+                                               progname);
                                else
                                        fprintf(stderr,
-                               "%s: ioctl failed - XFS_IOC_FSGROWFSLOG: %s\n",
+                               _("%s: XFS_IOC_FSGROWFSLOG xfsctl failed: %s\n"),
                                                progname, strerror(errno));
                                error = 1;
                        }
                }
        }
 
-       if (ioctl(ffd, XFS_IOC_FSGEOMETRY_V1, &ngeo) < 0) {
-               fprintf(stderr, "%s: ioctl failed - XFS_IOC_FSGEOMETRY: %s\n",
+       if (xfsctl(fname, ffd, XFS_IOC_FSGEOMETRY_V1, &ngeo) < 0) {
+               fprintf(stderr, _("%s: XFS_IOC_FSGEOMETRY xfsctl failed: %s\n"),
                        progname, strerror(errno));
                exit(1);
        }
        if (geo.datablocks != ngeo.datablocks)
-               printf("data blocks changed from %lld to %lld\n",
+               printf(_("data blocks changed from %lld to %lld\n"),
                        (long long)geo.datablocks, (long long)ngeo.datablocks);
        if (geo.imaxpct != ngeo.imaxpct)
-               printf("inode max percent changed from %d to %d\n",
+               printf(_("inode max percent changed from %d to %d\n"),
                        geo.imaxpct, ngeo.imaxpct);
        if (geo.logblocks != ngeo.logblocks)
-               printf("log blocks changed from %d to %d\n",
+               printf(_("log blocks changed from %d to %d\n"),
                        geo.logblocks, ngeo.logblocks);
        if ((geo.logstart == 0) != (ngeo.logstart == 0))
-               printf("log changed from %s to %s\n",
-                       geo.logstart ? "internal" : "external",
-                       ngeo.logstart ? "internal" : "external");
+               printf(_("log changed from %s to %s\n"),
+                       geo.logstart ? _("internal") : _("external"),
+                       ngeo.logstart ? _("internal") : _("external"));
        if (geo.rtblocks != ngeo.rtblocks)
-               printf("realtime blocks changed from %lld to %lld\n",
+               printf(_("realtime blocks changed from %lld to %lld\n"),
                        (long long)geo.rtblocks, (long long)ngeo.rtblocks);
        if (geo.rtextsize != ngeo.rtextsize)
-               printf("realtime extent size changed from %d to %d\n",
+               printf(_("realtime extent size changed from %d to %d\n"),
                        geo.rtextsize, ngeo.rtextsize);
        exit(0);
 }