int main(int argc, char* argv[]) { void* pointer = NULL; int shm_ID; if ((shm_ID = shmget(SHMKEY, SHMSIZE, IPC_CREAT | 0444)) < 0 ) { perror("Error getting SHM segment."); exit(-1); } if ((pointer = shmat(shm_ID, NULL, 0)) == NULL) { perror("Error including SHM address space."); exit(0); } shmStruct *value = (shmStruct*)pointer; //memcpy(&value, pointer, sizeof(pointer)); printf("pointer size: %i\n", sizeof(pointer)); loadFloppyImage(value->floppyName); if (shmdt(pointer) < 0) { perror("Error deallocating shared memory."); exit(-1); } readBootSector(); printBootSector(); return 0; }
int main(int argc, char* argv[]) { bootsector * bs = malloc(sizeof(bootsector)); FILE *fat_file; if(argc != 3) { printf("Argument error.\n"); exit(1); } if(!(fat_file = fopen(argv[2],"r+"))) { printf("The file can not be open.\n"); } //Read boot sector fread(bs->jmp, 3, 1, fat_file); fread(bs->oem, 8, 1, fat_file); fread(bs->bytesInSector, 2, 1, fat_file); fread(bs->sectorInCluster, 1, 1, fat_file); fread(bs->numResSector, 2, 1, fat_file); fread(bs->numFatCopies, 1, 1, fat_file); fread(bs->numRootDirs, 2, 1, fat_file); fread(bs->numSectFS, 2, 1, fat_file); fread(bs->mediaDesc, 1, 1, fat_file); fread(bs->numSectFat, 2, 1, fat_file); fread(bs->numSectTrac, 2, 1, fat_file); fread(bs->numheads, 2, 1, fat_file); fread(bs->numHiddenSect, 2, 1, fat_file); fread(bs->bootstrap, 480, 1, fat_file); fread(bs->sig, 2, 1, fat_file); int reservedRegion = twoByteToInt(bs->numResSector) * twoByteToInt(bs->bytesInSector); int fatByteSize = twoByteToInt(bs->numSectFat) * twoByteToInt(bs->bytesInSector);\ int fatClusterSize = fatByteSize/2; int fat0pos = reservedRegion; int fat1pos = reservedRegion + fatByteSize; int rootDirSectorPosition = twoByteToInt(bs->numResSector) + (bs->numFatCopies[0] * twoByteToInt(bs->numSectFat)); int dataRegionStart = rootDirSectorPosition + ((twoByteToInt(bs->numRootDirs)*32)/twoByteToInt(bs->bytesInSector)); int dirBytePos = rootDirSectorPosition * twoByteToInt(bs->bytesInSector); //printf("\n FAT0 position = %d \n", fat0pos); //printf(" FAT1 position = %d \n", fat1pos); fseek(fat_file, fat0pos, SEEK_SET); unsigned short fat0[fatClusterSize]; unsigned short fat1[fatClusterSize]; fread(fat0, fatClusterSize, 2, fat_file); fread(fat1, fatClusterSize, 2, fat_file); if (strcmp("-i", argv[1]) == 0) { printBootSector(bs); } else if(strcmp("-vf", argv[1]) == 0) { verifyFats(fatClusterSize, fat0, fat1); }else if(strcmp("-bl", argv[1]) == 0) { emptyBlocks(fatClusterSize, fat0); }else if(strcmp("-bd", argv[1]) == 0) { emptyBlocksWithData(fatClusterSize, dirBytePos, fat0, fat_file); }else if(strcmp("-cf1", argv[1]) == 0) { copyFat(fat0pos, fatClusterSize, fat_file, fat1); }else if(strcmp("-cf2", argv[1]) == 0) { copyFat(fat1pos, fatClusterSize, fat_file, fat0); }else if(strcmp("-crp1", argv[1]) == 0) { fatCorrupted(fat0pos, fat_file); }else if(strcmp("-crp2", argv[1]) == 0) { fatCorrupted(fat1pos, fat_file); }else { printf("Wrong argument.\n"); exit(1); } return (EXIT_SUCCESS); }