Changeset b0ac906b283b428ba1c7f35fe1e71a84b3d3d9c6 for libinstaller
- Timestamp:
- 09/07/11 07:19:05 (9 months ago)
- Children:
- 045bc5cd1118fee51b19d89dc316038c8a93e5bf
- Parents:
- 67954e370003d9bbfd8b58042669f2e9d532636f
- git-author:
- Paulo Alcantara <pcacjr@gmail.com> / 2011-07-05T21:32:51Z+0000
- git-committer:
- Paulo Alcantara <pcacjr@gmail.com> / 2011-09-07T07:19:05Z+0000
- Location:
- libinstaller
- Files:
-
- 1 added
- 8 modified
- 1 moved
-
fs.c (moved) (moved from libinstaller/fat.c) (6 diffs)
-
linuxioctl.h (modified) (2 diffs)
-
setadv.c (modified) (1 diff)
-
syslinux.h (modified) (1 diff)
-
syslxcom.c (modified) (3 diffs)
-
syslxcom.h (modified) (1 diff)
-
syslxfs.h (added)
-
syslxint.h (modified) (3 diffs)
-
syslxmod.c (modified) (1 diff)
-
syslxopt.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
libinstaller/fs.c
r0fb43d rb0ac90 1 1 /* ----------------------------------------------------------------------- * 2 2 * 3 * Copyright 1998-2008 H. Peter Anvin - All Rights Reserved 4 * Copyright 2009-2010 Intel Corporation; author H. Peter Anvin 3 * Copyright 1998-2011 H. Peter Anvin - All Rights Reserved 4 * Copyright 2009-2011 Intel Corporation; author H. Peter Anvin 5 * Copyright 2011 Paulo Alcantara <pcacjr@gmail.com> 5 6 * 6 7 * This program is free software; you can redistribute it and/or modify … … 13 14 14 15 /* 15 * f at.c - Initial sanity check for FAT-based installers16 * fs.c - Generic sanity check for FAT/NTFS-based installers 16 17 */ 17 18 … … 26 27 #include "syslinux.h" 27 28 #include "syslxint.h" 29 #include "syslxcom.h" 30 #include "syslxfs.h" 28 31 29 void syslinux_make_bootsect(void *bs )32 void syslinux_make_bootsect(void *bs, int fs_type) 30 33 { 31 struct boot_sector *bootsect = bs; 32 const struct boot_sector *sbs = 33 (const struct boot_sector *)boot_sector; 34 if (fs_type == VFAT) { 35 struct fat_boot_sector *bootsect = bs; 36 const struct fat_boot_sector *sbs = 37 (const struct fat_boot_sector *)boot_sector; 34 38 35 memcpy(&bootsect->bsHead, &sbs->bsHead, bsHeadLen); 36 memcpy(&bootsect->bsCode, &sbs->bsCode, bsCodeLen); 39 memcpy(&bootsect->FAT_bsHead, &sbs->FAT_bsHead, FAT_bsHeadLen); 40 memcpy(&bootsect->FAT_bsCode, &sbs->FAT_bsCode, FAT_bsCodeLen); 41 } else if (fs_type == NTFS) { 42 struct ntfs_boot_sector *bootsect = bs; 43 const struct ntfs_boot_sector *sbs = 44 (const struct ntfs_boot_sector *)boot_sector; 45 46 memcpy(&bootsect->NTFS_bsHead, &sbs->NTFS_bsHead, NTFS_bsHeadLen); 47 memcpy(&bootsect->NTFS_bsCode, &sbs->NTFS_bsCode, NTFS_bsCodeLen); 48 } 37 49 } 38 50 39 /* 40 * Check to see that what we got was indeed an MS-DOS boot sector/superblock; 41 * Return NULL if OK and otherwise an error message; 42 */ 43 const char *syslinux_check_bootsect(const void *bs) 51 static const char *check_fat_bootsect(const void *bs, int *fs_type) 44 52 { 45 53 int sectorsize; 54 const struct fat_boot_sector *sectbuf = bs; 46 55 long long sectors, fatsectors, dsectors; 47 56 long long clusters; 48 57 int rootdirents, clustersize; 49 const struct boot_sector *sectbuf = bs;50 51 /* Must be 0xF0 or 0xF8..0xFF */52 if (get_8(§buf->bsMedia) != 0xF0 && get_8(§buf->bsMedia) < 0xF8)53 return "invalid media signature (not a FAT filesystem?)";54 58 55 59 sectorsize = get_16(§buf->bsBytesPerSec); 56 if (sectorsize == SECTOR_SIZE)57 ; /* ok */58 else if (sectorsize >= 512 && sectorsize <= 4096 &&59 (sectorsize & (sectorsize - 1)) == 0)60 return "unsupported sectors size";61 else62 return "impossible sector size";63 60 64 61 clustersize = get_8(§buf->bsSecPerClust); 65 62 if (clustersize == 0 || (clustersize & (clustersize - 1))) 66 return "impossible cluster size ";63 return "impossible cluster size on an FAT volume"; 67 64 68 65 sectors = get_16(§buf->bsSectors); … … 80 77 81 78 if (dsectors < 0) 82 return "negative number of data sectors"; 83 84 if (fatsectors == 0) 85 return "zero FAT sectors"; 79 return "negative number of data sectors on an FAT volume"; 86 80 87 81 clusters = dsectors / clustersize; 88 82 83 fatsectors = get_16(§buf->bsFATsecs); 84 fatsectors = fatsectors ? fatsectors : get_32(§buf->bs32.FATSz32); 85 fatsectors *= get_8(§buf->bsFATs); 86 87 if (!fatsectors) 88 return "zero FAT sectors"; 89 89 90 if (clusters < 0xFFF5) { 90 91 /* FAT12 or FAT16 */ 91 92 92 if (!get_16(§buf->bsFATsecs)) 93 93 return "zero FAT sectors (FAT12/16)"; … … 101 101 return "less than 4084 clusters but claims FAT16"; 102 102 } else if (!memcmp(§buf->bs16.FileSysType, "FAT32 ", 8)) { 103 return "less than 65525 clusters but claims FAT32";103 return "less than 65525 clusters but claims FAT32"; 104 104 } else if (memcmp(§buf->bs16.FileSysType, "FAT ", 8)) { 105 static char fserr[] = 106 " filesystem type \"????????\" notsupported";105 static char fserr[] = "filesystem type \"????????\" not " 106 "supported"; 107 107 memcpy(fserr + 17, §buf->bs16.FileSysType, 8); 108 108 return fserr; … … 120 120 return "missing FAT32 signature"; 121 121 } else { 122 return "impossibly large number of clusters ";122 return "impossibly large number of clusters on an FAT volume"; 123 123 } 124 125 if (fs_type) 126 *fs_type = VFAT; 124 127 125 128 return NULL; 126 129 } 130 131 static const char *check_ntfs_bootsect(const void *bs, int *fs_type) 132 { 133 const struct ntfs_boot_sector *sectbuf = bs; 134 135 if (memcmp(§buf->bsOemName, "NTFS ", 8) && 136 memcmp(§buf->bsOemName, "MSWIN4.0", 8) && 137 memcmp(§buf->bsOemName, "MSWIN4.1", 8)) 138 return "unknown OEM name but claims NTFS"; 139 140 if (fs_type) 141 *fs_type = NTFS; 142 143 return NULL; 144 } 145 146 const char *syslinux_check_bootsect(const void *bs, int *fs_type) 147 { 148 uint8_t media_sig; 149 int sectorsize; 150 const struct fat_boot_sector *sectbuf = bs; 151 const char *retval; 152 153 media_sig = get_8(§buf->bsMedia); 154 /* Must be 0xF0 or 0xF8-0xFF for FAT/NTFS volumes */ 155 if (media_sig != 0xF0 && media_sig < 0xF8) 156 return "invalid media signature (not an FAT/NTFS volume?)"; 157 158 sectorsize = get_16(§buf->bsBytesPerSec); 159 if (sectorsize == SECTOR_SIZE) ; /* ok */ 160 else if (sectorsize >= 512 && sectorsize <= 4096 && 161 (sectorsize & (sectorsize - 1)) == 0) 162 return "unsupported sectors size"; 163 else 164 return "impossible sector size"; 165 166 if (ntfs_check_zero_fields((struct ntfs_boot_sector *)bs)) 167 retval = check_ntfs_bootsect(bs, fs_type); 168 else 169 retval = check_fat_bootsect(bs, fs_type); 170 171 return retval; 172 } -
libinstaller/linuxioctl.h
r92e6eda rb0ac90 16 16 17 17 #include <linux/fs.h> /* FIGETBSZ, FIBMAP, FS_IOC_FIEMAP */ 18 #include <linux/msdos_fs.h> /* FAT_IOCTL_SET_ATTRIBUTES */19 18 20 19 #undef SECTOR_SIZE /* Defined in msdos_fs.h for no good reason */ … … 26 25 #endif 27 26 28 #ifndef FAT_IOCTL_SET_ATTRIBUTES 29 # define FAT_IOCTL_SET_ATTRIBUTES _IOW('r', 0x11, __u32) 30 #endif 27 #define FAT_IOCTL_SET_ATTRIBUTES _IOW('r', 0x11, __u32) 31 28 32 29 #include <linux/fiemap.h> /* FIEMAP definitions */ -
libinstaller/setadv.c
rbdf966 rb0ac90 31 31 #include "syslxint.h" 32 32 #include "syslxcom.h" 33 #include "syslxfs.h" 33 34 34 35 unsigned char syslinux_adv[2 * ADV_SIZE]; -
libinstaller/syslinux.h
r2ef260 rb0ac90 41 41 42 42 /* This takes a boot sector and merges in the syslinux fields */ 43 void syslinux_make_bootsect(void * );43 void syslinux_make_bootsect(void *bs, int fs_type); 44 44 45 45 /* Check to see that what we got was indeed an MS-DOS boot sector/superblock */ 46 const char *syslinux_check_bootsect(const void *bs );46 const char *syslinux_check_bootsect(const void *bs, int *fs_type); 47 47 48 48 /* This patches the boot sector and ldlinux.sys based on a sector map */ -
libinstaller/syslxcom.c
r0ac822 rb0ac90 31 31 #include <sys/mount.h> 32 32 #include <sys/vfs.h> 33 33 34 #include "linuxioctl.h" 34 35 #include "syslxcom.h" 36 #include "syslxfs.h" 35 37 36 38 const char *program; … … 134 136 break; 135 137 } 138 case NTFS: 139 break; 136 140 default: 137 141 break; … … 164 168 break; 165 169 } 170 case NTFS: 171 break; 166 172 default: 167 173 break; -
libinstaller/syslxcom.h
r0ac822 rb0ac90 4 4 #include "syslinux.h" 5 5 6 /* Global fs_type for handling fat, ext2/3/4 and btrfs */7 enum filesystem {8 NONE,9 EXT2,10 BTRFS,11 VFAT,12 };13 14 extern int fs_type;15 6 extern const char *program; 16 7 ssize_t xpread(int fd, void *buf, size_t count, off_t offset); -
libinstaller/syslxint.h
r4d0869 rb0ac90 3 3 * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved 4 4 * Copyright 2009-2011 Intel Corporation; author: H. Peter Anvin 5 * Copyright 2011 Paulo Alcantara <pcacjr@gmail.com> 5 6 * 6 7 * This program is free software; you can redistribute it and/or modify … … 193 194 194 195 /* FAT bootsector format, also used by other disk-based derivatives */ 195 struct boot_sector {196 struct fat_boot_sector { 196 197 uint8_t bsJump[3]; 197 198 char bsOemName[8]; … … 242 243 } __attribute__ ((packed)); 243 244 244 #define bsHead bsJump 245 #define bsHeadLen offsetof(struct boot_sector, bsBytesPerSec) 246 #define bsCode bs32.Code /* The common safe choice */ 247 #define bsCodeLen (offsetof(struct boot_sector, bsSignature) - \ 248 offsetof(struct boot_sector, bsCode)) 249 250 static inline int fat_check_sb_fields(const struct boot_sector *sb) 245 /* NTFS bootsector format */ 246 struct ntfs_boot_sector { 247 uint8_t bsJump[3]; 248 char bsOemName[8]; 249 uint16_t bsBytesPerSec; 250 uint8_t bsSecPerClust; 251 uint16_t bsResSectors; 252 uint8_t bsZeroed_0[3]; 253 uint16_t bsZeroed_1; 254 uint8_t bsMedia; 255 uint16_t bsZeroed_2; 256 uint16_t bsUnused_0; 257 uint16_t bsUnused_1; 258 uint32_t bsUnused_2; 259 uint32_t bsZeroed_3; 260 uint32_t bsUnused_3; 261 uint64_t bsTotalSectors; 262 uint64_t bsMFTLogicalClustNr; 263 uint64_t bsMFTMirrLogicalClustNr; 264 uint8_t bsClustPerMFTrecord; 265 uint8_t bsUnused_4[3]; 266 uint8_t bsClustPerIdxBuf; 267 uint8_t bsUnused_5[3]; 268 uint64_t bsVolSerialNr; 269 uint32_t bsUnused_6; 270 271 uint8_t Code[420]; 272 273 uint32_t bsMagic; 274 uint16_t bsForwardPtr; 275 uint16_t bsSignature; 276 } __attribute__((packed)); 277 278 #define FAT_bsHead bsJump 279 #define FAT_bsHeadLen offsetof(struct fat_boot_sector, bsBytesPerSec) 280 #define FAT_bsCode bs32.Code /* The common safe choice */ 281 #define FAT_bsCodeLen (offsetof(struct fat_boot_sector, bsSignature) - \ 282 offsetof(struct fat_boot_sector, FAT_bsCode)) 283 284 #define NTFS_bsHead bsJump 285 #define NTFS_bsHeadLen offsetof(struct ntfs_boot_sector, bsOemName) 286 #define NTFS_bsCode Code 287 #define NTFS_bsCodeLen (offsetof(struct ntfs_boot_sector, bsSignature) - \ 288 offsetof(struct ntfs_boot_sector, NTFS_bsCode)) 289 290 /* Check if there are specific zero fields in an NTFS boot sector */ 291 static inline int ntfs_check_zero_fields(const struct ntfs_boot_sector *sb) 292 { 293 return !sb->bsResSectors && (!sb->bsZeroed_0[0] && !sb->bsZeroed_0[1] && 294 !sb->bsZeroed_0[2]) && !sb->bsZeroed_1 && !sb->bsZeroed_2 && 295 !sb->bsZeroed_3; 296 } 297 298 static inline int ntfs_check_sb_fields(const struct ntfs_boot_sector *sb) 299 { 300 return ntfs_check_zero_fields(sb) && 301 (!memcmp(sb->bsOemName, "NTFS ", 8) || 302 !memcmp(sb->bsOemName, "MSWIN4.0", 8) || 303 !memcmp(sb->bsOemName, "MSWIN4.1", 8)); 304 } 305 306 static inline int fat_check_sb_fields(const struct fat_boot_sector *sb) 251 307 { 252 308 return sb->bsResSectors && sb->bsFATs && -
libinstaller/syslxmod.c
r3c123f rb0ac90 110 110 uint32_t csum; 111 111 int i, dw, nptrs; 112 struct boot_sector *sbs = (structboot_sector *)boot_sector;112 struct fat_boot_sector *sbs = (struct fat_boot_sector *)boot_sector; 113 113 uint64_t *advptrs; 114 114 -
libinstaller/syslxopt.c
r6f438c rb0ac90 26 26 #include "../version.h" 27 27 #include "syslxcom.h" 28 #include "syslxfs.h" 28 29 #include "syslxopt.h" 29 30
