/*
- * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2003-2004 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
#include <xfs/libxfs.h>
#include "command.h"
+#include "init.h"
cmdinfo_t *cmdtab;
int ncmds;
fprintf(stderr, _("command \"%s\" not found\n"), cmd);
return 0;
}
+ if (foreign && !ct->foreign) {
+ fprintf(stderr,
+ _("foreign file is open, %s command is for XFS filesystems only\n"),
+ cmd);
+ }
if (argc-1 < ct->argmin || (ct->argmax != -1 && argc-1 > ct->argmax)) {
if (ct->argmax == -1)
fprintf(stderr,
/*
- * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2000-2004 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
int argmin;
int argmax;
int canpush;
+ int foreign;
const char *args;
const char *oneline;
helpfunc_t help;
/*
- * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2003-2004 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
fsync_cmd.name = _("fsync");
fsync_cmd.altname = _("s");
fsync_cmd.cfunc = fsync_f;
+ fsync_cmd.foreign = 1;
fsync_cmd.oneline =
_("calls fsync(2) to flush all in-core file state to disk");
fdatasync_cmd.name = _("fdatasync");
fdatasync_cmd.altname = _("ds");
fdatasync_cmd.cfunc = fdatasync_f;
+ fdatasync_cmd.foreign = 1;
fdatasync_cmd.oneline =
_("calls fdatasync(2) to flush the files in-core data to disk");
/*
- * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2003-2004 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
help_cmd.cfunc = help_f;
help_cmd.argmin = 0;
help_cmd.argmax = 1;
+ help_cmd.foreign = 1;
help_cmd.args = _("[command]");
help_cmd.oneline = _("help for one or all commands");
/*
- * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2003-2004 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
int readonly;
int directio;
int realtime;
+int foreign;
int append;
int osync;
int trunc;
usage(void)
{
fprintf(stderr,
- _("Usage: %s [-r] [-p prog] [-c cmd]... file\n"), progname);
+ _("Usage: %s [-adFfrstx] [-p prog] [-c cmd]... file\n"),
+ progname);
exit(1);
}
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- while ((c = getopt(argc, argv, "ac:dfp:rstVx")) != EOF) {
+ while ((c = getopt(argc, argv, "ac:dFfp:rstVx")) != EOF) {
switch (c) {
case 'a': /* append */
append = 1;
case 'd': /* directIO */
directio = 1;
break;
+ case 'F': /* foreign */
+ foreign = 1;
+ break;
case 'f': /* create */
fflag = 1;
break;
usage();
fname = strdup(argv[optind]);
- if ((fdesc = openfile(fname, &fgeom, append, fflag, directio,
+ if ((fdesc = openfile(fname, foreign ? NULL : &fgeom,
+ append, fflag, directio,
readonly, osync, trunc, realtime)) < 0)
exit(1);
/*
- * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2003-2004 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
extern int readonly;
extern int directio;
extern int realtime;
+extern int foreign;
extern int append;
extern int osync;
extern int trunc;
/*
- * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2003-2004 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
"\n"
" Opens a file for subsequent use by all of the other xfs_io commands.\n"
" With no arguments, open uses the stat command to show the current file.\n"
+" -F -- foreign filesystem file, disallow XFS-specific commands\n"
" -a -- open with the O_APPEND flag (append-only mode)\n"
" -c -- open with O_CREAT (create the file if it doesn't exist)\n"
" -d -- open with O_DIRECT (non-buffered IO, note alignment constraints)\n"
int argc,
char **argv)
{
+ int Fflag = 0;
int aflag = 0;
int cflag = 0;
int dflag = 0;
int tflag = 0;
int xflag = 0;
char *filename;
- xfs_fsop_geom_t geometry;
+ xfs_fsop_geom_t geometry = { 0 };
int fd;
int c;
if (argc == 1)
return stat_f(argc, argv);
- while ((c = getopt(argc, argv, "acdrstx")) != EOF) {
+ while ((c = getopt(argc, argv, "Facdrstx")) != EOF) {
switch (c) {
+ case 'F':
+ Fflag = 1;
+ break;
case 'a':
aflag = 1;
break;
if (optind != argc - 1)
return usage();
- fd = openfile(argv[optind], &geometry,
+ fd = openfile(argv[optind], Fflag ? NULL : &geometry,
aflag, cflag, dflag, rflag, sflag, tflag, xflag);
if (fd < 0)
return 0;
osync = sflag;
trunc = tflag;
append = aflag;
+ foreign = Fflag;
directio = dflag;
readonly = rflag;
realtime = xflag;
printf(_("stat.ctime = %s"), ctime(&st.st_ctime));
}
}
+ if (foreign)
+ return 0;
if ((xfsctl(fname, fdesc, XFS_IOC_FSGETXATTR, &fsx)) < 0) {
perror("xfsctl(XFS_IOC_FSGETXATTR)");
} else {
printf(_("statfs.f_files = %lld\n"), (long long) st.f_files);
printf(_("statfs.f_ffree = %lld\n"), (long long) st.f_ffree);
}
+ if (foreign)
+ return 0;
if ((xfsctl(fname, fdesc, XFS_IOC_FSGEOMETRY_V1, &fsgeo)) < 0) {
perror("xfsctl(XFS_IOC_FSGEOMETRY_V1)");
} else {
open_cmd.cfunc = open_f;
open_cmd.argmin = 0;
open_cmd.argmax = -1;
+ open_cmd.foreign = 1;
open_cmd.args = _("[-acdrstx] [path]");
open_cmd.oneline =
_("close the current file, open file specified by path");
stat_cmd.cfunc = stat_f;
stat_cmd.argmin = 0;
stat_cmd.argmax = 1;
+ stat_cmd.foreign = 1;
stat_cmd.args = _("[-v]");
stat_cmd.oneline =
_("statistics on the currently open file");
statfs_cmd.name = _("statfs");
statfs_cmd.cfunc = statfs_f;
+ statfs_cmd.foreign = 1;
statfs_cmd.oneline =
_("statistics on the filesystem of the currently open file");
{
off64_t offset;
long long count, total;
- unsigned int bsize = 4096;
+ unsigned int blocksize, sectsize;
struct timeval t1, t2;
char s1[64], s2[64], ts[64];
int vflag = 0;
int c;
+ if (foreign) {
+ blocksize = 4096;
+ sectsize = 512;
+ } else {
+ blocksize = fgeom.blocksize;
+ sectsize = fgeom.sectsize;
+ }
while ((c = getopt(argc, argv, "b:v")) != EOF) {
switch (c) {
case 'b':
- bsize = cvtnum(fgeom.blocksize, fgeom.sectsize, optarg);
- if (bsize < 0) {
+ blocksize = cvtnum(blocksize, sectsize, optarg);
+ if (blocksize < 0) {
printf(_("non-numeric bsize -- %s\n"), optarg);
return 0;
}
printf("%s %s\n", pread_cmd.name, pread_cmd.oneline);
return 0;
}
- offset = cvtnum(fgeom.blocksize, fgeom.sectsize, argv[optind]);
+ offset = cvtnum(blocksize, sectsize, argv[optind]);
if (offset < 0) {
printf(_("non-numeric offset argument -- %s\n"), argv[optind]);
return 0;
}
optind++;
- count = cvtnum(fgeom.blocksize, fgeom.sectsize, argv[optind]);
+ count = cvtnum(blocksize, sectsize, argv[optind]);
if (count < 0) {
printf(_("non-numeric length argument -- %s\n"), argv[optind]);
return 0;
}
- if (!alloc_buffer(bsize, 0xabababab))
+ if (!alloc_buffer(blocksize, 0xabababab))
return 0;
gettimeofday(&t1, NULL);
pread_cmd.cfunc = pread_f;
pread_cmd.argmin = 2;
pread_cmd.argmax = -1;
+ pread_cmd.foreign = 1;
pread_cmd.args = _("[-b bs] [-v] off len");
pread_cmd.oneline = _("reads a number of bytes at a specified offset");
pread_cmd.help = pread_help;
off64_t offset, skip = 0;
long long count, total;
unsigned int seed = 0xcdcdcdcd;
- unsigned int bsize = 4096;
+ unsigned int blocksize, sectsize;
struct timeval t1, t2;
char s1[64], s2[64], ts[64];
char *sp, *infile = NULL;
int c, fd = -1, dflag = 0;
+ if (foreign) {
+ blocksize = 4096;
+ sectsize = 512;
+ } else {
+ blocksize = fgeom.blocksize;
+ sectsize = fgeom.sectsize;
+ }
while ((c = getopt(argc, argv, "b:df:i:s:S:")) != EOF) {
switch (c) {
case 'b':
- bsize = cvtnum(fgeom.blocksize, fgeom.sectsize, optarg);
- if (bsize < 0) {
+ blocksize = cvtnum(blocksize, sectsize, optarg);
+ if (blocksize < 0) {
printf(_("non-numeric bsize -- %s\n"), optarg);
return 0;
}
infile = optarg;
break;
case 's':
- skip = cvtnum(fgeom.blocksize, fgeom.sectsize, optarg);
+ skip = cvtnum(blocksize, sectsize, optarg);
if (skip < 0) {
printf(_("non-numeric skip -- %s\n"), optarg);
return 0;
printf("%s %s\n", pwrite_cmd.name, pwrite_cmd.oneline);
return 0;
}
- offset = cvtnum(fgeom.blocksize, fgeom.sectsize, argv[optind]);
+ offset = cvtnum(blocksize, sectsize, argv[optind]);
if (offset < 0) {
printf(_("non-numeric offset argument -- %s\n"), argv[optind]);
return 0;
}
optind++;
- count = cvtnum(fgeom.blocksize, fgeom.sectsize, argv[optind]);
+ count = cvtnum(blocksize, sectsize, argv[optind]);
if (count < 0) {
printf(_("non-numeric length argument -- %s\n"), argv[optind]);
return 0;
}
- if (!alloc_buffer(bsize, seed))
+ if (!alloc_buffer(blocksize, seed))
return 0;
if (infile &&
return 0;
gettimeofday(&t1, NULL);
- if ((c = write_buffer(offset, count, bsize, fd, skip, &total)) < 0) {
+ c = write_buffer(offset, count, blocksize, fd, skip, &total);
+ if (c < 0) {
close(fd);
return 0;
}
pwrite_cmd.cfunc = pwrite_f;
pwrite_cmd.argmin = 2;
pwrite_cmd.argmax = -1;
+ pwrite_cmd.foreign = 1;
pwrite_cmd.args =
_("[-i infile [-d] [-s skip]] [-b bs] [-S seed] off len");
pwrite_cmd.oneline =
/*
- * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2003-2004 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
quit_cmd.name = _("quit");
quit_cmd.altname = _("q");
quit_cmd.cfunc = quit_f;
+ quit_cmd.foreign = 1;
quit_cmd.oneline = _("exit xfs_io");
add_command(&quit_cmd);
/*
- * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2003-2004 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
char **argv)
{
off64_t offset;
+ unsigned int blocksize, sectsize;
- offset = cvtnum(fgeom.blocksize, fgeom.sectsize, argv[1]);
+ if (foreign) {
+ blocksize = 4096;
+ sectsize = 512;
+ } else {
+ blocksize = fgeom.blocksize;
+ sectsize = fgeom.sectsize;
+ }
+ offset = cvtnum(blocksize, sectsize, argv[1]);
if (offset < 0) {
printf(_("non-numeric truncate argument -- %s\n"), argv[1]);
return 0;
truncate_cmd.cfunc = truncate_f;
truncate_cmd.argmin = 1;
truncate_cmd.argmax = 1;
+ truncate_cmd.foreign = 1;
truncate_cmd.args = _("off");
truncate_cmd.oneline =
_("truncates the current file at the given offset");
xfs_io \- debug the IO path of an XFS filesystem
.SH SYNOPSIS
.nf
-\f3xfs_io\f1 [ \f3\-c\f1 cmd ] ... [ \f3\-p\f1 prog ] [ \f3\-r\f1 ] file
+\f3xfs_io\f1 [ \f3\-c\f1 cmd ] ... [ \f3\-p\f1 prog ] [ \f3\-Ffr\f1 ] file
.fi
.SH DESCRIPTION
\f2xfs_io\f1 is a debugging tool like \f2xfs_db\f1(8), but is aimed
Set the program name for prompts and some error messages,
the default value is \f2xfs_io\f1.
.TP
+\f3\-F\f1
+Allow \f2file\f1 to be ``foreign'', i.e. not in an XFS filesystem.
+This mode has a restricted set of commands.
+.TP
+\f3\-f\f1
+Create \f2file\f1 if it does not already exist.
+.TP
\f3\-r\f1
Open \f2file\f1 read-only, initially.
.SH CONCEPTS
\f3o\f1
See the \f3open\f1 command.
.TP
-\f3open\f1 [ \f2-acdrstx\f1 ] [ \f2path\f1 ]
+\f3open\f1 [ \f2-Facdrstx\f1 ] [ \f2path\f1 ]
Closes the current file, and opens the file specified by \f2path\f1 instead.
Without any arguments, displays statistics about the currently open file \-
see the \f3stat\f1 command.
.br
+The \f3\-F\f1 option allows non-XFS (foreign) files to be opened and
+operated on with a restricted command set.
+.br
The \f3\-a\f1 option opens append-only (O_APPEND).
.br
The \f3\-c\f1 option creates the file if it doesn't already exist (O_CREAT).