changeset 215:517dd86b45b1

gsm-fw/services/ffs: fsck.c compiles
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 06 Jan 2014 07:12:02 +0000
parents bdfdea886bea
children 0eb85790c0ed
files gsm-fw/services/ffs/Makefile gsm-fw/services/ffs/fsck.c
diffstat 2 files changed, 75 insertions(+), 81 deletions(-) [+]
line wrap: on
line diff
--- a/gsm-fw/services/ffs/Makefile	Mon Jan 06 04:43:21 2014 +0000
+++ b/gsm-fw/services/ffs/Makefile	Mon Jan 06 07:12:02 2014 +0000
@@ -2,7 +2,7 @@
 CFLAGS=	-O2 -fno-builtin -mthumb-interwork -mthumb
 LD=	arm-elf-ld
 
-OBJS=	cfgffs.o core.o drv.o ffs_env.o ffstrace.o task.o
+OBJS=	cfgffs.o core.o drv.o ffs_env.o ffstrace.o fsck.o task.o
 
 HDRS=	core.h drv.h ffs.h ffs_api.h ffs_env.h ffs_pool_size.h ffstrace.h \
 	intctl.h ramffs.h task.h tmffs.h
--- a/gsm-fw/services/ffs/fsck.c	Mon Jan 06 04:43:21 2014 +0000
+++ b/gsm-fw/services/ffs/fsck.c	Mon Jan 06 07:12:02 2014 +0000
@@ -8,17 +8,13 @@
  *
  ******************************************************************************/
 
-#ifndef TARGET
-#include "ffs.cfg"
-#endif
-
 #include <string.h>
 #include <assert.h>
 
-#include "ffs/ffs.h"
-#include "ffs/board/core.h"
-#include "ffs/board/drv.h"
-#include "ffs/board/ffstrace.h"
+#include "ffs.h"
+#include "core.h"
+#include "drv.h"
+#include "ffstrace.h"
 
 /******************************************************************************
  * Functions
@@ -89,14 +85,14 @@
             break;    
     }
 
-	// Init all file_descriptors to zero
-	memset(fs.fd, 0, sizeof(struct file_descriptor_s) * fs.fd_max);
+    // Init all file_descriptors to zero
+    memset(fs.fd, 0, sizeof(struct file_descriptor_s) * fs.fd_max);
 
     // If blocks_fsck() found a block that needs cleaning, we do it, now
     // that all the file system has been initialized.
     if (b > 0) {
         block_clean(b - 1);
-		block_free(b - 1);
+	block_free(b - 1);
     }
 
     statistics_init();
@@ -124,20 +120,20 @@
 {
     uint8 opt, digit;
     uint32 n;
-	int numdatablocks;
+    int numdatablocks;
 
     tw(tr(TR_BEGIN, TrFsck, "fsparams_init('%s') {\n", p));
 
-	// Compiled default values
+    // Compiled default values
     fs.filename_max   = FFS_FILENAME_MAX;
-	fs.path_depth_max = FFS_PATH_DEPTH_MAX;
+    fs.path_depth_max = FFS_PATH_DEPTH_MAX;
     fs.fd_max         = FFS_FD_MAX;
-	fs.journal_size   = FFS_JOURNAL_SIZE_IN256THS;
-	fs.flags          = 0;
+    fs.journal_size   = FFS_JOURNAL_SIZE_IN256THS;
+    fs.flags          = 0;
     fs.testflags      = 0;
-	
+
     // Flag that it not has been changed by an input arg.
-	fs.block_files_max = 0;
+    fs.block_files_max = 0;
 
     // The default lost bytes percentage of a block before it is reclaimed
     // is approx. 90%.
@@ -148,19 +144,19 @@
     fs.blocks_free_min = (dev.numblocks > 2 ? 1 : 0);
 
     // Don't count free and inodes blocks
-	numdatablocks = dev.numblocks - fs.blocks_free_min - 1;
+    numdatablocks = dev.numblocks - fs.blocks_free_min - 1;
 
-	// Abselute max number of inodes.
+    // Abselute max number of inodes.
     fs.inodes_max = dev.blocksize / sizeof(struct inode_s);
     if (fs.inodes_max > FFS_INODES_MAX)
-		fs.inodes_max = FFS_INODES_MAX;
+	fs.inodes_max = FFS_INODES_MAX;
 
-   	// MUST be true: objects_max <= inodes_max - block_files_max, this is do
-   	// to the fact that we always need to have block_files_max number of
-   	// inodes left when we run a data reclaim.
+    // MUST be true: objects_max <= inodes_max - block_files_max, this is do
+    // to the fact that we always need to have block_files_max number of
+    // inodes left when we run a data reclaim.
     fs.objects_max = fs.inodes_max / 2;
 
-	// Find a suitable chunk_size
+    // Find a suitable chunk_size
     if (dev.numblocks*dev.blocksize > 1024*1024)
         fs.chunk_size_max = 8192;
     else
@@ -168,7 +164,7 @@
                              ? (dev.blocksize / 8)
                              : 2048);
     fs.fd_buf_size = fs.chunk_size_max;
-    
+
     fs.journal_size = fs.journal_size * dev.blocksize / 256;
     if (fs.journal_size < FFS_JOURNAL_SIZE_MIN)
         fs.journal_size = FFS_JOURNAL_SIZE_MIN;
@@ -183,7 +179,7 @@
     // reserved_space.
     if (fs.block_files_max > fs.objects_max / 2)
         fs.block_files_max = fs.objects_max / 2 - 4;
-		
+
     // Are we able to reach objects_max? If not then lower the number
     if (fs.objects_max > numdatablocks * fs.block_files_max)
         fs.objects_max = numdatablocks * fs.block_files_max + 10;
@@ -192,7 +188,7 @@
     // needed to have a reasonable performance.
     fs.reserved_space = dev.blocksize / 2 + 
         numdatablocks * dev.blocksize / 16 + RESERVED_LOW; 
-    
+
     // skip to first char following second slash in name
     n = 0;
     while (*p) {
@@ -239,14 +235,14 @@
 
     // Now recompute a few parameters based on adjusted values.
 
-	// No journal file thuse no reserved space.
-	if (fs.journal_size == 0) {   
-		fs.block_files_max = fs.objects_max / 2;
-		fs.reserved_space = 0;
-		fs.block_files_reserved = 0;
-	}
+    // No journal file thuse no reserved space.
+    if (fs.journal_size == 0) {   
+	fs.block_files_max = fs.objects_max / 2;
+	fs.reserved_space = 0;
+	fs.block_files_reserved = 0;
+    }
 
-	else {
+    else {
         // If journal size is less than minimum must it have been changed by an
         // input arg, recalculate.
         if (fs.journal_size < FFS_JOURNAL_SIZE_MIN)
@@ -255,28 +251,28 @@
         if (fs.reserved_space < RESERVED_LOW)
             fs.reserved_space = fs.reserved_space * dev.blocksize / 256;
 
-		// Only one reserved is needed however we want a margin and set it to two 
-		fs.block_files_reserved = 2;
+	// Only one reserved is needed however we want a margin and set it to 2
+	fs.block_files_reserved = 2;
     }
-	
-	// Don't count free blocks, inode block, reserved space, block headers
-	// and the size of one filename.
-	fs.filesize_max = numdatablocks * dev.blocksize - fs.reserved_space - 
-		numdatablocks * BHEADER_SIZE - FFS_FILENAME_MAX;
-	
-	// Furthermore don't count the overhead from each chunk (alignment) 
-	fs.filesize_max -= ((fs.filesize_max / fs.chunk_size_max) * dev.atomsize 
+
+    // Don't count free blocks, inode block, reserved space, block headers
+    // and the size of one filename.
+    fs.filesize_max = numdatablocks * dev.blocksize - fs.reserved_space - 
+	numdatablocks * BHEADER_SIZE - FFS_FILENAME_MAX;
+
+    // Furthermore don't count the overhead from each chunk (alignment) 
+    fs.filesize_max -= ((fs.filesize_max / fs.chunk_size_max) * dev.atomsize 
                         + dev.atomsize);
-	
+
     // NOTEME: chunk_size_min is never used
-	fs.chunk_size_min = numdatablocks / fs.objects_max;
-    
+    fs.chunk_size_min = numdatablocks / fs.objects_max;
+
     tw(tr(TR_FUNC, TrFsck, "dev.numblocks      = %d\n", dev.numblocks));
     tw(tr(TR_FUNC, TrFsck, "fs.blocks_free_min = %d\n", fs.blocks_free_min));
     tw(tr(TR_FUNC, TrFsck, "fs.inodes_max      = %d\n", fs.inodes_max));
     tw(tr(TR_FUNC, TrFsck, "fs.objects_max     = %d\n", fs.objects_max));
     tw(tr(TR_FUNC, TrFsck, "fs.block_files_max = %d\n", fs.block_files_max));
-	tw(tr(TR_FUNC, TrFsck, "fs.block_files_reserved    = %d\n", fs.block_files_reserved));
+    tw(tr(TR_FUNC, TrFsck, "fs.block_files_reserved    = %d\n", fs.block_files_reserved));
     tw(tr(TR_FUNC, TrFsck, "fs.chunk_size_max  = %d\n", fs.chunk_size_max));
     tw(tr(TR_FUNC, TrFsck, "fs.filename_max    = %d\n", fs.filename_max));
     tw(tr(TR_FUNC, TrFsck, "fs.lost_threshold  = %d\n", fs.lost_threshold));
@@ -341,7 +337,7 @@
     uint32 *p, *q;
 
     tlw(led_toggle(LED_BLOCKS_FSCK));
-        
+
     // We search backwards through block to find the last used byte and
     // thus the total number of used bytes. Note that this code depends
     // on the fact that an erased flash location is 0xFF!
@@ -384,7 +380,7 @@
 // block is found or another error occurs, we return the error code.
 bref_t blocks_fsck(void)
 {
-	bref_t b, b_to_clean, b_inode_lost;
+    bref_t b, b_to_clean, b_inode_lost;
     int age_valid;
     age_t age_min, age_max, age_dist, age_dist_min, age_dist_max;
     struct block_header_s *bhp;
@@ -399,7 +395,7 @@
     fs.format    =  0;
     fs.inodes    = -1;
     fs.newinodes = -1;
-	b_inode_lost = -1;
+    b_inode_lost = -1;
     b_to_clean   = EFFS_OK;
 
     for (b = 0; b < dev.numblocks; b++)
@@ -571,7 +567,7 @@
     ttw(ttr(TTrInit, "fs.inodes, newinodes = %d, %d" NL, 
             fs.inodes, fs.newinodes));
     tw(tr(TR_FUNC, TrFsck, "age min, max = %d, %d\n", age_min, age_max));
-    
+
     // If any blocks were in the EMPTY state, now is the time to bring them
     // into the FREE state. Note that we must only do this *after*
     // fs.age_max has been initialized.
@@ -584,32 +580,31 @@
         }
     }
 
-	if (fs.inodes >= 0) {  
+    if (fs.inodes >= 0) {  
         // The 'old' inode block is still valid thus we keep it.
-		if (fs.newinodes >= 0)
+	if (fs.newinodes >= 0)
             // The copying of inodes to the new block was not finished thus
             // we free the block
-			block_free(fs.newinodes);   
-		inodes_set(fs.inodes);
-	}
-	else {                                 
-		// Copying must have been finished
-		if (fs.newinodes >= 0 && b_inode_lost >= 0) {
+	    block_free(fs.newinodes);   
+	inodes_set(fs.inodes);
+    }
+    else {                                 
+	// Copying must have been finished
+	if (fs.newinodes >= 0 && b_inode_lost >= 0) {
             // The inode reclaim did finish but currently there is no valid
             // inode block thus the operation must be finished by committing
             // the new block as the valid inode block.
-			fs.inodes = b_inode_lost;
-			block_commit();
-			
-		}
-		else {
+	    fs.inodes = b_inode_lost;
+	    block_commit();
+	}
+	else {
             // No old or new Inode block!
-			tw(tr(TR_END, TrFsck, "} %d\n", EFFS_NOFORMAT));
-			ttw(ttr(TTrInitLow, "} %d" NL, EFFS_NOFORMAT));
-			return EFFS_NOFORMAT;
-		}
+	    tw(tr(TR_END, TrFsck, "} %d\n", EFFS_NOFORMAT));
+	    ttw(ttr(TTrInitLow, "} %d" NL, EFFS_NOFORMAT));
+	    return EFFS_NOFORMAT;
 	}
-	
+    }
+
     if ((fs.format >> 8) != (FFS_FORMAT_VERSION >> 8)) {
         tw(tr(TR_END, TrFsck, "} %d\n", EFFS_BADFORMAT));
         ttw(ttr(TTrInitLow, "} %d" NL, EFFS_BADFORMAT));
@@ -1085,7 +1080,7 @@
     // Unless we are currently relocating the journal file itself, check if
     // journal file is near full and relocate it if it is.
     if (fs.journal_pos >= fs.journal_size - FFS_JOURNAL_MARGIN * 
-		sizeof(struct journal_s) && fs.journal.oldi != fs.ijournal) {
+	sizeof(struct journal_s) && fs.journal.oldi != fs.ijournal) {
         tw(tr(TR_FUNC, TrJournal, "Journal file (near) full!\n"));
         journal_create(fs.ijournal);
     }
@@ -1214,13 +1209,13 @@
     if (fs.journal_depth > 1) {
         tw(tr(TR_FUNC, TrAll, "FATAL: journal_push() to depth %d\n",
               fs.journal_depth));
-		return -1;
-	}
+	return -1;
+    }
 
     tw(tr(TR_FUNC, TrJournal, "journal_push() to depth %d\n",
           fs.journal_depth));
-	
-	return EFFS_OK;
+
+    return EFFS_OK;
 }
 
 // Recall "old" journal into current journal
@@ -1233,11 +1228,11 @@
     if (fs.journal_depth < 0) {
         tw(tr(TR_FUNC, TrAll, "FATAL: journal_pop() to depth %d\n",
               fs.journal_depth));
-		return -1;
+	return -1;
     }
     memcpy(&fs.journal, &fs.ojournal, sizeof(struct journal_s));
 
-	return EFFS_OK;
+    return EFFS_OK;
 }
 
 // Initialize the journalling system. Create journal file if it not already
@@ -1441,7 +1436,7 @@
 // zero and set the magic. This function is called from ffs_init().
 void statistics_init(void)
 {
-	memset(&stats, 0, sizeof(struct ffs_stats_s));
+    memset(&stats, 0, sizeof(struct ffs_stats_s));
 }
 
 void statistics_update_drec(int valid, int lost, int candidate)
@@ -1472,4 +1467,3 @@
     stats.irec.valid += valid;
     stats.irec.lost += lost;
 }
-