From 57f46ec02f6016d057a9edb9b77b33fe28ccc0ab Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Fri, 3 Jun 2005 06:11:20 +0000 Subject: [PATCH] Add O_NONBLOCK option to xfs_io open command. Merge of master-melb:xfs-cmds:22799a by kenmcd. --- io/file.c | 5 +++-- io/init.c | 9 ++++++--- io/io.h | 1 + io/open.c | 18 +++++++++++++----- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/io/file.c b/io/file.c index bb23109a2..037abef34 100644 --- a/io/file.c +++ b/io/file.c @@ -50,14 +50,15 @@ print_fileio( int index, int braces) { - printf(_("%c%03d%c %-14s (%s,%s,%s,%s%s%s)\n"), + printf(_("%c%03d%c %-14s (%s,%s,%s,%s%s%s%s)\n"), braces? '[' : ' ', index, braces? ']' : ' ', file->name, file->flags & IO_FOREIGN ? _("foreign") : _("xfs"), file->flags & IO_OSYNC ? _("sync") : _("non-sync"), file->flags & IO_DIRECT ? _("direct") : _("non-direct"), file->flags & IO_READONLY ? _("read-only") : _("read-write"), file->flags & IO_REALTIME ? _(",real-time") : "", - file->flags & IO_APPEND ? _(",append-only") : ""); + file->flags & IO_APPEND ? _(",append-only") : "", + file->flags & IO_NONBLOCK ? _(",non-block") : ""); } int diff --git a/io/init.c b/io/init.c index 0f92b3da6..d1947d630 100644 --- a/io/init.c +++ b/io/init.c @@ -140,12 +140,12 @@ init( pagesize = getpagesize(); gettimeofday(&stopwatch, NULL); - while ((c = getopt(argc, argv, "ac:dFfmp:rRstVx")) != EOF) { + while ((c = getopt(argc, argv, "ac:dFfmp:nrRstVx")) != EOF) { switch (c) { - case 'a': /* append */ + case 'a': flags |= IO_APPEND; break; - case 'c': /* commands */ + case 'c': add_user_command(optarg); break; case 'd': @@ -165,6 +165,9 @@ init( exit(1); } break; + case 'n': + flags |= IO_NONBLOCK; + break; case 'p': progname = optarg; break; diff --git a/io/io.h b/io/io.h index c5cdd4635..656fb243b 100644 --- a/io/io.h +++ b/io/io.h @@ -38,6 +38,7 @@ #define IO_CREAT (1<<5) #define IO_TRUNC (1<<6) #define IO_FOREIGN (1<<7) +#define IO_NONBLOCK (1<<8) /* * Regular file I/O control diff --git a/io/open.c b/io/open.c index 9c837912c..11b694b38 100644 --- a/io/open.c +++ b/io/open.c @@ -90,12 +90,13 @@ stat_f( int verbose = (argc == 2 && !strcmp(argv[1], "-v")); printf(_("fd.path = \"%s\"\n"), file->name); - printf(_("fd.flags = %s,%s,%s%s%s\n"), + printf(_("fd.flags = %s,%s,%s%s%s%s\n"), file->flags & IO_OSYNC ? _("sync") : _("non-sync"), file->flags & IO_DIRECT ? _("direct") : _("non-direct"), file->flags & IO_READONLY ? _("read-only") : _("read-write"), file->flags & IO_REALTIME ? _(",real-time") : "", - file->flags & IO_APPEND ? _(",append-only") : ""); + file->flags & IO_APPEND ? _(",append-only") : "", + file->flags & IO_NONBLOCK ? _(",non-block") : ""); if (fstat64(file->fd, &st) < 0) { perror("fstat64"); } else { @@ -143,6 +144,8 @@ openfile( oflags |= O_SYNC; if (flags & IO_TRUNC) oflags |= O_TRUNC; + if (flags & IO_NONBLOCK) + oflags |= O_NONBLOCK; fd = open(path, oflags, mode); if (fd < 0) { @@ -240,10 +243,11 @@ open_help(void) " -d -- open with O_DIRECT (non-buffered IO, note alignment constraints)\n" " -f -- open with O_CREAT (create the file if it doesn't exist)\n" " -m -- permissions to use in case a new file is created (default 0600)\n" +" -n -- open with O_NONBLOCK\n" " -r -- open with O_RDONLY, the default is O_RDWR\n" " -s -- open with O_SYNC\n" " -t -- open with O_TRUNC (truncate the file to zero length if it exists)\n" -" -x -- mark the file as a realtime XFS file immediately after opening it\n" +" -R -- mark the file as a realtime XFS file immediately after opening it\n" " Note1: usually read/write direct IO requests must be blocksize aligned;\n" " some kernels, however, allow sectorsize alignment for direct IO.\n" " Note2: the bmap for non-regular files can be obtained provided the file\n" @@ -268,7 +272,7 @@ open_f( return 0; } - while ((c = getopt(argc, argv, "Facdfm:rstx")) != EOF) { + while ((c = getopt(argc, argv, "FRacdfm:nrstx")) != EOF) { switch (c) { case 'F': flags |= IO_FOREIGN; @@ -290,6 +294,9 @@ open_f( return 0; } break; + case 'n': + flags |= IO_NONBLOCK; + break; case 'r': flags |= IO_READONLY; break; @@ -299,7 +306,8 @@ open_f( case 't': flags |= IO_TRUNC; break; - case 'x': + case 'R': + case 'x': /* backwards compatibility */ flags |= IO_REALTIME; break; default: -- 2.47.2