예제 #1
0
/* move the cursor of offset positions. */
void 
seek_ifile(file_desc_t *fd, int offset)
{     
    unsigned int old_pos = fd->fds_pos;
    unsigned int fbloc, vbloc; 
    
    /* update the position */
    fd->fds_pos += offset;

    /* does the seek imply a jump in another bloc? */
    if (bloc_of_pos(fd->fds_pos) != bloc_of_pos(old_pos)) {
	/* flush */
	flush_ifile(fd);
    
	/* the bloc index of the new buffer */
	fbloc = bloc_of_pos(fd->fds_pos);
	vbloc = vbloc_of_fbloc(fd->fds_inumber, fbloc, FALSE);

	if (! vbloc)
	    /* the bloc #0 is full of zeros */
	    memset(fd->fds_buf, 0, BLOC_SIZE);
	else
	    /* load the bloc */
	    read_bloc(current_volume, vbloc, fd->fds_buf);
    }
}
예제 #2
0
파일: writefile.c 프로젝트: agoryu/systeme
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);
}
예제 #3
0
void
close_ifile(file_desc_t *fd)
{
    struct inode_s inode;
    
    /* if the buffer is dirty, flush the file */
    flush_ifile(fd);
    
    /* update the inode information (size) */
    read_inode(fd->fds_inumber, &inode);
    inode.ind_size = fd->fds_size;
    write_inode(fd->fds_inumber, &inode);
}