]> www.infradead.org Git - mtd-utils.git/commitdiff
mkfs.jffs2: Set mkfs.jffs2 page size runtime instead of fixed
authorRicard Wanderlof <ricard.wanderlof@axis.com>
Thu, 20 Dec 2007 11:46:38 +0000 (22:46 +1100)
committerJosh Boyer <jwboyer@gmail.com>
Thu, 20 Dec 2007 15:34:52 +0000 (09:34 -0600)
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>
mkfs.jffs2.c

index 2228ee103ec3523d27d2398ad3d8589f0a064d7d..2f2c371c008cfdc068e89ac682c8c7b05e7a34a2 100644 (file)
@@ -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);