Index: libcio/filesys.c
===================================================================
--- libcio/filesys.c	(revision fa3880436faee3a802167a6643a177727fdf94ea)
+++ libcio/filesys.c	(revision 8973acd23a70305139d469bac63060280979efcb)
@@ -30,5 +30,5 @@
 struct	dirent	*_dptr;			/* internal directory pointer */
 
-uint16_t _thefat[MAXFAT * WDPSEC];	/* file allocation table */
+uint8_t _thefat[MAXFAT * BPSEC];	/* file allocation table */
 
 int16_t	_fatin;				/* FAT has been read */
@@ -47,5 +47,5 @@
 */
 
-uint16_t _cl2lsn(struct bpb *bpp, uint16_t clnum)
+int16_t _cl2lsn(struct bpb *bpp, int16_t clnum)
 {
 	return(bpp->datrec + (bpp->clsiz * (clnum - 2)) );
@@ -59,17 +59,18 @@
 */
 
-uint16_t _gtcl12(int8_t *fat, uint16_t cl)
-{
-	register uint16_t cla, clt;
+int16_t _gtcl12(uint8_t *fat, int16_t cl)
+{
+	int16_t cla;
+	uint16_t clt;
 
 	cla = cl + (cl >> 1);
-	clt = ((uint16_t)0xFF00 & (fat[cla+1] << 8))
-		| ((uint16_t)0x00FF & fat[cla]);
+	clt = (0xFF00u & ((uint16_t)fat[cla + 1] << 8))
+		| (0x00FFu & fat[cla]);
 
 	if (cl & 1)
 		clt >>= 4;
 
-	clt &= (uint16_t)0x0FFF;
-	return(clt);
+	clt &= 0x0FFFu;
+	return((int16_t)clt);
 }
 
@@ -81,10 +82,10 @@
 */
 
-uint16_t _getfat(uint16_t *bufad, struct bpb *bpp, uint16_t nfat)
-{
-	uint16_t fatsec;
+int32_t _getfat(uint8_t *bufad, struct bpb *bpp, int16_t nfat)
+{
+	int16_t fatsec;
 
 	fatsec = nfat ? bpp->fatrec : (bpp->fatrec - bpp->fsiz);
-	return(BIOS(B_RDWR, 0, (int8_t *)bufad, bpp->fsiz, fatsec, 0));
+	return(BIOS(B_RDWR, 0, bufad, bpp->fsiz, fatsec, 0));
 }
 
@@ -96,5 +97,5 @@
 */
 
-int16_t _rdfat(uint16_t *bufad, struct bpb *bpp)
+int16_t _rdfat(uint8_t *bufad, struct bpb *bpp)
 {
 	if (_getfat(bufad, bpp, 0)) {
@@ -116,7 +117,7 @@
 */
 
-int16_t _rdroot(uint16_t *buf, struct bpb *bpp)
-{
-	return(BIOS(B_RDWR, 0, (int8_t *)buf, bpp->rdlen,
+int32_t _rdroot(struct dirent *buf, struct bpb *bpp)
+{
+	return(BIOS(B_RDWR, 0, buf, bpp->rdlen,
 		(bpp->fatrec + bpp->fsiz), 0));
 }
@@ -131,7 +132,7 @@
 */
 
-int16_t _nsic(struct fcb *fcp, struct bpb *bpp, int8_t *fp)
-{
-	register uint16_t tfe;
+int16_t _nsic(struct fcb *fcp, struct bpb *bpp, uint8_t *fp)
+{
+	register int16_t tfe;
 
 	/* check the FCB flags */
@@ -220,9 +221,9 @@
 struct dirent *_dsrch(struct dirent *de)
 {
-	uint16_t i, dl;
+	int16_t i, dl;
 	register struct dirent *dp;
 
 	dp = _thedir;
-	dl = _thebpb->rdlen * (_thebpb->recsiz / DENTSIZE);
+	dl = _thebpb->rdlen * (_thebpb->recsiz / (int16_t)DENTSIZE);
 
 	for (i = 0; i < dl; i++) {		/* check each entry */
@@ -253,9 +254,9 @@
 struct dirent *_dsnew(void)
 {
-	uint16_t i, dl;
+	int16_t i, dl;
 	register struct dirent *dp;
 
 	dp = _thedir;
-	dl = _thebpb->rdlen * (_thebpb->recsiz / DENTSIZE);
+	dl = _thebpb->rdlen * (_thebpb->recsiz / (int16_t)DENTSIZE);
 
 	for (i = 0; i < dl; i++) {		/* check each entry */
@@ -304,6 +305,6 @@
 int16_t _seek(struct fcb *fcp)
 {
-	register uint16_t acls, rcls, nc;
-	uint16_t sic, spc;
+	register int16_t acls, rcls, nc;
+	int16_t sic, spc;
 
 	if (!(fcp->modefl & FC_OPN)) {		/* file must be open */
@@ -328,5 +329,5 @@
 	rcls = fcp->curlsn / spc;		/* calculate relative cluster */
 	sic = fcp->curlsn - (rcls * spc);	/* calculate sector in cluster */
-	acls = micons(fcp->de.bclust);		/* get first cluster */
+	acls = (int16_t)micon16(fcp->de.bclust);	/* get first cluster */
 	fcp->modefl &= ~FC_EOF;			/* turn off the EOF flag */
 
@@ -400,5 +401,5 @@
 int16_t _ftrnc(struct dirent *dp)
 {
-	register uint16_t acls, ncls;
+	register int16_t acls, ncls;
 
 #if	DEBUGIT
@@ -408,5 +409,5 @@
 #endif
 
-	acls = micons(dp->bclust);		/* get first cluster number */
+	acls = (int16_t)micon16(dp->bclust);	/* get first cluster number */
 
 	/* zap entries until EOF or bad cluster */
@@ -481,5 +482,5 @@
 #endif
 
-	if (nc = _newcls()) {			/* get a new cluster */
+	if ((nc = _newcls())) {			/* get a new cluster */
 
 #if	DEBUGIT
@@ -488,5 +489,5 @@
 
 		_ptcl12(_thefat, nc, FAT_EOF);	/* mark new cluster as EOF */
-		pc = micons(fcp->de.bclust);	/* get first cluster */
+		pc = (int16_t)micon16(fcp->de.bclust);	/* get first cluster */
 
 #if	DEBUGIT
@@ -689,5 +690,5 @@
 		/* create the file */
 
-		if(rc = _fmake(fcp)) {
+		if ((rc = _fmake(fcp))) {
 
 			_deadio(fcp, EIO);	/* couldn't create the file */
@@ -758,11 +759,11 @@
 	memcpy(&fcp->de, _dptr, DENTSIZE);
 	fcp->clsec = 0;
-	fcp->curcls = micons(fcp->de.bclust);
+	fcp->curcls = (int16_t)micon16(fcp->de.bclust);
 	fcp->offset = 0;
 	fcp->curlsn = 0L;
 	fcp->curdsn = fcp->de.bclust ? _cl2lsn(_thebpb, fcp->curcls) : 0;
-	fcp->curlen = miconl(fcp->de.flen);
-
-	fcp->asects = ((fcp->curlen / _thebpb->clsizb)
+	fcp->curlen = (int32_t)micon32(fcp->de.flen);
+
+	fcp->asects = ((int16_t)(fcp->curlen / _thebpb->clsizb)
 		+ ((fcp->curlen & (_thebpb->clsizb - 1)) ? 1 : 0))
 		* _thebpb->clsiz;
@@ -787,5 +788,5 @@
 */
 
-int16_t _inifcb(struct fcb *fcp, int8_t *name, int8_t *ext, int16_t mode)
+int16_t _inifcb(struct fcb *fcp, int8_t *name, int8_t *ext, uint16_t mode)
 {
 	int16_t	fl;
@@ -923,5 +924,5 @@
 		if (fcp->modefl & (FC_CR | FC_AP | FC_WR)) {	/* writing ? */
 
-			if (dp = _dsrch(&fcp->de)) {	/* locate the dirent */
+			if ((dp = _dsrch(&fcp->de))) {	/* locate the dirent */
 
 				/* update the directory entry if it changed */
@@ -1050,5 +1051,5 @@
 		return(FAILURE);
 
-	_dptr->fname[0] = 0xE5;		/* mark directory entry as free */
+	_dptr->fname[0] = (int8_t)0xE5;	/* mark directory entry as free */
 
 #if	DEBUGIT
