[sl] syslinux support (EXPERIMENTAL)

* MS platforms only (*BREAKS* MinGW)
This commit is contained in:
Pete Batard 2012-01-12 02:52:40 +00:00
parent 130afd8294
commit acf7d072b0
43 changed files with 3063 additions and 57 deletions

18
configure vendored
View File

@ -652,6 +652,7 @@ ac_user_opts='
enable_option_checking
enable_silent_rules
with_freedos
with_syslinux
enable_debug
'
ac_precious_vars='build_alias
@ -1286,6 +1287,7 @@ Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-freedos embed FreeDOS support (default=yes)
--with-syslinux embed SysLinux support (default=yes)
Some influential environment variables:
CC C compiler command
@ -3475,10 +3477,24 @@ else
fi
if test "x$with_freedos" != "xno" ; then
AM_RCFLAGS="-DWITH_FREEDOS"
AM_RCFLAGS="${AM_RCFLAGS} -DWITH_FREEDOS"
EXESUFFIX="f"
fi
# Check whether --with-syslinux was given.
if test "${with_syslinux+set}" = set; then :
withval=$with_syslinux;
else
with_freedos=yes
fi
if test "x$with_syslinux" != "xno" ; then
AM_RCFLAGS="${AM_RCFLAGS} -DWITH_SYSLINUX"
EXESUFFIX="f"
fi
# Debug symbols
# Check whether --enable-debug was given.
if test "${enable_debug+set}" = set; then :

View File

@ -43,10 +43,21 @@ AC_ARG_WITH([freedos],
[],
[with_freedos=yes])
if test "x$with_freedos" != "xno" ; then
AM_RCFLAGS="-DWITH_FREEDOS"
AM_RCFLAGS="${AM_RCFLAGS} -DWITH_FREEDOS"
EXESUFFIX="f"
fi
AC_ARG_WITH([syslinux],
[AS_HELP_STRING([--with-syslinux],
[embed SysLinux support (default=yes)])],
[],
[with_freedos=yes])
if test "x$with_syslinux" != "xno" ; then
AM_RCFLAGS="${AM_RCFLAGS} -DWITH_SYSLINUX"
EXESUFFIX="f"
fi
# Debug symbols
AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], [keep debug symbols for gdb (default=yes)]),
[debug_enabled=$enableval],

View File

@ -3,3 +3,6 @@
/* Embed FreeDOS files and allow FreeDOS support */
#define WITH_FREEDOS
/* SysLinux support, for ISO -> bootable USB */
//#define WITH_SYSLINUX

BIN
res/syslinux/ldlinux.bss Normal file

Binary file not shown.

BIN
res/syslinux/ldlinux.sys Normal file

Binary file not shown.

View File

@ -8,6 +8,10 @@ Project("{11411DA5-63FE-49DC-8D5C-CA379B95FF3C}") = "rufus", "src\.msvc\rufus_20
EndProject
Project("{11411DA5-63FE-49DC-8D5C-CA379B95FF3C}") = "ms-sys", "src\ms-sys\.msvc\ms-sys.vcxproj", "{2B1D078D-8EB4-4398-9CA4-23457265A7F6}"
EndProject
Project("{11411DA5-63FE-49DC-8D5C-CA379B95FF3C}") = "syslinux-libfat", "src\syslinux\libfat\.msvc\libfat.vcxproj", "{8390DCE0-859D-4F57-AD9C-AAEAC4D77EEF}"
EndProject
Project("{11411DA5-63FE-49DC-8D5C-CA379B95FF3C}") = "syslinux-libinstaller", "src\syslinux\libinstaller\.msvc\libinstaller.vcxproj", "{266502AC-CD74-4581-B707-938A7D05AD7A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -32,6 +36,22 @@ Global
{2B1D078D-8EB4-4398-9CA4-23457265A7F6}.Release|Win32.Build.0 = Release|Win32
{2B1D078D-8EB4-4398-9CA4-23457265A7F6}.Release|x64.ActiveCfg = Release|x64
{2B1D078D-8EB4-4398-9CA4-23457265A7F6}.Release|x64.Build.0 = Release|x64
{8390DCE0-859D-4F57-AD9C-AAEAC4D77EEF}.Debug|Win32.ActiveCfg = Debug|Win32
{8390DCE0-859D-4F57-AD9C-AAEAC4D77EEF}.Debug|Win32.Build.0 = Debug|Win32
{8390DCE0-859D-4F57-AD9C-AAEAC4D77EEF}.Debug|x64.ActiveCfg = Debug|x64
{8390DCE0-859D-4F57-AD9C-AAEAC4D77EEF}.Debug|x64.Build.0 = Debug|x64
{8390DCE0-859D-4F57-AD9C-AAEAC4D77EEF}.Release|Win32.ActiveCfg = Release|Win32
{8390DCE0-859D-4F57-AD9C-AAEAC4D77EEF}.Release|Win32.Build.0 = Release|Win32
{8390DCE0-859D-4F57-AD9C-AAEAC4D77EEF}.Release|x64.ActiveCfg = Release|x64
{8390DCE0-859D-4F57-AD9C-AAEAC4D77EEF}.Release|x64.Build.0 = Release|x64
{266502AC-CD74-4581-B707-938A7D05AD7A}.Debug|Win32.ActiveCfg = Debug|Win32
{266502AC-CD74-4581-B707-938A7D05AD7A}.Debug|Win32.Build.0 = Debug|Win32
{266502AC-CD74-4581-B707-938A7D05AD7A}.Debug|x64.ActiveCfg = Debug|x64
{266502AC-CD74-4581-B707-938A7D05AD7A}.Debug|x64.Build.0 = Debug|x64
{266502AC-CD74-4581-B707-938A7D05AD7A}.Release|Win32.ActiveCfg = Release|Win32
{266502AC-CD74-4581-B707-938A7D05AD7A}.Release|Win32.Build.0 = Release|Win32
{266502AC-CD74-4581-B707-938A7D05AD7A}.Release|x64.ActiveCfg = Release|x64
{266502AC-CD74-4581-B707-938A7D05AD7A}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -80,7 +80,7 @@
<PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;_CRT_SECURE_NO_WARNINGS;ISOLATION_AWARE_ENABLED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>..\ms-sys\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\ms-sys\inc;..\syslinux;..\syslinux\libinstaller;..\syslinux\libfat;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>setupapi.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
@ -99,7 +99,7 @@
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>..\ms-sys\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\ms-sys\inc;..\syslinux;..\syslinux\libinstaller;..\syslinux\libfat;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;_CRT_SECURE_NO_WARNINGS;ISOLATION_AWARE_ENABLED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
@ -122,7 +122,7 @@
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;ISOLATION_AWARE_ENABLED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>..\ms-sys\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\ms-sys\inc;..\syslinux;..\syslinux\libinstaller;..\syslinux\libfat;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>setupapi.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
@ -144,7 +144,7 @@
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;ISOLATION_AWARE_ENABLED;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<AdditionalIncludeDirectories>..\ms-sys\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\ms-sys\inc;..\syslinux;..\syslinux\libinstaller;..\syslinux\libfat;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalDependencies>setupapi.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
@ -166,6 +166,7 @@
<ClCompile Include="..\rufus.c" />
<ClCompile Include="..\stdio.c" />
<ClCompile Include="..\stdlg.c" />
<ClCompile Include="..\syslinux.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\ms-config.h" />
@ -191,6 +192,12 @@
<ProjectReference Include="..\ms-sys\.msvc\ms-sys.vcxproj">
<Project>{2b1d078d-8eb4-4398-9ca4-23457265a7f6}</Project>
</ProjectReference>
<ProjectReference Include="..\syslinux\libfat\.msvc\libfat.vcxproj">
<Project>{8390dce0-859d-4f57-ad9c-aaeac4d77eef}</Project>
</ProjectReference>
<ProjectReference Include="..\syslinux\libinstaller\.msvc\libinstaller.vcxproj">
<Project>{266502ac-cd74-4581-b707-938a7d05ad7a}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -39,6 +39,9 @@
<ClCompile Include="..\dos_locale.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\syslinux.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\rufus.h">

View File

@ -3,7 +3,7 @@ TARGETTYPE=PROGRAM
UMTYPE=windows
UMENTRY=winmain
INCLUDES=$(DDK_INC_PATH);.\ms-sys\inc
INCLUDES=$(DDK_INC_PATH);.\ms-sys\inc;.\syslinux;.\syslinux\libfat;.\syslinux\libinstaller
C_DEFINES = $(C_DEFINES) /DDDKBUILD /DUNICODE /D_UNICODE /DISOLATION_AWARE_ENABLED
!IFNDEF MSC_WARNING_LEVEL
@ -18,7 +18,9 @@ TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib \
$(SDK_LIB_PATH)\version.lib \
$(SDK_LIB_PATH)\uuid.lib \
$(SDK_LIB_PATH)\shell32.lib \
.\ms-sys\ms-sys.lib
.\ms-sys\ms-sys.lib \
.\syslinux\libfat\libfat.lib \
.\syslinux\libinstaller\libinstaller.lib
# http://jpassing.com/2008/02/01/how-to-use-manifests-with-buildexe/
SXS_APPLICATION_MANIFEST=..\common_controls_and_elevation.manifest
@ -31,4 +33,5 @@ SOURCES=rufus.c \
dos_locale.c \
badblocks.c \
drive.c \
syslinux.c \
rufus.rc

View File

@ -25,6 +25,7 @@
#endif
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <string.h>
@ -428,9 +429,13 @@ BOOL ExtractFreeDOS(const char* path)
return SetDOSLocale(path, TRUE);
}
BOOL ExtractDOS(const char* path, int dos_type)
BOOL ExtractDOS(const char* path)
{
if (dos_type == DT_WINME)
switch(ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType))) {
case DT_WINME:
return ExtractMSDOS(path);
return ExtractFreeDOS(path);
case DT_FREEDOS:
return ExtractFreeDOS(path);
}
return FALSE;
}

View File

@ -105,7 +105,7 @@ typedef struct _LONG_FILE_NAME_ENTRY {
} LONG_FILE_NAME_ENTRY, *PLONG_FILE_NAME_ENTRY;
// sizeof = 0x020
#pragma pack()
#pragma pack(pop)
#define FAT_LFN_NAME_LENGTH \
(RTL_FIELD_SIZE(LONG_FILE_NAME_ENTRY, NameA) \

View File

@ -308,7 +308,11 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive)
fake_fd._ptr = (char*)hPhysicalDrive;
fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector;
r = write_95b_mbr(&fake_fd);
if (ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType)) == DT_SYSLINUX) {
r = write_syslinux_mbr(&fake_fd);
} else {
r = write_95b_mbr(&fake_fd);
}
out:
safe_free(buf);
@ -494,26 +498,38 @@ void __cdecl FormatThread(void* param)
UpdateProgress(OP_FIX_MBR, -1.0f);
if (IsChecked(IDC_DOS)) {
// We still have a lock, which we need to modify the volume boot record
// => no need to reacquire the lock...
hLogicalVolume = GetDriveHandle(num, drive_name, TRUE, FALSE);
if (hLogicalVolume == INVALID_HANDLE_VALUE) {
uprintf("Could not re-mount volume for partition boot record access\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED;
goto out;
}
PrintStatus(0, "Writing partition boot record...\n");
if (!WritePBR(hLogicalVolume, ComboBox_GetCurSel(hDOSType) == DT_FREEDOS)) {
// Errorcode has already been set
goto out;
}
// ...but we must have relinquished that lock to write the MS-DOS files
safe_unlockclose(hLogicalVolume);
UpdateProgress(OP_DOS, -1.0f);
PrintStatus(0, "Copying DOS files...\n");
if (!ExtractDOS(drive_name, ComboBox_GetCurSel(hDOSType))) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANNOT_COPY;
goto out;
switch (ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType))) {
case DT_FREEDOS:
case DT_WINME:
// We still have a lock, which we need to modify the volume boot record
// => no need to reacquire the lock...
hLogicalVolume = GetDriveHandle(num, drive_name, TRUE, FALSE);
if (hLogicalVolume == INVALID_HANDLE_VALUE) {
uprintf("Could not re-mount volume for partition boot record access\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED;
goto out;
}
PrintStatus(0, "Writing partition boot record...\n");
if (!WritePBR(hLogicalVolume, ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType)) == DT_FREEDOS)) {
// Errorcode has already been set
goto out;
}
// ...but we must have relinquished that lock to write the MS-DOS files
safe_unlockclose(hLogicalVolume);
UpdateProgress(OP_DOS, -1.0f);
PrintStatus(0, "Copying DOS files...\n");
if (!ExtractDOS(drive_name)) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANNOT_COPY;
goto out;
}
break;
// SysLinux requires patching of the PBR after the files have been extracted
case DT_SYSLINUX:
if (!InstallSysLinux(num, drive_name)) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANNOT_COPY;
goto out;
}
break;
}
}

View File

@ -10,13 +10,7 @@ MSC_WARNING_LEVEL=/W3
USE_MSVCRT=1
TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib \
$(SDK_LIB_PATH)\user32.lib \
$(SDK_LIB_PATH)\setupapi.lib \
$(SDK_LIB_PATH)\ole32.lib \
$(SDK_LIB_PATH)\version.lib \
$(SDK_LIB_PATH)\uuid.lib \
$(SDK_LIB_PATH)\shell32.lib \
ms-sys.lib
$(SDK_LIB_PATH)\user32.lib
SOURCES=file.c \
br.c \

View File

@ -35,6 +35,8 @@
#define IDR_FD_EGA16_CPX 324
#define IDR_FD_EGA17_CPX 325
#define IDR_FD_EGA18_CPX 326
#define IDR_SL_LDLINUX_BSS 400
#define IDR_SL_LDLINUX_SYS 401
#define IDC_DEVICE 1001
#define IDC_FILESYSTEM 1002
#define IDC_START 1003

View File

@ -56,7 +56,7 @@ char szFolderPath[MAX_PATH];
float fScale = 1.0f;
int default_fs;
HWND hDeviceList, hCapacity, hFileSystem, hClusterSize, hLabel, hDOSType, hNBPasses;
BOOL bWithFreeDOS;
BOOL bWithFreeDOS, bWithSysLinux;
static HWND hDeviceTooltip = NULL, hFSTooltip = NULL, hProgress = NULL;
static StrArray DriveID, DriveLabel;
@ -621,7 +621,18 @@ static void InitProgress(void)
}
if (IsChecked(IDC_DOS)) {
// 1 extra slot for PBR writing
nb_slots[OP_DOS] = ((ComboBox_GetCurSel(hDOSType) == DT_FREEDOS)?5:3)+1;
// TODO: switch
switch (ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType))) {
case DT_WINME:
nb_slots[OP_DOS] = 3+1;
break;
case DT_FREEDOS:
nb_slots[OP_DOS] = 5+1;
break;
default:
nb_slots[OP_DOS] = 2+1;
break;
}
}
nb_slots[OP_PARTITION] = 1;
nb_slots[OP_FIX_MBR] = 1;
@ -932,10 +943,13 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
IGNORE_RETVAL(ComboBox_AddStringU(hNBPasses, "4 Passes"));
IGNORE_RETVAL(ComboBox_SetCurSel(hNBPasses, 1));
// Fill up the DOS type dropdown
IGNORE_RETVAL(ComboBox_AddStringU(hDOSType, "FreeDOS"));
IGNORE_RETVAL(ComboBox_AddStringU(hDOSType, "WinMe"));
IGNORE_RETVAL(ComboBox_SetItemData(hDOSType, ComboBox_AddStringU(hDOSType, "WinMe"), DT_WINME));
if (bWithFreeDOS)
IGNORE_RETVAL(ComboBox_SetItemData(hDOSType, ComboBox_AddStringU(hDOSType, "FreeDOS"), DT_FREEDOS));
if (bWithSysLinux)
IGNORE_RETVAL(ComboBox_SetItemData(hDOSType, ComboBox_AddStringU(hDOSType, "SysLinux"), DT_SYSLINUX));
IGNORE_RETVAL(ComboBox_SetCurSel(hDOSType, bWithFreeDOS?DT_FREEDOS:DT_WINME));
if (bWithFreeDOS) {
if (bWithFreeDOS || bWithSysLinux) {
SetDlgItemTextA(hDlg, IDC_DOS, "Create a DOS bootable disk:");
ShowWindow(hDOSType, SW_SHOW);
}
@ -1126,6 +1140,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
bWithFreeDOS = (FindResource(hMainInstance, MAKEINTRESOURCE(IDR_FD_COMMAND_COM), RT_RCDATA) != NULL) &&
(FindResource(hMainInstance, MAKEINTRESOURCE(IDR_FD_KERNEL_SYS), RT_RCDATA) != NULL);
uprintf("FreeDOS resources are %sembedded with this app\n", bWithFreeDOS?"":"NOT ");
// Find out if the SysLinux resources are embedded in the app
bWithSysLinux = (FindResource(hMainInstance, MAKEINTRESOURCE(IDR_SL_LDLINUX_SYS), RT_RCDATA) != NULL) &&
(FindResource(hMainInstance, MAKEINTRESOURCE(IDR_SL_LDLINUX_BSS), RT_RCDATA) != NULL);
uprintf("SysLinux resources are %sembedded with this app\n", bWithSysLinux?"":"NOT ");
// Create the main Window
if ( (hDlg = CreateDialogA(hInstance, MAKEINTRESOURCEA(IDD_DIALOG), NULL, MainCallback)) == NULL ) {

View File

@ -117,8 +117,9 @@ enum {
};
enum dos_type {
DT_FREEDOS = 0,
DT_WINME,
DT_WINME = 0,
DT_FREEDOS,
DT_SYSLINUX,
DT_MAX
};
@ -163,7 +164,8 @@ extern HWND CreateTooltip(HWND hControl, const char* message, int duration);
extern void DestroyTooltip(HWND hWnd);
extern void DestroyAllTooltips(void);
extern BOOL Notification(int type, char* title, char* format, ...);
extern BOOL ExtractDOS(const char* path, int dos_type);
extern BOOL ExtractDOS(const char* path);
extern BOOL InstallSysLinux(DWORD num, const char* drive_name);
extern void __cdecl FormatThread(void* param);
extern BOOL CreatePartition(HANDLE hDrive);
extern HANDLE GetDriveHandle(DWORD DriveIndex, char* DriveLetter, BOOL bWriteAccess, BOOL bLockDrive);

View File

@ -7,8 +7,10 @@
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "../ms-config.h"
#include <windows.h>
#ifndef __GNUC__
#include "../ms-config.h"
#endif
#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif
@ -31,7 +33,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 206, 278
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Rufus v1.0.7.115"
CAPTION "Rufus v1.0.7.116"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,236,50,14
@ -67,7 +69,7 @@ BEGIN
DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP
CONTROL "<a href=""http://rufus.akeo.ie"">http://rufus.akeo.ie</a>",IDC_ABOUT_RUFUS_URL,
"SysLink",WS_TABSTOP,46,47,114,9
LTEXT "Version 1.0.7 (Build 115)",IDC_STATIC,46,19,78,8
LTEXT "Version 1.0.7 (Build 116)",IDC_STATIC,46,19,78,8
PUSHBUTTON "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP
EDITTEXT IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL
LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8
@ -111,8 +113,10 @@ END
2 TEXTINCLUDE
BEGIN
"#include ""../ms-config.h""\r\n"
"#include <windows.h>\r\n"
"#ifndef __GNUC__\r\n"
"#include ""../ms-config.h""\r\n"
"#endif\r\n"
"#ifndef IDC_STATIC\r\n"
"#define IDC_STATIC -1\r\n"
"#endif\r\n"
@ -152,6 +156,10 @@ BEGIN
"IDR_FD_EGA17_CPX RCDATA ""../res/freedos/ega17.cpx""\r\n"
"IDR_FD_EGA18_CPX RCDATA ""../res/freedos/ega18.cpx""\r\n"
"#endif\r\n"
"#if defined(WITH_SYSLINUX)\r\n"
"IDR_SL_LDLINUX_BSS RCDATA ""../res/syslinux/ldlinux.bss""\r\n"
"IDR_SL_LDLINUX_SYS RCDATA ""../res/syslinux/ldlinux.sys""\r\n"
"#endif\r\n"
"\r\n"
"// Must reference a manifest for visual styles and elevation\r\n"
"// Oh, and it must happen at the end, or MinGW will ignore it!\r\n"
@ -198,8 +206,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,7,115
PRODUCTVERSION 1,0,7,115
FILEVERSION 1,0,7,116
PRODUCTVERSION 1,0,7,116
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -216,13 +224,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "akeo.ie"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "1.0.7.115"
VALUE "FileVersion", "1.0.7.116"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "1.0.7.115"
VALUE "ProductVersion", "1.0.7.116"
END
END
BLOCK "VarFileInfo"
@ -281,6 +289,10 @@ IDR_FD_EGA16_CPX RCDATA "../res/freedos/ega16.cpx"
IDR_FD_EGA17_CPX RCDATA "../res/freedos/ega17.cpx"
IDR_FD_EGA18_CPX RCDATA "../res/freedos/ega18.cpx"
#endif
#if defined(WITH_SYSLINUX)
IDR_SL_LDLINUX_BSS RCDATA "../res/syslinux/ldlinux.bss"
IDR_SL_LDLINUX_SYS RCDATA "../res/syslinux/ldlinux.sys"
#endif
// Must reference a manifest for visual styles and elevation
// Oh, and it must happen at the end, or MinGW will ignore it!

212
src/syslinux.c Normal file
View File

@ -0,0 +1,212 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2003 Lars Munch Christensen - All Rights Reserved
* Copyright 1998-2008 H. Peter Anvin - All Rights Reserved
* Copyright 2011 Pete Batard
*
* Based on the Linux installer program for SYSLINUX by H. Peter Anvin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/* Memory leaks detection - define _CRTDBG_MAP_ALLOC as preprocessor macro */
#ifdef _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
#include <windows.h>
#include <stdio.h>
#include <malloc.h>
#include <ctype.h>
#include "rufus.h"
#include "resource.h"
#include "syslinux.h"
#include "libfat.h"
#include "setadv.h"
unsigned char* syslinux_ldlinux;
unsigned int syslinux_ldlinux_len;
unsigned char* syslinux_bootsect;
unsigned int syslinux_bootsect_len;
/*
* Wrapper for ReadFile suitable for libfat
*/
int libfat_readfile(intptr_t pp, void *buf, size_t secsize,
libfat_sector_t sector)
{
uint64_t offset = (uint64_t) sector * secsize;
LONG loword = (LONG) offset;
LONG hiword = (LONG) (offset >> 32);
LONG hiwordx = hiword;
DWORD bytes_read;
if (SetFilePointer((HANDLE) pp, loword, &hiwordx, FILE_BEGIN) != loword ||
hiword != hiwordx ||
!ReadFile((HANDLE) pp, buf, (DWORD)secsize, &bytes_read, NULL) ||
bytes_read != secsize) {
uprintf("Cannot read sector %u\n", sector);
// TODO -1?
return 0;
}
return (int)secsize;
}
// TODO: set format errors
BOOL InstallSysLinux(DWORD num, const char* drive_name)
{
HANDLE f_handle = INVALID_HANDLE_VALUE;
HANDLE d_handle = INVALID_HANDLE_VALUE;
DWORD bytes_read;
DWORD bytes_written;
BOOL r = FALSE;
HGLOBAL res_handle;
HRSRC res;
static unsigned char sectbuf[SECTOR_SIZE];
static char ldlinux_name[] = "?:\\ldlinux.sys";
struct libfat_filesystem *fs;
libfat_sector_t s, *secp;
libfat_sector_t *sectors;
int ldlinux_sectors;
uint32_t ldlinux_cluster;
int nsectors;
ldlinux_name[0] = drive_name[0];
/* Initialize the ADV -- this should be smarter */
syslinux_reset_adv(syslinux_adv);
/* Access ldlinux.sys resource */
res = FindResource(hMainInstance, MAKEINTRESOURCE(IDR_SL_LDLINUX_SYS), RT_RCDATA);
if (res == NULL) {
uprintf("Unable to locate ldlinux.sys resource: %s\n", WindowsErrorString());
goto out;
}
res_handle = LoadResource(NULL, res);
if (res_handle == NULL) {
uprintf("Unable to load ldlinux.sys resource: %s\n", WindowsErrorString());
goto out;
}
syslinux_ldlinux = (unsigned char*)LockResource(res_handle);
syslinux_ldlinux_len = SizeofResource(NULL, res);
/* Access ldlinux.bss resource */
res = FindResource(hMainInstance, MAKEINTRESOURCE(IDR_SL_LDLINUX_BSS), RT_RCDATA);
if (res == NULL) {
uprintf("Unable to locate ldlinux.bss resource: %s\n", WindowsErrorString());
goto out;
}
res_handle = LoadResource(NULL, res);
if (res_handle == NULL) {
uprintf("Unable to load ldlinux.bss resource: %s\n", WindowsErrorString());
goto out;
}
syslinux_bootsect = (unsigned char*)LockResource(res_handle);
syslinux_bootsect_len = SizeofResource(NULL, res);
/* Create ldlinux.sys file */
f_handle = CreateFileA(ldlinux_name, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM |
FILE_ATTRIBUTE_HIDDEN, NULL);
if (f_handle == INVALID_HANDLE_VALUE) {
uprintf("Unable to create ldlinux.sys\n");
goto out;
}
/* Write ldlinux.sys file */
if (!WriteFile(f_handle, syslinux_ldlinux, syslinux_ldlinux_len,
&bytes_written, NULL) ||
bytes_written != syslinux_ldlinux_len) {
uprintf("Could not write ldlinux.sys\n");
goto out;
}
if (!WriteFile(f_handle, syslinux_adv, 2 * ADV_SIZE,
&bytes_written, NULL) ||
bytes_written != 2 * ADV_SIZE) {
uprintf("Could not write ADV to ldlinux.sys\n");
goto out;
}
/* Now flush the media */
if (!FlushFileBuffers(f_handle)) {
uprintf("FlushFileBuffers failed\n");
goto out;
}
/* Reopen the volume (we already have a lock) */
d_handle = GetDriveHandle(num, (char*)drive_name, TRUE, FALSE);
if (d_handle == INVALID_HANDLE_VALUE) {
uprintf("Could open volume for syslinux operation\n");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED;
goto out;
}
/* Map the file (is there a better way to do this?) */
ldlinux_sectors = (syslinux_ldlinux_len + 2 * ADV_SIZE + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
sectors = (libfat_sector_t*) calloc(ldlinux_sectors, sizeof *sectors);
fs = libfat_open(libfat_readfile, (intptr_t) d_handle);
ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL);
secp = sectors;
nsectors = 0;
s = libfat_clustertosector(fs, ldlinux_cluster);
while (s && nsectors < ldlinux_sectors) {
*secp++ = s;
nsectors++;
s = libfat_nextsector(fs, s);
}
libfat_close(fs);
/* Patch ldlinux.sys and the boot sector */
syslinux_patch(sectors, nsectors, 0, 0, NULL, NULL);
/* Rewrite the file */
if (SetFilePointer(f_handle, 0, NULL, FILE_BEGIN) != 0 ||
!WriteFile(f_handle, syslinux_ldlinux, syslinux_ldlinux_len,
&bytes_written, NULL)
|| bytes_written != syslinux_ldlinux_len) {
uprintf("Could not write ldlinux.sys: %s\n", WindowsErrorString());
goto out;
}
/* Close file */
safe_closehandle(f_handle);
/* Make the syslinux boot sector */
if (SetFilePointer(d_handle, 0, NULL, FILE_BEGIN) != 0 ||
!ReadFile(d_handle, sectbuf, SECTOR_SIZE,
&bytes_read, NULL)
|| bytes_read != SECTOR_SIZE) {
uprintf("Could not read boot record: %s\n", WindowsErrorString());
goto out;
}
syslinux_make_bootsect(sectbuf);
if (SetFilePointer(d_handle, 0, NULL, FILE_BEGIN) != 0 ||
!WriteFile(d_handle, sectbuf, SECTOR_SIZE,
&bytes_written, NULL)
|| bytes_written != SECTOR_SIZE) {
uprintf("Could not write boot record: %s\n", WindowsErrorString());
goto out;
}
r = TRUE;
out:
safe_closehandle(d_handle);
safe_closehandle(f_handle);
return r;
}

301
src/syslinux/inttypes.h Normal file
View File

@ -0,0 +1,301 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file was original part of the w64 mingw-runtime package.
*/
/*
* THIS SOFTWARE IS NOT COPYRIGHTED
*
* Modified for libusb/MSVC: Pete Batard <pbatard@gmail.com>
*
* This source code is offered for use in the public domain. You may
* use, modify or distribute it freely.
*
* This code is distributed in the hope that it will be useful but
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
* DISCLAIMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* Date: 2010-04-02
*/
#ifndef _MSC_VER
#error This header should only be used with Microsoft compilers
#endif
/* 7.8 Format conversion of integer types <inttypes.h> */
#ifndef _INTTYPES_H_
#define _INTTYPES_H_
#include <stdint.h>
/* SysLinux types addon */
#include <sltypes.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
intmax_t quot;
intmax_t rem;
} imaxdiv_t;
#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS)
/* 7.8.1 Macros for format specifiers
*
* MS runtime does not yet understand C9x standard "ll"
* length specifier. It appears to treat "ll" as "l".
* The non-standard I64 length specifier causes warning in GCC,
* but understood by MS runtime functions.
*/
/* fprintf macros for signed types */
#define PRId8 "d"
#define PRId16 "d"
#define PRId32 "d"
#define PRId64 "I64d"
#define PRIdLEAST8 "d"
#define PRIdLEAST16 "d"
#define PRIdLEAST32 "d"
#define PRIdLEAST64 "I64d"
#define PRIdFAST8 "d"
#define PRIdFAST16 "d"
#define PRIdFAST32 "d"
#define PRIdFAST64 "I64d"
#define PRIdMAX "I64d"
#define PRIi8 "i"
#define PRIi16 "i"
#define PRIi32 "i"
#define PRIi64 "I64i"
#define PRIiLEAST8 "i"
#define PRIiLEAST16 "i"
#define PRIiLEAST32 "i"
#define PRIiLEAST64 "I64i"
#define PRIiFAST8 "i"
#define PRIiFAST16 "i"
#define PRIiFAST32 "i"
#define PRIiFAST64 "I64i"
#define PRIiMAX "I64i"
#define PRIo8 "o"
#define PRIo16 "o"
#define PRIo32 "o"
#define PRIo64 "I64o"
#define PRIoLEAST8 "o"
#define PRIoLEAST16 "o"
#define PRIoLEAST32 "o"
#define PRIoLEAST64 "I64o"
#define PRIoFAST8 "o"
#define PRIoFAST16 "o"
#define PRIoFAST32 "o"
#define PRIoFAST64 "I64o"
#define PRIoMAX "I64o"
/* fprintf macros for unsigned types */
#define PRIu8 "u"
#define PRIu16 "u"
#define PRIu32 "u"
#define PRIu64 "I64u"
#define PRIuLEAST8 "u"
#define PRIuLEAST16 "u"
#define PRIuLEAST32 "u"
#define PRIuLEAST64 "I64u"
#define PRIuFAST8 "u"
#define PRIuFAST16 "u"
#define PRIuFAST32 "u"
#define PRIuFAST64 "I64u"
#define PRIuMAX "I64u"
#define PRIx8 "x"
#define PRIx16 "x"
#define PRIx32 "x"
#define PRIx64 "I64x"
#define PRIxLEAST8 "x"
#define PRIxLEAST16 "x"
#define PRIxLEAST32 "x"
#define PRIxLEAST64 "I64x"
#define PRIxFAST8 "x"
#define PRIxFAST16 "x"
#define PRIxFAST32 "x"
#define PRIxFAST64 "I64x"
#define PRIxMAX "I64x"
#define PRIX8 "X"
#define PRIX16 "X"
#define PRIX32 "X"
#define PRIX64 "I64X"
#define PRIXLEAST8 "X"
#define PRIXLEAST16 "X"
#define PRIXLEAST32 "X"
#define PRIXLEAST64 "I64X"
#define PRIXFAST8 "X"
#define PRIXFAST16 "X"
#define PRIXFAST32 "X"
#define PRIXFAST64 "I64X"
#define PRIXMAX "I64X"
/*
* fscanf macros for signed int types
* NOTE: if 32-bit int is used for int_fast8_t and int_fast16_t
* (see stdint.h, 7.18.1.3), FAST8 and FAST16 should have
* no length identifiers
*/
#define SCNd16 "hd"
#define SCNd32 "d"
#define SCNd64 "I64d"
#define SCNdLEAST16 "hd"
#define SCNdLEAST32 "d"
#define SCNdLEAST64 "I64d"
#define SCNdFAST16 "hd"
#define SCNdFAST32 "d"
#define SCNdFAST64 "I64d"
#define SCNdMAX "I64d"
#define SCNi16 "hi"
#define SCNi32 "i"
#define SCNi64 "I64i"
#define SCNiLEAST16 "hi"
#define SCNiLEAST32 "i"
#define SCNiLEAST64 "I64i"
#define SCNiFAST16 "hi"
#define SCNiFAST32 "i"
#define SCNiFAST64 "I64i"
#define SCNiMAX "I64i"
#define SCNo16 "ho"
#define SCNo32 "o"
#define SCNo64 "I64o"
#define SCNoLEAST16 "ho"
#define SCNoLEAST32 "o"
#define SCNoLEAST64 "I64o"
#define SCNoFAST16 "ho"
#define SCNoFAST32 "o"
#define SCNoFAST64 "I64o"
#define SCNoMAX "I64o"
#define SCNx16 "hx"
#define SCNx32 "x"
#define SCNx64 "I64x"
#define SCNxLEAST16 "hx"
#define SCNxLEAST32 "x"
#define SCNxLEAST64 "I64x"
#define SCNxFAST16 "hx"
#define SCNxFAST32 "x"
#define SCNxFAST64 "I64x"
#define SCNxMAX "I64x"
/* fscanf macros for unsigned int types */
#define SCNu16 "hu"
#define SCNu32 "u"
#define SCNu64 "I64u"
#define SCNuLEAST16 "hu"
#define SCNuLEAST32 "u"
#define SCNuLEAST64 "I64u"
#define SCNuFAST16 "hu"
#define SCNuFAST32 "u"
#define SCNuFAST64 "I64u"
#define SCNuMAX "I64u"
#ifdef _WIN64
#define PRIdPTR "I64d"
#define PRIiPTR "I64i"
#define PRIoPTR "I64o"
#define PRIuPTR "I64u"
#define PRIxPTR "I64x"
#define PRIXPTR "I64X"
#define SCNdPTR "I64d"
#define SCNiPTR "I64i"
#define SCNoPTR "I64o"
#define SCNxPTR "I64x"
#define SCNuPTR "I64u"
#else
#define PRIdPTR "d"
#define PRIiPTR "i"
#define PRIoPTR "o"
#define PRIuPTR "u"
#define PRIxPTR "x"
#define PRIXPTR "X"
#define SCNdPTR "d"
#define SCNiPTR "i"
#define SCNoPTR "o"
#define SCNxPTR "x"
#define SCNuPTR "u"
#endif
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
/*
* no length modifier for char types prior to C9x
* MS runtime scanf appears to treat "hh" as "h"
*/
/* signed char */
#define SCNd8 "hhd"
#define SCNdLEAST8 "hhd"
#define SCNdFAST8 "hhd"
#define SCNi8 "hhi"
#define SCNiLEAST8 "hhi"
#define SCNiFAST8 "hhi"
#define SCNo8 "hho"
#define SCNoLEAST8 "hho"
#define SCNoFAST8 "hho"
#define SCNx8 "hhx"
#define SCNxLEAST8 "hhx"
#define SCNxFAST8 "hhx"
/* unsigned char */
#define SCNu8 "hhu"
#define SCNuLEAST8 "hhu"
#define SCNuFAST8 "hhu"
#endif /* __STDC_VERSION__ >= 199901 */
#endif /* !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) */
#ifdef __cplusplus
}
#endif
#endif /* ndef _INTTYPES_H */

View File

@ -0,0 +1,172 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\fat.h" />
<ClInclude Include="..\libfat.h" />
<ClInclude Include="..\libfatint.h" />
<ClInclude Include="..\ulint.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\cache.c" />
<ClCompile Include="..\fatchain.c" />
<ClCompile Include="..\open.c" />
<ClCompile Include="..\searchdir.c" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8390DCE0-859D-4F57-AD9C-AAEAC4D77EEF}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>libfat</RootNamespace>
<ProjectName>syslinux-libfat</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)x86_32\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)x86_32\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)x86_32\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)x86_32\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)x86_64\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)x86_64\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)x86_64\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)x86_64\$(Configuration)\$(ProjectName)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;_CRT_SECURE_NO_WARNINGS;ISOLATION_AWARE_ENABLED;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..;..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Lib>
<TargetMachine>MachineX86</TargetMachine>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;_CRT_SECURE_NO_WARNINGS;ISOLATION_AWARE_ENABLED;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..;..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<TargetMachine>MachineX86</TargetMachine>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;_CRT_SECURE_NO_WARNINGS;ISOLATION_AWARE_ENABLED;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..;..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Lib>
<TargetMachine>MachineX64</TargetMachine>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;_CRT_SECURE_NO_WARNINGS;ISOLATION_AWARE_ENABLED;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..;..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Lib>
<TargetMachine>MachineX64</TargetMachine>
</Lib>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\fat.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\libfat.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\libfatint.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\ulint.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\cache.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\fatchain.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\open.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\searchdir.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,18 @@
TARGETNAME=libfat
TARGETTYPE=LIBRARY
INCLUDES=$(DDK_INC_PATH);..
C_DEFINES=$(C_DEFINES) /DDDKBUILD /DUNICODE /D_UNICODE /DISOLATION_AWARE_ENABLED
!IFNDEF MSC_WARNING_LEVEL
MSC_WARNING_LEVEL=/W3
!ENDIF
USE_MSVCRT=1
TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib \
$(SDK_LIB_PATH)\user32.lib
SOURCES=cache.c \
fatchain.c \
open.c \
searchdir.c

View File

@ -0,0 +1,65 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/*
* cache.c
*
* Simple sector cache
*/
#include <stdlib.h>
#include "libfatint.h"
void *libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n)
{
struct libfat_sector *ls;
for (ls = fs->sectors; ls; ls = ls->next) {
if (ls->n == n)
return ls->data; /* Found in cache */
}
/* Not found in cache */
ls = malloc(sizeof(struct libfat_sector));
if (!ls) {
libfat_flush(fs);
ls = malloc(sizeof(struct libfat_sector));
if (!ls)
return NULL; /* Can't allocate memory */
}
if (fs->read(fs->readptr, ls->data, LIBFAT_SECTOR_SIZE, n)
!= LIBFAT_SECTOR_SIZE) {
free(ls);
return NULL; /* I/O error */
}
ls->n = n;
ls->next = fs->sectors;
fs->sectors = ls;
return ls->data;
}
void libfat_flush(struct libfat_filesystem *fs)
{
struct libfat_sector *ls, *lsnext;
lsnext = fs->sectors;
fs->sectors = NULL;
for (ls = lsnext; ls; ls = lsnext) {
lsnext = ls->next;
free(ls);
}
}

108
src/syslinux/libfat/fat.h Normal file
View File

@ -0,0 +1,108 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2001-2008 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/*
* fat.h
*
* Basic data structures for a FAT filesystem
*/
#ifndef FAT_H
#define FAT_H
#include "ulint.h"
/* The poor excuse FAT has for a superblock -- in the boot sector */
struct fat_bootsect {
le8_t bsJump[3]; /* Jump to code */
char bsOemName[8]; /* Formatting program */
le16_t bsBytesPerSec; /* Bytes/sector */
le8_t bsSecPerClust; /* Sectors/cluster */
le16_t bsResSectors; /* Reserved sectors */
le8_t bsFATs; /* Number of FATs */
le16_t bsRootDirEnts; /* Number of entries/root directory */
le16_t bsSectors; /* Number of sectors [1] */
le8_t bsMedia; /* Magic media type byte */
le16_t bsFATsecs; /* Sectors/FAT */
le16_t bsSecPerTrack; /* Sectors/track */
le16_t bsHeads; /* Number of heads */
le32_t bsHiddenSecs; /* Number of hidden sectors */
le32_t bsHugeSectors; /* Number of sectors [2] */
union {
/* FAT12/16 */
struct {
le8_t bsDriveNumber; /* Drive number */
le8_t bsReserved1; /* Reserved */
le8_t bsBootSignature; /* 0x29 */
le32_t bsVolumeID; /* Volume serial number */
char bsVolumeLabel[11]; /* Volume name */
char bsFileSysType[8]; /* File system type */
le8_t bsCode[448]; /* Boot sector code */
} fat16;
/* FAT32 */
struct {
le32_t bpb_fatsz32; /* Sectors/FAT */
le16_t bpb_extflags; /* Extended flags */
le16_t bpb_fsver; /* Filesystem version */
le32_t bpb_rootclus; /* Root directory cluster */
le16_t bpb_fsinfo; /* FSINFO sector number */
le16_t bpb_bkbootsec; /* Backup boot sector (superblock) */
char bpb_reserved[12];
/* Same shit, different offset! */
le8_t bsDriveNumber; /* Drive number */
le8_t bsReserved1; /* Reserved */
le8_t bsBootSignature; /* 0x29 */
le32_t bsVolumeID; /* Volume serial number */
char bsVolumeLabel[11]; /* Volume name */
char bsFileSysType[8]; /* File system type */
le8_t bsCode[420]; /* Boot sector code */
} fat32;
} u;
le16_t bsSignature; /* 0xAA55 */
};
#define BS_BOOTSIGNATURE 0x29
#define BS_SIGNATURE 0xAA55
/* A FAT filesystem directory entry */
struct fat_dirent {
le8_t name[11]; /* Mangled filename */
le8_t attribute; /* File type/attribute */
le8_t caseflags; /* VFAT: case for basis and extension */
le8_t ctime_ms; /* ms of creation time */
le32_t ctime; /* Creation time */
le16_t atime; /* Date portion (high 16 bits) of atime */
le16_t clusthi; /* FAT32: high 16 bits of cluster */
le32_t mtime; /* Modification time */
le16_t clustlo; /* First cluster pointer */
le32_t size; /* File size (bytes) */
};
/* A VFAT filesystem continuation entry */
struct fat_vfat_slot {
le8_t id; /* Sequence number for slot */
le16_t name0[5]; /* 5 characters */
le8_t attribute; /* Attribute byte */
le8_t reserved; /* Reserved, MBZ */
le8_t alias_csum; /* Short name checksum */
le16_t name5[6]; /* 6 characters */
le16_t firstclust; /* MBZ */
le16_t name11[2]; /* 2 characters */
};
#endif /* FAT_H */

View File

@ -0,0 +1,134 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/*
* fatchain.c
*
* Follow a FAT chain
*/
#include "libfatint.h"
#include "ulint.h"
/*
* Convert a cluster number (or 0 for the root directory) to a
* sector number. Return -1 on failure.
*/
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);
}
/*
* Get the next sector of either the root directory or a FAT chain.
* Returns 0 on end of file and -1 on error.
*/
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 = (int32_t) (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);
}

View File

@ -0,0 +1,85 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/*
* libfat.h
*
* Headers for the libfat library
*/
#ifndef LIBFAT_H
#define LIBFAT_H
#include <stddef.h>
#include <inttypes.h>
#define LIBFAT_SECTOR_SHIFT 9
#define LIBFAT_SECTOR_SIZE 512
#define LIBFAT_SECTOR_MASK 511
typedef uint64_t libfat_sector_t;
struct libfat_filesystem;
struct libfat_direntry {
libfat_sector_t sector;
int offset;
unsigned char entry[32];
};
/*
* Open the filesystem. The readfunc is the function to read
* sectors, in the format:
* int readfunc(intptr_t readptr, void *buf, size_t secsize,
* libfat_sector_t secno)
*
* ... where readptr is a private argument.
*
* A return value of != secsize is treated as error.
*/
struct libfat_filesystem
*libfat_open(int (*readfunc) (intptr_t, void *, size_t, libfat_sector_t),
intptr_t readptr);
void libfat_close(struct libfat_filesystem *);
/*
* Convert a cluster number (or 0 for the root directory) to a
* sector number. Return -1 on failure.
*/
libfat_sector_t libfat_clustertosector(const struct libfat_filesystem *fs,
int32_t cluster);
/*
* Get the next sector of either the root directory or a FAT chain.
* Returns 0 on end of file and -1 on error.
*/
libfat_sector_t libfat_nextsector(struct libfat_filesystem *fs,
libfat_sector_t s);
/*
* Flush all cached sectors for this filesystem.
*/
void libfat_flush(struct libfat_filesystem *fs);
/*
* Get a pointer to a specific sector.
*/
void *libfat_get_sector(struct libfat_filesystem *fs, libfat_sector_t n);
/*
* Search a FAT directory for a particular pre-mangled filename.
* Copies the directory entry into direntry and returns 0 if found.
*/
int32_t libfat_searchdir(struct libfat_filesystem *fs, int32_t dirclust,
const void *name, struct libfat_direntry *direntry);
#endif /* LIBFAT_H */

View File

@ -0,0 +1,55 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/*
* libfatint.h
*
* Internals for the libfat filesystem
*/
#ifndef LIBFATINT_H
#define LIBFATINT_H
#include "libfat.h"
#include "fat.h"
struct libfat_sector {
libfat_sector_t n; /* Sector number */
struct libfat_sector *next; /* Next in list */
char data[LIBFAT_SECTOR_SIZE];
};
enum fat_type {
FAT12,
FAT16,
FAT28
};
struct libfat_filesystem {
int (*read) (intptr_t, void *, size_t, libfat_sector_t);
intptr_t readptr;
enum fat_type fat_type;
unsigned int clustsize;
int clustshift;
int32_t endcluster; /* Highest legal cluster number + 1 */
int32_t rootcluster; /* Root directory cluster */
libfat_sector_t fat; /* Start of FAT */
libfat_sector_t rootdir; /* Start of root directory */
libfat_sector_t data; /* Start of data area */
libfat_sector_t end; /* End of filesystem */
struct libfat_sector *sectors;
};
#endif /* LIBFATINT_H */

117
src/syslinux/libfat/open.c Normal file
View File

@ -0,0 +1,117 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/*
* open.c
*
* Open a FAT filesystem and compute some initial values; return NULL
* on failure.
*/
#include <stdlib.h>
#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 *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 = (uint32_t) ((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);
}

View File

@ -0,0 +1,64 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2004-2008 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/*
* searchdir.c
*
* Search a FAT directory for a particular pre-mangled filename.
* Copies the directory entry into direntry and returns the starting cluster
* if found; returns -2 on not found, -1 on error, 0 on empty file.
*/
#include <string.h>
#include "libfatint.h"
int32_t libfat_searchdir(struct libfat_filesystem *fs, int32_t dirclust,
const void *name, struct libfat_direntry *direntry)
{
struct fat_dirent *dep;
int nent;
libfat_sector_t s = libfat_clustertosector(fs, dirclust);
while (1) {
if (s == 0)
return -2; /* Not found */
else if (s == (libfat_sector_t) - 1)
return -1; /* Error */
dep = libfat_get_sector(fs, s);
if (!dep)
return -1; /* Read error */
for (nent = 0; nent < LIBFAT_SECTOR_SIZE;
nent += sizeof(struct fat_dirent)) {
if (!memcmp(dep->name, name, 11)) {
if (direntry) {
memcpy(direntry->entry, dep, sizeof(*dep));
direntry->sector = s;
direntry->offset = nent;
}
if (read32(&dep->size) == 0)
return 0; /* An empty file has no clusters */
else
return read16(&dep->clustlo) +
(read16(&dep->clusthi) << 16);
}
if (dep->name[0] == 0)
return -2; /* Hit high water mark */
dep++;
}
s = libfat_nextsector(fs, s);
}
}

112
src/syslinux/libfat/ulint.h Normal file
View File

@ -0,0 +1,112 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2001-2008 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
* USA; either version 2 of the License, or (at your option) any later
* version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/*
* ulint.h
*
* Basic operations on unaligned, littleendian integers
*/
#ifndef ULINT_H
#define ULINT_H
#include <inttypes.h>
/* These are unaligned, littleendian integer types */
typedef uint8_t le8_t; /* 8-bit byte */
typedef uint8_t le16_t[2]; /* 16-bit word */
typedef uint8_t le32_t[4]; /* 32-bit dword */
/* Read/write these quantities */
static inline unsigned char read8(le8_t * _p)
{
return *_p;
}
static inline void write8(le8_t * _p, uint8_t _v)
{
*_p = _v;
}
#if defined(__i386__) || defined(__x86_64__)
/* Littleendian architectures which support unaligned memory accesses */
static inline unsigned short read16(le16_t * _p)
{
return *((const uint16_t *)_p);
}
static inline void write16(le16_t * _p, unsigned short _v)
{
*((uint16_t *) _p) = _v;
}
static inline unsigned int read32(le32_t * _p)
{
return *((const uint32_t *)_p);
}
static inline void write32(le32_t * _p, uint32_t _v)
{
*((uint32_t *) _p) = _v;
}
#else
/* Generic, mostly portable versions */
static inline unsigned short read16(le16_t * _pp)
{
uint8_t *_p = *_pp;
uint16_t _v;
_v = _p[0];
_v |= _p[1] << 8;
return _v;
}
static inline void write16(le16_t * _pp, uint16_t _v)
{
uint8_t *_p = *_pp;
_p[0] = _v & 0xFF;
_p[1] = (_v >> 8) & 0xFF;
}
static inline unsigned int read32(le32_t * _pp)
{
uint8_t *_p = *_pp;
uint32_t _v;
_v = _p[0];
_v |= _p[1] << 8;
_v |= _p[2] << 16;
_v |= _p[3] << 24;
return _v;
}
static inline void write32(le32_t * _pp, uint32_t _v)
{
uint8_t *_p = *_pp;
_p[0] = _v & 0xFF;
_p[1] = (_v >> 8) & 0xFF;
_p[2] = (_v >> 16) & 0xFF;
_p[3] = (_v >> 24) & 0xFF;
}
#endif
#endif /* ULINT_H */

View File

@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\advconst.h" />
<ClInclude Include="..\syslinux.h" />
<ClInclude Include="..\syslxint.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\fat.c" />
<ClCompile Include="..\setadv.c" />
<ClCompile Include="..\syslxmod.c" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{266502AC-CD74-4581-B707-938A7D05AD7A}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>libinstaller</RootNamespace>
<ProjectName>syslinux-libinstaller</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)x86_32\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)x86_32\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)x86_32\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)x86_32\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)x86_64\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)x86_64\$(Configuration)\$(ProjectName)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)x86_64\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)x86_64\$(Configuration)\$(ProjectName)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</LinkIncremental>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;_CRT_SECURE_NO_WARNINGS;ISOLATION_AWARE_ENABLED;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..;..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Lib>
<TargetMachine>MachineX86</TargetMachine>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;_CRT_SECURE_NO_WARNINGS;ISOLATION_AWARE_ENABLED;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..;..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<TargetMachine>MachineX86</TargetMachine>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;_CRT_SECURE_NO_WARNINGS;ISOLATION_AWARE_ENABLED;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..;..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Lib>
<TargetMachine>MachineX64</TargetMachine>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;_CRT_SECURE_NO_WARNINGS;ISOLATION_AWARE_ENABLED;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..;..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Lib>
<TargetMachine>MachineX64</TargetMachine>
</Lib>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\advconst.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\syslinux.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\syslxint.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\fat.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\setadv.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\syslxmod.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,17 @@
TARGETNAME=libinstaller
TARGETTYPE=LIBRARY
INCLUDES=$(DDK_INC_PATH);..
C_DEFINES=$(C_DEFINES) /DDDKBUILD /DUNICODE /D_UNICODE /DISOLATION_AWARE_ENABLED
!IFNDEF MSC_WARNING_LEVEL
MSC_WARNING_LEVEL=/W3
!ENDIF
USE_MSVCRT=1
TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib \
$(SDK_LIB_PATH)\user32.lib
SOURCES=fat.c \
setadv.c \
syslxmod.c

View File

@ -0,0 +1,45 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
* Copyright 2009 Intel Corporation; author: H. Peter Anvin
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* syslinux/advconst.h
*
* ADV defined constants
*
* Defined in a separate file so it can be used by non-COM32 code.
* Some of these constants are also defined in adv.inc, they better match...
*/
#ifndef _SYSLINUX_ADVCONST_H
#define _SYSLINUX_ADVCONST_H
#define ADV_END 0
#define ADV_BOOTONCE 1
#define ADV_MENUSAVE 2
#endif /* _SYSLINUX_ADVCONST_H */

View File

@ -0,0 +1,126 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1998-2008 H. Peter Anvin - All Rights Reserved
* Copyright 2009-2010 Intel Corporation; author H. Peter Anvin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/*
* fat.c - Initial sanity check for FAT-based installers
*/
#define _XOPEN_SOURCE 500 /* Required on glibc 2.x */
#define _BSD_SOURCE
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include "syslinux.h"
#include "syslxint.h"
void syslinux_make_bootsect(void *bs)
{
struct boot_sector *bootsect = bs;
const struct boot_sector *sbs =
(const struct boot_sector *)boot_sector;
memcpy(&bootsect->bsHead, &sbs->bsHead, bsHeadLen);
memcpy(&bootsect->bsCode, &sbs->bsCode, bsCodeLen);
}
/*
* Check to see that what we got was indeed an MS-DOS boot sector/superblock;
* Return NULL if OK and otherwise an error message;
*/
const char *syslinux_check_bootsect(const void *bs)
{
int sectorsize;
long long sectors, fatsectors, dsectors;
long long clusters;
int rootdirents, clustersize;
const struct boot_sector *sectbuf = bs;
/* Must be 0xF0 or 0xF8..0xFF */
if (get_8(&sectbuf->bsMedia) != 0xF0 && get_8(&sectbuf->bsMedia) < 0xF8)
return "invalid media signature (not a FAT filesystem?)";
sectorsize = get_16(&sectbuf->bsBytesPerSec);
if (sectorsize == SECTOR_SIZE)
; /* ok */
else if (sectorsize >= 512 && sectorsize <= 4096 &&
(sectorsize & (sectorsize - 1)) == 0)
return "unsupported sectors size";
else
return "impossible sector size";
clustersize = get_8(&sectbuf->bsSecPerClust);
if (clustersize == 0 || (clustersize & (clustersize - 1)))
return "impossible cluster size";
sectors = get_16(&sectbuf->bsSectors);
sectors = sectors ? sectors : get_32(&sectbuf->bsHugeSectors);
dsectors = sectors - get_16(&sectbuf->bsResSectors);
fatsectors = get_16(&sectbuf->bsFATsecs);
fatsectors = fatsectors ? fatsectors : get_32(&sectbuf->bs32.FATSz32);
fatsectors *= get_8(&sectbuf->bsFATs);
dsectors -= fatsectors;
rootdirents = get_16(&sectbuf->bsRootDirEnts);
dsectors -= (rootdirents + sectorsize / 32 - 1) / sectorsize;
if (dsectors < 0)
return "negative number of data sectors";
if (fatsectors == 0)
return "zero FAT sectors";
clusters = dsectors / clustersize;
if (clusters < 0xFFF5) {
/* FAT12 or FAT16 */
if (!get_16(&sectbuf->bsFATsecs))
return "zero FAT sectors (FAT12/16)";
if (get_8(&sectbuf->bs16.BootSignature) == 0x29) {
if (!memcmp(&sectbuf->bs16.FileSysType, "FAT12 ", 8)) {
if (clusters >= 0xFF5)
return "more than 4084 clusters but claims FAT12";
} else if (!memcmp(&sectbuf->bs16.FileSysType, "FAT16 ", 8)) {
if (clusters < 0xFF5)
return "less than 4084 clusters but claims FAT16";
} else if (!memcmp(&sectbuf->bs16.FileSysType, "FAT32 ", 8)) {
return "less than 65525 clusters but claims FAT32";
} else if (memcmp(&sectbuf->bs16.FileSysType, "FAT ", 8)) {
static char fserr[] =
"filesystem type \"????????\" not supported";
memcpy(fserr + 17, &sectbuf->bs16.FileSysType, 8);
return fserr;
}
}
} else if (clusters < 0x0FFFFFF5) {
/*
* FAT32...
*
* Moving the FileSysType and BootSignature was a lovely stroke
* of M$ idiocy...
*/
if (get_8(&sectbuf->bs32.BootSignature) != 0x29 ||
memcmp(&sectbuf->bs32.FileSysType, "FAT32 ", 8))
return "missing FAT32 signature";
} else {
return "impossibly large number of clusters";
}
return NULL;
}

View File

@ -0,0 +1,166 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
* Copyright 2010 Intel Corporation; author: H. Peter Anvin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/*
* setadv.c
*
* (Over)write a data item in the auxilliary data vector. To
* delete an item, set its length to zero.
*
* Return 0 on success, -1 on error, and set errno.
*
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include "syslxint.h"
unsigned char syslinux_adv[2 * ADV_SIZE];
#define ADV_MAGIC1 0x5a2d2fa5 /* Head signature */
#define ADV_MAGIC2 0xa3041767 /* Total checksum */
#define ADV_MAGIC3 0xdd28bf64 /* Tail signature */
static void cleanup_adv(unsigned char *advbuf)
{
int i;
uint32_t csum;
/* Make sure both copies agree, and update the checksum */
set_32((uint32_t *) advbuf, ADV_MAGIC1);
csum = ADV_MAGIC2;
for (i = 8; i < ADV_SIZE - 4; i += 4)
csum -= get_32((uint32_t *) (advbuf + i));
set_32((uint32_t *) (advbuf + 4), csum);
set_32((uint32_t *) (advbuf + ADV_SIZE - 4), ADV_MAGIC3);
memcpy(advbuf + ADV_SIZE, advbuf, ADV_SIZE);
}
int syslinux_setadv(int tag, size_t size, const void *data)
{
uint8_t *p;
size_t left;
uint8_t advtmp[ADV_SIZE];
if ((unsigned)tag - 1 > 254) {
errno = EINVAL;
return -1; /* Impossible tag value */
}
if (size > 255) {
errno = ENOSPC; /* Max 255 bytes for a data item */
return -1;
}
left = ADV_LEN;
p = advtmp;
memcpy(p, syslinux_adv + 2 * 4, left); /* Make working copy */
while (left >= 2) {
uint8_t ptag = p[0];
size_t plen = p[1] + 2;
if (ptag == ADV_END)
break;
if (ptag == tag) {
/* Found our tag. Delete it. */
if (plen >= left) {
/* Entire remainder is our tag */
break;
}
memmove(p, p + plen, left - plen);
} else {
/* Not our tag */
if (plen > left)
break; /* Corrupt tag (overrun) - overwrite it */
left -= plen;
p += plen;
}
}
/* Now (p, left) reflects the position to write in and how much space
we have for our data. */
if (size) {
if (left < size + 2) {
errno = ENOSPC; /* Not enough space for data */
return -1;
}
*p++ = (uint8_t) tag;
*p++ = (uint8_t) size;
memcpy(p, data, size);
p += size;
left -= size + 2;
}
memset(p, 0, left);
/* If we got here, everything went OK, commit the write */
memcpy(syslinux_adv + 2 * 4, advtmp, ADV_LEN);
cleanup_adv(syslinux_adv);
return 0;
}
void syslinux_reset_adv(unsigned char *advbuf)
{
/* Create an all-zero ADV */
memset(advbuf + 2 * 4, 0, ADV_LEN);
cleanup_adv(advbuf);
}
static int adv_consistent(const unsigned char *p)
{
int i;
uint32_t csum;
if (get_32((uint32_t *) p) != ADV_MAGIC1 ||
get_32((uint32_t *) (p + ADV_SIZE - 4)) != ADV_MAGIC3)
return 0;
csum = 0;
for (i = 4; i < ADV_SIZE - 4; i += 4)
csum += get_32((uint32_t *) (p + i));
return csum == ADV_MAGIC2;
}
/*
* Verify that an in-memory ADV is consistent, making the copies consistent.
* If neither copy is OK, return -1 and call syslinux_reset_adv().
*/
int syslinux_validate_adv(unsigned char *advbuf)
{
if (adv_consistent(advbuf + 0 * ADV_SIZE)) {
memcpy(advbuf + ADV_SIZE, advbuf, ADV_SIZE);
return 0;
} else if (adv_consistent(advbuf + 1 * ADV_SIZE)) {
memcpy(advbuf, advbuf + ADV_SIZE, ADV_SIZE);
return 0;
} else {
syslinux_reset_adv(advbuf);
return -1;
}
}

View File

@ -0,0 +1,16 @@
#ifndef _H_SET_ADV_
#define _H_SET_ADV_
/* ADV information */
#define ADV_SIZE 512 /* Total size */
#define ADV_LEN (ADV_SIZE-3*4) /* Usable data size */
extern unsigned char syslinux_adv[2 * ADV_SIZE];
int syslinux_setadv(int tag, size_t size, const void *data);
void syslinux_reset_adv(unsigned char *advbuf);
int syslinux_validate_adv(unsigned char *advbuf);
int read_adv(const char *path, const char *cfg);
int write_adv(const char *path, const char *cfg);
#endif

View File

@ -0,0 +1,55 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1998-2008 H. Peter Anvin - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
#ifndef SYSLINUX_H
#define SYSLINUX_H
#include <inttypes.h>
#include <sys/types.h>
#include "advconst.h"
#include "setadv.h"
/* The standard boot sector and ldlinux image */
extern unsigned char* syslinux_bootsect;
extern unsigned int syslinux_bootsect_len;
extern const int syslinux_bootsect_mtime;
extern unsigned char* syslinux_ldlinux;
extern unsigned int syslinux_ldlinux_len;
extern const int syslinux_ldlinux_mtime;
#define boot_sector syslinux_bootsect
#define boot_sector_len syslinux_bootsect_len
#define boot_image syslinux_ldlinux
#define boot_image_len syslinux_ldlinux_len
extern unsigned char syslinux_mbr[];
extern const unsigned int syslinux_mbr_len;
extern const int syslinux_mbr_mtime;
/* Sector size assumptions... */
#define SECTOR_SHIFT 9
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
/* This takes a boot sector and merges in the syslinux fields */
void syslinux_make_bootsect(void *);
/* Check to see that what we got was indeed an MS-DOS boot sector/superblock */
const char *syslinux_check_bootsect(const void *bs);
/* This patches the boot sector and ldlinux.sys based on a sector map */
typedef uint64_t sector_t;
int syslinux_patch(const sector_t *sectors, int nsectors,
int stupid, int raid_mode,
const char *subdir, const char *subvol);
#endif

View File

@ -0,0 +1,261 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
* Copyright 2009-2011 Intel Corporation; author: H. Peter Anvin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
#ifndef SYSLXINT_H
#define SYSLXINT_H
#include "syslinux.h"
#if defined(__386__) || defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)
# define X86_MEM 1 /* Littleendian and unaligned safe */
#else
# define X86_MEM 0
#endif
/*
* Access functions for littleendian numbers, possibly misaligned.
*/
static inline uint8_t get_8(const uint8_t * p)
{
return *p;
}
static inline uint16_t get_16(const uint16_t * p)
{
#if X86_MEM
/* Littleendian and unaligned-capable */
return *p;
#else
const uint8_t *pp = (const uint8_t *)p;
return pp[0] + ((uint16_t)pp[1] << 8);
#endif
}
static inline uint32_t get_32(const uint32_t * p)
{
#if X86_MEM
/* Littleendian and unaligned-capable */
return *p;
#else
const uint16_t *pp = (const uint16_t *)p;
return get_16(pp[0]) + (uint32_t)get_16(pp[1]);
#endif
}
static inline uint64_t get_64(const uint64_t * p)
{
#if X86_MEM
/* Littleendian and unaligned-capable */
return *p;
#else
const uint32_t *pp = (const uint32_t *)p;
return get_32(pp[0]) + (uint64_t)get_32(pp[1]);
#endif
}
static inline void set_8(uint8_t *p, uint8_t v)
{
*p = v;
}
static inline void set_16(uint16_t *p, uint16_t v)
{
#if X86_MEM
/* Littleendian and unaligned-capable */
*p = v;
#else
uint8_t *pp = (uint8_t *) p;
pp[0] = (v & 0xff);
pp[1] = ((v >> 8) & 0xff);
#endif
}
static inline void set_32(uint32_t *p, uint32_t v)
{
#if X86_MEM
/* Littleendian and unaligned-capable */
*p = v;
#else
uint8_t *pp = (uint8_t *) p;
pp[0] = (v & 0xff);
pp[1] = ((v >> 8) & 0xff);
pp[2] = ((v >> 16) & 0xff);
pp[3] = ((v >> 24) & 0xff);
#endif
}
static inline void set_64(uint64_t *p, uint64_t v)
{
#if X86_MEM
/* Littleendian and unaligned-capable */
*p = v;
#else
uint32_t *pp = (uint32_t *) p;
set_32(pp[0], v);
set_32(pp[1], v >> 32);
#endif
}
/*
* Special handling for the MS-DOS derivative: syslinux_ldlinux
* is a "far" object...
*/
#ifdef __MSDOS__
static inline __attribute__ ((const))
uint16_t ds(void)
{
uint16_t v;
asm("movw %%ds,%0":"=rm"(v));
return v;
}
static inline void *set_fs(const void *p)
{
uint16_t seg;
seg = ds() + ((size_t) p >> 4);
asm volatile ("movw %0,%%fs"::"rm" (seg));
return (void *)((size_t) p & 0xf);
}
uint8_t get_8_sl(const uint8_t * p);
uint16_t get_16_sl(const uint16_t * p);
uint32_t get_32_sl(const uint32_t * p);
uint64_t get_64_sl(const uint64_t * p);
void set_8_sl(uint8_t * p, uint8_t v);
void set_16_sl(uint16_t * p, uint16_t v);
void set_32_sl(uint32_t * p, uint32_t v);
void set_64_sl(uint64_t * p, uint64_t v);
void memcpy_to_sl(void *dst, const void *src, size_t len);
void memcpy_from_sl(void *dst, const void *src, size_t len);
#else
/* Sane system ... */
#define get_8_sl(x) get_8(x)
#define get_16_sl(x) get_16(x)
#define get_32_sl(x) get_32(x)
#define get_64_sl(x) get_64(x)
#define set_8_sl(x,y) set_8(x,y)
#define set_16_sl(x,y) set_16(x,y)
#define set_32_sl(x,y) set_32(x,y)
#define set_64_sl(x,y) set_64(x,y)
#define memcpy_to_sl(d,s,l) memcpy(d,s,l)
#define memcpy_from_sl(d,s,l) memcpy(d,s,l)
#endif
#define LDLINUX_MAGIC 0x3eb202fe
#define BS_MAGIC_VER (0x1b << 9)
/* Patch area for disk-based installers */
struct patch_area {
uint32_t magic; /* LDLINUX_MAGIC */
uint32_t instance; /* Per-version value */
uint16_t data_sectors;
uint16_t adv_sectors;
uint32_t dwords;
uint32_t checksum;
uint16_t maxtransfer;
uint16_t epaoffset; /* Pointer to the extended patch area */
};
struct ext_patch_area {
uint16_t advptroffset; /* ADV pointers */
uint16_t diroffset; /* Current directory field */
uint16_t dirlen; /* Length of current directory field */
uint16_t subvoloffset; /* Subvolume field */
uint16_t subvollen; /* Length of subvolume field */
uint16_t secptroffset; /* Sector extent pointers */
uint16_t secptrcnt; /* Number of sector extent pointers */
uint16_t sect1ptr0; /* Boot sector offset of sector 1 ptr LSW */
uint16_t sect1ptr1; /* Boot sector offset of sector 1 ptr MSW */
uint16_t raidpatch; /* Boot sector RAID mode patch pointer */
};
/* Sector extent */
#pragma pack(push, 1)
struct syslinux_extent {
uint64_t lba;
uint16_t len;
};
/* FAT bootsector format, also used by other disk-based derivatives */
struct boot_sector {
uint8_t bsJump[3];
char bsOemName[8];
uint16_t bsBytesPerSec;
uint8_t bsSecPerClust;
uint16_t bsResSectors;
uint8_t bsFATs;
uint16_t bsRootDirEnts;
uint16_t bsSectors;
uint8_t bsMedia;
uint16_t bsFATsecs;
uint16_t bsSecPerTrack;
uint16_t bsHeads;
uint32_t bsHiddenSecs;
uint32_t bsHugeSectors;
union {
struct {
uint8_t DriveNumber;
uint8_t Reserved1;
uint8_t BootSignature;
uint32_t VolumeID;
char VolumeLabel[11];
char FileSysType[8];
uint8_t Code[442];
} bs16;
struct {
uint32_t FATSz32;
uint16_t ExtFlags;
uint16_t FSVer;
uint32_t RootClus;
uint16_t FSInfo;
uint16_t BkBootSec;
uint8_t Reserved0[12];
uint8_t DriveNumber;
uint8_t Reserved1;
uint8_t BootSignature;
uint32_t VolumeID;
char VolumeLabel[11];
char FileSysType[8];
uint8_t Code[414];
} bs32;
};
uint32_t bsMagic;
uint16_t bsForwardPtr;
uint16_t bsSignature;
};
#pragma pack(pop)
#define bsHead bsJump
#define bsHeadLen offsetof(struct boot_sector, bsBytesPerSec)
#define bsCode bs32.Code /* The common safe choice */
#define bsCodeLen (offsetof(struct boot_sector, bsSignature) - \
offsetof(struct boot_sector, bsCode))
static inline int fat_check_sb_fields(const struct boot_sector *sb)
{
return sb->bsResSectors && sb->bsFATs &&
(!memcmp(sb->bs16.FileSysType, "FAT12 ", 8) ||
!memcmp(sb->bs16.FileSysType, "FAT16 ", 8) ||
!memcmp(sb->bs16.FileSysType, "FAT ", 8) ||
!memcmp(sb->bs32.FileSysType, "FAT32 ", 8));
}
#endif /* SYSLXINT_H */

View File

@ -0,0 +1,201 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1998-2008 H. Peter Anvin - All Rights Reserved
* Copyright 2009-2010 Intel Corporation; author H. Peter Anvin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
* Boston MA 02111-1307, USA; either version 2 of the License, or
* (at your option) any later version; incorporated herein by reference.
*
* ----------------------------------------------------------------------- */
/*
* syslxmod.c - Code to provide a SYSLINUX code set to an installer.
*/
#define _XOPEN_SOURCE 500 /* Required on glibc 2.x */
#define _BSD_SOURCE
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include "syslinux.h"
#include "syslxint.h"
/*
* Generate sector extents
*/
static void generate_extents(struct syslinux_extent *ex, int nptrs,
const sector_t *sectp, int nsect)
{
uint32_t addr = 0x8000; /* ldlinux.sys starts loading here */
uint32_t base;
sector_t sect, lba;
unsigned int len;
base = addr;
len = 0;
lba = 0;
memset(ex, 0, nptrs * sizeof *ex);
while (nsect) {
sect = *sectp++;
if (len) {
uint32_t xbytes = (len + 1) * SECTOR_SIZE;
if (sect == lba + len && xbytes < 65536 &&
((addr ^ (base + xbytes - 1)) & 0xffff0000) == 0) {
/* We can add to the current extent */
len++;
goto next;
}
set_64_sl(&ex->lba, lba);
set_16_sl(&ex->len, (uint16_t) len);
ex++;
}
base = addr;
lba = sect;
len = 1;
next:
addr += SECTOR_SIZE;
nsect--;
}
if (len) {
set_64_sl(&ex->lba, lba);
set_16_sl(&ex->len, (uint16_t) len);
ex++;
}
}
/*
* Form a pointer based on a 16-bit patcharea/epa field
*/
static inline void *ptr(void *img, uint16_t *offset_p)
{
return (char *)img + get_16_sl(offset_p);
}
/*
* This patches the boot sector and the beginning of ldlinux.sys
* based on an ldlinux.sys sector map passed in. Typically this is
* handled by writing ldlinux.sys, mapping it, and then overwrite it
* with the patched version. If this isn't safe to do because of
* an OS which does block reallocation, then overwrite it with
* direct access since the location is known.
*
* Returns the number of modified bytes in ldlinux.sys if successful,
* otherwise -1.
*/
#define NADV 2
int syslinux_patch(const sector_t *sectp, int nsectors,
int stupid, int raid_mode,
const char *subdir, const char *subvol)
{
struct patch_area *patcharea;
struct ext_patch_area *epa;
struct syslinux_extent *ex;
uint32_t *wp;
int nsect = ((boot_image_len + SECTOR_SIZE - 1) >> SECTOR_SHIFT) + 2;
uint32_t csum;
int i, dw, nptrs;
struct boot_sector *sbs = (struct boot_sector *)boot_sector;
uint64_t *advptrs;
if (nsectors < nsect)
return -1; /* The actual file is too small for content */
/* Search for LDLINUX_MAGIC to find the patch area */
for (wp = (uint32_t *)boot_image; get_32_sl(wp) != LDLINUX_MAGIC;
wp++)
;
patcharea = (struct patch_area *)wp;
epa = ptr(boot_image, &patcharea->epaoffset);
/* First sector need pointer in boot sector */
set_32(ptr(sbs, &epa->sect1ptr0), (uint32_t) sectp[0]);
set_32(ptr(sbs, &epa->sect1ptr1), (uint32_t) (sectp[0] >> 32));
sectp++;
/* Handle RAID mode */
if (raid_mode) {
/* Patch in INT 18h = CD 18 */
set_16(ptr(sbs, &epa->raidpatch), 0x18CD);
}
/* Set up the totals */
dw = boot_image_len >> 2; /* COMPLETE dwords, excluding ADV */
set_16_sl(&patcharea->data_sectors, nsect - 2); /* Not including ADVs */
set_16_sl(&patcharea->adv_sectors, 2); /* ADVs need 2 sectors */
set_32_sl(&patcharea->dwords, dw);
/* Handle Stupid mode */
if (stupid) {
/* Access only one sector at a time */
set_16_sl(&patcharea->maxtransfer, 1);
}
/* Set the sector extents */
ex = ptr(boot_image, &epa->secptroffset);
nptrs = get_16_sl(&epa->secptrcnt);
if (nsect > nptrs) {
/* Not necessarily an error in this case, but a general problem */
fprintf(stderr, "Insufficient extent space, build error!\n");
exit(1);
}
/* -1 for the pointer in the boot sector, -2 for the two ADVs */
generate_extents(ex, nptrs, sectp, nsect-1-2);
/* ADV pointers */
advptrs = ptr(boot_image, &epa->advptroffset);
set_64_sl(&advptrs[0], sectp[nsect-1-2]);
set_64_sl(&advptrs[1], sectp[nsect-1-1]);
/* Poke in the base directory path */
if (subdir) {
int sublen = (int) (strlen(subdir) + 1);
if (get_16_sl(&epa->dirlen) < sublen) {
fprintf(stderr, "Subdirectory path too long... aborting install!\n");
exit(1);
}
memcpy_to_sl(ptr(boot_image, &epa->diroffset), subdir, sublen);
}
/* Poke in the subvolume information */
if (subvol) {
int sublen = (int) (strlen(subvol) + 1);
if (get_16_sl(&epa->subvollen) < sublen) {
fprintf(stderr, "Subvol name too long... aborting install!\n");
exit(1);
}
memcpy_to_sl(ptr(boot_image, &epa->subvoloffset), subvol, sublen);
}
/* Now produce a checksum */
set_32_sl(&patcharea->checksum, 0);
csum = LDLINUX_MAGIC;
for (i = 0, wp = (uint32_t *)boot_image; i < dw; i++, wp++)
csum -= get_32_sl(wp); /* Negative checksum */
set_32_sl(&patcharea->checksum, csum);
/*
* Assume all bytes modified. This can be optimized at the expense
* of keeping track of what the highest modified address ever was.
*/
return dw << 2;
}

26
src/syslinux/sltypes.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef _MSC_VER
#error This header should only be used with Microsoft compilers
#endif
/* The addons below are not part of inttypes but required for syslinux */
#ifndef _SLTYPES_H_
#define _SLTYPES_H_
/* On MS environments, the inline keyword is available in C++ only */
#ifndef inline
#define inline __inline
#endif
/* ssize_t is also not available (copy/paste from MinGW) */
#ifndef _SSIZE_T_DEFINED
#define _SSIZE_T_DEFINED
#undef ssize_t
#ifdef _WIN64
typedef __int64 ssize_t;
#else
typedef int ssize_t;
#endif /* _WIN64 */
#endif /* _SSIZE_T_DEFINED */
#endif

262
src/syslinux/stdint.h Normal file
View File

@ -0,0 +1,262 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file was originally part of the w64 mingw-runtime package.
*/
/* ISO C9x 7.18 Integer types <stdint.h>
* Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794)
*
* THIS SOFTWARE IS NOT COPYRIGHTED
*
* Contributor: Danny Smith <danny_r_smith_2001@yahoo.co.nz>
* Modified for libusb/MSVC: Pete Batard <pbatard@gmail.com>
*
* This source code is offered for use in the public domain. You may
* use, modify or distribute it freely.
*
* This code is distributed in the hope that it will be useful but
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
* DISCLAIMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* Date: 2010-04-02
*/
#ifndef _MSC_VER
#error This header should only be used with Microsoft compilers
#endif
#ifndef _STDINT_H
#define _STDINT_H
#ifndef _INTPTR_T_DEFINED
#define _INTPTR_T_DEFINED
#ifndef __intptr_t_defined
#define __intptr_t_defined
#undef intptr_t
#ifdef _WIN64
typedef __int64 intptr_t;
#else
typedef int intptr_t;
#endif /* _WIN64 */
#endif /* __intptr_t_defined */
#endif /* _INTPTR_T_DEFINED */
#ifndef _UINTPTR_T_DEFINED
#define _UINTPTR_T_DEFINED
#ifndef __uintptr_t_defined
#define __uintptr_t_defined
#undef uintptr_t
#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
#else
typedef unsigned int uintptr_t;
#endif /* _WIN64 */
#endif /* __uintptr_t_defined */
#endif /* _UINTPTR_T_DEFINED */
#ifndef _PTRDIFF_T_DEFINED
#define _PTRDIFF_T_DEFINED
#ifndef _PTRDIFF_T_
#define _PTRDIFF_T_
#undef ptrdiff_t
#ifdef _WIN64
typedef __int64 ptrdiff_t;
#else
typedef int ptrdiff_t;
#endif /* _WIN64 */
#endif /* _PTRDIFF_T_ */
#endif /* _PTRDIFF_T_DEFINED */
#ifndef _WCHAR_T_DEFINED
#define _WCHAR_T_DEFINED
#ifndef __cplusplus
typedef unsigned short wchar_t;
#endif /* C++ */
#endif /* _WCHAR_T_DEFINED */
#ifndef _WCTYPE_T_DEFINED
#define _WCTYPE_T_DEFINED
#ifndef _WINT_T
#define _WINT_T
typedef unsigned short wint_t;
typedef unsigned short wctype_t;
#endif /* _WINT_T */
#endif /* _WCTYPE_T_DEFINED */
/* 7.18.1.1 Exact-width integer types */
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
/* 7.18.1.2 Minimum-width integer types */
typedef signed char int_least8_t;
typedef unsigned char uint_least8_t;
typedef short int_least16_t;
typedef unsigned short uint_least16_t;
typedef int int_least32_t;
typedef unsigned uint_least32_t;
typedef __int64 int_least64_t;
typedef unsigned __int64 uint_least64_t;
/* 7.18.1.3 Fastest minimum-width integer types
* Not actually guaranteed to be fastest for all purposes
* Here we use the exact-width types for 8 and 16-bit ints.
*/
typedef __int8 int_fast8_t;
typedef unsigned __int8 uint_fast8_t;
typedef __int16 int_fast16_t;
typedef unsigned __int16 uint_fast16_t;
typedef __int32 int_fast32_t;
typedef unsigned __int32 uint_fast32_t;
typedef __int64 int_fast64_t;
typedef unsigned __int64 uint_fast64_t;
/* 7.18.1.5 Greatest-width integer types */
typedef __int64 intmax_t;
typedef unsigned __int64 uintmax_t;
/* 7.18.2 Limits of specified-width integer types */
#if !defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS)
/* 7.18.2.1 Limits of exact-width integer types */
#define INT8_MIN (-128)
#define INT16_MIN (-32768)
#define INT32_MIN (-2147483647 - 1)
#define INT64_MIN (-9223372036854775807LL - 1)
#define INT8_MAX 127
#define INT16_MAX 32767
#define INT32_MAX 2147483647
#define INT64_MAX 9223372036854775807LL
#define UINT8_MAX 255
#define UINT16_MAX 65535
#define UINT32_MAX 0xffffffffU /* 4294967295U */
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
/* 7.18.2.2 Limits of minimum-width integer types */
#define INT_LEAST8_MIN INT8_MIN
#define INT_LEAST16_MIN INT16_MIN
#define INT_LEAST32_MIN INT32_MIN
#define INT_LEAST64_MIN INT64_MIN
#define INT_LEAST8_MAX INT8_MAX
#define INT_LEAST16_MAX INT16_MAX
#define INT_LEAST32_MAX INT32_MAX
#define INT_LEAST64_MAX INT64_MAX
#define UINT_LEAST8_MAX UINT8_MAX
#define UINT_LEAST16_MAX UINT16_MAX
#define UINT_LEAST32_MAX UINT32_MAX
#define UINT_LEAST64_MAX UINT64_MAX
/* 7.18.2.3 Limits of fastest minimum-width integer types */
#define INT_FAST8_MIN INT8_MIN
#define INT_FAST16_MIN INT16_MIN
#define INT_FAST32_MIN INT32_MIN
#define INT_FAST64_MIN INT64_MIN
#define INT_FAST8_MAX INT8_MAX
#define INT_FAST16_MAX INT16_MAX
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST64_MAX INT64_MAX
#define UINT_FAST8_MAX UINT8_MAX
#define UINT_FAST16_MAX UINT16_MAX
#define UINT_FAST32_MAX UINT32_MAX
#define UINT_FAST64_MAX UINT64_MAX
/* 7.18.2.4 Limits of integer types capable of holding
object pointers */
#ifdef _WIN64
#define INTPTR_MIN INT64_MIN
#define INTPTR_MAX INT64_MAX
#define UINTPTR_MAX UINT64_MAX
#else
#define INTPTR_MIN INT32_MIN
#define INTPTR_MAX INT32_MAX
#define UINTPTR_MAX UINT32_MAX
#endif
/* 7.18.2.5 Limits of greatest-width integer types */
#define INTMAX_MIN INT64_MIN
#define INTMAX_MAX INT64_MAX
#define UINTMAX_MAX UINT64_MAX
/* 7.18.3 Limits of other integer types */
#ifdef _WIN64
#define PTRDIFF_MIN INT64_MIN
#define PTRDIFF_MAX INT64_MAX
#else
#define PTRDIFF_MIN INT32_MIN
#define PTRDIFF_MAX INT32_MAX
#endif
#define SIG_ATOMIC_MIN INT32_MIN
#define SIG_ATOMIC_MAX INT32_MAX
#ifndef SIZE_MAX
#ifdef _WIN64
#define SIZE_MAX UINT64_MAX
#else
#define SIZE_MAX UINT32_MAX
#endif
#endif
#ifndef WCHAR_MIN /* also in wchar.h */
#define WCHAR_MIN 0U
#define WCHAR_MAX 0xffffU
#endif
/*
* wint_t is unsigned short for compatibility with MS runtime
*/
#define WINT_MIN 0U
#define WINT_MAX 0xffffU
#endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */
/* 7.18.4 Macros for integer constants */
#if !defined ( __cplusplus) || defined (__STDC_CONSTANT_MACROS)
/* 7.18.4.1 Macros for minimum-width integer constants
Accoding to Douglas Gwyn <gwyn@arl.mil>:
"This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
9899:1999 as initially published, the expansion was required
to be an integer constant of precisely matching type, which
is impossible to accomplish for the shorter types on most
platforms, because C99 provides no standard way to designate
an integer constant with width less than that of type int.
TC1 changed this to require just an integer constant
*expression* with *promoted* type."
The trick used here is from Clive D W Feather.
*/
#define INT8_C(val) (INT_LEAST8_MAX-INT_LEAST8_MAX+(val))
#define INT16_C(val) (INT_LEAST16_MAX-INT_LEAST16_MAX+(val))
#define INT32_C(val) (INT_LEAST32_MAX-INT_LEAST32_MAX+(val))
/* The 'trick' doesn't work in C89 for long long because, without
suffix, (val) will be evaluated as int, not intmax_t */
#define INT64_C(val) val##i64
#define UINT8_C(val) (val)
#define UINT16_C(val) (val)
#define UINT32_C(val) (val##i32)
#define UINT64_C(val) val##ui64
/* 7.18.4.2 Macros for greatest-width integer constants */
#define INTMAX_C(val) val##i64
#define UINTMAX_C(val) val##ui64
#endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */
#endif

View File

@ -25,8 +25,38 @@ copy obj%BUILD_ALT_DIR%\%ARCH_DIR%\ms-sys.lib . >NUL 2>&1
if EXIST Makefile.hide ren Makefile.hide Makefile
if EXIST sources del sources >NUL 2>&1
::# SysLinux libfat Library
cd ..\syslinux\libfat
if EXIST Makefile ren Makefile Makefile.hide
copy .msvc\libfat_sources sources >NUL 2>&1
@echo on
%BUILD_CMD%
@echo off
if errorlevel 1 goto builderror
copy obj%BUILD_ALT_DIR%\%ARCH_DIR%\libfat.lib . >NUL 2>&1
if EXIST Makefile.hide ren Makefile.hide Makefile
if EXIST sources del sources >NUL 2>&1
::# SysLinux libinstaller Library
cd ..\libinstaller
if EXIST Makefile ren Makefile Makefile.hide
copy .msvc\libinstaller_sources sources >NUL 2>&1
@echo on
%BUILD_CMD%
@echo off
if errorlevel 1 goto builderror
copy obj%BUILD_ALT_DIR%\%ARCH_DIR%\libinstaller.lib . >NUL 2>&1
if EXIST Makefile.hide ren Makefile.hide Makefile
if EXIST sources del sources >NUL 2>&1
::# Rufus Application
cd ..
cd ..\..
if EXIST Makefile ren Makefile Makefile.hide
copy .msvc\rufus_sources sources >NUL 2>&1