Esempio 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;
    
}
Esempio 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;
}
Esempio n. 3
0
int main(int argc, char** argv) {
	int inumber;

	if(argc != 2) {
		printf("%s <absolute_path>\n", argv[0]);
		return EXIT_FAILURE;
	}

	mount();

	if((inumber = inumber_of_path(argv[1])) != 0) {
		file_desc_t fd;
		if(open_ifile(&fd, inumber) != RETURN_FAILURE) {
			struct entry_s entry;

			while(read_ifile(&fd, &entry, sizeof(struct entry_s)) > 0) {
				if(entry.inumber != 0)
					printf("%s\n", entry.name);
			}
			close_ifile(&fd);
		}
	}
	else
		 PRINT_FATAL_ERROR("Not a valid path");

	return EXIT_SUCCESS;
}
Esempio n. 4
0
unsigned int inumber_of_basename(unsigned int idir, const char* basename) {
    file_desc_t fd;
    int ret;
    unsigned int inumber;
    struct entry_s entry;
    open_ifile(&fd, idir);

    ret = find_entry(&fd, basename);

    if(ret < 0) {
        return 0;
    }

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

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

    inumber = entry.inumber;

    close_ifile(&fd);

    return inumber;
}
Esempio n. 5
0
Errcode pic_getsize(Popot path, Popot width, Popot height, Popot depth)
/*****************************************************************************
 * return the width, height, and pixel depth of a picture file.
 ****************************************************************************/
{
	Errcode err;

	if (path.pt == NULL || width.pt == NULL ||
		height.pt == NULL || depth.pt == NULL)
		return builtin_err = Err_null_ref;

	if (Success > (err = pdr_find_load(path)))
		return err;

	if (Success > (err = open_ifile(path.pt))) /* open fills in ainfo */
		return err;

	*((int *)width.pt)	= ainfo.width;
	*((int *)height.pt) = ainfo.height;
	*((int *)depth.pt)	= ainfo.depth;

	close_ifile();

	return err;
}
Esempio n. 6
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);
}
Esempio n. 7
0
Errcode pic_load(Popot path, Popot screen)
/*****************************************************************************
 * load a picture.
 ****************************************************************************/
{
	Errcode err;
	Boolean allow_retry = TRUE;

	/*------------------------------------------------------------------------
	 * if a pdr is already loaded, we will try to use it to load the picture,
	 * else we try to figure out which pdr to use and load it.
	 * if the pdr was pre-loaded and it fails to process the picture, we
	 * unload it and come back to here to figure out which pdr to use.	once
	 * we've been through the figure-it-out routine, we disable further
	 * retries; at that point we just can't find a pdr that can cope.
	 * the main point of this complicated retry stuff is to allow a poco
	 * program to preload a pdr we don't know about (and would thus never
	 * find for ourselves).
	 *----------------------------------------------------------------------*/

RETRY:

	if (pdr == NULL) {
		if (Success > (err = pdr_find_load(path)))
			return err;
		allow_retry = FALSE;
	}

	if (path.pt == NULL)
		return builtin_err = Err_null_ref;

	if (screen.pt == NULL)
		screen.pt = GetPicScreen();

	if (Success > (err = open_ifile(path.pt))) {
		if (allow_retry) {
			pdr_unload();
			goto RETRY;
		} else
			return err;
	}

	pj_set_rast((Rcel *)screen.pt,0);

	if (ainfo.depth > 8)
		err = load_rgbframe(screen.pt);
	else
		err = load_mappedframe(screen.pt);

	close_ifile();

	poePicDirtied();	/* signal to pj that we've changed the pic screen */

	return err;
}
Esempio n. 8
0
static void
cfile(unsigned int sinumber)
{
    file_desc_t sfd, dfd;
    unsigned int dinumber;
    int status;
    int c;
    
    dinumber = create_ifile(FT_STD);
    ffatal(dinumber, "erreur creation fichier");
    printf("%d\n", dinumber);

    status = open_ifile(&dfd, dinumber);
    ffatal(!status, "erreur ouverture fichier %d", dinumber);
    
    status = open_ifile(&sfd, sinumber);
    ffatal(!status, "erreur ouverture fichier %d", sinumber);

    while((c=readc_ifile(&sfd)) != READ_EOF)
        writec_ifile(&dfd, c);

    close_ifile(&dfd);
    close_ifile(&sfd);
}
Esempio n. 9
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;
}
Esempio n. 10
0
void bundle_slurp(struct para_bundle * pb, struct ifile ifi, _Bool reg)
{
	int fd = open_ifile(ifi);
	if (fd == -1) {
		record_error();
		return;
	}
	
	FSAF * f = fsaf_fdopen(fd, ifi.s);
	if (f == 0) fatal_enomem(0);

	struct srcfile * sf = malloc(sizeof *sf);
	if (sf == 0) fatal_enomem(0);

	sf->ifi = ifi;
	sf->fd = fd;
	sf->fs = f;
	sf->next = pb->files;
	pb->files = sf;

	para_parser_init(&sf->pp, f, false, false, reg);
	while (true) {
		if (pb->num_paras == pb->max_num) {
			size_t max_num = pb->max_num == 0 ? 256 :
				2 * pb->max_num;
			para_t ** paras = realloc(pb->paras,
						  max_num 
						  * sizeof *paras);
			if (paras == 0) fatal_enomem(0);
			pb->max_num = max_num;
			pb->paras = paras;
		}
		assert(pb->num_paras < pb->max_num);
		assert(pb->paras != 0);
		para_t * p = new_para(&pb->pool, &sf->pp);
		if (p == 0) fatal_enomem(0);
		para_parse_next(p);
		if (para_eof(&sf->pp)) break;
		debug("pb->num_paras = %zi", pb->num_paras);
		pb->paras[pb->num_paras++] = p;
	}

//      DO NOT CLOSE fsaf -- this makes the whole para_bundle useless!
//	fsaf_close(f);
	close_ifile(ifi, fd);
}
Esempio n. 11
0
void ref_test(const char *in_file, const unsigned int it_cnt, enum test_type t_type, AESREF alg)
{   u4byte          i, kl, test_no, cnt, e_cnt;
    u1byte          key[32], pt[16], iv[16], ect[16], act[32];
    char            str[128], tstr[16];
    int             ty;
    IFILE           inf;

    con_string("\nTest file: "); con_string(in_file); con_string("\nStatus: \n");

    if(!(inf = open_ifile(inf, in_file)))   // reference file for test vectors
    {                                       // if file is not present
        con_string("error in running test\n"); return;
    }

    cnt = 0; e_cnt = test_no = 0;

    for(;;)                         // while there are tests
    {
        ty = find_line(inf, str);   // input a line

        if(ty < 0)                  // until end of file

            break;

        switch(ty)      // process line type
        {
          case 0:   kl = get_dec(str + 8); continue;        // key length
          case 1:   test_no = get_dec(str + 2); continue;   // test number
          case 2:   block_in(iv, str + 3); continue;        // init vector
          case 3:   block_in(key, str + 4); continue;       // key
          case 4:   block_in(pt, str + 3);                  // plaintext
                    if(t_type != ecb_md && t_type != cbc_md)
                        continue;
                    break;
          case 5:   block_in(ect, str + 3);                 // ciphertext
                    if(t_type == ecb_md || t_type == cbc_md)
                        continue;
                    break;
        }

        if(serpent_hack)
        
            block_reverse(key, kl / 8);

        alg.set_key(key, kl, both); // set the key

        if(it_cnt > 100)

            OUT_DOTS(test_no);

        if(t_type == ecb_md || t_type == cbc_md)
        {
            block_copy(act, ect, 16);           // encrypted text to low block

            if(t_type == cbc_md)                // CBC Monte Carlo decryption
            {
                block_copy(act + 16, iv, 16);   // IV to high block

                for(i = 0; i < it_cnt; i += 2)  // do decryptions two at a time
                {
                    if(serpent_hack)
                
                        block_reverse(act, 16);

                    alg.decrypt(act, ect);      // decrypt low block

                    if(serpent_hack)
                    {
                        block_reverse(act, 16); block_reverse(ect, 16);

                    }

                    block_xor(act + 16, ect, 16);// xor into high block

                    if(serpent_hack)
                
                        block_reverse(act + 16, 16);

                    alg.decrypt(act + 16, ect); // decrypt high block

                    if(serpent_hack)
                    {               
                        block_reverse(ect, 16); block_reverse(act + 16, 16);
                    }

                    block_xor(act, ect, 16);    // xor into low block
                }
            }
            else    // ECB Monte Carlo decryption 
            {
                if(serpent_hack)

                    block_reverse(act, 16);

                for(i = 0; i < it_cnt; ++i)
        
                    alg.decrypt(act, act);
        
                if(serpent_hack)

                    block_reverse(act, 16);
            }

            if(!block_cmp(pt, act, 16))
            {
                con_string("\n\ndecryption error on test "); 
                put_dec(tstr, test_no); con_string(tstr); e_cnt++;
            }

            if(t_type == ecb_md)    // test encryption if ECB mode
            {
                if(serpent_hack)

                    block_reverse(act, 16);

                for(i = 0; i < it_cnt; ++i)

                    alg.encrypt(act, act); 

                if(serpent_hack)

                    block_reverse(act, 16);

                if(!block_cmp(ect, act, 16))
                {   
                    con_string("\n\nencryption error on test ");
                    put_dec(tstr, test_no); con_string(tstr); e_cnt++;
                }
            }
        }
        else    // if(t_type == ecb_me || t_type == cbc_me || ecb_vk || ecb_vt)
        {
            if(t_type == cbc_me)                        // CBC Monte Carlo encryption
            {
                block_copy(act, iv, 16); 
                block_copy(act + 16, pt, 16);           // copy IV and plaintext

                for(i = 0; i < it_cnt; i += 2)
                {
                    block_xor(act + 16, act, 16);       // xor low block into high block

                    if(serpent_hack)

                        block_reverse(act + 16, 16);

                    alg.encrypt(act + 16, act + 16);    // encrypt high block

                    if(serpent_hack)

                        block_reverse(act + 16, 16);

                    block_xor(act, act + 16, 16);       // xor high block into low block

                    if(serpent_hack)

                        block_reverse(act, 16);

                    alg.encrypt(act, act);              // encrypt low block
        
                    if(serpent_hack)

                        block_reverse(act, 16);
                }
            }
            else    // ECB Monte Carlo encryption
            {
                block_copy(act, pt, 16);

                if(serpent_hack)

                    block_reverse(act, 16);

                for(i = 0; i < it_cnt; ++i)
        
                    alg.encrypt(act, act);

                if(serpent_hack)
                
                    block_reverse(act, 16);
            }

            if(!block_cmp(ect, act, 16))
            {
                    con_string("\n\nencryption error on test ");
                    put_dec(tstr, test_no); con_string(tstr); e_cnt++;
            }
        
            if(t_type != cbc_me)    // if ECB mode test decrytpion
            {
                if(serpent_hack)
                
                    block_reverse(act, 16);

                for(i = 0; i < it_cnt; ++i)

                    alg.decrypt(act, act); 

                if(serpent_hack)
                
                    block_reverse(act, 16);

                if(!block_cmp(pt, act, 16))
                {   
                    con_string("\n\ndecryption error on test ");
                    put_dec(tstr, test_no); con_string(tstr); e_cnt++;
                }
            }
        }
    }

    close_ifile(inf);

    if(e_cnt > 0)   // report any errors
    {
        put_dec(tstr, e_cnt); con_string("\n"); con_string(tstr);
        con_string(" errors during test\n");
    }
    else            // else report all is well

        con_string("\nall tests correct\n");
}