/*
* yaffs2utils: Utilities to make/extract a YAFFS2/YAFFS1 image.
* Copyright (C) 2010-2011 Luen-Yung Lin <penguin.lin@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "configs.h"
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <getopt.h>
#include <limits.h>
#include <libgen.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
#ifdef _HAVE_LUTIMES
#include <sys/time.h>
#else
#include <utime.h>
#endif
#ifdef _HAVE_OSX_SYSLIMITS
#include <sys/syslimits.h>
#endif
#include "yaffs_packedtags1.h"
#include "yaffs_packedtags2.h"
#include "yaffs_trace.h"
#include "yaffs2utils.h"
#include "yaffs2utils_io.h"
#include "yaffs2utils_ecc.h"
#include "yaffs2utils_list.h"
#include "yaffs2utils_endian.h"
#include "yaffs2utils_progress.h"
/*-------------------------------------------------------------------------*/
typedef struct unyaffs2_file_var {
size_t file_size;
} unyaffs2_file_var_t;
typedef struct unyaffs2_symlink_var {
char *alias;
} unyaffs2_symlink_var_t;
typedef struct unyaffs2_hardlink_var {
struct unyaffs2_obj *equiv_obj;
} unyaffs2_hardlink_var_t;
typedef struct unyaffs2_dev_var {
unsigned rdev;
} unyaffs2_dev_var_t;
typedef union unyaffs2_file_variant {
struct unyaffs2_file_var file;
struct unyaffs2_symlink_var symlink;
struct unyaffs2_hardlink_var hardlink;
struct unyaffs2_dev_var dev;
} unyaffs2_file_variant;
typedef struct unyaffs2_obj {
unsigned char valid:1;
unsigned char extracted:1; /* 1 when extracted. */
unsigned obj_id;
unsigned parent_id;
struct unyaffs2_obj *parent_obj;
off_t hdr_off; /* header offset in the image */
char name[NAME_MAX + 1];
enum yaffs_obj_type type; /* file type */
union unyaffs2_file_variant variant;
unsigned mode; /* file mode */
unsigned uid; /* owner uid */
unsigned gid; /* owner gid */
unsigned atime;
unsigned mtime;
unsigned ctime;
struct list_head hashlist; /* hash table */
struct list_head hardlink; /* hardlink list */
struct list_head children; /* if it is the directory */
struct list_head siblings; /* neighbors of fs tree */
} unyaffs2_obj_t;
typedef struct unyaffs2_fstree {
unsigned objs;
struct unyaffs2_obj *root;
} unyaffs2_fstree_t;
typedef struct unyaffs2_specfile {
char *path; /* file path */
struct list_head list; /* specified files list */
struct unyaffs2_obj *obj; /* object */
} unyaffs2_specfile_t;
#ifdef _HAVE_MMAP
typedef struct unyaffs2_mmap {
unsigned char *addr;
size_t size;
} unyaffs2_mmap_t;
#endif
/*-------------------------------------------------------------------------*/
#define UNYAFFS2_OBJTABLE_SIZE YAFFS_NOBJECT_BUCKETS
#define UNYAFFS2_FLAGS_NONROOT 0x01
#define UNYAFFS2_FLAGS_YAFFS1 0x02
#define UNYAFFS2_FLAGS_ENDIAN 0x04
#define UNYAFFS2_FLAGS_VERBOSE 0x08
#define UNYAFFS2_ISYAFFS1 (unyaffs2_flags & UNYAFFS2_FLAGS_YAFFS1)
#define UNYAFFS2_ISENDIAN (unyaffs2_flags & UNYAFFS2_FLAGS_ENDIAN)
#define UNYAFFS2_ISVERBOSE (unyaffs2_flags & UNYAFFS2_FLAGS_VERBOSE)
#define UNYAFFS2_PRINT(s, args...) fprintf(stdout, s, ##args)
#define UNYAFFS2_ERROR(s, args...) fprintf(stderr, s, ##args)
#define UNYAFFS2_WARN(s, args...) UNYAFFS2_ERROR(s, ##args)
#define UNYAFFS2_HELP(s, args...) UNYAFFS2_ERROR(s, ##args)
#ifdef _UNYAFFS2_DEBUG
#define UNYAFFS2_DEBUG(s, args...) UNYAFFS2_ERROR(s, ##args)
#else
#define UNYAFFS2_DEBUG(s, args...)
#endif
#define UNYAFFS2_VERBOSE(s, args...) \
({if (UNYAFFS2_ISVERBOSE) \
UNYAFFS2_PRINT(s, ##args);})
#define UNYAFFS2_PROGRESS_INIT() \
({ if (!UNYAFFS2_ISVERBOSE) \
progress_init();})
#define UNYAFFS2_PROGRESS_BAR(objs, all) \
({ if (!UNYAFFS2_ISVERBOSE) \
progress_bar(objs, all);})
/*-------------------------------------------------------------------------*/
static unsigned unyaffs2_chunksize = 0;
static unsigned unyaffs2_sparesize = 0;
static unsigned unyaffs2_flags = 0;
static unsigned unyaffs2_image_objs = 0;
static unsigned unyaffs2_bufsize = 0;
static unsigned char *unyaffs2_datbuf = NULL;
static int unyaffs2_image_fd = -1;
static char unyaffs2_curfile[PATH_MAX + PATH_MAX] = {0};
static char unyaffs2_linkfile[PATH_MAX + PATH_MAX] = {0};
static LIST_HEAD(unyaffs2_hardlink_list); /* hardlink */
static LIST_HEAD(unyaffs2_specfile_list); /* specfied files */
static nand_ecclayout_t *unyaffs2_oobinfo = NULL;
static struct unyaffs2_fstree unyaffs2_objtree = {0};
static struct list_head unyaffs2_objtable[UNYAFFS2_OBJTABLE_SIZE];
#ifdef _HAVE_MMAP
static struct unyaffs2_mmap unyaffs2_mmapinfo = {0};
#endif
/*-------------------------------------------------------------------------*/
static struct unyaffs2_obj *
unyaffs2_obj_alloc (void)
{
struct unyaffs2_obj *obj;
obj = calloc(sizeof(struct unyaffs2_obj), sizeof(unsigned char));
if (obj == NULL)
return NULL;
obj->parent_obj = obj;
INIT_LIST_HEAD(&obj->hardlink);
INIT_LIST_HEAD(&obj->children);
INIT_LIST_HEAD(&obj->siblings);
INIT_LIST_HEAD(&obj->hashlist);
return obj;
}
static void
unyaffs2_obj_free (struct unyaffs2_obj *obj)
{
if (obj->type == YAFFS_OBJECT_TYPE_SYMLINK &&
obj->variant.symlink.alias != NULL)
free(obj->variant.symlink.alias);
list_del(&obj->hardlink);
list_del(&obj->children);
list_del(&obj->siblings);
list_del(&obj->hashlist);
free(obj);
}
/*-------------------------------------------------------------------------*/
/*
* hash table to look up objects
*/
static inline unsigned
unyaffs2_objtable_hash (unsigned hash)
{
return hash % UNYAFFS2_OBJTABLE_SIZE;
}
static inline void
unyaffs2_objtable_insert (struct unyaffs2_obj *obj)
{
unsigned n = unyaffs2_objtable_hash(obj->obj_id);
list_add_tail(&obj->hashlist, &unyaffs2_objtable[n]);
}
static inline struct unyaffs2_obj *
unyaffs2_objtable_lookup (unsigned obj_id)
{
unsigned n = unyaffs2_objtable_hash(obj_id);
struct list_head *p;
struct unyaffs2_obj *obj;
list_for_each(p, &unyaffs2_objtable[n]) {
obj = list_entry(p, unyaffs2_obj_t, hashlist);
if (obj->obj_id == obj_id)
return obj;
}
return NULL;
}
static inline void
unyaffs2_objtable_init (void)
{
unsigned n;
for (n = 0; n < UNYAFFS2_OBJTABLE_SIZE; n++)
INIT_LIST_HEAD(&unyaffs2_objtable[n]);
}
static inline void
unyaffs2_objtable_exit (void)
{
unsigned i;
struct list_head *p, *n;
struct unyaffs2_obj *obj;
for (i = 0; i < UNYAFFS2_OBJTABLE_SIZE; i++) {
list_for_each_safe(p, n, &unyaffs2_objtable[i]) {
obj = list_entry(p, unyaffs2_obj_t, hashlist);
unyaffs2_obj_free(obj);
}
}
}
/*-------------------------------------------------------------------------*/
/*
* fs tree for objects extraction.
*/
static void
unyaffs2_objtree_cleanup (struct unyaffs2_obj *obj)
{
struct list_head *p, *n;
struct unyaffs2_obj *child;
if (obj == NULL)
return;
list_for_each_safe(p, n, &obj->children) {
child = list_entry(p, unyaffs2_obj_t, siblings);
unyaffs2_objtree_cleanup(child);
}
unyaffs2_obj_free(obj);
}
static struct unyaffs2_fstree *
unyaffs2_objtree_init (struct unyaffs2_fstree *fst)
{
struct unyaffs2_fstree *f = fst;
if (f == NULL) {
f = malloc(sizeof(struct unyaffs2_fstree));
if (f == NULL)
return NULL;
}
/* initialize */
memset(f, 0, sizeof(struct unyaffs2_fstree));
return f;
}
static void
unyaffs2_objtree_exit (struct unyaffs2_fstree *fst)
{
return unyaffs2_objtree_cleanup(fst->root);
Android 制作yaffs2 以及unyaffs(解压yaffs2)工具
4星 · 超过85%的资源 需积分: 10 43 浏览量
2012-02-11
18:52:26
上传
评论
收藏 35KB GZ 举报
性能侠客行
- 粉丝: 5
- 资源: 10
最新资源
- 《Fundamentals of Power Electronics》翻译-3.1 直流变压器模型
- 111111111111111111
- Motorbike Physics Tool v1.5.6
- RF System Design ppt-射频系统设计
- torchvision resnet18 计算相似度
- 250+ Stylized Mountain & Cave Textures
- foobar2000v1.2.0.apk
- Web开发 技术关键词: React 内容关键词: 前端UI库 用途: 开发交互式用户界面
- 三菱PLC例程源码三菱CC-LINK配置和变频器通信程序(注释)
- 三菱PLC例程源码三菱A系列程序
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页