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; }
int main(int argc, char const *argv[]) { unsigned int i; unsigned int inumber; if (argc < 2) { printf("Usage : if_delete [inumber] -> supprimer l'inode de numero [inumber] et renvoi OK ou KO\n"); return EXIT_FAILURE; } /* init hardware */ if(init_hardware("hardware.ini") == 0) { fprintf(stderr, "Error in hardware initialization\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<16; i++) { IRQVECTOR[i] = empty_it; } /* Allows all IT */ _mask(1); printf("Loading Master Boot Record...\n"); load_mbr(); load_super(0); inumber = atoi(argv[1]); delete_ifile(inumber, 0); return EXIT_SUCCESS; }
int main(int argc, char**argv){ unsigned int i; unsigned int inumber = 0; file_desc_t fd; /* gestion des arguments */ if(argc!=3){ usage(); exit(EXIT_SUCCESS); } inumber = atoi(argv[1]); if(inumber==0){ usage(); exit(EXIT_FAILURE); } /* init hardware */ if(!init_hardware(HW_CONFIG)) { fprintf(stderr, "Initialization error\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<NB_EMPTY_FUNCTION; i++) IRQVECTOR[i] = empty_it; /* Allows all IT */ _mask(1); /* chargement du mbr */ if(!load_mbr()){ fprintf(stderr, "Erreur lors du chargement du Master Boot Record.\n"); 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); /* manipulation du fichier */ if(open_ifile(&fd, inumber) == RETURN_FAILURE){ fprintf(stderr, "Erreur lors de l'ouverture du fichier\n"); exit(EXIT_FAILURE); } if(write_ifile(&fd, argv[2], strlen(argv[2])+1) == RETURN_FAILURE){ fprintf(stderr, "Erreur lors de l'ecriture dans le fichier\n"); exit(EXIT_FAILURE); } flush_ifile(&fd); close_ifile(&fd); exit(EXIT_SUCCESS); }
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 create_volume(unsigned int cylinder, unsigned int sector, int size, enum vol_type_e type){ int i,l; unsigned int cyl_target, sec_target; struct volume_s vol; char name[MAX_TAILLE]; load_mbr(); if (mbr.nb_vol >= MAX_VOL){ fprintf(stderr,"Error: Reached maximum number of volume.\n"); return -1; } if (cylinder >= HDA_MAXCYLINDER){ fprintf(stderr,"Error: Specified cylinder is too high.\n"); return -1; } if (sector >= HDA_MAXSECTOR){ fprintf(stderr,"Error: Specified sector is too high.\n"); return -1; } cyl_target = cylinder + ((sector+size) / HDA_MAXSECTOR); sec_target = ((sector+size) % HDA_MAXSECTOR) -1; if (cyl_target >= HDA_MAXCYLINDER){ fprintf(stderr,"Error: Specified size is too high.\n"); return -1; } for (i = 0,l = mbr.nb_vol; i < l; i++) { unsigned int cyl_target_i, sec_target_i; cyl_target_i = mbr.vol[i].cylinder + ((mbr.vol[i].sector+mbr.vol[i].size)/ HDA_MAXSECTOR); sec_target_i = ((mbr.vol[i].sector+mbr.vol[i].size) % HDA_MAXSECTOR) - 1; if (!((cylinder == mbr.vol[i].cylinder && size <= (mbr.vol[i].sector - sector)) || (cyl_target < mbr.vol[i].cylinder) || (cylinder > cyl_target_i) || (cyl_target == mbr.vol[i].cylinder && sec_target < mbr.vol[i].sector) || (cylinder == cyl_target_i && sector > sec_target_i))) { fprintf(stderr, "Error: specified cylinder and sector values will overlap existing volume\n"); return -1; } } vol.cylinder = cylinder; vol.sector = sector; vol.size = size; vol.type = type; mbr.vol[mbr.nb_vol] = vol; mbr.nb_vol++; save_mbr(); sprintf(name, "Volume %d [%d,%d,%d]", (mbr.nb_vol-1),cylinder,sector,size); if (init_super(mbr.nb_vol-1,name)){ printf("%s initialisé\n", name); } printf("Volume %d de taille %d créé (début [%d,%d], fin [%d,%d]).\n",(mbr.nb_vol-1),size,cylinder,sector,cyl_target,sec_target); return (mbr.nb_vol-1); }
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 main(int argc, char**argv){ unsigned int i; unsigned int inumber; /* gestion des arguments */ if(argc != 1){ usage(); exit(EXIT_SUCCESS); } /* init hardware */ if(!init_hardware(HW_CONFIG)) { fprintf(stderr, "Initialization error\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<NB_EMPTY_FUNCTION; i++) IRQVECTOR[i] = empty_it; /* Allows all IT */ _mask(1); /* chargement du mbr */ if(!load_mbr()){ fprintf(stderr, "Erreur lors du chargement du Master Boot Record.\n"); 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); /* création du fichier */ inumber = create_ifile(IT_FILE); if(!inumber){ fprintf(stderr, "Erreur lors de la creation du fichier\n"); exit(EXIT_FAILURE); } printf("Création d'un fichier:\n"); printf("\tinumber: %d.\n", inumber); exit(inumber); }
int main(int argc, char const *argv[]) { unsigned int i; unsigned int inumber; char line[LINE_SIZE]; struct file_desc_t fd; if (argc < 2) { printf("Usage : if_copy [inumber] -> ecrit le contenu de l'entrée standard dans l'inode de numero [inumber]\n"); return EXIT_FAILURE; } /* init hardware */ if(init_hardware("hardware.ini") == 0) { fprintf(stderr, "Error in hardware initialization\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<16; i++) { IRQVECTOR[i] = empty_it; } /* Allows all IT */ _mask(1); printf("Loading Master Boot Record...\n"); load_mbr(); load_super(0); inumber = atoi(argv[1]); open_ifile(&fd, inumber, 0); while (fgets(line, LINE_SIZE, stdin) != NULL) { write_ifile(&fd, line, strlen(line), 0); } close_ifile(&fd, 0); return EXIT_SUCCESS; }
int main(int argc, char**argv){ unsigned int i; unsigned fc = 0; unsigned fs = 1; unsigned nb_bloc = 10; /* init hardware */ if(!init_hardware(HW_CONFIG)) { fprintf(stderr, "Initialization error\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<NB_EMPTY_FUNCTION; i++) IRQVECTOR[i] = empty_it; /* Allows all IT */ _mask(1); /* chargement du mbr */ if(!load_mbr()){ fprintf(stderr, "Erreur lors du chargement du Master Boot Record.\n"); exit(EXIT_FAILURE); } if(mbr.mbr_n_vol < 1) { /* creation d'un volume bidon */ if(!make_vol(fc, fs, nb_bloc)) { fprintf(stderr, "Erreur a la creation d'un volume bidon.\n"); exit(EXIT_FAILURE); } /* initialise le super du volume 1 */ init_super(CURRENT_VOLUME); printf("Le volume principale a été créé avec succès.\n"); /* sauvegarde de tous les changements effectué sur le mbr */ save_mbr(); } else { printf("Le volume principale a déjà été créé!\n"); } exit(EXIT_SUCCESS); }
int main(int argc, char **argv){ uint size, type_no; enum type_e type; init_hard(); if(argc < 2){ printf("exe: ./create_vol size\n"); printf("Volume' size: "); scanf("%d", &size); } else { size = atoi(argv[1]); } printf("Choose the type of the new volume: \n"); printf("\tBASIC --> 0\n\tANNEX --> 1\n\tOTHER --> 2\nType: "); scanf("%d", &type_no); if(type_no == 0) type = BASE; else if(type_no == 1) type = ANNEXE; else type = AUTRE; 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(0); assert(mbr.nb_vol < MAX_VOL); if(create_new_volume(size, type) != 0 ) printf("New volume correctly created\n"); else printf("Impossible to create the new volume...\n"); displayAllVolume(); save_mbr(); return 0; }
/* ------------------------------ Initialization and finalization fucntions ------------------------------------------------------------*/ void mount() { char *hw_config; int status, i; /* Hardware initialization */ hw_config = get_hw_config(); status = init_hardware(hw_config); ffatal(status, "error in hardware initialization with %s\n", hw_config); /* Interrupt handlers */ for(i=0; i<16; i++) IRQVECTOR[i] = emptyIT; /* Allows all IT */ _mask(1); /* Load MBR and current volume */ load_mbr(); load_current_volume(); }
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; }
int main(int argc, char** argv){ int v, first_cylinder, first_sector, n_block; unsigned int i; /* init hardware */ if(init_hardware("hardware.ini") == 0) { fprintf(stderr, "Error in hardware initialization\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<16; i++) { IRQVECTOR[i] = empty_it; } /* Allows all IT */ _mask(1); if ( argc < 5 ){ printf("Usage : mkvol vol_name first_cylinder first_sector nb_block [-tother, -tannexe]\n"); return EXIT_FAILURE; } first_cylinder = atoi(argv[2]); first_sector = atoi(argv[3]); n_block = atoi(argv[4]); if ( atoi(argv[2])==0 && atoi(argv[3])==0 ){ printf("Cannot create volume at Master Boot Record position.\n"); return EXIT_FAILURE; } printf("Loading Master Boot Record...\n"); load_mbr(); if ( mbr.n_vol >= MAX_VOL ){ printf("Hard drive already has 8 volumes, please delete at least one volume before creating new one.\n"); return EXIT_FAILURE; } first_cylinder = atoi(argv[2]); check_before_create(atoi(argv[2]), atoi(argv[3]), atoi(argv[4])); v = mbr.n_vol; mbr.vol[v].first_cylinder = first_cylinder; mbr.vol[v].first_sector = first_sector; mbr.vol[v].n_block = n_block; printf("Creating volume %d...\n", v); mbr.vol[v].type = BASE; if ( argc == 5 ){ if ( strcmp(argv[4], "-tother") == 0){ mbr.vol[v].type = OTHER; } if ( strcmp(argv[4], "-tannexe") == 0){ mbr.vol[v].type = ANNEXE; } } srand((unsigned)time(NULL)); init_super(v, argv[1], rand(), n_block); mbr.n_vol++; save_mbr(); save_super(v); printf("Volume %d created.\n", v); return EXIT_SUCCESS; }