int main(int argc, char* argv[]) { int iSourceFd; int iTargetFd; int iBootLoaderSize; int iKernel32SectorCount; int iKernel64SectorCount; int iSourceSize; if( argc < 3 ) { fprintf( stderr, "[ERROR] ImageMaker.exe BootLoader.bin Kernel32.bin\n" ); exit( -1 ); } if( ( iTargetFd = open( "Disk.img", O_RDWR | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE ) ) == -1 ) { fprintf( stderr , "[ERROR] Disk.img open fail.\n" ); exit( -1 ); } printf( "[INFO] Copy boot loader to image file\n" ); if( ( iSourceFd = open( argv[ 1 ], O_RDONLY | O_BINARY ) ) == -1 ) { fprintf( stderr, "[ERROR] %s open fail\n", argv[ 1 ] ); exit( -1 ); } iSourceSize = CopyFile( iSourceFd, iTargetFd ); close( iSourceFd ); iBootLoaderSize = AdjustInSectorSize( iTargetFd , iSourceSize ); printf( "[INFO] %s size = [%d] and sector count = [%d]\n", argv[ 1 ], iSourceSize, iBootLoaderSize ); printf( "[INFO] Copy protected mode kernel to image file\n" ); if( ( iSourceFd = open( argv[ 2 ], O_RDONLY | O_BINARY ) ) == -1 ) { fprintf( stderr, "[ERROR] %s open fail\n", argv[ 2 ] ); exit( -1 ); } iSourceSize = CopyFile( iSourceFd, iTargetFd ); close( iSourceFd ); iKernel32SectorCount = AdjustInSectorSize( iTargetFd, iSourceSize ); printf( "[INFO] %s size = [%d] and sector count = [%d]\n", argv[ 2 ], iSourceSize, iKernel32SectorCount ); iSourceSize = CopyFile( iSourceFd, iTargetFd ); close( iSourceFd ); printf( "[INFO] Start to write kernel information\n" ); WriteKernelInformation( iTargetFd, iKernel32SectorCount ); printf( "[INFO] Image file create complete\n" ); close( iTargetFd ); return 0; }
/** * Main 함수 */ int main(int argc, char* argv[]) { int iSourceFd; int iTargetFd; int iBootLoaderSize; int iKernel32SectorCount; int iSourceSize; // 커맨드 라인 옵션 검사 if( argc < 3 ) { fprintf( stderr, "[ERROR] ImageMaker.exe BootLoader.bin Kernel32.bin\n" ); exit( -1 ); } // Disk.img 파일을 생성 if( ( iTargetFd = open( "Disk.img", O_RDWR | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE ) ) == -1 ) { fprintf( stderr , "[ERROR] Disk.img open fail.\n" ); exit( -1 ); } //-------------------------------------------------------------------------- // 부트 로더 파일을 열어서 모든 내용을 디스크 이미지 파일로 복사 //-------------------------------------------------------------------------- printf( "[INFO] Copy boot loader to image file\n" ); if( ( iSourceFd = open( argv[ 1 ], O_RDONLY | O_BINARY ) ) == -1 ) { fprintf( stderr, "[ERROR] %s open fail\n", argv[ 1 ] ); exit( -1 ); } iSourceSize = CopyFile( iSourceFd, iTargetFd ); close( iSourceFd ); // 파일 크기를 섹터 크기인 512바이트로 맞추기 위해 나머지 부분을 0x00 으로 채움 iBootLoaderSize = AdjustInSectorSize( iTargetFd , iSourceSize ); printf( "[INFO] %s size = [%d] and sector count = [%d]\n", argv[ 1 ], iSourceSize, iBootLoaderSize ); //-------------------------------------------------------------------------- // 32비트 커널 파일을 열어서 모든 내용을 디스크 이미지 파일로 복사 //-------------------------------------------------------------------------- printf( "[INFO] Copy protected mode kernel to image file\n" ); if( ( iSourceFd = open( argv[ 2 ], O_RDONLY | O_BINARY ) ) == -1 ) { fprintf( stderr, "[ERROR] %s open fail\n", argv[ 2 ] ); exit( -1 ); } iSourceSize = CopyFile( iSourceFd, iTargetFd ); close( iSourceFd ); // 파일 크기를 섹터 크기인 512바이트로 맞추기 위해 나머지 부분을 0x00 으로 채움 iKernel32SectorCount = AdjustInSectorSize( iTargetFd, iSourceSize ); printf( "[INFO] %s size = [%d] and sector count = [%d]\n", argv[ 2 ], iSourceSize, iKernel32SectorCount ); //-------------------------------------------------------------------------- // 디스크 이미지에 커널 정보를 갱신 //-------------------------------------------------------------------------- printf( "[INFO] Start to write kernel information\n" ); // 부트섹터의 5번째 바이트부터 커널에 대한 정보를 넣음 WriteKernelInformation( iTargetFd, iKernel32SectorCount ); printf( "[INFO] Image file create complete\n" ); close( iTargetFd ); return 0; }