]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/open.c
2 * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
37 static cmdinfo_t open_cmd
;
38 static cmdinfo_t stat_cmd
;
39 static cmdinfo_t statfs_cmd
;
40 static int stat_f(int, char **);
56 oflags
= (rflag
? O_RDONLY
: O_RDWR
);
68 fd
= open(path
, oflags
, 0644);
73 if (!platform_test_xfs_fd(fd
)) {
74 fprintf(stderr
, _("%s: specified file "
75 "[\"%s\"] is not on an XFS filesystem\n"),
81 if (!readonly
&& xflag
) { /* read/write and realtime */
84 if (xfsctl(path
, fd
, XFS_IOC_FSGETXATTR
, &attr
) < 0) {
85 perror("XFS_IOC_FSGETXATTR");
89 if (!(attr
.fsx_xflags
& XFS_XFLAG_REALTIME
)) {
90 attr
.fsx_xflags
|= XFS_XFLAG_REALTIME
;
91 if (xfsctl(path
, fd
, XFS_IOC_FSSETXATTR
, &attr
) < 0) {
92 perror("XFS_IOC_FSSETXATTR");
104 printf("%s %s\n", open_cmd
.name
, open_cmd
.oneline
);
113 " opens a new file in the requested mode, after closing the current file\n"
116 " 'open -d /tmp/data' - opens data file read-write for direct IO\n"
118 " Opens a file for subsequent use by all of the other xfs_io commands.\n"
119 " With no arguments, open uses the stat command to show the current file.\n"
120 " -a -- open with the O_APPEND flag (append-only mode)\n"
121 " -c -- open with O_CREAT (create the file if it doesn't exist)\n"
122 " -d -- open with O_DIRECT (non-buffered IO, note alignment constraints)\n"
123 " -r -- open with O_RDONLY, the default is O_RDWR\n"
124 " -s -- open with O_SYNC\n"
125 " -t -- open with O_TRUNC (truncate the file to zero length if it exists)\n"
126 " -x -- mark the file as a realtime XFS file immediately after opening it\n"
127 " Note1: read/write direct IO requests must be blocksize aligned.\n"
128 " Note2: the bmap for non-regular files can be obtained provided the file\n"
129 " was opened appropriately (in particular, must be opened read-only).\n"
150 return stat_f(argc
, argv
);
152 while ((c
= getopt(argc
, argv
, "acdrstx")) != EOF
) {
180 if (optind
!= argc
- 1)
183 fd
= openfile(argv
[optind
],
184 aflag
, cflag
, dflag
, rflag
, sflag
, tflag
, xflag
);
188 filename
= strdup(argv
[optind
]);
196 * All OK, proceed to make this the new global open file
218 if (fstat64(fdesc
, &st
) < 0) {
226 filetype(mode_t mode
)
228 switch (mode
& S_IFMT
) {
232 return _("directory");
234 return _("char device");
236 return _("block device");
238 return _("regular file");
240 return _("symbolic link");
254 char fullname
[PATH_MAX
+ 1];
256 printf(_("fd.path = \"%s\"\n"),
257 realpath(fname
, fullname
) ? fullname
: fname
);
258 printf(_("fd.flags = %s,%s,%s%s%s\n"),
259 osync
? _("sync") : _("non-sync"),
260 directio
? _("direct") : _("non-direct"),
261 readonly
? _("read-only") : _("read-write"),
262 realtime
? _(",real-time") : "",
263 append
? _(",append-only") : "");
264 if (fstat64(fdesc
, &st
) < 0) {
267 printf(_("stat.ino = %lld\n"), (long long)st
.st_ino
);
268 printf(_("stat.type = %s\n"), filetype(st
.st_mode
));
269 printf(_("stat.size = %lld\n"), (long long)st
.st_size
);
270 printf(_("stat.blocks = %lld\n"), (long long)st
.st_blocks
);
271 if (argc
== 2 && !strcmp(argv
[1], "-v")) {
272 printf(_("stat.atime = %s"), ctime(&st
.st_atime
));
273 printf(_("stat.mtime = %s"), ctime(&st
.st_mtime
));
274 printf(_("stat.ctime = %s"), ctime(&st
.st_ctime
));
277 if ((xfsctl(fname
, fdesc
, XFS_IOC_FSGETXATTR
, &fsx
)) < 0) {
278 perror("xfsctl(XFS_IOC_FSGETXATTR)");
280 printf(_("xattr.xflags = 0x%x\n"), fsx
.fsx_xflags
);
281 printf(_("xattr.nextents = %u\n"), fsx
.fsx_nextents
);
291 struct xfs_fsop_geom_v1 fsgeo
;
293 char fullname
[PATH_MAX
+ 1];
295 printf(_("fd.path = \"%s\"\n"),
296 realpath(fname
, fullname
) ? fullname
: fname
);
297 if (platform_fstatfs(fdesc
, &st
) < 0) {
300 printf(_("statfs.f_bsize = %lld\n"), (long long) st
.f_bsize
);
301 printf(_("statfs.f_blocks = %lld\n"), (long long) st
.f_blocks
);
302 #if !defined(__sgi__)
303 printf(_("statfs.f_bavail = %lld\n"), (long long) st
.f_bavail
);
306 if ((xfsctl(fname
, fdesc
, XFS_IOC_FSGEOMETRY_V1
, &fsgeo
)) < 0) {
307 perror("xfsctl(XFS_IOC_FSGEOMETRY_V1)");
309 printf(_("geom.bsize = %u\n"), fsgeo
.blocksize
);
310 printf(_("geom.agcount = %u\n"), fsgeo
.agcount
);
311 printf(_("geom.agblocks = %u\n"), fsgeo
.agblocks
);
312 printf(_("geom.datablocks = %llu\n"),
313 (unsigned long long) fsgeo
.datablocks
);
314 printf(_("geom.rtblocks = %llu\n"),
315 (unsigned long long) fsgeo
.rtblocks
);
316 printf(_("geom.rtextents = %llu\n"),
317 (unsigned long long) fsgeo
.rtextents
);
318 printf(_("geom.rtextsize = %u\n"), fsgeo
.rtextsize
);
319 printf(_("geom.sunit = %u\n"), fsgeo
.sunit
);
320 printf(_("geom.swidth = %u\n"), fsgeo
.swidth
);
328 open_cmd
.name
= _("open");
329 open_cmd
.altname
= _("o");
330 open_cmd
.cfunc
= open_f
;
332 open_cmd
.argmax
= -1;
333 open_cmd
.args
= _("[-acdrstx] [path]");
335 _("close the current file, open file specified by path");
336 open_cmd
.help
= open_help
;
338 stat_cmd
.name
= _("stat");
339 stat_cmd
.cfunc
= stat_f
;
342 stat_cmd
.args
= _("[-v]");
344 _("statistics on the currently open file");
346 statfs_cmd
.name
= _("statfs");
347 statfs_cmd
.cfunc
= statfs_f
;
349 _("statistics on the filesystem of the currently open file");
351 add_command(&open_cmd
);
352 add_command(&stat_cmd
);
353 add_command(&statfs_cmd
);