/* encode.c Written by, Sohail Qayum Malik */ #include "encode.h" void main(int argc, char * argv[]){ unsigned int flag = ZERO; short int bootBlockFileHandle = ZERO; short int bootFileHandle = ZERO; if( argc < THREE ){ printf("Incorrect usage.\n"); printf("Usage example.... %s bootblock boot\n", argv[ZERO]); printf("bootblock is your partition bootsector code....\n"); printf("boot is your kernel.\n"); return; } flag = ZERO; flag = readSector(sectorBuffer, DRIVE_FD + HEAD_ZERO, TRACK + SECTOR_ONE, SECTORS); if(flag != 0){ printf("Read error %d\n", flag); return; } if( (bootBlockFileHandle = open( argv[ONE], O_RDONLY | O_BINARY )) == (int)LESS_THAN_ZERO){ printf("Unable to open %s .\n", argv[ONE]); return; } if( (bootFileHandle = open( argv[TWO], O_RDONLY | O_BINARY )) == (int)LESS_THAN_ZERO){ printf("Unable to open %s .\n", argv[TWO]); close(bootBlockFileHandle); return; } printf("%s is accessed.\n", argv[ONE]); printf("%s is accessed.\n", argv[TWO]); numberOfBytesReadBootBlock = read(bootBlockFileHandle, (sectorBuffer + 62), SECTOR_SIZE); numberOfBytesReadBoot = read(bootFileHandle, (sectorBuffer + SECTOR_SIZE), SECTOR_SIZE); sectorBuffer[SYMBOLAINDEX] = SYMBOLA; sectorBuffer[SYMBOLBINDEX] = SYMBOLB; if( numberOfBytesReadBootBlock == (int)LESS_THAN_ZERO || numberOfBytesReadBoot == (int)LESS_THAN_ZERO ) printf("Unable to read either %s or %s.\n", argv[ONE], argv[TWO]); else{ printf("%d bytes read from %s.\n", numberOfBytesReadBootBlock, argv[ONE]); printf("%d bytes read from %s.\n", numberOfBytesReadBoot, argv[TWO]); printf("Attempting a write to the disk.... "); flag = ZERO; flag = writeSector(sectorBuffer, DRIVE_FD + HEAD_ZERO, TRACK + SECTOR_ONE, (SECTORS * TWO)); if(flag != 0){ printf("Write error %d\n", flag); return; } printf("write completed.\n"); printf(":-) bye.\n"); } close(bootBlockFileHandle); close(bootFileHandle); }