#include <sys/types.h>#include <stdio.h>#include <sys/stat.h>#include <unistd.h>#include <sys/mman.h>#include <fcntl.h>#include <dirent.h>#include <stdlib.h>#include <errno.h>#include <string.h>#include <stdarg.h>#include <stdint.h>#include <libgen.h>#include <ctype.h>#include <time.h>#include <getopt.h>#include <byteswap.h>#include <zlib.h>#include "crc32.h"#include "mtd/jffs2-user.h"#include "compr.h"Include dependency graph for mkfs.jffs2.c:

Go to the source code of this file.
Data Structures | |
| struct | filesystem_entry |
Defines | |
| #define | _GNU_SOURCE |
| #define | crc32 __complete_crap |
| #define | mkfs_debug_msg(a...) { } |
| #define | min(x, y) ({ typeof((x)) _x = (x); typeof((y)) _y = (y); (_x>_y)?_y:_x; }) |
| #define | PAD(x) (((x)+3)&~3) |
| #define | SCANF_PREFIX "511" |
| #define | SCANF_STRING(s) (s = malloc(512)) |
| #define | GETCWD_SIZE -1 |
| #define | JFFS2_MAX_FILE_SIZE 0xFFFFFFFF |
| #define | JFFS2_MAX_SYMLINK_LEN 254 |
| #define | write_xattr_entry(x) |
Functions | |
| static void | verror_msg (const char *s, va_list p) |
| static void | error_msg (const char *s,...) |
| static void | error_msg_and_die (const char *s,...) |
| static void | vperror_msg (const char *s, va_list p) |
| static void | perror_msg (const char *s,...) |
| static void | perror_msg_and_die (const char *s,...) |
| void * | xmalloc (size_t size) |
| void * | xcalloc (size_t nmemb, size_t size) |
| void * | xrealloc (void *ptr, size_t size) |
| char * | xstrdup (const char *s) |
| char * | xreadlink (const char *path) |
| static FILE * | xfopen (const char *path, const char *mode) |
| static struct filesystem_entry * | find_filesystem_entry (struct filesystem_entry *dir, char *fullname, uint32_t type) |
| static struct filesystem_entry * | add_host_filesystem_entry (char *name, char *path, unsigned long uid, unsigned long gid, unsigned long mode, dev_t rdev, struct filesystem_entry *parent) |
| static struct filesystem_entry * | recursive_add_host_directory (struct filesystem_entry *parent, char *targetpath, char *hostpath) |
| int | snprintf (char *str, size_t n, const char *fmt,...) |
| static int | interpret_table_entry (struct filesystem_entry *root, char *line) |
| static int | parse_device_table (struct filesystem_entry *root, FILE *file) |
| static void | cleanup (struct filesystem_entry *dir) |
| static void | full_write (int fd, const void *buf, int len) |
| static void | padblock (void) |
| static void | pad (int req) |
| static void | padword (void) |
| static void | pad_block_if_less_than (int req) |
| static void | write_dirent (struct filesystem_entry *e) |
| static unsigned int | write_regular_file (struct filesystem_entry *e) |
| static void | write_symlink (struct filesystem_entry *e) |
| static void | write_pipe (struct filesystem_entry *e) |
| static void | write_special_file (struct filesystem_entry *e) |
| static void | recursive_populate_directory (struct filesystem_entry *dir) |
| static void | create_target_filesystem (struct filesystem_entry *root) |
| int | load_next_block () |
| void | process_buffer (int inp_size) |
| void | parse_image () |
| int | main (int argc, char **argv) |
Variables | |
| static int | out_fd = -1 |
| static int | in_fd = -1 |
| static char | default_rootdir [] = "." |
| static char * | rootdir = default_rootdir |
| static int | verbose = 0 |
| static int | squash_uids = 0 |
| static int | squash_perms = 0 |
| static int | fake_times = 0 |
| int | target_endian = __BYTE_ORDER |
| static const char *const | app_name = "mkfs.jffs2" |
| static const char *const | memory_exhausted = "memory exhausted" |
| static uint32_t | ino = 0 |
| static uint8_t * | file_buffer = NULL |
| static int | out_ofs = 0 |
| static int | erase_block_size = 65536 |
| static int | pad_fs_size = 0 |
| static int | add_cleanmarkers = 1 |
| static struct jffs2_unknown_node | cleanmarker |
| static int | cleanmarker_size = sizeof(cleanmarker) |
| static unsigned char | ffbuf [16] |
| int | page_size = 4096 |
| static struct option | long_options [] |
| static char * | helptext |
| static char * | revtext = "$Revision: 1.1.1.1 $" |
| #define _GNU_SOURCE |
Definition at line 52 of file mkfs.jffs2.c.
| #define crc32 __complete_crap |
Definition at line 74 of file mkfs.jffs2.c.
Referenced by create_target_filesystem(), png_calculate_crc(), png_reset_crc(), write_dirent(), write_pipe(), write_regular_file(), write_special_file(), and write_symlink().
| #define GETCWD_SIZE -1 |
| #define JFFS2_MAX_FILE_SIZE 0xFFFFFFFF |
| #define JFFS2_MAX_SYMLINK_LEN 254 |
Definition at line 85 of file mkfs.jffs2.c.
| #define mkfs_debug_msg | ( | a... | ) | { } |
Definition at line 84 of file mkfs.jffs2.c.
Referenced by write_pipe(), write_regular_file(), and write_symlink().
| #define SCANF_PREFIX "511" |
| #define write_xattr_entry | ( | x | ) |
| static struct filesystem_entry* add_host_filesystem_entry | ( | char * | name, | |
| char * | path, | |||
| unsigned long | uid, | |||
| unsigned long | gid, | |||
| unsigned long | mode, | |||
| dev_t | rdev, | |||
| struct filesystem_entry * | parent | |||
| ) | [static] |
Definition at line 282 of file mkfs.jffs2.c.
References error_msg_and_die(), fake_times, filesystem_entry::files, free(), filesystem_entry::fullname, filesystem_entry::hostname, filesystem_entry::link, memset(), filesystem_entry::name, filesystem_entry::next, filesystem_entry::parent, filesystem_entry::path, filesystem_entry::prev, filesystem_entry::sb, squash_perms, squash_uids, time, xcalloc(), xreadlink(), and xstrdup().
Referenced by interpret_table_entry(), and recursive_add_host_directory().
| static void cleanup | ( | struct filesystem_entry * | dir | ) | [static] |
Definition at line 630 of file mkfs.jffs2.c.
References e, filesystem_entry::files, free(), and filesystem_entry::prev.
Referenced by main().
| static void create_target_filesystem | ( | struct filesystem_entry * | root | ) | [static] |
Definition at line 1373 of file mkfs.jffs2.c.
References add_cleanmarkers, cleanmarker, cleanmarker_size, crc32, ffbuf, full_write(), ino, min, out_fd, out_ofs, pad(), pad_fs_size, padblock(), recursive_populate_directory(), and filesystem_entry::sb.
Referenced by main().
| static void error_msg | ( | const char * | s, | |
| ... | ||||
| ) | [static] |
Definition at line 121 of file mkfs.jffs2.c.
References putc(), stderr, and verror_msg().
Referenced by interpret_table_entry(), recursive_add_host_directory(), recursive_populate_directory(), write_regular_file(), and write_symlink().
| static void error_msg_and_die | ( | const char * | s, | |
| ... | ||||
| ) | [static] |
Definition at line 131 of file mkfs.jffs2.c.
References exit, putc(), stderr, and verror_msg().
Referenced by add_host_filesystem_entry(), interpret_table_entry(), main(), xcalloc(), xmalloc(), xrealloc(), and xstrdup().
| static struct filesystem_entry* find_filesystem_entry | ( | struct filesystem_entry * | dir, | |
| char * | fullname, | |||
| uint32_t | type | |||
| ) | [static] |
Definition at line 242 of file mkfs.jffs2.c.
References e, filesystem_entry::files, and filesystem_entry::sb.
Referenced by interpret_table_entry().
| static void full_write | ( | int | fd, | |
| const void * | buf, | |||
| int | len | |||
| ) | [static] |
Definition at line 683 of file mkfs.jffs2.c.
References out_ofs, perror_msg_and_die(), and write.
Referenced by create_target_filesystem(), pad(), pad_block_if_less_than(), padblock(), padword(), write_dirent(), write_pipe(), write_regular_file(), write_special_file(), and write_symlink().
| static int interpret_table_entry | ( | struct filesystem_entry * | root, | |
| char * | line | |||
| ) | [static] |
Definition at line 480 of file mkfs.jffs2.c.
References add_host_filesystem_entry(), error_msg(), error_msg_and_die(), find_filesystem_entry(), free(), mode, name, filesystem_entry::parent, rootdir, filesystem_entry::sb, SCANF_PREFIX, SCANF_STRING, start, and type.
Referenced by parse_device_table().
| int load_next_block | ( | ) |
Definition at line 1477 of file mkfs.jffs2.c.
References erase_block_size, file_buffer, in_fd, and read.
Referenced by parse_image().
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 1613 of file mkfs.jffs2.c.
References add_cleanmarkers, cleanmarker, cleanmarker_size, cleanup(), create_target_filesystem(), default_rootdir, erase_block_size, error_msg_and_die(), exit, fake_times, free(), GETCWD_SIZE, in_fd, malloc(), filesystem_entry::next, out_fd, pad_fs_size, page_size, parse_device_table(), parse_image(), perror_msg_and_die(), recursive_add_host_directory(), rootdir, s, squash_perms, squash_uids, stderr, target_endian, units, xfopen(), and xstrdup().
| static void pad | ( | int | req | ) | [static] |
Definition at line 710 of file mkfs.jffs2.c.
References ffbuf, full_write(), and out_fd.
Referenced by create_target_filesystem(), and pad_block_if_less_than().
| static void pad_block_if_less_than | ( | int | req | ) | [inline, static] |
Definition at line 730 of file mkfs.jffs2.c.
References add_cleanmarkers, cleanmarker, cleanmarker_size, erase_block_size, full_write(), out_fd, out_ofs, pad(), padblock(), and padword().
Referenced by write_dirent(), write_pipe(), write_regular_file(), write_special_file(), and write_symlink().
| static void padblock | ( | void | ) | [static] |
Definition at line 702 of file mkfs.jffs2.c.
References erase_block_size, ffbuf, full_write(), min, out_fd, and out_ofs.
Referenced by create_target_filesystem(), and pad_block_if_less_than().
| static void padword | ( | void | ) | [inline, static] |
Definition at line 723 of file mkfs.jffs2.c.
References ffbuf, full_write(), out_fd, and out_ofs.
Referenced by pad_block_if_less_than(), write_dirent(), write_pipe(), write_regular_file(), write_special_file(), and write_symlink().
| static int parse_device_table | ( | struct filesystem_entry * | root, | |
| FILE * | file | |||
| ) | [static] |
Definition at line 586 of file mkfs.jffs2.c.
References free(), interpret_table_entry(), length, squash_perms, and squash_uids.
Referenced by main().
| void parse_image | ( | ) |
Definition at line 1591 of file mkfs.jffs2.c.
References erase_block_size, exit, file_buffer, free(), in_fd, load_next_block(), malloc(), out_fd, and process_buffer().
Referenced by main().
| static void perror_msg | ( | const char * | s, | |
| ... | ||||
| ) | [static] |
| static void perror_msg_and_die | ( | const char * | s, | |
| ... | ||||
| ) | [static] |
Definition at line 163 of file mkfs.jffs2.c.
References exit, and vperror_msg().
Referenced by full_write(), main(), recursive_add_host_directory(), write_regular_file(), and xfopen().
| void process_buffer | ( | int | inp_size | ) |
Definition at line 1488 of file mkfs.jffs2.c.
References file_buffer, ino, memcpy(), name, PAD, and type.
Referenced by parse_image().
| static struct filesystem_entry* recursive_add_host_directory | ( | struct filesystem_entry * | parent, | |
| char * | targetpath, | |||
| char * | hostpath | |||
| ) | [static] |
Definition at line 369 of file mkfs.jffs2.c.
References add_host_filesystem_entry(), error_msg(), free(), n, filesystem_entry::parent, and perror_msg_and_die().
Referenced by main().
| static void recursive_populate_directory | ( | struct filesystem_entry * | dir | ) | [static] |
Definition at line 1271 of file mkfs.jffs2.c.
References e, error_msg(), filesystem_entry::files, filesystem_entry::fullname, write_pipe(), write_regular_file(), write_special_file(), write_symlink(), and write_xattr_entry.
Referenced by create_target_filesystem().
| int snprintf | ( | char * | str, | |
| size_t | n, | |||
| const char * | fmt, | |||
| ... | ||||
| ) | [inline] |
Definition at line 451 of file mkfs.jffs2.c.
Referenced by _snd_config_evaluate(), open_ctl(), parse_array_def(), safe_strtod(), snd_config_get_ascii(), snd_config_hooks_call(), and snd_func_pcm_args_by_class().
| static void verror_msg | ( | const char * | s, | |
| va_list | p | |||
| ) | [static] |
Definition at line 115 of file mkfs.jffs2.c.
References app_name, stderr, and stdout.
Referenced by error_msg(), error_msg_and_die(), and vperror_msg().
| static void vperror_msg | ( | const char * | s, | |
| va_list | p | |||
| ) | [static] |
Definition at line 142 of file mkfs.jffs2.c.
References stderr, and verror_msg().
Referenced by perror_msg(), and perror_msg_and_die().
| static void write_dirent | ( | struct filesystem_entry * | e | ) | [static] |
Definition at line 751 of file mkfs.jffs2.c.
References crc32, e, full_write(), memset(), name, out_fd, pad_block_if_less_than(), padword(), and version.
Referenced by write_pipe(), write_regular_file(), write_special_file(), and write_symlink().
| static void write_pipe | ( | struct filesystem_entry * | e | ) | [static] |
Definition at line 955 of file mkfs.jffs2.c.
References crc32, e, full_write(), ino, memset(), mkfs_debug_msg, out_fd, pad_block_if_less_than(), padword(), and write_dirent().
Referenced by recursive_populate_directory().
| static unsigned int write_regular_file | ( | struct filesystem_entry * | e | ) | [static] |
Definition at line 782 of file mkfs.jffs2.c.
References buf, crc32, e, erase_block_size, error_msg(), fd, free(), full_write(), ino, JFFS2_MAX_FILE_SIZE, memset(), mkfs_debug_msg, out_fd, out_ofs, pad_block_if_less_than(), padword(), page_size, perror_msg_and_die(), read, space, wbuf, write_dirent(), and xmalloc().
Referenced by recursive_populate_directory().
| static void write_special_file | ( | struct filesystem_entry * | e | ) | [static] |
Definition at line 996 of file mkfs.jffs2.c.
References crc32, e, full_write(), ino, memset(), out_fd, pad_block_if_less_than(), padword(), and write_dirent().
Referenced by recursive_populate_directory().
| static void write_symlink | ( | struct filesystem_entry * | e | ) | [static] |
Definition at line 907 of file mkfs.jffs2.c.
References crc32, e, error_msg(), full_write(), ino, JFFS2_MAX_SYMLINK_LEN, memset(), mkfs_debug_msg, out_fd, pad_block_if_less_than(), padword(), and write_dirent().
Referenced by recursive_populate_directory().
| void* xcalloc | ( | size_t | nmemb, | |
| size_t | size | |||
| ) |
Definition at line 183 of file mkfs.jffs2.c.
References error_msg_and_die(), memory_exhausted, and ptr.
Referenced by add_host_filesystem_entry().
| static FILE* xfopen | ( | const char * | path, | |
| const char * | mode | |||
| ) | [static] |
Definition at line 234 of file mkfs.jffs2.c.
References fp, and perror_msg_and_die().
Referenced by main().
| void* xmalloc | ( | size_t | size | ) |
Definition at line 174 of file mkfs.jffs2.c.
References error_msg_and_die(), malloc(), memory_exhausted, and ptr.
Referenced by write_regular_file().
| char* xreadlink | ( | const char * | path | ) |
Definition at line 213 of file mkfs.jffs2.c.
References app_name, buf, perror_msg(), and xrealloc().
Referenced by add_host_filesystem_entry().
| void* xrealloc | ( | void * | ptr, | |
| size_t | size | |||
| ) |
Definition at line 192 of file mkfs.jffs2.c.
References error_msg_and_die(), and memory_exhausted.
Referenced by xreadlink().
| char* xstrdup | ( | const char * | s | ) |
Definition at line 200 of file mkfs.jffs2.c.
References error_msg_and_die(), memory_exhausted, and t.
Referenced by add_host_filesystem_entry(), and main().
int add_cleanmarkers = 1 [static] |
Definition at line 669 of file mkfs.jffs2.c.
Referenced by create_target_filesystem(), main(), and pad_block_if_less_than().
const char* const app_name = "mkfs.jffs2" [static] |
struct jffs2_unknown_node cleanmarker [static] |
Definition at line 670 of file mkfs.jffs2.c.
Referenced by create_target_filesystem(), main(), and pad_block_if_less_than().
int cleanmarker_size = sizeof(cleanmarker) [static] |
Definition at line 671 of file mkfs.jffs2.c.
Referenced by create_target_filesystem(), main(), and pad_block_if_less_than().
char default_rootdir[] = "." [static] |
int erase_block_size = 65536 [static] |
Definition at line 667 of file mkfs.jffs2.c.
Referenced by load_next_block(), main(), pad_block_if_less_than(), padblock(), parse_image(), and write_regular_file().
int fake_times = 0 [static] |
unsigned char ffbuf[16] [static] |
Initial value:
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff
}
Definition at line 672 of file mkfs.jffs2.c.
Referenced by create_target_filesystem(), pad(), padblock(), and padword().
uint8_t* file_buffer = NULL [static] |
Definition at line 665 of file mkfs.jffs2.c.
Referenced by load_next_block(), parse_image(), and process_buffer().
char* helptext [static] |
Definition at line 1435 of file mkfs.jffs2.c.
int in_fd = -1 [static] |
Definition at line 104 of file mkfs.jffs2.c.
Referenced by load_next_block(), main(), and parse_image().
uint32_t ino = 0 [static] |
Definition at line 664 of file mkfs.jffs2.c.
Referenced by create_target_filesystem(), process_buffer(), write_pipe(), write_regular_file(), write_special_file(), and write_symlink().
struct option long_options[] [static] |
Initial value:
{
{"pad", 2, NULL, 'p'},
{"root", 1, NULL, 'r'},
{"pagesize", 1, NULL, 's'},
{"eraseblock", 1, NULL, 'e'},
{"output", 1, NULL, 'o'},
{"help", 0, NULL, 'h'},
{"verbose", 0, NULL, 'v'},
{"version", 0, NULL, 'V'},
{"big-endian", 0, NULL, 'b'},
{"little-endian", 0, NULL, 'l'},
{"no-cleanmarkers", 0, NULL, 'n'},
{"cleanmarkers", 0, NULL, 0},
{"cleanmarker", 1, NULL, 'c'},
{"squash", 0, NULL, 'q'},
{"squash-uids", 0, NULL, 'U'},
{"squash-perms", 0, NULL, 'P'},
{"faketime", 0, NULL, 'f'},
{"devtable", 1, NULL, 'D'},
{"compression-mode", 1, NULL, 'm'},
{"disable-compressor", 1, NULL, 'x'},
{"test-compression", 0, NULL, 't'},
{"compressor-priority", 1, NULL, 'y'},
{"incremental", 1, NULL, 'i'},
{"with-xattr", 0, NULL, 1000 },
{"with-selinux", 0, NULL, 1001 },
{"with-posix-acl", 0, NULL, 1002 },
{NULL, 0, NULL, 0}
}
Definition at line 1405 of file mkfs.jffs2.c.
const char* const memory_exhausted = "memory exhausted" [static] |
Definition at line 113 of file mkfs.jffs2.c.
Referenced by xcalloc(), xmalloc(), xrealloc(), and xstrdup().
int out_fd = -1 [static] |
Definition at line 103 of file mkfs.jffs2.c.
Referenced by create_target_filesystem(), main(), pad(), pad_block_if_less_than(), padblock(), padword(), parse_image(), write_dirent(), write_pipe(), write_regular_file(), write_special_file(), and write_symlink().
int out_ofs = 0 [static] |
Definition at line 666 of file mkfs.jffs2.c.
Referenced by create_target_filesystem(), full_write(), pad_block_if_less_than(), padblock(), padword(), and write_regular_file().
int pad_fs_size = 0 [static] |
| int page_size = 4096 |
char* revtext = "$Revision: 1.1.1.1 $" [static] |
Definition at line 1475 of file mkfs.jffs2.c.
char* rootdir = default_rootdir [static] |
int squash_perms = 0 [static] |
Definition at line 109 of file mkfs.jffs2.c.
Referenced by add_host_filesystem_entry(), main(), and parse_device_table().
int squash_uids = 0 [static] |
Definition at line 108 of file mkfs.jffs2.c.
Referenced by add_host_filesystem_entry(), main(), and parse_device_table().
| int target_endian = __BYTE_ORDER |
int verbose = 0 [static] |
Definition at line 107 of file mkfs.jffs2.c.
1.5.1