diff options
| author | Juli Mallett <jmallett@FreeBSD.org> | 2003-02-19 00:32:48 +0000 |
|---|---|---|
| committer | Juli Mallett <jmallett@FreeBSD.org> | 2003-02-19 00:32:48 +0000 |
| commit | a506dcda3de7e1d7ddb74ce0a5ce4584228e2118 (patch) | |
| tree | 3c8471670fcb6130212dbcd6edaef8bc8027b1d4 | |
| parent | bbf9145de38533391b76fd4d3fa3cb4c074ff288 (diff) | |
Notes
| -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 efc39ef86941..5c019d461768 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 455fee0bcb77..7f87f652ccac 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; } |
