diff --git a/freeldr/install/linux/finstext2.c b/freeldr/install/linux/finstext2.c new file mode 100644 index 00000000000..891439f4870 --- /dev/null +++ b/freeldr/install/linux/finstext2.c @@ -0,0 +1,147 @@ +#include +#include +#include "finstext2.h" +#include "ext2.h" // #defines ext2_data +#include +#include +#include +#include +#include +#include +#include + +#define MAJOR_VERSION 1 +#define MINOR_VERSION 0 + +PEXT2_BOOTCODE Ext2BootCode = (PEXT2_BOOTCODE)ext2_data; +struct ext3_super_block Ext2SuperBlock; +struct hd_geometry Ext2DriveGeometry; +unsigned char Ext2ExistingBootCode[1024]; + +char BlockDevice[260]; +int BlockDeviceSpecified = 0; +int BlockDeviceFileDescriptor; + +int main(int argc, char *argv[]) +{ + int Index; + char ch; + + // Verify that we got enough command line parameters + if (argc < 2) + { + printf("finstext2 block_device [-v]\n\n"); + printf("block_device Specifies the ext2/3 volume to install to (i.e. /dev/hda1)\n"); + printf("-v Displays the version\n\n"); + } + + // Parse the command line parameters + for (Index=1; IndexBootDrive = 0x80; + Ext2BootCode->BootPartition = 0x05; + //Ext2BootCode->SectorsPerTrack = Ext2DriveGeometry.sectors; + //Ext2BootCode->NumberOfHeads = Ext2DriveGeometry.heads; + Ext2BootCode->Ext2VolumeStartSector = Ext2DriveGeometry.start; + Ext2BootCode->Ext2BlockSizeInBytes = 1024 << Ext2SuperBlock.s_log_block_size; + Ext2BootCode->Ext2BlockSize = Ext2BootCode->Ext2BlockSizeInBytes / 512; + Ext2BootCode->Ext2PointersPerBlock = Ext2BootCode->Ext2BlockSizeInBytes / 4; + Ext2BootCode->Ext2GroupDescPerBlock = Ext2BootCode->Ext2BlockSizeInBytes / 32; + Ext2BootCode->Ext2FirstDataBlock = Ext2SuperBlock.s_first_data_block; + Ext2BootCode->Ext2InodesPerGroup = Ext2SuperBlock.s_inodes_per_group; + Ext2BootCode->Ext2InodesPerBlock = Ext2BootCode->Ext2BlockSizeInBytes / 128; + + if (lseek(BlockDeviceFileDescriptor, (off_t)0, SEEK_SET) == (off_t)-1) + { + close(BlockDeviceFileDescriptor); + printf("Couldn't write boot code on %s\n", BlockDevice); + return 1; + } + + if (write(BlockDeviceFileDescriptor, Ext2BootCode, (size_t)1024) != (ssize_t)1024) + { + close(BlockDeviceFileDescriptor); + printf("Couldn't write boot code on %s\n", BlockDevice); + return 1; + } + + close(BlockDeviceFileDescriptor); + + printf("Boot code written successfully!\n"); + } + + return 0; +} \ No newline at end of file diff --git a/freeldr/install/linux/finstext2.h b/freeldr/install/linux/finstext2.h new file mode 100644 index 00000000000..e6b6bf9f966 --- /dev/null +++ b/freeldr/install/linux/finstext2.h @@ -0,0 +1,29 @@ +#ifndef __FINSTEXT2_H +#define __FINSTEXT2_H + + +#define PACKED __attribute__((packed)) + +typedef struct +{ + unsigned char JmpBoot[3]; + unsigned char BootDrive; + unsigned char BootPartition; + //unsigned char SectorsPerTrack; + //unsigned short NumberOfHeads; + //unsigned long Reserved1; + //unsigned long Reserved2; + + unsigned long Ext2VolumeStartSector; // Start sector of the ext2 volume + unsigned long Ext2BlockSize; // Block size in sectors + unsigned long Ext2BlockSizeInBytes; // Block size in bytes + unsigned long Ext2PointersPerBlock; // Number of block pointers that can be contained in one block + unsigned long Ext2GroupDescPerBlock; // Number of group descriptors per block + unsigned long Ext2FirstDataBlock; // First data block (1 for 1024-byte blocks, 0 for bigger sizes) + unsigned long Ext2InodesPerGroup; // Number of inodes per group + unsigned long Ext2InodesPerBlock; // Number of inodes per block +} PACKED EXT2_BOOTCODE, *PEXT2_BOOTCODE; + + + +#endif // defined __FINSTEXT2_H \ No newline at end of file