int delete_inode(unsigned int inumber) { struct inode_s inode; int i; read_inode(inumber,&inode); /* ici on libère les directs de l'inode */ free_blocs(inode.direct,NDIRECT); if(inode.indirect) { /* si c'est différent de zéro = il existe */ unsigned int bloc[NBPB]; read_blocn(current_volume,inode.indirect,(unsigned char *)bloc,NBPB*sizeof(unsigned)); free_blocs(bloc,NBPB); free_bloc(inode.indirect); } if(inode.two_indirect) { read_blocn(current_volume, inumber, (unsigned char *)inode.two_indirect,NBPB*sizeof(unsigned)); for(i = 0; i < NBPB; i++) { unsigned int tmp[NBPB]; read_blocn(current_volume, inode.two_indirect, (unsigned char *)tmp,NBPB*sizeof(unsigned)); free_blocs(tmp, NBPB); } free_bloc(inode.two_indirect); //free_blocs(inode,NBPB); } free_bloc(inode.two_indirect); free_bloc(inumber); return inumber; }
/*Delete a inode in the memory*/ int delete_inode(unsigned int inumber) { /*Free the direct blocs*/ int i; struct inode_s inode; read_inode(inumber,&inode); free_blocs(inode.direct,NDIRECT); /*Free the indirect blocs if needed*/ if(inode.indirect) { unsigned bloc[NBBLOCPARBLOC]; read_nbloc(CURRENT_VOLUME,inode.indirect, (unsigned char *) &bloc, NBBLOCPARBLOC*sizeof(unsigned)); free_blocs(bloc,NBBLOCPARBLOC); free_bloc(inode.indirect); } /*Free the double indirect blocs if needed*/ if(inode.two_indirect) { unsigned bbloc[NBBLOCPARBLOC]; read_nbloc(CURRENT_VOLUME,inode.two_indirect,(unsigned char *) &bbloc,NBBLOCPARBLOC*sizeof(unsigned)); for(i=0; i<NBBLOCPARBLOC; i++) { if(bbloc[i]) { unsigned bbbloc[NBBLOCPARBLOC]; read_nbloc(CURRENT_VOLUME,inode.indirect,(unsigned char *) &bbbloc, NBBLOCPARBLOC*sizeof(unsigned)); free_blocs(bbbloc,NBBLOCPARBLOC); free_bloc(bbloc[i]); } } free_bloc(inode.two_indirect); } /*Free the bloc with the inode */ free_bloc(inumber); return 1; }
int delete_inode(unsigned int inumber) { struct inode_s inode; read_inode(inumber, &inode); free_blocs(inode.blocs_directs, NB_DIRECTS); unsigned int bloc[NB_BLOCS_BY_BLOC]; /* A voir si utile */ int i; if(inode.blocs_indirect) { read_bloc(current_volume, inumber, (unsigned char *)inode.blocs_indirect); free_blocs(inode.blocs_directs, NB_BLOCS_BY_BLOC); free_bloc(inode.blocs_indirect); } if(inode.blocs_double_indirect) { read_bloc(current_volume, inumber, (unsigned char *)inode.blocs_double_indirect); for(i = 0; i < NB_BLOCS_BY_BLOC; i++) { unsigned int tmp[NB_BLOCS_BY_BLOC]; read_bloc(current_volume, inode.blocs_double_indirect, (unsigned char *)tmp); free_blocs(tmp, NB_BLOCS_BY_BLOC); free_bloc(inode.blocs_double_indirect); } free_blocs(bloc, NB_BLOCS_BY_BLOC); } free_bloc(inode.blocs_double_indirect); free_bloc(inumber); return inumber; }
int main() { unsigned int cpt = 0, i; /* init hardware */ if(!init_hardware(HW_CONFIG)){ perror("Initialization error\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<16; i++) IRQVECTOR[i] = empty_it; /* Allows all IT */ _mask(1); /* chargement du mbr */ if(!load_mbr()){ perror("Erreur lors du chargement du Master Boot Record."); exit(EXIT_FAILURE); } /* creation d'un volume bidon */ if(!make_vol(1, 1, 10)) { perror("Erreur a la creation d'un volume bidon."); exit(EXIT_FAILURE); } /* initialise le super du premier volume */ init_super(CURRENT_VOLUME); /* charge le super du premier volume dans la variable globale */ load_super(CURRENT_VOLUME); /* creation de nouveau bloc jusqu'a ce qu'il y est une erreur */ while(new_bloc()); if(is_full()) { free_bloc(2); free_bloc(5); free_bloc(6); printf("nombre de bloc libre = %d\n", get_nb_free_bloc()); while(new_bloc()) cpt++; printf("le nombre de bloc alloué est %d\n", cpt); } else { printf("le disque n'est pas encore rempli\n"); } exit(EXIT_SUCCESS); }
int main(int argc, char** argv) { int i,volume,bloc,res; if (argc != 3){ printf("Usage:\n\tnew_bloc <volume> <bloc>\n"); exit(0); } volume = atoi(argv[1]); bloc = atoi(argv[2]); // Initialisation assert(init_hardware(HARDWARE_INI)); for(i = 0; i < 15; i++) IRQVECTOR[i] = empty_it; load_mbr(); if (volume < 0 || volume >= mbr.nb_vol){ printf("Le volume %d n'existe pas.\n",volume); exit(0); } if (bloc < 0 || bloc >= mbr.vol[volume].size){ printf("Le bloc %d n'est pas présent dans le volume %d\n",bloc,volume); exit(0); } load_super(volume); if (free_bloc(bloc) != 0) { fprintf(stderr, "Impossible de libérer le bloc %d du volume %d.\n",bloc, volume ); } else { printf("Volume %d, bloc %d libéré.\n",volume, bloc ); } return 0; }
void test_superbloc(){ int i=0; execute("list"); printf("Choisir le volume sur lequel nous allons effectuer les opérations: "); scanf("%d", ¤t_vol); current_vol=current_vol-1; //current_vol=1; if(current_vol == 0 && mbr.nbr_volumes == 0){ printf("Erreur il n'y a pas de volume, veuillez en créer un avant\n"); return; } if( load_super(current_vol) == 1 ){ printf("Chargement de Super réussi !\n"); } else printf("Chargement de Super: FAIL\n"); printf("Size: %d", mbr.disque[current_vol].size); for(i=0; i<5; i++){ printf("\ni = %d", i); printf("\tfirst-free-bloc: %d", current_super.super_first_free_bloc); printf("\tnb_free: %d\n", current_super.super_nb_free); new_bloc(); } i=10; for(i=10; i<15; i++){ printf("\ni = %d", i); printf("\tfirst-free-bloc: %d", current_super.super_first_free_bloc); printf("\tnb_free: %d\n", current_super.super_nb_free); free_bloc(i); } }
void free_blocs(unsigned int *bloc, unsigned int n) { int i; for(i=0; i < n ; i++) { if(bloc[i]){ free_bloc(bloc[i]); } } }
void free_blocs(unsigned *blocs, unsigned int size) { int i; for(i=0; i<size; i++) { if(blocs[i]) { free_bloc(blocs[i]); } } }
int delete_inode(unsigned int inumber) { struct inode_s inode; unsigned int buffer_indirect_1[SECTOR_SIZE]; unsigned int buffer_indirect_2[SECTOR_SIZE]; unsigned int i; PRINT_ASSERT_ERROR_MSG(inumber != BLOC_NULL, "Null inode (delete_inode)"); read_inode(inumber, &inode); /* Direct */ free_bloc_array(inode.inode_direct_bloc, NB_DIRECT_BLOC); /* Indirect 1 */ if(inode.inode_indirect_1 != BLOC_NULL) { read_bloc(current_vol, inode.inode_indirect_1, (unsigned char*)buffer_indirect_1); free_bloc_array(buffer_indirect_1, NB_INDIRECT_BLOC); free_bloc(inode.inode_indirect_1); } /* Indirect 2 */ if(inode.inode_indirect_2 != BLOC_NULL) { read_bloc(current_vol, inode.inode_indirect_2, (unsigned char*)buffer_indirect_2); for(i=0; i<NB_INDIRECT_BLOC; i++) { if(buffer_indirect_2[i] != BLOC_NULL) { read_bloc(current_vol, buffer_indirect_2[i], (unsigned char*)buffer_indirect_1); free_bloc_array(buffer_indirect_1, NB_INDIRECT_BLOC); free_bloc(buffer_indirect_2[i]); } } free_bloc(inode.inode_indirect_2); } free_bloc(inumber); return RETURN_SUCCESS; }
int main(int argc, char **argv) { uint volume; init_hard(); if(argc < 2){ printf("exe: ./create_bloc volume\n"); printf("On which volume: "); scanf("%d", &volume); } else { volume = atoi(argv[1]); } assert(volume < MAX_VOL); if(load_mbr() == 1){ printf("Okay, partition ready to be use\n"); } else { printf("Partition not initialized.. Now it is !"); } info_on_volume_to_display(volume); if(load_super(volume) == 1){ printf("Okay, superbloc of volume n°%d loaded\n", volume); } else { printf("Superbloc not initialized.. :(\n"); } while (superbloc.nb_free != 0) { printf("New bloc: %d\n", new_bloc()); } printf("There is no more freebloc available... :(\n"); while (mbr.vol[volume].nb_bloc-1 != superbloc.nb_free) { printf("free_bloc(%d)\n", (mbr.vol[volume].nb_bloc-1) - superbloc.nb_free); free_bloc((mbr.vol[volume].nb_bloc-1) - superbloc.nb_free); } save_super(); save_mbr(); printf("All blocs are now available and free. :)\n"); info_on_volume_to_display(volume); return 0; }
int delete_inode(unsigned int inumber) { free_blocs(unsigned int bloc[],unsigned int n); // free_blocs(ine.indirect_direct,indirect); whaaat ? if(inode.inode_indirect) { unsigned bloc[NBPB]; read_blocn(inode.indirect,bloc,NBPB*sizeof(unsigned)); free_blocs(bloc,&NBPB); free_bloc(inode.indirect); } if(inode.two_indirect) { read_blocn(current_vol, inumber, (unsigned char *)inode.two_indirect); for(i = 0; i < NBPB; i++) { unsigned int tmp[NBPB]; read_blocn(current_vol, inode.two_indirect, (unsigned char *)tmp); free_blocs(tmp, NBPB); free_bloc(inode.two_indirect); } free_blocs(bloc, NB_BLOCS_BY_BLOC); } free_bloc(inode.two_indirect); free_bloc(inumber); return inumber; }
int main(int argc, char** argv) { /* Variable declaration */ unsigned char* buffer; int free_size = 0, count = 0, i, j; /* Variable initialization */ srand(time(NULL)); buffer = (unsigned char*) malloc(HDA_SECTORSIZE * sizeof(unsigned char)); /* Check the usage of the main program */ cmdname = argv[0]; processtype = argv[1]; if (argc == 1) { usage(); return EXIT_FAILURE; } /* Only disk creation */ if(strcmp(processtype, "mkhd") == 0) { /* Delete the old disks */ remove("vdiskA.bin"); remove("vdiskB.bin"); /* New disk initialization */ init_master(); printf("The disks have been successfully created.\n"); return EXIT_SUCCESS; } /* Disk initialization */ init_master(); /* Load master boot record and partition information */ load_mbr(); init_volume(); /* Get the status of the disk (free space) */ if (strcmp(processtype, "status") == 0) { if (!load_super(CURRENT_VOL)) { fprintf(stderr, "No file system on the chosen partition\n"); return EXIT_FAILURE; } printf("Space status of the volume : %s \n", current_super.super_name); free_size = mbr.mbr_vol[CURRENT_VOL].vol_n_sector - 1; double percent = (current_super.super_nb_free / (double) free_size) * 100; printf("Free space : %f %\n", percent); printf("Free blocs : %d\n", current_super.super_nb_free); return EXIT_SUCCESS; } /* Fill the partition */ if (strcmp(processtype, "debug_fill") == 0) { printf("Filling the current partition\n"); if (!load_super(CURRENT_VOL)) { fprintf(stderr, "No file system on the chosen partition\n"); return EXIT_FAILURE; } int b; do { b = new_bloc(); if(b != BLOC_NULL) { count++; printf("."); fflush(stdout); } } while (b != 0); printf("\n"); printf("Number of allocated blocs : %d\n", count); return EXIT_SUCCESS; } /* Random free of the partition */ if (strcmp(processtype, "debug_free") == 0) { unsigned size = mbr.mbr_vol[CURRENT_VOL].vol_n_sector - 1; unsigned begin = mbr.mbr_vol[CURRENT_VOL].vol_first_sector; int it = begin + size; int n; count = 0; if (!load_super(CURRENT_VOL)) { fprintf(stderr, "No file system on the chosen partition\n"); return EXIT_FAILURE; } /* Check if the partition is empty */ if(current_super.super_nb_free == size) { fprintf(stderr, "No bloc to free, the current partition is empty.\n"); return EXIT_FAILURE; } /* Random free of the partition blocs */ for (n = begin; n < it / 10; n++) { int random = rand() % it; if(random == 0) continue; free_bloc(random); printf("%d\n", random); count++; } printf("Number of desallocated blocs : %d\n", count); return EXIT_SUCCESS; } /* Make a new filesystem */ if (strcmp(processtype, "mknfs") == 0) { init_super(CURRENT_VOL); printf("A new file system has been successfully installed on the current partition N°%d.\n", CURRENT_VOL); return EXIT_SUCCESS; } /* Process to format the entire disk */ if (strcmp(processtype, "frmt") == 0) { for (i = 0; i < HDA_MAXCYLINDER; i++) { for (j = 0; j < HDA_MAXSECTOR; j++) { format_sector(i, j, HDA_SECTORSIZE, 0); } } printf("The entire disk has been successfully formated.\n"); return EXIT_SUCCESS; } /* Process to dump the content of the first sector */ if (strcmp(processtype, "dmps") == 0) { read_sector_n(0, 0, HDA_SECTORSIZE, buffer); dump(buffer, HDA_SECTORSIZE, 0, 1); return EXIT_SUCCESS; } /* Process type unknown */ usage(); return EXIT_FAILURE; }
/*free tsize bloc(s)*/ void free_blocs(unsigned tbloc[], unsigned tsize){ int i; for(i=0; i<tsize; i++){ free_bloc(tbloc[i]); } }