diff options
Diffstat (limited to 'lib/libufs')
-rw-r--r-- | lib/libufs/block.c | 27 | ||||
-rw-r--r-- | lib/libufs/sblock.c | 8 |
2 files changed, 22 insertions, 13 deletions
diff --git a/lib/libufs/block.c b/lib/libufs/block.c index efc39ef..5c019d4 100644 --- a/lib/libufs/block.c +++ b/lib/libufs/block.c @@ -59,16 +59,21 @@ bread(struct uufsd *disk, ufs2_daddr_t blockno, void *data, size_t size) buf = data; cnt = pread(disk->d_fd, data, size, (off_t)(blockno * disk->d_bsize)); - /* - * In case of failure, zero data, which must be fs_bsize. - */ - if (cnt != size) { - ERROR(disk, "short read from block device"); - for (cnt = 0; cnt < MIN(size, disk->d_fs.fs_bsize); cnt++) - buf[cnt] = 0; - return -1; + if (cnt == -1) { + ERROR(disk, "read error from block device"); + goto fail; + } + if (cnt == 0) { + ERROR(disk, "end of file from block device"); + goto fail; + } + if ((size_t)cnt != size) { + ERROR(disk, "short read or read error from block device"); + goto fail; } return cnt; +fail: memset(buf, 0, size); + return -1; } ssize_t @@ -86,7 +91,11 @@ bwrite(struct uufsd *disk, ufs2_daddr_t blockno, const void *data, size_t size) } cnt = pwrite(disk->d_fd, data, size, (off_t)(blockno * disk->d_bsize)); - if (cnt != size) { + if (cnt == -1) { + ERROR(disk, "read write to block device"); + return -1; + } + if ((size_t)cnt != size) { ERROR(disk, "short write to block device"); return -1; } diff --git a/lib/libufs/sblock.c b/lib/libufs/sblock.c index 455fee0..7f87f65 100644 --- a/lib/libufs/sblock.c +++ b/lib/libufs/sblock.c @@ -64,11 +64,11 @@ sbread(struct uufsd *disk) } if (fs->fs_magic == FS_UFS1_MAGIC) disk->d_ufs = 1; - if ((fs->fs_magic == FS_UFS2_MAGIC) && - (fs->fs_sblockloc == superblock)) + if (fs->fs_magic == FS_UFS2_MAGIC && + fs->fs_sblockloc == superblock) disk->d_ufs = 2; - if ((fs->fs_bsize <= MAXBSIZE) && - (fs->fs_bsize >= sizeof(*fs))) { + if (fs->fs_bsize <= MAXBSIZE && + (size_t)fs->fs_bsize >= sizeof(*fs)) { if (disk->d_ufs) break; } |