#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 = 0xff; Ext2BootCode->BootPartition = 0x00; //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; }