From: H. Peter Anvin Date: Fri, 29 May 2009 22:10:33 +0000 (-0700) Subject: Run Nindent on libfat/open.c X-Git-Tag: syslinux-3.83-pre2~80 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fe91ddaa3ab16f2fe692b76928964b2a3c5a7d85;p=profile%2Fivi%2Fsyslinux.git Run Nindent on libfat/open.c Automatically reformat libfat/open.c using Nindent. Do this for all files except HDT, gPXE and externally maintained libraries (zlib, tinyjpeg, libpng). Signed-off-by: H. Peter Anvin --- diff --git a/libfat/open.c b/libfat/open.c index 2602b1a..19a34ad 100644 --- a/libfat/open.c +++ b/libfat/open.c @@ -21,97 +21,97 @@ #include "libfatint.h" #include "ulint.h" -struct libfat_filesystem * -libfat_open(int (*readfunc)(intptr_t, void *, size_t, libfat_sector_t), - intptr_t readptr) +struct libfat_filesystem + *libfat_open(int (*readfunc) (intptr_t, void *, size_t, libfat_sector_t), + intptr_t readptr) { - struct libfat_filesystem *fs = NULL; - struct fat_bootsect *bs; - int i; - uint32_t sectors, fatsize, minfatsize, rootdirsize; - uint32_t nclusters; - - 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 ) - goto barf; - - if ( read16(&bs->bsBytesPerSec) != LIBFAT_SECTOR_SIZE ) - goto barf; - - for ( i = 0 ; i <= 8 ; i++ ) { - if ( (uint8_t)(1 << i) == read8(&bs->bsSecPerClust) ) - break; - } - if ( i > 8 ) - 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; - - /* Sanity checking */ - if ( fs->data >= fs->end ) - goto barf; - - /* Figure out how many clusters */ - nclusters = (fs->end - fs->data) >> fs->clustshift; - fs->endcluster = nclusters + 2; - - if ( nclusters <= 0xff4 ) { - fs->fat_type = FAT12; - minfatsize = fs->endcluster + (fs->endcluster >> 1); - } else if ( nclusters <= 0xfff4 ) { - fs->fat_type = FAT16; - minfatsize = fs->endcluster << 1; - } else if ( nclusters <= 0xffffff4 ) { - fs->fat_type = FAT28; - minfatsize = fs->endcluster << 2; - } else - goto barf; /* Impossibly many clusters */ - - minfatsize = (minfatsize + LIBFAT_SECTOR_SIZE-1) >> LIBFAT_SECTOR_SHIFT; - - if ( minfatsize > fatsize ) - goto barf; /* The FATs don't fit */ - - if ( fs->fat_type == FAT28 ) - fs->rootcluster = read32(&bs->u.fat32.bpb_rootclus); - else - fs->rootcluster = 0; - - return fs; /* All good */ - - barf: - if ( fs ) - free(fs); - return NULL; + struct libfat_filesystem *fs = NULL; + struct fat_bootsect *bs; + int i; + uint32_t sectors, fatsize, minfatsize, rootdirsize; + uint32_t nclusters; + + 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) + goto barf; + + if (read16(&bs->bsBytesPerSec) != LIBFAT_SECTOR_SIZE) + goto barf; + + for (i = 0; i <= 8; i++) { + if ((uint8_t) (1 << i) == read8(&bs->bsSecPerClust)) + break; + } + if (i > 8) + 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; + + /* Sanity checking */ + if (fs->data >= fs->end) + goto barf; + + /* Figure out how many clusters */ + nclusters = (fs->end - fs->data) >> fs->clustshift; + fs->endcluster = nclusters + 2; + + if (nclusters <= 0xff4) { + fs->fat_type = FAT12; + minfatsize = fs->endcluster + (fs->endcluster >> 1); + } else if (nclusters <= 0xfff4) { + fs->fat_type = FAT16; + minfatsize = fs->endcluster << 1; + } else if (nclusters <= 0xffffff4) { + fs->fat_type = FAT28; + minfatsize = fs->endcluster << 2; + } else + goto barf; /* Impossibly many clusters */ + + minfatsize = (minfatsize + LIBFAT_SECTOR_SIZE - 1) >> LIBFAT_SECTOR_SHIFT; + + if (minfatsize > fatsize) + goto barf; /* The FATs don't fit */ + + if (fs->fat_type == FAT28) + fs->rootcluster = read32(&bs->u.fat32.bpb_rootclus); + else + fs->rootcluster = 0; + + return fs; /* All good */ + +barf: + if (fs) + free(fs); + return NULL; } void libfat_close(struct libfat_filesystem *fs) { - libfat_flush(fs); - free(fs); + libfat_flush(fs); + free(fs); }