static int filldir(struct ubifs_info *c, const char *name, int namlen, u64 ino, unsigned int d_type) { struct inode *inode; char filetime[32]; switch (d_type) { case UBIFS_ITYPE_REG: printf("\t"); break; case UBIFS_ITYPE_DIR: printf("<DIR>\t"); break; case UBIFS_ITYPE_LNK: printf("<LNK>\t"); break; default: printf("other\t"); break; } inode = ubifs_iget(c->vfs_sb, ino); if (IS_ERR(inode)) { printf("%s: Error in ubifs_iget(), ino=%lld ret=%p!\n", __func__, ino, inode); return -1; } ctime_r((time_t *)&inode->i_mtime, filetime); printf("%9lld %24.24s ", inode->i_size, filetime); ubifs_iput(inode); printf("%s\n", name); return 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; }
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; }
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; }
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; }
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; }