}
#endif /* HAVE_PREAD */
- if (ext2fs_llseek(data->dev, location, SEEK_SET) < 0) {
- retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
- goto error_out;
- }
if ((channel->align == 0) ||
(IS_ALIGNED(buf, channel->align) &&
IS_ALIGNED(location, channel->align) &&
IS_ALIGNED(size, channel->align))) {
+ mutex_lock(data, BOUNCE_MTX);
+ if (ext2fs_llseek(data->dev, location, SEEK_SET) < 0) {
+ retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
+ goto error_unlock;
+ }
actual = read(data->dev, buf, size);
if (actual != size) {
short_read:
actual = 0;
} else
retval = EXT2_ET_SHORT_READ;
- goto error_out;
+ goto error_unlock;
}
- return 0;
+ goto success_unlock;
}
#ifdef ALIGN_DEBUG
aligned_blk = location / align_size;
offset = location % align_size;
+ mutex_lock(data, BOUNCE_MTX);
if (ext2fs_llseek(data->dev, aligned_blk * align_size, SEEK_SET) < 0) {
retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
- goto error_out;
+ goto error_unlock;
}
while (size > 0) {
- mutex_lock(data, BOUNCE_MTX);
actual = read(data->dev, data->bounce, align_size);
if (actual != align_size) {
mutex_unlock(data, BOUNCE_MTX);
size += really_read;
goto short_read;
}
- if ((actual + offset) > align_size)
- actual = align_size - offset;
- if (actual > size)
- actual = size;
+ actual = size;
+ if (actual > align_size)
+ actual = align_size;
+ actual -= offset;
memcpy(buf, data->bounce + offset, actual);
really_read += actual;
buf += actual;
offset = 0;
aligned_blk++;
- mutex_unlock(data, BOUNCE_MTX);
}
+success_unlock:
+ mutex_unlock(data, BOUNCE_MTX);
return 0;
+error_unlock:
+ mutex_unlock(data, BOUNCE_MTX);
error_out:
if (actual >= 0 && actual < size)
memset((char *) buf+actual, 0, size-actual);
}
#endif /* HAVE_PWRITE */
- if (ext2fs_llseek(data->dev, location, SEEK_SET) < 0) {
- retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
- goto error_out;
- }
-
if ((channel->align == 0) ||
(IS_ALIGNED(buf, channel->align) &&
IS_ALIGNED(location, channel->align) &&
IS_ALIGNED(size, channel->align))) {
+ mutex_lock(data, BOUNCE_MTX);
+ if (ext2fs_llseek(data->dev, location, SEEK_SET) < 0) {
+ retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
+ goto error_out;
+ }
actual = write(data->dev, buf, size);
+ mutex_unlock(data, BOUNCE_MTX);
if (actual < 0) {
retval = errno;
goto error_out;
if (ext2fs_llseek(data->dev, aligned_blk * align_size,
SEEK_SET) < 0) {
retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
- goto error_out;
+ goto error_unlock;
}
actual = read(data->dev, data->bounce,
align_size);
if (actual != align_size) {
if (actual < 0) {
- mutex_unlock(data, BOUNCE_MTX);
retval = errno;
- goto error_out;
+ goto error_unlock;
}
memset((char *) data->bounce + actual, 0,
align_size - actual);
}
}
actual = size;
- if ((actual + offset) > align_size)
- actual = align_size - offset;
- if (actual > size)
- actual = size;
+ if (actual > align_size)
+ actual = align_size;
+ actual -= offset;
memcpy(((char *)data->bounce) + offset, buf, actual);
if (ext2fs_llseek(data->dev, aligned_blk * align_size, SEEK_SET) < 0) {
retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
- goto error_out;
+ goto error_unlock;
}
actual_w = write(data->dev, data->bounce, align_size);
mutex_unlock(data, BOUNCE_MTX);
}
return 0;
+error_unlock:
+ mutex_unlock(data, BOUNCE_MTX);
error_out:
if (channel->write_error)
retval = (channel->write_error)(channel, block, count, buf,