diff options
Diffstat (limited to 'blockdev')
| -rw-r--r-- | blockdev/blockdev.c | 3 | ||||
| -rw-r--r-- | blockdev/linux/file_dev.c | 5 | ||||
| -rw-r--r-- | blockdev/windows/file_windows.c | 12 |
3 files changed, 14 insertions, 6 deletions
diff --git a/blockdev/blockdev.c b/blockdev/blockdev.c index a44a2e1..15ce00f 100644 --- a/blockdev/blockdev.c +++ b/blockdev/blockdev.c @@ -32,6 +32,9 @@ #include <ext4_errno.h> +uint32_t ext4_blockdev_errno; + + /**********************BLOCKDEV INTERFACE**************************************/ static int blockdev_open(struct ext4_blockdev *bdev); static int blockdev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id, diff --git a/blockdev/linux/file_dev.c b/blockdev/linux/file_dev.c index 4e4cc67..77c6112 100644 --- a/blockdev/linux/file_dev.c +++ b/blockdev/linux/file_dev.c @@ -77,6 +77,7 @@ static int file_dev_open(struct ext4_blockdev *bdev) if (dev_file < 0) { printf("open of %s failed %d\n", fname, errno); + ext4_blockdev_errno = errno; return EIO; } @@ -119,12 +120,14 @@ static int file_dev_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id uint32_t blk_cnt) { if (lseek(dev_file, blk_id * bdev->bdif->ph_bsize, SEEK_SET) < 0) { + ext4_blockdev_errno = errno; printf("lseek failed %d\n", errno); return EIO; } if (!blk_cnt) return EOK; if (read(dev_file, buf, bdev->bdif->ph_bsize * blk_cnt) < 0) { + ext4_blockdev_errno = errno; printf("read failed %d\n", errno); return EIO; } @@ -150,12 +153,14 @@ static int file_dev_bwrite(struct ext4_blockdev *bdev, const void *buf, uint64_t blk_id, uint32_t blk_cnt) { if (lseek(dev_file, blk_id * bdev->bdif->ph_bsize, SEEK_SET) < 0) { + ext4_blockdev_errno = errno; printf("fseeko failed %d\n", errno); return EIO; } if (!blk_cnt) return EOK; if (write(dev_file, buf, bdev->bdif->ph_bsize * blk_cnt) < 0) { + ext4_blockdev_errno = errno; printf("write failed %d\n", errno); return EIO; } diff --git a/blockdev/windows/file_windows.c b/blockdev/windows/file_windows.c index 45588e3..75a372f 100644 --- a/blockdev/windows/file_windows.c +++ b/blockdev/windows/file_windows.c @@ -80,6 +80,7 @@ static int file_open(struct ext4_blockdev *bdev) FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, NULL); if (dev_file == INVALID_HANDLE_VALUE) { + ext4_blockdev_errno = GetLastError(); return EIO; } @@ -88,6 +89,7 @@ static int file_open(struct ext4_blockdev *bdev) &pdg, sizeof(pdg), &junk, (LPOVERLAPPED)NULL); if (bResult == FALSE) { + ext4_blockdev_errno = GetLastError(); CloseHandle(dev_file); return EIO; } @@ -116,19 +118,18 @@ static int file_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id, { long hipart = blk_id >> (32 - 9); long lopart = blk_id << 9; - long err; SetLastError(0); lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN); - if (lopart == -1 && NO_ERROR != (err = GetLastError())) { + if (lopart == -1 && NO_ERROR != (ext4_blockdev_errno = GetLastError())) { return EIO; } DWORD n; if (!ReadFile(dev_file, buf, blk_cnt * 512, &n, NULL)) { - err = GetLastError(); + ext4_blockdev_errno = GetLastError(); return EIO; } return EOK; @@ -140,19 +141,18 @@ static int file_bwrite(struct ext4_blockdev *bdev, const void *buf, { long hipart = blk_id >> (32 - 9); long lopart = blk_id << 9; - long err; SetLastError(0); lopart = SetFilePointer(dev_file, lopart, &hipart, FILE_BEGIN); - if (lopart == -1 && NO_ERROR != (err = GetLastError())) { + if (lopart == -1 && NO_ERROR != (ext4_blockdev_errno = GetLastError())) { return EIO; } DWORD n; if (!WriteFile(dev_file, buf, blk_cnt * 512, &n, NULL)) { - err = GetLastError(); + ext4_blockdev_errno = GetLastError(); return EIO; } return EOK; |
