void myformat(int size) { // Do not touch or move this function dcreate_connect(); // Calculate number of data blocks, FAT entries. int num_dblocks = get_num_dblocks(size); // Format volume control block. vcb volblock = make_volblock(num_dblocks); char vcbtemp[BLOCKSIZE]; memset(vcbtemp,0,BLOCKSIZE); memcpy(vcbtemp,&volblock,sizeof(vcb)); dwrite(0,vcbtemp); // Format directory entries. dirent dent = make_directent(); char dirtemp[BLOCKSIZE]; //FIXME: Eventually will have to be smaller. memset(dirtemp,0,BLOCKSIZE); memcpy(dirtemp,&dent, sizeof(dirent)); for(int i = 1; i < 101; i++){ dwrite(i,dirtemp); } /* dirent dent; char dirblock[BLOCKSIZE]; memset(dirblock,0,BLOCKSIZE); memcpy(dirblock,&dirent,sizeof(dirblock)); for(int i = 1; i <= 100; i++){ dwrite(i,dirblock); } */ /* 3600: FILL IN CODE HERE. YOU SHOULD INITIALIZE ANY ON-DISK STRUCTURES TO THEIR INITIAL VALUE, AS YOU ARE FORMATTING A BLANK DISK. YOUR DISK SHOULD BE size BLOCKS IN SIZE. */ /* 3600: AN EXAMPLE OF READING/WRITING TO THE DISK IS BELOW - YOU'LL WANT TO REPLACE THE CODE BELOW WITH SOMETHING MEANINGFUL. */ /* // first, create a zero-ed out array of memory char *tmp = (char *) malloc(BLOCKSIZE); memset(tmp, 0, BLOCKSIZE); // now, write that to every block for (int i=0; i<size; i++) if (dwrite(i, tmp) < 0) perror("Error while writing to disk"); */ // voila! we now have a disk containing all zeros // Do not touch or move this function dunconnect(); }
void myformat(int size) { // Do not touch or move this function dcreate_connect(); int num_dblocks = get_num_dblocks(size); // Format vcb vcb volblock = make_volblock(num_dblocks); // Do we need to malloc space(BLOCKSIZE) for vcbtemp? char vcbtemp[BLOCKSIZE]; memset(vcbtemp, 0, BLOCKSIZE); memcpy(vcbtemp, &volblock, BLOCKSIZE); dwrite(0, vcbtemp); // Format dirents dirent dent = make_dirent(); // Do we need to malloc space(BLOCKSIZE) for dirtemp? char dirtemp[BLOCKSIZE]; memset(dirtemp, 0, BLOCKSIZE); memcpy(dirtemp, &dent, BLOCKSIZE); for(int i = volblock.de_start; i < volblock.de_start+volblock.de_length; i++){ dwrite(i, dirtemp); } // char fat_block_temp[BLOCKSIZE]; // memset(fat_block_temp,0,BLOCKSIZE); fatent fe = make_fatent(); fatent fat_block[128]; int remaining = volblock.fat_length; int block = volblock.fat_start; while(remaining > 0){ for(int i = 0; i<128; i++){ fat_block[i] = fe; remaining--; } char fat_block_temp[BLOCKSIZE]; memset(fat_block_temp,0,BLOCKSIZE); memcpy(fat_block_temp,&fat_block,sizeof(fat_block)); dwrite(block,fat_block_temp); block++; } char empty_block[BLOCKSIZE]; memset(empty_block,0,BLOCKSIZE); for(int i = 0; i < num_dblocks; i++){ dwrite((volblock.db_start + i), empty_block); } /* char fat_entry_temp[4]; // memset(fat_entry_temp,0,4); // memcpy(fat_entry_temp,&fe,4); for(int i = volblock.fat_start; i<volblock.fat_start+volblock.fat_length;i++){ fprintf(stderr,"writing fat shit"); for(int j = 0; j < 128; j++){ // Set FAT defaults // Format single FAT block with 128 default FAT entries memcpy(&fat_block_temp[4*j],fat_entry_temp,4); fprintf(stderr,"memcpy(&fat_block_temp..."); } dwrite(i, fat_block_temp); }*/ /* 3600: FILL IN CODE HERE. YOU SHOULD INITIALIZE ANY ON-DISK STRUCTURES TO THEIR INITIAL VALUE, AS YOU ARE FORMATTING A BLANK DISK. YOUR DISK SHOULD BE size BLOCKS IN SIZE. */ /* 3600: AN EXAMPLE OF READING/WRITING TO THE DISK IS BELOW - YOU'LL WANT TO REPLACE THE CODE BELOW WITH SOMETHING MEANINGFUL. */ /* // first, create a zero-ed out array of memory char *tmp = (char *) malloc(BLOCKSIZE); memset(tmp, 0, BLOCKSIZE); // now, write that to every block for (int i=0; i<size; i++) if (dwrite(i, tmp) < 0) perror("Error while writing to disk"); // voila! we now have a disk containing all zeros */ // Do not touch or move this function dunconnect(); }