Clean up error reporting in block.c, so that it gives honest error strings

for the sorts of errors we run into[1].  This also gives us room to put in a
vaguely appropriate casts to silence warnings since our compiler doesn't like
when we compare ssize_t to size_t[2].  Add a cast in sblock.c[3] to silence
a warning because of signed vs. size_t hell (again).  Clean up nearby
excessive parenthemutilation[4].

Reviewed by:	bde [2] [3]
Suggested by:	bde, many [1]
Submitted by:	bde [4]

An aside about [4], bde notes that we do not check for a negative value for
the fs bsize.  I'm nto going to do that in every situation we use it, one must
expect a reasonable program to pass down reasonable values.  Some foot shooting
protection I will tolerate, some I will not.  Also he suggests some possible
conditional improvements there, which I may take to heart.

PS: For me at least, this is now WARNS=5 clean...
This commit is contained in:
Juli Mallett 2003-02-19 00:32:48 +00:00
parent bbf9145de3
commit a506dcda3d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=111111
2 changed files with 22 additions and 13 deletions

View File

@ -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;
}

View File

@ -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;
}