示例#1
0
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);
}
示例#2
0
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);
}
示例#3
0
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);
}
示例#4
0
文件: volume.c 项目: DherJ/Master1
int create_new_volume(uint size, enum type_e type) {
    if(mbr.nb_vol +1 >= MAX_VOL) {
        printf("Stop, max number of volumes reached\n");
        return 0;
    }
    struct volume_s new_vol;
    uchar sectors[HDA_MAXCYLINDER][HDA_MAXSECTOR] = {{0}};
    char name_superbloc[32], number_superbloc[5];
    uint i, j, cyl, sect, nbFree = 0;
    // Put the sectors already use to 1
    // MBR
    sectors[0][0] = 1;
    for (i = 0; i < mbr.nb_vol; i++) {
        for (j = 0; j < mbr.vol[i].nb_bloc; j++) {
            cyl = cylinder_of_bloc(i, j);
            sect = sector_of_bloc(i, j);
            sectors[cyl][sect] = 1;
        }
    }

    // Looking for space to insert the new volume
    for(i = 0; i<(HDA_MAXCYLINDER*HDA_MAXSECTOR); i++) {
        cyl = i / HDA_MAXSECTOR;
        sect = i % HDA_MAXSECTOR;
        
        // If free
        if(sectors[cyl][sect] == 0)
            nbFree ++;
        
        // If there is enought memory to insert our new volume
        if(nbFree >= size) {
            // Go back to the start of the free space
            cyl = (i-(size-1)) / HDA_MAXSECTOR;
            sect = (i-(size-1)) % HDA_MAXSECTOR;
            
            new_vol.first_cylinder = cyl;
            new_vol.first_sector = sect;
            new_vol.nb_bloc = size;
            new_vol.type = type;
            mbr.vol[mbr.nb_vol] = new_vol;
            (mbr.nb_vol)++;
            strcat(name_superbloc, "SUPERBLOC-");
            sprintf(number_superbloc, "%d", mbr.nb_vol-1);
            strcat(name_superbloc, number_superbloc);
            init_super(mbr.nb_vol-1, name_superbloc);
            return 1;
        }
    }
    return 0;
}
示例#5
0
文件: mkfile.c 项目: agoryu/ASE
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);
}
示例#6
0
文件: mknfs.c 项目: agoryu/systeme
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);
}
示例#7
0
文件: mkgfs.c 项目: Arseny-N/fgfs
int main ( int argc, char * argv [] )
{
	struct gfs_super *super;
	struct conf conf;
	int super_len, i;
	
	prase_cmdLine(&conf, argv, argc);
	init_conf(&conf);	
	super_len = init_super(&conf, &super);
	
	write_inode(&conf, 0, super, super_len, S_IFREG | 0777);
	write_inode(&conf, 1, NULL, 0, S_IFDIR | 0777);
	for( i = 0;i < conf.nblocks; i++)
		write_inode(&conf, i+2, NULL, 0, 0);
		
	printf("Created fs in file %s.\n%ld blocks with bs %d.\nTotal size %ld bytes.\n",
			conf.fname, conf.nblocks, conf.block_size, conf.nblocks*conf.block_size);	
	return 0;
}
示例#8
0
int main(int argc, char **argv)
{
    int ret = 0;
    int i_argc;
    char **s_argv;

    if (argc < 3) {
        fprintf(stderr, "argument error: %s <mountpoint> [options] <device>\n", argv[0]);
        exit(1);
    }

    log_init();

    ret = init_super(argv[argc - 1]);
    if (ret < 0) {
        fprintf(stderr, "Invalidate filesystem\n");
        exit(1);
    }

    i_argc = argc - 1;
    s_argv = argv;
    s_argv[argc - 1] = NULL;

    ctx_equeue_init();

    ret = init_root_inode();
    if (ret < 0) {
        fprintf(stderr, "root inode init error\n");
        exit(1);
    }
    vbfs_init_bitmap();

    ret = fuse_main(i_argc, s_argv, &vbfs_op, NULL);
    log_err("fuse_main end\n");

    return ret;
}
示例#9
0
文件: mknfs.c 项目: Levrifon/ASE
int main(){
	int vol;
	int nom;
	int nbblocs;
	int i;
	unsigned int test_serial = 0xDEADBEEF;
        init_drive();
	read_mbr();
	dump_vols();

	printf("Saisir le numero du volume:\n");
	scanf("%i", &vol);
	while (mbr.mbr_vol[vol].vol_nblocs == 0){
		printf("Veuillez saisir un  numero de volume valide:\n");
		scanf("%i", &vol);
	}
	printf("Saisir le nom:\n");
	scanf("%i", &nom);
	init_super(vol, nom, test_serial);

	printf("Saisir le nombre de blocs:\n");
	scanf("%i", &nbblocs);

	for (i=0; i<nbblocs; i++){
		new_bloc();
	}

	save_super();
	if (nbblocs > mbr.mbr_vol[vol].vol_nblocs-1){
		nbblocs = mbr.mbr_vol[vol].vol_nblocs-1;
	}
	printf("Superbloc rempli de %d blocs !\n", nbblocs);
	printf("Taux d'occupation : %f/100\n", used_percents(vol));

	return 0;
}
示例#10
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;

}
示例#11
0
文件: mkvol.c 项目: dtbinh/m1s1
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;
}