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) { 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); } }
// Superbloc void init_super(uint vol, char *nom) { // read_bloc_n(vol, 0, (uchar *) &superbloc, sizeof(struct superbloc_s)); load_super(vol); if(superbloc.magic == MAGIC_SUPERBLOC){ printf("Wait, superbloc already initialized :)\n"); exit(EXIT_FAILURE); } else { superbloc.magic = MAGIC_SUPERBLOC; strcpy(superbloc.nom, nom); superbloc.first_free_bloc = 1; superbloc.root = 0; superbloc.nb_free = mbr.vol[vol].nb_bloc-1; int i = 0; for(i = 1; i<mbr.vol[vol].nb_bloc; i++) { struct free_bloc_s fb; if(i == mbr.vol[vol].nb_bloc-1) fb.next_free_bloc = 0; else fb.next_free_bloc = i+1; write_bloc_n(vol, i, (uchar *) &fb, sizeof(struct free_bloc_s)); } save_super(); } }
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 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; }
/* load super bloc of the $CURRENT_VOLUME set current_volume accordingly */ static void load_current_volume () { char* current_volume_str; int status; current_volume_str = getenv("CURRENT_VOLUME"); ffatal(current_volume_str != NULL, "no definition of $CURRENT_VOLUME"); errno = 0; current_volume = strtol(current_volume_str, NULL, 10); ffatal(!errno, "bad value of $CURRENT_VOLUME %s", current_volume_str); status = load_super(current_volume); ffatal(!status, "unable to load super of vol %d", current_volume); }
void main () { int err; while (1) { /* puts ("C="); word_hex (track_max); puts (" H="); word_hex (head_max); puts (" S="); word_hex (sect_max); puts ("\r\n"); */ err = load_super (); /* if (err) { //log_err ("load_super"); break; } */ /* puts ("inodes="); word_hex (sb_data->s_ninodes); puts (" zones="); word_hex (sb_data->s_nzones); puts ("\r\n"); */ load_file (); for (int d = 0; d < i_data->i_size; d += DIRENT_SIZE) { if (!strcmp (d_dir + 2 + d, "linux")) { //puts ("Linux found\r\n"); i_now = (*(int *)(d_dir + d)) - 1; load_file (); run_prog (); break; } } break; } }
int init_super(const char *dev_name) { int fd; if ((vbfs_superblock_disk = Valloc(VBFS_SUPER_SIZE)) == NULL) goto err; memset(vbfs_superblock_disk, 0, VBFS_SUPER_SIZE); fd = open(dev_name, O_RDWR | O_DIRECT | O_LARGEFILE); if (fd < 0) { fprintf(stderr, "open %s error, %s\n", dev_name, strerror(errno)); goto err; } init_vbfs_ctx(fd); if (read_from_disk(fd, vbfs_superblock_disk, VBFS_SUPER_OFFSET, VBFS_SUPER_SIZE)) goto err; if (load_super()) goto err; vbfs_ctx.super.s_mount_time = time(NULL); vbfs_ctx.super.s_state = MOUNT_DIRTY; vbfs_ctx.super.super_vbfs_dirty = SUPER_DIRTY; vbfs_ctx.super.inode_offset = vbfs_ctx.super.extend_bitmap_offset + vbfs_ctx.super.extend_bitmap_count; vbfs_ctx.super.inode_extends = ((__u64)vbfs_ctx.super.s_inode_count * INODE_SIZE) / vbfs_ctx.super.s_extend_size; /* bad extend init */ if (init_bad_extend()) goto err; /* calculate free extend */ /* */ return 0; err: return -1; }
/** Affiche les informations du disque courrant **/ void info_on_volume_to_display(int volume) { load_super(volume); struct volume_s vol = mbr.vol[volume]; printf("\n----------------------------------------------------------------------\n"); printf("Volume n°%d\n", volume); printf("Cylinder n°%d\tSector n°%d\n", vol.first_cylinder, vol.first_sector); printf("Number of bloc: %d\t", vol.nb_bloc); printf("Number freebloc: %d\n", superbloc.nb_free); display_space_on_volume(); if(vol.type == BASE) printf("Type: Base\n"); else if(vol.type == ANNEXE) printf("Type: Annex\n"); else if(vol.type == AUTRE) printf("Type: Other\n"); else printf("Type: Unknown\n"); printf("----------------------------------------------------------------------\n"); }
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; }