Ejemplo n.º 1
0
int add_entry(int inumber, const char* name, enum file_type_e type) {
    file_desc_t fd;

    if(strcmp(name, "") == 0) {
        return -1;
    }

    

    if(open_ifile(&fd, inumber) != RETURN_FAILURE) {
        struct entry_s entry;

        if(find_entry(&fd, name) != -1) {
            return -1;
        }

        unsigned int index = new_entry(&fd);

        seek2_ifile(&fd, index*sizeof(struct entry_s));

        entry.inumber = create_ifile(type);

        strncpy(entry.name, name, MAX_FILE_LENGTH);

        write_ifile(&fd, &entry, sizeof(struct entry_s));

        close_ifile(&fd);

        //add .. & .
        if(type == FILE_DIRECTORY) {
            file_desc_t fd_child;
            struct entry_s entry_child;

            if(open_ifile(&fd_child, entry.inumber) != RETURN_FAILURE) {
                entry_child.inumber = entry.inumber;
                strcpy(entry_child.name, ".");
                write_ifile(&fd_child, &entry_child, sizeof(struct entry_s));

                entry_child.inumber = inumber;
                strcpy(entry_child.name, "..");
                write_ifile(&fd_child, &entry_child, sizeof(struct entry_s));

                close_ifile(&fd_child);
            }
        }

        return entry.inumber;
        
    }
    else
        return -1;
    
}
Ejemplo n.º 2
0
int del_entry(int idir, const char* name) {
    int ret;    
    struct entry_s entry;
    file_desc_t fd;

    open_ifile(&fd, idir);

    ret = find_entry(&fd, name);

    if(ret < 0) {
        return -1;
    }

    seek2_ifile(&fd, ret*sizeof(struct entry_s));

    if(read_ifile(&fd, &entry, sizeof(struct entry_s)) <= 0) {
        return -1;
    }

    delete_ifile(entry.inumber);

    entry.inumber = 0;

    seek2_ifile(&fd, ret*sizeof(struct entry_s));

    if(write_ifile(&fd, &entry, sizeof(struct entry_s)) <= 0) {
        return -1;
    }

    close_ifile(&fd);

    return 0;
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
0
unsigned int new_entry(file_desc_t* dir_fd) {
    struct entry_s entry;
    int cursor;

    do {
        
        if(dir_fd->fds_pos >= dir_fd->fds_size) {
            break;
        }

        if(read_ifile(dir_fd, &entry, sizeof(struct entry_s)) <= 0) {
            break;
        }

        if(entry.inumber == 0) {
            return cursor;
        }

        cursor++;
    } while(1);

    entry.inumber = 0;
    memset(entry.name, 0, MAX_FILE_LENGTH);

    
    write_ifile(dir_fd, &entry, sizeof(struct entry_s));

    return cursor;
}
Ejemplo n.º 5
0
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;
}