fix sign-compare issues

This commit is contained in:
lukem 2009-04-11 06:59:18 +00:00
parent cefb0777de
commit a2b5923e3e
6 changed files with 41 additions and 40 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: boot.c,v 1.14 2008/06/13 20:46:09 martin Exp $ */
/* $NetBSD: boot.c,v 1.15 2009/04/11 07:14:50 lukem Exp $ */
/*
* Copyright (C) 1995, 1997 Wolfgang Solfrank
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: boot.c,v 1.14 2008/06/13 20:46:09 martin Exp $");
__RCSID("$NetBSD: boot.c,v 1.15 2009/04/11 07:14:50 lukem Exp $");
#endif /* not lint */
#include <stdlib.h>
@ -48,7 +48,7 @@ readboot(int dosfs, struct bootblock *boot)
int ret = FSOK;
int i;
if (read(dosfs, block, sizeof block) < sizeof block) {
if ((size_t)read(dosfs, block, sizeof block) != sizeof block) {
perr("could not read boot block");
return FSFATAL;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: check.c,v 1.17 2008/06/13 20:46:09 martin Exp $ */
/* $NetBSD: check.c,v 1.18 2009/04/11 07:14:50 lukem Exp $ */
/*
* Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: check.c,v 1.17 2008/06/13 20:46:09 martin Exp $");
__RCSID("$NetBSD: check.c,v 1.18 2009/04/11 07:14:50 lukem Exp $");
#endif /* not lint */
#include <stdlib.h>
@ -47,7 +47,8 @@ checkfilesys(const char *filename)
int dosfs;
struct bootblock boot;
struct fatEntry *fat = NULL;
int i, finish_dosdirsection=0;
int finish_dosdirsection=0;
u_int i;
int mod = 0;
int ret = FSCK_EXIT_CHECK_FAILED;

View File

@ -1,4 +1,4 @@
/* $NetBSD: dir.c,v 1.22 2008/06/13 20:46:09 martin Exp $ */
/* $NetBSD: dir.c,v 1.23 2009/04/11 07:14:50 lukem Exp $ */
/*
* Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: dir.c,v 1.22 2008/06/13 20:46:09 martin Exp $");
__RCSID("$NetBSD: dir.c,v 1.23 2009/04/11 07:14:50 lukem Exp $");
#endif /* not lint */
#include <stdio.h>
@ -393,7 +393,7 @@ checksize(struct bootblock *boot, struct fatEntry *fat, u_char *p,
/*
* Check size on ordinary files
*/
int32_t physicalSize;
u_int32_t physicalSize;
if (dir->head == CLUST_FREE)
physicalSize = 0;
@ -963,7 +963,7 @@ reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head)
lfoff = lfcl * boot->ClusterSize
+ boot->ClusterOffset * boot->BytesPerSec;
if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
|| read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
|| (size_t)read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
perr("could not read LOST.DIR");
return FSFATAL;
}
@ -993,7 +993,7 @@ reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head)
p[31] = (u_char)(d.size >> 24);
fat[head].flags |= FAT_USED;
if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
|| write(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
|| (size_t)write(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) {
perr("could not write LOST.DIR");
return FSFATAL;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ext.h,v 1.12 2008/06/13 20:46:09 martin Exp $ */
/* $NetBSD: ext.h,v 1.13 2009/04/11 07:14:50 lukem Exp $ */
/*
* Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
@ -83,13 +83,13 @@ int writefsinfo(int, struct bootblock *);
* Read one of the FAT copies and return a pointer to the new
* allocated array holding our description of it.
*/
int readfat(int, struct bootblock *, int, struct fatEntry **);
int readfat(int, struct bootblock *, u_int, struct fatEntry **);
/*
* Check two FAT copies for consistency and merge changes into the
* first if necessary.
*/
int comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, int);
int comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, u_int);
/*
* Check a FAT

View File

@ -1,4 +1,4 @@
/* $NetBSD: fat.c,v 1.21 2008/07/24 14:23:16 matthias Exp $ */
/* $NetBSD: fat.c,v 1.22 2009/04/11 07:14:50 lukem Exp $ */
/*
* Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: fat.c,v 1.21 2008/07/24 14:23:16 matthias Exp $");
__RCSID("$NetBSD: fat.c,v 1.22 2009/04/11 07:14:50 lukem Exp $");
#endif /* not lint */
#include <stdlib.h>
@ -40,16 +40,16 @@ __RCSID("$NetBSD: fat.c,v 1.21 2008/07/24 14:23:16 matthias Exp $");
#include "ext.h"
#include "fsutil.h"
static int checkclnum(struct bootblock *, int, cl_t, cl_t *);
static int clustdiffer(cl_t, cl_t *, cl_t *, int);
static int checkclnum(struct bootblock *, u_int, cl_t, cl_t *);
static int clustdiffer(cl_t, cl_t *, cl_t *, u_int);
static int tryclear(struct bootblock *, struct fatEntry *, cl_t, cl_t *);
static int _readfat(int, struct bootblock *, int, u_char **);
static int _readfat(int, struct bootblock *, u_int, u_char **);
/*
* Check a cluster number for valid value
*/
static int
checkclnum(struct bootblock *boot, int fat, cl_t cl, cl_t *next)
checkclnum(struct bootblock *boot, u_int fat, cl_t cl, cl_t *next)
{
if (*next >= (CLUST_RSRVD&boot->ClustMask))
*next |= ~boot->ClustMask;
@ -63,7 +63,7 @@ checkclnum(struct bootblock *boot, int fat, cl_t cl, cl_t *next)
}
if (*next < CLUST_FIRST
|| (*next >= boot->NumClusters && *next < CLUST_EOFS)) {
pwarn("Cluster %u in FAT %d continues with %s cluster number %u\n",
pwarn("Cluster %u in FAT %u continues with %s cluster number %u\n",
cl, fat,
*next < CLUST_RSRVD ? "out of range" : "reserved",
*next&boot->ClustMask);
@ -80,7 +80,7 @@ checkclnum(struct bootblock *boot, int fat, cl_t cl, cl_t *next)
* Read a FAT from disk. Returns 1 if successful, 0 otherwise.
*/
static int
_readfat(int fs, struct bootblock *boot, int no, u_char **buffer)
_readfat(int fs, struct bootblock *boot, u_int no, u_char **buffer)
{
off_t off;
size_t len;
@ -99,7 +99,7 @@ _readfat(int fs, struct bootblock *boot, int no, u_char **buffer)
goto err;
}
if (read(fs, *buffer, boot->FATsecs * boot->BytesPerSec)
if ((size_t)read(fs, *buffer, boot->FATsecs * boot->BytesPerSec)
!= boot->FATsecs * boot->BytesPerSec) {
perr("Unable to read FAT");
goto err;
@ -116,7 +116,7 @@ _readfat(int fs, struct bootblock *boot, int no, u_char **buffer)
* Read a FAT and decode it into internal format
*/
int
readfat(int fs, struct bootblock *boot, int no, struct fatEntry **fp)
readfat(int fs, struct bootblock *boot, u_int no, struct fatEntry **fp)
{
struct fatEntry *fat;
u_char *buffer, *p;
@ -252,7 +252,7 @@ rsrvdcltype(cl_t cl)
}
static int
clustdiffer(cl_t cl, cl_t *cp1, cl_t *cp2, int fatnum)
clustdiffer(cl_t cl, cl_t *cp1, cl_t *cp2, u_int fatnum)
{
if (*cp1 == CLUST_FREE || *cp1 >= CLUST_RSRVD) {
if (*cp2 == CLUST_FREE || *cp2 >= CLUST_RSRVD) {
@ -267,21 +267,21 @@ clustdiffer(cl_t cl, cl_t *cp1, cl_t *cp2, int fatnum)
}
return FSFATAL;
}
pwarn("Cluster %u is marked %s in FAT 0, %s in FAT %d\n",
pwarn("Cluster %u is marked %s in FAT 0, %s in FAT %u\n",
cl, rsrvdcltype(*cp1), rsrvdcltype(*cp2), fatnum);
if (ask(0, "use FAT 0's entry")) {
*cp2 = *cp1;
return FSFATMOD;
}
if (ask(0, "use FAT %d's entry", fatnum)) {
if (ask(0, "use FAT %u's entry", fatnum)) {
*cp1 = *cp2;
return FSFATMOD;
}
return FSFATAL;
}
pwarn("Cluster %u is marked %s in FAT 0, but continues with cluster %u in FAT %d\n",
pwarn("Cluster %u is marked %s in FAT 0, but continues with cluster %u in FAT %u\n",
cl, rsrvdcltype(*cp1), *cp2, fatnum);
if (ask(0, "Use continuation from FAT %d", fatnum)) {
if (ask(0, "Use continuation from FAT %u", fatnum)) {
*cp1 = *cp2;
return FSFATMOD;
}
@ -292,25 +292,25 @@ clustdiffer(cl_t cl, cl_t *cp1, cl_t *cp2, int fatnum)
return FSFATAL;
}
if (*cp2 == CLUST_FREE || *cp2 >= CLUST_RSRVD) {
pwarn("Cluster %u continues with cluster %u in FAT 0, but is marked %s in FAT %d\n",
pwarn("Cluster %u continues with cluster %u in FAT 0, but is marked %s in FAT %u\n",
cl, *cp1, rsrvdcltype(*cp2), fatnum);
if (ask(0, "Use continuation from FAT 0")) {
*cp2 = *cp1;
return FSFATMOD;
}
if (ask(0, "Use mark from FAT %d", fatnum)) {
if (ask(0, "Use mark from FAT %u", fatnum)) {
*cp1 = *cp2;
return FSFATMOD;
}
return FSERROR;
}
pwarn("Cluster %u continues with cluster %u in FAT 0, but with cluster %u in FAT %d\n",
pwarn("Cluster %u continues with cluster %u in FAT 0, but with cluster %u in FAT %u\n",
cl, *cp1, *cp2, fatnum);
if (ask(0, "Use continuation from FAT 0")) {
*cp2 = *cp1;
return FSFATMOD;
}
if (ask(0, "Use continuation from FAT %d", fatnum)) {
if (ask(0, "Use continuation from FAT %u", fatnum)) {
*cp1 = *cp2;
return FSFATMOD;
}
@ -323,7 +323,7 @@ clustdiffer(cl_t cl, cl_t *cp1, cl_t *cp2, int fatnum)
*/
int
comparefat(struct bootblock *boot, struct fatEntry *first,
struct fatEntry *second, int fatnum)
struct fatEntry *second, u_int fatnum)
{
cl_t cl;
int ret = FSOK;
@ -463,7 +463,7 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat)
{
u_char *buffer, *p;
cl_t cl;
int i;
u_int i;
size_t fatsz;
off_t off;
int ret = FSOK;
@ -554,7 +554,7 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat)
off = boot->ResSectors + i * boot->FATsecs;
off *= boot->BytesPerSec;
if (lseek(fs, off, SEEK_SET) != off
|| write(fs, buffer, fatsz) != fatsz) {
|| (size_t)write(fs, buffer, fatsz) != fatsz) {
perr("Unable to write FAT");
ret = FSFATAL; /* Return immediately? XXX */
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: newfs_msdos.c,v 1.33 2009/03/28 21:34:33 he Exp $ */
/* $NetBSD: newfs_msdos.c,v 1.34 2009/04/11 06:59:18 lukem Exp $ */
/*
* Copyright (c) 1998 Robert Nordier
@ -33,7 +33,7 @@
static const char rcsid[] =
"$FreeBSD: src/sbin/newfs_msdos/newfs_msdos.c,v 1.15 2000/10/10 01:49:37 wollman Exp $";
#else
__RCSID("$NetBSD: newfs_msdos.c,v 1.33 2009/03/28 21:34:33 he Exp $");
__RCSID("$NetBSD: newfs_msdos.c,v 1.34 2009/04/11 06:59:18 lukem Exp $");
#endif
#endif /* not lint */
@ -655,7 +655,7 @@ main(int argc, char *argv[])
if (opt_B && x < bss) {
if ((n = read(fd1, img, bpb.bps)) == -1)
err(1, "%s", bname);
if (n != bpb.bps)
if ((size_t)n != bpb.bps)
errx(1, "%s: can't read sector %u", bname, x);
} else
memset(img, 0, bpb.bps);
@ -743,7 +743,7 @@ main(int argc, char *argv[])
}
if ((n = write(fd, img, bpb.bps)) == -1)
err(1, "%s", fname);
if (n != bpb.bps)
if ((size_t)n != bpb.bps)
errx(1, "%s: can't write sector %u", fname, lsn);
}
}