-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
11,142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
*.dylib | ||
|
||
# Executables | ||
jffs2extract | ||
*.exe | ||
*.out | ||
*.app | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
LDFLAGS=-lz | ||
CFLAGS=-Iinclude | ||
|
||
all: jffs2extract | ||
|
||
clean: | ||
rm -f jffs2extract.o minilzo.o jffs2extract | ||
|
||
jffs2extract: jffs2extract.o minilzo.o | ||
|
||
%.o: %.c | ||
$(CC) -c $(CFLAGS) $< -o $@ | ||
|
||
.PHONY: clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#define __BYTEORDER | ||
#define __bswap_16(x) \ | ||
((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)) | ||
#define __bswap_32(x) \ | ||
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ | ||
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) | ||
#define __bswap_64(x) \ | ||
((((x) & 0xff00000000000000ull) >> 56) \ | ||
| (((x) & 0x00ff000000000000ull) >> 40) \ | ||
| (((x) & 0x0000ff0000000000ull) >> 24) \ | ||
| (((x) & 0x000000ff00000000ull) >> 8) \ | ||
| (((x) & 0x00000000ff000000ull) << 8) \ | ||
| (((x) & 0x0000000000ff0000ull) << 24) \ | ||
| (((x) & 0x000000000000ff00ull) << 40) \ | ||
| (((x) & 0x00000000000000ffull) << 56)) | ||
|
||
#define bswap_16 __bswap_16 | ||
#define bswap_32 __bswap_32 | ||
#define bswap_64 __bswap_64 | ||
|
||
#ifdef WORDS_BIGENDIAN | ||
# define int32_little(x) ((int32_t)(__bswap_32 (x))) | ||
# define int16_little(x) ((int16_t)(__bswap_16 (x))) | ||
# define uint32_little(x) ((uint32_t)(__bswap_32 (x))) | ||
# define uint16_little(x) ((uint16_t)(__bswap_16 (x))) | ||
# define int32_big(x) (x) | ||
# define int16_big(x) (x) | ||
# define uint32_big(x) (x) | ||
# define uint16_big(x) (x) | ||
|
||
# else | ||
# define int32_little(x) (x) | ||
# define int16_little(x) (x) | ||
# define uint32_little(x) (x) | ||
# define uint16_little(x) (x) | ||
# define int32_big(x) ((int32_t)(__bswap_32 (x))) | ||
# define int16_big(x) ((int16_t)(__bswap_16 (x))) | ||
# define uint32_big(x) ((uint32_t)(__bswap_32 (x))) | ||
# define uint16_big(x) ((uint16_t)(__bswap_16 (x))) | ||
# endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
* Copyright (c) Artem Bityutskiy, 2007, 2008 | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
*/ | ||
|
||
#ifndef __MTD_UTILS_COMMON_H__ | ||
#define __MTD_UTILS_COMMON_H__ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <ctype.h> | ||
#include <string.h> | ||
#include <fcntl.h> | ||
#include <errno.h> | ||
#ifndef __APPLE__ | ||
#include <features.h> | ||
#endif | ||
#include <inttypes.h> | ||
|
||
#ifndef PROGRAM_NAME | ||
# error "You must define PROGRAM_NAME before including this header" | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifndef MIN /* some C lib headers define this for us */ | ||
#define MIN(a, b) ((a) < (b) ? (a) : (b)) | ||
#endif | ||
#ifndef MAX | ||
#define MAX(a, b) ((a) > (b) ? (a) : (b)) | ||
#endif | ||
#define min(a, b) MIN(a, b) /* glue for linux kernel source */ | ||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) | ||
|
||
#ifndef O_CLOEXEC | ||
#define O_CLOEXEC 0 | ||
#endif | ||
|
||
/* define a print format specifier for off_t */ | ||
#ifdef __USE_FILE_OFFSET64 | ||
#define PRIxoff_t PRIx64 | ||
#define PRIdoff_t PRId64 | ||
#else | ||
#define PRIxoff_t "l"PRIx32 | ||
#define PRIdoff_t "l"PRId32 | ||
#endif | ||
|
||
/* Verbose messages */ | ||
#define bareverbose(verbose, fmt, ...) do { \ | ||
if (verbose) \ | ||
printf(fmt, ##__VA_ARGS__); \ | ||
} while(0) | ||
#define verbose(verbose, fmt, ...) \ | ||
bareverbose(verbose, "%s: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__) | ||
|
||
/* Normal messages */ | ||
#define normsg_cont(fmt, ...) do { \ | ||
printf("%s: " fmt, PROGRAM_NAME, ##__VA_ARGS__); \ | ||
} while(0) | ||
#define normsg(fmt, ...) do { \ | ||
normsg_cont(fmt "\n", ##__VA_ARGS__); \ | ||
} while(0) | ||
|
||
/* Error messages */ | ||
#define errmsg(fmt, ...) ({ \ | ||
fprintf(stderr, "%s: error!: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__); \ | ||
-1; \ | ||
}) | ||
#define errmsg_die(fmt, ...) do { \ | ||
exit(errmsg(fmt, ##__VA_ARGS__)); \ | ||
} while(0) | ||
|
||
/* System error messages */ | ||
#define sys_errmsg(fmt, ...) ({ \ | ||
int _err = errno; \ | ||
errmsg(fmt, ##__VA_ARGS__); \ | ||
fprintf(stderr, "%*serror %d (%s)\n", (int)sizeof(PROGRAM_NAME) + 1,\ | ||
"", _err, strerror(_err)); \ | ||
-1; \ | ||
}) | ||
#define sys_errmsg_die(fmt, ...) do { \ | ||
exit(sys_errmsg(fmt, ##__VA_ARGS__)); \ | ||
} while(0) | ||
|
||
/* Warnings */ | ||
#define warnmsg(fmt, ...) do { \ | ||
fprintf(stderr, "%s: warning!: " fmt "\n", PROGRAM_NAME, ##__VA_ARGS__); \ | ||
} while(0) | ||
|
||
static inline int is_power_of_2(unsigned long long n) | ||
{ | ||
return (n != 0 && ((n & (n - 1)) == 0)); | ||
} | ||
|
||
/** | ||
* simple_strtoX - convert a hex/dec/oct string into a number | ||
* @snum: buffer to convert | ||
* @error: set to 1 when buffer isn't fully consumed | ||
* | ||
* These functions are similar to the standard strtoX() functions, but they are | ||
* a little bit easier to use if you want to convert full string of digits into | ||
* the binary form. The typical usage: | ||
* | ||
* int error = 0; | ||
* unsigned long num; | ||
* | ||
* num = simple_strtoul(str, &error); | ||
* if (error || ... if needed, your check that num is not out of range ...) | ||
* error_happened(); | ||
*/ | ||
#define simple_strtoX(func, type) \ | ||
static inline type simple_##func(const char *snum, int *error) \ | ||
{ \ | ||
char *endptr; \ | ||
type ret = func(snum, &endptr, 0); \ | ||
\ | ||
if (error && (!*snum || *endptr)) { \ | ||
errmsg("%s: unable to parse the number '%s'", #func, snum); \ | ||
*error = 1; \ | ||
} \ | ||
\ | ||
return ret; \ | ||
} | ||
simple_strtoX(strtol, long int) | ||
simple_strtoX(strtoll, long long int) | ||
simple_strtoX(strtoul, unsigned long int) | ||
simple_strtoX(strtoull, unsigned long long int) | ||
|
||
/* Simple version-printing for utils */ | ||
#define common_print_version() \ | ||
do { \ | ||
printf("%s %s\n", PROGRAM_NAME, VERSION); \ | ||
} while (0) | ||
|
||
#include "xalloc.h" | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* !__MTD_UTILS_COMMON_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* $Id: jffs2-user.h,v 1.1 2004/05/05 11:57:54 dwmw2 Exp $ | ||
* | ||
* JFFS2 definitions for use in user space only | ||
*/ | ||
|
||
#ifndef __JFFS2_USER_H__ | ||
#define __JFFS2_USER_H__ | ||
|
||
/* This file is blessed for inclusion by userspace */ | ||
#include "jffs2.h" | ||
#ifdef __APPLE__ | ||
#define __LITTLE_ENDIAN 1234 | ||
#define __BIG_ENDIAN 1234 | ||
#define __BYTE_ORDER __LITTLE_ENDIAN | ||
#include "byteswap-osx.h" | ||
#else | ||
#include <endian.h> | ||
#include <byteswap.h> | ||
#endif | ||
#undef cpu_to_je16 | ||
#undef cpu_to_je32 | ||
#undef cpu_to_jemode | ||
#undef je16_to_cpu | ||
#undef je32_to_cpu | ||
#undef jemode_to_cpu | ||
|
||
extern int target_endian; | ||
|
||
#define t16(x) ((target_endian==__BYTE_ORDER)?(x):bswap_16((x))) | ||
#define t32(x) ((target_endian==__BYTE_ORDER)?(x):bswap_32((x))) | ||
|
||
#define cpu_to_je16(x) ((jint16_t)t16(x)) | ||
#define cpu_to_je32(x) ((jint32_t)t32(x)) | ||
#define cpu_to_jemode(x) ((jmode_t)t32(x)) | ||
|
||
#define je16_to_cpu(x) (t16((x).v16)) | ||
#define je32_to_cpu(x) (t32((x).v32)) | ||
#define jemode_to_cpu(x) (t32((x).m)) | ||
|
||
#define le16_to_cpu(x) (__BYTE_ORDER==__LITTLE_ENDIAN ? (x) : bswap_16(x)) | ||
#define le32_to_cpu(x) (__BYTE_ORDER==__LITTLE_ENDIAN ? (x) : bswap_32(x)) | ||
#define cpu_to_le16(x) (__BYTE_ORDER==__LITTLE_ENDIAN ? (x) : bswap_16(x)) | ||
#define cpu_to_le32(x) (__BYTE_ORDER==__LITTLE_ENDIAN ? (x) : bswap_32(x)) | ||
|
||
/* XATTR/POSIX-ACL related definition */ | ||
/* Namespaces copied from xattr.h and posix_acl_xattr.h */ | ||
#define XATTR_USER_PREFIX "user." | ||
#define XATTR_USER_PREFIX_LEN (sizeof (XATTR_USER_PREFIX) - 1) | ||
#define XATTR_SECURITY_PREFIX "security." | ||
#define XATTR_SECURITY_PREFIX_LEN (sizeof (XATTR_SECURITY_PREFIX) - 1) | ||
#define POSIX_ACL_XATTR_ACCESS "system.posix_acl_access" | ||
#define POSIX_ACL_XATTR_ACCESS_LEN (sizeof (POSIX_ACL_XATTR_ACCESS) - 1) | ||
#define POSIX_ACL_XATTR_DEFAULT "system.posix_acl_default" | ||
#define POSIX_ACL_XATTR_DEFAULT_LEN (sizeof (POSIX_ACL_XATTR_DEFAULT) - 1) | ||
#define XATTR_TRUSTED_PREFIX "trusted." | ||
#define XATTR_TRUSTED_PREFIX_LEN (sizeof (XATTR_TRUSTED_PREFIX) - 1) | ||
|
||
struct jffs2_acl_entry { | ||
jint16_t e_tag; | ||
jint16_t e_perm; | ||
jint32_t e_id; | ||
}; | ||
|
||
struct jffs2_acl_entry_short { | ||
jint16_t e_tag; | ||
jint16_t e_perm; | ||
}; | ||
|
||
struct jffs2_acl_header { | ||
jint32_t a_version; | ||
}; | ||
|
||
/* copied from include/linux/posix_acl_xattr.h */ | ||
#define POSIX_ACL_XATTR_VERSION 0x0002 | ||
|
||
struct posix_acl_xattr_entry { | ||
uint16_t e_tag; | ||
uint16_t e_perm; | ||
uint32_t e_id; | ||
}; | ||
|
||
struct posix_acl_xattr_header { | ||
uint32_t a_version; | ||
struct posix_acl_xattr_entry a_entries[0]; | ||
}; | ||
|
||
#endif /* __JFFS2_USER_H__ */ |
Oops, something went wrong.