#ident "$Id$"
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
if ( !ls ) {
libfat_flush(fs);
ls = malloc(sizeof(struct libfat_sector));
-
+
if ( !ls )
return NULL; /* Can't allocate memory */
}
- if ( fs->read(fs->readptr, ls->data, LIBFAT_SECTOR_SIZE, n)
+ if ( fs->read(fs->readptr, ls->data, LIBFAT_SECTOR_SIZE, n)
!= LIBFAT_SECTOR_SIZE ) {
free(ls);
return NULL; /* I/O error */
free(ls);
}
}
-
-
-
-
#ident "$Id$"
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 2001-2004 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
le32_t bsVolumeID; /* Volume serial number */
char bsVolumeLabel[11]; /* Volume name */
char bsFileSysType[8]; /* File system type */
-
+
le8_t bsCode[448]; /* Boot sector code */
} fat16;
-
+
/* FAT32 */
struct {
le32_t bpb_fatsz32; /* Sectors/FAT */
};
#endif /* FAT_H */
-
#ident "$Id$"
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
if ( !fsdata )
return -1;
nextcluster = read16((le16_t *)&fsdata[fatoffset & LIBFAT_SECTOR_MASK]);
-
+
if ( nextcluster >= 0x0FFF8 )
return 0;
break;
return -1;
nextcluster = read32((le32_t *)&fsdata[fatoffset & LIBFAT_SECTOR_MASK]);
nextcluster &= 0x0FFFFFFF;
-
+
if ( nextcluster >= 0x0FFFFFF8 )
return 0;
break;
-
+
default:
return -1; /* WTF? */
}
return libfat_clustertosector(fs, nextcluster);
}
-
-
-
#ident "$Id$"
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
const void *name, struct libfat_direntry *direntry);
#endif /* LIBFAT_H */
-
#ident "$Id$"
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
struct libfat_filesystem {
int (*read)(intptr_t, void *, size_t, libfat_sector_t);
intptr_t readptr;
-
+
enum fat_type fat_type;
unsigned int clustsize;
int clustshift;
#ident "$Id$"
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
fs = malloc(sizeof(struct libfat_filesystem));
if ( !fs )
goto barf;
-
+
fs->sectors = NULL;
fs->read = readfunc;
fs->readptr = readptr;
bs = libfat_get_sector(fs, 0);
- if ( !bs )
+ if ( !bs )
goto barf;
if ( read16(&bs->bsBytesPerSec) != LIBFAT_SECTOR_SIZE )
goto barf;
fs->clustsize = 1 << i; /* Treat 0 as 2^8 = 64K */
fs->clustshift = i;
-
+
sectors = read16(&bs->bsSectors);
if ( !sectors )
sectors = read32(&bs->bsHugeSectors);
fs->end = sectors;
-
+
fs->fat = read16(&bs->bsResSectors);
fatsize = read16(&bs->bsFATsecs);
if ( !fatsize )
fatsize = read32(&bs->u.fat32.bpb_fatsz32);
-
+
fs->rootdir = fs->fat + fatsize * read8(&bs->bsFATs);
-
+
rootdirsize = ((read16(&bs->bsRootDirEnts) << 5) + LIBFAT_SECTOR_MASK)
>> LIBFAT_SECTOR_SHIFT;
fs->data = fs->rootdir + rootdirsize;
minfatsize = fs->endcluster << 2;
} else
goto barf; /* Impossibly many clusters */
-
+
minfatsize = (minfatsize + LIBFAT_SECTOR_SIZE-1) >> LIBFAT_SECTOR_SHIFT;
if ( minfatsize > fatsize )
#ident "$Id$"
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
return -2; /* Not found */
else if ( s == (libfat_sector_t)-1 )
return -1; /* Error */
-
+
dep = libfat_get_sector(fs, s);
if ( !dep )
return -1; /* Read error */
else
return read16(&dep->clustlo) + (read16(&dep->clusthi) << 16);
}
-
+
if ( dep->name[0] == 0 )
return -2; /* Hit high water mark */
dep++;
- }
+ }
s = libfat_nextsector(fs, s);
}
#ident "$Id$"
/* ----------------------------------------------------------------------- *
- *
+ *
* Copyright 2001-2004 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
/*
* ulint.h
*
- * Basic operations on unaligned, littleendian integers
+ * Basic operations on unaligned, littleendian integers
*/
#ifndef ULINT_H
*((uint32_t *)_p) = _v;
}
-#else
+#else
/* Generic, mostly portable versions */