]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
Fix up xfs_io mread command that read from the wrong offset
authorBarry Naujok <bnaujok@sgi.com>
Fri, 8 Dec 2006 03:01:47 +0000 (03:01 +0000)
committerBarry Naujok <bnaujok@sgi.com>
Fri, 8 Dec 2006 03:01:47 +0000 (03:01 +0000)
Merge of master-melb:xfs-cmds:27661a by kenmcd.

  Fix up xfs_io mread command that read from the wrong offset

doc/CHANGES
io/mmap.c
man/man8/xfs_io.8

index f31456e8a9a5698044e9038cb7fa670fa21ef8fd..a245139bc8538ae3fdd1f9d7805a474f5004379d 100644 (file)
@@ -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 <utako@tnes.nec.co.jp> for these.
+
 xfsprogs-2.8.17
        - Fix up libxfs SEGV when attempting to mount a non-XFS filesystem.
-         Thanks to Utako Kuzaka <utako@tnes.nec.co.jp> for this.
+         Thanks to Utako Kusaka <utako@tnes.nec.co.jp> 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 <utako@tnes.nec.co.jp> for this.
+         Thanks to Utako Kusaka <utako@tnes.nec.co.jp> for this.
        - Set the blocksize on the device to the given sector
          size which is _not_ necessarily 512 bytes;
          idea suggested by Shailendra Tripathi.
index faace11c605bd65988e5cb6388cf5ee920c35c5e..c3aa88459049cf402d007fa9dc4efc6f7828c278 100644 (file)
--- 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++)
index 2b74e67473cf259e929e8973d6fa68f300028c94..1e2c23037c02c3977604443990bc03404fbea474 100644 (file)
@@ -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.