Пример #1
0
TEST_F(IOFSTest, FputcFsSecondBlock) {
    Stream *s;
    int c;
    int i;
    NamedFile *file;

    /* need file to exist */
    create_fs("/dev/fs/data");

    file = find_file("/dev/fs/data");
    s = myFopen("/dev/fs/data");

    /* fill the first block */
    for (i = 0; i < BLOCK_SIZE; i++) {
        c = fputc_fs('x', s);
    }

    c = fputc_fs('x', s);
    EXPECT_EQ(BLOCK_SIZE + 1, file->size);

    EXPECT_NE(s->file->first_block, s->write_block);
    EXPECT_EQ(s->file->first_block->next, s->write_block);

    myFclose(s);
    delete_fs("/dev/fs/data");
}
Пример #2
0
TEST_F(IOFSTest, FgetcFsSecondBlock) {
    Stream *s;
    int c, d;
    int i;
    NamedFile *file;
    Block *original_block;

    create_fs("/dev/fs/data");
    file = find_file("/dev/fs/data");
    s = myFopen("/dev/fs/data");
    original_block = s->read_block;
    /* fill up the first block */
    for (i = 0; i < BLOCK_SIZE; i++) {
        c = fputc_fs('x', s);
    }
    /* read it back out */
    for (i = 0; i < BLOCK_SIZE; i++) {
        d = fgetc_fs(s);
    }
    EXPECT_EQ('x', d);

    /* next char should write into the next block */
    c = fputc_fs('y', s);
    d = fgetc_fs(s);
    EXPECT_EQ('y', d);
    EXPECT_EQ(s->read_block->data + 1, s->next_byte_to_read);

    myFclose(s);
    delete_fs("/dev/fs/data");
}
Пример #3
0
TEST_F(IOFSTest, FputcFsFirstBlock) {
    Stream *s;
    int c;
    int i;
    NamedFile *file;

    /* need file to exist */
    create_fs("/dev/fs/data");

    file = find_file("/dev/fs/data");
    s = myFopen("/dev/fs/data");
    EXPECT_EQ(0, file->size);
    EXPECT_EQ(file->first_block, s->write_block);


    c = fputc_fs('x', s);
    EXPECT_EQ(1, file->size);

    /* start at 1 not 0 since we already put a char */
    for (i = 1; i < BLOCK_SIZE; i++) {
        c = fputc_fs('x', s);
    }
    EXPECT_EQ(BLOCK_SIZE, file->size);

    myFclose(s);
    delete_fs("/dev/fs/data");
}
Пример #4
0
TEST_F(IOFSTest, CreateFs) {
    int result;
    NamedFile *file;
    initialize_io_fs();
    EXPECT_FALSE(file_exists("/dev/fs/fake"));

    result = create_fs("/dev/fs/data");
    EXPECT_EQ(SUCCESS, result);
    create_fs("/dev/fs/whale");
    create_fs("/dev/fs/manatee");

    EXPECT_TRUE(file_exists("/dev/fs/data"));
    EXPECT_TRUE(file_exists("/dev/fs/whale"));
    EXPECT_TRUE(file_exists("/dev/fs/manatee"));
    EXPECT_FALSE(file_exists("/dev/fs/fake"));

    file = find_file("/dev/fs/data");
    EXPECT_STREQ(file->filename, "/dev/fs/data");
}
Пример #5
0
void *
st_pbo_get_download_fs(struct st_context *st, enum pipe_texture_target target)
{
   assert(target < PIPE_MAX_TEXTURE_TYPES);

   if (!st->pbo.download_fs[target])
      st->pbo.download_fs[target] = create_fs(st, true, target);

   return st->pbo.download_fs[target];
}
Пример #6
0
TEST_F(IOFSTest, DeleteFs) {
    int result;
    initialize_io_fs();
    result = delete_fs("/dev/fs/fake");
    EXPECT_EQ(CANNOT_DELETE_FILE, result);

    create_fs("/dev/fs/data");
    EXPECT_TRUE(file_exists("/dev/fs/data"));
    result = delete_fs("/dev/fs/data");
    EXPECT_FALSE(file_exists("/dev/fs/data"));
    EXPECT_EQ(SUCCESS, result);

    create_fs("/dev/fs/whale");
    create_fs("/dev/fs/manatee");

    result = delete_fs("/dev/fs/manatee");
    EXPECT_EQ(SUCCESS, result);
    EXPECT_TRUE(file_exists("/dev/fs/whale"));
    EXPECT_FALSE(file_exists("/dev/fs/manatee"));
}
Пример #7
0
TEST_F(IOFSTest, FgetcFs) {
    Stream *s;
    int c, d;
    int i;
    NamedFile *file;

    /* need file to exist */
    create_fs("/dev/fs/data");
    file = find_file("/dev/fs/data");
    s = myFopen("/dev/fs/data");

    /* haven't put any chars in the file yet */
    EXPECT_EQ(EOF, fgetc_fs(s));

    c = fputc_fs('x', s);
    c = fputc_fs('y', s);
    c = fputc_fs('z', s);

    d = fgetc_fs(s);
    EXPECT_EQ('x', d);
    EXPECT_EQ((file->first_block->data + 1), s->next_byte_to_read);

    d = fgetc_fs(s);
    EXPECT_EQ('y', d);
    EXPECT_EQ((file->first_block->data + 2), s->next_byte_to_read);

    d = fgetc_fs(s);
    EXPECT_EQ('z', d);
    EXPECT_EQ((file->first_block->data + 3), s->next_byte_to_read);

    EXPECT_EQ(EOF, fgetc_fs(s));

    /* start at 3 not 0 since we already put 3 chars */
    for (i = 3; i < BLOCK_SIZE; i++) {
        c = fputc_fs('x', s);
    }
    /* now get all but one of the chars from this block */
    for (i = 3; i < BLOCK_SIZE - 1; i++) {
        d = fgetc_fs(s);
    }

    /* should have one more byte left to read from this block */
    EXPECT_EQ((file->first_block->data + (BLOCK_SIZE - 1)), s->next_byte_to_read);
    d = fgetc_fs(s);
    EXPECT_EQ('x', d);

    d = fgetc_fs(s);
    EXPECT_EQ(EOF, d);

    myFclose(s);
    delete_fs("/dev/fs/data");
}
Пример #8
0
TEST_F(IOFSTest, FgetcFsTwoStreams) {
    Stream *s1, *s2;
    int c, d;
    int i;
    NamedFile *file;

    /* need file to exist */
    create_fs("/dev/fs/data");
    file = find_file("/dev/fs/data");

    s1 = myFopen("/dev/fs/data");
    s2 = myFopen("/dev/fs/data");
    EXPECT_EQ(s1->read_block, s2->read_block);

    /* get onto the second block with the first stream */
    for (i = 0; i < BLOCK_SIZE; i++) {
        c = fputc_fs('x', s1);
    }
    c = fputc_fs('y', s1);

    for (i = 0; i < BLOCK_SIZE; i++) {
        d = fgetc_fs(s1);
    }
    d = fgetc_fs(s1);

    EXPECT_NE(s1->read_block, s2->read_block);
    EXPECT_EQ(s1->read_block, s2->read_block->next);

    d = fgetc_fs(s2);
    EXPECT_EQ('x', d);
    /* start at 1 not 0 since we already got a one char */
    for (i = 1; i < BLOCK_SIZE; i++) {
        d = fgetc_fs(s2);
    }
    EXPECT_EQ('x', d);

    d = fgetc_fs(s2);
    EXPECT_EQ('y', d);
    EXPECT_EQ(s1->read_block, s2->read_block);

    myFclose(s1);
    myFclose(s2);
    delete_fs("/dev/fs/data");
}
Пример #9
0
static INLINE void *
shader_from_cache(struct pipe_context *pipe,
		  unsigned type, struct cso_hash *hash, unsigned key)
{
    void *shader = 0;

    struct cso_hash_iter iter = cso_hash_find(hash, key);

    if (cso_hash_iter_is_null(iter)) {
	if (type == PIPE_SHADER_VERTEX)
	    shader = create_vs(pipe, key);
	else
	    shader = create_fs(pipe, key);
	cso_hash_insert(hash, key, shader);
    } else
	shader = (void *)cso_hash_iter_data(iter);

    return shader;
}
Пример #10
0
TEST_F(IOFSTest, FputcFsTwoStreams) {
    Stream *s1, *s2;
    int c;
    int i;
    NamedFile *file;

    /* need file to exist */
    create_fs("/dev/fs/data");

    file = find_file("/dev/fs/data");
    s1 = myFopen("/dev/fs/data");
    /* open a new stream on the same file */
    s2 = myFopen("/dev/fs/data");
    EXPECT_EQ(s1->write_block, s2->write_block);

    /* fill the first block of the file using the first stream */
    for (i = 0; i < BLOCK_SIZE; i++) {
        c = fputc_fs('x', s1);
    }

    c = fputc_fs('x', s1);
    EXPECT_EQ(BLOCK_SIZE + 1, file->size);
    EXPECT_NE(s1->write_block, s2->write_block);
    EXPECT_EQ(s1->write_block, s2->write_block->next);

    /* fill the first block of the file using the second stream */
    for (i = 0; i < BLOCK_SIZE; i++) {
        c = fputc_fs('y', s2);
    }
    c = fputc_fs('y', s2);
    EXPECT_EQ(BLOCK_SIZE + 1, file->size);
    /* s2 should now point to the next block s1 created */
    /* not a brand new block */
    EXPECT_EQ(s1->write_block, s2->write_block);

    myFclose(s1);
    myFclose(s2);
    delete_fs("/dev/fs/data");
}
Пример #11
0
TEST(TestMkfs, create_fs) {
	create_fs();

	struct inode root_inode;
	TEST_ASSERT_TRUE(-1 != iget(ROOT_INODE_NUMBER, &root_inode));

	TEST_ASSERT_EQUAL(ROOT_INODE_NUMBER, root_inode.inode_id);
	TEST_ASSERT_EQUAL(1, root_inode.links_nb);
	TEST_ASSERT_EQUAL(1, root_inode.num_blocks);
	TEST_ASSERT_EQUAL(TYPE_DIRECTORY, root_inode.type);
	TEST_ASSERT_TRUE(root_inode.direct_blocks[0] != 0);

	struct dir_block dir_block;
	read_block(root_inode.direct_blocks[0], &dir_block);

	TEST_ASSERT_EQUAL(ROOT_INODE_NUMBER, dir_block.inode_ids[0]);
	TEST_ASSERT_EQUAL(0, strcmp(".", dir_block.names[0]));

	TEST_ASSERT_EQUAL(ROOT_INODE_NUMBER, dir_block.inode_ids[1]);
	TEST_ASSERT_EQUAL(0, strcmp("..", dir_block.names[1]));

	TEST_ASSERT_EQUAL(0, dir_block.inode_ids[2]);
	TEST_ASSERT_EQUAL(0, strcmp("", dir_block.names[2]));
}
Пример #12
0
TEST_F(IOFSTest, CreateFsInvalidName) {
    int result;
    result = create_fs("data");
    EXPECT_EQ(CANNOT_CREATE_FILE, result);
    EXPECT_FALSE(file_exists("data"));
}
Пример #13
0
/*main*/
void HariMain(void){
	fs_pid=get_pid();
	while(identify_hd()==FALSE);
	while(identify_fs()==FALSE);//读取superBlock
	/*如果硬盘上不存在文件系统,则新建一个。注:约定tinyOS文件系统的superBlock前5字节为字符串“TINY”*/
	if(strcmp(superBlock.sign,"TINY")==FALSE)
	{
		create_fs();
		identify_fs();/*因为之前读取的可能无效,当文件系统不存在时*/
	}
	read_hd_bmp ();
	read_fat();
	
	while(1)
	{
		receive(&msg_recv,STATUS_RECV_ANY,0,fs_pid);
		u_int32 recv_type=msg_recv.type;
		u_int32 send_pid =msg_recv.send_pid;
		switch(recv_type)
		{
			case FILE_MSG_TYPE:
			{
				struct FILE_MSG *msg =&msg_recv.u.msg_file;
				u_int32 file_msg_type=msg->type           ;
				int8*file_name       =msg->file_name      ;
				void*buf             =msg->buf            ;
				u_int32 buf_len      =msg->buf_len        ;
				u_int32  handle      =msg->handle         ;
				u_int32 result                            ;
				struct I_NODE*inode  =msg->inode          ;
				switch(file_msg_type)
				{
				    case FILE_IDENTIFY:
				                      if(identify_file(handle,inode,send_pid)==TRUE )
										  awake(send_pid,TRUE  );
									  else
										  awake(send_pid,FALSE );
								      break;
				    case FILE_OPEN    :
					                  handle=open_file(file_name,send_pid);
									  awake(send_pid,handle);
								      break;
				    case FILE_READ    :
				                      if((result=read_file(handle,buf_len,buf,send_pid))!=FALSE)
										   awake(send_pid,result );
									  else
										   awake(send_pid,FALSE  );
								      break;
				    case FILE_WRITE   :
				                      if(write_file(handle,buf_len,buf,send_pid)==TRUE    )
										   awake(send_pid,TRUE );
									  else
										   awake(send_pid,FALSE);
								      break;
				    case FILE_CREATE  :
				                      if(create_file(file_name,send_pid)==TRUE   )
										   awake(send_pid,TRUE );
									  else
										   awake(send_pid,FALSE);
									  
								      break;
				    case FILE_DELETE  :
				                      if(delete_file(handle,send_pid)==TRUE    )
										   awake(send_pid,TRUE  );
									  else
										   awake(send_pid,FALSE );
								      break;
					case POWER_OFF    :
					                   write_back(              );
									   awake(send_pid,TRUE      );
									   break;
				    default:
				                      awake(send_pid,FALSE     );
								      break;
			    }
				break;
		    }
			default:
			    break;
		
	    }
	
    }
}
Пример #14
0
void *
st_pbo_create_upload_fs(struct st_context *st)
{
   return create_fs(st, false, 0);
}