summaryrefslogtreecommitdiff
path: root/libfat
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-05-29 15:10:33 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-05-29 15:10:33 -0700
commit6b38abd5bc448d41331eec550314e57c6ea6e92d (patch)
tree2ea8711f97d321aa3a21042af3fa90a0cc15b7b2 /libfat
parent2953cf3a4d44c90885eb7abf1ed2acc6354f6ad7 (diff)
downloadsyslinux-6b38abd5bc448d41331eec550314e57c6ea6e92d.tar.gz
Run Nindent on libfat/fatchain.c
Automatically reformat libfat/fatchain.c using Nindent. Do this for all files except HDT, gPXE and externally maintained libraries (zlib, tinyjpeg, libpng). Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'libfat')
-rw-r--r--libfat/fatchain.c190
1 files changed, 96 insertions, 94 deletions
diff --git a/libfat/fatchain.c b/libfat/fatchain.c
index e00f46ac..9853a726 100644
--- a/libfat/fatchain.c
+++ b/libfat/fatchain.c
@@ -26,15 +26,15 @@
libfat_sector_t libfat_clustertosector(const struct libfat_filesystem *fs,
int32_t cluster)
{
- if ( cluster == 0 )
- cluster = fs->rootcluster;
-
- if ( cluster == 0 )
- return fs->rootdir;
- else if ( cluster < 2 || cluster >= fs->endcluster )
- return -1;
- else
- return fs->data + ((libfat_sector_t)(cluster-2) << fs->clustshift);
+ if (cluster == 0)
+ cluster = fs->rootcluster;
+
+ if (cluster == 0)
+ return fs->rootdir;
+ else if (cluster < 2 || cluster >= fs->endcluster)
+ return -1;
+ else
+ return fs->data + ((libfat_sector_t) (cluster - 2) << fs->clustshift);
}
/*
@@ -42,91 +42,93 @@ libfat_sector_t libfat_clustertosector(const struct libfat_filesystem *fs,
* Returns 0 on end of file and -1 on error.
*/
-libfat_sector_t libfat_nextsector(struct libfat_filesystem *fs,
+libfat_sector_t libfat_nextsector(struct libfat_filesystem * fs,
libfat_sector_t s)
{
- int32_t cluster, nextcluster;
- uint32_t fatoffset;
- libfat_sector_t fatsect;
- uint8_t *fsdata;
- uint32_t clustmask = fs->clustsize - 1;
- libfat_sector_t rs;
-
- if ( s < fs->data ) {
- if ( s < fs->rootdir )
- return -1;
-
- /* Root directory */
- s++;
- return ( s < fs->data ) ? s : 0;
- }
-
- rs = s - fs->data;
-
- if ( ~rs & clustmask )
- return s+1; /* Next sector in cluster */
-
- cluster = 2 + (rs >> fs->clustshift);
-
- if ( cluster >= fs->endcluster )
- return -1;
-
- switch ( fs->fat_type ) {
- case FAT12:
- /* Get first byte */
- fatoffset = cluster + (cluster >> 1);
- fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
- fsdata = libfat_get_sector(fs, fatsect);
- if ( !fsdata )
- return -1;
- nextcluster = fsdata[fatoffset & LIBFAT_SECTOR_MASK];
-
- /* Get second byte */
- fatoffset++;
- fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
- fsdata = libfat_get_sector(fs, fatsect);
- if ( !fsdata )
- return -1;
- nextcluster |= fsdata[fatoffset & LIBFAT_SECTOR_MASK] << 8;
-
- /* Extract the FAT entry */
- if ( cluster & 1 )
- nextcluster >>= 4;
- else
- nextcluster &= 0x0FFF;
-
- if ( nextcluster >= 0x0FF8 )
- return 0;
- break;
-
- case FAT16:
- fatoffset = cluster << 1;
- fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
- fsdata = libfat_get_sector(fs, fatsect);
- if ( !fsdata )
- return -1;
- nextcluster = read16((le16_t *)&fsdata[fatoffset & LIBFAT_SECTOR_MASK]);
-
- if ( nextcluster >= 0x0FFF8 )
- return 0;
- break;
-
- case FAT28:
- fatoffset = cluster << 2;
- fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
- fsdata = libfat_get_sector(fs, fatsect);
- if ( !fsdata )
- 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);
+ int32_t cluster, nextcluster;
+ uint32_t fatoffset;
+ libfat_sector_t fatsect;
+ uint8_t *fsdata;
+ uint32_t clustmask = fs->clustsize - 1;
+ libfat_sector_t rs;
+
+ if (s < fs->data) {
+ if (s < fs->rootdir)
+ return -1;
+
+ /* Root directory */
+ s++;
+ return (s < fs->data) ? s : 0;
+ }
+
+ rs = s - fs->data;
+
+ if (~rs & clustmask)
+ return s + 1; /* Next sector in cluster */
+
+ cluster = 2 + (rs >> fs->clustshift);
+
+ if (cluster >= fs->endcluster)
+ return -1;
+
+ switch (fs->fat_type) {
+ case FAT12:
+ /* Get first byte */
+ fatoffset = cluster + (cluster >> 1);
+ fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
+ fsdata = libfat_get_sector(fs, fatsect);
+ if (!fsdata)
+ return -1;
+ nextcluster = fsdata[fatoffset & LIBFAT_SECTOR_MASK];
+
+ /* Get second byte */
+ fatoffset++;
+ fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
+ fsdata = libfat_get_sector(fs, fatsect);
+ if (!fsdata)
+ return -1;
+ nextcluster |= fsdata[fatoffset & LIBFAT_SECTOR_MASK] << 8;
+
+ /* Extract the FAT entry */
+ if (cluster & 1)
+ nextcluster >>= 4;
+ else
+ nextcluster &= 0x0FFF;
+
+ if (nextcluster >= 0x0FF8)
+ return 0;
+ break;
+
+ case FAT16:
+ fatoffset = cluster << 1;
+ fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
+ fsdata = libfat_get_sector(fs, fatsect);
+ if (!fsdata)
+ return -1;
+ nextcluster =
+ read16((le16_t *) & fsdata[fatoffset & LIBFAT_SECTOR_MASK]);
+
+ if (nextcluster >= 0x0FFF8)
+ return 0;
+ break;
+
+ case FAT28:
+ fatoffset = cluster << 2;
+ fatsect = fs->fat + (fatoffset >> LIBFAT_SECTOR_SHIFT);
+ fsdata = libfat_get_sector(fs, fatsect);
+ if (!fsdata)
+ 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);
}