]> www.infradead.org Git - mtd-utils.git/commitdiff
Fixup whitespace
authorJosh Boyer <jwboyer@gmail.com>
Tue, 10 Oct 2006 01:49:57 +0000 (20:49 -0500)
committerJosh Boyer <jwboyer@gmail.com>
Tue, 10 Oct 2006 01:49:57 +0000 (20:49 -0500)
Signed-off-by: Josh Boyer <jwboyer@gmail.com>
33 files changed:
compr.c
compr.h
compr_rtime.c
compr_zlib.c
crc32.h
doc_loadbios.c
docfdisk.c
flash_erase.c
flash_eraseall.c
flash_info.c
flash_lock.c
flash_otp_dump.c
flash_otp_info.c
flash_otp_lock.c
flash_otp_write.c
flash_unlock.c
flashcp.c
ftl_check.c
ftl_format.c
jffs-dump.c
jffs2dump.c
jffs2reader.c
mkfs.jffs.c
mkfs.jffs2.c
mtd_debug.c
nanddump.c
nandwrite.c
nftl_format.c
nftldump.c
rfddump.c
rfdformat.c
summary.h
sumtool.c

diff --git a/compr.c b/compr.c
index 4f7087a476319a51830744ad1af14de7dc290b74..239abf7605ffa2c7d74e99642d04eb1dd5bd621e 100644 (file)
--- a/compr.c
+++ b/compr.c
@@ -23,48 +23,48 @@ extern int page_size;
 #define LIST_HEAD_INIT(name) { &(name), &(name) }
 
 #define LIST_HEAD(name) \
-        struct list_head name = LIST_HEAD_INIT(name)
+       struct list_head name = LIST_HEAD_INIT(name)
 
 static inline void __list_add(struct list_head *new,
-                              struct list_head *prev,
-                              struct list_head *next)
+               struct list_head *prev,
+               struct list_head *next)
 {
-        next->prev = new;
-        new->next = next;
-        new->prev = prev;
-        prev->next = new;
+       next->prev = new;
+       new->next = next;
+       new->prev = prev;
+       prev->next = new;
 }
 
 static inline void list_add(struct list_head *new, struct list_head *head)
 {
-        __list_add(new, head, head->next);
+       __list_add(new, head, head->next);
 }
 
 static inline void list_add_tail(struct list_head *new, struct list_head *head)
 {
-        __list_add(new, head->prev, head);
+       __list_add(new, head->prev, head);
 }
 
 static inline void __list_del(struct list_head *prev, struct list_head *next)
 {
-        next->prev = prev;
-        prev->next = next;
+       next->prev = prev;
+       prev->next = next;
 }
 
 static inline void list_del(struct list_head *entry)
 {
-        __list_del(entry->prev, entry->next);
-        entry->next = (void *) 0;
-        entry->prev = (void *) 0;
+       __list_del(entry->prev, entry->next);
+       entry->next = (void *) 0;
+       entry->prev = (void *) 0;
 }
 
 #define list_entry(ptr, type, member) \
-        ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
+       ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
 
 #define list_for_each_entry(pos, head, member)                          \
-        for (pos = list_entry((head)->next, typeof(*pos), member);      \
-             &pos->member != (head);                                    \
-             pos = list_entry(pos->member.next, typeof(*pos), member))
+       for (pos = list_entry((head)->next, typeof(*pos), member);      \
+                       &pos->member != (head);                                    \
+                       pos = list_entry(pos->member.next, typeof(*pos), member))
 
 
 /* Available compressors are on this list */
@@ -75,12 +75,12 @@ static int jffs2_compression_mode = JFFS2_COMPR_MODE_PRIORITY;
 
 void jffs2_set_compression_mode(int mode)
 {
-        jffs2_compression_mode = mode;
+       jffs2_compression_mode = mode;
 }
 
 int jffs2_get_compression_mode(void)
 {
-        return jffs2_compression_mode;
+       return jffs2_compression_mode;
 }
 
 /* Statistics for blocks stored without compression */
@@ -94,19 +94,19 @@ static unsigned char *jffs2_compression_check_buf = NULL;
 
 void jffs2_compression_check_set(int yesno)
 {
-        jffs2_compression_check = yesno;
+       jffs2_compression_check = yesno;
 }
 
 int jffs2_compression_check_get(void)
 {
-        return jffs2_compression_check;
+       return jffs2_compression_check;
 }
 
 static int jffs2_error_cnt = 0;
 
 int jffs2_compression_check_errorcnt_get(void)
 {
-        return jffs2_error_cnt;
+       return jffs2_error_cnt;
 }
 
 #define JFFS2_BUFFER_FILL 0x55
@@ -115,55 +115,55 @@ int jffs2_compression_check_errorcnt_get(void)
    the buffer for buffer overflow test */
 static void jffs2_decompression_test_prepare(unsigned char *buf, int size)
 {
-        memset(buf,JFFS2_BUFFER_FILL,size+1);
+       memset(buf,JFFS2_BUFFER_FILL,size+1);
 }
 
 /* Called after compression (if compression_check is setted) to test the result */
 static void jffs2_decompression_test(struct jffs2_compressor *compr,
-                                     unsigned char *data_in, unsigned char *output_buf,
-                                     uint32_t cdatalen, uint32_t datalen, uint32_t buf_size)
+               unsigned char *data_in, unsigned char *output_buf,
+               uint32_t cdatalen, uint32_t datalen, uint32_t buf_size)
 {
-        uint32_t i;
-
-        /* buffer overflow test */
-        for (i=buf_size;i>cdatalen;i--) {
-                if (output_buf[i]!=JFFS2_BUFFER_FILL) {
-                        fprintf(stderr,"COMPR_ERROR: buffer overflow at %s. "
-                                    "(bs=%d csize=%d b[%d]=%d)\n", compr->name,
-                                    buf_size, cdatalen, i, (int)(output_buf[i]));
-                        jffs2_error_cnt++;
-                        return;
-                }
-        }
-        /* allocing temporary buffer for decompression */
-        if (!jffs2_compression_check_buf) {
-                jffs2_compression_check_buf = malloc(page_size);
-                if (!jffs2_compression_check_buf) {
-                        fprintf(stderr,"No memory for buffer allocation. Compression check disabled.\n");
-                        jffs2_compression_check = 0;
-                        return;
-                }
-        }
-        /* decompressing */
-        if (!compr->decompress) {
-                fprintf(stderr,"JFFS2 compression check: there is no decompress function at %s.\n", compr->name);
-                jffs2_error_cnt++;
-                return;
-        }
-        if (compr->decompress(output_buf,jffs2_compression_check_buf,cdatalen,datalen,NULL)) {
-                fprintf(stderr,"JFFS2 compression check: decompression failed at %s.\n", compr->name);
-                jffs2_error_cnt++;
-        }
-        /* validate decompression */
-        else {
-                for (i=0;i<datalen;i++) {
-                        if (data_in[i]!=jffs2_compression_check_buf[i]) {
-                                fprintf(stderr,"JFFS2 compression check: data mismatch at %s (pos %d).\n", compr->name, i);
-                                jffs2_error_cnt++;
-                                break;
-                        }
-                }
-        }
+       uint32_t i;
+
+       /* buffer overflow test */
+       for (i=buf_size;i>cdatalen;i--) {
+               if (output_buf[i]!=JFFS2_BUFFER_FILL) {
+                       fprintf(stderr,"COMPR_ERROR: buffer overflow at %s. "
+                                       "(bs=%d csize=%d b[%d]=%d)\n", compr->name,
+                                       buf_size, cdatalen, i, (int)(output_buf[i]));
+                       jffs2_error_cnt++;
+                       return;
+               }
+       }
+       /* allocing temporary buffer for decompression */
+       if (!jffs2_compression_check_buf) {
+               jffs2_compression_check_buf = malloc(page_size);
+               if (!jffs2_compression_check_buf) {
+                       fprintf(stderr,"No memory for buffer allocation. Compression check disabled.\n");
+                       jffs2_compression_check = 0;
+                       return;
+               }
+       }
+       /* decompressing */
+       if (!compr->decompress) {
+               fprintf(stderr,"JFFS2 compression check: there is no decompress function at %s.\n", compr->name);
+               jffs2_error_cnt++;
+               return;
+       }
+       if (compr->decompress(output_buf,jffs2_compression_check_buf,cdatalen,datalen,NULL)) {
+               fprintf(stderr,"JFFS2 compression check: decompression failed at %s.\n", compr->name);
+               jffs2_error_cnt++;
+       }
+       /* validate decompression */
+       else {
+               for (i=0;i<datalen;i++) {
+                       if (data_in[i]!=jffs2_compression_check_buf[i]) {
+                               fprintf(stderr,"JFFS2 compression check: data mismatch at %s (pos %d).\n", compr->name, i);
+                               jffs2_error_cnt++;
+                               break;
+                       }
+               }
+       }
 }
 
 /* jffs2_compress:
@@ -185,305 +185,305 @@ static void jffs2_decompression_test(struct jffs2_compressor *compr,
  * *datalen accordingly to show the amount of data which were compressed.
  */
 uint16_t jffs2_compress( unsigned char *data_in, unsigned char **cpage_out,
-                        uint32_t *datalen, uint32_t *cdatalen)
+               uint32_t *datalen, uint32_t *cdatalen)
 {
        int ret = JFFS2_COMPR_NONE;
-        int compr_ret;
-        struct jffs2_compressor *this, *best=NULL;
-        unsigned char *output_buf = NULL, *tmp_buf;
-        uint32_t orig_slen, orig_dlen;
-        uint32_t best_slen=0, best_dlen=0;
-
-        switch (jffs2_compression_mode) {
-        case JFFS2_COMPR_MODE_NONE:
-                break;
-        case JFFS2_COMPR_MODE_PRIORITY:
-                orig_slen = *datalen;
-                orig_dlen = *cdatalen;
-                output_buf = malloc(orig_dlen+jffs2_compression_check);
-                if (!output_buf) {
-                        fprintf(stderr,"mkfs.jffs2: No memory for compressor allocation. Compression failed.\n");
-                        goto out;
-                }
-                list_for_each_entry(this, &jffs2_compressor_list, list) {
-                        /* Skip decompress-only backwards-compatibility and disabled modules */
-                        if ((!this->compress)||(this->disabled))
-                                continue;
-
-                        this->usecount++;
-
-                        if (jffs2_compression_check) /*preparing output buffer for testing buffer overflow */
-                                jffs2_decompression_test_prepare(output_buf, orig_dlen);
-
-                        *datalen  = orig_slen;
-                        *cdatalen = orig_dlen;
-                        compr_ret = this->compress(data_in, output_buf, datalen, cdatalen, NULL);
-                        this->usecount--;
-                        if (!compr_ret) {
-                                ret = this->compr;
-                                this->stat_compr_blocks++;
-                                this->stat_compr_orig_size += *datalen;
-                                this->stat_compr_new_size  += *cdatalen;
-                                if (jffs2_compression_check)
-                                        jffs2_decompression_test(this, data_in, output_buf, *cdatalen, *datalen, orig_dlen);
-                                break;
-                        }
-                }
-                if (ret == JFFS2_COMPR_NONE) free(output_buf);
-                break;
-        case JFFS2_COMPR_MODE_SIZE:
-                orig_slen = *datalen;
-                orig_dlen = *cdatalen;
-                list_for_each_entry(this, &jffs2_compressor_list, list) {
-                        /* Skip decompress-only backwards-compatibility and disabled modules */
-                        if ((!this->compress)||(this->disabled))
-                                continue;
-                        /* Allocating memory for output buffer if necessary */
-                        if ((this->compr_buf_size<orig_dlen+jffs2_compression_check)&&(this->compr_buf)) {
-                                free(this->compr_buf);
-                                this->compr_buf_size=0;
-                                this->compr_buf=NULL;
-                        }
-                        if (!this->compr_buf) {
-                                tmp_buf = malloc(orig_dlen+jffs2_compression_check);
-                                if (!tmp_buf) {
-                                        fprintf(stderr,"mkfs.jffs2: No memory for compressor allocation. (%d bytes)\n",orig_dlen);
-                                        continue;
-                                }
-                                else {
-                                        this->compr_buf = tmp_buf;
-                                        this->compr_buf_size = orig_dlen;
-                                }
-                        }
-                        this->usecount++;
-                        if (jffs2_compression_check) /*preparing output buffer for testing buffer overflow */
-                                jffs2_decompression_test_prepare(this->compr_buf,this->compr_buf_size);
-                        *datalen  = orig_slen;
-                        *cdatalen = orig_dlen;
-                        compr_ret = this->compress(data_in, this->compr_buf, datalen, cdatalen, NULL);
-                        this->usecount--;
-                        if (!compr_ret) {
-                                if (jffs2_compression_check)
-                                    jffs2_decompression_test(this, data_in, this->compr_buf, *cdatalen, *datalen, this->compr_buf_size);
-                                if ((!best_dlen)||(best_dlen>*cdatalen)) {
-                                        best_dlen = *cdatalen;
-                                        best_slen = *datalen;
-                                        best = this;
-                                }
-                        }
-                }
-                if (best_dlen) {
-                        *cdatalen = best_dlen;
-                        *datalen  = best_slen;
-                        output_buf = best->compr_buf;
-                        best->compr_buf = NULL;
-                        best->compr_buf_size = 0;
-                        best->stat_compr_blocks++;
-                        best->stat_compr_orig_size += best_slen;
-                        best->stat_compr_new_size  += best_dlen;
-                        ret = best->compr;
-                }
-                break;
-        default:
-                fprintf(stderr,"mkfs.jffs2: unknow compression mode.\n");
-        }
- out:
-        if (ret == JFFS2_COMPR_NONE) {
-               *cpage_out = data_in;
-               *datalen = *cdatalen;
-                none_stat_compr_blocks++;
-                none_stat_compr_size += *datalen;
-        }
-        else {
-                *cpage_out = output_buf;
-        }
+       int compr_ret;
+       struct jffs2_compressor *this, *best=NULL;
+       unsigned char *output_buf = NULL, *tmp_buf;
+       uint32_t orig_slen, orig_dlen;
+       uint32_t best_slen=0, best_dlen=0;
+
+       switch (jffs2_compression_mode) {
+               case JFFS2_COMPR_MODE_NONE:
+                       break;
+               case JFFS2_COMPR_MODE_PRIORITY:
+                       orig_slen = *datalen;
+                       orig_dlen = *cdatalen;
+                       output_buf = malloc(orig_dlen+jffs2_compression_check);
+                       if (!output_buf) {
+                               fprintf(stderr,"mkfs.jffs2: No memory for compressor allocation. Compression failed.\n");
+                               goto out;
+                       }
+                       list_for_each_entry(this, &jffs2_compressor_list, list) {
+                               /* Skip decompress-only backwards-compatibility and disabled modules */
+                               if ((!this->compress)||(this->disabled))
+                                       continue;
+
+                               this->usecount++;
+
+                               if (jffs2_compression_check) /*preparing output buffer for testing buffer overflow */
+                                       jffs2_decompression_test_prepare(output_buf, orig_dlen);
+
+                               *datalen  = orig_slen;
+                               *cdatalen = orig_dlen;
+                               compr_ret = this->compress(data_in, output_buf, datalen, cdatalen, NULL);
+                               this->usecount--;
+                               if (!compr_ret) {
+                                       ret = this->compr;
+                                       this->stat_compr_blocks++;
+                                       this->stat_compr_orig_size += *datalen;
+                                       this->stat_compr_new_size  += *cdatalen;
+                                       if (jffs2_compression_check)
+                                               jffs2_decompression_test(this, data_in, output_buf, *cdatalen, *datalen, orig_dlen);
+                                       break;
+                               }
+                       }
+                       if (ret == JFFS2_COMPR_NONE) free(output_buf);
+                       break;
+               case JFFS2_COMPR_MODE_SIZE:
+                       orig_slen = *datalen;
+                       orig_dlen = *cdatalen;
+                       list_for_each_entry(this, &jffs2_compressor_list, list) {
+                               /* Skip decompress-only backwards-compatibility and disabled modules */
+                               if ((!this->compress)||(this->disabled))
+                                       continue;
+                               /* Allocating memory for output buffer if necessary */
+                               if ((this->compr_buf_size<orig_dlen+jffs2_compression_check)&&(this->compr_buf)) {
+                                       free(this->compr_buf);
+                                       this->compr_buf_size=0;
+                                       this->compr_buf=NULL;
+                               }
+                               if (!this->compr_buf) {
+                                       tmp_buf = malloc(orig_dlen+jffs2_compression_check);
+                                       if (!tmp_buf) {
+                                               fprintf(stderr,"mkfs.jffs2: No memory for compressor allocation. (%d bytes)\n",orig_dlen);
+                                               continue;
+                                       }
+                                       else {
+                                               this->compr_buf = tmp_buf;
+                                               this->compr_buf_size = orig_dlen;
+                                       }
+                               }
+                               this->usecount++;
+                               if (jffs2_compression_check) /*preparing output buffer for testing buffer overflow */
+                                       jffs2_decompression_test_prepare(this->compr_buf,this->compr_buf_size);
+                               *datalen  = orig_slen;
+                               *cdatalen = orig_dlen;
+                               compr_ret = this->compress(data_in, this->compr_buf, datalen, cdatalen, NULL);
+                               this->usecount--;
+                               if (!compr_ret) {
+                                       if (jffs2_compression_check)
+                                               jffs2_decompression_test(this, data_in, this->compr_buf, *cdatalen, *datalen, this->compr_buf_size);
+                                       if ((!best_dlen)||(best_dlen>*cdatalen)) {
+                                               best_dlen = *cdatalen;
+                                               best_slen = *datalen;
+                                               best = this;
+                                       }
+                               }
+                       }
+                       if (best_dlen) {
+                               *cdatalen = best_dlen;
+                               *datalen  = best_slen;
+                               output_buf = best->compr_buf;
+                               best->compr_buf = NULL;
+                               best->compr_buf_size = 0;
+                               best->stat_compr_blocks++;
+                               best->stat_compr_orig_size += best_slen;
+                               best->stat_compr_new_size  += best_dlen;
+                               ret = best->compr;
+                       }
+                       break;
+               default:
+                       fprintf(stderr,"mkfs.jffs2: unknow compression mode.\n");
+       }
+out:
+       if (ret == JFFS2_COMPR_NONE) {
+               *cpage_out = data_in;
+               *datalen = *cdatalen;
+               none_stat_compr_blocks++;
+               none_stat_compr_size += *datalen;
+       }
+       else {
+               *cpage_out = output_buf;
+       }
        return ret;
 }
 
 
 int jffs2_register_compressor(struct jffs2_compressor *comp)
 {
-        struct jffs2_compressor *this;
-
-        if (!comp->name) {
-                fprintf(stderr,"NULL compressor name at registering JFFS2 compressor. Failed.\n");
-                return -1;
-        }
-        comp->compr_buf_size=0;
-        comp->compr_buf=NULL;
-        comp->usecount=0;
-        comp->stat_compr_orig_size=0;
-        comp->stat_compr_new_size=0;
-        comp->stat_compr_blocks=0;
-        comp->stat_decompr_blocks=0;
-
-        list_for_each_entry(this, &jffs2_compressor_list, list) {
-                if (this->priority < comp->priority) {
-                        list_add(&comp->list, this->list.prev);
-                        goto out;
-                }
-        }
-        list_add_tail(&comp->list, &jffs2_compressor_list);
+       struct jffs2_compressor *this;
+
+       if (!comp->name) {
+               fprintf(stderr,"NULL compressor name at registering JFFS2 compressor. Failed.\n");
+               return -1;
+       }
+       comp->compr_buf_size=0;
+       comp->compr_buf=NULL;
+       comp->usecount=0;
+       comp->stat_compr_orig_size=0;
+       comp->stat_compr_new_size=0;
+       comp->stat_compr_blocks=0;
+       comp->stat_decompr_blocks=0;
+
+       list_for_each_entry(this, &jffs2_compressor_list, list) {
+               if (this->priority < comp->priority) {
+                       list_add(&comp->list, this->list.prev);
+                       goto out;
+               }
+       }
+       list_add_tail(&comp->list, &jffs2_compressor_list);
 out:
-        return 0;
+       return 0;
 }
 
 int jffs2_unregister_compressor(struct jffs2_compressor *comp)
 {
 
-        if (comp->usecount) {
-                fprintf(stderr,"mkfs.jffs2: Compressor modul is in use. Unregister failed.\n");
-                return -1;
-        }
-        list_del(&comp->list);
+       if (comp->usecount) {
+               fprintf(stderr,"mkfs.jffs2: Compressor modul is in use. Unregister failed.\n");
+               return -1;
+       }
+       list_del(&comp->list);
 
-        return 0;
+       return 0;
 }
 
 #define JFFS2_STAT_BUF_SIZE 16000
 
 char *jffs2_list_compressors(void)
 {
-        struct jffs2_compressor *this;
-        char *buf, *act_buf;
-
-        act_buf = buf = malloc(JFFS2_STAT_BUF_SIZE);
-        list_for_each_entry(this, &jffs2_compressor_list, list) {
-                act_buf += sprintf(act_buf, "%10s priority:%d ", this->name, this->priority);
-                if ((this->disabled)||(!this->compress))
-                        act_buf += sprintf(act_buf,"disabled");
-                else
-                        act_buf += sprintf(act_buf,"enabled");
-                act_buf += sprintf(act_buf,"\n");
-        }
-        return buf;
+       struct jffs2_compressor *this;
+       char *buf, *act_buf;
+
+       act_buf = buf = malloc(JFFS2_STAT_BUF_SIZE);
+       list_for_each_entry(this, &jffs2_compressor_list, list) {
+               act_buf += sprintf(act_buf, "%10s priority:%d ", this->name, this->priority);
+               if ((this->disabled)||(!this->compress))
+                       act_buf += sprintf(act_buf,"disabled");
+               else
+                       act_buf += sprintf(act_buf,"enabled");
+               act_buf += sprintf(act_buf,"\n");
+       }
+       return buf;
 }
 
 char *jffs2_stats(void)
 {
-        struct jffs2_compressor *this;
-        char *buf, *act_buf;
-
-        act_buf = buf = malloc(JFFS2_STAT_BUF_SIZE);
-
-        act_buf += sprintf(act_buf,"Compression mode: ");
-        switch (jffs2_compression_mode) {
-        case JFFS2_COMPR_MODE_NONE:
-                act_buf += sprintf(act_buf,"none");
-                break;
-        case JFFS2_COMPR_MODE_PRIORITY:
-                act_buf += sprintf(act_buf,"priority");
-                break;
-        case JFFS2_COMPR_MODE_SIZE:
-                act_buf += sprintf(act_buf,"size");
-                break;
-        default:
-                act_buf += sprintf(act_buf,"unkown");
-                break;
-        }
-        act_buf += sprintf(act_buf,"\nCompressors:\n");
-        act_buf += sprintf(act_buf,"%10s             ","none");
-        act_buf += sprintf(act_buf,"compr: %d blocks (%d)  decompr: %d blocks\n", none_stat_compr_blocks,
-                           none_stat_compr_size, none_stat_decompr_blocks);
-        list_for_each_entry(this, &jffs2_compressor_list, list) {
-                act_buf += sprintf(act_buf,"%10s (prio:%d) ",this->name,this->priority);
-                if ((this->disabled)||(!this->compress))
-                        act_buf += sprintf(act_buf,"- ");
-                else
-                        act_buf += sprintf(act_buf,"+ ");
-                act_buf += sprintf(act_buf,"compr: %d blocks (%d/%d)  decompr: %d blocks ", this->stat_compr_blocks,
-                                   this->stat_compr_new_size, this->stat_compr_orig_size,
-                                   this->stat_decompr_blocks);
-                act_buf += sprintf(act_buf,"\n");
-        }
-        return buf;
+       struct jffs2_compressor *this;
+       char *buf, *act_buf;
+
+       act_buf = buf = malloc(JFFS2_STAT_BUF_SIZE);
+
+       act_buf += sprintf(act_buf,"Compression mode: ");
+       switch (jffs2_compression_mode) {
+               case JFFS2_COMPR_MODE_NONE:
+                       act_buf += sprintf(act_buf,"none");
+                       break;
+               case JFFS2_COMPR_MODE_PRIORITY:
+                       act_buf += sprintf(act_buf,"priority");
+                       break;
+               case JFFS2_COMPR_MODE_SIZE:
+                       act_buf += sprintf(act_buf,"size");
+                       break;
+               default:
+                       act_buf += sprintf(act_buf,"unkown");
+                       break;
+       }
+       act_buf += sprintf(act_buf,"\nCompressors:\n");
+       act_buf += sprintf(act_buf,"%10s             ","none");
+       act_buf += sprintf(act_buf,"compr: %d blocks (%d)  decompr: %d blocks\n", none_stat_compr_blocks,
+                       none_stat_compr_size, none_stat_decompr_blocks);
+       list_for_each_entry(this, &jffs2_compressor_list, list) {
+               act_buf += sprintf(act_buf,"%10s (prio:%d) ",this->name,this->priority);
+               if ((this->disabled)||(!this->compress))
+                       act_buf += sprintf(act_buf,"- ");
+               else
+                       act_buf += sprintf(act_buf,"+ ");
+               act_buf += sprintf(act_buf,"compr: %d blocks (%d/%d)  decompr: %d blocks ", this->stat_compr_blocks,
+                               this->stat_compr_new_size, this->stat_compr_orig_size,
+                               this->stat_decompr_blocks);
+               act_buf += sprintf(act_buf,"\n");
+       }
+       return buf;
 }
 
 int jffs2_set_compression_mode_name(const char *name)
 {
-        if (!strcmp("none",name)) {
-                jffs2_compression_mode = JFFS2_COMPR_MODE_NONE;
-                return 0;
-        }
-        if (!strcmp("priority",name)) {
-                jffs2_compression_mode = JFFS2_COMPR_MODE_PRIORITY;
-                return 0;
-        }
-        if (!strcmp("size",name)) {
-                jffs2_compression_mode = JFFS2_COMPR_MODE_SIZE;
-                return 0;
-        }
-        return 1;
+       if (!strcmp("none",name)) {
+               jffs2_compression_mode = JFFS2_COMPR_MODE_NONE;
+               return 0;
+       }
+       if (!strcmp("priority",name)) {
+               jffs2_compression_mode = JFFS2_COMPR_MODE_PRIORITY;
+               return 0;
+       }
+       if (!strcmp("size",name)) {
+               jffs2_compression_mode = JFFS2_COMPR_MODE_SIZE;
+               return 0;
+       }
+       return 1;
 }
 
 static int jffs2_compressor_Xable(const char *name, int disabled)
 {
-        struct jffs2_compressor *this;
-        list_for_each_entry(this, &jffs2_compressor_list, list) {
-                if (!strcmp(this->name, name)) {
-                        this->disabled = disabled;
-                        return 0;
-                }
-        }
-        return 1;
+       struct jffs2_compressor *this;
+       list_for_each_entry(this, &jffs2_compressor_list, list) {
+               if (!strcmp(this->name, name)) {
+                       this->disabled = disabled;
+                       return 0;
+               }
+       }
+       return 1;
 }
 
 int jffs2_enable_compressor_name(const char *name)
 {
-        return jffs2_compressor_Xable(name, 0);
+       return jffs2_compressor_Xable(name, 0);
 }
 
 int jffs2_disable_compressor_name(const char *name)
 {
-        return jffs2_compressor_Xable(name, 1);
+       return jffs2_compressor_Xable(name, 1);
 }
 
 int jffs2_set_compressor_priority(const char *name, int priority)
 {
-        struct jffs2_compressor *this,*comp;
-        list_for_each_entry(this, &jffs2_compressor_list, list) {
-                if (!strcmp(this->name, name)) {
-                        this->priority = priority;
-                        comp = this;
-                        goto reinsert;
-                }
-        }
-        fprintf(stderr,"mkfs.jffs2: compressor %s not found.\n",name);
-        return 1;
+       struct jffs2_compressor *this,*comp;
+       list_for_each_entry(this, &jffs2_compressor_list, list) {
+               if (!strcmp(this->name, name)) {
+                       this->priority = priority;
+                       comp = this;
+                       goto reinsert;
+               }
+       }
+       fprintf(stderr,"mkfs.jffs2: compressor %s not found.\n",name);
+       return 1;
 reinsert:
-        /* list is sorted in the order of priority, so if
-           we change it we have to reinsert it into the
-           good place */
-        list_del(&comp->list);
-        list_for_each_entry(this, &jffs2_compressor_list, list) {
-                if (this->priority < comp->priority) {
-                        list_add(&comp->list, this->list.prev);
-                        return 0;
-                }
-        }
-        list_add_tail(&comp->list, &jffs2_compressor_list);
-        return 0;
+       /* list is sorted in the order of priority, so if
+          we change it we have to reinsert it into the
+          good place */
+       list_del(&comp->list);
+       list_for_each_entry(this, &jffs2_compressor_list, list) {
+               if (this->priority < comp->priority) {
+                       list_add(&comp->list, this->list.prev);
+                       return 0;
+               }
+       }
+       list_add_tail(&comp->list, &jffs2_compressor_list);
+       return 0;
 }
 
 
 int jffs2_compressors_init(void)
 {
 #ifdef CONFIG_JFFS2_ZLIB
-        jffs2_zlib_init();
+       jffs2_zlib_init();
 #endif
 #ifdef CONFIG_JFFS2_RTIME
-        jffs2_rtime_init();
+       jffs2_rtime_init();
 #endif
-        return 0;
+       return 0;
 }
 
 int jffs2_compressors_exit(void)
 {
 #ifdef CONFIG_JFFS2_RTIME
-        jffs2_rtime_exit();
+       jffs2_rtime_exit();
 #endif
 #ifdef CONFIG_JFFS2_ZLIB
-        jffs2_zlib_exit();
+       jffs2_zlib_exit();
 #endif
-        return 0;
+       return 0;
 }
diff --git a/compr.h b/compr.h
index a30d953e81703272eeb2743d94e5dea614b96e01..3a0d3a1a048a455004201709fe6c0041af4f11b0 100644 (file)
--- a/compr.h
+++ b/compr.h
@@ -52,7 +52,7 @@
 #define KERN_DEBUG
 
 struct list_head {
-        struct list_head *next, *prev;
+       struct list_head *next, *prev;
 };
 
 void jffs2_set_compression_mode(int mode);
@@ -65,22 +65,22 @@ int jffs2_disable_compressor_name(const char *name);
 int jffs2_set_compressor_priority(const char *name, int priority);
 
 struct jffs2_compressor {
-        struct list_head list;
-        int priority;             /* used by prirority comr. mode */
-        char *name;
-        char compr;               /* JFFS2_COMPR_XXX */
-        int (*compress)(unsigned char *data_in, unsigned char *cpage_out,
-                        uint32_t *srclen, uint32_t *destlen, void *model);
-        int (*decompress)(unsigned char *cdata_in, unsigned char *data_out,
-                        uint32_t cdatalen, uint32_t datalen, void *model);
-        int usecount;
-        int disabled;             /* if seted the compressor won't compress */
-        unsigned char *compr_buf; /* used by size compr. mode */
-        uint32_t compr_buf_size;  /* used by size compr. mode */
-        uint32_t stat_compr_orig_size;
-        uint32_t stat_compr_new_size;
-        uint32_t stat_compr_blocks;
-        uint32_t stat_decompr_blocks;
+       struct list_head list;
+       int priority;             /* used by prirority comr. mode */
+       char *name;
+       char compr;               /* JFFS2_COMPR_XXX */
+       int (*compress)(unsigned char *data_in, unsigned char *cpage_out,
+                       uint32_t *srclen, uint32_t *destlen, void *model);
+       int (*decompress)(unsigned char *cdata_in, unsigned char *data_out,
+                       uint32_t cdatalen, uint32_t datalen, void *model);
+       int usecount;
+       int disabled;             /* if seted the compressor won't compress */
+       unsigned char *compr_buf; /* used by size compr. mode */
+       uint32_t compr_buf_size;  /* used by size compr. mode */
+       uint32_t stat_compr_orig_size;
+       uint32_t stat_compr_new_size;
+       uint32_t stat_compr_blocks;
+       uint32_t stat_decompr_blocks;
 };
 
 int jffs2_register_compressor(struct jffs2_compressor *comp);
@@ -90,7 +90,7 @@ int jffs2_compressors_init(void);
 int jffs2_compressors_exit(void);
 
 uint16_t jffs2_compress(unsigned char *data_in, unsigned char **cpage_out,
-                             uint32_t *datalen, uint32_t *cdatalen);
+               uint32_t *datalen, uint32_t *cdatalen);
 
 /* If it is setted, a decompress will be called after every compress */
 void jffs2_compression_check_set(int yesno);
index ab8cce31d4576d5edbe6893a965e2b450a62732b..59f174c6ddc6cf96e5f463e0984860c80f2b6b9f 100644 (file)
@@ -27,7 +27,7 @@
 
 /* _compress returns the compressed size, -1 if bigger */
 static int jffs2_rtime_compress(unsigned char *data_in, unsigned char *cpage_out,
-                  uint32_t *sourcelen, uint32_t *dstlen, void *model)
+               uint32_t *sourcelen, uint32_t *dstlen, void *model)
 {
        short positions[256];
        int outpos = 0;
@@ -35,7 +35,7 @@ static int jffs2_rtime_compress(unsigned char *data_in, unsigned char *cpage_out
 
        memset(positions,0,sizeof(positions));
 
-       while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
+       while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
                int backpos, runlen=0;
                unsigned char value;
 
@@ -47,7 +47,7 @@ static int jffs2_rtime_compress(unsigned char *data_in, unsigned char *cpage_out
                positions[value]=pos;
 
                while ((backpos < pos) && (pos < (*sourcelen)) &&
-                      (data_in[pos]==data_in[backpos++]) && (runlen<255)) {
+                               (data_in[pos]==data_in[backpos++]) && (runlen<255)) {
                        pos++;
                        runlen++;
                }
@@ -67,7 +67,7 @@ static int jffs2_rtime_compress(unsigned char *data_in, unsigned char *cpage_out
 
 
 static int jffs2_rtime_decompress(unsigned char *data_in, unsigned char *cpage_out,
-                     uint32_t srclen, uint32_t destlen, void *model)
+               uint32_t srclen, uint32_t destlen, void *model)
 {
        short positions[256];
        int outpos = 0;
@@ -98,25 +98,25 @@ static int jffs2_rtime_decompress(unsigned char *data_in, unsigned char *cpage_o
                        }
                }
        }
-        return 0;
+       return 0;
 }
 
 
 static struct jffs2_compressor jffs2_rtime_comp = {
-    .priority = JFFS2_RTIME_PRIORITY,
-    .name = "rtime",
-    .disabled = 0,
-    .compr = JFFS2_COMPR_RTIME,
-    .compress = &jffs2_rtime_compress,
-    .decompress = &jffs2_rtime_decompress,
+       .priority = JFFS2_RTIME_PRIORITY,
+       .name = "rtime",
+       .disabled = 0,
+       .compr = JFFS2_COMPR_RTIME,
+       .compress = &jffs2_rtime_compress,
+       .decompress = &jffs2_rtime_decompress,
 };
 
 int jffs2_rtime_init(void)
 {
-    return jffs2_register_compressor(&jffs2_rtime_comp);
+       return jffs2_register_compressor(&jffs2_rtime_comp);
 }
 
 void jffs2_rtime_exit(void)
 {
-    jffs2_unregister_compressor(&jffs2_rtime_comp);
+       jffs2_unregister_compressor(&jffs2_rtime_comp);
 }
index 167946ed5a6f849324becf91b3e5f5b691b1a740..d0976931810f94ec8126d1ae9f1813deccb5348d 100644 (file)
 
 #define min(x,y) ((x)<(y)?(x):(y))
 
-       /* Plan: call deflate() with avail_in == *sourcelen,
-               avail_out = *dstlen - 12 and flush == Z_FINISH.
-               If it doesn't manage to finish, call it again with
-               avail_in == 0 and avail_out set to the remaining 12
-               bytes for it to clean up.
-          Q: Is 12 bytes sufficient?
      */
+/* Plan: call deflate() with avail_in == *sourcelen,
+   avail_out = *dstlen - 12 and flush == Z_FINISH.
+   If it doesn't manage to finish,     call it again with
+   avail_in == 0 and avail_out set to the remaining 12
+   bytes for it to clean up.
+Q: Is 12 bytes sufficient?
+ */
 #define STREAM_END_SPACE 12
 
 int jffs2_zlib_compress(unsigned char *data_in, unsigned char *cpage_out,
-                  uint32_t *sourcelen, uint32_t *dstlen, void *model)
+               uint32_t *sourcelen, uint32_t *dstlen, void *model)
 {
        z_stream strm;
        int ret;
@@ -102,7 +102,7 @@ int jffs2_zlib_compress(unsigned char *data_in, unsigned char *cpage_out,
 }
 
 int jffs2_zlib_decompress(unsigned char *data_in, unsigned char *cpage_out,
-                     uint32_t srclen, uint32_t destlen, void *model)
+               uint32_t srclen, uint32_t destlen, void *model)
 {
        z_stream strm;
        int ret;
@@ -125,24 +125,24 @@ int jffs2_zlib_decompress(unsigned char *data_in, unsigned char *cpage_out,
                ;
 
        inflateEnd(&strm);
-        return 0;
+       return 0;
 }
 
 static struct jffs2_compressor jffs2_zlib_comp = {
-    .priority = JFFS2_ZLIB_PRIORITY,
-    .name = "zlib",
-    .disabled = 0,
-    .compr = JFFS2_COMPR_ZLIB,
-    .compress = &jffs2_zlib_compress,
-    .decompress = &jffs2_zlib_decompress,
+       .priority = JFFS2_ZLIB_PRIORITY,
+       .name = "zlib",
+       .disabled = 0,
+       .compr = JFFS2_COMPR_ZLIB,
+       .compress = &jffs2_zlib_compress,
+       .decompress = &jffs2_zlib_decompress,
 };
 
 int jffs2_zlib_init(void)
 {
-    return jffs2_register_compressor(&jffs2_zlib_comp);
+       return jffs2_register_compressor(&jffs2_zlib_comp);
 }
 
 void jffs2_zlib_exit(void)
 {
-    jffs2_unregister_compressor(&jffs2_zlib_comp);
+       jffs2_unregister_compressor(&jffs2_zlib_comp);
 }
diff --git a/crc32.h b/crc32.h
index f3f8caf930215403a9027970734f1e3019f0141a..ec9c1b18e4e1867ddf26c36de571405b7c377f78 100644 (file)
--- a/crc32.h
+++ b/crc32.h
@@ -9,13 +9,13 @@ extern const uint32_t crc32_table[256];
 
 /* Return a 32-bit CRC of the contents of the buffer. */
 
-static inline uint32_t
+       static inline uint32_t
 crc32(uint32_t val, const void *ss, int len)
 {
        const unsigned char *s = ss;
-        while (--len >= 0)
-                val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
-        return val;
+       while (--len >= 0)
+               val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
+       return val;
 }
 
 #endif
index f7ba8faab4408dce3f98601b6afc11915026d8e2..66e2e6ab53c3300f85c7258fd296bed522e1868d 100644 (file)
@@ -15,135 +15,135 @@ unsigned char databuf[512];
 
 int main(int argc,char **argv)
 {
-   mtd_info_t meminfo;
-   int ifd,ofd;
-   struct stat statbuf;
-   erase_info_t erase;
-   unsigned long retlen, ofs, iplsize, ipltailsize;
-   unsigned char *iplbuf;
-   iplbuf = NULL;
-
-   if (argc < 3) {
-          fprintf(stderr,"You must specify a device,"
-                       " the source firmware file and the offset\n");
-          return 1;
-   }
-
-   // Open and size the device
-   if ((ofd = open(argv[1],O_RDWR)) < 0) {
-          perror("Open flash device");
-          return 1;
-   }
-
-   if ((ifd = open(argv[2], O_RDONLY)) < 0) {
-          perror("Open firmware file\n");
-          close(ofd);
-          return 1;
-   }
-
-   if (fstat(ifd, &statbuf) != 0) {
-          perror("Stat firmware file");
-          goto error;
-   }
+       mtd_info_t meminfo;
+       int ifd,ofd;
+       struct stat statbuf;
+       erase_info_t erase;
+       unsigned long retlen, ofs, iplsize, ipltailsize;
+       unsigned char *iplbuf;
+       iplbuf = NULL;
+
+       if (argc < 3) {
+               fprintf(stderr,"You must specify a device,"
+                               " the source firmware file and the offset\n");
+               return 1;
+       }
+
+       // Open and size the device
+       if ((ofd = open(argv[1],O_RDWR)) < 0) {
+               perror("Open flash device");
+               return 1;
+       }
+
+       if ((ifd = open(argv[2], O_RDONLY)) < 0) {
+               perror("Open firmware file\n");
+               close(ofd);
+               return 1;
+       }
+
+       if (fstat(ifd, &statbuf) != 0) {
+               perror("Stat firmware file");
+               goto error;
+       }
 
 #if 0
-   if (statbuf.st_size > 65536) {
-          printf("Firmware too large (%ld bytes)\n",statbuf.st_size);
-          goto error;
-   }
+       if (statbuf.st_size > 65536) {
+               printf("Firmware too large (%ld bytes)\n",statbuf.st_size);
+               goto error;
+       }
 #endif
 
-   if (ioctl(ofd,MEMGETINFO,&meminfo) != 0) {
-          perror("ioctl(MEMGETINFO)");
-          goto error;
-   }
-
-   iplsize = (ipltailsize = 0);
-   if (argc >= 4) {
-          /* DoC Millennium has IPL in the first 1K of flash memory */
-          /* You may want to specify the offset 1024 to store
-             the firmware next to IPL. */
-          iplsize = strtoul(argv[3], NULL, 0);
-          ipltailsize = iplsize % meminfo.erasesize;
-   }
-
-   if (lseek(ofd, iplsize - ipltailsize, SEEK_SET) < 0) {
-          perror("lseek");
-          goto error;
-   }
-
-   if (ipltailsize) {
-          iplbuf = malloc(ipltailsize);
-          if (iplbuf == NULL) {
-                  fprintf(stderr, "Not enough memory for IPL tail buffer of"
-                       " %lu bytes\n", (unsigned long) ipltailsize);
-                  goto error;
-          }
-          printf("Reading IPL%s area of length %lu at offset %lu\n",
-               (iplsize - ipltailsize) ? " tail" : "",
-               (long unsigned) ipltailsize,
-               (long unsigned) (iplsize - ipltailsize));
-          if (read(ofd, iplbuf, ipltailsize) != ipltailsize) {
-                  perror("read");
-                  goto error;
-          }
-   }
-
-   erase.length = meminfo.erasesize;
-
-   for (ofs = iplsize - ipltailsize ;
-       ofs < iplsize + statbuf.st_size ;
-       ofs += meminfo.erasesize) {
-          erase.start = ofs;
-          printf("Performing Flash Erase of length %lu at offset %lu\n",
-                 (long unsigned) erase.length, (long unsigned) erase.start);
-
-          if (ioctl(ofd,MEMERASE,&erase) != 0) {
-                  perror("ioctl(MEMERASE)");
-                  goto error;
-          }
-   }
-
-   if (lseek(ofd, iplsize - ipltailsize, SEEK_SET) < 0) {
-          perror("lseek");
-          goto error;
-   }
-
-   if (ipltailsize) {
-          printf("Writing IPL%s area of length %lu at offset %lu\n",
-               (iplsize - ipltailsize) ? " tail" : "",
-               (long unsigned) ipltailsize,
-               (long unsigned) (iplsize - ipltailsize));
-          if (write(ofd, iplbuf, ipltailsize) != ipltailsize) {
-                  perror("write");
-                  goto error;
-          }
-   }
-
-   printf("Writing the firmware of length %lu at %lu... ",
-               (unsigned long) statbuf.st_size,
-               (unsigned long) iplsize);
-   do {
-          retlen = read(ifd, databuf, 512);
-          if (retlen < 512)
-            memset(databuf+retlen, 0xff, 512-retlen);
-          if (write(ofd, databuf, 512) != 512) {
-                  perror("write");
-                  goto error;
-          }
-   } while (retlen == 512);
-   printf("Done.\n");
-
-   if (iplbuf != NULL)
-          free(iplbuf);
-   close(ifd);
-   close(ofd);
-   return 0;
+       if (ioctl(ofd,MEMGETINFO,&meminfo) != 0) {
+               perror("ioctl(MEMGETINFO)");
+               goto error;
+       }
+
+       iplsize = (ipltailsize = 0);
+       if (argc >= 4) {
+               /* DoC Millennium has IPL in the first 1K of flash memory */
+               /* You may want to specify the offset 1024 to store
+                  the firmware next to IPL. */
+               iplsize = strtoul(argv[3], NULL, 0);
+               ipltailsize = iplsize % meminfo.erasesize;
+       }
+
+       if (lseek(ofd, iplsize - ipltailsize, SEEK_SET) < 0) {
+               perror("lseek");
+               goto error;
+       }
+
+       if (ipltailsize) {
+               iplbuf = malloc(ipltailsize);
+               if (iplbuf == NULL) {
+                       fprintf(stderr, "Not enough memory for IPL tail buffer of"
+                                       " %lu bytes\n", (unsigned long) ipltailsize);
+                       goto error;
+               }
+               printf("Reading IPL%s area of length %lu at offset %lu\n",
+                               (iplsize - ipltailsize) ? " tail" : "",
+                               (long unsigned) ipltailsize,
+                               (long unsigned) (iplsize - ipltailsize));
+               if (read(ofd, iplbuf, ipltailsize) != ipltailsize) {
+                       perror("read");
+                       goto error;
+               }
+       }
+
+       erase.length = meminfo.erasesize;
+
+       for (ofs = iplsize - ipltailsize ;
+                       ofs < iplsize + statbuf.st_size ;
+                       ofs += meminfo.erasesize) {
+               erase.start = ofs;
+               printf("Performing Flash Erase of length %lu at offset %lu\n",
+                               (long unsigned) erase.length, (long unsigned) erase.start);
+
+               if (ioctl(ofd,MEMERASE,&erase) != 0) {
+                       perror("ioctl(MEMERASE)");
+                       goto error;
+               }
+       }
+
+       if (lseek(ofd, iplsize - ipltailsize, SEEK_SET) < 0) {
+               perror("lseek");
+               goto error;
+       }
+
+       if (ipltailsize) {
+               printf("Writing IPL%s area of length %lu at offset %lu\n",
+                               (iplsize - ipltailsize) ? " tail" : "",
+                               (long unsigned) ipltailsize,
+                               (long unsigned) (iplsize - ipltailsize));
+               if (write(ofd, iplbuf, ipltailsize) != ipltailsize) {
+                       perror("write");
+                       goto error;
+               }
+       }
+
+       printf("Writing the firmware of length %lu at %lu... ",
+                       (unsigned long) statbuf.st_size,
+                       (unsigned long) iplsize);
+       do {
+               retlen = read(ifd, databuf, 512);
+               if (retlen < 512)
+                       memset(databuf+retlen, 0xff, 512-retlen);
+               if (write(ofd, databuf, 512) != 512) {
+                       perror("write");
+                       goto error;
+               }
+       } while (retlen == 512);
+       printf("Done.\n");
+
+       if (iplbuf != NULL)
+               free(iplbuf);
+       close(ifd);
+       close(ofd);
+       return 0;
 
 error:
-   if (iplbuf != NULL)
-          free(iplbuf);
-   close(ifd);
-   close(ofd);
-   return 1;
+       if (iplbuf != NULL)
+               free(iplbuf);
+       close(ifd);
+       close(ofd);
+       return 1;
 }
index 4d2dab4a11a8cbc2ef4f476d030c78a7972c69ac..3732691cc524a9be4a2afd11289a748193dc548c 100644 (file)
@@ -53,32 +53,32 @@ void show_header(int mhoffs) {
 
        bmbits = le32_to_cpu(mh->BlockMultiplierBits);
        printf("  bootRecordID          = %s\n"
-               "  NoOfBootImageBlocks   = %d\n"
-               "  NoOfBinaryPartitions  = %d\n"
-               "  NoOfBDTLPartitions    = %d\n"
-               "  BlockMultiplierBits   = %d\n"
-               "  FormatFlags           = %d\n"
-               "  OsakVersion           = %d.%d.%d.%d\n"
-                "  PercentUsed           = %d\n",
-                mh->bootRecordID, le32_to_cpu(mh->NoOfBootImageBlocks),
-                le32_to_cpu(mh->NoOfBinaryPartitions),
-                le32_to_cpu(mh->NoOfBDTLPartitions),
-                bmbits,
-                le32_to_cpu(mh->FormatFlags),
-                ((unsigned char *) &mh->OsakVersion)[0] & 0xf,
-                ((unsigned char *) &mh->OsakVersion)[1] & 0xf,
-                ((unsigned char *) &mh->OsakVersion)[2] & 0xf,
-                ((unsigned char *) &mh->OsakVersion)[3] & 0xf,
-                le32_to_cpu(mh->PercentUsed));
+                       "  NoOfBootImageBlocks   = %d\n"
+                       "  NoOfBinaryPartitions  = %d\n"
+                       "  NoOfBDTLPartitions    = %d\n"
+                       "  BlockMultiplierBits   = %d\n"
+                       "  FormatFlags           = %d\n"
+                       "  OsakVersion           = %d.%d.%d.%d\n"
+                       "  PercentUsed           = %d\n",
+                       mh->bootRecordID, le32_to_cpu(mh->NoOfBootImageBlocks),
+                       le32_to_cpu(mh->NoOfBinaryPartitions),
+                       le32_to_cpu(mh->NoOfBDTLPartitions),
+                       bmbits,
+                       le32_to_cpu(mh->FormatFlags),
+                       ((unsigned char *) &mh->OsakVersion)[0] & 0xf,
+                       ((unsigned char *) &mh->OsakVersion)[1] & 0xf,
+                       ((unsigned char *) &mh->OsakVersion)[2] & 0xf,
+                       ((unsigned char *) &mh->OsakVersion)[3] & 0xf,
+                       le32_to_cpu(mh->PercentUsed));
 
        numpart = le32_to_cpu(mh->NoOfBinaryPartitions) +
-                 le32_to_cpu(mh->NoOfBDTLPartitions);
+               le32_to_cpu(mh->NoOfBDTLPartitions);
        unitsize = meminfo.erasesize >> bmbits;
        numunits = meminfo.size / unitsize;
        nextunit = mhoffs / unitsize;
        nextunit++;
        printf("Unitsize is %d bytes.  Device has %d units.\n",
-               unitsize, numunits);
+                       unitsize, numunits);
        if (numunits > 32768) {
                printf("WARNING: More than 32768 units! Unexpectedly small BlockMultiplierBits.\n");
        }
@@ -96,24 +96,24 @@ void show_header(int mhoffs) {
                }
                if (start > nextunit) {
                        printf("  Unpartitioned space: %d bytes\n"
-                               "    virtualUnits  = %d\n"
-                               "    firstUnit     = %d\n"
-                               "    lastUnit      = %d\n",
-                               (start - nextunit) * unitsize, start - nextunit,
-                               nextunit, start - 1);
+                                       "    virtualUnits  = %d\n"
+                                       "    firstUnit     = %d\n"
+                                       "    lastUnit      = %d\n",
+                                       (start - nextunit) * unitsize, start - nextunit,
+                                       nextunit, start - 1);
                }
                if (flags & INFTL_BINARY)
                        printf("  Partition %d   (BDK):", i+1);
                else
                        printf("  Partition %d  (BDTL):", i+1);
                printf(" %d bytes\n"
-                       "    virtualUnits  = %d\n"
-                       "    firstUnit     = %d\n"
-                       "    lastUnit      = %d\n"
-                       "    flags         = 0x%x\n"
-                       "    spareUnits    = %d\n",
-                       num * unitsize, num, start, end,
-                       le32_to_cpu(ip->flags), le32_to_cpu(ip->spareUnits));
+                               "    virtualUnits  = %d\n"
+                               "    firstUnit     = %d\n"
+                               "    lastUnit      = %d\n"
+                               "    flags         = 0x%x\n"
+                               "    spareUnits    = %d\n",
+                               num * unitsize, num, start, end,
+                               le32_to_cpu(ip->flags), le32_to_cpu(ip->spareUnits));
                if (num > (1 + end - start)) {
                        printf("ERROR: virtualUnits not consistent with first/lastUnit!\n");
                }
@@ -135,11 +135,11 @@ void show_header(int mhoffs) {
        }
        if (nextunit < numunits) {
                printf("  Unpartitioned space: %d bytes\n"
-                       "    virtualUnits  = %d\n"
-                       "    firstUnit     = %d\n"
-                       "    lastUnit      = %d\n",
-                       (numunits - nextunit) * unitsize, numunits - nextunit,
-                       nextunit, numunits - 1);
+                               "    virtualUnits  = %d\n"
+                               "    firstUnit     = %d\n"
+                               "    lastUnit      = %d\n",
+                               (numunits - nextunit) * unitsize, numunits - nextunit,
+                               nextunit, numunits - 1);
        }
 }
 
@@ -158,10 +158,10 @@ int main(int argc, char **argv)
 
        if (argc < 2) {
                printf(
-"Usage: %s <mtddevice> [<size1> [<size2> [<size3> [<size4]]]]\n"
-"  Sizes are in device units (run with no sizes to show unitsize and current\n"
-"  partitions).  Last size = 0 means go to end of device.\n",
-                       argv[0]);
+                               "Usage: %s <mtddevice> [<size1> [<size2> [<size3> [<size4]]]]\n"
+                               "  Sizes are in device units (run with no sizes to show unitsize and current\n"
+                               "  partitions).  Last size = 0 means go to end of device.\n",
+                               argv[0]);
                return 1;
        }
 
@@ -191,7 +191,7 @@ int main(int argc, char **argv)
        }
 
        printf("Device size is %d bytes.  Erasesize is %d bytes.\n",
-               meminfo.size, meminfo.erasesize);
+                       meminfo.size, meminfo.erasesize);
 
        buf = malloc(meminfo.erasesize);
        oobbuf = malloc((meminfo.erasesize / meminfo.writesize) * meminfo.oobsize);
@@ -242,7 +242,7 @@ int main(int argc, char **argv)
                return 0;
 
        printf("\n"
-"-------------------------------------------------------------------------\n");
+                       "-------------------------------------------------------------------------\n");
 
        unitsize = meminfo.erasesize >> le32_to_cpu(mh->BlockMultiplierBits);
        totblocks = meminfo.size / unitsize;
index cf263fef18cbbacb474cd1666b856d9ee18546ce..fdf991852e7a723a846f67ac6a16e1b60b35e7e5 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * flash_erase.c -- erase parts of a MTD device
-*/
+ */
 
 #include <unistd.h>
 #include <stdlib.h>
@@ -144,7 +144,7 @@ int main(int argc,char *argv[])
 
        if (1 >= argc ||  !strcmp(argv[1], "-h") || !strcmp (argv[1], "--help") ) {
                printf("Usage: flash_erase MTD-device [start] [cnt (# erase blocks)] [lock]\n"
-                      "       flash_erase -h | --help\n") ;
+                               "       flash_erase -h | --help\n") ;
                return 16 ;
        }
 
index 3694e3d3a3c47a469d563f092436d670264cf6ad..5901b2673575d2e549e057c25751907b08ce9b91 100644 (file)
@@ -2,7 +2,7 @@
 
    Copyright (C) 2000 Arcom Control System Ltd
 
-    Renamed to flash_eraseall.c
+   Renamed to flash_eraseall.c
 
    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
@@ -19,7 +19,7 @@
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
    $Id: flash_eraseall.c,v 1.22 2005/02/17 14:55:06 hvr Exp $
-*/
+ */
 #include <sys/types.h>
 #include <stdio.h>
 #include <sys/stat.h>
@@ -107,18 +107,18 @@ int main (int argc, char *argv[])
                        } else {
                                /* Legacy mode */
                                switch (meminfo.oobsize) {
-                               case 8:
-                                       clmpos = 6;
-                                       clmlen = 2;
-                                       break;
-                               case 16:
-                                       clmpos = 8;
-                                       clmlen = 8;
-                                       break;
-                               case 64:
-                                       clmpos = 16;
-                                       clmlen = 8;
-                                       break;
+                                       case 8:
+                                               clmpos = 6;
+                                               clmlen = 2;
+                                               break;
+                                       case 16:
+                                               clmpos = 8;
+                                               clmlen = 8;
+                                               break;
+                                       case 64:
+                                               clmpos = 16;
+                                               clmlen = 8;
+                                               break;
                                }
                        }
                        cleanmarker.totlen = cpu_to_je32(8);
@@ -150,10 +150,10 @@ int main (int argc, char *argv[])
 
                if (!quiet) {
                        printf
-                           ("\rErasing %d Kibyte @ %x -- %2llu %% complete.",
-                            meminfo.erasesize / 1024, erase.start,
-                            (unsigned long long)
-                            erase.start * 100 / meminfo.size);
+                               ("\rErasing %d Kibyte @ %x -- %2llu %% complete.",
+                                meminfo.erasesize / 1024, erase.start,
+                                (unsigned long long)
+                                erase.start * 100 / meminfo.size);
                }
                fflush(stdout);
 
@@ -216,31 +216,31 @@ void process_options (int argc, char *argv[])
                };
 
                int c = getopt_long(argc, argv, short_options,
-                                   long_options, &option_index);
+                               long_options, &option_index);
                if (c == EOF) {
                        break;
                }
 
                switch (c) {
-               case 0:
-                       switch (option_index) {
                        case 0:
-                               display_help();
+                               switch (option_index) {
+                                       case 0:
+                                               display_help();
+                                               break;
+                                       case 1:
+                                               display_version();
+                                               break;
+                               }
                                break;
-                       case 1:
-                               display_version();
+                       case 'q':
+                               quiet = 1;
+                               break;
+                       case 'j':
+                               jffs2 = 1;
+                               break;
+                       case '?':
+                               error = 1;
                                break;
-                       }
-                       break;
-               case 'q':
-                       quiet = 1;
-                       break;
-               case 'j':
-                       jffs2 = 1;
-                       break;
-               case '?':
-                       error = 1;
-                       break;
                }
        }
        if (optind == argc) {
@@ -249,7 +249,7 @@ void process_options (int argc, char *argv[])
        }
        if (error) {
                fprintf(stderr, "Try `%s --help' for more information.\n",
-                       exe_name);
+                               exe_name);
                exit(1);
        }
 
@@ -260,14 +260,14 @@ void process_options (int argc, char *argv[])
 void display_help (void)
 {
        printf("Usage: %s [OPTION] MTD_DEVICE\n"
-              "Erases all of the specified MTD device.\n"
-              "\n"
-              "  -j, --jffs2    format the device for jffs2\n"
-              "  -q, --quiet    don't display progress messages\n"
-              "      --silent   same as --quiet\n"
-              "      --help     display this help and exit\n"
-              "      --version  output version information and exit\n",
-              exe_name);
+                       "Erases all of the specified MTD device.\n"
+                       "\n"
+                       "  -j, --jffs2    format the device for jffs2\n"
+                       "  -q, --quiet    don't display progress messages\n"
+                       "      --silent   same as --quiet\n"
+                       "      --help     display this help and exit\n"
+                       "      --version  output version information and exit\n",
+                       exe_name);
        exit(0);
 }
 
@@ -275,14 +275,14 @@ void display_help (void)
 void display_version (void)
 {
        printf(PROGRAM " " VERSION "\n"
-              "\n"
-              "Copyright (C) 2000 Arcom Control Systems Ltd\n"
-              "\n"
-              PROGRAM " comes with NO WARRANTY\n"
-              "to the extent permitted by law.\n"
-              "\n"
-              "You may redistribute copies of " PROGRAM "\n"
-              "under the terms of the GNU General Public Licence.\n"
-              "See the file `COPYING' for more information.\n");
+                       "\n"
+                       "Copyright (C) 2000 Arcom Control Systems Ltd\n"
+                       "\n"
+                       PROGRAM " comes with NO WARRANTY\n"
+                       "to the extent permitted by law.\n"
+                       "\n"
+                       "You may redistribute copies of " PROGRAM "\n"
+                       "under the terms of the GNU General Public Licence.\n"
+                       "See the file `COPYING' for more information.\n");
        exit(0);
 }
index 7157b9eb32db6e3bb820774094fe25dadbf33452..f5ed1c6ff78023f0e27803f717a981a7062eb981 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * flash_info.c -- print info about a MTD device
-*/
+ */
 
 #include <unistd.h>
 #include <stdlib.h>
@@ -41,13 +41,13 @@ int main(int argc,char *argv[])
                        if(ioctl(Fd, MEMGETREGIONINFO, &reginfo) == 0)
                        {
                                printf("Region %d is at 0x%x with size 0x%x and "
-                                      "has 0x%x blocks\n", i, reginfo.offset,
-                                      reginfo.erasesize, reginfo.numblocks);
+                                               "has 0x%x blocks\n", i, reginfo.offset,
+                                               reginfo.erasesize, reginfo.numblocks);
                        }
                        else
                        {
                                printf("Strange can not read region %d from a %d region device\n",
-                                      i, regcount);
+                                               i, regcount);
                        }
                }
        }
index 1238a3d1d7d20e31d150337605e14f58a0c12a18..dca679456ef1b9faa88899775e460ff561159ba5 100644 (file)
 
 int main(int argc, char *argv[])
 {
-  int fd;
-  struct mtd_info_user mtdInfo;
-  struct erase_info_user mtdLockInfo;
-  int num_sectors;
-  int ofs;
+       int fd;
+       struct mtd_info_user mtdInfo;
+       struct erase_info_user mtdLockInfo;
+       int num_sectors;
+       int ofs;
 
-  /*
-   * Parse command line options
-   */
-  if(argc != 4)
-  {
-    fprintf(stderr, "USAGE: %s <mtd device> <ofs in hex> <num of sectors in decimal or -1 for all sectors>\n", argv[0]);
-    exit(1);
-  }
-  else if(strncmp(argv[1], "/dev/mtd", 8) != 0)
-  {
-    fprintf(stderr, "'%s' is not a MTD device.  Must specify mtd device: /dev/mtd?\n", argv[1]);
-    exit(1);
-  }
+       /*
+        * Parse command line options
+        */
+       if(argc != 4)
+       {
+               fprintf(stderr, "USAGE: %s <mtd device> <ofs in hex> <num of sectors in decimal or -1 for all sectors>\n", argv[0]);
+               exit(1);
+       }
+       else if(strncmp(argv[1], "/dev/mtd", 8) != 0)
+       {
+               fprintf(stderr, "'%s' is not a MTD device.  Must specify mtd device: /dev/mtd?\n", argv[1]);
+               exit(1);
+       }
 
-  fd = open(argv[1], O_RDWR);
-  if(fd < 0)
-  {
-    fprintf(stderr, "Could not open mtd device: %s\n", argv[1]);
-    exit(1);
-  }
+       fd = open(argv[1], O_RDWR);
+       if(fd < 0)
+       {
+               fprintf(stderr, "Could not open mtd device: %s\n", argv[1]);
+               exit(1);
+       }
 
-  if(ioctl(fd, MEMGETINFO, &mtdInfo))
-  {
-    fprintf(stderr, "Could not get MTD device info from %s\n", argv[1]);
-    close(fd);
-    exit(1);
-  }
-  sscanf(argv[2], "%x",&ofs);
-  sscanf(argv[3], "%d",&num_sectors);
-  if(ofs > mtdInfo.size - mtdInfo.erasesize)
-  {
-    fprintf(stderr, "%x is beyond device size %x\n",ofs,(unsigned int)(mtdInfo.size - mtdInfo.erasesize));
-    exit(1);
-  }
+       if(ioctl(fd, MEMGETINFO, &mtdInfo))
+       {
+               fprintf(stderr, "Could not get MTD device info from %s\n", argv[1]);
+               close(fd);
+               exit(1);
+       }
+       sscanf(argv[2], "%x",&ofs);
+       sscanf(argv[3], "%d",&num_sectors);
+       if(ofs > mtdInfo.size - mtdInfo.erasesize)
+       {
+               fprintf(stderr, "%x is beyond device size %x\n",ofs,(unsigned int)(mtdInfo.size - mtdInfo.erasesize));
+               exit(1);
+       }
 
-  if (num_sectors == -1) {
-         num_sectors = mtdInfo.size/mtdInfo.erasesize;
-  }
-  else {
-         if(num_sectors > mtdInfo.size/mtdInfo.erasesize)
-         {
-           fprintf(stderr, "%d are too many sectors, device only has %d\n",num_sectors,(int)(mtdInfo.size/mtdInfo.erasesize));
-           exit(1);
-         }
-  }
+       if (num_sectors == -1) {
+               num_sectors = mtdInfo.size/mtdInfo.erasesize;
+       }
+       else {
+               if(num_sectors > mtdInfo.size/mtdInfo.erasesize)
+               {
+                       fprintf(stderr, "%d are too many sectors, device only has %d\n",num_sectors,(int)(mtdInfo.size/mtdInfo.erasesize));
+                       exit(1);
+               }
+       }
 
-  mtdLockInfo.start = ofs;
-  mtdLockInfo.length = num_sectors * mtdInfo.erasesize;
-  if(ioctl(fd, MEMLOCK, &mtdLockInfo))
-  {
-    fprintf(stderr, "Could not lock MTD device: %s\n", argv[1]);
-    close(fd);
-    exit(1);
-  }
+       mtdLockInfo.start = ofs;
+       mtdLockInfo.length = num_sectors * mtdInfo.erasesize;
+       if(ioctl(fd, MEMLOCK, &mtdLockInfo))
+       {
+               fprintf(stderr, "Could not lock MTD device: %s\n", argv[1]);
+               close(fd);
+               exit(1);
+       }
 
-  return 0;
+       return 0;
 }
 
index b930ca4282c00def5cd71cdf0e254e0e099abde6..a18130d24e670b3c1b6d2703bc2661f18c15962a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * flash_otp_dump.c -- display One-Time-Programm data
-*/
+ */
 
 #include <stdio.h>
 #include <unistd.h>
@@ -35,7 +35,7 @@ int main(int argc,char *argv[])
        }
 
        printf("OTP %s data for %s\n",
-              argv[1][1] == 'f' ? "factory" : "user", argv[2]);
+                       argv[1][1] == 'f' ? "factory" : "user", argv[2]);
        offset = 0;
        while ((ret = read(fd, buf, sizeof(buf)))) {
                if (ret < 0) {
index 3292da797b68c105bb4010f290cd19e6dfe01865..c9486ee54070b34f8ed5046f8b5cf10a66c4d872 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * flash_otp_info.c -- print info about One-Time-Programm data
-*/
+ */
 
 #include <stdio.h>
 #include <unistd.h>
@@ -40,22 +40,22 @@ int main(int argc,char *argv[])
        }
 
        printf("Number of OTP %s blocks on %s: %d\n",
-              argv[1][1] == 'f' ? "factory" : "user", argv[2], val);
+                       argv[1][1] == 'f' ? "factory" : "user", argv[2], val);
 
        if (val > 0) {
                struct otp_info info[val];
 
                ret = ioctl(fd, OTPGETREGIONINFO, &info);
-              if (ret  < 0) {
+               if (ret < 0) {
                        perror("OTPGETREGIONCOUNT");
                        return errno;
                }
 
                for (i = 0; i < val; i++)
                        printf("block %2d:  offset = 0x%04x  "
-                              "size = %2d bytes  %s\n",
-                              i, info[i].start, info[i].length,
-                              info[i].locked ? "[locked]" : "[unlocked]");
+                                       "size = %2d bytes  %s\n",
+                                       i, info[i].start, info[i].length,
+                                       info[i].locked ? "[locked]" : "[unlocked]");
        }
 
        close(fd);
index bd56df39638b5b7703abcd612a77d5b9319705af..d0e06cdb7817e7b686355dd3c05cd442d9fd0ded 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * flash_otp_lock.c -- lock area of One-Time-Program data
-*/
+ */
 
 #include <stdio.h>
 #include <unistd.h>
@@ -50,7 +50,7 @@ int main(int argc,char *argv[])
        }
 
        printf("About to lock OTP user data on %s from 0x%x to 0x%x\n",
-              argv[2], offset, offset + size);
+                       argv[2], offset, offset + size);
        printf("Are you sure (yes|no)? ");
        if (fgets(buf, sizeof(buf), stdin) && strcmp(buf, "yes\n") == 0) {
                struct otp_info info;
index 4cadcdf841952fc05af1682df3cd4320e442faa7..f01df514393885130a1b9d99873393d35fb57649 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * flash_otp_write.c -- write One-Time-Program data
-*/
+ */
 
 #include <stdio.h>
 #include <unistd.h>
index f4d7e207dab968d0d498e3273660d86238fe5c15..648dc4f42d994915e0b881bccfa5f5decb80d9ad 100644 (file)
 
 int main(int argc, char *argv[])
 {
-  int fd;
-  struct mtd_info_user mtdInfo;
-  struct erase_info_user mtdLockInfo;
+       int fd;
+       struct mtd_info_user mtdInfo;
+       struct erase_info_user mtdLockInfo;
 
-  /*
-   * Parse command line options
-   */
-  if(argc != 2)
-  {
-    fprintf(stderr, "USAGE: %s <mtd device>\n", argv[0]);
-    exit(1);
-  }
-  else if(strncmp(argv[1], "/dev/mtd", 8) != 0)
-  {
-    fprintf(stderr, "'%s' is not a MTD device.  Must specify mtd device: /dev/mtd?\n", argv[1]);
-    exit(1);
-  }
+       /*
+        * Parse command line options
+        */
+       if(argc != 2)
+       {
+               fprintf(stderr, "USAGE: %s <mtd device>\n", argv[0]);
+               exit(1);
+       }
+       else if(strncmp(argv[1], "/dev/mtd", 8) != 0)
+       {
+               fprintf(stderr, "'%s' is not a MTD device.  Must specify mtd device: /dev/mtd?\n", argv[1]);
+               exit(1);
+       }
 
-  fd = open(argv[1], O_RDWR);
-  if(fd < 0)
-  {
-    fprintf(stderr, "Could not open mtd device: %s\n", argv[1]);
-    exit(1);
-  }
+       fd = open(argv[1], O_RDWR);
+       if(fd < 0)
+       {
+               fprintf(stderr, "Could not open mtd device: %s\n", argv[1]);
+               exit(1);
+       }
 
-  if(ioctl(fd, MEMGETINFO, &mtdInfo))
-  {
-    fprintf(stderr, "Could not get MTD device info from %s\n", argv[1]);
-    close(fd);
-    exit(1);
-  }
+       if(ioctl(fd, MEMGETINFO, &mtdInfo))
+       {
+               fprintf(stderr, "Could not get MTD device info from %s\n", argv[1]);
+               close(fd);
+               exit(1);
+       }
 
-  mtdLockInfo.start = 0;
-  mtdLockInfo.length = mtdInfo.size;
-  if(ioctl(fd, MEMUNLOCK, &mtdLockInfo))
-  {
-    fprintf(stderr, "Could not unlock MTD device: %s\n", argv[1]);
-    close(fd);
-    exit(1);
-  }
+       mtdLockInfo.start = 0;
+       mtdLockInfo.length = mtdInfo.size;
+       if(ioctl(fd, MEMUNLOCK, &mtdLockInfo))
+       {
+               fprintf(stderr, "Could not unlock MTD device: %s\n", argv[1]);
+               close(fd);
+               exit(1);
+       }
 
-  return 0;
+       return 0;
 }
 
index 8033f5360f9356bca821d8567440719ed95e92b1..64b2eca23108256ea26481d93ee7ece673a93b7f 100644 (file)
--- a/flashcp.c
+++ b/flashcp.c
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (c) 2d3D, Inc.
  * Written by Abraham vd Merwe <abraham@2d3d.co.za>
@@ -79,81 +78,81 @@ typedef int bool;
 
 static void log_printf (int level,const char *fmt, ...)
 {
-   FILE *fp = level == LOG_NORMAL ? stdout : stderr;
-   va_list ap;
-   va_start (ap,fmt);
-   vfprintf (fp,fmt,ap);
-   va_end (ap);
-   fflush (fp);
+       FILE *fp = level == LOG_NORMAL ? stdout : stderr;
+       va_list ap;
+       va_start (ap,fmt);
+       vfprintf (fp,fmt,ap);
+       va_end (ap);
+       fflush (fp);
 }
 
 static void showusage (const char *progname,bool error)
 {
-   int level = error ? LOG_ERROR : LOG_NORMAL;
-
-   log_printf (level,
-                          "\n"
-                          "Flash Copy - Written by Abraham van der Merwe <abraham@2d3d.co.za>\n"
-                          "\n"
-                          "usage: %s [ -v | --verbose ] <filename> <device>\n"
-                          "       %s -h | --help\n"
-                          "\n"
-                          "   -h | --help      Show this help message\n"
-                          "   -v | --verbose   Show progress reports\n"
-                          "   <filename>       File which you want to copy to flash\n"
-                          "   <device>         Flash device to write to (e.g. /dev/mtd0, /dev/mtd1, etc.)\n"
-                          "\n",
-                          progname,progname);
-
-   exit (error ? EXIT_FAILURE : EXIT_SUCCESS);
+       int level = error ? LOG_ERROR : LOG_NORMAL;
+
+       log_printf (level,
+                       "\n"
+                       "Flash Copy - Written by Abraham van der Merwe <abraham@2d3d.co.za>\n"
+                       "\n"
+                       "usage: %s [ -v | --verbose ] <filename> <device>\n"
+                       "       %s -h | --help\n"
+                       "\n"
+                       "   -h | --help      Show this help message\n"
+                       "   -v | --verbose   Show progress reports\n"
+                       "   <filename>       File which you want to copy to flash\n"
+                       "   <device>         Flash device to write to (e.g. /dev/mtd0, /dev/mtd1, etc.)\n"
+                       "\n",
+                       progname,progname);
+
+       exit (error ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 static int safe_open (const char *pathname,int flags)
 {
-   int fd;
+       int fd;
 
-   fd = open (pathname,flags);
-   if (fd < 0)
-        {
+       fd = open (pathname,flags);
+       if (fd < 0)
+       {
                log_printf (LOG_ERROR,"While trying to open %s",pathname);
                if (flags & O_RDWR)
-                 log_printf (LOG_ERROR," for read/write access");
+                       log_printf (LOG_ERROR," for read/write access");
                else if (flags & O_RDONLY)
-                 log_printf (LOG_ERROR," for read access");
+                       log_printf (LOG_ERROR," for read access");
                else if (flags & O_WRONLY)
-                 log_printf (LOG_ERROR," for write access");
+                       log_printf (LOG_ERROR," for write access");
                log_printf (LOG_ERROR,": %m\n");
                exit (EXIT_FAILURE);
-        }
+       }
 
-   return (fd);
+       return (fd);
 }
 
 static void safe_read (int fd,const char *filename,void *buf,size_t count,bool verbose)
 {
-   ssize_t result;
+       ssize_t result;
 
-   result = read (fd,buf,count);
-   if (count != result)
-        {
+       result = read (fd,buf,count);
+       if (count != result)
+       {
                if (verbose) log_printf (LOG_NORMAL,"\n");
                if (result < 0)
-                 {
-                        log_printf (LOG_ERROR,"While reading data from %s: %m\n",filename);
-                        exit (EXIT_FAILURE);
-                 }
+               {
+                       log_printf (LOG_ERROR,"While reading data from %s: %m\n",filename);
+                       exit (EXIT_FAILURE);
+               }
                log_printf (LOG_ERROR,"Short read count returned while reading from %s\n",filename);
                exit (EXIT_FAILURE);
-        }
+       }
 }
 
 static void safe_rewind (int fd,const char *filename)
 {
-   if (lseek (fd,0L,SEEK_SET) < 0)
-        {
+       if (lseek (fd,0L,SEEK_SET) < 0)
+       {
                log_printf (LOG_ERROR,"While seeking to start of %s: %m\n",filename);
                exit (EXIT_FAILURE);
-        }
+       }
 }
 
 /******************************************************************************/
@@ -162,154 +161,154 @@ static int dev_fd = -1,fil_fd = -1;
 
 static void cleanup (void)
 {
-   if (dev_fd > 0) close (dev_fd);
-   if (fil_fd > 0) close (fil_fd);
+       if (dev_fd > 0) close (dev_fd);
+       if (fil_fd > 0) close (fil_fd);
 }
 
 int main (int argc,char *argv[])
 {
-   const char *progname,*filename = NULL,*device = NULL;
-   int i,flags = FLAG_NONE;
-   ssize_t result;
-   size_t size,written;
-   struct mtd_info_user mtd;
-   struct erase_info_user erase;
-   struct stat filestat;
-   unsigned char src[BUFSIZE],dest[BUFSIZE];
-
-   (progname = strrchr (argv[0],'/')) ? progname++ : (progname = argv[0]);
-
-   /*********************
-       * parse cmd-line
-       *****************/
-
-   for (;;) {
-       int option_index = 0;
-       static const char *short_options = "hv";
-       static const struct option long_options[] = {
-               {"help", no_argument, 0, 'h'},
-               {"verbose", no_argument, 0, 'v'},
-               {0, 0, 0, 0},
-       };
-
-       int c = getopt_long(argc, argv, short_options,
-                           long_options, &option_index);
-       if (c == EOF) {
-               break;
-       }
-
-       switch (c) {
-       case 'h':
-               flags |= FLAG_HELP;
-               DEBUG("Got FLAG_HELP\n");
-               break;
-       case 'v':
-               flags |= FLAG_VERBOSE;
-               DEBUG("Got FLAG_VERBOSE\n");
-               break;
-       default:
-               DEBUG("Unknown parameter: %s\n",argv[option_index]);
-               showusage (progname,true);
-       }
-   }
-   if (optind+2 == argc) {
-       flags |= FLAG_FILENAME;
-       filename = argv[optind];
-       DEBUG("Got filename: %s\n",filename);
-
-       flags |= FLAG_DEVICE;
-       device = argv[optind+1];
-       DEBUG("Got device: %s\n",device);
-   }
-
-   if (flags & FLAG_HELP || progname == NULL || device == NULL)
-        showusage (progname,flags != FLAG_HELP);
-
-   atexit (cleanup);
-
-   /* get some info about the flash device */
-   dev_fd = safe_open (device,O_SYNC | O_RDWR);
-   if (ioctl (dev_fd,MEMGETINFO,&mtd) < 0)
-        {
+       const char *progname,*filename = NULL,*device = NULL;
+       int i,flags = FLAG_NONE;
+       ssize_t result;
+       size_t size,written;
+       struct mtd_info_user mtd;
+       struct erase_info_user erase;
+       struct stat filestat;
+       unsigned char src[BUFSIZE],dest[BUFSIZE];
+
+       (progname = strrchr (argv[0],'/')) ? progname++ : (progname = argv[0]);
+
+       /*********************
+        * parse cmd-line
+        *****************/
+
+       for (;;) {
+               int option_index = 0;
+               static const char *short_options = "hv";
+               static const struct option long_options[] = {
+                       {"help", no_argument, 0, 'h'},
+                       {"verbose", no_argument, 0, 'v'},
+                       {0, 0, 0, 0},
+               };
+
+               int c = getopt_long(argc, argv, short_options,
+                               long_options, &option_index);
+               if (c == EOF) {
+                       break;
+               }
+
+               switch (c) {
+                       case 'h':
+                               flags |= FLAG_HELP;
+                               DEBUG("Got FLAG_HELP\n");
+                               break;
+                       case 'v':
+                               flags |= FLAG_VERBOSE;
+                               DEBUG("Got FLAG_VERBOSE\n");
+                               break;
+                       default:
+                               DEBUG("Unknown parameter: %s\n",argv[option_index]);
+                               showusage (progname,true);
+               }
+       }
+       if (optind+2 == argc) {
+               flags |= FLAG_FILENAME;
+               filename = argv[optind];
+               DEBUG("Got filename: %s\n",filename);
+
+               flags |= FLAG_DEVICE;
+               device = argv[optind+1];
+               DEBUG("Got device: %s\n",device);
+       }
+
+       if (flags & FLAG_HELP || progname == NULL || device == NULL)
+               showusage (progname,flags != FLAG_HELP);
+
+       atexit (cleanup);
+
+       /* get some info about the flash device */
+       dev_fd = safe_open (device,O_SYNC | O_RDWR);
+       if (ioctl (dev_fd,MEMGETINFO,&mtd) < 0)
+       {
                DEBUG("ioctl(): %m\n");
                log_printf (LOG_ERROR,"This doesn't seem to be a valid MTD flash device!\n");
                exit (EXIT_FAILURE);
-        }
+       }
 
-   /* get some info about the file we want to copy */
-   fil_fd = safe_open (filename,O_RDONLY);
-   if (fstat (fil_fd,&filestat) < 0)
-        {
+       /* get some info about the file we want to copy */
+       fil_fd = safe_open (filename,O_RDONLY);
+       if (fstat (fil_fd,&filestat) < 0)
+       {
                log_printf (LOG_ERROR,"While trying to get the file status of %s: %m\n",filename);
                exit (EXIT_FAILURE);
-        }
+       }
 
-   /* does it fit into the device/partition? */
-   if (filestat.st_size > mtd.size)
-        {
+       /* does it fit into the device/partition? */
+       if (filestat.st_size > mtd.size)
+       {
                log_printf (LOG_ERROR,"%s won't fit into %s!\n",filename,device);
                exit (EXIT_FAILURE);
-        }
+       }
 
-   /*****************************************************
-       * erase enough blocks so that we can write the file *
-       *****************************************************/
+       /*****************************************************
+        * erase enough blocks so that we can write the file *
+        *****************************************************/
 
 #warning "Check for smaller erase regions"
 
-   erase.start = 0;
-   erase.length = filestat.st_size & ~(mtd.erasesize - 1);
-   if (filestat.st_size % mtd.erasesize) erase.length += mtd.erasesize;
-   if (flags & FLAG_VERBOSE)
-        {
+       erase.start = 0;
+       erase.length = filestat.st_size & ~(mtd.erasesize - 1);
+       if (filestat.st_size % mtd.erasesize) erase.length += mtd.erasesize;
+       if (flags & FLAG_VERBOSE)
+       {
                /* if the user wants verbose output, erase 1 block at a time and show him/her what's going on */
                int blocks = erase.length / mtd.erasesize;
                erase.length = mtd.erasesize;
                log_printf (LOG_NORMAL,"Erasing blocks: 0/%d (0%%)",blocks);
                for (i = 1; i <= blocks; i++)
-                 {
-                        log_printf (LOG_NORMAL,"\rErasing blocks: %d/%d (%d%%)",i,blocks,PERCENTAGE (i,blocks));
-                        if (ioctl (dev_fd,MEMERASE,&erase) < 0)
-                          {
-                                 log_printf (LOG_NORMAL,"\n");
-                                 log_printf (LOG_ERROR,
-                                                  "While erasing blocks 0x%.8x-0x%.8x on %s: %m\n",
-                                                  (unsigned int) erase.start,(unsigned int) (erase.start + erase.length),device);
-                                 exit (EXIT_FAILURE);
-                          }
-                        erase.start += mtd.erasesize;
-                 }
+               {
+                       log_printf (LOG_NORMAL,"\rErasing blocks: %d/%d (%d%%)",i,blocks,PERCENTAGE (i,blocks));
+                       if (ioctl (dev_fd,MEMERASE,&erase) < 0)
+                       {
+                               log_printf (LOG_NORMAL,"\n");
+                               log_printf (LOG_ERROR,
+                                               "While erasing blocks 0x%.8x-0x%.8x on %s: %m\n",
+                                               (unsigned int) erase.start,(unsigned int) (erase.start + erase.length),device);
+                               exit (EXIT_FAILURE);
+                       }
+                       erase.start += mtd.erasesize;
+               }
                log_printf (LOG_NORMAL,"\rErasing blocks: %d/%d (100%%)\n",blocks,blocks);
-        }
-   else
-        {
+       }
+       else
+       {
                /* if not, erase the whole chunk in one shot */
                if (ioctl (dev_fd,MEMERASE,&erase) < 0)
-                 {
-                                 log_printf (LOG_ERROR,
-                                                  "While erasing blocks from 0x%.8x-0x%.8x on %s: %m\n",
-                                                  (unsigned int) erase.start,(unsigned int) (erase.start + erase.length),device);
-                        exit (EXIT_FAILURE);
-                 }
-        }
-   DEBUG("Erased %u / %luk bytes\n",erase.length,filestat.st_size);
-
-   /**********************************
-       * write the entire file to flash *
-       **********************************/
-
-   if (flags & FLAG_VERBOSE) log_printf (LOG_NORMAL,"Writing data: 0k/%luk (0%%)",KB (filestat.st_size));
-   size = filestat.st_size;
-   i = BUFSIZE;
-   written = 0;
-   while (size)
-        {
+               {
+                       log_printf (LOG_ERROR,
+                                       "While erasing blocks from 0x%.8x-0x%.8x on %s: %m\n",
+                                       (unsigned int) erase.start,(unsigned int) (erase.start + erase.length),device);
+                       exit (EXIT_FAILURE);
+               }
+       }
+       DEBUG("Erased %u / %luk bytes\n",erase.length,filestat.st_size);
+
+       /**********************************
+        * write the entire file to flash *
+        **********************************/
+
+       if (flags & FLAG_VERBOSE) log_printf (LOG_NORMAL,"Writing data: 0k/%luk (0%%)",KB (filestat.st_size));
+       size = filestat.st_size;
+       i = BUFSIZE;
+       written = 0;
+       while (size)
+       {
                if (size < BUFSIZE) i = size;
                if (flags & FLAG_VERBOSE)
-                 log_printf (LOG_NORMAL,"\rWriting data: %dk/%luk (%lu%%)",
-                                 KB (written + i),
-                                 KB (filestat.st_size),
-                                 PERCENTAGE (written + i,filestat.st_size));
+                       log_printf (LOG_NORMAL,"\rWriting data: %dk/%luk (%lu%%)",
+                                       KB (written + i),
+                                       KB (filestat.st_size),
+                                       PERCENTAGE (written + i,filestat.st_size));
 
                /* read from filename */
                safe_read (fil_fd,filename,src,i,flags & FLAG_VERBOSE);
@@ -317,50 +316,50 @@ int main (int argc,char *argv[])
                /* write to device */
                result = write (dev_fd,src,i);
                if (i != result)
-                 {
-                        if (flags & FLAG_VERBOSE) log_printf (LOG_NORMAL,"\n");
-                        if (result < 0)
-                          {
-                                 log_printf (LOG_ERROR,
-                                                  "While writing data to 0x%.8x-0x%.8x on %s: %m\n",
-                                                  written,written + i,device);
-                                 exit (EXIT_FAILURE);
-                          }
-                        log_printf (LOG_ERROR,
-                                         "Short write count returned while writing to x%.8x-0x%.8x on %s: %d/%lu bytes written to flash\n",
-                                         written,written + i,device,written + result,filestat.st_size);
-                        exit (EXIT_FAILURE);
-                 }
+               {
+                       if (flags & FLAG_VERBOSE) log_printf (LOG_NORMAL,"\n");
+                       if (result < 0)
+                       {
+                               log_printf (LOG_ERROR,
+                                               "While writing data to 0x%.8x-0x%.8x on %s: %m\n",
+                                               written,written + i,device);
+                               exit (EXIT_FAILURE);
+                       }
+                       log_printf (LOG_ERROR,
+                                       "Short write count returned while writing to x%.8x-0x%.8x on %s: %d/%lu bytes written to flash\n",
+                                       written,written + i,device,written + result,filestat.st_size);
+                       exit (EXIT_FAILURE);
+               }
 
                written += i;
                size -= i;
-        }
-   if (flags & FLAG_VERBOSE)
-        log_printf (LOG_NORMAL,
-                                "\rWriting data: %luk/%luk (100%%)\n",
-                                KB (filestat.st_size),
-                                KB (filestat.st_size));
-   DEBUG("Wrote %d / %luk bytes\n",written,filestat.st_size);
-
-   /**********************************
-       * verify that flash == file data *
-       **********************************/
-
-   safe_rewind (fil_fd,filename);
-   safe_rewind (dev_fd,device);
-   size = filestat.st_size;
-   i = BUFSIZE;
-   written = 0;
-   if (flags & FLAG_VERBOSE) log_printf (LOG_NORMAL,"Verifying data: 0k/%luk (0%%)",KB (filestat.st_size));
-   while (size)
-        {
+       }
+       if (flags & FLAG_VERBOSE)
+               log_printf (LOG_NORMAL,
+                               "\rWriting data: %luk/%luk (100%%)\n",
+                               KB (filestat.st_size),
+                               KB (filestat.st_size));
+       DEBUG("Wrote %d / %luk bytes\n",written,filestat.st_size);
+
+       /**********************************
+        * verify that flash == file data *
+        **********************************/
+
+       safe_rewind (fil_fd,filename);
+       safe_rewind (dev_fd,device);
+       size = filestat.st_size;
+       i = BUFSIZE;
+       written = 0;
+       if (flags & FLAG_VERBOSE) log_printf (LOG_NORMAL,"Verifying data: 0k/%luk (0%%)",KB (filestat.st_size));
+       while (size)
+       {
                if (size < BUFSIZE) i = size;
                if (flags & FLAG_VERBOSE)
-                 log_printf (LOG_NORMAL,
-                                         "\rVerifying data: %dk/%luk (%lu%%)",
-                                         KB (written + i),
-                                         KB (filestat.st_size),
-                                         PERCENTAGE (written + i,filestat.st_size));
+                       log_printf (LOG_NORMAL,
+                                       "\rVerifying data: %dk/%luk (%lu%%)",
+                                       KB (written + i),
+                                       KB (filestat.st_size),
+                                       PERCENTAGE (written + i,filestat.st_size));
 
                /* read from filename */
                safe_read (fil_fd,filename,src,i,flags & FLAG_VERBOSE);
@@ -370,23 +369,23 @@ int main (int argc,char *argv[])
 
                /* compare buffers */
                if (memcmp (src,dest,i))
-                 {
-                        log_printf (LOG_ERROR,
-                                         "File does not seem to match flash data. First mismatch at 0x%.8x-0x%.8x\n",
-                                         written,written + i);
-                        exit (EXIT_FAILURE);
-                 }
+               {
+                       log_printf (LOG_ERROR,
+                                       "File does not seem to match flash data. First mismatch at 0x%.8x-0x%.8x\n",
+                                       written,written + i);
+                       exit (EXIT_FAILURE);
+               }
 
                written += i;
                size -= i;
-        }
-   if (flags & FLAG_VERBOSE)
-        log_printf (LOG_NORMAL,
-                                "\rVerifying data: %luk/%luk (100%%)\n",
-                                KB (filestat.st_size),
-                                KB (filestat.st_size));
-   DEBUG("Verified %d / %luk bytes\n",written,filestat.st_size);
-
-   exit (EXIT_SUCCESS);
+       }
+       if (flags & FLAG_VERBOSE)
+               log_printf (LOG_NORMAL,
+                               "\rVerifying data: %luk/%luk (100%%)\n",
+                               KB (filestat.st_size),
+                               KB (filestat.st_size));
+       DEBUG("Verified %d / %luk bytes\n",written,filestat.st_size);
+
+       exit (EXIT_SUCCESS);
 }
 
index f5398ed8fe4b7d7a00446a3be0539f47997ee97f..5afc0f36f9fd742a416eb146a1044685d7dca94a 100644 (file)
@@ -4,36 +4,36 @@
  */
 /*======================================================================
 
-    Utility to create an FTL partition in a memory region
+  Utility to create an FTL partition in a memory region
 
-    ftl_check.c 1.10 1999/10/25 20:01:35
+  ftl_check.c 1.10 1999/10/25 20:01:35
 
-    The contents of this file are subject to the Mozilla Public
-    License Version 1.1 (the "License"); you may not use this file
-    except in compliance with the License. You may obtain a copy of
-    the License at http://www.mozilla.org/MPL/
+  The contents of this file are subject to the Mozilla Public
+  License Version 1.1 (the "License"); you may not use this file
+  except in compliance with the License. You may obtain a copy of
+  the License at http://www.mozilla.org/MPL/
 
-    Software distributed under the License is distributed on an "AS
-    IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
-    implied. See the License for the specific language governing
-    rights and limitations under the License.
+  Software distributed under the License is distributed on an "AS
+  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+  implied. See the License for the specific language governing
+  rights and limitations under the License.
 
-    The initial developer of the original code is David A. Hinds
-    <dhinds@pcmcia.sourceforge.org>.  Portions created by David A. Hinds
-    are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
+  The initial developer of the original code is David A. Hinds
+  <dhinds@pcmcia.sourceforge.org>.  Portions created by David A. Hinds
+  are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
 
-    Alternatively, the contents of this file may be used under the
-    terms of the GNU Public License version 2 (the "GPL"), in which
-    case the provisions of the GPL are applicable instead of the
-    above.  If you wish to allow the use of your version of this file
-    only under the terms of the GPL and not to allow others to use
-    your version of this file under the MPL, indicate your decision
-    by deleting the provisions above and replace them with the notice
-    and other provisions required by the GPL.  If you do not delete
-    the provisions above, a recipient may use your version of this
-    file under either the MPL or the GPL.
+  Alternatively, the contents of this file may be used under the
+  terms of the GNU Public License version 2 (the "GPL"), in which
+  case the provisions of the GPL are applicable instead of the
+  above.  If you wish to allow the use of your version of this file
+  only under the terms of the GPL and not to allow others to use
+  your version of this file under the MPL, indicate your decision
+  by deleting the provisions above and replace them with the notice
+  and other provisions required by the GPL.  If you do not delete
+  the provisions above, a recipient may use your version of this
+  file under either the MPL or the GPL.
 
-======================================================================*/
+  ======================================================================*/
 
 #include <sys/types.h>
 #include <stdio.h>
 
 static void print_size(u_int s)
 {
-    if ((s > 0x100000) && ((s % 0x100000) == 0))
-       printf("%d mb", s / 0x100000);
-    else if ((s > 0x400) && ((s % 0x400) == 0))
-       printf("%d kb", s / 0x400);
-    else
-       printf("%d bytes", s);
+       if ((s > 0x100000) && ((s % 0x100000) == 0))
+               printf("%d mb", s / 0x100000);
+       else if ((s > 0x400) && ((s % 0x400) == 0))
+               printf("%d kb", s / 0x400);
+       else
+               printf("%d bytes", s);
 }
 
 /*====================================================================*/
 
 static void check_partition(int fd, int verbose)
 {
-    mtd_info_t mtd;
-    erase_unit_header_t hdr, hdr2;
-    u_int i, j, nbam, *bam;
-    int control, data, free, deleted;
-
-    /* Get partition size, block size */
-    if (ioctl(fd, MEMGETINFO, &mtd) != 0) {
-       perror("get info failed");
-       return;
-    }
-
-    printf("Memory region info:\n");
-    printf("  Region size = ");
-    print_size(mtd.size);
-    printf("  Erase block size = ");
-    print_size(mtd.erasesize);
-    printf("\n\n");
-
-    for (i = 0; i < mtd.size/mtd.erasesize; i++) {
-       if (lseek(fd, (i * mtd.erasesize), SEEK_SET) == -1) {
-           perror("seek failed");
-           break;
+       mtd_info_t mtd;
+       erase_unit_header_t hdr, hdr2;
+       u_int i, j, nbam, *bam;
+       int control, data, free, deleted;
+
+       /* Get partition size, block size */
+       if (ioctl(fd, MEMGETINFO, &mtd) != 0) {
+               perror("get info failed");
+               return;
        }
-       read(fd, &hdr, sizeof(hdr));
-       if ((FROM_LE32(hdr.FormattedSize) > 0) &&
-           (FROM_LE32(hdr.FormattedSize) <= mtd.size) &&
-           (FROM_LE16(hdr.NumEraseUnits) > 0) &&
-           (FROM_LE16(hdr.NumEraseUnits) <= mtd.size/mtd.erasesize))
-           break;
-    }
-    if (i == mtd.size/mtd.erasesize) {
-       fprintf(stderr, "No valid erase unit headers!\n");
-       return;
-    }
-
-    printf("Partition header:\n");
-    printf("  Formatted size = ");
-    print_size(FROM_LE32(hdr.FormattedSize));
-    printf(", erase units = %d, transfer units = %d\n",
-          FROM_LE16(hdr.NumEraseUnits), hdr.NumTransferUnits);
-    printf("  Erase unit size = ");
-    print_size(1 << hdr.EraseUnitSize);
-    printf(", virtual block size = ");
-    print_size(1 << hdr.BlockSize);
-    printf("\n");
-
-    /* Create basic block allocation table for control blocks */
-    nbam = (mtd.erasesize >> hdr.BlockSize);
-    bam = malloc(nbam * sizeof(u_int));
-
-    for (i = 0; i < FROM_LE16(hdr.NumEraseUnits); i++) {
-       if (lseek(fd, (i << hdr.EraseUnitSize), SEEK_SET) == -1) {
-           perror("seek failed");
-           break;
+
+       printf("Memory region info:\n");
+       printf("  Region size = ");
+       print_size(mtd.size);
+       printf("  Erase block size = ");
+       print_size(mtd.erasesize);
+       printf("\n\n");
+
+       for (i = 0; i < mtd.size/mtd.erasesize; i++) {
+               if (lseek(fd, (i * mtd.erasesize), SEEK_SET) == -1) {
+                       perror("seek failed");
+                       break;
+               }
+               read(fd, &hdr, sizeof(hdr));
+               if ((FROM_LE32(hdr.FormattedSize) > 0) &&
+                               (FROM_LE32(hdr.FormattedSize) <= mtd.size) &&
+                               (FROM_LE16(hdr.NumEraseUnits) > 0) &&
+                               (FROM_LE16(hdr.NumEraseUnits) <= mtd.size/mtd.erasesize))
+                       break;
        }
-       if (read(fd, &hdr2, sizeof(hdr2)) == -1) {
-           perror("read failed");
-           break;
+       if (i == mtd.size/mtd.erasesize) {
+               fprintf(stderr, "No valid erase unit headers!\n");
+               return;
        }
-       printf("\nErase unit %d:\n", i);
-       if ((hdr2.FormattedSize != hdr.FormattedSize) ||
-           (hdr2.NumEraseUnits != hdr.NumEraseUnits) ||
-           (hdr2.SerialNumber != hdr.SerialNumber))
-           printf("  Erase unit header is corrupt.\n");
-       else if (FROM_LE16(hdr2.LogicalEUN) == 0xffff)
-           printf("  Transfer unit, erase count = %d\n", FROM_LE32(hdr2.EraseCount));
-       else {
-           printf("  Logical unit %d, erase count = %d\n",
-                  FROM_LE16(hdr2.LogicalEUN), FROM_LE32(hdr2.EraseCount));
-           if (lseek(fd, (i << hdr.EraseUnitSize)+FROM_LE32(hdr.BAMOffset),
-                     SEEK_SET) == -1) {
-               perror("seek failed");
-               break;
-           }
-           if (read(fd, bam, nbam * sizeof(u_int)) == -1) {
-               perror("read failed");
-               break;
-           }
-           free = deleted = control = data = 0;
-           for (j = 0; j < nbam; j++) {
-               if (BLOCK_FREE(FROM_LE32(bam[j])))
-                   free++;
-               else if (BLOCK_DELETED(FROM_LE32(bam[j])))
-                   deleted++;
-               else switch (BLOCK_TYPE(FROM_LE32(bam[j]))) {
-               case BLOCK_CONTROL: control++; break;
-               case BLOCK_DATA: data++; break;
-               default: break;
+
+       printf("Partition header:\n");
+       printf("  Formatted size = ");
+       print_size(FROM_LE32(hdr.FormattedSize));
+       printf(", erase units = %d, transfer units = %d\n",
+                       FROM_LE16(hdr.NumEraseUnits), hdr.NumTransferUnits);
+       printf("  Erase unit size = ");
+       print_size(1 << hdr.EraseUnitSize);
+       printf(", virtual block size = ");
+       print_size(1 << hdr.BlockSize);
+       printf("\n");
+
+       /* Create basic block allocation table for control blocks */
+       nbam = (mtd.erasesize >> hdr.BlockSize);
+       bam = malloc(nbam * sizeof(u_int));
+
+       for (i = 0; i < FROM_LE16(hdr.NumEraseUnits); i++) {
+               if (lseek(fd, (i << hdr.EraseUnitSize), SEEK_SET) == -1) {
+                       perror("seek failed");
+                       break;
+               }
+               if (read(fd, &hdr2, sizeof(hdr2)) == -1) {
+                       perror("read failed");
+                       break;
+               }
+               printf("\nErase unit %d:\n", i);
+               if ((hdr2.FormattedSize != hdr.FormattedSize) ||
+                               (hdr2.NumEraseUnits != hdr.NumEraseUnits) ||
+                               (hdr2.SerialNumber != hdr.SerialNumber))
+                       printf("  Erase unit header is corrupt.\n");
+               else if (FROM_LE16(hdr2.LogicalEUN) == 0xffff)
+                       printf("  Transfer unit, erase count = %d\n", FROM_LE32(hdr2.EraseCount));
+               else {
+                       printf("  Logical unit %d, erase count = %d\n",
+                                       FROM_LE16(hdr2.LogicalEUN), FROM_LE32(hdr2.EraseCount));
+                       if (lseek(fd, (i << hdr.EraseUnitSize)+FROM_LE32(hdr.BAMOffset),
+                                               SEEK_SET) == -1) {
+                               perror("seek failed");
+                               break;
+                       }
+                       if (read(fd, bam, nbam * sizeof(u_int)) == -1) {
+                               perror("read failed");
+                               break;
+                       }
+                       free = deleted = control = data = 0;
+                       for (j = 0; j < nbam; j++) {
+                               if (BLOCK_FREE(FROM_LE32(bam[j])))
+                                       free++;
+                               else if (BLOCK_DELETED(FROM_LE32(bam[j])))
+                                       deleted++;
+                               else switch (BLOCK_TYPE(FROM_LE32(bam[j]))) {
+                                       case BLOCK_CONTROL: control++; break;
+                                       case BLOCK_DATA: data++; break;
+                                       default: break;
+                               }
+                       }
+                       printf("  Block allocation: %d control, %d data, %d free,"
+                                       " %d deleted\n", control, data, free, deleted);
                }
-           }
-           printf("  Block allocation: %d control, %d data, %d free,"
-                  " %d deleted\n", control, data, free, deleted);
        }
-    }
 } /* format_partition */
 
 /* Show usage information */
@@ -189,45 +189,45 @@ void showusage(char *pname)
 
 int main(int argc, char *argv[])
 {
-    int verbose;
-    int optch, errflg, fd;
-    struct stat buf;
-
-    errflg = 0;
-    verbose = 0;
-    while ((optch = getopt(argc, argv, "vh")) != -1) {
-       switch (optch) {
-       case 'h':
-           errflg = 1; break;
-       case 'v':
-           verbose = 1; break;
-       default:
-           errflg = -1; break;
+       int verbose;
+       int optch, errflg, fd;
+       struct stat buf;
+
+       errflg = 0;
+       verbose = 0;
+       while ((optch = getopt(argc, argv, "vh")) != -1) {
+               switch (optch) {
+                       case 'h':
+                               errflg = 1; break;
+                       case 'v':
+                               verbose = 1; break;
+                       default:
+                               errflg = -1; break;
+               }
+       }
+       if (errflg || (optind != argc-1)) {
+               showusage(argv[0]);
+               exit(errflg > 0 ? 0 : EXIT_FAILURE);
        }
-    }
-    if (errflg || (optind != argc-1)) {
-       showusage(argv[0]);
-       exit(errflg > 0 ? 0 : EXIT_FAILURE);
-    }
-
-    if (stat(argv[optind], &buf) != 0) {
-       perror("status check failed");
-       exit(EXIT_FAILURE);
-    }
-    if (!(buf.st_mode & S_IFCHR)) {
-       fprintf(stderr, "%s is not a character special device\n",
-               argv[optind]);
-       exit(EXIT_FAILURE);
-    }
-    fd = open(argv[optind], O_RDONLY);
-    if (fd == -1) {
-       perror("open failed");
-       exit(EXIT_FAILURE);
-    }
-
-    check_partition(fd, verbose);
-    close(fd);
-
-    exit(EXIT_SUCCESS);
-    return 0;
+
+       if (stat(argv[optind], &buf) != 0) {
+               perror("status check failed");
+               exit(EXIT_FAILURE);
+       }
+       if (!(buf.st_mode & S_IFCHR)) {
+               fprintf(stderr, "%s is not a character special device\n",
+                               argv[optind]);
+               exit(EXIT_FAILURE);
+       }
+       fd = open(argv[optind], O_RDONLY);
+       if (fd == -1) {
+               perror("open failed");
+               exit(EXIT_FAILURE);
+       }
+
+       check_partition(fd, verbose);
+       close(fd);
+
+       exit(EXIT_SUCCESS);
+       return 0;
 }
index 8739fab02f9570805c4045163bdb1d4aff2cddad..c35e18b921cdb1a253e2896e0ae843f72f6c7afa 100644 (file)
@@ -4,36 +4,36 @@
  */
 /*======================================================================
 
-    Utility to create an FTL partition in a memory region
+  Utility to create an FTL partition in a memory region
 
-    ftl_format.c 1.13 1999/10/25 20:01:35
+  ftl_format.c 1.13 1999/10/25 20:01:35
 
-    The contents of this file are subject to the Mozilla Public
-    License Version 1.1 (the "License"); you may not use this file
-    except in compliance with the License. You may obtain a copy of
-    the License at http://www.mozilla.org/MPL/
+  The contents of this file are subject to the Mozilla Public
+  License Version 1.1 (the "License"); you may not use this file
+  except in compliance with the License. You may obtain a copy of
+  the License at http://www.mozilla.org/MPL/
 
-    Software distributed under the License is distributed on an "AS
-    IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
-    implied. See the License for the specific language governing
-    rights and limitations under the License.
+  Software distributed under the License is distributed on an "AS
+  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+  implied. See the License for the specific language governing
+  rights and limitations under the License.
 
-    The initial developer of the original code is David A. Hinds
-    <dhinds@pcmcia.sourceforge.org>.  Portions created by David A. Hinds
-    are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
+  The initial developer of the original code is David A. Hinds
+  <dhinds@pcmcia.sourceforge.org>.  Portions created by David A. Hinds
+  are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
 
-    Alternatively, the contents of this file may be used under the
-    terms of the GNU Public License version 2 (the "GPL"), in which
-    case the provisions of the GPL are applicable instead of the
-    above.  If you wish to allow the use of your version of this file
-    only under the terms of the GPL and not to allow others to use
-    your version of this file under the MPL, indicate your decision
-    by deleting the provisions above and replace them with the notice
-    and other provisions required by the GPL.  If you do not delete
-    the provisions above, a recipient may use your version of this
-    file under either the MPL or the GPL.
+  Alternatively, the contents of this file may be used under the
+  terms of the GNU Public License version 2 (the "GPL"), in which
+  case the provisions of the GPL are applicable instead of the
+  above.  If you wish to allow the use of your version of this file
+  only under the terms of the GPL and not to allow others to use
+  your version of this file under the MPL, indicate your decision
+  by deleting the provisions above and replace them with the notice
+  and other provisions required by the GPL.  If you do not delete
+  the provisions above, a recipient may use your version of this
+  file under either the MPL or the GPL.
 
-======================================================================*/
+  ======================================================================*/
 
 #include <sys/types.h>
 #include <stdio.h>
 
 static void print_size(u_int s)
 {
-    if ((s > 0x100000) && ((s % 0x100000) == 0))
-       printf("%d mb", s / 0x100000);
-    else if ((s > 0x400) && ((s % 0x400) == 0))
-       printf("%d kb", s / 0x400);
-    else
-       printf("%d bytes", s);
+       if ((s > 0x100000) && ((s % 0x100000) == 0))
+               printf("%d mb", s / 0x100000);
+       else if ((s > 0x400) && ((s % 0x400) == 0))
+               printf("%d kb", s / 0x400);
+       else
+               printf("%d bytes", s);
 }
 
 /*====================================================================*/
 
 static const char LinkTarget[] = {
-    0x13, 0x03, 'C', 'I', 'S'
+       0x13, 0x03, 'C', 'I', 'S'
 };
 static const char DataOrg[] = {
-    0x46, 0x39, 0x00, 'F', 'T', 'L', '1', '0', '0', 0x00
+       0x46, 0x39, 0x00, 'F', 'T', 'L', '1', '0', '0', 0x00
 };
 
 static void build_header(erase_unit_header_t *hdr, u_int RegionSize,
-                        u_int BlockSize, u_int Spare, int Reserve,
-                        u_int BootSize)
+               u_int BlockSize, u_int Spare, int Reserve,
+               u_int BootSize)
 {
-    u_int i, BootUnits, nbam, __FormattedSize;
-
-    /* Default everything to the erased state */
-    memset(hdr, 0xff, sizeof(*hdr));
-    memcpy(hdr->LinkTargetTuple, LinkTarget, 5);
-    memcpy(hdr->DataOrgTuple, DataOrg, 10);
-    hdr->EndTuple[0] = hdr->EndTuple[1] = 0xff;
-    BootSize = (BootSize + (BlockSize-1)) & ~(BlockSize-1);
-    BootUnits = BootSize / BlockSize;
-
-    /* We only support 512-byte blocks */
-    hdr->BlockSize = 9;
-    hdr->EraseUnitSize = 0;
-    for (i = BlockSize; i > 1; i >>= 1)
-       hdr->EraseUnitSize++;
-    hdr->EraseCount = TO_LE32(0);
-    hdr->FirstPhysicalEUN = TO_LE16(BootUnits);
-    hdr->NumEraseUnits = TO_LE16((RegionSize - BootSize) >> hdr->EraseUnitSize);
-    hdr->NumTransferUnits = Spare;
-    __FormattedSize = RegionSize - ((Spare + BootUnits) << hdr->EraseUnitSize);
-    /* Leave a little bit of space between the CIS and BAM */
-    hdr->BAMOffset = TO_LE32(0x80);
-    /* Adjust size to account for BAM space */
-    nbam = ((1 << (hdr->EraseUnitSize - hdr->BlockSize)) * sizeof(u_int)
-           + FROM_LE32(hdr->BAMOffset) + (1 << hdr->BlockSize) - 1) >> hdr->BlockSize;
-
-    __FormattedSize -=
-       (FROM_LE16(hdr->NumEraseUnits) - Spare) * (nbam << hdr->BlockSize);
-    __FormattedSize -= ((__FormattedSize * Reserve / 100) & ~0xfff);
-
-    hdr->FormattedSize = TO_LE32(__FormattedSize);
-
-    /* hdr->FirstVMAddress defaults to erased state */
-    hdr->NumVMPages = TO_LE16(0);
-    hdr->Flags = 0;
-    /* hdr->Code defaults to erased state */
-    hdr->SerialNumber = TO_LE32(time(NULL));
-    /* hdr->AltEUHOffset defaults to erased state */
+       u_int i, BootUnits, nbam, __FormattedSize;
+
+       /* Default everything to the erased state */
+       memset(hdr, 0xff, sizeof(*hdr));
+       memcpy(hdr->LinkTargetTuple, LinkTarget, 5);
+       memcpy(hdr->DataOrgTuple, DataOrg, 10);
+       hdr->EndTuple[0] = hdr->EndTuple[1] = 0xff;
+       BootSize = (BootSize + (BlockSize-1)) & ~(BlockSize-1);
+       BootUnits = BootSize / BlockSize;
+
+       /* We only support 512-byte blocks */
+       hdr->BlockSize = 9;
+       hdr->EraseUnitSize = 0;
+       for (i = BlockSize; i > 1; i >>= 1)
+               hdr->EraseUnitSize++;
+       hdr->EraseCount = TO_LE32(0);
+       hdr->FirstPhysicalEUN = TO_LE16(BootUnits);
+       hdr->NumEraseUnits = TO_LE16((RegionSize - BootSize) >> hdr->EraseUnitSize);
+       hdr->NumTransferUnits = Spare;
+       __FormattedSize = RegionSize - ((Spare + BootUnits) << hdr->EraseUnitSize);
+       /* Leave a little bit of space between the CIS and BAM */
+       hdr->BAMOffset = TO_LE32(0x80);
+       /* Adjust size to account for BAM space */
+       nbam = ((1 << (hdr->EraseUnitSize - hdr->BlockSize)) * sizeof(u_int)
+                       + FROM_LE32(hdr->BAMOffset) + (1 << hdr->BlockSize) - 1) >> hdr->BlockSize;
+
+       __FormattedSize -=
+               (FROM_LE16(hdr->NumEraseUnits) - Spare) * (nbam << hdr->BlockSize);
+       __FormattedSize -= ((__FormattedSize * Reserve / 100) & ~0xfff);
+
+       hdr->FormattedSize = TO_LE32(__FormattedSize);
+
+       /* hdr->FirstVMAddress defaults to erased state */
+       hdr->NumVMPages = TO_LE16(0);
+       hdr->Flags = 0;
+       /* hdr->Code defaults to erased state */
+       hdr->SerialNumber = TO_LE32(time(NULL));
+       /* hdr->AltEUHOffset defaults to erased state */
 
 } /* build_header */
 
 /*====================================================================*/
 
 static int format_partition(int fd, int quiet, int interrogate,
-                           u_int spare, int reserve, u_int bootsize)
+               u_int spare, int reserve, u_int bootsize)
 {
-    mtd_info_t mtd;
-    erase_info_t erase;
-    erase_unit_header_t hdr;
-    u_int step, lun, i, nbam, *bam;
-
-    /* Get partition size, block size */
-    if (ioctl(fd, MEMGETINFO, &mtd) != 0) {
-       perror("get info failed");
-       return -1;
-    }
+       mtd_info_t mtd;
+       erase_info_t erase;
+       erase_unit_header_t hdr;
+       u_int step, lun, i, nbam, *bam;
+
+       /* Get partition size, block size */
+       if (ioctl(fd, MEMGETINFO, &mtd) != 0) {
+               perror("get info failed");
+               return -1;
+       }
 
 #if 0
-    /* Intel Series 100 Flash: skip first block */
-    if ((region.JedecMfr == 0x89) && (region.JedecInfo == 0xaa) &&
-       (bootsize == 0)) {
-       if (!quiet)
-           printf("Skipping first block to protect CIS info...\n");
-       bootsize = 1;
-    }
+       /* Intel Series 100 Flash: skip first block */
+       if ((region.JedecMfr == 0x89) && (region.JedecInfo == 0xaa) &&
+                       (bootsize == 0)) {
+               if (!quiet)
+                       printf("Skipping first block to protect CIS info...\n");
+               bootsize = 1;
+       }
 #endif
 
-    /* Create header */
-    build_header(&hdr, mtd.size, mtd.erasesize,
-                spare, reserve, bootsize);
-
-    if (!quiet) {
-       printf("Partition size = ");
-       print_size(mtd.size);
-       printf(", erase unit size = ");
-       print_size(mtd.erasesize);
-       printf(", %d transfer units\n", spare);
-       if (bootsize != 0) {
-           print_size(FROM_LE16(hdr.FirstPhysicalEUN) << hdr.EraseUnitSize);
-           printf(" allocated for boot image\n");
-       }
-       printf("Reserved %d%%, formatted size = ", reserve);
-       print_size(FROM_LE32(hdr.FormattedSize));
-       printf("\n");
-       fflush(stdout);
-    }
-
-    if (interrogate) {
-       char str[3];
-       printf("This will destroy all data on the target device.  "
-              "Confirm (y/n): ");
-       if (fgets(str, 3, stdin) == NULL)
-           return -1;
-       if ((strcmp(str, "y\n") != 0) && (strcmp(str, "Y\n") != 0))
-           return -1;
-    }
-
-    /* Create basic block allocation table for control blocks */
-    nbam = ((mtd.erasesize >> hdr.BlockSize) * sizeof(u_int)
-           + FROM_LE32(hdr.BAMOffset) + (1 << hdr.BlockSize) - 1) >> hdr.BlockSize;
-    bam = malloc(nbam * sizeof(u_int));
-    for (i = 0; i < nbam; i++)
-       bam[i] = TO_LE32(BLOCK_CONTROL);
-
-    /* Erase partition */
-    if (!quiet) {
-       printf("Erasing all blocks...\n");
-       fflush(stdout);
-    }
-    erase.length = mtd.erasesize;
-    erase.start = mtd.erasesize * FROM_LE16(hdr.FirstPhysicalEUN);
-    for (i = 0; i < FROM_LE16(hdr.NumEraseUnits); i++) {
-       if (ioctl(fd, MEMERASE, &erase) < 0) {
-           if (!quiet) {
-               putchar('\n');
-               fflush(stdout);
-           }
-           perror("block erase failed");
-           return -1;
-       }
-       erase.start += erase.length;
+       /* Create header */
+       build_header(&hdr, mtd.size, mtd.erasesize,
+                       spare, reserve, bootsize);
+
        if (!quiet) {
-           if (mtd.size <= 0x800000) {
-               if (erase.start % 0x100000) {
-                   if (!(erase.start % 0x20000)) putchar('-');
+               printf("Partition size = ");
+               print_size(mtd.size);
+               printf(", erase unit size = ");
+               print_size(mtd.erasesize);
+               printf(", %d transfer units\n", spare);
+               if (bootsize != 0) {
+                       print_size(FROM_LE16(hdr.FirstPhysicalEUN) << hdr.EraseUnitSize);
+                       printf(" allocated for boot image\n");
                }
-               else putchar('+');
-           }
-           else {
-               if (erase.start % 0x800000) {
-                   if (!(erase.start % 0x100000)) putchar('+');
-               }
-               else putchar('*');
-           }
-           fflush(stdout);
+               printf("Reserved %d%%, formatted size = ", reserve);
+               print_size(FROM_LE32(hdr.FormattedSize));
+               printf("\n");
+               fflush(stdout);
        }
-    }
-    if (!quiet) putchar('\n');
-
-    /* Prepare erase units */
-    if (!quiet) {
-       printf("Writing erase unit headers...\n");
-       fflush(stdout);
-    }
-    lun = 0;
-    /* Distribute transfer units over the entire region */
-    step = (spare) ? (FROM_LE16(hdr.NumEraseUnits)/spare) : (FROM_LE16(hdr.NumEraseUnits)+1);
-    for (i = 0; i < FROM_LE16(hdr.NumEraseUnits); i++) {
-       u_int ofs = (i + FROM_LE16(hdr.FirstPhysicalEUN)) << hdr.EraseUnitSize;
-       if (lseek(fd, ofs, SEEK_SET) == -1) {
-           perror("seek failed");
-           break;
+
+       if (interrogate) {
+               char str[3];
+               printf("This will destroy all data on the target device.  "
+                               "Confirm (y/n): ");
+               if (fgets(str, 3, stdin) == NULL)
+                       return -1;
+               if ((strcmp(str, "y\n") != 0) && (strcmp(str, "Y\n") != 0))
+                       return -1;
        }
-       /* Is this a transfer unit? */
-       if (((i+1) % step) == 0)
-           hdr.LogicalEUN = TO_LE16(0xffff);
-       else {
-           hdr.LogicalEUN = TO_LE16(lun);
-           lun++;
+
+       /* Create basic block allocation table for control blocks */
+       nbam = ((mtd.erasesize >> hdr.BlockSize) * sizeof(u_int)
+                       + FROM_LE32(hdr.BAMOffset) + (1 << hdr.BlockSize) - 1) >> hdr.BlockSize;
+       bam = malloc(nbam * sizeof(u_int));
+       for (i = 0; i < nbam; i++)
+               bam[i] = TO_LE32(BLOCK_CONTROL);
+
+       /* Erase partition */
+       if (!quiet) {
+               printf("Erasing all blocks...\n");
+               fflush(stdout);
        }
-       if (write(fd, &hdr, sizeof(hdr)) == -1) {
-           perror("write failed");
-           break;
+       erase.length = mtd.erasesize;
+       erase.start = mtd.erasesize * FROM_LE16(hdr.FirstPhysicalEUN);
+       for (i = 0; i < FROM_LE16(hdr.NumEraseUnits); i++) {
+               if (ioctl(fd, MEMERASE, &erase) < 0) {
+                       if (!quiet) {
+                               putchar('\n');
+                               fflush(stdout);
+                       }
+                       perror("block erase failed");
+                       return -1;
+               }
+               erase.start += erase.length;
+               if (!quiet) {
+                       if (mtd.size <= 0x800000) {
+                               if (erase.start % 0x100000) {
+                                       if (!(erase.start % 0x20000)) putchar('-');
+                               }
+                               else putchar('+');
+                       }
+                       else {
+                               if (erase.start % 0x800000) {
+                                       if (!(erase.start % 0x100000)) putchar('+');
+                               }
+                               else putchar('*');
+                       }
+                       fflush(stdout);
+               }
        }
-       if (lseek(fd, ofs + FROM_LE32(hdr.BAMOffset), SEEK_SET) == -1) {
-           perror("seek failed");
-           break;
+       if (!quiet) putchar('\n');
+
+       /* Prepare erase units */
+       if (!quiet) {
+               printf("Writing erase unit headers...\n");
+               fflush(stdout);
        }
-       if (write(fd, bam, nbam * sizeof(u_int)) == -1) {
-           perror("write failed");
-           break;
+       lun = 0;
+       /* Distribute transfer units over the entire region */
+       step = (spare) ? (FROM_LE16(hdr.NumEraseUnits)/spare) : (FROM_LE16(hdr.NumEraseUnits)+1);
+       for (i = 0; i < FROM_LE16(hdr.NumEraseUnits); i++) {
+               u_int ofs = (i + FROM_LE16(hdr.FirstPhysicalEUN)) << hdr.EraseUnitSize;
+               if (lseek(fd, ofs, SEEK_SET) == -1) {
+                       perror("seek failed");
+                       break;
+               }
+               /* Is this a transfer unit? */
+               if (((i+1) % step) == 0)
+                       hdr.LogicalEUN = TO_LE16(0xffff);
+               else {
+                       hdr.LogicalEUN = TO_LE16(lun);
+                       lun++;
+               }
+               if (write(fd, &hdr, sizeof(hdr)) == -1) {
+                       perror("write failed");
+                       break;
+               }
+               if (lseek(fd, ofs + FROM_LE32(hdr.BAMOffset), SEEK_SET) == -1) {
+                       perror("seek failed");
+                       break;
+               }
+               if (write(fd, bam, nbam * sizeof(u_int)) == -1) {
+                       perror("write failed");
+                       break;
+               }
        }
-    }
-    if (i < FROM_LE16(hdr.NumEraseUnits))
-       return -1;
-    else
-       return 0;
+       if (i < FROM_LE16(hdr.NumEraseUnits))
+               return -1;
+       else
+               return 0;
 } /* format_partition */
 
 /*====================================================================*/
 
 int main(int argc, char *argv[])
 {
-    int quiet, interrogate, reserve;
-    int optch, errflg, fd, ret;
-    u_int spare, bootsize;
-    char *s;
-    extern char *optarg;
-    struct stat buf;
-
-    quiet = 0;
-    interrogate = 0;
-    spare = 1;
-    reserve = 5;
-    errflg = 0;
-    bootsize = 0;
-
-    while ((optch = getopt(argc, argv, "qir:s:b:")) != -1) {
-       switch (optch) {
-       case 'q':
-           quiet = 1; break;
-       case 'i':
-           interrogate = 1; break;
-       case 's':
-           spare = strtoul(optarg, NULL, 0); break;
-       case 'r':
-           reserve = strtoul(optarg, NULL, 0); break;
-       case 'b':
-           bootsize = strtoul(optarg, &s, 0);
-           if ((*s == 'k') || (*s == 'K'))
-               bootsize *= 1024;
-           break;
-       default:
-           errflg = 1; break;
+       int quiet, interrogate, reserve;
+       int optch, errflg, fd, ret;
+       u_int spare, bootsize;
+       char *s;
+       extern char *optarg;
+       struct stat buf;
+
+       quiet = 0;
+       interrogate = 0;
+       spare = 1;
+       reserve = 5;
+       errflg = 0;
+       bootsize = 0;
+
+       while ((optch = getopt(argc, argv, "qir:s:b:")) != -1) {
+               switch (optch) {
+                       case 'q':
+                               quiet = 1; break;
+                       case 'i':
+                               interrogate = 1; break;
+                       case 's':
+                               spare = strtoul(optarg, NULL, 0); break;
+                       case 'r':
+                               reserve = strtoul(optarg, NULL, 0); break;
+                       case 'b':
+                               bootsize = strtoul(optarg, &s, 0);
+                               if ((*s == 'k') || (*s == 'K'))
+                                       bootsize *= 1024;
+                               break;
+                       default:
+                               errflg = 1; break;
+               }
+       }
+       if (errflg || (optind != argc-1)) {
+               fprintf(stderr, "usage: %s [-q] [-i] [-s spare-blocks]"
+                               " [-r reserve-percent] [-b bootsize] device\n", argv[0]);
+               exit(EXIT_FAILURE);
+       }
+
+       if (stat(argv[optind], &buf) != 0) {
+               perror("status check failed");
+               exit(EXIT_FAILURE);
+       }
+       if (!(buf.st_mode & S_IFCHR)) {
+               fprintf(stderr, "%s is not a character special device\n",
+                               argv[optind]);
+               exit(EXIT_FAILURE);
+       }
+       fd = open(argv[optind], O_RDWR);
+       if (fd == -1) {
+               perror("open failed");
+               exit(EXIT_FAILURE);
        }
-    }
-    if (errflg || (optind != argc-1)) {
-       fprintf(stderr, "usage: %s [-q] [-i] [-s spare-blocks]"
-               " [-r reserve-percent] [-b bootsize] device\n", argv[0]);
-       exit(EXIT_FAILURE);
-    }
-
-    if (stat(argv[optind], &buf) != 0) {
-       perror("status check failed");
-       exit(EXIT_FAILURE);
-    }
-    if (!(buf.st_mode & S_IFCHR)) {
-       fprintf(stderr, "%s is not a character special device\n",
-               argv[optind]);
-       exit(EXIT_FAILURE);
-    }
-    fd = open(argv[optind], O_RDWR);
-    if (fd == -1) {
-       perror("open failed");
-       exit(EXIT_FAILURE);
-    }
-
-    ret = format_partition(fd, quiet, interrogate, spare, reserve,
-                          bootsize);
-    if (!quiet) {
-       if (ret)
-           printf("format failed.\n");
-       else
-           printf("format successful.\n");
-    }
-    close(fd);
 
-    exit((ret) ? EXIT_FAILURE : EXIT_SUCCESS);
-    return 0;
+       ret = format_partition(fd, quiet, interrogate, spare, reserve,
+                       bootsize);
+       if (!quiet) {
+               if (ret)
+                       printf("format failed.\n");
+               else
+                       printf("format successful.\n");
+       }
+       close(fd);
+
+       exit((ret) ? EXIT_FAILURE : EXIT_SUCCESS);
+       return 0;
 }
index 771025ef8428e7f2ac67d46268b0d1a8f78d8660..4d76aca72de9212b073581073f957596848505ff 100644 (file)
@@ -27,8 +27,8 @@
 /* How many padding bytes should be inserted between two chunks of data
    on the flash?  */
 #define JFFS_GET_PAD_BYTES(size) ((JFFS_ALIGN_SIZE                     \
-                                 - ((uint32_t)(size) % JFFS_ALIGN_SIZE)) \
-                                 % JFFS_ALIGN_SIZE)
+                       - ((uint32_t)(size) % JFFS_ALIGN_SIZE)) \
+               % JFFS_ALIGN_SIZE)
 
 #define JFFS_EMPTY_BITMASK 0xffffffff
 #define JFFS_MAGIC_BITMASK 0x34383931
 
 struct jffs_raw_inode
 {
-  uint32_t magic;    /* A constant magic number.  */
-  uint32_t ino;      /* Inode number.  */
-  uint32_t pino;     /* Parent's inode number.  */
-  uint32_t version;  /* Version number.  */
-  uint32_t mode;     /* file_type, mode  */
-  uint16_t uid;
-  uint16_t gid;
-  uint32_t atime;
-  uint32_t mtime;
-  uint32_t ctime;
-  uint32_t offset;     /* Where to begin to write.  */
-  uint32_t dsize;      /* Size of the file data.  */
-  uint32_t rsize;      /* How much are going to be replaced?  */
-  uint8_t nsize;       /* Name length.  */
-  uint8_t nlink;       /* Number of links.  */
-  uint8_t spare : 6;   /* For future use.  */
-  uint8_t rename : 1;  /* Is this a special rename?  */
-  uint8_t deleted : 1; /* Has this file been deleted?  */
-  uint8_t accurate;    /* The inode is obsolete if accurate == 0.  */
-  uint32_t dchksum;    /* Checksum for the data.  */
-  uint16_t nchksum;    /* Checksum for the name.  */
-  uint16_t chksum;     /* Checksum for the raw_inode.  */
+       uint32_t magic;    /* A constant magic number.  */
+       uint32_t ino;      /* Inode number.  */
+       uint32_t pino;     /* Parent's inode number.  */
+       uint32_t version;  /* Version number.  */
+       uint32_t mode;     /* file_type, mode  */
+       uint16_t uid;
+       uint16_t gid;
+       uint32_t atime;
+       uint32_t mtime;
+       uint32_t ctime;
+       uint32_t offset;     /* Where to begin to write.  */
+       uint32_t dsize;      /* Size of the file data.  */
+       uint32_t rsize;      /* How much are going to be replaced?  */
+       uint8_t nsize;       /* Name length.  */
+       uint8_t nlink;       /* Number of links.  */
+       uint8_t spare : 6;   /* For future use.  */
+       uint8_t rename : 1;  /* Is this a special rename?  */
+       uint8_t deleted : 1; /* Has this file been deleted?  */
+       uint8_t accurate;    /* The inode is obsolete if accurate == 0.  */
+       uint32_t dchksum;    /* Checksum for the data.  */
+       uint16_t nchksum;    /* Checksum for the name.  */
+       uint16_t chksum;     /* Checksum for the raw_inode.  */
 };
 
 
 struct jffs_file
 {
-  struct jffs_raw_inode inode;
-  char *name;
-  unsigned char *data;
+       struct jffs_raw_inode inode;
+       char *name;
+       unsigned char *data;
 };
 
 
@@ -83,68 +83,68 @@ int endian = ENDIAN_HOST;
 static uint32_t jffs_checksum(void *data, int size);
 void jffs_print_trace(const char *path, int depth);
 int make_root_dir(FILE *fs, int first_ino, const char *root_dir_path,
-                 int depth);
+               int depth);
 void write_file(struct jffs_file *f, FILE *fs, struct stat st);
 void read_data(struct jffs_file *f, const char *path, int offset);
 int mkfs(FILE *fs, const char *path, int ino, int parent, int depth);
 
 
-static uint32_t
+       static uint32_t
 jffs_checksum(void *data, int size)
 {
-  uint32_t sum = 0;
-  uint8_t *ptr = (uint8_t *)data;
+       uint32_t sum = 0;
+       uint8_t *ptr = (uint8_t *)data;
 
-  while (size-- > 0)
-  {
-    sum += *ptr++;
-  }
+       while (size-- > 0)
+       {
+               sum += *ptr++;
+       }
 
-  return sum;
+       return sum;
 }
 
 
-void
+       void
 jffs_print_trace(const char *path, int depth)
 {
-  int path_len = strlen(path);
-  int out_pos = depth * JFFS_TRACE_INDENT;
-  int pos = path_len - 1;
-  char *out = (char *)alloca(depth * JFFS_TRACE_INDENT + path_len + 1);
-
-  if (verbose >= 2)
-  {
-    fprintf(stderr, "jffs_print_trace(): path: \"%s\"\n", path);
-  }
-
-  if (!out) {
-    fprintf(stderr, "jffs_print_trace(): Allocation failed.\n");
-    fprintf(stderr, " path: \"%s\"\n", path);
-    fprintf(stderr, "depth: %d\n", depth);
-    exit(1);
-  }
-
-  memset(out, ' ', depth * JFFS_TRACE_INDENT);
-
-  if (path[pos] == '/')
-  {
-    pos--;
-  }
-  while (path[pos] && (path[pos] != '/'))
-  {
-    pos--;
-  }
-  for (pos++; path[pos] && (path[pos] != '/'); pos++)
-  {
-    out[out_pos++] = path[pos];
-  }
-  out[out_pos] = '\0';
-  fprintf(stderr, "%s\n", out);
+       int path_len = strlen(path);
+       int out_pos = depth * JFFS_TRACE_INDENT;
+       int pos = path_len - 1;
+       char *out = (char *)alloca(depth * JFFS_TRACE_INDENT + path_len + 1);
+
+       if (verbose >= 2)
+       {
+               fprintf(stderr, "jffs_print_trace(): path: \"%s\"\n", path);
+       }
+
+       if (!out) {
+               fprintf(stderr, "jffs_print_trace(): Allocation failed.\n");
+               fprintf(stderr, " path: \"%s\"\n", path);
+               fprintf(stderr, "depth: %d\n", depth);
+               exit(1);
+       }
+
+       memset(out, ' ', depth * JFFS_TRACE_INDENT);
+
+       if (path[pos] == '/')
+       {
+               pos--;
+       }
+       while (path[pos] && (path[pos] != '/'))
+       {
+               pos--;
+       }
+       for (pos++; path[pos] && (path[pos] != '/'); pos++)
+       {
+               out[out_pos++] = path[pos];
+       }
+       out[out_pos] = '\0';
+       fprintf(stderr, "%s\n", out);
 }
 
 
 /* Print the contents of a raw inode.  */
-void
+       void
 jffs_print_raw_inode(struct jffs_raw_inode *raw_inode)
 {
        fprintf(stdout, "jffs_raw_inode: inode number: %u, version %u\n", raw_inode->ino, raw_inode->version);
@@ -165,13 +165,13 @@ jffs_print_raw_inode(struct jffs_raw_inode *raw_inode)
        fprintf(stdout, "        0x%02x,       /* nsize  */\n", raw_inode->nsize);
        fprintf(stdout, "        0x%02x,       /* nlink  */\n", raw_inode->nlink);
        fprintf(stdout, "        0x%02x,       /* spare  */\n",
-                raw_inode->spare);
+                       raw_inode->spare);
        fprintf(stdout, "        %u,          /* rename  */\n",
-                raw_inode->rename);
+                       raw_inode->rename);
        fprintf(stdout, "        %u,          /* deleted  */\n",
-                raw_inode->deleted);
+                       raw_inode->deleted);
        fprintf(stdout, "        0x%02x,       /* accurate  */\n",
-                raw_inode->accurate);
+                       raw_inode->accurate);
        fprintf(stdout, "        0x%08x, /* dchksum  */\n", raw_inode->dchksum);
        fprintf(stdout, "        0x%04x,     /* nchksum  */\n", raw_inode->nchksum);
        fprintf(stdout, "        0x%04x,     /* chksum  */\n", raw_inode->chksum);
@@ -180,71 +180,71 @@ jffs_print_raw_inode(struct jffs_raw_inode *raw_inode)
 
 static void write_val32(uint32_t *adr, uint32_t val)
 {
-  switch(endian) {
-  case ENDIAN_HOST:
-    *adr = val;
-    break;
-  case ENDIAN_LITTLE:
-    *adr = __cpu_to_le32(val);
-    break;
-  case ENDIAN_BIG:
-    *adr = __cpu_to_be32(val);
-    break;
-  }
+       switch(endian) {
+               case ENDIAN_HOST:
+                       *adr = val;
+                       break;
+               case ENDIAN_LITTLE:
+                       *adr = __cpu_to_le32(val);
+                       break;
+               case ENDIAN_BIG:
+                       *adr = __cpu_to_be32(val);
+                       break;
+       }
 }
 
 static void write_val16(uint16_t *adr, uint16_t val)
 {
-  switch(endian) {
-  case ENDIAN_HOST:
-    *adr = val;
-    break;
-  case ENDIAN_LITTLE:
-    *adr = __cpu_to_le16(val);
-    break;
-  case ENDIAN_BIG:
-    *adr = __cpu_to_be16(val);
-    break;
-  }
+       switch(endian) {
+               case ENDIAN_HOST:
+                       *adr = val;
+                       break;
+               case ENDIAN_LITTLE:
+                       *adr = __cpu_to_le16(val);
+                       break;
+               case ENDIAN_BIG:
+                       *adr = __cpu_to_be16(val);
+                       break;
+       }
 }
 
 static uint32_t read_val32(uint32_t *adr)
 {
-  uint32_t val;
-
-  switch(endian) {
-  case ENDIAN_HOST:
-    val = *adr;
-    break;
-  case ENDIAN_LITTLE:
-    val = __le32_to_cpu(*adr);
-    break;
-  case ENDIAN_BIG:
-    val = __be32_to_cpu(*adr);
-    break;
-  }
-  return val;
+       uint32_t val;
+
+       switch(endian) {
+               case ENDIAN_HOST:
+                       val = *adr;
+                       break;
+               case ENDIAN_LITTLE:
+                       val = __le32_to_cpu(*adr);
+                       break;
+               case ENDIAN_BIG:
+                       val = __be32_to_cpu(*adr);
+                       break;
+       }
+       return val;
 }
 
 static uint16_t read_val16(uint16_t *adr)
 {
-  uint16_t val;
-
-  switch(endian) {
-  case ENDIAN_HOST:
-    val = *adr;
-    break;
-  case ENDIAN_LITTLE:
-    val = __le16_to_cpu(*adr);
-    break;
-  case ENDIAN_BIG:
-    val = __be16_to_cpu(*adr);
-    break;
-  }
-  return val;
+       uint16_t val;
+
+       switch(endian) {
+               case ENDIAN_HOST:
+                       val = *adr;
+                       break;
+               case ENDIAN_LITTLE:
+                       val = __le16_to_cpu(*adr);
+                       break;
+               case ENDIAN_BIG:
+                       val = __be16_to_cpu(*adr);
+                       break;
+       }
+       return val;
 }
 
-int
+       int
 main(int argc, char **argv)
 {
        int fs;
@@ -268,8 +268,8 @@ main(int argc, char **argv)
        }
 
        if (argc > 2) {
-         myino = atol(argv[2]);
-         printf("Printing ino #%d\n" , myino);
+               myino = atol(argv[2]);
+               printf("Printing ino #%d\n" , myino);
        }
 
        if (fstat(fs, &sb) < 0) {
@@ -286,73 +286,73 @@ main(int argc, char **argv)
                }
 
                switch(wordbuf) {
-               case JFFS_EMPTY_BITMASK:
-                 //                    printf("0xff started at 0x%lx\n", pos);
-                       for (; pos < end && wordbuf == JFFS_EMPTY_BITMASK; pos += 4) {
-                               if (pread(fs, &wordbuf, 4, pos) < 0) {
-                                       perror("pread");
-                                       exit(1);
+                       case JFFS_EMPTY_BITMASK:
+                               //                      printf("0xff started at 0x%lx\n", pos);
+                               for (; pos < end && wordbuf == JFFS_EMPTY_BITMASK; pos += 4) {
+                                       if (pread(fs, &wordbuf, 4, pos) < 0) {
+                                               perror("pread");
+                                               exit(1);
+                                       }
                                }
-                       }
-                       if (pos < end)
-                         pos -= 4;
-                       //                      printf("0xff ended at 0x%lx\n", pos);
-                       continue;
-
-               case JFFS_DIRTY_BITMASK:
-                 //                    printf("0x00 started at 0x%lx\n", pos);
-                       for (; pos < end && wordbuf == JFFS_DIRTY_BITMASK; pos += 4) {
-                               if (pread(fs, &wordbuf, 4, pos) < 0) {
-                                       perror("pread");
-                                       exit(1);
+                               if (pos < end)
+                                       pos -= 4;
+                               //                      printf("0xff ended at 0x%lx\n", pos);
+                               continue;
+
+                       case JFFS_DIRTY_BITMASK:
+                               //                      printf("0x00 started at 0x%lx\n", pos);
+                               for (; pos < end && wordbuf == JFFS_DIRTY_BITMASK; pos += 4) {
+                                       if (pread(fs, &wordbuf, 4, pos) < 0) {
+                                               perror("pread");
+                                               exit(1);
+                                       }
                                }
-                       }
-                       if (pos < end)
-                         pos -=4;
-                       //                      printf("0x00 ended at 0x%lx\n", pos);
-                       continue;
-
-               default:
-                       printf("Argh. Dirty memory at 0x%lx\n", pos);
-                       //                      file_hexdump(fs, pos, 128);
-                       for (pos += 4; pos < end; pos += 4) {
-                               if (pread(fs, &wordbuf, 4, pos) < 0) {
+                               if (pos < end)
+                                       pos -=4;
+                               //                      printf("0x00 ended at 0x%lx\n", pos);
+                               continue;
+
+                       default:
+                               printf("Argh. Dirty memory at 0x%lx\n", pos);
+                               //                      file_hexdump(fs, pos, 128);
+                               for (pos += 4; pos < end; pos += 4) {
+                                       if (pread(fs, &wordbuf, 4, pos) < 0) {
+                                               perror("pread");
+                                               exit(1);
+                                       }
+                                       if (wordbuf == JFFS_MAGIC_BITMASK)
+                                               break;
+                               }
+
+                       case JFFS_MAGIC_BITMASK:
+                               if (pread(fs, &ino, sizeof(ino), pos) < 0) {
                                        perror("pread");
                                        exit(1);
                                }
-                               if (wordbuf == JFFS_MAGIC_BITMASK)
-                                       break;
-                        }
-
-               case JFFS_MAGIC_BITMASK:
-                       if (pread(fs, &ino, sizeof(ino), pos) < 0) {
-                               perror("pread");
-                               exit(1);
-                       }
-                       if (myino == -1 || ino.ino == myino) {
-                               printf("Magic found at 0x%lx\n", pos);
-                               jffs_print_raw_inode(&ino);
-                       }
-                       pos += sizeof(ino);
-
-                       if (myino == -1 || ino.ino == myino) {
-                               if (ino.nsize) {
-                                       if (pread(fs, namebuf, min(ino.nsize, 4095), pos) < 0) {
-                                               perror("pread");
-                                               exit(1);
+                               if (myino == -1 || ino.ino == myino) {
+                                       printf("Magic found at 0x%lx\n", pos);
+                                       jffs_print_raw_inode(&ino);
+                               }
+                               pos += sizeof(ino);
+
+                               if (myino == -1 || ino.ino == myino) {
+                                       if (ino.nsize) {
+                                               if (pread(fs, namebuf, min(ino.nsize, 4095), pos) < 0) {
+                                                       perror("pread");
+                                                       exit(1);
+                                               }
+                                               if (ino.nsize < 4095)
+                                                       namebuf[ino.nsize] = 0;
+                                               else
+                                                       namebuf[4095] = 0;
+                                               printf("Name: \"%s\"\n", namebuf);
+                                       } else {
+                                               printf("No Name\n");
                                        }
-                                       if (ino.nsize < 4095)
-                                               namebuf[ino.nsize] = 0;
-                                       else
-                                               namebuf[4095] = 0;
-                                       printf("Name: \"%s\"\n", namebuf);
-                               } else {
-                                       printf("No Name\n");
                                }
-                       }
-                       pos += (ino.nsize + 3) & ~3;
+                               pos += (ino.nsize + 3) & ~3;
 
-                       pos += (ino.dsize + 3) & ~3;
+                               pos += (ino.dsize + 3) & ~3;
                }
 
 
index 0db0cd740e8f27ca233f0ff52c065ba550a928d6..2842f032ba420db70d3fe5cba97d6c69c7494ff5 100644 (file)
@@ -55,33 +55,33 @@ char        *data;          // image data
 void display_help (void)
 {
        printf("Usage: dumpjffs2 [OPTION] INPUTFILE\n"
-              "Dumps the contents of a binary JFFS2 image.\n"
-              "\n"
-              "           --help                     display this help and exit\n"
-              "           --version                  output version information and exit\n"
-              "-b         --bigendian                image is big endian\n"
-              "-l         --littleendian             image is little endian\n"
-              "-c         --content                  dump image contents\n"
-              "-e fname   --endianconvert=fname      convert image endianness, output to file fname\n"
-              "-r         --recalccrc                recalc name and data crc on endian conversion\n"
-              "-d len     --datsize=len              size of data chunks, when oob data in binary image (NAND only)\n"
-              "-o len     --oobsize=len              size of oob data chunk in binary image (NAND only)\n"
-              "-v         --verbose                  verbose output\n");
+                       "Dumps the contents of a binary JFFS2 image.\n"
+                       "\n"
+                       "           --help                    display this help and exit\n"
+                       "           --version                 output version information and exit\n"
+                       "-b         --bigendian               image is big endian\n"
+                       "-l         --littleendian             image is little endian\n"
+                       "-c         --content                 dump image contents\n"
+                       "-e fname   --endianconvert=fname      convert image endianness, output to file fname\n"
+                       "-r         --recalccrc                recalc name and data crc on endian conversion\n"
+                       "-d len     --datsize=len              size of data chunks, when oob data in binary image (NAND only)\n"
+                       "-o len     --oobsize=len              size of oob data chunk in binary image (NAND only)\n"
+                       "-v         --verbose                 verbose output\n");
        exit(0);
 }
 
 void display_version (void)
 {
        printf(PROGRAM " " VERSION "\n"
-              "\n"
-              "Copyright (C) 2003 Thomas Gleixner \n"
-              "\n"
-              PROGRAM " comes with NO WARRANTY\n"
-              "to the extent permitted by law.\n"
-              "\n"
-              "You may redistribute copies of " PROGRAM "\n"
-              "under the terms of the GNU General Public Licence.\n"
-              "See the file `COPYING' for more information.\n");
+                       "\n"
+                       "Copyright (C) 2003 Thomas Gleixner \n"
+                       "\n"
+                       PROGRAM " comes with NO WARRANTY\n"
+                       "to the extent permitted by law.\n"
+                       "\n"
+                       "You may redistribute copies of " PROGRAM "\n"
+                       "under the terms of the GNU General Public Licence.\n"
+                       "See the file `COPYING' for more information.\n");
        exit(0);
 }
 
@@ -119,50 +119,50 @@ void process_options (int argc, char *argv[])
                };
 
                int c = getopt_long(argc, argv, short_options,
-                                   long_options, &option_index);
+                               long_options, &option_index);
                if (c == EOF) {
                        break;
                }
 
                switch (c) {
-               case 0:
-                       switch (option_index) {
                        case 0:
-                               display_help();
+                               switch (option_index) {
+                                       case 0:
+                                               display_help();
+                                               break;
+                                       case 1:
+                                               display_version();
+                                               break;
+                               }
                                break;
-                       case 1:
-                               display_version();
+                       case 'v':
+                               verbose = 1;
+                               break;
+                       case 'b':
+                               target_endian = __BIG_ENDIAN;
+                               break;
+                       case 'l':
+                               target_endian = __LITTLE_ENDIAN;
+                               break;
+                       case 'c':
+                               dumpcontent = 1;
+                               break;
+                       case 'd':
+                               datsize = atoi(optarg);
+                               break;
+                       case 'o':
+                               oobsize = atoi(optarg);
+                               break;
+                       case 'e':
+                               convertendian = 1;
+                               strcpy (cnvfile, optarg);
+                               break;
+                       case 'r':
+                               recalccrc = 1;
+                               break;
+                       case '?':
+                               error = 1;
                                break;
-                       }
-                       break;
-               case 'v':
-                       verbose = 1;
-                       break;
-               case 'b':
-                       target_endian = __BIG_ENDIAN;
-                       break;
-               case 'l':
-                       target_endian = __LITTLE_ENDIAN;
-                       break;
-               case 'c':
-                       dumpcontent = 1;
-                       break;
-               case 'd':
-                       datsize = atoi(optarg);
-                       break;
-               case 'o':
-                       oobsize = atoi(optarg);
-                       break;
-               case 'e':
-                       convertendian = 1;
-                       strcpy (cnvfile, optarg);
-                       break;
-               case 'r':
-                       recalccrc = 1;
-                       break;
-               case '?':
-                       error = 1;
-                       break;
                }
        }
 
@@ -206,7 +206,7 @@ void do_dumpcontent (void)
 
                if (je16_to_cpu (node->u.magic) != JFFS2_MAGIC_BITMASK) {
                        if (!bitchbitmask++)
-                           printf ("Wrong bitmask  at  0x%08x, 0x%04x\n", p - data, je16_to_cpu (node->u.magic));
+                               printf ("Wrong bitmask  at  0x%08x, 0x%04x\n", p - data, je16_to_cpu (node->u.magic));
                        p += 4;
                        dirty += 4;
                        continue;
@@ -232,184 +232,184 @@ void do_dumpcontent (void)
 
                switch(je16_to_cpu(node->u.nodetype)) {
 
-               case JFFS2_NODETYPE_INODE:
-                       printf ("%8s Inode      node at 0x%08x, totlen 0x%08x, #ino  %5d, version %5d, isize %8d, csize %8d, dsize %8d, offset %8d\n",
-                                       obsolete ? "Obsolete" : "",
-                                       p - data, je32_to_cpu (node->i.totlen), je32_to_cpu (node->i.ino),
-                                       je32_to_cpu ( node->i.version), je32_to_cpu (node->i.isize),
-                                       je32_to_cpu (node->i.csize), je32_to_cpu (node->i.dsize), je32_to_cpu (node->i.offset));
+                       case JFFS2_NODETYPE_INODE:
+                               printf ("%8s Inode      node at 0x%08x, totlen 0x%08x, #ino  %5d, version %5d, isize %8d, csize %8d, dsize %8d, offset %8d\n",
+                                               obsolete ? "Obsolete" : "",
+                                               p - data, je32_to_cpu (node->i.totlen), je32_to_cpu (node->i.ino),
+                                               je32_to_cpu ( node->i.version), je32_to_cpu (node->i.isize),
+                                               je32_to_cpu (node->i.csize), je32_to_cpu (node->i.dsize), je32_to_cpu (node->i.offset));
+
+                               crc = crc32 (0, node, sizeof (struct jffs2_raw_inode) - 8);
+                               if (crc != je32_to_cpu (node->i.node_crc)) {
+                                       printf ("Wrong node_crc at  0x%08x, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->i.node_crc), crc);
+                                       p += PAD(je32_to_cpu (node->i.totlen));
+                                       dirty += PAD(je32_to_cpu (node->i.totlen));;
+                                       continue;
+                               }
 
-                       crc = crc32 (0, node, sizeof (struct jffs2_raw_inode) - 8);
-                       if (crc != je32_to_cpu (node->i.node_crc)) {
-                               printf ("Wrong node_crc at  0x%08x, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->i.node_crc), crc);
-                               p += PAD(je32_to_cpu (node->i.totlen));
-                               dirty += PAD(je32_to_cpu (node->i.totlen));;
-                               continue;
-                       }
+                               crc = crc32(0, p + sizeof (struct jffs2_raw_inode), je32_to_cpu(node->i.csize));
+                               if (crc != je32_to_cpu(node->i.data_crc)) {
+                                       printf ("Wrong data_crc at  0x%08x, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->i.data_crc), crc);
+                                       p += PAD(je32_to_cpu (node->i.totlen));
+                                       dirty += PAD(je32_to_cpu (node->i.totlen));;
+                                       continue;
+                               }
 
-                       crc = crc32(0, p + sizeof (struct jffs2_raw_inode), je32_to_cpu(node->i.csize));
-                       if (crc != je32_to_cpu(node->i.data_crc)) {
-                               printf ("Wrong data_crc at  0x%08x, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->i.data_crc), crc);
                                p += PAD(je32_to_cpu (node->i.totlen));
-                               dirty += PAD(je32_to_cpu (node->i.totlen));;
-                               continue;
-                       }
-
-                       p += PAD(je32_to_cpu (node->i.totlen));
-                       break;
-
-               case JFFS2_NODETYPE_DIRENT:
-                       memcpy (name, node->d.name, node->d.nsize);
-                       name [node->d.nsize] = 0x0;
-                       printf ("%8s Dirent     node at 0x%08x, totlen 0x%08x, #pino %5d, version %5d, #ino  %8d, nsize %8d, name %s\n",
-                                       obsolete ? "Obsolete" : "",
-                                       p - data, je32_to_cpu (node->d.totlen), je32_to_cpu (node->d.pino),
-                                       je32_to_cpu ( node->d.version), je32_to_cpu (node->d.ino),
-                                       node->d.nsize, name);
-
-                       crc = crc32 (0, node, sizeof (struct jffs2_raw_dirent) - 8);
-                       if (crc != je32_to_cpu (node->d.node_crc)) {
-                               printf ("Wrong node_crc at  0x%08x, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->d.node_crc), crc);
-                               p += PAD(je32_to_cpu (node->d.totlen));
-                               dirty += PAD(je32_to_cpu (node->d.totlen));;
-                               continue;
-                       }
-
-                       crc = crc32(0, p + sizeof (struct jffs2_raw_dirent), node->d.nsize);
-                       if (crc != je32_to_cpu(node->d.name_crc)) {
-                               printf ("Wrong name_crc at  0x%08x, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->d.name_crc), crc);
-                               p += PAD(je32_to_cpu (node->d.totlen));
-                               dirty += PAD(je32_to_cpu (node->d.totlen));;
-                               continue;
-                       }
-
-                       p += PAD(je32_to_cpu (node->d.totlen));
-                       break;
+                               break;
 
-               case JFFS2_NODETYPE_SUMMARY: {
-
-                       int i;
-                       struct jffs2_sum_marker * sm;
-
-                       printf("%8s Inode Sum  node at 0x%08x, totlen 0x%08x, sum_num  %5d, cleanmarker size %5d\n",
-                                       obsolete ? "Obsolete" : "",
-                                       p - data,
-                                       je32_to_cpu (node->s.totlen),
-                                       je32_to_cpu (node->s.sum_num),
-                                       je32_to_cpu (node->s.cln_mkr));
-
-                       crc = crc32 (0, node, sizeof (struct jffs2_raw_summary) - 8);
-                       if (crc != je32_to_cpu (node->s.node_crc)) {
-                               printf ("Wrong node_crc at  0x%08x, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->s.node_crc), crc);
-                               p += PAD(je32_to_cpu (node->s.totlen));
-                               dirty += PAD(je32_to_cpu (node->s.totlen));;
-                               continue;
-                       }
-
-                       crc = crc32(0, p + sizeof (struct jffs2_raw_summary),  je32_to_cpu (node->s.totlen) - sizeof(struct jffs2_raw_summary));
-                       if (crc != je32_to_cpu(node->s.sum_crc)) {
-                               printf ("Wrong data_crc at  0x%08x, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->s.sum_crc), crc);
-                               p += PAD(je32_to_cpu (node->s.totlen));
-                               dirty += PAD(je32_to_cpu (node->s.totlen));;
-                               continue;
-                       }
-
-                       if (verbose) {
-                               void *sp;
-                               sp = (p + sizeof(struct jffs2_raw_summary));
-
-                               for(i=0; i<je32_to_cpu(node->s.sum_num); i++) {
-
-                                       switch(je16_to_cpu(((struct jffs2_sum_unknown_flash *)sp)->nodetype)) {
-                                               case JFFS2_NODETYPE_INODE : {
-
-                                                       struct jffs2_sum_inode_flash *spi;
-                                                       spi = sp;
-
-                                                       printf ("%14s #ino  %5d,  version %5d, offset 0x%08x, totlen 0x%08x\n",
-                                                       "",
-                                                       je32_to_cpu (spi->inode),
-                                                       je32_to_cpu (spi->version),
-                                                       je32_to_cpu (spi->offset),
-                                                       je32_to_cpu (spi->totlen));
-
-                                                       sp += JFFS2_SUMMARY_INODE_SIZE;
-                                                       break;
-                                               }
-
-                                               case JFFS2_NODETYPE_DIRENT : {
-
-                                                       char name[255];
-                                                       struct jffs2_sum_dirent_flash *spd;
-                                                       spd = sp;
-
-                                                       memcpy(name,spd->name,spd->nsize);
-                                                       name [spd->nsize] = 0x0;
-
-                                                       printf ("%14s dirent offset 0x%08x, totlen 0x%08x, #pino  %5d,  version %5d, #ino  %8d, nsize %8d, name %s \n",
-                                                       "",
-                                                       je32_to_cpu (spd->offset),
-                                                       je32_to_cpu (spd->totlen),
-                                                       je32_to_cpu (spd->pino),
-                                                       je32_to_cpu (spd->version),
-                                                       je32_to_cpu (spd->ino),
-                                                       spd->nsize,
-                                                       name);
-
-                                                       sp += JFFS2_SUMMARY_DIRENT_SIZE(spd->nsize);
-                                                       break;
-                                               }
-
-                                               default :
-                                                       printf("Unknown summary node!\n");
-                                                       break;
-                                       }
+                       case JFFS2_NODETYPE_DIRENT:
+                               memcpy (name, node->d.name, node->d.nsize);
+                               name [node->d.nsize] = 0x0;
+                               printf ("%8s Dirent     node at 0x%08x, totlen 0x%08x, #pino %5d, version %5d, #ino  %8d, nsize %8d, name %s\n",
+                                               obsolete ? "Obsolete" : "",
+                                               p - data, je32_to_cpu (node->d.totlen), je32_to_cpu (node->d.pino),
+                                               je32_to_cpu ( node->d.version), je32_to_cpu (node->d.ino),
+                                               node->d.nsize, name);
+
+                               crc = crc32 (0, node, sizeof (struct jffs2_raw_dirent) - 8);
+                               if (crc != je32_to_cpu (node->d.node_crc)) {
+                                       printf ("Wrong node_crc at  0x%08x, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->d.node_crc), crc);
+                                       p += PAD(je32_to_cpu (node->d.totlen));
+                                       dirty += PAD(je32_to_cpu (node->d.totlen));;
+                                       continue;
                                }
 
-                               sm = (struct jffs2_sum_marker *) ((char *)p + je32_to_cpu(node->s.totlen) - sizeof(struct jffs2_sum_marker));
-
-                               printf("%14s Sum Node Offset  0x%08x, Magic 0x%08x, Padded size 0x%08x\n",
-                                       "",
-                                       je32_to_cpu(sm->offset),
-                                       je32_to_cpu(sm->magic),
-                                       je32_to_cpu(node->s.padded));
-                       }
-
-                       p += PAD(je32_to_cpu (node->s.totlen));
-                       break;
-               }
-
-               case JFFS2_NODETYPE_CLEANMARKER:
-                       if (verbose) {
-                               printf ("%8s Cleanmarker     at 0x%08x, totlen 0x%08x\n",
-                                       obsolete ? "Obsolete" : "",
-                                       p - data, je32_to_cpu (node->u.totlen));
-                       }
-                       p += PAD(je32_to_cpu (node->u.totlen));
-                       break;
-
-               case JFFS2_NODETYPE_PADDING:
-                       if (verbose) {
-                               printf ("%8s Padding    node at 0x%08x, totlen 0x%08x\n",
-                                       obsolete ? "Obsolete" : "",
-                                       p - data, je32_to_cpu (node->u.totlen));
-                       }
-                       p += PAD(je32_to_cpu (node->u.totlen));
-                       break;
+                               crc = crc32(0, p + sizeof (struct jffs2_raw_dirent), node->d.nsize);
+                               if (crc != je32_to_cpu(node->d.name_crc)) {
+                                       printf ("Wrong name_crc at  0x%08x, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->d.name_crc), crc);
+                                       p += PAD(je32_to_cpu (node->d.totlen));
+                                       dirty += PAD(je32_to_cpu (node->d.totlen));;
+                                       continue;
+                               }
 
-               case 0xffff:
-                       p += 4;
-                       empty += 4;
-                       break;
+                               p += PAD(je32_to_cpu (node->d.totlen));
+                               break;
 
-               default:
-                       if (verbose) {
-                               printf ("%8s Unknown    node at 0x%08x, totlen 0x%08x\n",
-                                       obsolete ? "Obsolete" : "",
-                                       p - data, je32_to_cpu (node->u.totlen));
-                       }
-                       p += PAD(je32_to_cpu (node->u.totlen));
-                       dirty += PAD(je32_to_cpu (node->u.totlen));
+                       case JFFS2_NODETYPE_SUMMARY: {
+
+                                                                                        int i;
+                                                                                        struct jffs2_sum_marker * sm;
+
+                                                                                        printf("%8s Inode Sum  node at 0x%08x, totlen 0x%08x, sum_num  %5d, cleanmarker size %5d\n",
+                                                                                                        obsolete ? "Obsolete" : "",
+                                                                                                        p - data,
+                                                                                                        je32_to_cpu (node->s.totlen),
+                                                                                                        je32_to_cpu (node->s.sum_num),
+                                                                                                        je32_to_cpu (node->s.cln_mkr));
+
+                                                                                        crc = crc32 (0, node, sizeof (struct jffs2_raw_summary) - 8);
+                                                                                        if (crc != je32_to_cpu (node->s.node_crc)) {
+                                                                                                printf ("Wrong node_crc at  0x%08x, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->s.node_crc), crc);
+                                                                                                p += PAD(je32_to_cpu (node->s.totlen));
+                                                                                                dirty += PAD(je32_to_cpu (node->s.totlen));;
+                                                                                                continue;
+                                                                                        }
+
+                                                                                        crc = crc32(0, p + sizeof (struct jffs2_raw_summary),  je32_to_cpu (node->s.totlen) - sizeof(struct jffs2_raw_summary));
+                                                                                        if (crc != je32_to_cpu(node->s.sum_crc)) {
+                                                                                                printf ("Wrong data_crc at  0x%08x, 0x%08x instead of 0x%08x\n", p - data, je32_to_cpu (node->s.sum_crc), crc);
+                                                                                                p += PAD(je32_to_cpu (node->s.totlen));
+                                                                                                dirty += PAD(je32_to_cpu (node->s.totlen));;
+                                                                                                continue;
+                                                                                        }
+
+                                                                                        if (verbose) {
+                                                                                                void *sp;
+                                                                                                sp = (p + sizeof(struct jffs2_raw_summary));
+
+                                                                                                for(i=0; i<je32_to_cpu(node->s.sum_num); i++) {
+
+                                                                                                        switch(je16_to_cpu(((struct jffs2_sum_unknown_flash *)sp)->nodetype)) {
+                                                                                                                case JFFS2_NODETYPE_INODE : {
+
+                                                                                                                                                                                struct jffs2_sum_inode_flash *spi;
+                                                                                                                                                                                spi = sp;
+
+                                                                                                                                                                                printf ("%14s #ino  %5d,  version %5d, offset 0x%08x, totlen 0x%08x\n",
+                                                                                                                                                                                                "",
+                                                                                                                                                                                                je32_to_cpu (spi->inode),
+                                                                                                                                                                                                je32_to_cpu (spi->version),
+                                                                                                                                                                                                je32_to_cpu (spi->offset),
+                                                                                                                                                                                                je32_to_cpu (spi->totlen));
+
+                                                                                                                                                                                sp += JFFS2_SUMMARY_INODE_SIZE;
+                                                                                                                                                                                break;
+                                                                                                                                                                        }
+
+                                                                                                                case JFFS2_NODETYPE_DIRENT : {
+
+                                                                                                                                                                                 char name[255];
+                                                                                                                                                                                 struct jffs2_sum_dirent_flash *spd;
+                                                                                                                                                                                 spd = sp;
+
+                                                                                                                                                                                 memcpy(name,spd->name,spd->nsize);
+                                                                                                                                                                                 name [spd->nsize] = 0x0;
+
+                                                                                                                                                                                 printf ("%14s dirent offset 0x%08x, totlen 0x%08x, #pino  %5d,  version %5d, #ino  %8d, nsize %8d, name %s \n",
+                                                                                                                                                                                                 "",
+                                                                                                                                                                                                 je32_to_cpu (spd->offset),
+                                                                                                                                                                                                 je32_to_cpu (spd->totlen),
+                                                                                                                                                                                                 je32_to_cpu (spd->pino),
+                                                                                                                                                                                                 je32_to_cpu (spd->version),
+                                                                                                                                                                                                 je32_to_cpu (spd->ino),
+                                                                                                                                                                                                 spd->nsize,
+                                                                                                                                                                                                 name);
+
+                                                                                                                                                                                 sp += JFFS2_SUMMARY_DIRENT_SIZE(spd->nsize);
+                                                                                                                                                                                 break;
+                                                                                                                                                                         }
+
+                                                                                                                default :
+                                                                                                                                                                         printf("Unknown summary node!\n");
+                                                                                                                                                                         break;
+                                                                                                        }
+                                                                                                }
+
+                                                                                                sm = (struct jffs2_sum_marker *) ((char *)p + je32_to_cpu(node->s.totlen) - sizeof(struct jffs2_sum_marker));
+
+                                                                                                printf("%14s Sum Node Offset  0x%08x, Magic 0x%08x, Padded size 0x%08x\n",
+                                                                                                                "",
+                                                                                                                je32_to_cpu(sm->offset),
+                                                                                                                je32_to_cpu(sm->magic),
+                                                                                                                je32_to_cpu(node->s.padded));
+                                                                                        }
+
+                                                                                        p += PAD(je32_to_cpu (node->s.totlen));
+                                                                                        break;
+                                                                                }
+
+                       case JFFS2_NODETYPE_CLEANMARKER:
+                                                                                if (verbose) {
+                                                                                        printf ("%8s Cleanmarker     at 0x%08x, totlen 0x%08x\n",
+                                                                                                        obsolete ? "Obsolete" : "",
+                                                                                                        p - data, je32_to_cpu (node->u.totlen));
+                                                                                }
+                                                                                p += PAD(je32_to_cpu (node->u.totlen));
+                                                                                break;
+
+                       case JFFS2_NODETYPE_PADDING:
+                                                                                if (verbose) {
+                                                                                        printf ("%8s Padding    node at 0x%08x, totlen 0x%08x\n",
+                                                                                                        obsolete ? "Obsolete" : "",
+                                                                                                        p - data, je32_to_cpu (node->u.totlen));
+                                                                                }
+                                                                                p += PAD(je32_to_cpu (node->u.totlen));
+                                                                                break;
+
+                       case 0xffff:
+                                                                                p += 4;
+                                                                                empty += 4;
+                                                                                break;
+
+                       default:
+                                                                                if (verbose) {
+                                                                                        printf ("%8s Unknown    node at 0x%08x, totlen 0x%08x\n",
+                                                                                                        obsolete ? "Obsolete" : "",
+                                                                                                        p - data, je32_to_cpu (node->u.totlen));
+                                                                                }
+                                                                                p += PAD(je32_to_cpu (node->u.totlen));
+                                                                                dirty += PAD(je32_to_cpu (node->u.totlen));
 
                }
        }
@@ -461,168 +461,168 @@ void do_endianconvert (void)
 
                switch(je16_to_cpu(node->u.nodetype)) {
 
-               case JFFS2_NODETYPE_INODE:
-
-                       newnode.i.magic = cnv_e16 (node->i.magic);
-                       newnode.i.nodetype = cnv_e16 (node->i.nodetype);
-                       newnode.i.totlen = cnv_e32 (node->i.totlen);
-                       newnode.i.hdr_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
-                       newnode.i.ino = cnv_e32 (node->i.ino);
-                       newnode.i.version = cnv_e32 (node->i.version);
-                       mode.v32 = node->i.mode.m;
-                       mode = cnv_e32 (mode);
-                       newnode.i.mode.m = mode.v32;
-                       newnode.i.uid = cnv_e16 (node->i.uid);
-                       newnode.i.gid = cnv_e16 (node->i.gid);
-                       newnode.i.isize = cnv_e32 (node->i.isize);
-                       newnode.i.atime = cnv_e32 (node->i.atime);
-                       newnode.i.mtime = cnv_e32 (node->i.mtime);
-                       newnode.i.ctime = cnv_e32 (node->i.ctime);
-                       newnode.i.offset = cnv_e32 (node->i.offset);
-                       newnode.i.csize = cnv_e32 (node->i.csize);
-                       newnode.i.dsize = cnv_e32 (node->i.dsize);
-                       newnode.i.compr = node->i.compr;
-                       newnode.i.usercompr = node->i.usercompr;
-                       newnode.i.flags = cnv_e16 (node->i.flags);
-                       if (recalccrc) {
-                               len = je32_to_cpu(node->i.csize);
-                               newnode.i.data_crc = cpu_to_e32 ( crc32(0, p + sizeof (struct jffs2_raw_inode), len));
-                       } else
-                               newnode.i.data_crc = cnv_e32 (node->i.data_crc);
-
-                       newnode.i.node_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_raw_inode) - 8));
-
-                       write (fd, &newnode, sizeof (struct jffs2_raw_inode));
-                       write (fd, p + sizeof (struct jffs2_raw_inode), PAD (je32_to_cpu (node->i.totlen) -  sizeof (struct jffs2_raw_inode)));
-
-                       p += PAD(je32_to_cpu (node->i.totlen));
-                       break;
-
-               case JFFS2_NODETYPE_DIRENT:
-                       newnode.d.magic = cnv_e16 (node->d.magic);
-                       newnode.d.nodetype = cnv_e16 (node->d.nodetype);
-                       newnode.d.totlen = cnv_e32 (node->d.totlen);
-                       newnode.d.hdr_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
-                       newnode.d.pino = cnv_e32 (node->d.pino);
-                       newnode.d.version = cnv_e32 (node->d.version);
-                       newnode.d.ino = cnv_e32 (node->d.ino);
-                       newnode.d.mctime = cnv_e32 (node->d.mctime);
-                       newnode.d.nsize = node->d.nsize;
-                       newnode.d.type = node->d.type;
-                       newnode.d.unused[0] = node->d.unused[0];
-                       newnode.d.unused[1] = node->d.unused[1];
-                       newnode.d.node_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_raw_dirent) - 8));
-                       if (recalccrc)
-                               newnode.d.name_crc = cpu_to_e32 ( crc32(0, p + sizeof (struct jffs2_raw_dirent), node->d.nsize));
-                       else
-                               newnode.d.name_crc = cnv_e32 (node->d.name_crc);
-
-                       write (fd, &newnode, sizeof (struct jffs2_raw_dirent));
-                       write (fd, p + sizeof (struct jffs2_raw_dirent), PAD (je32_to_cpu (node->d.totlen) -  sizeof (struct jffs2_raw_dirent)));
-                       p += PAD(je32_to_cpu (node->d.totlen));
-                       break;
-
-               case JFFS2_NODETYPE_CLEANMARKER:
-               case JFFS2_NODETYPE_PADDING:
-                       newnode.u.magic = cnv_e16 (node->u.magic);
-                       newnode.u.nodetype = cnv_e16 (node->u.nodetype);
-                       newnode.u.totlen = cnv_e32 (node->u.totlen);
-                       newnode.u.hdr_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
-
-                       write (fd, &newnode, sizeof (struct jffs2_unknown_node));
-                       len = PAD(je32_to_cpu (node->u.totlen) - sizeof (struct jffs2_unknown_node));
-                       if (len > 0)
-                               write (fd, p + sizeof (struct jffs2_unknown_node), len);
-
-                       p += PAD(je32_to_cpu (node->u.totlen));
-                       break;
-
-               case JFFS2_NODETYPE_SUMMARY : {
-                       struct jffs2_sum_marker *sm_ptr;
-                       int i,sum_len;
-                       int counter = 0;
-
-                       newnode.s.magic = cnv_e16 (node->s.magic);
-                       newnode.s.nodetype = cnv_e16 (node->s.nodetype);
-                       newnode.s.totlen = cnv_e32 (node->s.totlen);
-                       newnode.s.hdr_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
-                       newnode.s.sum_num = cnv_e32 (node->s.sum_num);
-                       newnode.s.cln_mkr = cnv_e32 (node->s.cln_mkr);
-                       newnode.s.padded = cnv_e32 (node->s.padded);
-
-                       newnode.s.node_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_raw_summary) - 8));
-
-                       // summary header
-                       p += sizeof (struct jffs2_raw_summary);
-
-                       // summary data
-                       sum_len = je32_to_cpu (node->s.totlen) - sizeof (struct jffs2_raw_summary) - sizeof (struct jffs2_sum_marker);
-
-                       for (i=0; i<je32_to_cpu (node->s.sum_num); i++) {
-                               union jffs2_sum_flash *fl_ptr;
-
-                               fl_ptr = (union jffs2_sum_flash *) p;
+                       case JFFS2_NODETYPE_INODE:
+
+                               newnode.i.magic = cnv_e16 (node->i.magic);
+                               newnode.i.nodetype = cnv_e16 (node->i.nodetype);
+                               newnode.i.totlen = cnv_e32 (node->i.totlen);
+                               newnode.i.hdr_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
+                               newnode.i.ino = cnv_e32 (node->i.ino);
+                               newnode.i.version = cnv_e32 (node->i.version);
+                               mode.v32 = node->i.mode.m;
+                               mode = cnv_e32 (mode);
+                               newnode.i.mode.m = mode.v32;
+                               newnode.i.uid = cnv_e16 (node->i.uid);
+                               newnode.i.gid = cnv_e16 (node->i.gid);
+                               newnode.i.isize = cnv_e32 (node->i.isize);
+                               newnode.i.atime = cnv_e32 (node->i.atime);
+                               newnode.i.mtime = cnv_e32 (node->i.mtime);
+                               newnode.i.ctime = cnv_e32 (node->i.ctime);
+                               newnode.i.offset = cnv_e32 (node->i.offset);
+                               newnode.i.csize = cnv_e32 (node->i.csize);
+                               newnode.i.dsize = cnv_e32 (node->i.dsize);
+                               newnode.i.compr = node->i.compr;
+                               newnode.i.usercompr = node->i.usercompr;
+                               newnode.i.flags = cnv_e16 (node->i.flags);
+                               if (recalccrc) {
+                                       len = je32_to_cpu(node->i.csize);
+                                       newnode.i.data_crc = cpu_to_e32 ( crc32(0, p + sizeof (struct jffs2_raw_inode), len));
+                               } else
+                                       newnode.i.data_crc = cnv_e32 (node->i.data_crc);
+
+                               newnode.i.node_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_raw_inode) - 8));
+
+                               write (fd, &newnode, sizeof (struct jffs2_raw_inode));
+                               write (fd, p + sizeof (struct jffs2_raw_inode), PAD (je32_to_cpu (node->i.totlen) -  sizeof (struct jffs2_raw_inode)));
 
-                               switch (je16_to_cpu (fl_ptr->u.nodetype)) {
-                                       case JFFS2_NODETYPE_INODE:
-
-                                               fl_ptr->i.nodetype = cnv_e16 (fl_ptr->i.nodetype);
-                                               fl_ptr->i.inode = cnv_e32 (fl_ptr->i.inode);
-                                               fl_ptr->i.version = cnv_e32 (fl_ptr->i.version);
-                                               fl_ptr->i.offset = cnv_e32 (fl_ptr->i.offset);
-                                               fl_ptr->i.totlen = cnv_e32 (fl_ptr->i.totlen);
-                                               p += sizeof (struct jffs2_sum_inode_flash);
-                                               counter += sizeof (struct jffs2_sum_inode_flash);
-                                               break;
-
-                                       case JFFS2_NODETYPE_DIRENT:
-                                               fl_ptr->d.nodetype = cnv_e16 (fl_ptr->d.nodetype);
-                                               fl_ptr->d.totlen = cnv_e32 (fl_ptr->d.totlen);
-                                               fl_ptr->d.offset = cnv_e32 (fl_ptr->d.offset);
-                                               fl_ptr->d.pino = cnv_e32 (fl_ptr->d.pino);
-                                               fl_ptr->d.version = cnv_e32 (fl_ptr->d.version);
-                                               fl_ptr->d.ino = cnv_e32 (fl_ptr->d.ino);
-                                               p += sizeof (struct jffs2_sum_dirent_flash) + fl_ptr->d.nsize;
-                                               counter += sizeof (struct jffs2_sum_dirent_flash) + fl_ptr->d.nsize;
-                                               break;
-
-                                       default :
-                                               printf("Unknown node in summary information!!! nodetype(%x)\n", je16_to_cpu (fl_ptr->u.nodetype));
-                                               exit(EXIT_FAILURE);
-                                               break;
-                               }
-
-                       }
-
-                       //pad
-                       p += sum_len - counter;
-
-                       // summary marker
-                       sm_ptr = (struct jffs2_sum_marker *) p;
-                       sm_ptr->offset = cnv_e32 (sm_ptr->offset);
-                       sm_ptr->magic = cnv_e32 (sm_ptr->magic);
-                       p += sizeof (struct jffs2_sum_marker);
+                               p += PAD(je32_to_cpu (node->i.totlen));
+                               break;
 
-                       // generate new crc on sum data
-                       newnode.s.sum_crc = cpu_to_e32 ( crc32(0, ((char *) node) + sizeof (struct jffs2_raw_summary),
-                               je32_to_cpu (node->s.totlen) - sizeof (struct jffs2_raw_summary)));
+                       case JFFS2_NODETYPE_DIRENT:
+                               newnode.d.magic = cnv_e16 (node->d.magic);
+                               newnode.d.nodetype = cnv_e16 (node->d.nodetype);
+                               newnode.d.totlen = cnv_e32 (node->d.totlen);
+                               newnode.d.hdr_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
+                               newnode.d.pino = cnv_e32 (node->d.pino);
+                               newnode.d.version = cnv_e32 (node->d.version);
+                               newnode.d.ino = cnv_e32 (node->d.ino);
+                               newnode.d.mctime = cnv_e32 (node->d.mctime);
+                               newnode.d.nsize = node->d.nsize;
+                               newnode.d.type = node->d.type;
+                               newnode.d.unused[0] = node->d.unused[0];
+                               newnode.d.unused[1] = node->d.unused[1];
+                               newnode.d.node_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_raw_dirent) - 8));
+                               if (recalccrc)
+                                       newnode.d.name_crc = cpu_to_e32 ( crc32(0, p + sizeof (struct jffs2_raw_dirent), node->d.nsize));
+                               else
+                                       newnode.d.name_crc = cnv_e32 (node->d.name_crc);
+
+                               write (fd, &newnode, sizeof (struct jffs2_raw_dirent));
+                               write (fd, p + sizeof (struct jffs2_raw_dirent), PAD (je32_to_cpu (node->d.totlen) -  sizeof (struct jffs2_raw_dirent)));
+                               p += PAD(je32_to_cpu (node->d.totlen));
+                               break;
 
-                       // write out new node header
-                       write(fd, &newnode, sizeof (struct jffs2_raw_summary));
-                       // write out new summary data
-                       write(fd, &node->s.sum, sum_len + sizeof (struct jffs2_sum_marker));
+                       case JFFS2_NODETYPE_CLEANMARKER:
+                       case JFFS2_NODETYPE_PADDING:
+                               newnode.u.magic = cnv_e16 (node->u.magic);
+                               newnode.u.nodetype = cnv_e16 (node->u.nodetype);
+                               newnode.u.totlen = cnv_e32 (node->u.totlen);
+                               newnode.u.hdr_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
 
-                       break;
-               }
+                               write (fd, &newnode, sizeof (struct jffs2_unknown_node));
+                               len = PAD(je32_to_cpu (node->u.totlen) - sizeof (struct jffs2_unknown_node));
+                               if (len > 0)
+                                       write (fd, p + sizeof (struct jffs2_unknown_node), len);
 
-               case 0xffff:
-                       write (fd, p, 4);
-                       p += 4;
-                       break;
+                               p += PAD(je32_to_cpu (node->u.totlen));
+                               break;
 
-               default:
-                       printf ("Unknown node type: 0x%04x at 0x%08x, totlen 0x%08x\n", je16_to_cpu (node->u.nodetype), p - data, je32_to_cpu (node->u.totlen));
-                       p += PAD(je32_to_cpu (node->u.totlen));
+                       case JFFS2_NODETYPE_SUMMARY : {
+                                                                                         struct jffs2_sum_marker *sm_ptr;
+                                                                                         int i,sum_len;
+                                                                                         int counter = 0;
+
+                                                                                         newnode.s.magic = cnv_e16 (node->s.magic);
+                                                                                         newnode.s.nodetype = cnv_e16 (node->s.nodetype);
+                                                                                         newnode.s.totlen = cnv_e32 (node->s.totlen);
+                                                                                         newnode.s.hdr_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_unknown_node) - 4));
+                                                                                         newnode.s.sum_num = cnv_e32 (node->s.sum_num);
+                                                                                         newnode.s.cln_mkr = cnv_e32 (node->s.cln_mkr);
+                                                                                         newnode.s.padded = cnv_e32 (node->s.padded);
+
+                                                                                         newnode.s.node_crc = cpu_to_e32 (crc32 (0, &newnode, sizeof (struct jffs2_raw_summary) - 8));
+
+                                                                                         // summary header
+                                                                                         p += sizeof (struct jffs2_raw_summary);
+
+                                                                                         // summary data
+                                                                                         sum_len = je32_to_cpu (node->s.totlen) - sizeof (struct jffs2_raw_summary) - sizeof (struct jffs2_sum_marker);
+
+                                                                                         for (i=0; i<je32_to_cpu (node->s.sum_num); i++) {
+                                                                                                 union jffs2_sum_flash *fl_ptr;
+
+                                                                                                 fl_ptr = (union jffs2_sum_flash *) p;
+
+                                                                                                 switch (je16_to_cpu (fl_ptr->u.nodetype)) {
+                                                                                                         case JFFS2_NODETYPE_INODE:
+
+                                                                                                                 fl_ptr->i.nodetype = cnv_e16 (fl_ptr->i.nodetype);
+                                                                                                                 fl_ptr->i.inode = cnv_e32 (fl_ptr->i.inode);
+                                                                                                                 fl_ptr->i.version = cnv_e32 (fl_ptr->i.version);
+                                                                                                                 fl_ptr->i.offset = cnv_e32 (fl_ptr->i.offset);
+                                                                                                                 fl_ptr->i.totlen = cnv_e32 (fl_ptr->i.totlen);
+                                                                                                                 p += sizeof (struct jffs2_sum_inode_flash);
+                                                                                                                 counter += sizeof (struct jffs2_sum_inode_flash);
+                                                                                                                 break;
+
+                                                                                                         case JFFS2_NODETYPE_DIRENT:
+                                                                                                                 fl_ptr->d.nodetype = cnv_e16 (fl_ptr->d.nodetype);
+                                                                                                                 fl_ptr->d.totlen = cnv_e32 (fl_ptr->d.totlen);
+                                                                                                                 fl_ptr->d.offset = cnv_e32 (fl_ptr->d.offset);
+                                                                                                                 fl_ptr->d.pino = cnv_e32 (fl_ptr->d.pino);
+                                                                                                                 fl_ptr->d.version = cnv_e32 (fl_ptr->d.version);
+                                                                                                                 fl_ptr->d.ino = cnv_e32 (fl_ptr->d.ino);
+                                                                                                                 p += sizeof (struct jffs2_sum_dirent_flash) + fl_ptr->d.nsize;
+                                                                                                                 counter += sizeof (struct jffs2_sum_dirent_flash) + fl_ptr->d.nsize;
+                                                                                                                 break;
+
+                                                                                                         default :
+                                                                                                                 printf("Unknown node in summary information!!! nodetype(%x)\n", je16_to_cpu (fl_ptr->u.nodetype));
+                                                                                                                 exit(EXIT_FAILURE);
+                                                                                                                 break;
+                                                                                                 }
+
+                                                                                         }
+
+                                                                                         //pad
+                                                                                         p += sum_len - counter;
+
+                                                                                         // summary marker
+                                                                                         sm_ptr = (struct jffs2_sum_marker *) p;
+                                                                                         sm_ptr->offset = cnv_e32 (sm_ptr->offset);
+                                                                                         sm_ptr->magic = cnv_e32 (sm_ptr->magic);
+                                                                                         p += sizeof (struct jffs2_sum_marker);
+
+                                                                                         // generate new crc on sum data
+                                                                                         newnode.s.sum_crc = cpu_to_e32 ( crc32(0, ((char *) node) + sizeof (struct jffs2_raw_summary),
+                                                                                                                 je32_to_cpu (node->s.totlen) - sizeof (struct jffs2_raw_summary)));
+
+                                                                                         // write out new node header
+                                                                                         write(fd, &newnode, sizeof (struct jffs2_raw_summary));
+                                                                                         // write out new summary data
+                                                                                         write(fd, &node->s.sum, sum_len + sizeof (struct jffs2_sum_marker));
+
+                                                                                         break;
+                                                                                 }
+
+                       case 0xffff:
+                                                                                 write (fd, p, 4);
+                                                                                 p += 4;
+                                                                                 break;
+
+                       default:
+                                                                                 printf ("Unknown node type: 0x%04x at 0x%08x, totlen 0x%08x\n", je16_to_cpu (node->u.nodetype), p - data, je32_to_cpu (node->u.totlen));
+                                                                                 p += PAD(je32_to_cpu (node->u.totlen));
 
                }
        }
@@ -647,7 +647,7 @@ int main(int argc, char **argv)
        }
 
        // get image length
-       imglen = lseek(fd, 0, SEEK_END);
+       imglen = lseek(fd, 0, SEEK_END);
        lseek (fd, 0, SEEK_SET);
 
        data = malloc (imglen);
index fdbf58101c001bfba3858906c86defcb62c99646..49cef6b306dd833ebfa9d4e4a29705fd74b9f0af 100644 (file)
  *  -Erik, 13 September 2001
  *
  * $Id: jffs2reader.c,v 1.6 2005/11/07 11:15:12 gleixner Exp $
-*/
+ */
 
 
 /*
-  TODO:
+TODO:
 
-  - Add CRC checking code to places marked with XXX.
-  - Add support for other node compression types.
+- Add CRC checking code to places marked with XXX.
+- Add support for other node compression types.
 
-  - Test with real life images.
-  - Maybe port into bootloader.
-*/
+- Test with real life images.
+- Maybe port into bootloader.
+ */
 
 /*
-  BUGS:
+BUGS:
 
-  - Doesn't check CRC checksums.
-*/
+- Doesn't check CRC checksums.
+ */
 
 
 #include <errno.h>
@@ -104,19 +104,19 @@ struct dir {
 void putblock(char *, size_t, size_t *, struct jffs2_raw_inode *);
 struct dir *putdir(struct dir *, struct jffs2_raw_dirent *);
 void printdir(char *o, size_t size, struct dir *d, char *path,
-                         int recurse);
+               int recurse);
 void freedir(struct dir *);
 
 struct jffs2_raw_inode *find_raw_inode(char *o, size_t size, uint32_t ino);
 struct jffs2_raw_dirent *resolvedirent(char *, size_t, uint32_t, uint32_t,
-                                                                          char *, uint8_t);
+               char *, uint8_t);
 struct jffs2_raw_dirent *resolvename(char *, size_t, uint32_t, char *, uint8_t);
 struct jffs2_raw_dirent *resolveinode(char *, size_t, uint32_t);
 
 struct jffs2_raw_dirent *resolvepath0(char *, size_t, uint32_t, char *,
-                                                                         uint32_t *, int);
+               uint32_t *, int);
 struct jffs2_raw_dirent *resolvepath(char *, size_t, uint32_t, char *,
-                                                                        uint32_t *);
+               uint32_t *);
 
 void lsdir(char *, size_t, char *, int);
 void catfile(char *, size_t, char *, char *, size_t, size_t *);
@@ -127,14 +127,14 @@ int main(int, char **);
 /* reading all valid nodes in version order reconstructs the file. */
 
 /*
-  b       - buffer
-  bsize   - buffer size
-  rsize   - result size
-  n       - node
-*/
+   b       - buffer
+   bsize   - buffer size
+   rsize   - result size
+   n       - node
+ */
 
 void putblock(char *b, size_t bsize, size_t * rsize,
-                         struct jffs2_raw_inode *n)
+               struct jffs2_raw_inode *n)
 {
        uLongf dlen = n->dsize;
 
@@ -147,26 +147,26 @@ void putblock(char *b, size_t bsize, size_t * rsize,
                bzero(b + *rsize, n->isize - *rsize);
 
        switch (n->compr) {
-       case JFFS2_COMPR_ZLIB:
-               uncompress((Bytef *) b + n->offset, &dlen,
-                                  (Bytef *) ((char *) n) + sizeof(struct jffs2_raw_inode),
-                                  (uLongf) n->csize);
-               break;
+               case JFFS2_COMPR_ZLIB:
+                       uncompress((Bytef *) b + n->offset, &dlen,
+                                       (Bytef *) ((char *) n) + sizeof(struct jffs2_raw_inode),
+                                       (uLongf) n->csize);
+                       break;
 
-       case JFFS2_COMPR_NONE:
-               memcpy(b + n->offset,
-                          ((char *) n) + sizeof(struct jffs2_raw_inode), dlen);
-               break;
+               case JFFS2_COMPR_NONE:
+                       memcpy(b + n->offset,
+                                       ((char *) n) + sizeof(struct jffs2_raw_inode), dlen);
+                       break;
 
-       case JFFS2_COMPR_ZERO:
-               bzero(b + n->offset, dlen);
-               break;
+               case JFFS2_COMPR_ZERO:
+                       bzero(b + n->offset, dlen);
+                       break;
 
-               /* [DYN]RUBIN support required! */
+                       /* [DYN]RUBIN support required! */
 
-       default:
-               fprintf(stderr, "Unsupported compression method!\n");
-               exit(EXIT_FAILURE);
+               default:
+                       fprintf(stderr, "Unsupported compression method!\n");
+                       exit(EXIT_FAILURE);
        }
 
        *rsize = n->isize;
@@ -176,11 +176,11 @@ void putblock(char *b, size_t bsize, size_t * rsize,
 /* reading all valid nodes in version order reconstructs the directory. */
 
 /*
-  dd      - directory struct being processed
-  n       - node
+   dd      - directory struct being processed
+   n       - node
 
-  return value: directory struct value replacing dd
-*/
+   return value: directory struct value replacing dd
+ */
 
 struct dir *putdir(struct dir *dd, struct jffs2_raw_dirent *n)
 {
@@ -202,7 +202,7 @@ struct dir *putdir(struct dir *dd, struct jffs2_raw_dirent *n)
 
                while (1) {
                        if (n->nsize == dd->nsize &&
-                               !memcmp(n->name, dd->name, n->nsize)) {
+                                       !memcmp(n->name, dd->name, n->nsize)) {
                                dd->type = n->type;
                                dd->ino = n->ino;
 
@@ -240,7 +240,7 @@ struct dir *putdir(struct dir *dd, struct jffs2_raw_dirent *n)
                                return o;
 
                        if (n->nsize == dd->nsize &&
-                               !memcmp(n->name, dd->name, n->nsize)) {
+                                       !memcmp(n->name, dd->name, n->nsize)) {
                                p->next = dd->next;
                                free(dd);
 
@@ -296,8 +296,8 @@ const char *mode_string(int mode)
 /* prints contents of directory structure */
 
 /*
-  d       - dir struct
-*/
+   d       - dir struct
+ */
 
 void printdir(char *o, size_t size, struct dir *d, char *path, int recurse)
 {
@@ -313,36 +313,36 @@ void printdir(char *o, size_t size, struct dir *d, char *path, int recurse)
 
        while (d != NULL) {
                switch (d->type) {
-               case DT_REG:
-                       m = ' ';
-                       break;
+                       case DT_REG:
+                               m = ' ';
+                               break;
 
-               case DT_FIFO:
-                       m = '|';
-                       break;
+                       case DT_FIFO:
+                               m = '|';
+                               break;
 
-               case DT_CHR:
-                       m = ' ';
-                       break;
+                       case DT_CHR:
+                               m = ' ';
+                               break;
 
-               case DT_BLK:
-                       m = ' ';
-                       break;
+                       case DT_BLK:
+                               m = ' ';
+                               break;
 
-               case DT_DIR:
-                       m = '/';
-                       break;
+                       case DT_DIR:
+                               m = '/';
+                               break;
 
-               case DT_LNK:
-                       m = ' ';
-                       break;
+                       case DT_LNK:
+                               m = ' ';
+                               break;
 
-               case DT_SOCK:
-                       m = '=';
-                       break;
+                       case DT_SOCK:
+                               m = '=';
+                               break;
 
-               default:
-                       m = '?';
+                       default:
+                               m = '?';
                }
                ri = find_raw_inode(o, size, d->ino);
                if (!ri) {
@@ -354,7 +354,7 @@ void printdir(char *o, size_t size, struct dir *d, char *path, int recurse)
                filetime = ctime((const time_t *) &(ri->ctime));
                age = time(NULL) - ri->ctime;
                printf("%s %-4d %-8d %-8d ", mode_string(ri->mode),
-                          1, ri->uid, ri->gid);
+                               1, ri->uid, ri->gid);
                if ( d->type==DT_BLK || d->type==DT_CHR ) {
                        dev_t rdev;
                        size_t devsize;
@@ -398,8 +398,8 @@ void printdir(char *o, size_t size, struct dir *d, char *path, int recurse)
 /* frees memory used by directory structure */
 
 /*
-  d       - dir struct
-*/
+   d       - dir struct
+ */
 
 void freedir(struct dir *d)
 {
@@ -415,16 +415,16 @@ void freedir(struct dir *d)
 /* collects directory/file nodes in version order. */
 
 /*
-  f       - file flag.
-            if zero, collect file, compare ino to inode
-            otherwise, collect directory, compare ino to parent inode
-  o       - filesystem image pointer
-  size    - size of filesystem image
-  ino     - inode to compare against. see f.
-
-  return value: a jffs2_raw_inode that corresponds the the specified
-    inode, or NULL
-*/
+   f       - file flag.
+   if zero, collect file, compare ino to inode
+   otherwise, collect directory, compare ino to parent inode
+   o       - filesystem image pointer
+   size    - size of filesystem image
+   ino     - inode to compare against. see f.
+
+   return value: a jffs2_raw_inode that corresponds the the specified
+   inode, or NULL
+ */
 
 struct jffs2_raw_inode *find_raw_inode(char *o, size_t size, uint32_t ino)
 {
@@ -452,7 +452,7 @@ struct jffs2_raw_inode *find_raw_inode(char *o, size_t size, uint32_t ino)
 
                if (n < e && n->u.magic == JFFS2_MAGIC_BITMASK) {
                        if (n->u.nodetype == JFFS2_NODETYPE_INODE &&
-                               n->i.ino == ino && (v = n->i.version) > vcur) {
+                                       n->i.ino == ino && (v = n->i.version) > vcur) {
                                /* XXX crc check */
 
                                if (vmaxt < v)
@@ -486,13 +486,13 @@ struct jffs2_raw_inode *find_raw_inode(char *o, size_t size, uint32_t ino)
 /* collects dir struct for selected inode */
 
 /*
-  o       - filesystem image pointer
-  size    - size of filesystem image
-  pino    - inode of the specified directory
-  d       - input directory structure
+   o       - filesystem image pointer
+   size    - size of filesystem image
+   pino    - inode of the specified directory
+   d       - input directory structure
 
-  return value: result directory structure, replaces d.
-*/
+   return value: result directory structure, replaces d.
+ */
 
 struct dir *collectdir(char *o, size_t size, uint32_t ino, struct dir *d)
 {
@@ -553,7 +553,7 @@ struct dir *collectdir(char *o, size_t size, uint32_t ino, struct dir *d)
 
                                lr = n =
                                        (union jffs2_node_union *) (((char *) mp) +
-                                                                                               ((mp->u.totlen + 3) & ~3));
+                                                       ((mp->u.totlen + 3) & ~3));
 
                                vcur = vmin;
                        }
@@ -568,23 +568,23 @@ struct dir *collectdir(char *o, size_t size, uint32_t ino, struct dir *d)
 /* resolve dirent based on criteria */
 
 /*
-  o       - filesystem image pointer
-  size    - size of filesystem image
-  ino     - if zero, ignore,
-            otherwise compare against dirent inode
-  pino    - if zero, ingore,
-            otherwise compare against parent inode
-            and use name and nsize as extra criteria
-  name    - name of wanted dirent, used if pino!=0
-  nsize   - length of name of wanted dirent, used if pino!=0
-
-  return value: pointer to relevant dirent structure in
-                filesystem image or NULL
-*/
+   o       - filesystem image pointer
+   size    - size of filesystem image
+   ino     - if zero, ignore,
+   otherwise compare against dirent inode
+   pino    - if zero, ingore,
+   otherwise compare against parent inode
+   and use name and nsize as extra criteria
+   name    - name of wanted dirent, used if pino!=0
+   nsize   - length of name of wanted dirent, used if pino!=0
+
+   return value: pointer to relevant dirent structure in
+   filesystem image or NULL
+ */
 
 struct jffs2_raw_dirent *resolvedirent(char *o, size_t size,
-                                                                          uint32_t ino, uint32_t pino,
-                                                                          char *name, uint8_t nsize)
+               uint32_t ino, uint32_t pino,
+               char *name, uint8_t nsize)
 {
        /* aligned! */
        union jffs2_node_union *n;
@@ -607,11 +607,11 @@ struct jffs2_raw_dirent *resolvedirent(char *o, size_t size,
 
                if (n < e && n->u.magic == JFFS2_MAGIC_BITMASK) {
                        if (n->u.nodetype == JFFS2_NODETYPE_DIRENT &&
-                               (!ino || n->d.ino == ino) &&
-                               (v = n->d.version) > vmax &&
-                               (!pino || (n->d.pino == pino &&
-                                                  nsize == n->d.nsize &&
-                                                  !memcmp(name, n->d.name, nsize)))) {
+                                       (!ino || n->d.ino == ino) &&
+                                       (v = n->d.version) > vmax &&
+                                       (!pino || (n->d.pino == pino &&
+                                                          nsize == n->d.nsize &&
+                                                          !memcmp(name, n->d.name, nsize)))) {
                                /* XXX crc check */
 
                                if (vmax < v) {
@@ -629,18 +629,18 @@ struct jffs2_raw_dirent *resolvedirent(char *o, size_t size,
 /* resolve name under certain parent inode to dirent */
 
 /*
-  o       - filesystem image pointer
-  size    - size of filesystem image
-  pino    - requested parent inode
-  name    - name of wanted dirent
-  nsize   - length of name of wanted dirent
-
-  return value: pointer to relevant dirent structure in
-                filesystem image or NULL
-*/
+   o       - filesystem image pointer
+   size    - size of filesystem image
+   pino    - requested parent inode
+   name    - name of wanted dirent
+   nsize   - length of name of wanted dirent
+
+   return value: pointer to relevant dirent structure in
+   filesystem image or NULL
+ */
 
 struct jffs2_raw_dirent *resolvename(char *o, size_t size, uint32_t pino,
-                                                                        char *name, uint8_t nsize)
+               char *name, uint8_t nsize)
 {
        return resolvedirent(o, size, 0, pino, name, nsize);
 }
@@ -648,13 +648,13 @@ struct jffs2_raw_dirent *resolvename(char *o, size_t size, uint32_t pino,
 /* resolve inode to dirent */
 
 /*
-  o       - filesystem image pointer
-  size    - size of filesystem image
-  ino     - compare against dirent inode
+   o       - filesystem image pointer
+   size    - size of filesystem image
+   ino     - compare against dirent inode
 
-  return value: pointer to relevant dirent structure in
-                filesystem image or NULL
-*/
+   return value: pointer to relevant dirent structure in
+   filesystem image or NULL
+ */
 
 struct jffs2_raw_dirent *resolveinode(char *o, size_t size, uint32_t ino)
 {
@@ -664,23 +664,23 @@ struct jffs2_raw_dirent *resolveinode(char *o, size_t size, uint32_t ino)
 /* resolve slash-style path into dirent and inode.
    slash as first byte marks absolute path (root=inode 1).
    . and .. are resolved properly, and symlinks are followed.
-*/
+ */
 
 /*
-  o       - filesystem image pointer
-  size    - size of filesystem image
-  ino     - root inode, used if path is relative
-  p       - path to be resolved
-  inos    - result inode, zero if failure
-  recc    - recursion count, to detect symlink loops
-
-  return value: pointer to dirent struct in file system image.
-                note that root directory doesn't have dirent struct
-                (return value is NULL), but it has inode (*inos=1)
-*/
+   o       - filesystem image pointer
+   size    - size of filesystem image
+   ino     - root inode, used if path is relative
+   p       - path to be resolved
+   inos    - result inode, zero if failure
+   recc    - recursion count, to detect symlink loops
+
+   return value: pointer to dirent struct in file system image.
+   note that root directory doesn't have dirent struct
+   (return value is NULL), but it has inode (*inos=1)
+ */
 
 struct jffs2_raw_dirent *resolvepath0(char *o, size_t size, uint32_t ino,
-                                                                         char *p, uint32_t * inos, int recc)
+               char *p, uint32_t * inos, int recc)
 {
        struct jffs2_raw_dirent *dir = NULL;
 
@@ -739,8 +739,8 @@ struct jffs2_raw_dirent *resolvepath0(char *o, size_t size, uint32_t ino,
                dir = resolvename(o, size, ino, path, (uint8_t) strlen(path));
 
                if (DIRENT_INO(dir) == 0 ||
-                       (next != NULL &&
-                        !(dir->type == DT_DIR || dir->type == DT_LNK))) {
+                               (next != NULL &&
+                                !(dir->type == DT_DIR || dir->type == DT_LNK))) {
                        free(pp);
 
                        *inos = 0;
@@ -760,7 +760,7 @@ struct jffs2_raw_dirent *resolvepath0(char *o, size_t size, uint32_t ino,
                        dir = resolvepath0(o, size, tino, symbuf, &ino, ++recc);
 
                        if (dir != NULL && next != NULL &&
-                               !(dir->type == DT_DIR || dir->type == DT_LNK)) {
+                                       !(dir->type == DT_DIR || dir->type == DT_LNK)) {
                                free(pp);
 
                                *inos = 0;
@@ -781,22 +781,22 @@ struct jffs2_raw_dirent *resolvepath0(char *o, size_t size, uint32_t ino,
 /* resolve slash-style path into dirent and inode.
    slash as first byte marks absolute path (root=inode 1).
    . and .. are resolved properly, and symlinks are followed.
-*/
+ */
 
 /*
-  o       - filesystem image pointer
-  size    - size of filesystem image
-  ino     - root inode, used if path is relative
-  p       - path to be resolved
-  inos    - result inode, zero if failure
-
-  return value: pointer to dirent struct in file system image.
-                note that root directory doesn't have dirent struct
-                (return value is NULL), but it has inode (*inos=1)
-*/
+   o       - filesystem image pointer
+   size    - size of filesystem image
+   ino     - root inode, used if path is relative
+   p       - path to be resolved
+   inos    - result inode, zero if failure
+
+   return value: pointer to dirent struct in file system image.
+   note that root directory doesn't have dirent struct
+   (return value is NULL), but it has inode (*inos=1)
+ */
 
 struct jffs2_raw_dirent *resolvepath(char *o, size_t size, uint32_t ino,
-                                                                        char *p, uint32_t * inos)
+               char *p, uint32_t * inos)
 {
        return resolvepath0(o, size, ino, p, inos, 0);
 }
@@ -804,10 +804,10 @@ struct jffs2_raw_dirent *resolvepath(char *o, size_t size, uint32_t ino,
 /* lists files on directory specified by path */
 
 /*
-  o       - filesystem image pointer
-  size    - size of filesystem image
-  p       - path to be resolved
-*/
+   o       - filesystem image pointer
+   size    - size of filesystem image
+   p       - path to be resolved
+ */
 
 void lsdir(char *o, size_t size, char *path, int recurse)
 {
@@ -819,7 +819,7 @@ void lsdir(char *o, size_t size, char *path, int recurse)
        dd = resolvepath(o, size, 1, path, &ino);
 
        if (ino == 0 ||
-               (dd == NULL && ino == 0) || (dd != NULL && dd->type != DT_DIR)) {
+                       (dd == NULL && ino == 0) || (dd != NULL && dd->type != DT_DIR)) {
                fprintf(stderr, "jffs2reader: %s: No such file or directory\n",
                                path);
                exit(EXIT_FAILURE);
@@ -833,16 +833,16 @@ void lsdir(char *o, size_t size, char *path, int recurse)
 /* writes file specified by path to the buffer */
 
 /*
-  o       - filesystem image pointer
-  size    - size of filesystem image
-  p       - path to be resolved
-  b       - file buffer
-  bsize   - file buffer size
-  rsize   - file result size
-*/
+   o       - filesystem image pointer
+   size    - size of filesystem image
+   p       - path to be resolved
+   b       - file buffer
+   bsize   - file buffer size
+   rsize   - file result size
+ */
 
 void catfile(char *o, size_t size, char *path, char *b, size_t bsize,
-                        size_t * rsize)
+               size_t * rsize)
 {
        struct jffs2_raw_dirent *dd;
        struct jffs2_raw_inode *ri;
@@ -880,19 +880,19 @@ int main(int argc, char **argv)
 
        while ((opt = getopt(argc, argv, "rd:f:")) > 0) {
                switch (opt) {
-               case 'd':
-                       dir = optarg;
-                       break;
-               case 'f':
-                       file = optarg;
-                       break;
-               case 'r':
-                       recurse++;
-                       break;
-               default:
-                       fprintf(stderr,
-                                       "Usage: jffs2reader <image> [-d|-f] < path > \n");
-                       exit(EXIT_FAILURE);
+                       case 'd':
+                               dir = optarg;
+                               break;
+                       case 'f':
+                               file = optarg;
+                               break;
+                       case 'r':
+                               recurse++;
+                               break;
+                       default:
+                               fprintf(stderr,
+                                               "Usage: jffs2reader <image> [-d|-f] < path > \n");
+                               exit(EXIT_FAILURE);
                }
        }
 
index 69266ed568045d098fcfec49a482355a67a8e9ab..1f4595ecfaa647bfe1194b2452f7f4357853a70a 100644 (file)
@@ -33,42 +33,42 @@ static int MAX_CHUNK_SIZE = 32768;
 /* How many padding bytes should be inserted between two chunks of data
    on the flash?  */
 #define JFFS_GET_PAD_BYTES(size) ((JFFS_ALIGN_SIZE                     \
-                                 - ((uint32_t)(size) % JFFS_ALIGN_SIZE)) \
-                                 % JFFS_ALIGN_SIZE)
+                       - ((uint32_t)(size) % JFFS_ALIGN_SIZE)) \
+               % JFFS_ALIGN_SIZE)
 
 
 struct jffs_raw_inode
 {
-  uint32_t magic;    /* A constant magic number.  */
-  uint32_t ino;      /* Inode number.  */
-  uint32_t pino;     /* Parent's inode number.  */
-  uint32_t version;  /* Version number.  */
-  uint32_t mode;     /* file_type, mode  */
-  uint16_t uid;
-  uint16_t gid;
-  uint32_t atime;
-  uint32_t mtime;
-  uint32_t ctime;
-  uint32_t offset;     /* Where to begin to write.  */
-  uint32_t dsize;      /* Size of the file data.  */
-  uint32_t rsize;      /* How much are going to be replaced?  */
-  uint8_t nsize;       /* Name length.  */
-  uint8_t nlink;       /* Number of links.  */
-  uint8_t spare : 6;   /* For future use.  */
-  uint8_t rename : 1;  /* Is this a special rename?  */
-  uint8_t deleted : 1; /* Has this file been deleted?  */
-  uint8_t accurate;    /* The inode is obsolete if accurate == 0.  */
-  uint32_t dchksum;    /* Checksum for the data.  */
-  uint16_t nchksum;    /* Checksum for the name.  */
-  uint16_t chksum;     /* Checksum for the raw_inode.  */
+       uint32_t magic;    /* A constant magic number.  */
+       uint32_t ino;      /* Inode number.  */
+       uint32_t pino;     /* Parent's inode number.  */
+       uint32_t version;  /* Version number.  */
+       uint32_t mode;     /* file_type, mode  */
+       uint16_t uid;
+       uint16_t gid;
+       uint32_t atime;
+       uint32_t mtime;
+       uint32_t ctime;
+       uint32_t offset;     /* Where to begin to write.  */
+       uint32_t dsize;      /* Size of the file data.  */
+       uint32_t rsize;      /* How much are going to be replaced?  */
+       uint8_t nsize;       /* Name length.  */
+       uint8_t nlink;       /* Number of links.  */
+       uint8_t spare : 6;   /* For future use.  */
+       uint8_t rename : 1;  /* Is this a special rename?  */
+       uint8_t deleted : 1; /* Has this file been deleted?  */
+       uint8_t accurate;    /* The inode is obsolete if accurate == 0.  */
+       uint32_t dchksum;    /* Checksum for the data.  */
+       uint16_t nchksum;    /* Checksum for the name.  */
+       uint16_t chksum;     /* Checksum for the raw_inode.  */
 };
 
 
 struct jffs_file
 {
-  struct jffs_raw_inode inode;
-  char *name;
-  unsigned char *data;
+       struct jffs_raw_inode inode;
+       char *name;
+       unsigned char *data;
 };
 
 
@@ -84,68 +84,68 @@ int endian = ENDIAN_HOST;
 static uint32_t jffs_checksum(void *data, int size);
 void jffs_print_trace(const char *path, int depth);
 int make_root_dir(FILE *fs, int first_ino, const char *root_dir_path,
-                 int depth);
+               int depth);
 void write_file(struct jffs_file *f, FILE *fs, struct stat st);
 void read_data(struct jffs_file *f, const char *path, int offset);
 int mkfs(FILE *fs, const char *path, int ino, int parent, int depth);
 
 
-static uint32_t
+       static uint32_t
 jffs_checksum(void *data, int size)
 {
-  uint32_t sum = 0;
-  uint8_t *ptr = (uint8_t *)data;
+       uint32_t sum = 0;
+       uint8_t *ptr = (uint8_t *)data;
 
-  while (size-- > 0)
-  {
-    sum += *ptr++;
-  }
+       while (size-- > 0)
+       {
+               sum += *ptr++;
+       }
 
-  return sum;
+       return sum;
 }
 
 
-void
+       void
 jffs_print_trace(const char *path, int depth)
 {
-  int path_len = strlen(path);
-  int out_pos = depth * JFFS_TRACE_INDENT;
-  int pos = path_len - 1;
-  char *out = (char *)alloca(depth * JFFS_TRACE_INDENT + path_len + 1);
-
-  if (verbose >= 2)
-  {
-    fprintf(stderr, "jffs_print_trace(): path: \"%s\"\n", path);
-  }
-
-  if (!out) {
-    fprintf(stderr, "jffs_print_trace(): Allocation failed.\n");
-    fprintf(stderr, " path: \"%s\"\n", path);
-    fprintf(stderr, "depth: %d\n", depth);
-    exit(1);
-  }
-
-  memset(out, ' ', depth * JFFS_TRACE_INDENT);
-
-  if (path[pos] == '/')
-  {
-    pos--;
-  }
-  while (path[pos] && (path[pos] != '/'))
-  {
-    pos--;
-  }
-  for (pos++; path[pos] && (path[pos] != '/'); pos++)
-  {
-    out[out_pos++] = path[pos];
-  }
-  out[out_pos] = '\0';
-  fprintf(stderr, "%s\n", out);
+       int path_len = strlen(path);
+       int out_pos = depth * JFFS_TRACE_INDENT;
+       int pos = path_len - 1;
+       char *out = (char *)alloca(depth * JFFS_TRACE_INDENT + path_len + 1);
+
+       if (verbose >= 2)
+       {
+               fprintf(stderr, "jffs_print_trace(): path: \"%s\"\n", path);
+       }
+
+       if (!out) {
+               fprintf(stderr, "jffs_print_trace(): Allocation failed.\n");
+               fprintf(stderr, " path: \"%s\"\n", path);
+               fprintf(stderr, "depth: %d\n", depth);
+               exit(1);
+       }
+
+       memset(out, ' ', depth * JFFS_TRACE_INDENT);
+
+       if (path[pos] == '/')
+       {
+               pos--;
+       }
+       while (path[pos] && (path[pos] != '/'))
+       {
+               pos--;
+       }
+       for (pos++; path[pos] && (path[pos] != '/'); pos++)
+       {
+               out[out_pos++] = path[pos];
+       }
+       out[out_pos] = '\0';
+       fprintf(stderr, "%s\n", out);
 }
 
 
 /* Print the contents of a raw inode.  */
-void
+       void
 jffs_print_raw_inode(struct jffs_raw_inode *raw_inode)
 {
        fprintf(stderr, "jffs_raw_inode: inode number: %u\n", raw_inode->ino);
@@ -166,13 +166,13 @@ jffs_print_raw_inode(struct jffs_raw_inode *raw_inode)
        fprintf(stderr, "        0x%02x,       /* nsize  */\n", raw_inode->nsize);
        fprintf(stderr, "        0x%02x,       /* nlink  */\n", raw_inode->nlink);
        fprintf(stderr, "        0x%02x,       /* spare  */\n",
-                raw_inode->spare);
+                       raw_inode->spare);
        fprintf(stderr, "        %u,          /* rename  */\n",
-                raw_inode->rename);
+                       raw_inode->rename);
        fprintf(stderr, "        %u,          /* deleted  */\n",
-                raw_inode->deleted);
+                       raw_inode->deleted);
        fprintf(stderr, "        0x%02x,       /* accurate  */\n",
-                raw_inode->accurate);
+                       raw_inode->accurate);
        fprintf(stderr, "        0x%08x, /* dchksum  */\n", raw_inode->dchksum);
        fprintf(stderr, "        0x%04x,     /* nchksum  */\n", raw_inode->nchksum);
        fprintf(stderr, "        0x%04x,     /* chksum  */\n", raw_inode->chksum);
@@ -181,536 +181,536 @@ jffs_print_raw_inode(struct jffs_raw_inode *raw_inode)
 
 static void write_val32(uint32_t *adr, uint32_t val)
 {
-  switch(endian) {
-  case ENDIAN_HOST:
-    *adr = val;
-    break;
-  case ENDIAN_LITTLE:
-    *adr = cpu_to_le32(val);
-    break;
-  case ENDIAN_BIG:
-    *adr = cpu_to_be32(val);
-    break;
-  }
+       switch(endian) {
+               case ENDIAN_HOST:
+                       *adr = val;
+                       break;
+               case ENDIAN_LITTLE:
+                       *adr = cpu_to_le32(val);
+                       break;
+               case ENDIAN_BIG:
+                       *adr = cpu_to_be32(val);
+                       break;
+       }
 }
 
 static void write_val16(uint16_t *adr, uint16_t val)
 {
-  switch(endian) {
-  case ENDIAN_HOST:
-    *adr = val;
-    break;
-  case ENDIAN_LITTLE:
-    *adr = cpu_to_le16(val);
-    break;
-  case ENDIAN_BIG:
-    *adr = cpu_to_be16(val);
-    break;
-  }
+       switch(endian) {
+               case ENDIAN_HOST:
+                       *adr = val;
+                       break;
+               case ENDIAN_LITTLE:
+                       *adr = cpu_to_le16(val);
+                       break;
+               case ENDIAN_BIG:
+                       *adr = cpu_to_be16(val);
+                       break;
+       }
 }
 
 static uint32_t read_val32(uint32_t *adr)
 {
-  uint32_t val = 0;
-
-  switch(endian) {
-  case ENDIAN_HOST:
-    val = *adr;
-    break;
-  case ENDIAN_LITTLE:
-    val = le32_to_cpu(*adr);
-    break;
-  case ENDIAN_BIG:
-    val = be32_to_cpu(*adr);
-    break;
-  }
-  return val;
+       uint32_t val = 0;
+
+       switch(endian) {
+               case ENDIAN_HOST:
+                       val = *adr;
+                       break;
+               case ENDIAN_LITTLE:
+                       val = le32_to_cpu(*adr);
+                       break;
+               case ENDIAN_BIG:
+                       val = be32_to_cpu(*adr);
+                       break;
+       }
+       return val;
 }
 
 
 /* This function constructs a root inode with no name and
    no data.  The inode is then written to the filesystem
    image.  */
-int
+       int
 make_root_dir(FILE *fs, int first_ino, const char *root_dir_path, int depth)
 {
-  struct jffs_file f;
-  struct stat st;
-
-  if (stat(root_dir_path, &st) < 0)
-  {
-    perror("stat");
-    exit(1);
-  }
-
-  write_val32(&f.inode.magic, JFFS_MAGIC);
-  write_val32(&f.inode.ino, first_ino);
-  write_val32(&f.inode.pino, 0);
-  write_val32(&f.inode.version, 1);
-  write_val32(&f.inode.mode, st.st_mode);
-  write_val16(&f.inode.uid, 0); /* root */
-  write_val16(&f.inode.gid, 0); /* root */
-  write_val32(&f.inode.atime, st.st_atime);
-  write_val32(&f.inode.mtime, st.st_mtime);
-  write_val32(&f.inode.ctime, st.st_ctime);
-  write_val32(&f.inode.offset, 0);
-  write_val32(&f.inode.dsize, 0);
-  write_val32(&f.inode.rsize,0);
-  f.inode.nsize = 0;
-  /*f.inode.nlink = st.st_nlink;*/
-  f.inode.nlink = 1;
-  f.inode.spare = 0;
-  f.inode.rename = 0;
-  f.inode.deleted = 0;
-  f.inode.accurate = 0;
-  write_val32(&f.inode.dchksum, 0);
-  write_val16(&f.inode.nchksum, 0);
-  write_val16(&f.inode.chksum, 0);
-  f.name = 0;
-  f.data = 0;
-  write_val16(&f.inode.chksum, jffs_checksum(&f.inode, sizeof(struct jffs_raw_inode)));
-  f.inode.accurate = 0xff;
-  write_file(&f, fs, st);
-  if (verbose >= 1)
-  {
-    jffs_print_trace(root_dir_path, depth);
-  }
-  if (verbose >= 2)
-  {
-    jffs_print_raw_inode(&f.inode);
-  }
-  return first_ino;
+       struct jffs_file f;
+       struct stat st;
+
+       if (stat(root_dir_path, &st) < 0)
+       {
+               perror("stat");
+               exit(1);
+       }
+
+       write_val32(&f.inode.magic, JFFS_MAGIC);
+       write_val32(&f.inode.ino, first_ino);
+       write_val32(&f.inode.pino, 0);
+       write_val32(&f.inode.version, 1);
+       write_val32(&f.inode.mode, st.st_mode);
+       write_val16(&f.inode.uid, 0); /* root */
+       write_val16(&f.inode.gid, 0); /* root */
+       write_val32(&f.inode.atime, st.st_atime);
+       write_val32(&f.inode.mtime, st.st_mtime);
+       write_val32(&f.inode.ctime, st.st_ctime);
+       write_val32(&f.inode.offset, 0);
+       write_val32(&f.inode.dsize, 0);
+       write_val32(&f.inode.rsize,0);
+       f.inode.nsize = 0;
+       /*f.inode.nlink = st.st_nlink;*/
+       f.inode.nlink = 1;
+       f.inode.spare = 0;
+       f.inode.rename = 0;
+       f.inode.deleted = 0;
+       f.inode.accurate = 0;
+       write_val32(&f.inode.dchksum, 0);
+       write_val16(&f.inode.nchksum, 0);
+       write_val16(&f.inode.chksum, 0);
+       f.name = 0;
+       f.data = 0;
+       write_val16(&f.inode.chksum, jffs_checksum(&f.inode, sizeof(struct jffs_raw_inode)));
+       f.inode.accurate = 0xff;
+       write_file(&f, fs, st);
+       if (verbose >= 1)
+       {
+               jffs_print_trace(root_dir_path, depth);
+       }
+       if (verbose >= 2)
+       {
+               jffs_print_raw_inode(&f.inode);
+       }
+       return first_ino;
 }
 
 
 /* This function writes a chunks of data.  A data chunk consists of a
    raw inode, perhaps a name and perhaps some data.  */
-void
+       void
 write_file(struct jffs_file *f, FILE *fs, struct stat st)
 {
-  int npad = JFFS_GET_PAD_BYTES(f->inode.nsize);
-  int dpad = JFFS_GET_PAD_BYTES(read_val32(&f->inode.dsize));
-  int size = sizeof(struct jffs_raw_inode) + f->inode.nsize + npad
-             + read_val32(&f->inode.dsize) + dpad;
-  unsigned char ff_data[] = { 0xff, 0xff, 0xff, 0xff };
-
-  if (verbose >= 2)
-  {
-    fprintf(stderr, "***write_file()\n");
-  }
-
-  /* Write the raw inode.  */
-  fwrite((void *)&f->inode, sizeof(struct jffs_raw_inode), 1, fs);
-
-  /* Write the name.  */
-  if (f->inode.nsize)
-  {
-    fwrite(f->name, 1, f->inode.nsize, fs);
-    if (npad)
-    {
-      fwrite(ff_data, 1, npad, fs);
-    }
-  }
-
-  /* Write the data.  */
-  if (read_val32(&f->inode.dsize))
-  {
-    if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
-    {
-      uint16_t tmp;
-
-      switch(endian) {
-        case ENDIAN_HOST:
-          tmp = st.st_rdev;
-          break;
-        case ENDIAN_LITTLE:
-          tmp = cpu_to_le16(st.st_rdev);
-          break;
-        case ENDIAN_BIG:
-          tmp = cpu_to_be16(st.st_rdev);
-          break;
-      }
-      fwrite((char *)&tmp, sizeof(st.st_rdev) / 4, 1, fs);
-    }
-    else
-    {
-      fwrite(f->data, 1, read_val32(&f->inode.dsize), fs);
-    }
-    if (dpad)
-    {
-      fwrite(ff_data, 1, dpad, fs);
-    }
-  }
-
-  fs_pos += size;
-  /* If the space left on the block is smaller than the size of an
-     inode, then skip it.  */
+       int npad = JFFS_GET_PAD_BYTES(f->inode.nsize);
+       int dpad = JFFS_GET_PAD_BYTES(read_val32(&f->inode.dsize));
+       int size = sizeof(struct jffs_raw_inode) + f->inode.nsize + npad
+               + read_val32(&f->inode.dsize) + dpad;
+       unsigned char ff_data[] = { 0xff, 0xff, 0xff, 0xff };
+
+       if (verbose >= 2)
+       {
+               fprintf(stderr, "***write_file()\n");
+       }
+
+       /* Write the raw inode.  */
+       fwrite((void *)&f->inode, sizeof(struct jffs_raw_inode), 1, fs);
+
+       /* Write the name.  */
+       if (f->inode.nsize)
+       {
+               fwrite(f->name, 1, f->inode.nsize, fs);
+               if (npad)
+               {
+                       fwrite(ff_data, 1, npad, fs);
+               }
+       }
+
+       /* Write the data.  */
+       if (read_val32(&f->inode.dsize))
+       {
+               if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
+               {
+                       uint16_t tmp;
+
+                       switch(endian) {
+                               case ENDIAN_HOST:
+                                       tmp = st.st_rdev;
+                                       break;
+                               case ENDIAN_LITTLE:
+                                       tmp = cpu_to_le16(st.st_rdev);
+                                       break;
+                               case ENDIAN_BIG:
+                                       tmp = cpu_to_be16(st.st_rdev);
+                                       break;
+                       }
+                       fwrite((char *)&tmp, sizeof(st.st_rdev) / 4, 1, fs);
+               }
+               else
+               {
+                       fwrite(f->data, 1, read_val32(&f->inode.dsize), fs);
+               }
+               if (dpad)
+               {
+                       fwrite(ff_data, 1, dpad, fs);
+               }
+       }
+
+       fs_pos += size;
+       /* If the space left on the block is smaller than the size of an
+          inode, then skip it.  */
 }
 
 
-void
+       void
 read_data(struct jffs_file *f, const char *path, int offset)
 {
-  FILE *file;
-  char *tot_path;
-  int pos = 0;
-  int r;
-
-  if (verbose >= 2)
-  {
-    fprintf(stderr, "***read_data(): f: 0x%08x, path: \"%s\", offset: %u\r\n",
-            (unsigned int)f, path, offset);
-    fprintf(stderr, "             file's size: %u\n", read_val32(&f->inode.dsize));
-  }
-
-  if (!(f->data = (unsigned char *)malloc(read_val32(&f->inode.dsize))))
-  {
-    fprintf(stderr, "read_data(): malloc() failed! (*data)\n");
-    exit(1);
-  }
-
-  if (!(tot_path = (char *)alloca(strlen(path) + f->inode.nsize + 1)))
-  {
-    fprintf(stderr, "read_data(): alloca() failed! (tot_path)\n");
-    exit(1);
-  }
-  strcpy(tot_path, path);
-  strncat(tot_path, f->name, f->inode.nsize);
-
-  if (!(file = fopen(tot_path, "r")))
-  {
-    fprintf(stderr, "read_data(): Couldn't open \"%s\".\n", tot_path);
-    exit(1);
-  }
-
-  if (fseek(file, offset, SEEK_SET) < 0)
-  {
-    fprintf(stderr, "read_data(): fseek failure: path = %s, offset = %u.\n",
-            path, offset);
-    exit(1);
-  }
-
-  while (pos < read_val32(&f->inode.dsize))
-  {
-    if ((r = fread(&f->data[pos], 1, read_val32(&f->inode.dsize) - pos, file)) < 0)
-    {
-      fprintf(stderr, "read_data(): fread failure (%s).\n", path);
-      exit(1);
-    }
-    pos += r;
-  }
-
-  fclose(file);
+       FILE *file;
+       char *tot_path;
+       int pos = 0;
+       int r;
+
+       if (verbose >= 2)
+       {
+               fprintf(stderr, "***read_data(): f: 0x%08x, path: \"%s\", offset: %u\r\n",
+                               (unsigned int)f, path, offset);
+               fprintf(stderr, "             file's size: %u\n", read_val32(&f->inode.dsize));
+       }
+
+       if (!(f->data = (unsigned char *)malloc(read_val32(&f->inode.dsize))))
+       {
+               fprintf(stderr, "read_data(): malloc() failed! (*data)\n");
+               exit(1);
+       }
+
+       if (!(tot_path = (char *)alloca(strlen(path) + f->inode.nsize + 1)))
+       {
+               fprintf(stderr, "read_data(): alloca() failed! (tot_path)\n");
+               exit(1);
+       }
+       strcpy(tot_path, path);
+       strncat(tot_path, f->name, f->inode.nsize);
+
+       if (!(file = fopen(tot_path, "r")))
+       {
+               fprintf(stderr, "read_data(): Couldn't open \"%s\".\n", tot_path);
+               exit(1);
+       }
+
+       if (fseek(file, offset, SEEK_SET) < 0)
+       {
+               fprintf(stderr, "read_data(): fseek failure: path = %s, offset = %u.\n",
+                               path, offset);
+               exit(1);
+       }
+
+       while (pos < read_val32(&f->inode.dsize))
+       {
+               if ((r = fread(&f->data[pos], 1, read_val32(&f->inode.dsize) - pos, file)) < 0)
+               {
+                       fprintf(stderr, "read_data(): fread failure (%s).\n", path);
+                       exit(1);
+               }
+               pos += r;
+       }
+
+       fclose(file);
 }
 
 
 /* This is the routine that constructs the filesystem image.  */
-int
+       int
 mkfs(FILE *fs, const char *path, int ino, int parent, int depth)
 {
-  struct dirent *dir_entry;
-  DIR *dir;
-  struct stat st;
-  struct jffs_file f;
-  int name_len;
-  int pos = 0;
-  int new_ino = ino;
-  char *filename;
-  int path_len = strlen(path);
-
-  if (verbose >= 2)
-  {
-    fprintf(stderr, "***mkfs(): path: \"%s\"\r\n", path);
-  }
-
-  if (!(dir = opendir(path)))
-  {
-    perror("opendir");
-    fprintf(stderr, "mkfs(): opendir() failed! (%s)\n", path);
-    exit(1);
-  }
-
-  while ((dir_entry = readdir(dir)))
-  {
-    if (verbose >= 2)
-    {
-     fprintf(stderr, "mkfs(): name: %s\n", dir_entry->d_name);
-    }
-    name_len = strlen(dir_entry->d_name);
-
-    if (((name_len == 1)
-         && (dir_entry->d_name[0] == '.'))
-        || ((name_len == 2)
-            && (dir_entry->d_name[0] == '.')
-            && (dir_entry->d_name[1] == '.')))
-    {
-      continue;
-    }
-
-    if (!(filename = (char *)alloca(path_len + name_len + 1)))
-    {
-      fprintf(stderr, "mkfs(): Allocation failed!\n");
-      exit(0);
-    }
-    strcpy(filename, path);
-    strcat(filename, dir_entry->d_name);
-
-    if (verbose >= 2)
-    {
-      fprintf(stderr, "mkfs(): filename: %s\n", filename);
-    }
-
-    if (lstat(filename, &st) < 0)
-    {
-      perror("lstat");
-      exit(1);
-    }
-
-    if (verbose >= 2)
-    {
-      fprintf(stderr, "mkfs(): filename: \"%s\", ino: %d, parent: %d\n",
-              filename, new_ino, parent);
-    }
-
-    write_val32(&f.inode.magic, JFFS_MAGIC);
-    write_val32(&f.inode.ino, new_ino);
-    write_val32(&f.inode.pino, parent);
-    write_val32(&f.inode.version, 1);
-    write_val32(&f.inode.mode, st.st_mode);
-    write_val16(&f.inode.uid, st.st_uid);
-    write_val16(&f.inode.gid, st.st_gid);
-    write_val32(&f.inode.atime, st.st_atime);
-    write_val32(&f.inode.mtime, st.st_mtime);
-    write_val32(&f.inode.ctime, st.st_ctime);
-    write_val32(&f.inode.dsize, 0);
-    write_val32(&f.inode.rsize, 0);
-    f.inode.nsize = name_len;
-    /*f.inode.nlink = st.st_nlink;*/
-    f.inode.nlink = 1;
-    f.inode.spare = 0;
-    f.inode.rename = 0;
-    f.inode.deleted = 0;
-    f.inode.accurate = 0;
-    write_val32(&f.inode.dchksum, 0);
-    write_val16(&f.inode.nchksum, 0);
-    write_val16(&f.inode.chksum, 0);
-    if (dir_entry->d_name)
-    {
-      f.name = strdup(dir_entry->d_name);
-    }
-    else
-    {
-      f.name = 0;
-    }
-
-  repeat:
-    write_val32(&f.inode.offset, pos);
-    f.data = 0;
-    f.inode.accurate = 0;
-    if (S_ISREG(st.st_mode) && st.st_size)
-    {
-      if (st.st_size - pos < MAX_CHUNK_SIZE)
-      {
-       write_val32(&f.inode.dsize, st.st_size - pos);
-      }
-      else
-      {
-       write_val32(&f.inode.dsize, MAX_CHUNK_SIZE);
-      }
-
-      read_data(&f, path, pos);
-      pos += read_val32(&f.inode.dsize);
-    }
-    else if (S_ISLNK(st.st_mode))
-    {
-      int linklen;
-      char *linkdata = malloc(1000);
-      if (!linkdata)
-      {
-        fprintf(stderr, "mkfs(): malloc() failed! (linkdata)\n");
-        exit(1);
-      }
-      if ((linklen = readlink(filename, linkdata, 1000)) < 0)
-      {
-        free(linkdata);
-        fprintf(stderr, "mkfs(): readlink() failed! f.name = \"%s\"\n",
-                f.name);
-        exit(1);
-      }
-
-      write_val32(&f.inode.dsize, linklen);
-      f.data = (unsigned char *)linkdata;
-      f.data[linklen] = '\0';
-    }
-    else if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
-    {
-      write_val32(&f.inode.dsize, sizeof(st.st_rdev) / 4);
-    }
-
-    write_val16(&f.inode.chksum, 0);
-    if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode))
-    {
-      write_val32(&f.inode.dchksum, jffs_checksum((void *)f.data, read_val32(&f.inode.dsize)));
-    }
-    else
-    {
-      write_val32(&f.inode.dchksum, jffs_checksum((void *)&st.st_rdev, sizeof(st.st_rdev) / 4));
-    }
-
-    write_val16(&f.inode.nchksum, jffs_checksum((void *)f.name, f.inode.nsize));
-    write_val16(&f.inode.chksum, jffs_checksum((void *)&f.inode, sizeof(struct jffs_raw_inode)));
-    f.inode.accurate = 0xff;
-
-    write_file(&f, fs, st);
-    if (S_ISREG(st.st_mode) && st.st_size)
-    {
-      if (pos < st.st_size)
-      {
-       write_val32(&f.inode.version, read_val32(&f.inode.version) + 1);
-       goto repeat;
-      }
-    }
-
-    new_ino++;
-    pos = 0;
-    if (verbose >= 1)
-    {
-      jffs_print_trace(f.name, depth);
-    }
-    if (verbose >= 2)
-    {
-      jffs_print_raw_inode(&f.inode);
-    }
-
-    if (S_ISDIR(st.st_mode))
-    {
-      char *new_path;
-
-      if (!(new_path = (char *)alloca(strlen(path) + name_len + 1 + 1)))
-      {
-        fprintf(stderr, "mkfs(): alloca() failed! (new_path)\n");
-        exit(1);
-      }
-      strcpy(new_path, path);
-      strncat(new_path, f.name, f.inode.nsize);
-      strcat(new_path, "/");
-
-      if (verbose >= 2)
-      {
-        fprintf(stderr, "mkfs(): new_path: \"%s\"\n", new_path);
-      }
-      new_ino = mkfs(fs, new_path, new_ino, new_ino - 1, depth + 1);
-    }
-    if (f.name)
-    {
-      free(f.name);
-    }
-    if (f.data)
-    {
-      free(f.data);
-    }
-  }
-
-  closedir(dir);
-  return new_ino;
+       struct dirent *dir_entry;
+       DIR *dir;
+       struct stat st;
+       struct jffs_file f;
+       int name_len;
+       int pos = 0;
+       int new_ino = ino;
+       char *filename;
+       int path_len = strlen(path);
+
+       if (verbose >= 2)
+       {
+               fprintf(stderr, "***mkfs(): path: \"%s\"\r\n", path);
+       }
+
+       if (!(dir = opendir(path)))
+       {
+               perror("opendir");
+               fprintf(stderr, "mkfs(): opendir() failed! (%s)\n", path);
+               exit(1);
+       }
+
+       while ((dir_entry = readdir(dir)))
+       {
+               if (verbose >= 2)
+               {
+                       fprintf(stderr, "mkfs(): name: %s\n", dir_entry->d_name);
+               }
+               name_len = strlen(dir_entry->d_name);
+
+               if (((name_len == 1)
+                                       && (dir_entry->d_name[0] == '.'))
+                               || ((name_len == 2)
+                                       && (dir_entry->d_name[0] == '.')
+                                       && (dir_entry->d_name[1] == '.')))
+               {
+                       continue;
+               }
+
+               if (!(filename = (char *)alloca(path_len + name_len + 1)))
+               {
+                       fprintf(stderr, "mkfs(): Allocation failed!\n");
+                       exit(0);
+               }
+               strcpy(filename, path);
+               strcat(filename, dir_entry->d_name);
+
+               if (verbose >= 2)
+               {
+                       fprintf(stderr, "mkfs(): filename: %s\n", filename);
+               }
+
+               if (lstat(filename, &st) < 0)
+               {
+                       perror("lstat");
+                       exit(1);
+               }
+
+               if (verbose >= 2)
+               {
+                       fprintf(stderr, "mkfs(): filename: \"%s\", ino: %d, parent: %d\n",
+                                       filename, new_ino, parent);
+               }
+
+               write_val32(&f.inode.magic, JFFS_MAGIC);
+               write_val32(&f.inode.ino, new_ino);
+               write_val32(&f.inode.pino, parent);
+               write_val32(&f.inode.version, 1);
+               write_val32(&f.inode.mode, st.st_mode);
+               write_val16(&f.inode.uid, st.st_uid);
+               write_val16(&f.inode.gid, st.st_gid);
+               write_val32(&f.inode.atime, st.st_atime);
+               write_val32(&f.inode.mtime, st.st_mtime);
+               write_val32(&f.inode.ctime, st.st_ctime);
+               write_val32(&f.inode.dsize, 0);
+               write_val32(&f.inode.rsize, 0);
+               f.inode.nsize = name_len;
+               /*f.inode.nlink = st.st_nlink;*/
+               f.inode.nlink = 1;
+               f.inode.spare = 0;
+               f.inode.rename = 0;
+               f.inode.deleted = 0;
+               f.inode.accurate = 0;
+               write_val32(&f.inode.dchksum, 0);
+               write_val16(&f.inode.nchksum, 0);
+               write_val16(&f.inode.chksum, 0);
+               if (dir_entry->d_name)
+               {
+                       f.name = strdup(dir_entry->d_name);
+               }
+               else
+               {
+                       f.name = 0;
+               }
+
+repeat:
+               write_val32(&f.inode.offset, pos);
+               f.data = 0;
+               f.inode.accurate = 0;
+               if (S_ISREG(st.st_mode) && st.st_size)
+               {
+                       if (st.st_size - pos < MAX_CHUNK_SIZE)
+                       {
+                               write_val32(&f.inode.dsize, st.st_size - pos);
+                       }
+                       else
+                       {
+                               write_val32(&f.inode.dsize, MAX_CHUNK_SIZE);
+                       }
+
+                       read_data(&f, path, pos);
+                       pos += read_val32(&f.inode.dsize);
+               }
+               else if (S_ISLNK(st.st_mode))
+               {
+                       int linklen;
+                       char *linkdata = malloc(1000);
+                       if (!linkdata)
+                       {
+                               fprintf(stderr, "mkfs(): malloc() failed! (linkdata)\n");
+                               exit(1);
+                       }
+                       if ((linklen = readlink(filename, linkdata, 1000)) < 0)
+                       {
+                               free(linkdata);
+                               fprintf(stderr, "mkfs(): readlink() failed! f.name = \"%s\"\n",
+                                               f.name);
+                               exit(1);
+                       }
+
+                       write_val32(&f.inode.dsize, linklen);
+                       f.data = (unsigned char *)linkdata;
+                       f.data[linklen] = '\0';
+               }
+               else if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
+               {
+                       write_val32(&f.inode.dsize, sizeof(st.st_rdev) / 4);
+               }
+
+               write_val16(&f.inode.chksum, 0);
+               if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode))
+               {
+                       write_val32(&f.inode.dchksum, jffs_checksum((void *)f.data, read_val32(&f.inode.dsize)));
+               }
+               else
+               {
+                       write_val32(&f.inode.dchksum, jffs_checksum((void *)&st.st_rdev, sizeof(st.st_rdev) / 4));
+               }
+
+               write_val16(&f.inode.nchksum, jffs_checksum((void *)f.name, f.inode.nsize));
+               write_val16(&f.inode.chksum, jffs_checksum((void *)&f.inode, sizeof(struct jffs_raw_inode)));
+               f.inode.accurate = 0xff;
+
+               write_file(&f, fs, st);
+               if (S_ISREG(st.st_mode) && st.st_size)
+               {
+                       if (pos < st.st_size)
+                       {
+                               write_val32(&f.inode.version, read_val32(&f.inode.version) + 1);
+                               goto repeat;
+                       }
+               }
+
+               new_ino++;
+               pos = 0;
+               if (verbose >= 1)
+               {
+                       jffs_print_trace(f.name, depth);
+               }
+               if (verbose >= 2)
+               {
+                       jffs_print_raw_inode(&f.inode);
+               }
+
+               if (S_ISDIR(st.st_mode))
+               {
+                       char *new_path;
+
+                       if (!(new_path = (char *)alloca(strlen(path) + name_len + 1 + 1)))
+                       {
+                               fprintf(stderr, "mkfs(): alloca() failed! (new_path)\n");
+                               exit(1);
+                       }
+                       strcpy(new_path, path);
+                       strncat(new_path, f.name, f.inode.nsize);
+                       strcat(new_path, "/");
+
+                       if (verbose >= 2)
+                       {
+                               fprintf(stderr, "mkfs(): new_path: \"%s\"\n", new_path);
+                       }
+                       new_ino = mkfs(fs, new_path, new_ino, new_ino - 1, depth + 1);
+               }
+               if (f.name)
+               {
+                       free(f.name);
+               }
+               if (f.data)
+               {
+                       free(f.data);
+               }
+       }
+
+       closedir(dir);
+       return new_ino;
 }
 
 
-void
+       void
 usage(void)
 {
-  fprintf(stderr, "Usage: mkfs.jffs -d root_directory [-a little|big] [-e erase_size] [-o output_file] [-v[0-9]]\n");
-  fprintf(stderr, "       By default, the file system is built using the same endianness as the\n");
-  fprintf(stderr, "       host.  If building for a different target, use the -a option.\n");
+       fprintf(stderr, "Usage: mkfs.jffs -d root_directory [-a little|big] [-e erase_size] [-o output_file] [-v[0-9]]\n");
+       fprintf(stderr, "       By default, the file system is built using the same endianness as the\n");
+       fprintf(stderr, "       host.  If building for a different target, use the -a option.\n");
 }
 
 
-int
+       int
 main(int argc, char **argv)
 {
-  FILE *fs;
-  int root_ino;
-  int len;
-  int ch;
-  extern int optind;
-  extern char *optarg;
-
-  fs = stdout; /* Send constructed file system to stdout by default */
-
-  while ((ch = getopt(argc, argv, "a:d:e:v::o:h?")) != -1) {
-    switch((char)ch) {
-    case 'd':
-      len = strlen(optarg);
-      root_directory_name = (char *)malloc(len + 2);
-      memcpy(root_directory_name, optarg, len);
-      if (root_directory_name[len - 1] != '/')
+       FILE *fs;
+       int root_ino;
+       int len;
+       int ch;
+       extern int optind;
+       extern char *optarg;
+
+       fs = stdout; /* Send constructed file system to stdout by default */
+
+       while ((ch = getopt(argc, argv, "a:d:e:v::o:h?")) != -1) {
+               switch((char)ch) {
+                       case 'd':
+                               len = strlen(optarg);
+                               root_directory_name = (char *)malloc(len + 2);
+                               memcpy(root_directory_name, optarg, len);
+                               if (root_directory_name[len - 1] != '/')
+                               {
+                                       root_directory_name[len++] = '/';
+                               }
+                               root_directory_name[len] = '\0';
+                               break;
+                       case 'v':
+                               if (!optarg || strlen(optarg) == 0) {
+                                       verbose = 1;
+                               }
+                               else if (strlen(optarg) > 1 || !isdigit(optarg[0])) {
+                                       fprintf(stderr, "verbose level must be between 0 and 9!\n");
+                                       usage();
+                                       exit(1);
+                               }
+                               else {
+                                       verbose = strtol(optarg, NULL, 0);
+                               }
+                               break;
+                       case 'o':
+                               fs = fopen(optarg, "w");
+                               if (!fs) {
+                                       fprintf(stderr, "unable to open file %s for output.\n", optarg);
+                                       exit(1);
+                               }
+                               break;
+                       case 'a':
+                               if (strcmp(optarg, "little") == 0) {
+                                       endian = ENDIAN_LITTLE;
+                               }
+                               else if (strcmp(optarg, "big") == 0) {
+                                       endian = ENDIAN_BIG;
+                               }
+                               else {
+                                       usage();
+                                       exit(1);
+                               }
+                               break;
+                       case 'e':
+                               MAX_CHUNK_SIZE = strtol(optarg, NULL, 0) / 2;
+                               break;
+                       case 'h':
+                       case '?':
+                       default:
+                               usage();
+                               exit(0);
+               }
+       }
+
+       if ((argc -= optind)) {
+               usage();
+               exit(1);
+       }
+
+       if (root_directory_name == NULL) {
+               fprintf(stderr, "Error:  must specify a root directory\n");
+               usage();
+               exit(1);
+       }
+
+       if (verbose >= 1)
        {
-         root_directory_name[len++] = '/';
+               fprintf(stderr, "Constructing JFFS filesystem...\n");
        }
-      root_directory_name[len] = '\0';
-      break;
-    case 'v':
-      if (!optarg || strlen(optarg) == 0) {
-       verbose = 1;
-      }
-      else if (strlen(optarg) > 1 || !isdigit(optarg[0])) {
-       fprintf(stderr, "verbose level must be between 0 and 9!\n");
-       usage();
-       exit(1);
-      }
-      else {
-       verbose = strtol(optarg, NULL, 0);
-      }
-      break;
-    case 'o':
-      fs = fopen(optarg, "w");
-      if (!fs) {
-       fprintf(stderr, "unable to open file %s for output.\n", optarg);
-       exit(1);
-      }
-      break;
-    case 'a':
-      if (strcmp(optarg, "little") == 0) {
-       endian = ENDIAN_LITTLE;
-      }
-      else if (strcmp(optarg, "big") == 0) {
-       endian = ENDIAN_BIG;
-      }
-      else {
-       usage();
-       exit(1);
-      }
-      break;
-    case 'e':
-      MAX_CHUNK_SIZE = strtol(optarg, NULL, 0) / 2;
-      break;
-    case 'h':
-    case '?':
-    default:
-      usage();
-      exit(0);
-    }
-  }
-
-  if ((argc -= optind)) {
-    usage();
-    exit(1);
-  }
-
-  if (root_directory_name == NULL) {
-    fprintf(stderr, "Error:  must specify a root directory\n");
-    usage();
-    exit(1);
-  }
-
-  if (verbose >= 1)
-  {
-    fprintf(stderr, "Constructing JFFS filesystem...\n");
-  }
-  root_ino = make_root_dir(fs, JFFS_MIN_INO, root_directory_name, 0);
-  mkfs(fs, root_directory_name, root_ino + 1, root_ino, 1);
-
-  fclose(fs);
-  free(root_directory_name);
-  exit(0);
+       root_ino = make_root_dir(fs, JFFS_MIN_INO, root_directory_name, 0);
+       mkfs(fs, root_directory_name, root_ino + 1, root_ino, 1);
+
+       fclose(fs);
+       free(root_directory_name);
+       exit(0);
 }
index 0f970c48c074dcacf7d84a9fd3283032b37758e6..468f89e4d1aea4b52d219140488e67d4520822c2 100644 (file)
@@ -217,8 +217,8 @@ extern char *xreadlink(const char *path)
                buf = xrealloc(buf, bufsize += GROWBY);
                readsize = readlink(path, buf, bufsize); /* 1st try */
                if (readsize == -1) {
-                   perror_msg("%s:%s", app_name, path);
-                   return NULL;
+                       perror_msg("%s:%s", app_name, path);
+                       return NULL;
                }
        }
        while (bufsize < readsize + 1);
@@ -388,7 +388,7 @@ static struct filesystem_entry *recursive_add_host_directory(
        {
                dp = namelist[i];
                if (dp->d_name[0] == '.' && (dp->d_name[1] == 0 ||
-                  (dp->d_name[1] == '.' &&  dp->d_name[2] == 0)))
+                                       (dp->d_name[1] == '.' &&  dp->d_name[2] == 0)))
                {
                        free(dp);
                        continue;
@@ -432,8 +432,8 @@ static struct filesystem_entry *recursive_add_host_directory(
 }
 
 /* the GNU C library has a wonderful scanf("%as", string) which will
- allocate the string with the right size, good to avoid buffer overruns.
- the following macros use it if available or use a hacky workaround...
  allocate the string with the right size, good to avoid buffer overruns.
  the following macros use it if available or use a hacky workaround...
  */
 
 #ifdef __GNUC__
@@ -457,22 +457,22 @@ inline int snprintf(char *str, size_t n, const char *fmt, ...)
 #endif
 
 /*  device table entries take the form of:
-    <path>     <type> <mode>   <uid>   <gid>   <major> <minor> <start> <inc>   <count>
-    /dev/mem     c    640       0       0         1       1       0     0         -
+       <path>  <type> <mode>   <uid>   <gid>   <major> <minor> <start> <inc>   <count>
+       /dev/mem     c    640       0       0         1       1       0     0         -
 
-    type can be one of:
+       type can be one of:
        f       A regular file
        d       Directory
        c       Character special device file
        b       Block special device file
        p       Fifo (named pipe)
 
-    I don't bother with symlinks (permissions are irrelevant), hard
-    links (special cases of regular files), or sockets (why bother).
+       I don't bother with symlinks (permissions are irrelevant), hard
+       links (special cases of regular files), or sockets (why bother).
 
-    Regular files must exist in the target root directory.  If a char,
-    block, fifo, or directory does not exist, it will be created.
-*/
+       Regular files must exist in the target root directory.  If a char,
+       block, fifo, or directory does not exist, it will be created.
+ */
 static int interpret_table_entry(struct filesystem_entry *root, char *line)
 {
        char *hostpath;
@@ -482,8 +482,8 @@ static int interpret_table_entry(struct filesystem_entry *root, char *line)
        struct filesystem_entry *parent, *entry;
 
        if (sscanf (line, "%" SCANF_PREFIX "s %c %lo %lu %lu %lu %lu %lu %lu %lu",
-                SCANF_STRING(name), &type, &mode, &uid, &gid, &major, &minor,
-                &start, &increment, &count) < 0)
+                               SCANF_STRING(name), &type, &mode, &uid, &gid, &major, &minor,
+                               &start, &increment, &count) < 0)
        {
                return 1;
        }
@@ -666,7 +666,7 @@ static int add_cleanmarkers = 1;
 static struct jffs2_unknown_node cleanmarker;
 static int cleanmarker_size = sizeof(cleanmarker);
 static unsigned char ffbuf[16] =
-       { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
        0xff, 0xff, 0xff, 0xff, 0xff
 };
 
@@ -829,7 +829,7 @@ static unsigned int write_regular_file(struct filesystem_entry *e)
 
                while (len) {
                        uint32_t dsize, space;
-                        uint16_t compression;
+                       uint16_t compression;
 
                        pad_block_if_less_than(sizeof(ri) + JFFS2_MIN_DATA_LEN);
 
@@ -1078,32 +1078,32 @@ static void formalize_posix_acl(void *xvalue, int *value_len)
 
        while (pent < plim) {
                switch(le16_to_cpu(pent->e_tag)) {
-               case ACL_USER_OBJ:
-               case ACL_GROUP_OBJ:
-               case ACL_MASK:
-               case ACL_OTHER:
-                       jent_s = (struct jffs2_acl_entry_short *)(buffer + offset);
-                       offset += sizeof(struct jffs2_acl_entry_short);
-                       jent_s->e_tag = cpu_to_je16(le16_to_cpu(pent->e_tag));
-                       jent_s->e_perm = cpu_to_je16(le16_to_cpu(pent->e_perm));
-                       break;
-               case ACL_USER:
-               case ACL_GROUP:
-                       jent = (struct jffs2_acl_entry *)(buffer + offset);
-                       offset += sizeof(struct jffs2_acl_entry);
-                       jent->e_tag = cpu_to_je16(le16_to_cpu(pent->e_tag));
-                       jent->e_perm = cpu_to_je16(le16_to_cpu(pent->e_perm));
-                       jent->e_id = cpu_to_je32(le32_to_cpu(pent->e_id));
-                       break;
-               default:
-                       printf("%04x : Unknown XATTR entry tag.\n", le16_to_cpu(pent->e_tag));
-                       exit(1);
+                       case ACL_USER_OBJ:
+                       case ACL_GROUP_OBJ:
+                       case ACL_MASK:
+                       case ACL_OTHER:
+                               jent_s = (struct jffs2_acl_entry_short *)(buffer + offset);
+                               offset += sizeof(struct jffs2_acl_entry_short);
+                               jent_s->e_tag = cpu_to_je16(le16_to_cpu(pent->e_tag));
+                               jent_s->e_perm = cpu_to_je16(le16_to_cpu(pent->e_perm));
+                               break;
+                       case ACL_USER:
+                       case ACL_GROUP:
+                               jent = (struct jffs2_acl_entry *)(buffer + offset);
+                               offset += sizeof(struct jffs2_acl_entry);
+                               jent->e_tag = cpu_to_je16(le16_to_cpu(pent->e_tag));
+                               jent->e_perm = cpu_to_je16(le16_to_cpu(pent->e_perm));
+                               jent->e_id = cpu_to_je32(le32_to_cpu(pent->e_id));
+                               break;
+                       default:
+                               printf("%04x : Unknown XATTR entry tag.\n", le16_to_cpu(pent->e_tag));
+                               exit(1);
                }
                pent++;
        }
        if (offset > *value_len) {
                printf("Length of JFFS2 ACL expression(%u) is longer than general one(%u).\n",
-                      offset, *value_len);
+                               offset, *value_len);
                exit(1);
        }
        memcpy(xvalue, buffer, offset);
@@ -1164,16 +1164,16 @@ static xattr_entry_t *find_xattr_entry(int xprefix, char *xname, char *xvalue, i
                xentry_hash = xcalloc(1, sizeof(xe) * XATTRENTRY_HASHSIZE);
 
        if (xprefix == JFFS2_XPREFIX_ACL_ACCESS
-           || xprefix == JFFS2_XPREFIX_ACL_DEFAULT)
+                       || xprefix == JFFS2_XPREFIX_ACL_DEFAULT)
                formalize_posix_acl(xvalue, &value_len);
 
        name_len = strlen(xname);
        index = (crc32(0, xname, name_len) ^ crc32(0, xvalue, value_len)) % XATTRENTRY_HASHSIZE;
        for (xe = xentry_hash[index]; xe; xe = xe->next) {
                if (xe->xprefix == xprefix
-                   && xe->value_len == value_len
-                   && !strcmp(xe->xname, xname)
-                   && !memcmp(xe->xvalue, xvalue, value_len))
+                               && xe->value_len == value_len
+                               && !strcmp(xe->xname, xname)
+                               && !memcmp(xe->xvalue, xvalue, value_len))
                        break;
        }
        if (!xe) {
@@ -1200,7 +1200,7 @@ static void write_xattr_entry(struct filesystem_entry *e)
        if (list_sz < 0) {
                if (verbose)
                        printf("llistxattr('%s') = %d : %s\n",
-                              e->hostname, errno, strerror(errno));
+                                       e->hostname, errno, strerror(errno));
                return;
        }
 
@@ -1222,7 +1222,7 @@ static void write_xattr_entry(struct filesystem_entry *e)
                if (!xprefix) {
                        if (verbose)
                                printf("%s: xattr '%s' is not supported.\n",
-                                      e->hostname, xname);
+                                               e->hostname, xname);
                        continue;
                }
                if ((enable_xattr & (1 << xprefix)) == 0)
@@ -1232,14 +1232,14 @@ static void write_xattr_entry(struct filesystem_entry *e)
                if (value_len < 0) {
                        if (verbose)
                                printf("lgetxattr('%s', '%s') = %d : %s\n",
-                                      e->hostname, xname, errno, strerror(errno));
+                                               e->hostname, xname, errno, strerror(errno));
                        continue;
                }
                xe = find_xattr_entry(xprefix, xname + prefix_len, xvalue, value_len);
                if (!xe) {
                        if (verbose)
                                printf("%s : xattr '%s' was ignored.\n",
-                                      e->hostname, xname);
+                                               e->hostname, xname);
                        continue;
                }
 
@@ -1423,41 +1423,41 @@ static struct option long_options[] = {
 };
 
 static char *helptext =
-       "Usage: mkfs.jffs2 [OPTIONS]\n"
-       "Make a JFFS2 file system image from an existing directory tree\n\n"
-       "Options:\n"
-       "  -p, --pad[=SIZE]        Pad output to SIZE bytes with 0xFF. If SIZE is\n"
-       "                          not specified, the output is padded to the end of\n"
-       "                          the final erase block\n"
-       "  -r, -d, --root=DIR      Build file system from directory DIR (default: cwd)\n"
-       "  -s, --pagesize=SIZE     Use page size (max data node size) SIZE (default: 4KiB)\n"
-       "  -e, --eraseblock=SIZE   Use erase block size SIZE (default: 64KiB)\n"
-       "  -c, --cleanmarker=SIZE  Size of cleanmarker (default 12)\n"
-       "  -m, --compr-mode=MODE   Select compression mode (default: priortiry)\n"
-        "  -x, --disable-compressor=COMPRESSOR_NAME\n"
-        "                          Disable a compressor\n"
-        "  -X, --enable-compressor=COMPRESSOR_NAME\n"
-        "                          Enable a compressor\n"
-        "  -y, --compressor-priority=PRIORITY:COMPRESSOR_NAME\n"
-        "                          Set the priority of a compressor\n"
-        "  -L, --list-compressors  Show the list of the avaiable compressors\n"
-        "  -t, --test-compression  Call decompress and compare with the original (for test)\n"
-       "  -n, --no-cleanmarkers   Don't add a cleanmarker to every eraseblock\n"
-       "  -o, --output=FILE       Output to FILE (default: stdout)\n"
-       "  -l, --little-endian     Create a little-endian filesystem\n"
-       "  -b, --big-endian        Create a big-endian filesystem\n"
-       "  -D, --devtable=FILE     Use the named FILE as a device table file\n"
-       "  -f, --faketime          Change all file times to '0' for regression testing\n"
-       "  -q, --squash            Squash permissions and owners making all files be owned by root\n"
-       "  -U, --squash-uids       Squash owners making all files be owned by root\n"
-       "  -P, --squash-perms      Squash permissions on all files\n"
-       "      --with-xattr        stuff all xattr entries into image\n"
-       "      --with-selinux      stuff only SELinux Labels into jffs2 image\n"
-       "      --with-posix-acl    stuff only POSIX ACL entries into jffs2 image\n"
-       "  -h, --help              Display this help text\n"
-       "  -v, --verbose           Verbose operation\n"
-       "  -V, --version           Display version information\n"
-       "  -i, --incremental=FILE  Parse FILE and generate appendage output for it\n\n";
+"Usage: mkfs.jffs2 [OPTIONS]\n"
+"Make a JFFS2 file system image from an existing directory tree\n\n"
+"Options:\n"
+"  -p, --pad[=SIZE]        Pad output to SIZE bytes with 0xFF. If SIZE is\n"
+"                          not specified, the output is padded to the end of\n"
+"                          the final erase block\n"
+"  -r, -d, --root=DIR      Build file system from directory DIR (default: cwd)\n"
+"  -s, --pagesize=SIZE     Use page size (max data node size) SIZE (default: 4KiB)\n"
+"  -e, --eraseblock=SIZE   Use erase block size SIZE (default: 64KiB)\n"
+"  -c, --cleanmarker=SIZE  Size of cleanmarker (default 12)\n"
+"  -m, --compr-mode=MODE   Select compression mode (default: priortiry)\n"
+"  -x, --disable-compressor=COMPRESSOR_NAME\n"
+"                          Disable a compressor\n"
+"  -X, --enable-compressor=COMPRESSOR_NAME\n"
+"                          Enable a compressor\n"
+"  -y, --compressor-priority=PRIORITY:COMPRESSOR_NAME\n"
+"                          Set the priority of a compressor\n"
+"  -L, --list-compressors  Show the list of the avaiable compressors\n"
+"  -t, --test-compression  Call decompress and compare with the original (for test)\n"
+"  -n, --no-cleanmarkers   Don't add a cleanmarker to every eraseblock\n"
+"  -o, --output=FILE       Output to FILE (default: stdout)\n"
+"  -l, --little-endian     Create a little-endian filesystem\n"
+"  -b, --big-endian        Create a big-endian filesystem\n"
+"  -D, --devtable=FILE     Use the named FILE as a device table file\n"
+"  -f, --faketime          Change all file times to '0' for regression testing\n"
+"  -q, --squash            Squash permissions and owners making all files be owned by root\n"
+"  -U, --squash-uids       Squash owners making all files be owned by root\n"
+"  -P, --squash-perms      Squash permissions on all files\n"
+"      --with-xattr        stuff all xattr entries into image\n"
+"      --with-selinux      stuff only SELinux Labels into jffs2 image\n"
+"      --with-posix-acl    stuff only POSIX ACL entries into jffs2 image\n"
+"  -h, --help              Display this help text\n"
+"  -v, --verbose           Verbose operation\n"
+"  -V, --version           Display version information\n"
+"  -i, --incremental=FILE  Parse FILE and generate appendage output for it\n\n";
 
 static char *revtext = "$Revision: 1.50 $";
 
@@ -1493,7 +1493,7 @@ void process_buffer(int inp_size) {
 
                if (je16_to_cpu (node->u.magic) != JFFS2_MAGIC_BITMASK) {
                        if (!bitchbitmask++)
-                           printf ("Wrong bitmask  at  0x%08x, 0x%04x\n", p - file_buffer, je16_to_cpu (node->u.magic));
+                               printf ("Wrong bitmask  at  0x%08x, 0x%04x\n", p - file_buffer, je16_to_cpu (node->u.magic));
                        p += 4;
                        continue;
                }
@@ -1514,10 +1514,10 @@ void process_buffer(int inp_size) {
                        case JFFS2_NODETYPE_INODE:
                                if(verbose)
                                        printf ("%8s Inode      node at 0x%08x, totlen 0x%08x, #ino  %5d, version %5d, isize %8d, csize %8d, dsize %8d, offset %8d\n",
-                                               obsolete ? "Obsolete" : "",
-                                               p - file_buffer, je32_to_cpu (node->i.totlen), je32_to_cpu (node->i.ino),
-                                               je32_to_cpu ( node->i.version), je32_to_cpu (node->i.isize),
-                                               je32_to_cpu (node->i.csize), je32_to_cpu (node->i.dsize), je32_to_cpu (node->i.offset));
+                                                       obsolete ? "Obsolete" : "",
+                                                       p - file_buffer, je32_to_cpu (node->i.totlen), je32_to_cpu (node->i.ino),
+                                                       je32_to_cpu ( node->i.version), je32_to_cpu (node->i.isize),
+                                                       je32_to_cpu (node->i.csize), je32_to_cpu (node->i.dsize), je32_to_cpu (node->i.offset));
 
                                if ( je32_to_cpu (node->i.ino) > ino )
                                        ino = je32_to_cpu (node->i.ino);
@@ -1531,10 +1531,10 @@ void process_buffer(int inp_size) {
 
                                if(verbose)
                                        printf ("%8s Dirent     node at 0x%08x, totlen 0x%08x, #pino %5d, version %5d, #ino  %8d, nsize %8d, name %s\n",
-                                               obsolete ? "Obsolete" : "",
-                                               p - file_buffer, je32_to_cpu (node->d.totlen), je32_to_cpu (node->d.pino),
-                                               je32_to_cpu ( node->d.version), je32_to_cpu (node->d.ino),
-                                               node->d.nsize, name);
+                                                       obsolete ? "Obsolete" : "",
+                                                       p - file_buffer, je32_to_cpu (node->d.totlen), je32_to_cpu (node->d.pino),
+                                                       je32_to_cpu ( node->d.version), je32_to_cpu (node->d.ino),
+                                                       node->d.nsize, name);
 
                                p += PAD(je32_to_cpu (node->d.totlen));
                                break;
@@ -1542,8 +1542,8 @@ void process_buffer(int inp_size) {
                        case JFFS2_NODETYPE_CLEANMARKER:
                                if (verbose) {
                                        printf ("%8s Cleanmarker     at 0x%08x, totlen 0x%08x\n",
-                                               obsolete ? "Obsolete" : "",
-                                               p - file_buffer, je32_to_cpu (node->u.totlen));
+                                                       obsolete ? "Obsolete" : "",
+                                                       p - file_buffer, je32_to_cpu (node->u.totlen));
                                }
 
                                p += PAD(je32_to_cpu (node->u.totlen));
@@ -1552,8 +1552,8 @@ void process_buffer(int inp_size) {
                        case JFFS2_NODETYPE_PADDING:
                                if (verbose) {
                                        printf ("%8s Padding    node at 0x%08x, totlen 0x%08x\n",
-                                               obsolete ? "Obsolete" : "",
-                                               p - file_buffer, je32_to_cpu (node->u.totlen));
+                                                       obsolete ? "Obsolete" : "",
+                                                       p - file_buffer, je32_to_cpu (node->u.totlen));
                                }
 
                                p += PAD(je32_to_cpu (node->u.totlen));
@@ -1566,8 +1566,8 @@ void process_buffer(int inp_size) {
                        default:
                                if (verbose) {
                                        printf ("%8s Unknown    node at 0x%08x, totlen 0x%08x\n",
-                                               obsolete ? "Obsolete" : "",
-                                               p - file_buffer, je32_to_cpu (node->u.totlen));
+                                                       obsolete ? "Obsolete" : "",
+                                                       p - file_buffer, je32_to_cpu (node->u.totlen));
                                }
 
                                p += PAD(je32_to_cpu (node->u.totlen));
@@ -1604,10 +1604,10 @@ int main(int argc, char **argv)
        struct stat sb;
        FILE *devtable = NULL;
        struct filesystem_entry *root;
-        char *compr_name = NULL;
-        int compr_prior  = -1;
+       char *compr_name = NULL;
+       int compr_prior  = -1;
 
-        jffs2_compressors_init();
+       jffs2_compressors_init();
 
        while ((opt = getopt_long(argc, argv,
                                        "D:d:r:s:o:qUPfh?vVe:lbp::nc:m:x:X:Lty:i:", long_options, &c)) >= 0)
@@ -1673,119 +1673,119 @@ int main(int argc, char **argv)
                                                (int) strlen(revtext) - 13, revtext + 11);
 
                        case 'e': {
-                               char *next;
-                               unsigned units = 0;
-                               erase_block_size = strtol(optarg, &next, 0);
-                               if (!erase_block_size)
-                                       error_msg_and_die("Unrecognisable erase size\n");
-
-                               if (*next) {
-                                       if (!strcmp(next, "KiB")) {
-                                               units = 1024;
-                                       } else if (!strcmp(next, "MiB")) {
-                                               units = 1024 * 1024;
-                                       } else {
-                                               error_msg_and_die("Unknown units in erasesize\n");
-                                       }
-                               } else {
-                                       if (erase_block_size < 0x1000)
-                                               units = 1024;
-                                       else
-                                               units = 1;
-                               }
-                               erase_block_size *= units;
-
-                               /* If it's less than 8KiB, they're not allowed */
-                               if (erase_block_size < 0x2000) {
-                                       fprintf(stderr, "Erase size 0x%x too small. Increasing to 8KiB minimum\n",
-                                               erase_block_size);
-                                       erase_block_size = 0x2000;
-                               }
-                               break;
-                       }
+                                                 char *next;
+                                                 unsigned units = 0;
+                                                 erase_block_size = strtol(optarg, &next, 0);
+                                                 if (!erase_block_size)
+                                                         error_msg_and_die("Unrecognisable erase size\n");
+
+                                                 if (*next) {
+                                                         if (!strcmp(next, "KiB")) {
+                                                                 units = 1024;
+                                                         } else if (!strcmp(next, "MiB")) {
+                                                                 units = 1024 * 1024;
+                                                         } else {
+                                                                 error_msg_and_die("Unknown units in erasesize\n");
+                                                         }
+                                                 } else {
+                                                         if (erase_block_size < 0x1000)
+                                                                 units = 1024;
+                                                         else
+                                                                 units = 1;
+                                                 }
+                                                 erase_block_size *= units;
+
+                                                 /* If it's less than 8KiB, they're not allowed */
+                                                 if (erase_block_size < 0x2000) {
+                                                         fprintf(stderr, "Erase size 0x%x too small. Increasing to 8KiB minimum\n",
+                                                                         erase_block_size);
+                                                         erase_block_size = 0x2000;
+                                                 }
+                                                 break;
+                                         }
 
                        case 'l':
-                               target_endian = __LITTLE_ENDIAN;
-                               break;
+                                         target_endian = __LITTLE_ENDIAN;
+                                         break;
 
                        case 'b':
-                               target_endian = __BIG_ENDIAN;
-                               break;
+                                         target_endian = __BIG_ENDIAN;
+                                         break;
 
                        case 'p':
-                               if (optarg)
-                                       pad_fs_size = strtol(optarg, NULL, 0);
-                               else
-                                       pad_fs_size = -1;
-                               break;
+                                         if (optarg)
+                                                 pad_fs_size = strtol(optarg, NULL, 0);
+                                         else
+                                                 pad_fs_size = -1;
+                                         break;
                        case 'n':
-                               add_cleanmarkers = 0;
-                               break;
+                                         add_cleanmarkers = 0;
+                                         break;
                        case 'c':
-                               cleanmarker_size = strtol(optarg, NULL, 0);
-                               if (cleanmarker_size < sizeof(cleanmarker)) {
-                                       error_msg_and_die("cleanmarker size must be >= 12");
-                               }
-                               if (cleanmarker_size >= erase_block_size) {
-                                       error_msg_and_die("cleanmarker size must be < eraseblock size");
-                               }
-                               break;
-                        case 'm':
-                                if (jffs2_set_compression_mode_name(optarg)) {
-                                       error_msg_and_die("Unknown compression mode %s", optarg);
-                               }
-                                break;
-                        case 'x':
-                                if (jffs2_disable_compressor_name(optarg)) {
-                                        error_msg_and_die("Unknown compressor name %s",optarg);
-                                }
-                                break;
-                        case 'X':
-                                if (jffs2_enable_compressor_name(optarg)) {
-                                        error_msg_and_die("Unknown compressor name %s",optarg);
-                                }
-                                break;
-                        case 'L':
-                                error_msg_and_die("\n%s",jffs2_list_compressors());
-                                break;
-                        case 't':
-                                jffs2_compression_check_set(1);
-                                break;
-                        case 'y':
-                                compr_name = malloc(strlen(optarg));
-                                sscanf(optarg,"%d:%s",&compr_prior,compr_name);
-                                if ((compr_prior>=0)&&(compr_name)) {
-                                        if (jffs2_set_compressor_priority(compr_name, compr_prior))
-                                               exit(EXIT_FAILURE);
-                                }
-                                else {
-                                        error_msg_and_die("Cannot parse %s",optarg);
-                                }
-                                free(compr_name);
-                                break;
+                                         cleanmarker_size = strtol(optarg, NULL, 0);
+                                         if (cleanmarker_size < sizeof(cleanmarker)) {
+                                                 error_msg_and_die("cleanmarker size must be >= 12");
+                                         }
+                                         if (cleanmarker_size >= erase_block_size) {
+                                                 error_msg_and_die("cleanmarker size must be < eraseblock size");
+                                         }
+                                         break;
+                       case 'm':
+                                         if (jffs2_set_compression_mode_name(optarg)) {
+                                                 error_msg_and_die("Unknown compression mode %s", optarg);
+                                         }
+                                         break;
+                       case 'x':
+                                         if (jffs2_disable_compressor_name(optarg)) {
+                                                 error_msg_and_die("Unknown compressor name %s",optarg);
+                                         }
+                                         break;
+                       case 'X':
+                                         if (jffs2_enable_compressor_name(optarg)) {
+                                                 error_msg_and_die("Unknown compressor name %s",optarg);
+                                         }
+                                         break;
+                       case 'L':
+                                         error_msg_and_die("\n%s",jffs2_list_compressors());
+                                         break;
+                       case 't':
+                                         jffs2_compression_check_set(1);
+                                         break;
+                       case 'y':
+                                         compr_name = malloc(strlen(optarg));
+                                         sscanf(optarg,"%d:%s",&compr_prior,compr_name);
+                                         if ((compr_prior>=0)&&(compr_name)) {
+                                                 if (jffs2_set_compressor_priority(compr_name, compr_prior))
+                                                         exit(EXIT_FAILURE);
+                                         }
+                                         else {
+                                                 error_msg_and_die("Cannot parse %s",optarg);
+                                         }
+                                         free(compr_name);
+                                         break;
                        case 'i':
-                               if (in_fd != -1) {
-                                       error_msg_and_die("(incremental) filename specified more than once");
-                               }
-                               in_fd = open(optarg, O_RDONLY);
-                               if (in_fd == -1) {
-                                       perror_msg_and_die("cannot open (incremental) file");
-                               }
-                               break;
+                                         if (in_fd != -1) {
+                                                 error_msg_and_die("(incremental) filename specified more than once");
+                                         }
+                                         in_fd = open(optarg, O_RDONLY);
+                                         if (in_fd == -1) {
+                                                 perror_msg_and_die("cannot open (incremental) file");
+                                         }
+                                         break;
                        case 1000:      /* --with-xattr  */
-                               enable_xattr |= (1 << JFFS2_XPREFIX_USER)
-                                               | (1 << JFFS2_XPREFIX_SECURITY)
-                                               | (1 << JFFS2_XPREFIX_ACL_ACCESS)
-                                               | (1 << JFFS2_XPREFIX_ACL_DEFAULT)
-                                               | (1 << JFFS2_XPREFIX_TRUSTED);
-                               break;
+                                         enable_xattr |= (1 << JFFS2_XPREFIX_USER)
+                                                 | (1 << JFFS2_XPREFIX_SECURITY)
+                                                 | (1 << JFFS2_XPREFIX_ACL_ACCESS)
+                                                 | (1 << JFFS2_XPREFIX_ACL_DEFAULT)
+                                                 | (1 << JFFS2_XPREFIX_TRUSTED);
+                                         break;
                        case 1001:      /*  --with-selinux  */
-                               enable_xattr |= (1 << JFFS2_XPREFIX_SECURITY);
-                               break;
+                                         enable_xattr |= (1 << JFFS2_XPREFIX_SECURITY);
+                                         break;
                        case 1002:      /*  --with-posix-acl  */
-                               enable_xattr |= (1 << JFFS2_XPREFIX_ACL_ACCESS)
-                                               | (1 << JFFS2_XPREFIX_ACL_DEFAULT);
-                               break;
+                                         enable_xattr |= (1 << JFFS2_XPREFIX_ACL_ACCESS)
+                                                 | (1 << JFFS2_XPREFIX_ACL_DEFAULT);
+                                         break;
                }
        }
        if (out_fd == -1) {
@@ -1820,16 +1820,16 @@ int main(int argc, char **argv)
 
        close(out_fd);
 
-        if (verbose) {
-                char *s = jffs2_stats();
-                fprintf(stderr,"\n\n%s",s);
-                free(s);
-        }
-        if ((verbose)||(jffs2_compression_check_get()&&(jffs2_compression_check_errorcnt_get()))) {
-                fprintf(stderr,"Compression errors: %d\n",jffs2_compression_check_errorcnt_get());
-        }
+       if (verbose) {
+               char *s = jffs2_stats();
+               fprintf(stderr,"\n\n%s",s);
+               free(s);
+       }
+       if ((verbose)||(jffs2_compression_check_get()&&(jffs2_compression_check_errorcnt_get()))) {
+               fprintf(stderr,"Compression errors: %d\n",jffs2_compression_check_errorcnt_get());
+       }
 
-        jffs2_compressors_exit();
+       jffs2_compressors_exit();
 
        return 0;
 }
index ee3c67c0db014b65298bb25c6be3102580b121f1..e0cc7d721f9edafcd7ab2789a781b824f6c4a562 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (c) 2d3D, Inc.
  * Written by Abraham vd Merwe <abraham@2d3d.co.za>
@@ -46,7 +45,7 @@
  */
 static int getmeminfo (int fd,struct mtd_info_user *mtd)
 {
-   return (ioctl (fd,MEMGETINFO,mtd));
+       return (ioctl (fd,MEMGETINFO,mtd));
 }
 
 /*
@@ -54,7 +53,7 @@ static int getmeminfo (int fd,struct mtd_info_user *mtd)
  */
 static int memerase (int fd,struct erase_info_user *erase)
 {
-   return (ioctl (fd,MEMERASE,erase));
+       return (ioctl (fd,MEMERASE,erase));
 }
 
 /*
@@ -63,66 +62,66 @@ static int memerase (int fd,struct erase_info_user *erase)
  */
 static int getregions (int fd,struct region_info_user *regions,int *n)
 {
-   int i,err;
-   err = ioctl (fd,MEMGETREGIONCOUNT,n);
-   if (err) return (err);
-   for (i = 0; i < *n; i++)
-        {
+       int i,err;
+       err = ioctl (fd,MEMGETREGIONCOUNT,n);
+       if (err) return (err);
+       for (i = 0; i < *n; i++)
+       {
                regions[i].regionindex = i;
                err = ioctl (fd,MEMGETREGIONINFO,&regions[i]);
                if (err) return (err);
-        }
-   return (0);
+       }
+       return (0);
 }
 
 int erase_flash (int fd,u_int32_t offset,u_int32_t bytes)
 {
-   int err;
-   struct erase_info_user erase;
-   erase.start = offset;
-   erase.length = bytes;
-   err = memerase (fd,&erase);
-   if (err < 0)
-        {
+       int err;
+       struct erase_info_user erase;
+       erase.start = offset;
+       erase.length = bytes;
+       err = memerase (fd,&erase);
+       if (err < 0)
+       {
                perror ("MEMERASE");
                return (1);
-        }
-   fprintf (stderr,"Erased %d bytes from address 0x%.8x in flash\n",bytes,offset);
-   return (0);
+       }
+       fprintf (stderr,"Erased %d bytes from address 0x%.8x in flash\n",bytes,offset);
+       return (0);
 }
 
 void printsize (u_int32_t x)
 {
-   int i;
-   static const char *flags = "KMGT";
-   printf ("%u ",x);
-   for (i = 0; x >= 1024 && flags[i] != '\0'; i++) x /= 1024;
-   i--;
-   if (i >= 0) printf ("(%u%c)",x,flags[i]);
+       int i;
+       static const char *flags = "KMGT";
+       printf ("%u ",x);
+       for (i = 0; x >= 1024 && flags[i] != '\0'; i++) x /= 1024;
+       i--;
+       if (i >= 0) printf ("(%u%c)",x,flags[i]);
 }
 
 int flash_to_file (int fd,u_int32_t offset,size_t len,const char *filename)
 {
-   u_int8_t *buf = NULL;
-   int outfd,err;
-   int size = len * sizeof (u_int8_t);
-   int n = len;
+       u_int8_t *buf = NULL;
+       int outfd,err;
+       int size = len * sizeof (u_int8_t);
+       int n = len;
 
-   if (offset != lseek (fd,offset,SEEK_SET))
-        {
+       if (offset != lseek (fd,offset,SEEK_SET))
+       {
                perror ("lseek()");
                goto err0;
-        }
-   outfd = creat (filename,O_WRONLY);
-   if (outfd < 0)
-        {
+       }
+       outfd = creat (filename,O_WRONLY);
+       if (outfd < 0)
+       {
                perror ("creat()");
                goto err1;
-        }
+       }
 
 retry:
-   if ((buf = (u_int8_t *) malloc (size)) == NULL)
-        {
+       if ((buf = (u_int8_t *) malloc (size)) == NULL)
+       {
 #define BUF_SIZE       (64 * 1024 * sizeof (u_int8_t))
                fprintf (stderr, "%s: malloc(%#x)\n", __FUNCTION__, size);
                if (size != BUF_SIZE) {
@@ -132,68 +131,68 @@ retry:
                }
                perror ("malloc()");
                goto err0;
-        }
- do {
-   if (n <= size)
-          size = n;
-   err = read (fd,buf,size);
-   if (err < 0)
-        {
-               fprintf (stderr, "%s: read, size %#x, n %#x\n", __FUNCTION__, size, n);
-               perror ("read()");
-               goto err2;
-        }
-   err = write (outfd,buf,size);
-   if (err < 0)
-        {
-               fprintf (stderr, "%s: write, size %#x, n %#x\n", __FUNCTION__, size, n);
-               perror ("write()");
-               goto err2;
-        }
-   if (err != size)
-        {
-               fprintf (stderr,"Couldn't copy entire buffer to %s. (%d/%d bytes copied)\n",filename,err,size);
-               goto err2;
-        }
-   n -= size;
-   } while (n > 0);
-
-   if (buf != NULL)
-   free (buf);
-   close (outfd);
-   printf ("Copied %d bytes from address 0x%.8x in flash to %s\n",len,offset,filename);
-   return (0);
-
-   err2:
-   close (outfd);
-   err1:
-   if (buf != NULL)
-   free (buf);
-   err0:
-   return (1);
+       }
      do {
+               if (n <= size)
+                       size = n;
+               err = read (fd,buf,size);
+               if (err < 0)
+               {
+                       fprintf (stderr, "%s: read, size %#x, n %#x\n", __FUNCTION__, size, n);
+                       perror ("read()");
+                       goto err2;
+               }
+               err = write (outfd,buf,size);
+               if (err < 0)
+               {
+                       fprintf (stderr, "%s: write, size %#x, n %#x\n", __FUNCTION__, size, n);
+                       perror ("write()");
+                       goto err2;
+               }
+               if (err != size)
+               {
+                       fprintf (stderr,"Couldn't copy entire buffer to %s. (%d/%d bytes copied)\n",filename,err,size);
+                       goto err2;
+               }
+               n -= size;
+       } while (n > 0);
+
+       if (buf != NULL)
+               free (buf);
+       close (outfd);
+       printf ("Copied %d bytes from address 0x%.8x in flash to %s\n",len,offset,filename);
+       return (0);
+
+err2:
+       close (outfd);
+err1:
+       if (buf != NULL)
+               free (buf);
+err0:
+       return (1);
 }
 
 int file_to_flash (int fd,u_int32_t offset,u_int32_t len,const char *filename)
 {
-   u_int8_t *buf = NULL;
-   FILE *fp;
-   int err;
-   int size = len * sizeof (u_int8_t);
-   int n = len;
-
-   if (offset != lseek (fd,offset,SEEK_SET))
-        {
+       u_int8_t *buf = NULL;
+       FILE *fp;
+       int err;
+       int size = len * sizeof (u_int8_t);
+       int n = len;
+
+       if (offset != lseek (fd,offset,SEEK_SET))
+       {
                perror ("lseek()");
                return (1);
-        }
-   if ((fp = fopen (filename,"r")) == NULL)
-        {
+       }
+       if ((fp = fopen (filename,"r")) == NULL)
+       {
                perror ("fopen()");
                return (1);
-        }
+       }
 retry:
-   if ((buf = (u_int8_t *) malloc (size)) == NULL)
-        {
+       if ((buf = (u_int8_t *) malloc (size)) == NULL)
+       {
                fprintf (stderr, "%s: malloc(%#x) failed\n", __FUNCTION__, size);
                if (size != BUF_SIZE) {
                        size = BUF_SIZE;
@@ -203,147 +202,147 @@ retry:
                perror ("malloc()");
                fclose (fp);
                return (1);
-        }
- do {
-   if (n <= size)
-          size = n;
-   if (fread (buf,size,1,fp) != 1 || ferror (fp))
-        {
-               fprintf (stderr, "%s: fread, size %#x, n %#x\n", __FUNCTION__, size, n);
-               perror ("fread()");
-               free (buf);
-               fclose (fp);
-               return (1);
-        }
-   err = write (fd,buf,size);
-   if (err < 0)
-        {
-               fprintf (stderr, "%s: write, size %#x, n %#x\n", __FUNCTION__, size, n);
-               perror ("write()");
+       }
+       do {
+               if (n <= size)
+                       size = n;
+               if (fread (buf,size,1,fp) != 1 || ferror (fp))
+               {
+                       fprintf (stderr, "%s: fread, size %#x, n %#x\n", __FUNCTION__, size, n);
+                       perror ("fread()");
+                       free (buf);
+                       fclose (fp);
+                       return (1);
+               }
+               err = write (fd,buf,size);
+               if (err < 0)
+               {
+                       fprintf (stderr, "%s: write, size %#x, n %#x\n", __FUNCTION__, size, n);
+                       perror ("write()");
+                       free (buf);
+                       fclose (fp);
+                       return (1);
+               }
+               n -= size;
+       } while (n > 0);
+
+       if (buf != NULL)
                free (buf);
-               fclose (fp);
-               return (1);
-        }
-   n -= size;
-} while (n > 0);
-
-   if (buf != NULL)
-   free (buf);
-   fclose (fp);
-   printf ("Copied %d bytes from %s to address 0x%.8x in flash\n",len,filename,offset);
-   return (0);
+       fclose (fp);
+       printf ("Copied %d bytes from %s to address 0x%.8x in flash\n",len,filename,offset);
+       return (0);
 }
 
 int showinfo (int fd)
 {
-   int i,err,n;
-   struct mtd_info_user mtd;
-   static struct region_info_user region[1024];
+       int i,err,n;
+       struct mtd_info_user mtd;
+       static struct region_info_user region[1024];
 
-   err = getmeminfo (fd,&mtd);
-   if (err < 0)
-        {
+       err = getmeminfo (fd,&mtd);
+       if (err < 0)
+       {
                perror ("MEMGETINFO");
                return (1);
-        }
+       }
 
-   err = getregions (fd,region,&n);
-   if (err < 0)
-        {
+       err = getregions (fd,region,&n);
+       if (err < 0)
+       {
                perror ("MEMGETREGIONCOUNT");
                return (1);
-        }
-
-   printf ("mtd.type = ");
-   switch (mtd.type)
-        {
-         case MTD_ABSENT:
-               printf ("MTD_ABSENT");
-               break;
-         case MTD_NORFLASH:
-               printf ("MTD_NORFLASH");
-               break;
-         case MTD_NANDFLASH:
-               printf ("MTD_NANDFLASH");
-               break;
-         case MTD_GENERIC_TYPE:
-               printf ("MTD_GENERIC_TYPE");
-               break;
-         default:
-               printf ("(unknown type - new MTD API maybe?)");
-        }
-
-   printf ("\nmtd.flags = ");
-   if (mtd.flags == MTD_CAP_ROM)
-        printf ("MTD_CAP_ROM");
-   else if (mtd.flags == MTD_CAP_RAM)
-        printf ("MTD_CAP_RAM");
-   else if (mtd.flags == MTD_CAP_NORFLASH)
-        printf ("MTD_CAP_NORFLASH");
-   else if (mtd.flags == MTD_CAP_NANDFLASH)
-        printf ("MTD_CAP_NANDFLASH");
-   else if (mtd.flags == MTD_WRITEABLE)
-        printf ("MTD_WRITEABLE");
-   else
-        {
+       }
+
+       printf ("mtd.type = ");
+       switch (mtd.type)
+       {
+               case MTD_ABSENT:
+                       printf ("MTD_ABSENT");
+                       break;
+               case MTD_NORFLASH:
+                       printf ("MTD_NORFLASH");
+                       break;
+               case MTD_NANDFLASH:
+                       printf ("MTD_NANDFLASH");
+                       break;
+               case MTD_GENERIC_TYPE:
+                       printf ("MTD_GENERIC_TYPE");
+                       break;
+               default:
+                       printf ("(unknown type - new MTD API maybe?)");
+       }
+
+       printf ("\nmtd.flags = ");
+       if (mtd.flags == MTD_CAP_ROM)
+               printf ("MTD_CAP_ROM");
+       else if (mtd.flags == MTD_CAP_RAM)
+               printf ("MTD_CAP_RAM");
+       else if (mtd.flags == MTD_CAP_NORFLASH)
+               printf ("MTD_CAP_NORFLASH");
+       else if (mtd.flags == MTD_CAP_NANDFLASH)
+               printf ("MTD_CAP_NANDFLASH");
+       else if (mtd.flags == MTD_WRITEABLE)
+               printf ("MTD_WRITEABLE");
+       else
+       {
                int first = 1;
                static struct
-                 {
-                        const char *name;
-                        int value;
-                 } flags[] =
-                 {
-                        { "MTD_WRITEABLE", MTD_WRITEABLE },
-                        { "MTD_BIT_WRITEABLE", MTD_BIT_WRITEABLE },
-                        { NULL, -1 }
-                 };
+               {
+                       const char *name;
+                       int value;
+               } flags[] =
+               {
+                       { "MTD_WRITEABLE", MTD_WRITEABLE },
+                       { "MTD_BIT_WRITEABLE", MTD_BIT_WRITEABLE },
+                       { NULL, -1 }
+               };
                for (i = 0; flags[i].name != NULL; i++)
-                 if (mtd.flags & flags[i].value)
+                       if (mtd.flags & flags[i].value)
                        {
-                          if (first)
-                                {
+                               if (first)
+                               {
                                        printf (flags[i].name);
                                        first = 0;
-                                }
-                          else printf (" | %s",flags[i].name);
+                               }
+                               else printf (" | %s",flags[i].name);
                        }
-        }
-
-   printf ("\nmtd.size = ");
-   printsize (mtd.size);
-
-   printf ("\nmtd.erasesize = ");
-   printsize (mtd.erasesize);
-
-   printf ("\nmtd.writesize = ");
-   printsize (mtd.writesize);
-
-   printf ("\nmtd.oobsize = ");
-   printsize (mtd.oobsize);
-
-   printf ("\nmtd.ecctype = ");
-   switch (mtd.ecctype)
-        {
-         case MTD_ECC_NONE:
-               printf ("MTD_ECC_NONE");
-               break;
-         case MTD_ECC_RS_DiskOnChip:
-               printf ("MTD_ECC_RS_DiskOnChip");
-               break;
-         case MTD_ECC_SW:
-               printf ("MTD_ECC_SW");
-               break;
-         default:
-               printf ("(unknown ECC type - new MTD API maybe?)");
-        }
-
-   printf ("\n"
-                  "regions = %d\n"
-                  "\n",
-                  n);
-
-   for (i = 0; i < n; i++)
-        {
+       }
+
+       printf ("\nmtd.size = ");
+       printsize (mtd.size);
+
+       printf ("\nmtd.erasesize = ");
+       printsize (mtd.erasesize);
+
+       printf ("\nmtd.writesize = ");
+       printsize (mtd.writesize);
+
+       printf ("\nmtd.oobsize = ");
+       printsize (mtd.oobsize);
+
+       printf ("\nmtd.ecctype = ");
+       switch (mtd.ecctype)
+       {
+               case MTD_ECC_NONE:
+                       printf ("MTD_ECC_NONE");
+                       break;
+               case MTD_ECC_RS_DiskOnChip:
+                       printf ("MTD_ECC_RS_DiskOnChip");
+                       break;
+               case MTD_ECC_SW:
+                       printf ("MTD_ECC_SW");
+                       break;
+               default:
+                       printf ("(unknown ECC type - new MTD API maybe?)");
+       }
+
+       printf ("\n"
+                       "regions = %d\n"
+                       "\n",
+                       n);
+
+       for (i = 0; i < n; i++)
+       {
                printf ("region[%d].offset = 0x%.8x\n"
                                "region[%d].erasesize = ",
                                i,region[i].offset,i);
@@ -352,13 +351,13 @@ int showinfo (int fd)
                                "region[%d].regionindex = %d\n",
                                i,region[i].numblocks,
                                i,region[i].regionindex);
-        }
-   return (0);
+       }
+       return (0);
 }
 
 void showusage (const char *progname)
 {
-   fprintf (stderr,
+       fprintf (stderr,
                        "usage: %s info <device>\n"
                        "       %s read <device> <offset> <len> <dest-filename>\n"
                        "       %s write <device> <offset> <len> <source-filename>\n"
@@ -367,7 +366,7 @@ void showusage (const char *progname)
                        progname,
                        progname,
                        progname);
-   exit (1);
+       exit (1);
 }
 
 #define OPT_INFO       1
@@ -377,51 +376,51 @@ void showusage (const char *progname)
 
 int main (int argc,char *argv[])
 {
-   const char *progname;
-   int err = 0,fd,option = OPT_INFO;
-   int open_flag;
-   (progname = strrchr (argv[0],'/')) ? progname++ : (progname = argv[0]);
-
-   /* parse command-line options */
-   if (argc == 3 && !strcmp (argv[1],"info"))
-        option = OPT_INFO;
-   else if (argc == 6 && !strcmp (argv[1],"read"))
-        option = OPT_READ;
-   else if (argc == 6 && !strcmp (argv[1],"write"))
-        option = OPT_WRITE;
-   else if (argc == 5 && !strcmp (argv[1],"erase"))
-        option = OPT_ERASE;
-   else
-        showusage (progname);
-
-   /* open device */
-   open_flag = (option==OPT_INFO || option==OPT_READ) ? O_RDONLY : O_RDWR;
-   if ((fd = open (argv[2],O_SYNC | open_flag)) < 0)
-        {
+       const char *progname;
+       int err = 0,fd,option = OPT_INFO;
+       int open_flag;
+       (progname = strrchr (argv[0],'/')) ? progname++ : (progname = argv[0]);
+
+       /* parse command-line options */
+       if (argc == 3 && !strcmp (argv[1],"info"))
+               option = OPT_INFO;
+       else if (argc == 6 && !strcmp (argv[1],"read"))
+               option = OPT_READ;
+       else if (argc == 6 && !strcmp (argv[1],"write"))
+               option = OPT_WRITE;
+       else if (argc == 5 && !strcmp (argv[1],"erase"))
+               option = OPT_ERASE;
+       else
+               showusage (progname);
+
+       /* open device */
+       open_flag = (option==OPT_INFO || option==OPT_READ) ? O_RDONLY : O_RDWR;
+       if ((fd = open (argv[2],O_SYNC | open_flag)) < 0)
+       {
                perror ("open()");
                exit (1);
-        }
-
-   switch (option)
-        {
-         case OPT_INFO:
-               showinfo (fd);
-               break;
-         case OPT_READ:
-               err = flash_to_file (fd,strtol (argv[3],NULL,0),strtol (argv[4],NULL,0),argv[5]);
-               break;
-         case OPT_WRITE:
-               err = file_to_flash (fd,strtol (argv[3],NULL,0),strtol (argv[4],NULL,0),argv[5]);
-               break;
-         case OPT_ERASE:
-               err = erase_flash (fd,strtol (argv[3],NULL,0),strtol (argv[4],NULL,0));
-               break;
-        }
-
-   /* close device */
-   if (close (fd) < 0)
-        perror ("close()");
-
-   exit (err);
+       }
+
+       switch (option)
+       {
+               case OPT_INFO:
+                       showinfo (fd);
+                       break;
+               case OPT_READ:
+                       err = flash_to_file (fd,strtol (argv[3],NULL,0),strtol (argv[4],NULL,0),argv[5]);
+                       break;
+               case OPT_WRITE:
+                       err = file_to_flash (fd,strtol (argv[3],NULL,0),strtol (argv[4],NULL,0),argv[5]);
+                       break;
+               case OPT_ERASE:
+                       err = erase_flash (fd,strtol (argv[3],NULL,0),strtol (argv[4],NULL,0));
+                       break;
+       }
+
+       /* close device */
+       if (close (fd) < 0)
+               perror ("close()");
+
+       exit (err);
 }
 
index b2323f65e893a8e9531af260eaed445dd8122220..ab39c047ebf1b11749485e0e55365f33538265f1 100644 (file)
@@ -41,31 +41,31 @@ struct nand_oobinfo none_oobinfo = {
 void display_help (void)
 {
        printf("Usage: nanddump [OPTIONS] MTD-device\n"
-              "Dumps the contents of a nand mtd partition.\n"
-              "\n"
-              "           --help               display this help and exit\n"
-              "           --version            output version information and exit\n"
-              "-f file    --file=file          dump to file\n"
-              "-i         --ignoreerrors       ignore errors\n"
-              "-l length  --length=length      length\n"
-              "-n         --noecc              read without error correction\n"
-              "-o         --omitoob            omit oob data\n"
-              "-b         --omitbad            omit bad blocks from the dump\n"
-              "-p         --prettyprint        print nice (hexdump)\n"
-              "-s addr    --startaddress=addr  start address\n");
+                       "Dumps the contents of a nand mtd partition.\n"
+                       "\n"
+                       "           --help              display this help and exit\n"
+                       "           --version           output version information and exit\n"
+                       "-f file    --file=file          dump to file\n"
+                       "-i         --ignoreerrors       ignore errors\n"
+                       "-l length  --length=length      length\n"
+                       "-n         --noecc              read without error correction\n"
+                       "-o         --omitoob            omit oob data\n"
+                       "-b         --omitbad            omit bad blocks from the dump\n"
+                       "-p         --prettyprint        print nice (hexdump)\n"
+                       "-s addr    --startaddress=addr  start address\n");
        exit(0);
 }
 
 void display_version (void)
 {
        printf(PROGRAM " " VERSION "\n"
-              "\n"
-              PROGRAM " comes with NO WARRANTY\n"
-              "to the extent permitted by law.\n"
-              "\n"
-              "You may redistribute copies of " PROGRAM "\n"
-              "under the terms of the GNU General Public Licence.\n"
-              "See the file `COPYING' for more information.\n");
+                       "\n"
+                       PROGRAM " comes with NO WARRANTY\n"
+                       "to the extent permitted by law.\n"
+                       "\n"
+                       "You may redistribute copies of " PROGRAM "\n"
+                       "under the terms of the GNU General Public Licence.\n"
+                       "See the file `COPYING' for more information.\n");
        exit(0);
 }
 
@@ -102,52 +102,52 @@ void process_options (int argc, char *argv[])
                };
 
                int c = getopt_long(argc, argv, short_options,
-                                   long_options, &option_index);
+                               long_options, &option_index);
                if (c == EOF) {
                        break;
                }
 
                switch (c) {
-               case 0:
-                       switch (option_index) {
                        case 0:
-                               display_help();
+                               switch (option_index) {
+                                       case 0:
+                                               display_help();
+                                               break;
+                                       case 1:
+                                               display_version();
+                                               break;
+                               }
                                break;
-                       case 1:
-                               display_version();
+                       case 'b':
+                               omitbad = 1;
+                               break;
+                       case 's':
+                               start_addr = strtol(optarg, NULL, 0);
+                               break;
+                       case 'f':
+                               if (!(dumpfile = strdup(optarg))) {
+                                       perror("stddup");
+                                       exit(1);
+                               }
+                               break;
+                       case 'i':
+                               ignoreerrors = 1;
+                               break;
+                       case 'l':
+                               length = strtol(optarg, NULL, 0);
+                               break;
+                       case 'o':
+                               omitoob = 1;
+                               break;
+                       case 'p':
+                               pretty_print = 1;
+                               break;
+                       case 'n':
+                               noecc = 1;
+                               break;
+                       case '?':
+                               error = 1;
                                break;
-                       }
-                       break;
-               case 'b':
-                       omitbad = 1;
-                       break;
-               case 's':
-                       start_addr = strtol(optarg, NULL, 0);
-                       break;
-               case 'f':
-                       if (!(dumpfile = strdup(optarg))) {
-                               perror("stddup");
-                               exit(1);
-                       }
-                       break;
-               case 'i':
-                       ignoreerrors = 1;
-                       break;
-               case 'l':
-                       length = strtol(optarg, NULL, 0);
-                       break;
-               case 'o':
-                       omitoob = 1;
-                       break;
-               case 'p':
-                       pretty_print = 1;
-                       break;
-               case 'n':
-                       noecc = 1;
-                       break;
-               case '?':
-                       error = 1;
-                       break;
                }
        }
 
@@ -196,8 +196,8 @@ int main(int argc, char **argv)
 
        /* Make sure device page sizes are valid */
        if (!(meminfo.oobsize == 64 && meminfo.writesize == 2048) &&
-           !(meminfo.oobsize == 16 && meminfo.writesize == 512) &&
-           !(meminfo.oobsize == 8 && meminfo.writesize == 256)) {
+                       !(meminfo.oobsize == 16 && meminfo.writesize == 512) &&
+                       !(meminfo.oobsize == 8 && meminfo.writesize == 256)) {
                fprintf(stderr, "Unknown flash (not normal NAND)\n");
                close(fd);
                exit(1);
@@ -208,27 +208,27 @@ int main(int argc, char **argv)
        if (noecc)  {
                switch (ioctl(fd, MTDFILEMODE, (void *) MTD_MODE_RAW)) {
 
-               case -ENOTTY:
-                       if (ioctl (fd, MEMGETOOBSEL, &old_oobinfo) != 0) {
-                               perror ("MEMGETOOBSEL");
-                               close (fd);
-                               exit (1);
-                       }
-                       if (ioctl (fd, MEMSETOOBSEL, &none_oobinfo) != 0) {
-                               perror ("MEMSETOOBSEL");
+                       case -ENOTTY:
+                               if (ioctl (fd, MEMGETOOBSEL, &old_oobinfo) != 0) {
+                                       perror ("MEMGETOOBSEL");
+                                       close (fd);
+                                       exit (1);
+                               }
+                               if (ioctl (fd, MEMSETOOBSEL, &none_oobinfo) != 0) {
+                                       perror ("MEMSETOOBSEL");
+                                       close (fd);
+                                       exit (1);
+                               }
+                               oobinfochanged = 1;
+                               break;
+
+                       case 0:
+                               oobinfochanged = 2;
+                               break;
+                       default:
+                               perror ("MTDFILEMODE");
                                close (fd);
                                exit (1);
-                       }
-                       oobinfochanged = 1;
-                       break;
-
-               case 0:
-                       oobinfochanged = 2;
-                       break;
-               default:
-                       perror ("MTDFILEMODE");
-                       close (fd);
-                       exit (1);
                }
        } else {
 
@@ -263,10 +263,10 @@ int main(int argc, char **argv)
 
        /* Print informative message */
        fprintf(stderr, "Block size %u, page size %u, OOB size %u\n",
-               meminfo.erasesize, meminfo.writesize, meminfo.oobsize);
+                       meminfo.erasesize, meminfo.writesize, meminfo.oobsize);
        fprintf(stderr,
-               "Dumping data starting at 0x%08x and ending at 0x%08x...\n",
-               (unsigned int) start_addr, (unsigned int) end_addr);
+                       "Dumping data starting at 0x%08x and ending at 0x%08x...\n",
+                       (unsigned int) start_addr, (unsigned int) end_addr);
 
        /* Dump the flash contents */
        for (ofs = start_addr; ofs < end_addr ; ofs+=bs) {
@@ -300,12 +300,12 @@ int main(int argc, char **argv)
                        }
                        if (stat1.failed != stat2.failed)
                                fprintf(stderr, "ECC: %d uncorrectable bitflip(s)"
-                                       " at offset 0x%08lx\n",
-                                       stat2.failed - stat1.failed, ofs);
+                                               " at offset 0x%08lx\n",
+                                               stat2.failed - stat1.failed, ofs);
                        if (stat1.corrected != stat2.corrected)
                                fprintf(stderr, "ECC: %d corrected bitflip(s) at"
-                                       " offset 0x%08lx\n",
-                                       stat2.corrected - stat1.corrected, ofs);
+                                               " offset 0x%08lx\n",
+                                               stat2.corrected - stat1.corrected, ofs);
                        stat1 = stat2;
                }
 
@@ -313,17 +313,17 @@ int main(int argc, char **argv)
                if (pretty_print) {
                        for (i = 0; i < bs; i += 16) {
                                sprintf(pretty_buf,
-                                       "0x%08x: %02x %02x %02x %02x %02x %02x %02x "
-                                       "%02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
-                                       (unsigned int) (ofs + i),  readbuf[i],
-                                       readbuf[i+1], readbuf[i+2],
-                                       readbuf[i+3], readbuf[i+4],
-                                       readbuf[i+5], readbuf[i+6],
-                                       readbuf[i+7], readbuf[i+8],
-                                       readbuf[i+9], readbuf[i+10],
-                                       readbuf[i+11], readbuf[i+12],
-                                       readbuf[i+13], readbuf[i+14],
-                                       readbuf[i+15]);
+                                               "0x%08x: %02x %02x %02x %02x %02x %02x %02x "
+                                               "%02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
+                                               (unsigned int) (ofs + i),  readbuf[i],
+                                               readbuf[i+1], readbuf[i+2],
+                                               readbuf[i+3], readbuf[i+4],
+                                               readbuf[i+5], readbuf[i+6],
+                                               readbuf[i+7], readbuf[i+8],
+                                               readbuf[i+9], readbuf[i+10],
+                                               readbuf[i+11], readbuf[i+12],
+                                               readbuf[i+13], readbuf[i+14],
+                                               readbuf[i+15]);
                                write(ofd, pretty_buf, 60);
                        }
                } else
@@ -349,23 +349,23 @@ int main(int argc, char **argv)
                if (pretty_print) {
                        if (meminfo.oobsize < 16) {
                                sprintf(pretty_buf, "  OOB Data: %02x %02x %02x %02x %02x %02x "
-                                       "%02x %02x\n",
-                                       oobbuf[0], oobbuf[1], oobbuf[2],
-                                       oobbuf[3], oobbuf[4], oobbuf[5],
-                                       oobbuf[6], oobbuf[7]);
+                                               "%02x %02x\n",
+                                               oobbuf[0], oobbuf[1], oobbuf[2],
+                                               oobbuf[3], oobbuf[4], oobbuf[5],
+                                               oobbuf[6], oobbuf[7]);
                                write(ofd, pretty_buf, 48);
                                continue;
                        }
 
                        for (i = 0; i < meminfo.oobsize; i += 16) {
                                sprintf(pretty_buf, "  OOB Data: %02x %02x %02x %02x %02x %02x "
-                                       "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
-                                       oobbuf[i], oobbuf[i+1], oobbuf[i+2],
-                                       oobbuf[i+3], oobbuf[i+4], oobbuf[i+5],
-                                       oobbuf[i+6], oobbuf[i+7], oobbuf[i+8],
-                                       oobbuf[i+9], oobbuf[i+10], oobbuf[i+11],
-                                       oobbuf[i+12], oobbuf[i+13], oobbuf[i+14],
-                                       oobbuf[i+15]);
+                                               "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
+                                               oobbuf[i], oobbuf[i+1], oobbuf[i+2],
+                                               oobbuf[i+3], oobbuf[i+4], oobbuf[i+5],
+                                               oobbuf[i+6], oobbuf[i+7], oobbuf[i+8],
+                                               oobbuf[i+9], oobbuf[i+10], oobbuf[i+11],
+                                               oobbuf[i+12], oobbuf[i+13], oobbuf[i+14],
+                                               oobbuf[i+15]);
                                write(ofd, pretty_buf, 60);
                        }
                } else
@@ -388,7 +388,7 @@ int main(int argc, char **argv)
        /* Exit happy */
        return 0;
 
- closeall:
+closeall:
        /* The new mode change is per file descriptor ! */
        if (oobinfochanged == 1) {
                if (ioctl (fd, MEMSETOOBSEL, &old_oobinfo) != 0)  {
index 037474afca5596a842ad37e12d6bb387529c9e62..f4c399d5396ddc99c071ca993a6b7099d94d3d66 100644 (file)
@@ -75,35 +75,35 @@ struct nand_oobinfo autoplace_oobinfo = {
 void display_help (void)
 {
        printf("Usage: nandwrite [OPTION] MTD_DEVICE INPUTFILE\n"
-              "Writes to the specified MTD device.\n"
-              "\n"
-              "  -a, --autoplace       Use auto oob layout\n"
-              "  -j, --jffs2           force jffs2 oob layout (legacy support)\n"
-              "  -y, --yaffs           force yaffs oob layout (legacy support)\n"
-              "  -f, --forcelegacy     force legacy support on autoplacement enabled mtd device\n"
-              "  -n, --noecc           write without ecc\n"
-              "  -o, --oob             image contains oob data\n"
-              "  -s addr, --start=addr set start address (default is 0)\n"
-              "  -p, --pad             pad to page size\n"
-              "  -b, --blockalign=1|2|4 set multiple of eraseblocks to align to\n"
-              "  -q, --quiet           don't display progress messages\n"
-              "      --help            display this help and exit\n"
-              "      --version         output version information and exit\n");
+                       "Writes to the specified MTD device.\n"
+                       "\n"
+                       "  -a, --autoplace      Use auto oob layout\n"
+                       "  -j, --jffs2          force jffs2 oob layout (legacy support)\n"
+                       "  -y, --yaffs          force yaffs oob layout (legacy support)\n"
+                       "  -f, --forcelegacy     force legacy support on autoplacement enabled mtd device\n"
+                       "  -n, --noecc          write without ecc\n"
+                       "  -o, --oob            image contains oob data\n"
+                       "  -s addr, --start=addr set start address (default is 0)\n"
+                       "  -p, --pad             pad to page size\n"
+                       "  -b, --blockalign=1|2|4 set multiple of eraseblocks to align to\n"
+                       "  -q, --quiet          don't display progress messages\n"
+                       "      --help           display this help and exit\n"
+                       "      --version                output version information and exit\n");
        exit(0);
 }
 
 void display_version (void)
 {
        printf(PROGRAM " " VERSION "\n"
-              "\n"
-              "Copyright (C) 2003 Thomas Gleixner \n"
-              "\n"
-              PROGRAM " comes with NO WARRANTY\n"
-              "to the extent permitted by law.\n"
-              "\n"
-              "You may redistribute copies of " PROGRAM "\n"
-              "under the terms of the GNU General Public Licence.\n"
-              "See the file `COPYING' for more information.\n");
+                       "\n"
+                       "Copyright (C) 2003 Thomas Gleixner \n"
+                       "\n"
+                       PROGRAM " comes with NO WARRANTY\n"
+                       "to the extent permitted by law.\n"
+                       "\n"
+                       "You may redistribute copies of " PROGRAM "\n"
+                       "under the terms of the GNU General Public Licence.\n"
+                       "See the file `COPYING' for more information.\n");
        exit(0);
 }
 
@@ -143,55 +143,55 @@ void process_options (int argc, char *argv[])
                };
 
                int c = getopt_long(argc, argv, short_options,
-                                   long_options, &option_index);
+                               long_options, &option_index);
                if (c == EOF) {
                        break;
                }
 
                switch (c) {
-               case 0:
-                       switch (option_index) {
                        case 0:
-                               display_help();
+                               switch (option_index) {
+                                       case 0:
+                                               display_help();
+                                               break;
+                                       case 1:
+                                               display_version();
+                                               break;
+                               }
                                break;
-                       case 1:
-                               display_version();
+                       case 'q':
+                               quiet = 1;
+                               break;
+                       case 'a':
+                               autoplace = 1;
+                               break;
+                       case 'j':
+                               forcejffs2 = 1;
+                               break;
+                       case 'y':
+                               forceyaffs = 1;
+                               break;
+                       case 'f':
+                               forcelegacy = 1;
+                               break;
+                       case 'n':
+                               noecc = 1;
+                               break;
+                       case 'o':
+                               writeoob = 1;
+                               break;
+                       case 'p':
+                               pad = 1;
+                               break;
+                       case 's':
+                               mtdoffset = strtol (optarg, NULL, 0);
+                               break;
+                       case 'b':
+                               blockalign = atoi (optarg);
+                               break;
+                       case '?':
+                               error = 1;
                                break;
-                       }
-                       break;
-               case 'q':
-                       quiet = 1;
-                       break;
-               case 'a':
-                       autoplace = 1;
-                       break;
-               case 'j':
-                       forcejffs2 = 1;
-                       break;
-               case 'y':
-                       forceyaffs = 1;
-                       break;
-               case 'f':
-                       forcelegacy = 1;
-                       break;
-               case 'n':
-                       noecc = 1;
-                       break;
-               case 'o':
-                       writeoob = 1;
-                       break;
-               case 'p':
-                       pad = 1;
-                       break;
-               case 's':
-                       mtdoffset = strtol (optarg, NULL, 0);
-                       break;
-               case 'b':
-                       blockalign = atoi (optarg);
-                       break;
-               case '?':
-                       error = 1;
-                       break;
                }
        }
 
@@ -243,8 +243,8 @@ int main(int argc, char **argv)
 
        /* Make sure device page sizes are valid */
        if (!(meminfo.oobsize == 16 && meminfo.writesize == 512) &&
-           !(meminfo.oobsize == 8 && meminfo.writesize == 256) &&
-           !(meminfo.oobsize == 64 && meminfo.writesize == 2048)) {
+                       !(meminfo.oobsize == 8 && meminfo.writesize == 256) &&
+                       !(meminfo.oobsize == 64 && meminfo.writesize == 2048)) {
                fprintf(stderr, "Unknown flash (not normal NAND)\n");
                close(fd);
                exit(1);
@@ -273,27 +273,27 @@ int main(int argc, char **argv)
        if (noecc)  {
                switch (ioctl(fd, MTDFILEMODE, (void *) MTD_MODE_RAW)) {
 
-               case -ENOTTY:
-                       if (ioctl (fd, MEMGETOOBSEL, &old_oobinfo) != 0) {
-                               perror ("MEMGETOOBSEL");
-                               close (fd);
-                               exit (1);
-                       }
-                       if (ioctl (fd, MEMSETOOBSEL, &none_oobinfo) != 0) {
-                               perror ("MEMSETOOBSEL");
+                       case -ENOTTY:
+                               if (ioctl (fd, MEMGETOOBSEL, &old_oobinfo) != 0) {
+                                       perror ("MEMGETOOBSEL");
+                                       close (fd);
+                                       exit (1);
+                               }
+                               if (ioctl (fd, MEMSETOOBSEL, &none_oobinfo) != 0) {
+                                       perror ("MEMSETOOBSEL");
+                                       close (fd);
+                                       exit (1);
+                               }
+                               oobinfochanged = 1;
+                               break;
+
+                       case 0:
+                               oobinfochanged = 2;
+                               break;
+                       default:
+                               perror ("MTDFILEMODE");
                                close (fd);
                                exit (1);
-                       }
-                       oobinfochanged = 1;
-                       break;
-
-               case 0:
-                       oobinfochanged = 2;
-                       break;
-               default:
-                       perror ("MTDFILEMODE");
-                       close (fd);
-                       exit (1);
                }
        }
 
@@ -381,8 +381,8 @@ int main(int argc, char **argv)
                                        baderaseblock = 1;
                                        if (!quiet)
                                                fprintf (stderr, "Bad block at %x, %u block(s) "
-                                                        "from %x will be skipped\n",
-                                                        (int) offs, blockalign, blockstart);
+                                                               "from %x will be skipped\n",
+                                                               (int) offs, blockalign, blockstart);
                                }
 
                                if (baderaseblock) {
@@ -429,16 +429,16 @@ int main(int argc, char **argv)
                                                start = old_oobinfo.oobfree[i][0];
                                                len = old_oobinfo.oobfree[i][1];
                                                memcpy(oobbuf + start,
-                                                       oobreadbuf + start,
-                                                       len);
+                                                               oobreadbuf + start,
+                                                               len);
                                        }
                                } else {
                                        /* Set at least the ecc byte positions to 0xff */
                                        start = old_oobinfo.eccbytes;
                                        len = meminfo.oobsize - start;
                                        memcpy(oobbuf + start,
-                                               oobreadbuf + start,
-                                               len);
+                                                       oobreadbuf + start,
+                                                       len);
                                }
                        }
                        /* Write OOB data first, as ecc will be placed in there*/
@@ -459,10 +459,10 @@ int main(int argc, char **argv)
                mtdoffset += meminfo.writesize;
        }
 
- closeall:
+closeall:
        close(ifd);
 
- restoreoob:
+restoreoob:
        if (oobinfochanged == 1) {
                if (ioctl (fd, MEMSETOOBSEL, &old_oobinfo) != 0) {
                        perror ("MEMSETOOBSEL");
index b0a80cff7439118cf5b59387647219e27d1c0086..4861753a0162db95865823df68efa9fc3ee24987 100644 (file)
@@ -212,26 +212,26 @@ int main(int argc, char **argv)
        printf("$Id: nftl_format.c,v 1.24 2005/11/07 11:15:13 gleixner Exp $\n");
 
        if (argc < 2)
-               usage(1);
+               usage(1);
 
        nftl = "NFTL";
 
        while ((c = getopt(argc, argv, "?hib")) > 0) {
                switch (c) {
-               case 'i':
-                       nftl = "INFTL";
-                       do_inftl = 1;
-                       break;
-               case 'b':
-                       do_bbt = 1;
-                       break;
-               case 'h':
-               case '?':
-                       usage(0);
-                       break;
-               default:
-                       usage(1);
-                       break;
+                       case 'i':
+                               nftl = "INFTL";
+                               do_inftl = 1;
+                               break;
+                       case 'b':
+                               do_bbt = 1;
+                               break;
+                       case 'h':
+                       case '?':
+                               usage(0);
+                               break;
+                       default:
+                               usage(1);
+                               break;
                }
        }
 
@@ -256,16 +256,16 @@ int main(int argc, char **argv)
        }
 
        switch (meminfo.erasesize) {
-       case 0x1000:
-       case 0x2000:
-       case 0x4000:
-       case 0x8000:
-               break;
-       default:
-               printf("Unrecognized Erase size, 0x%x - I'm confused\n",
-                       meminfo.erasesize);
-               close(fd);
-               return 1;
+               case 0x1000:
+               case 0x2000:
+               case 0x4000:
+               case 0x8000:
+                       break;
+               default:
+                       printf("Unrecognized Erase size, 0x%x - I'm confused\n",
+                                       meminfo.erasesize);
+                       close(fd);
+                       return 1;
        }
        writebuf[0] = malloc(meminfo.erasesize * 5);
        if (!writebuf[0]) {
@@ -307,9 +307,9 @@ int main(int argc, char **argv)
        /* Phase 1. Erasing and checking each erase zones in the NFTL partition.
           N.B. Erase Zones not used by the NFTL partition are untouched and marked ZONE_GOOD */
        printf("Phase 1. Checking and erasing Erase Zones from 0x%08lx to 0x%08lx\n",
-              startofs, startofs + part_size);
+                       startofs, startofs + part_size);
        for (ezone = startofs / meminfo.erasesize;
-            ezone < (ezones + startofs / meminfo.erasesize); ezone++) {
+                       ezone < (ezones + startofs / meminfo.erasesize); ezone++) {
                if (BadUnitTable[ezone] != ZONE_GOOD)
                        continue;
                if ((BadUnitTable[ezone] = erase_block(ezone)) == ZONE_GOOD) {
@@ -380,7 +380,7 @@ int main(int argc, char **argv)
        pwrite(fd, writebuf[0], 512, MediaUnit1 * meminfo.erasesize + MediaUnitOff1);
        for (ezone = 0; ezone < (meminfo.size / meminfo.erasesize); ezone += 512) {
                pwrite(fd, BadUnitTable + ezone, 512,
-                       (MediaUnit1 * meminfo.erasesize) + 512 * (1 + ezone / 512));
+                               (MediaUnit1 * meminfo.erasesize) + 512 * (1 + ezone / 512));
        }
 
 #if 0
@@ -388,13 +388,13 @@ int main(int argc, char **argv)
        printf("    NumEraseUnits: %d\n", le16_to_cpu(NFTLhdr->NumEraseUnits));
        printf("    FirstPhysicalEUN: %d\n", le16_to_cpu(NFTLhdr->FirstPhysicalEUN));
        printf("    FormattedSize: %d (%d sectors)\n", le32_to_cpu(NFTLhdr->FormattedSize),
-              le32_to_cpu(NFTLhdr->FormattedSize)/512);
+                       le32_to_cpu(NFTLhdr->FormattedSize)/512);
 #endif
        printf("Phase 2.b Writing Spare %s Media Header and Spare Bad Unit Table\n", nftl);
        pwrite(fd, writebuf[0], 512, MediaUnit2 * meminfo.erasesize + MediaUnitOff2);
        for (ezone = 0; ezone < (meminfo.size / meminfo.erasesize); ezone += 512) {
                pwrite(fd, BadUnitTable + ezone, 512,
-                       (MediaUnit2 * meminfo.erasesize + MediaUnitOff2) + 512 * (1 + ezone / 512));
+                               (MediaUnit2 * meminfo.erasesize + MediaUnitOff2) + 512 * (1 + ezone / 512));
        }
 
        /* UCI #1 for newly erased Erase Unit */
index 59aa7d77b2f498898119b8b46b089969bb633718..5b293db9de9ecf7c68c5184a1a651a70ce05d9a4 100644 (file)
@@ -88,13 +88,13 @@ static unsigned int find_media_headers(void)
                        if (NumMedHeads == 0) {
                                printf("NFTL Media Header found at offset 0x%08lx:\n", ofs);
                                printf("NumEraseUnits:    %d\n",
-                                      MedHead[NumMedHeads].NumEraseUnits);
+                                               MedHead[NumMedHeads].NumEraseUnits);
                                printf("FirstPhysicalEUN: %d\n",
-                                      MedHead[NumMedHeads].FirstPhysicalEUN);
+                                               MedHead[NumMedHeads].FirstPhysicalEUN);
                                printf("Formatted Size:   %d\n",
-                                      MedHead[NumMedHeads].FormattedSize);
+                                               MedHead[NumMedHeads].FormattedSize);
                                printf("UnitSizeFactor:   0x%x\n",
-                                      MedHead[NumMedHeads].UnitSizeFactor);
+                                               MedHead[NumMedHeads].UnitSizeFactor);
 
                                /* read BadUnitTable, I don't know why pread() does not work for
                                   larger (7680 bytes) chunks */
@@ -109,7 +109,7 @@ static unsigned int find_media_headers(void)
                if (NumMedHeads == 2) {
                        if (strncmp((char *)&MedHead[0], (char *)&MedHead[1], sizeof(struct NFTLMediaHeader)) != 0) {
                                printf("warning: NFTL Media Header is not consistent with "
-                                      "Spare NFTL Media Header\n");
+                                               "Spare NFTL Media Header\n");
                        }
                        break;
                }
@@ -126,7 +126,7 @@ static void dump_erase_units(void)
        unsigned long ofs;
 
        for (i = MedHead[0].FirstPhysicalEUN; i < MedHead[0].FirstPhysicalEUN +
-                    MedHead[0].NumEraseUnits; i++) {
+                       MedHead[0].NumEraseUnits; i++) {
                /* For each Erase Unit */
                ofs = i * meminfo.erasesize;
 
@@ -135,12 +135,12 @@ static void dump_erase_units(void)
                        oob.start = ofs + (j * 512);
                        if (ioctl(fd, MEMREADOOB, &oob))
                                printf("MEMREADOOB at %lx: %s\n",
-                                      (unsigned long) oob.start, strerror(errno));
+                                               (unsigned long) oob.start, strerror(errno));
                        memcpy(&UCItable[i][j], &oobbuf.u, 8);
                }
                if (UCItable[i][1].b.EraseMark != cpu_to_le16(0x3c69)) {
                        printf("EraseMark not present in unit %d: %x\n",
-                              i, UCItable[i][1].b.EraseMark);
+                                       i, UCItable[i][1].b.EraseMark);
                } else {
                        /* a properly formatted unit */
                        SWAP16(UCItable[i][0].a.VirtUnitNum);
@@ -157,21 +157,21 @@ static void dump_erase_units(void)
                                /* If this is the first in a chain, store the EUN in the VUC table */
                                if (VUCtable[UCItable[i][0].a.VirtUnitNum & 0x7fff]) {
                                        printf("Duplicate start of chain for VUC %d: "
-                                              "Unit %d replaces Unit %d\n",
-                                              UCItable[i][0].a.VirtUnitNum & 0x7fff,
-                                              i, VUCtable[UCItable[i][0].a.VirtUnitNum & 0x7fff]);
+                                                       "Unit %d replaces Unit %d\n",
+                                                       UCItable[i][0].a.VirtUnitNum & 0x7fff,
+                                                       i, VUCtable[UCItable[i][0].a.VirtUnitNum & 0x7fff]);
                                }
                                VUCtable[UCItable[i][0].a.VirtUnitNum & 0x7fff] = i;
                        }
                }
 
                switch (BadUnitTable[i]) {
-               case ZONE_BAD_ORIGINAL:
-                       printf("Unit %d is marked as ZONE_BAD_ORIGINAL\n", i);
-                       continue;
-               case ZONE_BAD_MARKED:
-                       printf("Unit %d is marked as ZONE_BAD_MARKED\n", i);
-                       continue;
+                       case ZONE_BAD_ORIGINAL:
+                               printf("Unit %d is marked as ZONE_BAD_ORIGINAL\n", i);
+                               continue;
+                       case ZONE_BAD_MARKED:
+                               printf("Unit %d is marked as ZONE_BAD_MARKED\n", i);
+                               continue;
                }
 
                /* ZONE_GOOD */
@@ -179,8 +179,8 @@ static void dump_erase_units(void)
                        printf("Unit %d is free\n", i);
                else
                        printf("Unit %d is in chain %d and %s a replacement\n", i,
-                              UCItable[i][0].a.VirtUnitNum & 0x7fff,
-                              UCItable[i][0].a.VirtUnitNum & 0x8000 ? "is" : "is not");
+                                       UCItable[i][0].a.VirtUnitNum & 0x7fff,
+                                       UCItable[i][0].a.VirtUnitNum & 0x8000 ? "is" : "is not");
        }
 }
 
@@ -189,7 +189,7 @@ static void dump_virtual_units(void)
        int i, j;
        char readbuf[512];
 
-       for (i = 0; i < (MedHead[0].FormattedSize / meminfo.erasesize); i++) {
+       for (i = 0; i < (MedHead[0].FormattedSize / meminfo.erasesize); i++) {
                unsigned short curEUN = VUCtable[i];
 
                printf("Virtual Unit #%d: ", i);
@@ -220,15 +220,15 @@ static void dump_virtual_units(void)
                                        status = oobbuf.b.Status | oobbuf.b.Status1;
 
                                        switch (status) {
-                                       case SECTOR_FREE:
-                                               /* This is still free. Don't look any more */
-                                               thisEUN = 0;
-                                               break;
-
-                                       case SECTOR_USED:
-                                               /* SECTOR_USED. This is a good one. */
-                                               lastgoodEUN = thisEUN;
-                                               break;
+                                               case SECTOR_FREE:
+                                                       /* This is still free. Don't look any more */
+                                                       thisEUN = 0;
+                                                       break;
+
+                                               case SECTOR_USED:
+                                                       /* SECTOR_USED. This is a good one. */
+                                                       lastgoodEUN = thisEUN;
+                                                       break;
                                        }
 
                                        /* Find the next erase unit in this chain, if any */
@@ -240,7 +240,7 @@ static void dump_virtual_units(void)
                                        memset(readbuf, 0, 512);
                                else
                                        pread(fd, readbuf, 512,
-                                             (lastgoodEUN * ERASESIZE) + (j * 512));
+                                                       (lastgoodEUN * ERASESIZE) + (j * 512));
 
                                write(ofd, readbuf, 512);
                        }
index d939dbefa224c2b67d01be22f0e32a32dc50ebe6..09c29f23a1f6d5c733ce0527136afaba59af4623 100644 (file)
--- a/rfddump.c
+++ b/rfddump.c
@@ -59,23 +59,23 @@ struct rfd {
 void display_help(void)
 {
        printf("Usage: " PROGRAM " [OPTIONS] MTD-device filename\n"
-              "Dumps the contents of a resident flash disk\n"
-              "\n"
-              "-h         --help               display this help and exit\n"
-              "-V         --version            output version information and exit\n"
-              "-v         --verbose            Be verbose\n"
-              "-b size    --blocksize          Block size (defaults to erase unit)\n");
+                       "Dumps the contents of a resident flash disk\n"
+                       "\n"
+                       "-h         --help               display this help and exit\n"
+                       "-V         --version            output version information and exit\n"
+                       "-v         --verbose           Be verbose\n"
+                       "-b size    --blocksize          Block size (defaults to erase unit)\n");
        exit(0);
 }
 
 void display_version(void)
 {
-        printf(PROGRAM " " VERSION "\n"
-               "\n"
-              "This is free software; see the source for copying conditions.  There is NO\n"
-              "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
+       printf(PROGRAM " " VERSION "\n"
+                       "\n"
+                       "This is free software; see the source for copying conditions.  There is NO\n"
+                       "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
 
-        exit(0);
+       exit(0);
 }
 
 void process_options(int argc, char *argv[], struct rfd *rfd)
@@ -102,21 +102,21 @@ void process_options(int argc, char *argv[], struct rfd *rfd)
                        break;
 
                switch (c) {
-               case 'h':
-                       display_help();
-                       break;
-               case 'V':
-                       display_version();
-                       break;
-               case 'v':
-                       rfd->verbose = 1;
-                       break;
-               case 'b':
-                       rfd->block_size = atoi(optarg);
-                       break;
-               case '?':
-                       error = 1;
-                       break;
+                       case 'h':
+                               display_help();
+                               break;
+                       case 'V':
+                               display_version();
+                               break;
+                       case 'v':
+                               rfd->verbose = 1;
+                               break;
+                       case 'b':
+                               rfd->block_size = atoi(optarg);
+                               break;
+                       case '?':
+                               error = 1;
+                               break;
                }
        }
 
@@ -156,13 +156,13 @@ int build_block_map(struct rfd *rfd, int fd, int block)
 
                if (entry >= rfd->sector_count) {
                        fprintf(stderr, "%s: warning: sector %d out of range\n",
-                               rfd->mtd_filename, entry);
+                                       rfd->mtd_filename, entry);
                        continue;
                }
 
                if (rfd->sector_map[entry] != -1) {
                        fprintf(stderr, "%s: warning: more than one entry "
-                               "for sector %d\n", rfd->mtd_filename, entry);
+                                       "for sector %d\n", rfd->mtd_filename, entry);
                        continue;
                }
 
@@ -239,8 +239,8 @@ int main(int argc, char *argv[])
        }
 
        rfd.header_sectors =
-                ((HEADER_MAP_OFFSET + sectors_per_block) *
-                  sizeof(uint16_t) + SECTOR_SIZE - 1) / SECTOR_SIZE;
+               ((HEADER_MAP_OFFSET + sectors_per_block) *
+                sizeof(uint16_t) + SECTOR_SIZE - 1) / SECTOR_SIZE;
        rfd.data_sectors = sectors_per_block - rfd.header_sectors;
        cylinders = ((rfd.block_count - 1) * rfd.data_sectors - 1)
                / SECTORS_PER_TRACK;
index dbe122984b29a753ae0e49eb57060c0ef0b8cca8..aa0f01cbfe38063d8ee084327ac8e8b05131ae4d 100644 (file)
 void display_help(void)
 {
        printf("Usage: " PROGRAM " [OPTIONS] MTD-device\n"
-              "Formats NOR flash for resident flash disk\n"
-              "\n"
-              "-h         --help               display this help and exit\n"
-              "-V         --version            output version information and exit\n");
+                       "Formats NOR flash for resident flash disk\n"
+                       "\n"
+                       "-h         --help               display this help and exit\n"
+                       "-V         --version            output version information and exit\n");
        exit(0);
 }
 
 void display_version(void)
 {
-        printf(PROGRAM " " VERSION "\n"
-               "\n"
-              "This is free software; see the source for copying conditions.  There is NO\n"
-              "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
+       printf(PROGRAM " " VERSION "\n"
+                       "\n"
+                       "This is free software; see the source for copying conditions.  There is NO\n"
+                       "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
 
-        exit(0);
+       exit(0);
 }
 
 void process_options(int argc, char *argv[], const char **mtd_filename)
@@ -70,15 +70,15 @@ void process_options(int argc, char *argv[], const char **mtd_filename)
                        break;
 
                switch (c) {
-               case 'h':
-                       display_help();
-                       break;
-               case 'V':
-                       display_version();
-                       break;
-               case '?':
-                       error = 1;
-                       break;
+                       case 'h':
+                               display_help();
+                               break;
+                       case 'V':
+                               display_version();
+                               break;
+                       case '?':
+                               error = 1;
+                               break;
                }
        }
 
index 5715b1f7aa4b9066b975941d483dc7a202096592..93e577aceab0157a6f579e37e323c30ad4e48abc 100644 (file)
--- a/summary.h
+++ b/summary.h
 #include <linux/jffs2.h>
 
 #define DIRTY_SPACE(x) do { typeof(x) _x = (x); \
-               c->free_size -= _x; c->dirty_size += _x; \
-               jeb->free_size -= _x ; jeb->dirty_size += _x; \
-               }while(0)
+       c->free_size -= _x; c->dirty_size += _x; \
+       jeb->free_size -= _x ; jeb->dirty_size += _x; \
+}while(0)
 #define USED_SPACE(x) do { typeof(x) _x = (x); \
-               c->free_size -= _x; c->used_size += _x; \
-               jeb->free_size -= _x ; jeb->used_size += _x; \
-               }while(0)
+       c->free_size -= _x; c->used_size += _x; \
+       jeb->free_size -= _x ; jeb->used_size += _x; \
+}while(0)
 #define WASTED_SPACE(x) do { typeof(x) _x = (x); \
-               c->free_size -= _x; c->wasted_size += _x; \
-               jeb->free_size -= _x ; jeb->wasted_size += _x; \
-               }while(0)
+       c->free_size -= _x; c->wasted_size += _x; \
+       jeb->free_size -= _x ; jeb->wasted_size += _x; \
+}while(0)
 #define UNCHECKED_SPACE(x) do { typeof(x) _x = (x); \
-               c->free_size -= _x; c->unchecked_size += _x; \
-               jeb->free_size -= _x ; jeb->unchecked_size += _x; \
-               }while(0)
+       c->free_size -= _x; c->unchecked_size += _x; \
+       jeb->free_size -= _x ; jeb->unchecked_size += _x; \
+}while(0)
 
 #define BLK_STATE_ALLFF                0
 #define BLK_STATE_CLEAN                1
index cb8739da024d82f613e358a43a78cc4144412bda..92d6584a72a15e481cbf60297b1770a0348efe45 100644 (file)
--- a/sumtool.c
+++ b/sumtool.c
@@ -91,27 +91,27 @@ static struct option long_options[] = {
 };
 
 static char *helptext =
-       "Usage: sumtool [OPTIONS] -i inputfile -o outputfile\n\n"
-       "Convert the input JFFS2 image to a summarized JFFS2 image\n"
-       "Summary makes mounting faster - if summary support enabled in your kernel\n\n"
-       "Options:\n"
-       "  -e, --eraseblock=SIZE     Use erase block size SIZE (default: 64KiB)\n"
-       "                            (usually 16KiB on NAND)\n"
-       "  -c, --cleanmarker=SIZE    Size of cleanmarker (default 12).\n"
-       "                            (usually 16 bytes on NAND, and will be set to\n"
-       "                            this value if left at the default 12). Will be\n"
-       "                            stored in OOB after each physical page composing\n"
-       "                            a physical eraseblock.\n"
-       "  -n, --no-cleanmarkers     Don't add a cleanmarker to every eraseblock\n"
-       "  -o, --output=FILE         Output to FILE \n"
-       "  -i, --input=FILE          Input from FILE \n"
-       "  -b, --bigendian           Image is big endian\n"
-       "  -l  --littleendian        Image is little endian\n"
-       "  -h, --help                Display this help text\n"
-       "  -v, --verbose             Verbose operation\n"
-       "  -V, --version             Display version information\n"
-       "  -p, --pad                 Pad the OUTPUT with 0xFF to the end of the final\n"
-       "                            eraseblock\n\n";
+"Usage: sumtool [OPTIONS] -i inputfile -o outputfile\n\n"
+"Convert the input JFFS2 image to a summarized JFFS2 image\n"
+"Summary makes mounting faster - if summary support enabled in your kernel\n\n"
+"Options:\n"
+"  -e, --eraseblock=SIZE     Use erase block size SIZE (default: 64KiB)\n"
+"                            (usually 16KiB on NAND)\n"
+"  -c, --cleanmarker=SIZE    Size of cleanmarker (default 12).\n"
+"                            (usually 16 bytes on NAND, and will be set to\n"
+"                            this value if left at the default 12). Will be\n"
+"                            stored in OOB after each physical page composing\n"
+"                            a physical eraseblock.\n"
+"  -n, --no-cleanmarkers     Don't add a cleanmarker to every eraseblock\n"
+"  -o, --output=FILE         Output to FILE \n"
+"  -i, --input=FILE          Input from FILE \n"
+"  -b, --bigendian           Image is big endian\n"
+"  -l  --littleendian        Image is little endian\n"
+"  -h, --help                Display this help text\n"
+"  -v, --verbose             Verbose operation\n"
+"  -V, --version             Display version information\n"
+"  -p, --pad                 Pad the OUTPUT with 0xFF to the end of the final\n"
+"                            eraseblock\n\n";
 
 
 static char *revtext = "$Revision: 1.9 $";
@@ -212,58 +212,58 @@ void process_options (int argc, char **argv)
                                                (int) strlen(revtext) - 13, revtext + 11);
 
                        case 'e': {
-                               char *next;
-                               unsigned units = 0;
-                               erase_block_size = strtol(optarg, &next, 0);
-                               if (!erase_block_size)
-                                       error_msg_and_die("Unrecognisable erase size\n");
-
-                               if (*next) {
-                                       if (!strcmp(next, "KiB")) {
-                                               units = 1024;
-                                       } else if (!strcmp(next, "MiB")) {
-                                               units = 1024 * 1024;
-                                       } else {
-                                               error_msg_and_die("Unknown units in erasesize\n");
-                                       }
-                               } else {
-                                       if (erase_block_size < 0x1000)
-                                               units = 1024;
-                                       else
-                                               units = 1;
-                               }
-                               erase_block_size *= units;
-
-                               /* If it's less than 8KiB, they're not allowed */
-                               if (erase_block_size < 0x2000) {
-                                       fprintf(stderr, "Erase size 0x%x too small. Increasing to 8KiB minimum\n",
-                                               erase_block_size);
-                                       erase_block_size = 0x2000;
-                               }
-                               break;
-                       }
+                                                 char *next;
+                                                 unsigned units = 0;
+                                                 erase_block_size = strtol(optarg, &next, 0);
+                                                 if (!erase_block_size)
+                                                         error_msg_and_die("Unrecognisable erase size\n");
+
+                                                 if (*next) {
+                                                         if (!strcmp(next, "KiB")) {
+                                                                 units = 1024;
+                                                         } else if (!strcmp(next, "MiB")) {
+                                                                 units = 1024 * 1024;
+                                                         } else {
+                                                                 error_msg_and_die("Unknown units in erasesize\n");
+                                                         }
+                                                 } else {
+                                                         if (erase_block_size < 0x1000)
+                                                                 units = 1024;
+                                                         else
+                                                                 units = 1;
+                                                 }
+                                                 erase_block_size *= units;
+
+                                                 /* If it's less than 8KiB, they're not allowed */
+                                                 if (erase_block_size < 0x2000) {
+                                                         fprintf(stderr, "Erase size 0x%x too small. Increasing to 8KiB minimum\n",
+                                                                         erase_block_size);
+                                                         erase_block_size = 0x2000;
+                                                 }
+                                                 break;
+                                         }
 
                        case 'n':
-                               add_cleanmarkers = 0;
-                               break;
+                                         add_cleanmarkers = 0;
+                                         break;
                        case 'c':
-                               cleanmarker_size = strtol(optarg, NULL, 0);
+                                         cleanmarker_size = strtol(optarg, NULL, 0);
 
-                               if (cleanmarker_size < sizeof(cleanmarker)) {
-                                       error_msg_and_die("cleanmarker size must be >= 12");
-                               }
-                               if (cleanmarker_size >= erase_block_size) {
-                                       error_msg_and_die("cleanmarker size must be < eraseblock size");
-                               }
+                                         if (cleanmarker_size < sizeof(cleanmarker)) {
+                                                 error_msg_and_die("cleanmarker size must be >= 12");
+                                         }
+                                         if (cleanmarker_size >= erase_block_size) {
+                                                 error_msg_and_die("cleanmarker size must be < eraseblock size");
+                                         }
 
-                               use_input_cleanmarker_size = 0;
-                               found_cleanmarkers = 1;
-                               setup_cleanmarker();
+                                         use_input_cleanmarker_size = 0;
+                                         found_cleanmarkers = 1;
+                                         setup_cleanmarker();
 
-                               break;
+                                         break;
                        case 'p':
-                               padto = 1;
-                               break;
+                                         padto = 1;
+                                         break;
                }
        }
 }
@@ -412,63 +412,63 @@ void dump_sum_records()
                switch(je16_to_cpu(sum_collected->sum_list_head->u.nodetype)) {
 
                        case JFFS2_NODETYPE_INODE : {
-                               struct jffs2_sum_inode_flash *sino_ptr = wpage;
+                                                                                       struct jffs2_sum_inode_flash *sino_ptr = wpage;
 
-                               sino_ptr->nodetype = sum_collected->sum_list_head->i.nodetype;
-                               sino_ptr->inode = sum_collected->sum_list_head->i.inode;
-                               sino_ptr->version = sum_collected->sum_list_head->i.version;
-                               sino_ptr->offset = sum_collected->sum_list_head->i.offset;
-                               sino_ptr->totlen = sum_collected->sum_list_head->i.totlen;
+                                                                                       sino_ptr->nodetype = sum_collected->sum_list_head->i.nodetype;
+                                                                                       sino_ptr->inode = sum_collected->sum_list_head->i.inode;
+                                                                                       sino_ptr->version = sum_collected->sum_list_head->i.version;
+                                                                                       sino_ptr->offset = sum_collected->sum_list_head->i.offset;
+                                                                                       sino_ptr->totlen = sum_collected->sum_list_head->i.totlen;
 
-                               wpage += JFFS2_SUMMARY_INODE_SIZE;
-                               break;
-                       }
+                                                                                       wpage += JFFS2_SUMMARY_INODE_SIZE;
+                                                                                       break;
+                                                                               }
 
                        case JFFS2_NODETYPE_DIRENT : {
-                               struct jffs2_sum_dirent_flash *sdrnt_ptr = wpage;
+                                                                                        struct jffs2_sum_dirent_flash *sdrnt_ptr = wpage;
 
-                               sdrnt_ptr->nodetype = sum_collected->sum_list_head->d.nodetype;
-                               sdrnt_ptr->totlen = sum_collected->sum_list_head->d.totlen;
-                               sdrnt_ptr->offset = sum_collected->sum_list_head->d.offset;
-                               sdrnt_ptr->pino = sum_collected->sum_list_head->d.pino;
-                               sdrnt_ptr->version = sum_collected->sum_list_head->d.version;
-                               sdrnt_ptr->ino = sum_collected->sum_list_head->d.ino;
-                               sdrnt_ptr->nsize = sum_collected->sum_list_head->d.nsize;
-                               sdrnt_ptr->type = sum_collected->sum_list_head->d.type;
+                                                                                        sdrnt_ptr->nodetype = sum_collected->sum_list_head->d.nodetype;
+                                                                                        sdrnt_ptr->totlen = sum_collected->sum_list_head->d.totlen;
+                                                                                        sdrnt_ptr->offset = sum_collected->sum_list_head->d.offset;
+                                                                                        sdrnt_ptr->pino = sum_collected->sum_list_head->d.pino;
+                                                                                        sdrnt_ptr->version = sum_collected->sum_list_head->d.version;
+                                                                                        sdrnt_ptr->ino = sum_collected->sum_list_head->d.ino;
+                                                                                        sdrnt_ptr->nsize = sum_collected->sum_list_head->d.nsize;
+                                                                                        sdrnt_ptr->type = sum_collected->sum_list_head->d.type;
 
-                               memcpy(sdrnt_ptr->name, sum_collected->sum_list_head->d.name,
-                                               sum_collected->sum_list_head->d.nsize);
+                                                                                        memcpy(sdrnt_ptr->name, sum_collected->sum_list_head->d.name,
+                                                                                                        sum_collected->sum_list_head->d.nsize);
 
-                               wpage += JFFS2_SUMMARY_DIRENT_SIZE(sum_collected->sum_list_head->d.nsize);
-                               break;
-                       }
+                                                                                        wpage += JFFS2_SUMMARY_DIRENT_SIZE(sum_collected->sum_list_head->d.nsize);
+                                                                                        break;
+                                                                                }
 
                        case JFFS2_NODETYPE_XATTR: {
-                               struct jffs2_sum_xattr_flash *sxattr_ptr = wpage;
+                                                                                  struct jffs2_sum_xattr_flash *sxattr_ptr = wpage;
 
-                               sxattr_ptr->nodetype = sum_collected->sum_list_head->x.nodetype;
-                               sxattr_ptr->xid = sum_collected->sum_list_head->x.xid;
-                               sxattr_ptr->version = sum_collected->sum_list_head->x.version;
-                               sxattr_ptr->offset = sum_collected->sum_list_head->x.offset;
-                               sxattr_ptr->totlen = sum_collected->sum_list_head->x.totlen;
+                                                                                  sxattr_ptr->nodetype = sum_collected->sum_list_head->x.nodetype;
+                                                                                  sxattr_ptr->xid = sum_collected->sum_list_head->x.xid;
+                                                                                  sxattr_ptr->version = sum_collected->sum_list_head->x.version;
+                                                                                  sxattr_ptr->offset = sum_collected->sum_list_head->x.offset;
+                                                                                  sxattr_ptr->totlen = sum_collected->sum_list_head->x.totlen;
 
-                               wpage += JFFS2_SUMMARY_XATTR_SIZE;
-                               break;
-                       }
+                                                                                  wpage += JFFS2_SUMMARY_XATTR_SIZE;
+                                                                                  break;
+                                                                          }
 
                        case JFFS2_NODETYPE_XREF: {
-                               struct jffs2_sum_xref_flash *sxref_ptr = wpage;
+                                                                                 struct jffs2_sum_xref_flash *sxref_ptr = wpage;
 
-                               sxref_ptr->nodetype = sum_collected->sum_list_head->r.nodetype;
-                               sxref_ptr->offset = sum_collected->sum_list_head->r.offset;
+                                                                                 sxref_ptr->nodetype = sum_collected->sum_list_head->r.nodetype;
+                                                                                 sxref_ptr->offset = sum_collected->sum_list_head->r.offset;
 
-                               wpage += JFFS2_SUMMARY_XREF_SIZE;
-                               break;
-                       }
+                                                                                 wpage += JFFS2_SUMMARY_XREF_SIZE;
+                                                                                 break;
+                                                                         }
 
                        default : {
-                               printf("Unknown node type!\n");
-                       }
+                                                 printf("Unknown node type!\n");
+                                         }
                }
 
                temp = sum_collected->sum_list_head;
@@ -637,7 +637,7 @@ void add_sum_inode_mem(union jffs2_node_union *node)
 void add_sum_dirent_mem(union jffs2_node_union *node)
 {
        struct jffs2_sum_dirent_mem *temp = (struct jffs2_sum_dirent_mem *)
-                       malloc(sizeof(struct jffs2_sum_dirent_mem) + node->d.nsize);
+               malloc(sizeof(struct jffs2_sum_dirent_mem) + node->d.nsize);
 
        if (!temp)
                error_msg_and_die("Can't allocate memory for summary information!\n");
@@ -659,7 +659,7 @@ void add_sum_dirent_mem(union jffs2_node_union *node)
 void add_sum_xattr_mem(union jffs2_node_union *node)
 {
        struct jffs2_sum_xattr_mem *temp = (struct jffs2_sum_xattr_mem *)
-                       malloc(sizeof(struct jffs2_sum_xattr_mem));
+               malloc(sizeof(struct jffs2_sum_xattr_mem));
        if (!temp)
                error_msg_and_die("Can't allocate memory for summary information!\n");
 
@@ -676,7 +676,7 @@ void add_sum_xattr_mem(union jffs2_node_union *node)
 void add_sum_xref_mem(union jffs2_node_union *node)
 {
        struct jffs2_sum_xref_mem *temp = (struct jffs2_sum_xref_mem *)
-                       malloc(sizeof(struct jffs2_sum_xref_mem));
+               malloc(sizeof(struct jffs2_sum_xref_mem));
        if (!temp)
                error_msg_and_die("Can't allocate memory for summary information!\n");
 
@@ -770,10 +770,10 @@ void create_summed_image(int inp_size)
                        case JFFS2_NODETYPE_INODE:
                                if (verbose)
                                        printf ("%8s Inode      node at 0x%08x, totlen 0x%08x, #ino  %5d, version %5d, isize %8d, csize %8d, dsize %8d, offset %8d\n",
-                                               obsolete ? "Obsolete" : "",
-                                               p - file_buffer, je32_to_cpu (node->i.totlen), je32_to_cpu (node->i.ino),
-                                               je32_to_cpu ( node->i.version), je32_to_cpu (node->i.isize),
-                                               je32_to_cpu (node->i.csize), je32_to_cpu (node->i.dsize), je32_to_cpu (node->i.offset));
+                                                       obsolete ? "Obsolete" : "",
+                                                       p - file_buffer, je32_to_cpu (node->i.totlen), je32_to_cpu (node->i.ino),
+                                                       je32_to_cpu ( node->i.version), je32_to_cpu (node->i.isize),
+                                                       je32_to_cpu (node->i.csize), je32_to_cpu (node->i.dsize), je32_to_cpu (node->i.offset));
 
                                crc = crc32 (0, node, sizeof (struct jffs2_raw_inode) - 8);
                                if (crc != je32_to_cpu (node->i.node_crc)) {
@@ -800,10 +800,10 @@ void create_summed_image(int inp_size)
 
                                if (verbose)
                                        printf ("%8s Dirent     node at 0x%08x, totlen 0x%08x, #pino %5d, version %5d, #ino  %8d, nsize %8d, name %s\n",
-                                               obsolete ? "Obsolete" : "",
-                                               p - file_buffer, je32_to_cpu (node->d.totlen), je32_to_cpu (node->d.pino),
-                                               je32_to_cpu ( node->d.version), je32_to_cpu (node->d.ino),
-                                               node->d.nsize, name);
+                                                       obsolete ? "Obsolete" : "",
+                                                       p - file_buffer, je32_to_cpu (node->d.totlen), je32_to_cpu (node->d.pino),
+                                                       je32_to_cpu ( node->d.version), je32_to_cpu (node->d.ino),
+                                                       node->d.nsize, name);
 
                                crc = crc32 (0, node, sizeof (struct jffs2_raw_dirent) - 8);
                                if (crc != je32_to_cpu (node->d.node_crc)) {
@@ -829,14 +829,14 @@ void create_summed_image(int inp_size)
                                        obsolete = 1;
                                if (verbose)
                                        printf("%8s Xdatum     node at 0x%08x, totlen 0x%08x, "
-                                              "#xid  %5u, version %5u\n",
-                                              obsolete ? "Obsolete" : "",
-                                              p - file_buffer, je32_to_cpu (node->x.totlen),
-                                              je32_to_cpu(node->x.xid), je32_to_cpu(node->x.version));
+                                                       "#xid  %5u, version %5u\n",
+                                                       obsolete ? "Obsolete" : "",
+                                                       p - file_buffer, je32_to_cpu (node->x.totlen),
+                                                       je32_to_cpu(node->x.xid), je32_to_cpu(node->x.version));
                                crc = crc32(0, node, sizeof (struct jffs2_raw_xattr) - 4);
                                if (crc != je32_to_cpu(node->x.node_crc)) {
                                        printf("Wrong node_crc at 0x%08x, 0x%08x instead of 0x%08x\n",
-                                              p - file_buffer, je32_to_cpu(node->x.node_crc), crc);
+                                                       p - file_buffer, je32_to_cpu(node->x.node_crc), crc);
                                        p += PAD(je32_to_cpu (node->x.totlen));
                                        continue;
                                }
@@ -844,7 +844,7 @@ void create_summed_image(int inp_size)
                                crc = crc32(0, node->x.data, length);
                                if (crc != je32_to_cpu(node->x.data_crc)) {
                                        printf("Wrong data_crc at 0x%08x, 0x%08x instead of 0x%08x\n",
-                                              p - file_buffer, je32_to_cpu(node->x.data_crc), crc);
+                                                       p - file_buffer, je32_to_cpu(node->x.data_crc), crc);
                                        p += PAD(je32_to_cpu (node->x.totlen));
                                        continue;
                                }
@@ -858,14 +858,14 @@ void create_summed_image(int inp_size)
                                        obsolete = 1;
                                if (verbose)
                                        printf("%8s Xref       node at 0x%08x, totlen 0x%08x, "
-                                              "#ino  %5u, xid     %5u\n",
-                                              obsolete ? "Obsolete" : "",
-                                              p - file_buffer, je32_to_cpu(node->r.totlen),
-                                              je32_to_cpu(node->r.ino), je32_to_cpu(node->r.xid));
+                                                       "#ino  %5u, xid     %5u\n",
+                                                       obsolete ? "Obsolete" : "",
+                                                       p - file_buffer, je32_to_cpu(node->r.totlen),
+                                                       je32_to_cpu(node->r.ino), je32_to_cpu(node->r.xid));
                                crc = crc32(0, node, sizeof (struct jffs2_raw_xref) - 4);
                                if (crc != je32_to_cpu(node->r.node_crc)) {
                                        printf("Wrong node_crc at 0x%08x, 0x%08x instead of 0x%08x\n",
-                                              p - file_buffer, je32_to_cpu(node->r.node_crc), crc);
+                                                       p - file_buffer, je32_to_cpu(node->r.node_crc), crc);
                                        p += PAD(je32_to_cpu (node->r.totlen));
                                        continue;
                                }
@@ -877,8 +877,8 @@ void create_summed_image(int inp_size)
                        case JFFS2_NODETYPE_CLEANMARKER:
                                if (verbose) {
                                        printf ("%8s Cleanmarker     at 0x%08x, totlen 0x%08x\n",
-                                               obsolete ? "Obsolete" : "",
-                                               p - file_buffer, je32_to_cpu (node->u.totlen));
+                                                       obsolete ? "Obsolete" : "",
+                                                       p - file_buffer, je32_to_cpu (node->u.totlen));
                                }
 
                                if (!found_cleanmarkers) {
@@ -896,8 +896,8 @@ void create_summed_image(int inp_size)
                        case JFFS2_NODETYPE_PADDING:
                                if (verbose) {
                                        printf ("%8s Padding    node at 0x%08x, totlen 0x%08x\n",
-                                               obsolete ? "Obsolete" : "",
-                                               p - file_buffer, je32_to_cpu (node->u.totlen));
+                                                       obsolete ? "Obsolete" : "",
+                                                       p - file_buffer, je32_to_cpu (node->u.totlen));
                                }
                                p += PAD(je32_to_cpu (node->u.totlen));
                                break;
@@ -909,8 +909,8 @@ void create_summed_image(int inp_size)
                        default:
                                if (verbose) {
                                        printf ("%8s Unknown    node at 0x%08x, totlen 0x%08x\n",
-                                               obsolete ? "Obsolete" : "",
-                                               p - file_buffer, je32_to_cpu (node->u.totlen));
+                                                       obsolete ? "Obsolete" : "",
+                                                       p - file_buffer, je32_to_cpu (node->u.totlen));
                                }
 
                                p += PAD(je32_to_cpu (node->u.totlen));