shithub: lwext4

Download patch

ref: eeb7150b0e4ee24bdbf8c351ea2ffe481510f5f7
parent: 63e88926bd518a530e14cb6b2186d642b9abfe18
author: gkostka <kostka.grzegorz@gmail.com>
date: Tue Jun 16 07:09:51 EDT 2015

clang-format: generic demo app

--- a/demos/generic/main.c
+++ b/demos/generic/main.c
@@ -49,13 +49,13 @@
 char input_name[128] = "ext2";
 
 /**@brief   Read-write size*/
-static int rw_szie  = 1024 * 1024;
+static int rw_szie = 1024 * 1024;
 
 /**@brief   Read-write size*/
 static int rw_count = 10;
 
 /**@brief   Directory test count*/
-static int dir_cnt  = 0;
+static int dir_cnt = 0;
 
 /**@brief   Static or dynamic cache mode*/
 static bool cache_mode = true;
@@ -85,7 +85,7 @@
 EXT4_BCACHE_STATIC_INSTANCE(_lwext4_cache, CONFIG_BLOCK_DEV_CACHE_SIZE, 1024);
 
 /**@brief   Block cache handle.*/
-static struct ext4_bcache   *bc = &_lwext4_cache;
+static struct ext4_bcache *bc = &_lwext4_cache;
 
 static const char *usage = "                                    \n\
 Welcome in ext4 generic demo.                                   \n\
@@ -102,9 +102,9 @@
     --wpart  - windows partition mode                           \n\
 \n";
 
-static char* entry_to_str(uint8_t type)
+static char *entry_to_str(uint8_t type)
 {
-    switch(type){
+    switch (type) {
     case EXT4_DIRENTRY_UNKNOWN:
         return "[UNK] ";
     case EXT4_DIRENTRY_REG_FILE:
@@ -138,8 +138,7 @@
     ext4_dir_open(&d, path);
     de = ext4_dir_entry_next(&d);
 
-
-    while(de){
+    while (de) {
         memcpy(sss, de->name, de->name_length);
         sss[de->name_length] = 0;
         printf("\t%s", entry_to_str(de->inode_type));
@@ -156,17 +155,17 @@
     ext4_mount_point_stats("/mp/", &stats);
 
     printf("ext4_mount_point_stats:\n");
-    printf("\tinodes_count        = %"PRIu32"\n", stats.inodes_count);
-    printf("\tfree_inodes_count   = %"PRIu32"\n", stats.free_inodes_count);
-    printf("\tblocks_count        = %"PRIu32"\n", (uint32_t)stats.blocks_count);
-    printf("\tfree_blocks_count   = %"PRIu32"\n", (uint32_t)stats.free_blocks_count);
-    printf("\tblock_size          = %"PRIu32"\n", stats.block_size);
-    printf("\tblock_group_count   = %"PRIu32"\n", stats.block_group_count);
-    printf("\tblocks_per_group    = %"PRIu32"\n", stats.blocks_per_group);
-    printf("\tinodes_per_group    = %"PRIu32"\n", stats.inodes_per_group);
+    printf("\tinodes_count        = %" PRIu32 "\n", stats.inodes_count);
+    printf("\tfree_inodes_count   = %" PRIu32 "\n", stats.free_inodes_count);
+    printf("\tblocks_count        = %" PRIu32 "\n",
+           (uint32_t)stats.blocks_count);
+    printf("\tfree_blocks_count   = %" PRIu32 "\n",
+           (uint32_t)stats.free_blocks_count);
+    printf("\tblock_size          = %" PRIu32 "\n", stats.block_size);
+    printf("\tblock_group_count   = %" PRIu32 "\n", stats.block_group_count);
+    printf("\tblocks_per_group    = %" PRIu32 "\n", stats.blocks_per_group);
+    printf("\tinodes_per_group    = %" PRIu32 "\n", stats.inodes_per_group);
     printf("\tvolume_name         = %s\n", stats.volume_name);
-
-
 }
 
 static void block_stats(void)
@@ -174,34 +173,36 @@
     uint32_t i;
 
     printf("ext4 blockdev stats\n");
-    printf("\tbdev->bread_ctr          = %"PRIu32"\n", bd->bread_ctr);
-    printf("\tbdev->bwrite_ctr         = %"PRIu32"\n", bd->bwrite_ctr);
+    printf("\tbdev->bread_ctr          = %" PRIu32 "\n", bd->bread_ctr);
+    printf("\tbdev->bwrite_ctr         = %" PRIu32 "\n", bd->bwrite_ctr);
 
+    printf("\tbcache->ref_blocks       = %" PRIu32 "\n", bc->ref_blocks);
+    printf("\tbcache->max_ref_blocks   = %" PRIu32 "\n", bc->max_ref_blocks);
+    printf("\tbcache->lru_ctr          = %" PRIu32 "\n", bc->lru_ctr);
 
-    printf("\tbcache->ref_blocks       = %"PRIu32"\n", bc->ref_blocks);
-    printf("\tbcache->max_ref_blocks   = %"PRIu32"\n", bc->max_ref_blocks);
-    printf("\tbcache->lru_ctr          = %"PRIu32"\n", bc->lru_ctr);
-
     printf("\n");
     for (i = 0; i < bc->cnt; ++i) {
-        printf("\tbcache->refctr[%"PRIu32"]     = %"PRIu32"\n", i, bc->refctr[i]);
+        printf("\tbcache->refctr[%" PRIu32 "]     = %" PRIu32 "\n", i,
+               bc->refctr[i]);
     }
 
     printf("\n");
     for (i = 0; i < bc->cnt; ++i) {
-        printf("\tbcache->lru_id[%"PRIu32"]     = %"PRIu32"\n", i, bc->lru_id[i]);
+        printf("\tbcache->lru_id[%" PRIu32 "]     = %" PRIu32 "\n", i,
+               bc->lru_id[i]);
     }
 
     printf("\n");
     for (i = 0; i < bc->cnt; ++i) {
-        printf("\tbcache->free_delay[%"PRIu32"] = %d\n", i, bc->free_delay[i]);
+        printf("\tbcache->free_delay[%" PRIu32 "] = %d\n", i,
+               bc->free_delay[i]);
     }
 
     printf("\n");
     for (i = 0; i < bc->cnt; ++i) {
-        printf("\tbcache->lba[%"PRIu32"]        = %"PRIu32"\n", i, (uint32_t)bc->lba[i]);
+        printf("\tbcache->lba[%" PRIu32 "]        = %" PRIu32 "\n", i,
+               (uint32_t)bc->lba[i]);
     }
-
 }
 
 static clock_t get_ms(void)
@@ -214,8 +215,8 @@
 static bool dir_test(int len)
 {
     ext4_file f;
-    int       r;
-    int       i;
+    int r;
+    int i;
     char path[64];
     clock_t diff;
     clock_t stop;
@@ -225,18 +226,17 @@
     printf("directory create: /mp/dir1\n");
     start = get_ms();
     r = ext4_dir_mk("/mp/dir1");
-    if(r != EOK){
+    if (r != EOK) {
         printf("\text4_dir_mk: rc = %d\n", r);
         return false;
     }
 
-
     ext4_cache_write_back("/mp/", 1);
     printf("add files to: /mp/dir1\n");
     for (i = 0; i < len; ++i) {
         sprintf(path, "/mp/dir1/f%d", i);
         r = ext4_fopen(&f, path, "wb");
-        if(r != EOK){
+        if (r != EOK) {
             printf("\text4_fopen: rc = %d\n", r);
             return false;
         }
@@ -243,7 +243,7 @@
     }
     ext4_cache_write_back("/mp/", 0);
 
-    stop =  get_ms();
+    stop = get_ms();
     diff = stop - start;
     dir_ls("/mp/dir1");
     printf("dir_test: time: %d ms\n", (int)diff);
@@ -250,11 +250,10 @@
     return true;
 }
 
-
 static bool file_test(void)
 {
     int r;
-    uint32_t  size;
+    uint32_t size;
     ext4_file f;
     int i;
     clock_t start;
@@ -269,16 +268,15 @@
     r = ext4_fwrite(&f, "Hello World !\n", strlen("Hello World !\n"), 0);
     r = ext4_fclose(&f);
 
-
     printf("ext4_fopen: write test\n");
     start = get_ms();
     r = ext4_fopen(&f, "/mp/test1", "wb");
-    if(r != EOK){
+    if (r != EOK) {
         printf("\text4_fopen rc = %d\n", r);
         return false;
     }
 
-    printf("ext4_write: %d * %d ...\n" , rw_szie, rw_count);
+    printf("ext4_write: %d * %d ...\n", rw_szie, rw_count);
     for (i = 0; i < rw_count; ++i) {
 
         memset(wr_buff, i % 10 + '0', rw_szie);
@@ -285,11 +283,11 @@
 
         r = ext4_fwrite(&f, wr_buff, rw_szie, &size);
 
-        if((r != EOK) || (size != rw_szie))
+        if ((r != EOK) || (size != rw_szie))
             break;
     }
 
-    if(i != rw_count){
+    if (i != rw_count) {
         printf("\tfile_test: rw_count = %d\n", i);
         return false;
     }
@@ -300,30 +298,30 @@
     size_bytes = (size_bytes * 1000) / 1024;
     kbps = (size_bytes) / (diff + 1);
     printf("\twrite time: %d ms\n", (int)diff);
-    printf("\twrite speed: %"PRIu32" KB/s\n", kbps);
+    printf("\twrite speed: %" PRIu32 " KB/s\n", kbps);
     r = ext4_fclose(&f);
 
     printf("ext4_fopen: read test\n");
     start = get_ms();
     r = ext4_fopen(&f, "/mp/test1", "r+");
-    if(r != EOK){
+    if (r != EOK) {
         printf("\text4_fopen rc = %d\n", r);
         return false;
     }
 
-    printf("ext4_read: %d * %d ...\n" , rw_szie, rw_count);
+    printf("ext4_read: %d * %d ...\n", rw_szie, rw_count);
     for (i = 0; i < rw_count; ++i) {
         memset(wr_buff, i % 10 + '0', rw_szie);
         r = ext4_fread(&f, rd_buff, rw_szie, &size);
 
-        if((r != EOK) || (size != rw_szie))
+        if ((r != EOK) || (size != rw_szie))
             break;
 
-        if(memcmp(rd_buff, wr_buff, rw_szie)){
+        if (memcmp(rd_buff, wr_buff, rw_szie)) {
             break;
         }
     }
-    if(i != rw_count){
+    if (i != rw_count) {
         printf("\tfile_test: rw_count = %d\n", i);
         return false;
     }
@@ -333,11 +331,10 @@
     size_bytes = (size_bytes * 1000) / 1024;
     kbps = (size_bytes) / (diff + 1);
     printf("\tread time: %d ms\n", (int)diff);
-    printf("\tread speed: %"PRIu32" KB/s\n", kbps);
+    printf("\tread speed: %" PRIu32 " KB/s\n", kbps);
     r = ext4_fclose(&f);
 
     return true;
-
 }
 static void cleanup(void)
 {
@@ -362,7 +359,7 @@
 {
     ext4_filedev_filename(input_name);
     bd = ext4_filedev_get();
-    if(!bd){
+    if (!bd) {
         printf("open_filedev: fail\n");
         return false;
     }
@@ -374,13 +371,14 @@
 #ifdef WIN32
     ext4_io_raw_filename(input_name);
     bd = ext4_io_raw_dev_get();
-    if(!bd){
+    if (!bd) {
         printf("open_winpartition: fail\n");
         return false;
     }
     return true;
 #else
-    printf("open_winpartition: this mode should be used only under windows !\n");
+    printf(
+        "open_winpartition: this mode should be used only under windows !\n");
     return false;
 #endif
 }
@@ -388,18 +386,17 @@
 static bool mount(void)
 {
     int r;
-    if(winpart){
-        if(!open_winpartition())
+    if (winpart) {
+        if (!open_winpartition())
             return false;
-    }else{
-        if(!open_filedev())
+    } else {
+        if (!open_filedev())
             return false;
-
     }
     wr_buff = malloc(rw_szie);
     rd_buff = malloc(rw_szie);
 
-    if(!wr_buff || !rd_buff){
+    if (!wr_buff || !rd_buff) {
         printf("mount: allocation failed\n");
         return false;
     }
@@ -407,13 +404,13 @@
     ext4_dmask_set(EXT4_DEBUG_ALL);
 
     r = ext4_device_register(bd, cache_mode ? 0 : bc, "ext4_fs");
-    if(r != EOK){
+    if (r != EOK) {
         printf("ext4_device_register: rc = %d\n", r);
         return false;
     }
 
     r = ext4_mount("ext4_fs", "/mp/");
-    if(r != EOK){
+    if (r != EOK) {
         printf("ext4_mount: rc = %d\n", r);
         return false;
     }
@@ -424,7 +421,7 @@
 static bool umount(void)
 {
     int r = ext4_umount("/mp/");
-    if(r != EOK){
+    if (r != EOK) {
         printf("ext4_umount: rc = %d", r);
         return false;
     }
@@ -436,23 +433,21 @@
     int option_index = 0;
     int c;
 
-    static struct option long_options[] =
-    {
-            {"in",      required_argument, 0, 'a'},
-            {"rws",     required_argument, 0, 'b'},
-            {"rwc",     required_argument, 0, 'c'},
-            {"cache",   required_argument, 0, 'd'},
-            {"dirs",    required_argument, 0, 'e'},
-            {"clean",   no_argument,       0, 'f'},
-            {"bstat",   no_argument,       0, 'g'},
-            {"sbstat",  no_argument,       0, 'h'},
-            {"wpart",   no_argument,       0, 'i'},
-            {0, 0, 0, 0}
-    };
+    static struct option long_options[] = {{"in", required_argument, 0, 'a'},
+                                           {"rws", required_argument, 0, 'b'},
+                                           {"rwc", required_argument, 0, 'c'},
+                                           {"cache", required_argument, 0, 'd'},
+                                           {"dirs", required_argument, 0, 'e'},
+                                           {"clean", no_argument, 0, 'f'},
+                                           {"bstat", no_argument, 0, 'g'},
+                                           {"sbstat", no_argument, 0, 'h'},
+                                           {"wpart", no_argument, 0, 'i'},
+                                           {0, 0, 0, 0}};
 
-    while(-1 != (c = getopt_long (argc, argv, "a:b:c:d:e:fghi", long_options, &option_index))) {
+    while (-1 != (c = getopt_long(argc, argv, "a:b:c:d:e:fghi", long_options,
+                                  &option_index))) {
 
-        switch(c){
+        switch (c) {
         case 'a':
             strcpy(input_name, optarg);
             break;
@@ -483,7 +478,6 @@
         default:
             printf("%s", usage);
             return false;
-
         }
     }
     return true;
@@ -491,48 +485,47 @@
 
 int main(int argc, char **argv)
 {
-    if(!parse_opt(argc, argv))
+    if (!parse_opt(argc, argv))
         return EXIT_FAILURE;
 
     printf("test conditions:\n");
     printf("\timput name: %s\n", input_name);
-    printf("\trw size: %d\n",  rw_szie);
+    printf("\trw size: %d\n", rw_szie);
     printf("\trw count: %d\n", rw_count);
     printf("\tcache mode: %s\n", cache_mode ? "dynamic" : "static");
 
-    if(!mount())
+    if (!mount())
         return EXIT_FAILURE;
 
     cleanup();
 
-    if(sbstat)
+    if (sbstat)
         mp_stats();
 
     dir_ls("/mp/");
     fflush(stdout);
-    if(!dir_test(dir_cnt))
+    if (!dir_test(dir_cnt))
         return EXIT_FAILURE;
 
     fflush(stdout);
-    if(!file_test())
+    if (!file_test())
         return EXIT_FAILURE;
 
     fflush(stdout);
     dir_ls("/mp/");
 
-    if(sbstat)
+    if (sbstat)
         mp_stats();
 
-    if(cleanup_flag)
+    if (cleanup_flag)
         cleanup();
 
-    if(bstat)
+    if (bstat)
         block_stats();
 
-    if(!umount())
+    if (!umount())
         return EXIT_FAILURE;
 
     printf("\ntest finished\n");
     return EXIT_SUCCESS;
-
 }