From 8e1929914dc45b6e79b312f97f6ce5b7d388c54a Mon Sep 17 00:00:00 2001 From: Barry Naujok Date: Fri, 8 Dec 2006 03:01:47 +0000 Subject: [PATCH] Fix up xfs_io mread command that read from the wrong offset Merge of master-melb:xfs-cmds:27661a by kenmcd. Fix up xfs_io mread command that read from the wrong offset --- doc/CHANGES | 9 +++++-- io/mmap.c | 68 +++++++++++++++++++++-------------------------- man/man8/xfs_io.8 | 8 +++--- 3 files changed, 41 insertions(+), 44 deletions(-) diff --git a/doc/CHANGES b/doc/CHANGES index f31456e8a..a245139bc 100644 --- a/doc/CHANGES +++ b/doc/CHANGES @@ -1,6 +1,11 @@ +xfsprogs-2.8.x + - Fix up xfs_io mmap read that read from the wrong offset. + - Updated xfs_io man page. + Thanks to Utako Kusaka for these. + xfsprogs-2.8.17 - Fix up libxfs SEGV when attempting to mount a non-XFS filesystem. - Thanks to Utako Kuzaka for this. + Thanks to Utako Kusaka for this. - Fix up xfs_repair aborting if it finds an inode with an invalid inode type. - Fix up default realtime extent size for large block sizes. @@ -17,7 +22,7 @@ xfsprogs-2.8.15 (19 October 2006) xfsprogs-2.8.14 (6 October 2006) - Fix up the ring command in xfs_db, - Thanks to Utako Kuzaka for this. + Thanks to Utako Kusaka for this. - Set the blocksize on the device to the given sector size which is _not_ necessarily 512 bytes; idea suggested by Shailendra Tripathi. diff --git a/io/mmap.c b/io/mmap.c index faace11c6..c3aa88459 100644 --- a/io/mmap.c +++ b/io/mmap.c @@ -323,26 +323,6 @@ msync_f( return 0; } -static int -read_mapping( - char *dest, - off64_t offset, - int dump, - off64_t dumpoffset, - size_t dumplength) -{ - *dest = *(((char *)mapping->addr) + offset); - - if (offset % pagesize == 0) { - if (dump == 2) - dumpoffset += mapping->offset; - if (dump) - dump_buffer(dumpoffset, dumplength); - return 1; - } - return 0; -} - static void mread_help(void) { @@ -373,9 +353,9 @@ mread_f( int argc, char **argv) { - off64_t offset, tmp; + off64_t offset, tmp, dumpoffset, printoffset; ssize_t length; - size_t dumplen; + size_t dumplen, cnt = 0; char *bp; void *start; int dump = 0, rflag = 0, c; @@ -422,6 +402,11 @@ mread_f( start = check_mapping_range(mapping, offset, length, 0); if (!start) return 0; + dumpoffset = offset - mapping->offset; + if (dump == 2) + printoffset = offset; + else + printoffset = dumpoffset; if (alloc_buffer(pagesize, 0, 0) < 0) return 0; @@ -432,28 +417,35 @@ mread_f( dumplen = pagesize; if (rflag) { - for (tmp = length, c = 0; tmp > 0; tmp--, bp++, c = 1) - if (read_mapping(bp, tmp, c? dump:0, offset, dumplen)) { + for (tmp = length - 1, c = 0; tmp >= 0; tmp--, c = 1) { + *bp = *(((char *)mapping->addr) + dumpoffset + tmp); + cnt++; + if (c && cnt == dumplen) { + if (dump) { + dump_buffer(printoffset, dumplen); + printoffset += dumplen; + } bp = (char *)buffer; dumplen = pagesize; + cnt = 0; + } else { + bp++; } + } } else { - for (tmp = 0, c = 0; tmp < length; tmp++, bp++, c = 1) - if (read_mapping(bp, tmp, c? dump:0, offset, dumplen)) { + for (tmp = 0, c = 0; tmp < length; tmp++, c = 1) { + *bp = *(((char *)mapping->addr) + dumpoffset + tmp); + cnt++; + if (c && cnt == dumplen) { + if (dump) + dump_buffer(printoffset + tmp - + (dumplen - 1), dumplen); bp = (char *)buffer; dumplen = pagesize; + cnt = 0; + } else { + bp++; } - } - /* dump the remaining (partial page) part of the read buffer */ - if (dump) { - if (rflag) - dumplen = length % pagesize; - else - dumplen = tmp % pagesize; - if (dumplen) { - if (dump == 2) - tmp += mapping->offset; - dump_buffer(tmp, dumplen); } } return 0; @@ -571,7 +563,7 @@ mwrite_f( return 0; if (rflag) { - for (tmp = offset + length; tmp > offset; tmp--) + for (tmp = offset + length -1; tmp >= offset; tmp--) ((char *)mapping->addr)[tmp] = seed; } else { for (tmp = offset; tmp < offset + length; tmp++) diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index 2b74e6747..1e2c23037 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -99,7 +99,7 @@ Closes the current open file, marking the next open file as current \f3c\f1 See the \f3close\f1 command. .TP -\f3pread\f1 [ \f2\-b bsize\f1 ] [ \f2\-v\f1 ] +\f3pread\f1 [ \f2\-b bsize\f1 ] [ \f2\-v\f1 ] \f2offset\f1 \f2length\f1 Reads a range of bytes in a specified blocksize from the given offset. .br The \f3\-b\f1 option can be used to set the blocksize into which the @@ -112,7 +112,7 @@ by default only the count of bytes actually read is dumped. \f3r\f1 See the \f3pread\f1 command. .TP -\f3pwrite\f1 [ \f2\-i file\f1 ] [ \f2\-d\f1 ] [ \f2\-s skip\f1 ] [ \f2\-b size\f1 ] [ \f2\-S seed\f1 ] +\f3pwrite\f1 [ \f2\-i file\f1 ] [ \f2\-d\f1 ] [ \f2\-s skip\f1 ] [ \f2\-b size\f1 ] [ \f2\-S seed\f1 ] \f2offset\f1 \f2length\f1 Writes a range of bytes in a specified blocksize from the given offset. The bytes written can be either a set pattern or read in from another file before writing. @@ -211,7 +211,7 @@ Unmaps the current memory mapping. \f3mu\f1 See the \f3munmap\f1 command. .TP -\f3mread\f1 [ \-\f2frv\f1 ] +\f3mread\f1 [ \-\f2frv\f1 ] [ \f2offset\f1 \f2length\f1 ] Accesses a segment of the current memory mapping, optionally dumping it to the standard output stream (with \f2-v\f1 or \f2-f\f1 option) for inspection. The accesses are performed sequentially from the start offset by default, @@ -224,7 +224,7 @@ offsets relative to the start of the mapping. \f3mr\f1 See the \f3mread\f1 command. .TP -\f3mwrite\f1 [ \f2-r\f1 ] [ \f2-S seed\f1 ] +\f3mwrite\f1 [ \f2-r\f1 ] [ \f2-S seed\f1 ] [ \f2offset\f1 \f2length\f1 ] Stores a byte into memory for a range within a mapping. The default stored value is 'X', repeated to fill the range specified, but this can be changed using the \f2-S\f1 option. -- 2.47.2