Example #1
0
//zone below [fs.update.driver]
int analysis_copylist(const char *copy_list)
{
    struct file *filep;
    struct inode *inode = NULL;
    mm_segment_t old_fs;
    char *token = NULL, *file_ptr = NULL, *file_ptmp = NULL, *pchar = NULL;
    int all_purpose;
    unsigned int file_len;

    filep = filp_open(copy_list, O_RDONLY , 0);
    if(IS_ERR(filep))
    {
        FS_ERR("<open:%s>\n", copy_list);
        return -1;
    }
    FS_SUC("<open:%s>\n", copy_list);

    fs_remount_system();

    old_fs = get_fs();
    set_fs(get_ds());

    inode = filep->f_dentry->d_inode;
    file_len = inode->i_size;
    file_len = file_len + 1;

    file_ptr = (unsigned char *)kzalloc(file_len, GFP_KERNEL);
    if(file_ptr == NULL)
    {
        FS_ERR( "<kzalloc>\n");
        return -1;
    }

    filep->f_op->llseek(filep, 0, 0);
    all_purpose = filep->f_op->read(filep, file_ptr, file_len, &filep->f_pos);
    if(all_purpose <= 0)
    {
        FS_ERR( "<f_op->read>\n");
        return -1;
    }
    set_fs(old_fs);
    filp_close(filep, 0);

    file_ptr[file_len - 1] = '\0';
    file_ptmp = file_ptr;
    while((token = strsep(&file_ptmp, "\n")) != NULL )
    {
        if(token && token[0] != '#' && (pchar = strchr(token, '=')))
        {
            *pchar++ = '\0';
            FS_WARN("<cp:%s,%s>\n", token, pchar);
            fs_copy_file(token, pchar);
            pchar = NULL;
        }
    }
    kfree(file_ptr);
    return 1;
}
Example #2
0
int fs_copy(fs_t *fs, inodeid_t dir1, inodeid_t dir2, char* file1, char* file2)
{
	if (fs == NULL || dir1>=ITAB_SIZE || dir2>=ITAB_SIZE || file1 == NULL || file2 == NULL) {
		dprintf("[fs_copy] malformed arguments\n");
		return -1;
	}

	if (strlen(file1) == 0 || strlen(file1)+1 > FS_MAX_FNAME_SZ) {
		dprintf("[fs_copy] source file name size error\n");
		return -1;
	}
	
	if (strlen(file2) == 0 || strlen(file2)+1 > FS_MAX_FNAME_SZ) {
		dprintf("[fs_copy] source file name size error\n");
		return -1;
	}

	if (!BMAP_ISSET(fs->inode_bmap, dir1)) {
		dprintf("[fs_copy] inode (dir1) is not being used");
		return -1;
	}

	if (!BMAP_ISSET(fs->inode_bmap, dir2)) {
		dprintf("[fs_copy] inode (dir2) is not being used");
		return -1;
	}

	inodeid_t fileid=0;
	if (!fsi_dir_search(fs, dir1, file1, &fileid)==0) {
		dprintf("[fs_copy] file does not exist\n");
		return -1;
	}
	
	fs_inode_t* idir1 = &fs->inode_tab[dir1];
	if (idir1->type != FS_DIR) {
		dprintf("[fs_copy] inode (dir1) is not a directory");
		return -1;
	}

	fs_inode_t* idir2 = &fs->inode_tab[dir2];
	if (idir2->type != FS_DIR) {
		dprintf("[fs_copy] inode (dir2) is not a directory");
		return -1;
	}

//	fs_dentry_t page[DIR_PAGE_ENTRIES];
//	int num_dir_entry = 0, block_num = 0;

	fs_copy_file(fs, dir2,fileid, file2);		
	
	return 0;
}
Example #3
0
void fs_copy_dir(fs_t *fs, inodeid_t dir1id, inodeid_t dir2id, char* dirname)
{
	fs_inode_t idir1 = fs->inode_tab[dir1id];
	inodeid_t idir2;
	int dirsize = idir1.size / sizeof(fs_dentry_t); //numero de entradas do directório a ser copiado
	fs_dentry_t page[DIR_PAGE_ENTRIES];

	fs_mkdir(fs, dir2id, dirname, &idir2);

	for (int i = 0; i < INODE_NUM_BLKS && idir1.blocks[i] != 0; i++) {
		int num_dir_pg_entries;
		while (dirsize > 0) { // enquanto houver entradas no directório
			block_read(fs->blocks, idir1.blocks[i], (char*) page);
			for(num_dir_pg_entries = 0; num_dir_pg_entries < DIR_PAGE_ENTRIES && dirsize > 0; i++, dirsize--) {
				inodeid_t entryid = page[num_dir_pg_entries].inodeid;
				if (fs->inode_tab[entryid].type == FS_FILE)
					fs_copy_file(fs, dir2id, entryid, page[num_dir_pg_entries].name);
				if (fs->inode_tab[entryid].type == FS_DIR)
					fs_copy_dir(fs, entryid, idir2, page[num_dir_pg_entries].name);
			}
		}
	}
}
Example #4
0
int update_ko(const char *ko_list, const char *fromdir, const char *todir)
{
    struct file *filep;
    struct inode *inode = NULL;
    mm_segment_t old_fs;
    char *token, *file_ptr = NULL, *file_ptmp;
    char file_from[256];
    char file_to[256];
    int all_purpose;
    unsigned int file_len;

    filep = filp_open(ko_list, O_RDONLY , 0);
    if(IS_ERR(filep))
    {
        FS_ERR("<open:%s>\n", ko_list);
        return -1;
    }
    FS_SUC("<open:%s>\n", ko_list);

    fs_remount_system();

    old_fs = get_fs();
    set_fs(get_ds());

    inode = filep->f_dentry->d_inode;
    file_len = inode->i_size;
    file_len = file_len + 1;

    file_ptr = (unsigned char *)kzalloc(file_len, GFP_KERNEL);
    if(file_ptr == NULL)
    {
        FS_ERR( "<kzalloc>\n");
        return -1;
    }

    filep->f_op->llseek(filep, 0, 0);
    all_purpose = filep->f_op->read(filep, file_ptr, file_len, &filep->f_pos);
    if(all_purpose <= 0)
    {
        FS_ERR( "<f_op->read>\n");
        return -1;
    }
    set_fs(old_fs);
    filp_close(filep, 0);

    file_ptr[file_len - 1] = '\0';
    file_ptmp = file_ptr;
    while((token = strsep(&file_ptmp, "\n")) != NULL )
    {
        if( token[0] != '#' && strlen(token) > 2)
        {
            memset(file_from, '\0', sizeof(file_from));
            memset(file_to, '\0', sizeof(file_to));
            sprintf(file_from, "%s/%s", fromdir, token);
            sprintf(file_to, "%s/%s", todir, token);
            FS_WARN("<cp:%s,%s>\n", file_from, file_to);
            fs_copy_file(file_from, file_to);
        }
    }
    kfree(file_ptr);
    return 1;
}
Example #5
0
DECLARE_TEST( fs, file )
{
	char* testpath = path_merge( environment_temporary_directory(), string_from_int_static( random64(), 0, 0 ) );
	char* copypath = path_merge( environment_temporary_directory(), string_from_int_static( random64(), 0, 0 ) );
	stream_t* teststream = 0;

	if( !fs_is_directory( environment_temporary_directory() ) )
		fs_make_directory( environment_temporary_directory() );

	if( fs_is_directory( testpath ) )
		fs_remove_directory( testpath );
	fs_remove_file( testpath );

	if( fs_is_directory( copypath ) )
		fs_remove_directory( copypath );
	fs_remove_file( copypath );


	teststream = fs_open_file( testpath, STREAM_IN );
	EXPECT_EQ( teststream, 0 );
	EXPECT_FALSE( fs_is_file( testpath ) );

	teststream = fs_open_file( testpath, STREAM_IN | STREAM_OUT );
	EXPECT_NE( teststream, 0 );
	EXPECT_TRUE( fs_is_file( testpath ) );

	stream_deallocate( teststream );
	fs_remove_file( testpath );
	teststream = fs_open_file( testpath, STREAM_IN );
	EXPECT_EQ( teststream, 0 );
	EXPECT_FALSE( fs_is_file( testpath ) );

	teststream = fs_open_file( testpath, STREAM_OUT );
	EXPECT_NE( teststream, 0 );
	EXPECT_TRUE( fs_is_file( testpath ) );

	stream_deallocate( teststream );
	teststream = 0;

	fs_copy_file( testpath, copypath );
	EXPECT_TRUE( fs_is_file( copypath ) );

	fs_remove_file( copypath );
	EXPECT_FALSE( fs_is_file( copypath ) );

	teststream = fs_open_file( testpath, STREAM_OUT );
	EXPECT_NE( teststream, 0 );
	EXPECT_TRUE( fs_is_file( testpath ) );

	stream_write_string( teststream, "testing testing" );

	stream_deallocate( teststream );
	teststream = 0;

	fs_copy_file( testpath, copypath );
	EXPECT_TRUE( fs_is_file( copypath ) );

	fs_remove_file( copypath );
	EXPECT_FALSE( fs_is_file( copypath ) );

	stream_deallocate( teststream );
	string_deallocate( testpath );
	string_deallocate( copypath );

	return 0;
}
Example #6
0
void test_file_notification(void**) {
    int temp = 1;
    const char* test_dir = "t2-output/test_dir";
    const char* test_dir_2 = "t2-output/2_test_dir";
    const char* test_dir_3 = "t2-output/3_test_dir";
    const char* filename_2 = "t2-output/test_dir/test_file_2";
    s_filename = "t2-output/test_dir/test_file.dll";
    s_filename_2 = "t2-output/2_test_dir/test_file.txt";

    s_filename_3 = "t2-output/3_test_dir/test_file.bin";
    s_filename_4 = "t2-output/3_test_dir/test_file.so";
    s_filename_5 = "t2-output/3_test_dir/test_file.exe";

    fs_remove_directory(test_dir);
    fs_make_directory(test_dir);

    fs_remove_directory(test_dir_2);
    fs_make_directory(test_dir_2);

    fs_remove_directory(test_dir_3);
    fs_make_directory(test_dir_3);

    FILE* t = fopen(filename_2, "wb");
    fwrite(&temp, 4, 1, t);
    fclose(t);

    FileMonitor_addPath(test_dir, "*", fileNotifaction, &s_user_data_1);

    thread_sleep(200);

    // Test notification when writing one file

    t = fopen(s_filename, "wb");
    fclose(t);

    thread_sleep(1000);

    FileMonitor_update();

    thread_sleep(400);

    assert_int_equal(s_checkPhase, 1);

    fs_copy_file(filename_2, s_filename);

    thread_sleep(1000);

    FileMonitor_update();

    thread_sleep(400);

    assert_int_equal(s_checkPhase, 2);

    FileMonitor_addPath(test_dir_2, "txt", fileNotifaction2, &s_user_data_2);

    thread_sleep(1000);

    fs_copy_file(filename_2, s_filename_2);

    thread_sleep(1200);

    FileMonitor_update();

    assert_int_equal(s_checkPhase, 3);


    FileMonitor_removePath(test_dir);

    // Except no notifactions for this

    fs_remove_file(s_filename);

    FileMonitor_update();

    thread_sleep(1000);

    FileMonitor_update();

    thread_sleep(400);

    assert_int_equal(s_checkPhase, 3);


    FileMonitor_addPath(test_dir_3, "bin;so", fileNotifaction3, &s_user_data_3);

    thread_sleep(1000);

    fs_copy_file(filename_2, s_filename_3);

    thread_sleep(1200);

    FileMonitor_update();

    assert_int_equal(s_checkPhase, 4);

    thread_sleep(1000);

    fs_copy_file(filename_2, s_filename_4);

    thread_sleep(1200);

    FileMonitor_update();

    assert_int_equal(s_checkPhase, 5);

    thread_sleep(1000);

    fs_copy_file(filename_2, s_filename_5);

    thread_sleep(1200);

    FileMonitor_update();

    assert_int_equal(s_checkPhase, 5);

    FileMonitor_close();
}