summaryrefslogtreecommitdiff
path: root/mkfs.jffs2.c
diff options
context:
space:
mode:
authorRicard Wanderlof <ricard.wanderlof@axis.com>2007-12-20 22:46:38 +1100
committerJosh Boyer <jwboyer@gmail.com>2007-12-20 09:34:52 -0600
commit6fb0083666f126d5c0df0c67c30effcb806b5987 (patch)
tree05a55ee32aaa9152b5b876686cec4005af5ad84b /mkfs.jffs2.c
parent1ba6959299cb386faf178317b21ffd61689246b5 (diff)
mkfs.jffs2: Set mkfs.jffs2 page size runtime instead of fixed
This patch reads the default PAGE_SIZE from sysconf(), i.e. the system mkfs.jffs2 is running on, instead of just setting it to 4096 (which of course is valid for most systems but not all). This is useful if mkfs.jffs2 is running on the target system, e.g. to create a backup image during firmware upgrade, so that the page size does not have to be set explicitly using a command line parameter. The --pagesize option is supported just as before. If the user has not set the page size explicitly with --pagesize, and the system page size is anything other than 4096, warn the user that an unusual page size is being used, since this behavior is different from before. Signed-off-by Ricard Wanderlöf <ricardw@axis.com> . Signed-off-by: Josh Boyer <jwboyer@gmail.com>
Diffstat (limited to 'mkfs.jffs2.c')
-rw-r--r--mkfs.jffs2.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/mkfs.jffs2.c b/mkfs.jffs2.c
index 2228ee1..2f2c371 100644
--- a/mkfs.jffs2.c
+++ b/mkfs.jffs2.c
@@ -706,9 +706,9 @@ static unsigned char ffbuf[16] =
0xff, 0xff, 0xff, 0xff, 0xff
};
-/* We default to 4096, per x86. When building a fs for
- * 64-bit arches and whatnot, use the --pagesize=SIZE option */
-int page_size = 4096;
+/* We set this at start of main() using sysconf(), -1 means we don't know */
+/* When building an fs for non-native systems, use --pagesize=SIZE option */
+int page_size = -1;
#include "compr.h"
@@ -1660,9 +1660,16 @@ int main(int argc, char **argv)
struct filesystem_entry *root;
char *compr_name = NULL;
int compr_prior = -1;
+ int warn_page_size = 0;
jffs2_compressors_init();
+ page_size = sysconf(_SC_PAGESIZE);
+ if (page_size < 0) /* System doesn't know so ... */
+ page_size = 4096; /* ... we make an educated guess */
+ if (page_size != 4096)
+ warn_page_size = 1; /* warn user if page size not 4096 */
+
while ((opt = getopt_long(argc, argv,
"D:d:r:s:o:qUPfh?vVe:lbp::nc:m:x:X:Lty:i:", long_options, &c)) >= 0)
{
@@ -1685,6 +1692,7 @@ int main(int argc, char **argv)
case 's':
page_size = strtol(optarg, NULL, 0);
+ warn_page_size = 0; /* set by user, so don't need to warn */
break;
case 'o':
@@ -1843,6 +1851,10 @@ int main(int argc, char **argv)
#endif
}
}
+ if (warn_page_size) {
+ error_msg("Page size for this system is by default %d", page_size);
+ error_msg("Use the --pagesize=SIZE option if this is not what you want");
+ }
if (out_fd == -1) {
if (isatty(1)) {
error_msg_and_die(helptext);