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:
extlinux
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • extlinux/Makefile

    r261317 rb0ac90  
    1212 
    1313## 
    14 ## Linux vfat, ext2/ext3/ext4 and btrfs installer 
     14## Linux vfat, ntfs, ext2/ext3/ext4 and btrfs installer 
    1515## 
    1616 
  • extlinux/main.c

    rc210e5 rb0ac90  
    1515 * extlinux.c 
    1616 * 
    17  * Install the syslinux boot block on an fat, ext2/3/4 and btrfs filesystem 
     17 * Install the syslinux boot block on an fat, ntfs, ext2/3/4 and btrfs filesystem 
    1818 */ 
    1919 
     
    4646#include "btrfs.h" 
    4747#include "fat.h" 
     48#include "ntfs.h" 
    4849#include "../version.h" 
    4950#include "syslxint.h" 
    5051#include "syslxcom.h" /* common functions shared with extlinux and syslinux */ 
     52#include "syslxfs.h" 
    5153#include "setadv.h" 
    5254#include "syslxopt.h" /* unified options */ 
     
    215217    uint64_t totalbytes, totalsectors; 
    216218    int nsect; 
    217     struct boot_sector *sbs; 
     219    struct fat_boot_sector *sbs; 
    218220    char *dirpath, *subpath, *xdirpath; 
    219221    int rv; 
     
    272274    dprintf("heads = %u, sect = %u\n", geo.heads, geo.sectors); 
    273275 
    274     sbs = (struct boot_sector *)syslinux_bootsect; 
     276    sbs = (struct fat_boot_sector *)syslinux_bootsect; 
    275277 
    276278    totalsectors = totalbytes >> SECTOR_SHIFT; 
     
    293295    nsect += 2;                 /* Two sectors for the ADV */ 
    294296    sectp = alloca(sizeof(sector_t) * nsect); 
    295     if (fs_type == EXT2 || fs_type == VFAT) { 
     297    if (fs_type == EXT2 || fs_type == VFAT || fs_type == NTFS) { 
    296298        if (sectmap(fd, sectp, nsect)) { 
    297299                perror("bmap"); 
     
    324326    struct ext2_super_block sb; 
    325327    struct btrfs_super_block sb2; 
    326     struct boot_sector sb3; 
     328    struct fat_boot_sector sb3; 
     329    struct ntfs_boot_sector sb4; 
    327330    bool ok = false; 
    328331 
     
    349352        if (fat_check_sb_fields(&sb3)) 
    350353                ok = true; 
     354    } else if (fs_type == NTFS) { 
     355        if (xpread(fd, &sb4, sizeof(sb4), 0) != sizeof(sb4)) { 
     356            perror("reading ntfs superblock"); 
     357            return 1; 
     358        } 
     359 
     360        if (ntfs_check_sb_fields(&sb4)) 
     361             ok = true; 
    351362    } 
    352363    if (!ok) { 
    353         fprintf(stderr, "no fat, ext2/3/4 or btrfs superblock found on %s\n", 
     364        fprintf(stderr, "no fat, ntfs, ext2/3/4 or btrfs superblock found on %s\n", 
    354365                        device); 
    355366        return 1; 
    356367    } 
    357368    if (fs_type == VFAT) { 
    358         struct boot_sector *sbs = (struct boot_sector *)syslinux_bootsect; 
    359         if (xpwrite(fd, &sbs->bsHead, bsHeadLen, 0) != bsHeadLen || 
    360             xpwrite(fd, &sbs->bsCode, bsCodeLen, 
    361                     offsetof(struct boot_sector, bsCode)) != bsCodeLen) { 
     369        struct fat_boot_sector *sbs = (struct fat_boot_sector *)syslinux_bootsect; 
     370        if (xpwrite(fd, &sbs->FAT_bsHead, FAT_bsHeadLen, 0) != FAT_bsHeadLen || 
     371            xpwrite(fd, &sbs->FAT_bsCode, FAT_bsCodeLen, 
     372                    offsetof(struct fat_boot_sector, FAT_bsCode)) != FAT_bsCodeLen) { 
    362373            perror("writing fat bootblock"); 
    363374            return 1; 
    364375        } 
     376    } else if (fs_type == NTFS) { 
     377        struct ntfs_boot_sector *sbs = 
     378                (struct ntfs_boot_sector *)syslinux_bootsect; 
     379        if (xpwrite(fd, &sbs->NTFS_bsHead, 
     380                    NTFS_bsHeadLen, 0) != NTFS_bsHeadLen || 
     381                    xpwrite(fd, &sbs->NTFS_bsCode, NTFS_bsCodeLen, 
     382                    offsetof(struct ntfs_boot_sector, 
     383                    NTFS_bsCode)) != NTFS_bsCodeLen) { 
     384            perror("writing ntfs bootblock"); 
     385            return 1; 
     386        } 
    365387    } else { 
    366388        if (xpwrite(fd, syslinux_bootsect, syslinux_bootsect_len, 0) 
     
    755777int install_file(const char *path, int devfd, struct stat *rst) 
    756778{ 
    757         if (fs_type == EXT2 || fs_type == VFAT) 
     779        if (fs_type == EXT2 || fs_type == VFAT || fs_type == NTFS) 
    758780                return ext2_fat_install_file(path, devfd, rst); 
    759781        else if (fs_type == BTRFS) 
     
    829851                    break; 
    830852                } 
     853    case NTFS: 
     854        if ((!strcmp(mnt->mnt_type, "fuseblk") /* ntfs-3g */ || 
     855             !strcmp(mnt->mnt_type, "ntfs")) && 
     856            !stat(mnt->mnt_fsname, &dst) && 
     857            dst.st_rdev == dev) { 
     858            done = true; 
     859            break; 
     860        } 
     861 
     862        break; 
    831863        case NONE: 
    832864            break; 
     
    911943    else if (sfs.f_type == MSDOS_SUPER_MAGIC) 
    912944        fs_type = VFAT; 
     945    else if (sfs.f_type == NTFS_SB_MAGIC || 
     946                sfs.f_type == FUSE_SUPER_MAGIC /* ntfs-3g */) 
     947        fs_type = NTFS; 
    913948 
    914949    if (!fs_type) { 
    915         fprintf(stderr, "%s: not a fat, ext2/3/4 or btrfs filesystem: %s\n", 
     950        fprintf(stderr, "%s: not a fat, ntfs, ext2/3/4 or btrfs filesystem: %s\n", 
    916951                program, path); 
    917952        return -1;