Show
Ignore:
Timestamp:
09/07/11 07:19:05 (9 months ago)
Author:
Paulo Alcantara <pcacjr@…>
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
Message:

Add NTFS filesystem support to Linux and Windows installers

Signed-off-by: Paulo Alcantara <pcacjr@…>

Location:
libinstaller
Files:
1 added
8 modified
1 moved

Legend:

Unmodified
Added
Removed
  • libinstaller/fs.c

    r0fb43d rb0ac90  
    11/* ----------------------------------------------------------------------- * 
    22 * 
    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> 
    56 * 
    67 *   This program is free software; you can redistribute it and/or modify 
     
    1314 
    1415/* 
    15  * fat.c - Initial sanity check for FAT-based installers 
     16 * fs.c - Generic sanity check for FAT/NTFS-based installers 
    1617 */ 
    1718 
     
    2627#include "syslinux.h" 
    2728#include "syslxint.h" 
     29#include "syslxcom.h" 
     30#include "syslxfs.h" 
    2831 
    29 void syslinux_make_bootsect(void *bs) 
     32void syslinux_make_bootsect(void *bs, int fs_type) 
    3033{ 
    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; 
    3438 
    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    } 
    3749} 
    3850 
    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) 
     51static const char *check_fat_bootsect(const void *bs, int *fs_type) 
    4452{ 
    4553    int sectorsize; 
     54    const struct fat_boot_sector *sectbuf = bs; 
    4655    long long sectors, fatsectors, dsectors; 
    4756    long long clusters; 
    4857    int rootdirents, clustersize; 
    49     const struct boot_sector *sectbuf = bs; 
    50  
    51     /* Must be 0xF0 or 0xF8..0xFF */ 
    52     if (get_8(&sectbuf->bsMedia) != 0xF0 && get_8(&sectbuf->bsMedia) < 0xF8) 
    53         return "invalid media signature (not a FAT filesystem?)"; 
    5458 
    5559    sectorsize = get_16(&sectbuf->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     else 
    62         return "impossible sector size"; 
    6360 
    6461    clustersize = get_8(&sectbuf->bsSecPerClust); 
    6562    if (clustersize == 0 || (clustersize & (clustersize - 1))) 
    66         return "impossible cluster size"; 
     63        return "impossible cluster size on an FAT volume"; 
    6764 
    6865    sectors = get_16(&sectbuf->bsSectors); 
     
    8077 
    8178    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"; 
    8680 
    8781    clusters = dsectors / clustersize; 
    8882 
     83    fatsectors = get_16(&sectbuf->bsFATsecs); 
     84    fatsectors = fatsectors ? fatsectors : get_32(&sectbuf->bs32.FATSz32); 
     85    fatsectors *= get_8(&sectbuf->bsFATs); 
     86 
     87    if (!fatsectors) 
     88        return "zero FAT sectors"; 
     89 
    8990    if (clusters < 0xFFF5) { 
    9091        /* FAT12 or FAT16 */ 
    91  
    9292        if (!get_16(&sectbuf->bsFATsecs)) 
    9393            return "zero FAT sectors (FAT12/16)"; 
     
    101101                    return "less than 4084 clusters but claims FAT16"; 
    102102            } else if (!memcmp(&sectbuf->bs16.FileSysType, "FAT32   ", 8)) { 
    103                     return "less than 65525 clusters but claims FAT32"; 
     103                return "less than 65525 clusters but claims FAT32"; 
    104104            } else if (memcmp(&sectbuf->bs16.FileSysType, "FAT     ", 8)) { 
    105                 static char fserr[] = 
    106                     "filesystem type \"????????\" not supported"; 
     105                static char fserr[] = "filesystem type \"????????\" not " 
     106                    "supported"; 
    107107                memcpy(fserr + 17, &sectbuf->bs16.FileSysType, 8); 
    108108                return fserr; 
     
    120120            return "missing FAT32 signature"; 
    121121    } else { 
    122         return "impossibly large number of clusters"; 
     122        return "impossibly large number of clusters on an FAT volume"; 
    123123    } 
     124 
     125    if (fs_type) 
     126        *fs_type = VFAT; 
    124127 
    125128    return NULL; 
    126129} 
     130 
     131static const char *check_ntfs_bootsect(const void *bs, int *fs_type) 
     132{ 
     133    const struct ntfs_boot_sector *sectbuf = bs; 
     134 
     135    if (memcmp(&sectbuf->bsOemName, "NTFS    ", 8) && 
     136        memcmp(&sectbuf->bsOemName, "MSWIN4.0", 8) && 
     137        memcmp(&sectbuf->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 
     146const 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(&sectbuf->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(&sectbuf->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  
    1616 
    1717#include <linux/fs.h>           /* FIGETBSZ, FIBMAP, FS_IOC_FIEMAP */ 
    18 #include <linux/msdos_fs.h>     /* FAT_IOCTL_SET_ATTRIBUTES */ 
    1918 
    2019#undef SECTOR_SIZE              /* Defined in msdos_fs.h for no good reason */ 
     
    2625#endif 
    2726 
    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) 
    3128 
    3229#include <linux/fiemap.h>       /* FIEMAP definitions */ 
  • libinstaller/setadv.c

    rbdf966 rb0ac90  
    3131#include "syslxint.h" 
    3232#include "syslxcom.h" 
     33#include "syslxfs.h" 
    3334 
    3435unsigned char syslinux_adv[2 * ADV_SIZE]; 
  • libinstaller/syslinux.h

    r2ef260 rb0ac90  
    4141 
    4242/* This takes a boot sector and merges in the syslinux fields */ 
    43 void syslinux_make_bootsect(void *); 
     43void syslinux_make_bootsect(void *bs, int fs_type); 
    4444 
    4545/* Check to see that what we got was indeed an MS-DOS boot sector/superblock */ 
    46 const char *syslinux_check_bootsect(const void *bs); 
     46const char *syslinux_check_bootsect(const void *bs, int *fs_type); 
    4747 
    4848/* This patches the boot sector and ldlinux.sys based on a sector map */ 
  • libinstaller/syslxcom.c

    r0ac822 rb0ac90  
    3131#include <sys/mount.h> 
    3232#include <sys/vfs.h> 
     33 
    3334#include "linuxioctl.h" 
    3435#include "syslxcom.h" 
     36#include "syslxfs.h" 
    3537 
    3638const char *program; 
     
    134136            break; 
    135137        } 
     138    case NTFS: 
     139        break; 
    136140        default: 
    137141            break; 
     
    164168            break; 
    165169        } 
     170    case NTFS: 
     171        break; 
    166172        default: 
    167173            break; 
  • libinstaller/syslxcom.h

    r0ac822 rb0ac90  
    44#include "syslinux.h" 
    55 
    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; 
    156extern const char *program; 
    167ssize_t xpread(int fd, void *buf, size_t count, off_t offset); 
  • libinstaller/syslxint.h

    r4d0869 rb0ac90  
    33 *   Copyright 2007-2008 H. Peter Anvin - All Rights Reserved 
    44 *   Copyright 2009-2011 Intel Corporation; author: H. Peter Anvin 
     5 *   Copyright 2011 Paulo Alcantara <pcacjr@gmail.com> 
    56 * 
    67 *   This program is free software; you can redistribute it and/or modify 
     
    193194 
    194195/* FAT bootsector format, also used by other disk-based derivatives */ 
    195 struct boot_sector { 
     196struct fat_boot_sector { 
    196197    uint8_t bsJump[3]; 
    197198    char bsOemName[8]; 
     
    242243} __attribute__ ((packed)); 
    243244 
    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 */ 
     246struct 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 */ 
     291static 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 
     298static 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 
     306static inline int fat_check_sb_fields(const struct fat_boot_sector *sb) 
    251307{ 
    252308    return sb->bsResSectors && sb->bsFATs && 
  • libinstaller/syslxmod.c

    r3c123f rb0ac90  
    110110    uint32_t csum; 
    111111    int i, dw, nptrs; 
    112     struct boot_sector *sbs = (struct boot_sector *)boot_sector; 
     112    struct fat_boot_sector *sbs = (struct fat_boot_sector *)boot_sector; 
    113113    uint64_t *advptrs; 
    114114 
  • libinstaller/syslxopt.c

    r6f438c rb0ac90  
    2626#include "../version.h" 
    2727#include "syslxcom.h" 
     28#include "syslxfs.h" 
    2829#include "syslxopt.h" 
    2930