Beispiel #1
0
void format_all(const unsigned int value){

  unsigned int i, j;

  for(i=0; i<HDA_MAXCYLINDER; i++){
    for(j=0; j<HDA_MAXSECTOR; j++){
      format_sector(i, j, 0, value);
    }
  }
}
Beispiel #2
0
void format_vol(const unsigned int vol) {

  unsigned int secteur, cylindre;
  unsigned int fs, fc, nb_bloc;
  int i;

  fs = mbr.mbr_vol[vol].vol_first_sector;
  fc = mbr.mbr_vol[vol].vol_first_cylinder;
  nb_bloc = mbr.mbr_vol[vol].vol_n_sector;

  for(i=0; i<nb_bloc; i++){

    /* passage de cylindre a volume et de secteur a bloc */
    secteur = (fs + i) % HDA_MAXSECTOR;
    cylindre = fc + (fs + i) / HDA_MAXSECTOR;

    /* revoir la valeur a mettre dans le dernier parametre */
    format_sector(cylindre, secteur, 1, 0);

  }
}
int main(){
	int nbSec,nbCyl,cylinder,secteur,i;
	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);
	_out(HDA_CMDREG,CMD_DSKINFO);
	nbCyl=_in(HDA_DATAREGS)<<8;
	nbCyl+=_in(HDA_DATAREGS+1);
	nbSec=_in(HDA_DATAREGS+2)<<8;
	nbSec+=_in(HDA_DATAREGS+3);
	printf("Formatage du disque\n");
	for(cylinder=0;cylinder<nbCyl;cylinder++)
		for(secteur=0;secteur<nbSec;secteur++)
			format_sector(cylinder,secteur,1,0);
	return 0;
} 
Beispiel #4
0
void format_bloc(uint vol, uint nbloc, uint value) {
    uint cylinder = cylinder_of_bloc(vol, nbloc);
    uint sector = sector_of_bloc(vol, nbloc);
    format_sector(cylinder, sector, value);
}
Beispiel #5
0
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;

}
Beispiel #6
0
Datei: vol.c Projekt: dtbinh/m1s1
void format_block(int vol, int block, int value){
  format_sector(cylinder_of_block(vol, block),
        sector_of_block(vol, block),
        value);
  return;
}