int main(int argc, char const *argv[]) { int i, s, fc, fs, res; const char * n; /* Checking arguments */ s = fc = fs = -1; n = NULL; if (argc < 5) { usage(argv[0]); } for (i = 1; i < argc; i++) { if (!strcmp("-s", argv[i])) { s = strtol(argv[++i], NULL, 10); } else if (!strcmp("-fc", argv[i])) { fc = strtol(argv[++i], NULL, 10); } else if (!strcmp("-fs", argv[i])) { fs = strtol(argv[++i], NULL, 10); } else if (!strcmp("-n", argv[i])) { n = argv[++i]; } else { usage(argv[0]); } } if (s == -1 || fc == -1) { usage(argv[0]); } /* Checking for idiotic input */ if (fc == 0 && fs == 0) { fprintf(stderr, "Wrong input: cannot write on the Master Boot Record, use other values than (0, 0).\n"); } /* Default values */ if (fs == -1) { fs = 0; } /* Start modifying the mbr */ read_mbr(); /* Creating a new volume */ res = create_volume(s, fc, fs, n); display_all_volume_name(); /* End of all modifications, saving them */ save_mbr(); return res; }
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 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; }
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; }
int main (int argc, char **argv) { int vol = VOL_DFLT, nsectors = NSECTORS_DFLT, firstcylinder = FIRST_CYLINDER_DFLT, firstsector = FIRST_SECTOR_DFLT; int i, c; cmdname = argv[0]; opterr = 0; init_mbr(); while ((c = getopt(argc, argv, "l:c:s:v:")) != -1) { switch (c) { case 'l': nsectors = atol(optarg); break; case 'c': firstcylinder = atol(optarg); break; case 's': firstsector = atol(optarg); break; case 'v': vol = atol(optarg); break; case '?': /* missing option argument */ if (optopt == 'l' || optopt == 'c' || optopt == 's') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); usage(); } else unknown_opt(optopt); default: unknown_opt(c); } } printf("b\n"); struct vol_descr_s vol_desc; for(i=0;i<vol;i++){ vol_desc.vol_cylinder=firstcylinder; vol_desc.vol_sector=firstsector; vol_desc.vol_nsector=nsectors; vol_desc.vol_voltype=VT_BASE; mbr.mbr_vols[i]= vol_desc; } mbr.mbr_magic=0xA5E; mbr.mbr_nbvol=vol; if (optind != argc) { fprintf(stderr, "Argument(s): "); for (i = optind; i < argc; i++) fprintf(stderr, "%s ", argv[i]); fprintf(stderr, "ignored.\n"); usage(); } save_mbr(); save_mbr(); printf("mkvol(vol=%d, nsectors=%d, firstcylinder=%d, firstsector=%d)\n", vol, nsectors, firstcylinder, firstsector); exit(EXIT_SUCCESS); }