예제 #1
0
int ubifs_size(const char *filename, loff_t *size)
{
	struct ubifs_info *c = ubifs_sb->s_fs_info;
	unsigned long inum;
	struct inode *inode;
	int err = 0;

	c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY);

	inum = ubifs_findfile(ubifs_sb, (char *)filename);
	if (!inum) {
		err = -1;
		goto out;
	}

	inode = ubifs_iget(ubifs_sb, inum);
	if (IS_ERR(inode)) {
		printf("%s: Error reading inode %ld!\n", __func__, inum);
		err = PTR_ERR(inode);
		goto out;
	}

	*size = inode->i_size;

	ubifs_iput(inode);
out:
	ubi_close_volume(c->ubi);
	return err;
}
예제 #2
0
int ubifs_exists(const char *filename)
{
	struct ubifs_info *c = ubifs_sb->s_fs_info;
	unsigned long inum;

	c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY);
	inum = ubifs_findfile(ubifs_sb, (char *)filename);
	ubi_close_volume(c->ubi);

	return inum != 0;
}
예제 #3
0
int ubifs_ls(char *filename)
{
	struct ubifs_info *c = ubifs_sb->s_fs_info;
	struct file *file;
	struct dentry *dentry;
	struct inode *dir;
	void *dirent = NULL;
	unsigned long inum;
	int ret = 0;

	c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY);
	inum = ubifs_findfile(ubifs_sb, filename);
	if (!inum) {
		ret = -1;
		goto out;
	}

	file = kzalloc(sizeof(struct file), 0);
	dentry = kzalloc(sizeof(struct dentry), 0);
	dir = kzalloc(sizeof(struct inode), 0);
	if (!file || !dentry || !dir) {
		printf("%s: Error, no memory for malloc!\n", __func__);
		ret = -ENOMEM;
		goto out_mem;
	}

	dir->i_sb = ubifs_sb;
	file->f_path.dentry = dentry;
	file->f_path.dentry->d_parent = dentry;
	file->f_path.dentry->d_inode = dir;
	file->f_path.dentry->d_inode->i_ino = inum;
	file->f_pos = 1;
	file->private_data = NULL;
	ubifs_printdir(file, dirent);

out_mem:
	if (file)
		free(file);
	if (dentry)
		free(dentry);
	if (dir)
		free(dir);

out:
	ubi_close_volume(c->ubi);
	return ret;
}
예제 #4
0
int ubifs_filesize(char *filename, u32* size)
{
    struct ubifs_info *c = ubifs_sb->s_fs_info;
    unsigned long inum=0;
    struct inode *inode=NULL;
    int err = 0;

    c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY);
    if (IS_ERR(c->ubi)) {
        err = PTR_ERR(c->ubi);
    	goto out_no_close;
    }
    inum = ubifs_findfile(ubifs_sb, filename);
    if (!inum) {
        err = -1;
        goto out;
    }

    /*
     * Read file inode
     */
    inode = ubifs_iget(ubifs_sb, inum);
    if (IS_ERR(inode)) {
        printf("%s: Error reading inode %ld!\n", __func__, inum);
        err = PTR_ERR(inode);
        goto out;
    }

    /*
     * If no size was specified or if size bigger than filesize
     * set size to filesize
     */
    //if ((size == 0) || (size > inode->i_size))
     *size = inode->i_size;
     printf("ubifs_filesize  %08x \n", *size);

    //return 0;
out:
    ubi_close_volume(c->ubi);
out_no_close:
    return err;

}
예제 #5
0
int ubifs_load(char *filename, u32 addr, u32 size)
{
	struct ubifs_info *c = ubifs_sb->s_fs_info;
	unsigned long inum;
	struct inode *inode;
	struct page page;
	int err = 0;
	int i;
	int count;
	int last_block_size = 0;

	c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY);
	/* ubifs_findfile will resolve symlinks, so we know that we get
	 * the real file here */
	inum = ubifs_findfile(ubifs_sb, filename);
	if (!inum) {
		err = -1;
		goto out;
	}

	/*
	 * Read file inode
	 */
	inode = ubifs_iget(ubifs_sb, inum);
	if (IS_ERR(inode)) {
		printf("%s: Error reading inode %ld!\n", __func__, inum);
		err = PTR_ERR(inode);
		goto out;
	}

	/*
	 * If no size was specified or if size bigger than filesize
	 * set size to filesize
	 */
	if ((size == 0) || (size > inode->i_size))
		size = inode->i_size;

	count = (size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT;
	printf("Loading file '%s' to addr 0x%08x with size %d (0x%08x)...\n",
	       filename, addr, size, size);

	page.addr = (void *)addr;
	page.index = 0;
	page.inode = inode;
	for (i = 0; i < count; i++) {
		/*
		 * Make sure to not read beyond the requested size
		 */
		if ((i + 1) == count)
			last_block_size = size - (i * PAGE_SIZE);

		err = do_readpage(c, inode, &page, last_block_size);
		if (err)
			break;

		page.addr += PAGE_SIZE;
		page.index++;
	}

	if (err)
		printf("Error reading file '%s'\n", filename);
	else
		printf("Done\n");

	ubifs_iput(inode);

out:
	ubi_close_volume(c->ubi);
	return err;
}
예제 #6
0
int ubifs_load(char *filename, u32 addr, u32 size)
{
	struct ubifs_info *c = ubifs_sb->s_fs_info;
	unsigned long inum;
	struct inode *inode;
	struct page page;
	int err = 0;
	int i;
	int count;
	char link_name[64];
	struct ubifs_inode *ui;

	c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY);
	inum = ubifs_findfile(ubifs_sb, filename);
	if (!inum) {
		err = -1;
		goto out;
	}

	/*
	 * Read file inode
	 */
	inode = ubifs_iget(ubifs_sb, inum);
	if (IS_ERR(inode)) {
		printf("%s: Error reading inode %ld!\n", __func__, inum);
		err = PTR_ERR(inode);
		goto out;
	}

	/*
	 * Check for symbolic link
	 */
	ui = ubifs_inode(inode);
	if (((inode->i_mode & S_IFMT) == S_IFLNK) && ui->data_len) {
		memcpy(link_name, ui->data, ui->data_len);
		printf("%s is linked to %s!\n", filename, link_name);
		ubifs_iput(inode);

		/*
		 * Now we have the "real" filename, call ubifs_load()
		 * again (recursive call) to load this file instead
		 */
		return ubifs_load(link_name, addr, size);
	}

	/*
	 * If no size was specified or if size bigger than filesize
	 * set size to filesize
	 */
	if ((size == 0) || (size > inode->i_size))
		size = inode->i_size;

	count = (size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT;
	printf("Loading file '%s' to addr 0x%08x with size %d (0x%08x)...\n",
	       filename, addr, size, size);

	page.addr = (void *)addr;
	page.index = 0;
	page.inode = inode;
	for (i = 0; i < count; i++) {
		err = do_readpage(c, inode, &page);
		if (err)
			break;

		page.addr += PAGE_SIZE;
		page.index++;
	}

	if (err)
		printf("Error reading file '%s'\n", filename);
	else
		printf("Done\n");

	ubifs_iput(inode);

out:
	ubi_close_volume(c->ubi);
	return err;
}
예제 #7
0
int ubifs_read(const char *filename, void *buf, loff_t offset,
	       loff_t size, loff_t *actread)
{
	struct ubifs_info *c = ubifs_sb->s_fs_info;
	unsigned long inum;
	struct inode *inode;
	struct page page;
	int err = 0;
	int i;
	int count;
	int last_block_size = 0;

	*actread = 0;

	if (offset & (PAGE_SIZE - 1)) {
		printf("ubifs: Error offset must be a multple of %d\n",
		       PAGE_SIZE);
		return -1;
	}

	c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY);
	/* ubifs_findfile will resolve symlinks, so we know that we get
	 * the real file here */
	inum = ubifs_findfile(ubifs_sb, (char *)filename);
	if (!inum) {
		err = -1;
		goto out;
	}

	/*
	 * Read file inode
	 */
	inode = ubifs_iget(ubifs_sb, inum);
	if (IS_ERR(inode)) {
		printf("%s: Error reading inode %ld!\n", __func__, inum);
		err = PTR_ERR(inode);
		goto out;
	}

	if (offset > inode->i_size) {
		printf("ubifs: Error offset (%lld) > file-size (%lld)\n",
		       offset, size);
		err = -1;
		goto put_inode;
	}

	/*
	 * If no size was specified or if size bigger than filesize
	 * set size to filesize
	 */
	if ((size == 0) || (size > (inode->i_size - offset)))
		size = inode->i_size - offset;

	count = (size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT;

	page.addr = buf;
	page.index = offset / PAGE_SIZE;
	page.inode = inode;
	for (i = 0; i < count; i++) {
		/*
		 * Make sure to not read beyond the requested size
		 */
		if (((i + 1) == count) && (size < inode->i_size))
			last_block_size = size - (i * PAGE_SIZE);

		err = do_readpage(c, inode, &page, last_block_size);
		if (err)
			break;

		page.addr += PAGE_SIZE;
		page.index++;
	}

	if (err) {
		printf("Error reading file '%s'\n", filename);
		*actread = i * PAGE_SIZE;
	} else {
		*actread = size;
	}

put_inode:
	ubifs_iput(inode);

out:
	ubi_close_volume(c->ubi);
	return err;
}
예제 #8
0
int ubifs_part_load(char *filename, u32 addr, u32 offset, u32 size)
{
    struct ubifs_info *c = ubifs_sb->s_fs_info;
    unsigned long inum=0;
    struct inode *inode=NULL;
    struct page page;
    int err = 0;
    int i=0;
    int count=0;
	int last_block_size = 0;
    char link_name[64];
    struct ubifs_inode *ui=NULL;
    
    if(offset % PAGE_SIZE != 0)
    {
        printf("%s: offset(0x%x) should align to page size(0x%x), at %d\n", __func__, offset, PAGE_SIZE, __LINE__);
        return 1;
    }

    c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READONLY);
    if (IS_ERR(c->ubi)) {
        err = PTR_ERR(c->ubi);
        goto out_no_close;
    }
    inum = ubifs_findfile(ubifs_sb, filename);
    if (!inum) {
        err = -1;
        goto out;
    }

    /*
    * Read file inode
    */
    inode = ubifs_iget(ubifs_sb, inum);
    if (IS_ERR(inode)) {
        printf("%s: Error reading inode %ld!\n", __func__, inum);
        err = PTR_ERR(inode);
        goto out;
    }

    /*
    * Check for symbolic link
    */
    ui = ubifs_inode(inode);
    if (((inode->i_mode & S_IFMT) == S_IFLNK) && ui->data_len) {
        memcpy(link_name, ui->data, ui->data_len);
        link_name[ui->data_len] = '\0';
        printf("%s is linked to %s!\n", filename, link_name);
        ubifs_iput(inode);

        /*
         * Now we have the "real" filename, call ubifs_load()
         * again (recursive call) to load this file instead
         */
        return ubifs_part_load(link_name, addr, offset, size);
    }

    /*
    * If no size was specified or if size bigger than filesize
    * set size to filesize
    */
    if ((size == 0) || (size > inode->i_size))
        size = inode->i_size;

    count = (size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT;
    printf("Loading file '%s' to addr 0x%08x with size %d (0x%08x)...\n",
        filename, addr, size, size);

    page.addr = (void *)addr;
    page.index = (offset / PAGE_SIZE);
    page.inode = inode;
    //offset
    for (i = 0; i < count; i++) {
		/*
		 * Make sure to not read beyond the requested size
		 */
		if (((i + 1) == count) && (size < inode->i_size))
			last_block_size = size - (i * PAGE_SIZE);

        err = do_readpage(c, inode, &page, last_block_size);
        if (err)
            break;

        page.addr += PAGE_SIZE;
        page.index++;
    }

    if (err)
        printf("Error reading file '%s'\n", filename);
    else
        printf("Done\n");

    ubifs_iput(inode);

out:
    ubi_close_volume(c->ubi);
out_no_close:
	return err;
}