From d0a2e7d3a28b25f333a24fac0ded40544e0d05ed Mon Sep 17 00:00:00 2001 From: szaka Date: Tue, 12 Dec 2006 23:16:43 +0000 Subject: [PATCH] ntfs_read/ntfs_write: use pread/pwrite => 2-8% speed increase (Henk, Szaka) --- libntfs-3g/device.c | 23 ++++++++--------------- libntfs-3g/unix_io.c | 4 ++-- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/libntfs-3g/device.c b/libntfs-3g/device.c index afdfbcd2..e1170825 100644 --- a/libntfs-3g/device.c +++ b/libntfs-3g/device.c @@ -179,22 +179,18 @@ s64 ntfs_pread(struct ntfs_device *dev, const s64 pos, s64 count, void *b) struct ntfs_device_operations *dops; ntfs_log_trace("Entering for pos 0x%llx, count 0x%llx.\n", pos, count); + if (!b || count < 0 || pos < 0) { errno = EINVAL; return -1; } if (!count) return 0; + dops = dev->d_ops; - /* Locate to position. */ - if (dops->seek(dev, pos, SEEK_SET) == (off_t)-1) { - ntfs_log_perror("ntfs_pread: device seek to 0x%llx returned error", - pos); - return -1; - } - /* Read the data. */ + for (total = 0; count; count -= br, total += br) { - br = dops->read(dev, (char*)b + total, count); + br = dops->pread(dev, (char*)b + total, count, pos + total); /* If everything ok, continue. */ if (br > 0) continue; @@ -244,16 +240,13 @@ s64 ntfs_pwrite(struct ntfs_device *dev, const s64 pos, s64 count, errno = EROFS; goto out; } + dops = dev->d_ops; - /* Locate to position. */ - if (dops->seek(dev, pos, SEEK_SET) == (off_t)-1) { - ntfs_log_perror("ntfs_pwrite: seek to 0x%llx returned error", - pos); - goto out; - } + NDevSetDirty(dev); for (total = 0; count; count -= written, total += written) { - written = dops->write(dev, (const char*)b + total, count); + written = dops->pwrite(dev, (const char*)b + total, count, + pos + total); /* If everything ok, continue. */ if (written > 0) continue; diff --git a/libntfs-3g/unix_io.c b/libntfs-3g/unix_io.c index 5f2c825b..78a09207 100644 --- a/libntfs-3g/unix_io.c +++ b/libntfs-3g/unix_io.c @@ -239,7 +239,7 @@ static s64 ntfs_device_unix_io_write(struct ntfs_device *dev, const void *buf, static s64 ntfs_device_unix_io_pread(struct ntfs_device *dev, void *buf, s64 count, s64 offset) { - return ntfs_pread(dev, offset, count, buf); + return pread(DEV_FD(dev), buf, count, offset); } /** @@ -261,7 +261,7 @@ static s64 ntfs_device_unix_io_pwrite(struct ntfs_device *dev, const void *buf, return -1; } NDevSetDirty(dev); - return ntfs_pwrite(dev, offset, count, buf); + return pwrite(DEV_FD(dev), buf, count, offset); } /**