FreeCalypso > hg > freecalypso-sw
annotate gsm-fw/services/ffs/fsck.c @ 502:cff42ff57c60
osx.c: osx_free_mem() done
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Tue, 01 Jul 2014 18:34:53 +0000 |
parents | 517dd86b45b1 |
children |
rev | line source |
---|---|
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /****************************************************************************** |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * Flash File System (ffs) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * Idea, design and coding by Mads Meisner-Jensen, mmj@ti.com |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 * |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 * FFS file system integrity checking, journalling, init and exit |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 * |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 * $Id: fsck.c 1.3.1.1.1.33 Thu, 08 Jan 2004 15:05:23 +0100 tsj $ |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 * |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 ******************************************************************************/ |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <string.h> |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include <assert.h> |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
14 #include "ffs.h" |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
15 #include "core.h" |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
16 #include "drv.h" |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
17 #include "ffstrace.h" |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 /****************************************************************************** |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 * Functions |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 ******************************************************************************/ |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 bref_t blocks_fsck(void); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 iref_t inodes_fsck(void); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 /****************************************************************************** |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 * Init and Exit |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 ******************************************************************************/ |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 effs_t ffs_initialize(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 bref_t b; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 struct inode_s *ip; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 int i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 tlw(led_set(0)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 tlw(led_on(LED_INIT)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 ttw(str(TTrInit, "initialize {" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 tw(tr(TR_BEGIN, TrFsck, "ffs_initialize() {\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 // default to non-initialized ffs |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 fs.root = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 fs.debug[0] = fs.debug[1] = fs.debug[2] = fs.debug[3] = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 fs.testflags = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 tlw(led_on(LED_DRV_INIT)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 fs.initerror = ffsdrv_init(); // read manufacturer and device ID |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 tlw(led_off(LED_DRV_INIT)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 if (fs.initerror < 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 tlw(led_off(0)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 tw(tr(TR_END, TrFsck, "} %d\n", fs.initerror)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 ttw(ttr(TTrInit, "} %d" NL, fs.initerror)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 return fs.initerror; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 for (i = 0; i < 2; i++) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 tlw(led_on(LED_BLOCKS_FSCK)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 fs.initerror = EFFS_INVALID; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 fs.initerror = b = blocks_fsck(); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 tlw(led_off(LED_BLOCKS_FSCK)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 if (fs.initerror < 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 tlw(led_off(0)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 tw(tr(TR_END, TrFsck, "} %d\n", fs.initerror)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 ttw(ttr(TTrInit, "} %d" NL, fs.initerror)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 return fs.initerror; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 tlw(led_on(LED_INODES_FSCK)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 fs.initerror = EFFS_INVALID; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 fs.initerror = inodes_fsck(); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 tlw(led_off(LED_INODES_FSCK)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 if (fs.initerror < 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 tlw(led_off(0)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 tw(tr(TR_END, TrFsck, "} %d\n", fs.initerror)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 ttw(ttr(TTrInit, "} %d" NL, fs.initerror)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 return fs.initerror; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 // parse the fs options in the root inode's name |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 ip = inode_addr(fs.root); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 fs_params_init(addr2name(offset2addr(location2offset(ip->location)))); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 if ((fs.initerror = journal_init(fs.ijournal)) == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
88 // Init all file_descriptors to zero |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
89 memset(fs.fd, 0, sizeof(struct file_descriptor_s) * fs.fd_max); |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 // If blocks_fsck() found a block that needs cleaning, we do it, now |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 // that all the file system has been initialized. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 if (b > 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 block_clean(b - 1); |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
95 block_free(b - 1); |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 statistics_init(); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 // In target, we do this before entering the task event loop... |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 // Otherwise we would in some cases impose a long reboot delay if we did |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 // it here. If we test in target it is nessesary to call |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 // blocks_reclaim() anyway because we re-init ffs. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 #if (TARGET == 1) //NOTEME: can this be done in another/better way? |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 #if (WITH_TFFS == 1) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 blocks_reclaim(); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 #endif |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 #else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 blocks_reclaim(); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 #endif |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 tlw(led_off(LED_INIT)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
113 tw(tr(TR_END, TrFsck, "} %d\n", EFFS_OK)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
114 ttw(str(TTrInit, "} 0" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
115 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
116 return EFFS_OK; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
117 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
118 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
119 void fs_params_init(const char *p) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
120 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
121 uint8 opt, digit; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
122 uint32 n; |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
123 int numdatablocks; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
124 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
125 tw(tr(TR_BEGIN, TrFsck, "fsparams_init('%s') {\n", p)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
126 |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
127 // Compiled default values |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
128 fs.filename_max = FFS_FILENAME_MAX; |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
129 fs.path_depth_max = FFS_PATH_DEPTH_MAX; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 fs.fd_max = FFS_FD_MAX; |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
131 fs.journal_size = FFS_JOURNAL_SIZE_IN256THS; |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
132 fs.flags = 0; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
133 fs.testflags = 0; |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
134 |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
135 // Flag that it not has been changed by an input arg. |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
136 fs.block_files_max = 0; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
137 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
138 // The default lost bytes percentage of a block before it is reclaimed |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
139 // is approx. 90%. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
140 fs.lost_threshold = (256 - 256/10); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
141 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
142 // If we only have two blocks, we cannot make any reclaims and thus we |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
143 // have a write-once FFS system. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
144 fs.blocks_free_min = (dev.numblocks > 2 ? 1 : 0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
145 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
146 // Don't count free and inodes blocks |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
147 numdatablocks = dev.numblocks - fs.blocks_free_min - 1; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
148 |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
149 // Abselute max number of inodes. |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
150 fs.inodes_max = dev.blocksize / sizeof(struct inode_s); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
151 if (fs.inodes_max > FFS_INODES_MAX) |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
152 fs.inodes_max = FFS_INODES_MAX; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
153 |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
154 // MUST be true: objects_max <= inodes_max - block_files_max, this is do |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
155 // to the fact that we always need to have block_files_max number of |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
156 // inodes left when we run a data reclaim. |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
157 fs.objects_max = fs.inodes_max / 2; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
158 |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
159 // Find a suitable chunk_size |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
160 if (dev.numblocks*dev.blocksize > 1024*1024) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
161 fs.chunk_size_max = 8192; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
162 else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
163 fs.chunk_size_max = (2048 > (dev.blocksize / 8) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
164 ? (dev.blocksize / 8) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
165 : 2048); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
166 fs.fd_buf_size = fs.chunk_size_max; |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
167 |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
168 fs.journal_size = fs.journal_size * dev.blocksize / 256; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
169 if (fs.journal_size < FFS_JOURNAL_SIZE_MIN) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
170 fs.journal_size = FFS_JOURNAL_SIZE_MIN; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
171 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
172 // Set it just below the same amount as entries in one journal file |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
173 fs.block_files_max = (fs.journal_size / sizeof(struct journal_s) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
174 - FFS_JOURNAL_MARGIN - 2); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
175 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
176 // MUST be true: block_files_max < objects_max / 2. But if we want |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
177 // to reach objects_max must block_files_max >= objects_max / number |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
178 // of datablocks, however a big block_files_max require higher |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
179 // reserved_space. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
180 if (fs.block_files_max > fs.objects_max / 2) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
181 fs.block_files_max = fs.objects_max / 2 - 4; |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
182 |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
183 // Are we able to reach objects_max? If not then lower the number |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
184 if (fs.objects_max > numdatablocks * fs.block_files_max) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
185 fs.objects_max = numdatablocks * fs.block_files_max + 10; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
186 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
187 // Absolute minimum is RESERVED_LOW the rest is 'workspace' which is |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
188 // needed to have a reasonable performance. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
189 fs.reserved_space = dev.blocksize / 2 + |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
190 numdatablocks * dev.blocksize / 16 + RESERVED_LOW; |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
191 |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
192 // skip to first char following second slash in name |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
193 n = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
194 while (*p) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
195 if (*p++ == '/') { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
196 n++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
197 if (n == 2) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
198 break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
199 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
200 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
201 if (n == 2) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
202 // while still options to process... |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
203 while (*p) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
204 opt = *p++; // save option letter for later |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
205 // collect option value... |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
206 n = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
207 while ((digit = *p)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
208 if (digit >= '0' && digit <= '9') { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
209 n = 10 * n + digit - '0'; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
210 p++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
211 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
212 else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
213 break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
214 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
215 switch (opt) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
216 case 'b': dev.numblocks = n; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
217 case 'm': fs.blocks_free_min = n; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
218 case 'i': fs.inodes_max = n; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
219 case 'o': fs.objects_max = n; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
220 case 'n': fs.filename_max = n; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
221 case 'f': fs.block_files_max = n; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
222 case 'd': fs.fd_max = n; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
223 case 's': fs.fd_buf_size = n; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
224 case 't': fs.lost_threshold = n; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
225 case 'z': fs.flags = n; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
226 case 'j': fs.journal_size = n; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
227 case 'c': fs.chunk_size_max = n; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
228 case 'r': fs.reserved_space = n; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
229 // d = &fs.path_depth_max; // really necessary? |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
230 default: |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
231 break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
232 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
233 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
234 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
235 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
236 // Now recompute a few parameters based on adjusted values. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
237 |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
238 // No journal file thuse no reserved space. |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
239 if (fs.journal_size == 0) { |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
240 fs.block_files_max = fs.objects_max / 2; |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
241 fs.reserved_space = 0; |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
242 fs.block_files_reserved = 0; |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
243 } |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
244 |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
245 else { |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
246 // If journal size is less than minimum must it have been changed by an |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
247 // input arg, recalculate. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
248 if (fs.journal_size < FFS_JOURNAL_SIZE_MIN) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
249 fs.journal_size = fs.journal_size * dev.blocksize / 256; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
250 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
251 if (fs.reserved_space < RESERVED_LOW) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
252 fs.reserved_space = fs.reserved_space * dev.blocksize / 256; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
253 |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
254 // Only one reserved is needed however we want a margin and set it to 2 |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
255 fs.block_files_reserved = 2; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
256 } |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
257 |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
258 // Don't count free blocks, inode block, reserved space, block headers |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
259 // and the size of one filename. |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
260 fs.filesize_max = numdatablocks * dev.blocksize - fs.reserved_space - |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
261 numdatablocks * BHEADER_SIZE - FFS_FILENAME_MAX; |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
262 |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
263 // Furthermore don't count the overhead from each chunk (alignment) |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
264 fs.filesize_max -= ((fs.filesize_max / fs.chunk_size_max) * dev.atomsize |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
265 + dev.atomsize); |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
266 |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
267 // NOTEME: chunk_size_min is never used |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
268 fs.chunk_size_min = numdatablocks / fs.objects_max; |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
269 |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
270 tw(tr(TR_FUNC, TrFsck, "dev.numblocks = %d\n", dev.numblocks)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
271 tw(tr(TR_FUNC, TrFsck, "fs.blocks_free_min = %d\n", fs.blocks_free_min)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
272 tw(tr(TR_FUNC, TrFsck, "fs.inodes_max = %d\n", fs.inodes_max)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
273 tw(tr(TR_FUNC, TrFsck, "fs.objects_max = %d\n", fs.objects_max)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
274 tw(tr(TR_FUNC, TrFsck, "fs.block_files_max = %d\n", fs.block_files_max)); |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
275 tw(tr(TR_FUNC, TrFsck, "fs.block_files_reserved = %d\n", fs.block_files_reserved)); |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
276 tw(tr(TR_FUNC, TrFsck, "fs.chunk_size_max = %d\n", fs.chunk_size_max)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
277 tw(tr(TR_FUNC, TrFsck, "fs.filename_max = %d\n", fs.filename_max)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
278 tw(tr(TR_FUNC, TrFsck, "fs.lost_threshold = %d\n", fs.lost_threshold)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
279 tw(tr(TR_FUNC, TrFsck, "fs.path_depth_max = %d\n", fs.path_depth_max)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
280 tw(tr(TR_FUNC, TrFsck, "fs.journal_size = %d\n", fs.journal_size)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
281 tw(tr(TR_FUNC, TrFsck, "fs.reserved_space = %d\n", fs.reserved_space)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
282 tw(tr(TR_FUNC, TrFsck, "fs.fd_max = %d\n", fs.fd_max)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
283 tw(tr(TR_FUNC, TrFsck, "fs.fd_buf_size = 0x%02x\n", fs.fd_buf_size)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
284 tw(tr(TR_FUNC, TrFsck, "fs.flags = 0x%02x\n", fs.flags)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
285 tw(tr(TR_END, TrFsck, "}\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
286 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
287 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
288 // TODO: Finish pending commits/writes. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
289 effs_t ffs_exit(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
290 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
291 tw(tr(TR_FUNC, TrFsck, "exit() 0\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
292 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
293 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
294 return EFFS_OK; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
295 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
296 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
297 #if 0 // Not used in this version |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
298 // Purely for core internal use; Read a file. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
299 effs_t file_read_int(const char *path, void *src, int size) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
300 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
301 if (fs.initerror != EFFS_OK) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
302 return fs.initerror; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
303 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
304 return object_read(path, src, size, 0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
305 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
306 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
307 // Purely for core internal use; Update a file. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
308 effs_t file_update(const char *path, void *src, int size) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
309 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
310 char *name; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
311 iref_t i, dir; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
312 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
313 if (fs.initerror != EFFS_OK) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
314 return fs.initerror; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
315 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
316 if ((i = object_lookup(path, &name, &dir)) < 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
317 return i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
318 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
319 journal_begin(i); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
320 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
321 if ((i = object_create(name, src, size, -dir)) < 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
322 return i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
323 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
324 journal_end(0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
325 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
326 return EFFS_OK; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
327 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
328 #endif |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
329 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
330 /****************************************************************************** |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
331 * blocks_fsck() |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
332 ******************************************************************************/ |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
333 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
334 blocksize_t block_used(bref_t b) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
335 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
336 blocksize_t used; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
337 uint32 *p, *q; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
338 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
339 tlw(led_toggle(LED_BLOCKS_FSCK)); |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
340 |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
341 // We search backwards through block to find the last used byte and |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
342 // thus the total number of used bytes. Note that this code depends |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
343 // on the fact that an erased flash location is 0xFF! |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
344 p = (uint32 *) offset2addr(dev.binfo[b].offset); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
345 for (q = p + dev.blocksize/4 - 4; q > p; q -= 4) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
346 if ( ~(q[0] & q[1] & q[2] & q[3]) ) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
347 break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
348 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
349 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
350 if ( ~(q[0] & q[1] & q[2] & q[3]) ) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
351 q += 4; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
352 used = atomalign((char *) q - (char *) p); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
353 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
354 tw(tr(TR_FUNC, TrFsckLow, "ffs_block_used(%d) %d\n", b, used)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
355 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
356 return used; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
357 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
358 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
359 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
360 age_t age_distance(age_t x, age_t y) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
361 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
362 age_t a = x - y; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
363 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
364 if (a > 0x8000) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
365 a = -a; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
366 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
367 tw(tr(TR_FUNC, TrFsckLow, "age_distance(%d, %d) %d\n", x, y, a)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
368 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
369 return a; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
370 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
371 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
372 // For each ffs block, we initialise the basic bstat array information, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
373 // namely the number of used bytes. Also, we locate the inodes block and if |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
374 // a previous operation was interrupted by a powerfail, we clean it up. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
375 // |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
376 // We return EFFS_OK if all is fine. If a positive integer is returned, it |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
377 // denotes a block that needs to be cleaned by block_clean() once FFS |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
378 // has been properly intialized (we actually return the block number + 1 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
379 // because otherwise it would clash with EFFS_OK return code). If no inodes |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
380 // block is found or another error occurs, we return the error code. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
381 bref_t blocks_fsck(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
382 { |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
383 bref_t b, b_to_clean, b_inode_lost; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
384 int age_valid; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
385 age_t age_min, age_max, age_dist, age_dist_min, age_dist_max; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
386 struct block_header_s *bhp; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
387 struct block_header_old_s *obhp; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
388 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
389 ttw(str(TTrInitLow, "blocks_fsck {" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
390 tw(tr(TR_BEGIN, TrFsck, "blocks_fsck() {\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
391 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
392 // initialize ages to the illegal/unset value |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
393 age_min = age_max = age_dist = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
394 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
395 fs.format = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
396 fs.inodes = -1; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
397 fs.newinodes = -1; |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
398 b_inode_lost = -1; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
399 b_to_clean = EFFS_OK; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
400 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
401 for (b = 0; b < dev.numblocks; b++) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
402 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
403 tlw(led_toggle(LED_DRV_INIT)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
404 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
405 // read block flags from flash |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
406 bhp = (struct block_header_s *) offset2addr(dev.binfo[b].offset); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
407 obhp = (struct block_header_old_s *) bhp; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
408 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
409 bstat[b].used = dev.blocksize; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
410 bstat[b].lost = bstat[b].used; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
411 bstat[b].flags = bhp->flags; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
412 bstat[b].objects = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
413 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
414 age_valid = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
415 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
416 if (bhp->magic_low != BLOCK_MAGIC_LOW || |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
417 bhp->magic_high != BLOCK_MAGIC_HIGH) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
418 // The block magic as bad! It *could* be because the flash |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
419 // memory map is incorrect or because another application has |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
420 // spuriously written to the flash or ... who knows what. First |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
421 // we check to see if the reason is that we are dealing with a |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
422 // (really) old ffs format version. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
423 if (obhp->magic_low == OLD_BLOCK_MAGIC_LOW && |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
424 obhp->magic_high == OLD_FFS_FORMAT_VERSION) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
425 tw(tr(TR_FUNC, TrFsck, "OLD ")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
426 fs.format = obhp->magic_high; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
427 // We simulate that all the blocks are data blocks, in order |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
428 // to have some well-defined state that preformat() can work |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
429 // on. Later we will return EFFS_BADFORMAT and otherwise |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
430 // leave everything as it is, *without* modifying anything! |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
431 bstat[b].flags = BF_IS_DATA; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
432 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
433 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
434 // Quickly test if block is in empty state. We do not make a |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
435 // full check with block_used() because that takes too |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
436 // long --- we let preformat() do that. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
437 if (bhp->magic_low == FLASH_NULL16 && |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
438 bhp->magic_high == FLASH_NULL16 && |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
439 bhp->age == FLASH_NULL16 && |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
440 bhp->version == FLASH_NULL16 && |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
441 bhp->flags == FLASH_NULL16) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
442 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
443 bstat[b].used = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
444 bstat[b].lost = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
445 bstat[b].flags = BF_IS_EMPTY; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
446 tw(tr(TR_FUNC, TrFsck, "EMPTY ")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
447 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
448 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
449 // If the block is not free, it is probably corrupted. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
450 // Thus we reset its age and free it. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
451 tw(tr(TR_FUNC, TrFsck, "magic = 0x%08x\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
452 bhp->magic_low | (bhp->magic_high << 16))); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
453 ffsdrv.write_halfword(&bhp->age, 0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
454 block_free(b); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
455 tw(tr(TR_FUNC, TrFsck, "BAD ")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
456 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
457 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
458 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
459 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
460 fs.format = bhp->version; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
461 age_valid = 1; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
462 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
463 if (!is_block(b, BF_IS_FREE)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
464 bstat[b].used = block_used(b); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
465 bstat[b].lost = bstat[b].used - BHEADER_SIZE; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
466 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
467 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
468 if (is_block(b, BF_IS_FREE)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
469 // The only case where we do not call block_used() is |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
470 // when the block is truly free. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
471 bstat[b].used = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
472 bstat[b].lost = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
473 tw(tr(TR_FUNC, TrFsck, "FREE ")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
474 ttw(ttr(TTrInitLow, "FREE" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
475 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
476 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
477 else if (is_block(b, BF_IS_DATA)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
478 tw(tr(TR_FUNC, TrFsck, "DATA ")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
479 ttw(ttr(TTrInitLow, "DATA" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
480 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
481 else if (is_block(b, BF_IS_CLEANING)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
482 // Here we schedule a block_clean(). Note that we can |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
483 // and do not execute the block cleaning now, as the info |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
484 // that block_clean() needs is not at all ready at this |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
485 // point in the initialization. So we set a flag and then |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
486 // clean the block at the end of ffs_initialize() |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
487 tw(tr(TR_FUNC, TrFsck, "CLEANING ")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
488 ttw(ttr(TTrInitLow, "CLEANING" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
489 b_to_clean = b + 1; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
490 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
491 else if (is_block(b, BF_IS_COPYING)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
492 tw(tr(TR_FUNC, TrFsck, "COPYING ")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
493 ttw(ttr(TTrInitLow, "COPYING" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
494 fs.newinodes = b; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
495 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
496 else if (is_block(b, BF_IS_INODES)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
497 tw(tr(TR_FUNC, TrFsck, "INODES ")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
498 ttw(ttr(TTrInitLow, "INODES" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
499 fs.inodes = b; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
500 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
501 else if (is_block(b, BF_IS_INODES_LOST)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
502 tw(tr(TR_FUNC, TrFsck, "INODESLOST")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
503 ttw(ttr(TTrInitLow, "INODESLOST" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
504 b_inode_lost = b; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
505 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
506 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
507 block_free(b); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
508 tw(tr(TR_FUNC, TrFsck, "INVALID ")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
509 ttw(ttr(TTrInitLow, "INVALID" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
510 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
511 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
512 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
513 tw(tr(TR_NULL, TrFsck, " %2d: (0x%05x) %02x, used = %6d\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
514 b, dev.binfo[b].offset, bstat[b].flags & 0xFF, bstat[b].used)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
515 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
516 if (age_valid) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
517 if (age_min == 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
518 // Initialize minimum and maximum block ages |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
519 age_min = age_max = bhp->age; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
520 tw(tr(TR_FUNC, TrFsckLow, "age_min/max = %d\n", age_min)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
521 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
522 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
523 age_dist_min = age_distance(bhp->age, age_min); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
524 age_dist_max = age_distance(bhp->age, age_max); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
525 if (age_dist_min > age_dist || |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
526 age_dist_max > age_dist) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
527 if (age_dist_max > age_dist_min) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
528 age_dist = age_dist_max; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
529 age_min = bhp->age; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
530 tw(tr(TR_FUNC, TrFsckLow, "age_min = %d (dist = %d)\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
531 age_min, age_dist)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
532 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
533 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
534 age_dist = age_dist_min; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
535 age_max = bhp->age; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
536 tw(tr(TR_FUNC, TrFsckLow, "age_max = %d (dist = %d)\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
537 age_max, age_dist)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
538 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
539 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
540 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
541 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
542 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
543 tlw(led_off(LED_DRV_INIT)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
544 tw(tr(TR_FUNC, TrFsck, "age min, max, max-min = %d, %d, %d\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
545 age_min, age_max, (uint16) (age_max-age_min))); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
546 // If age_max is untouched is is because all blocks were in the 'Empty' |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
547 // state. In this case we let the age be as it is (0xFFFF). |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
548 if (age_max == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
549 age_max = age_min = BLOCK_AGE_MAX; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
550 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
551 // Handle age wrap around thus ensuring fs.age_max is set correctly. We |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
552 // have to type-cast the whole computation, otherwise it will be |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
553 // incorrect. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
554 if ((age_t) (age_max - age_min) > 0x8000) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
555 age_dist = age_max; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
556 age_max = age_min; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
557 age_min = age_dist; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
558 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
559 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
560 // save maximum age found for the case of a bad block that is going to |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
561 // be reclaimed later on by blocks_reclaim() |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
562 fs.age_max = age_max; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
563 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
564 tw(tr(TR_FUNC, TrFsck, "fs.format = 0x%04x\n", fs.format)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
565 tw(tr(TR_FUNC, TrFsck, "fs.inodes, newinodes = %d, %d\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
566 fs.inodes, fs.newinodes)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
567 ttw(ttr(TTrInit, "fs.inodes, newinodes = %d, %d" NL, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
568 fs.inodes, fs.newinodes)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
569 tw(tr(TR_FUNC, TrFsck, "age min, max = %d, %d\n", age_min, age_max)); |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
570 |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
571 // If any blocks were in the EMPTY state, now is the time to bring them |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
572 // into the FREE state. Note that we must only do this *after* |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
573 // fs.age_max has been initialized. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
574 for (b = 0; b < dev.numblocks; b++) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
575 if (is_block(b, BF_IS_EMPTY)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
576 if ((bstat[b].used = block_used(b)) == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
577 block_preformat(b, 0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
578 else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
579 block_free(b); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
580 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
581 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
582 |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
583 if (fs.inodes >= 0) { |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
584 // The 'old' inode block is still valid thus we keep it. |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
585 if (fs.newinodes >= 0) |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
586 // The copying of inodes to the new block was not finished thus |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
587 // we free the block |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
588 block_free(fs.newinodes); |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
589 inodes_set(fs.inodes); |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
590 } |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
591 else { |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
592 // Copying must have been finished |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
593 if (fs.newinodes >= 0 && b_inode_lost >= 0) { |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
594 // The inode reclaim did finish but currently there is no valid |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
595 // inode block thus the operation must be finished by committing |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
596 // the new block as the valid inode block. |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
597 fs.inodes = b_inode_lost; |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
598 block_commit(); |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
599 } |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
600 else { |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
601 // No old or new Inode block! |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
602 tw(tr(TR_END, TrFsck, "} %d\n", EFFS_NOFORMAT)); |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
603 ttw(ttr(TTrInitLow, "} %d" NL, EFFS_NOFORMAT)); |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
604 return EFFS_NOFORMAT; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
605 } |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
606 } |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
607 |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
608 if ((fs.format >> 8) != (FFS_FORMAT_VERSION >> 8)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
609 tw(tr(TR_END, TrFsck, "} %d\n", EFFS_BADFORMAT)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
610 ttw(ttr(TTrInitLow, "} %d" NL, EFFS_BADFORMAT)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
611 return EFFS_BADFORMAT; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
612 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
613 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
614 // FIXME: Insert age sanity check; age distance must not be too big (> 2 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
615 // * FFS_AGE_DISTANCE)? |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
616 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
617 tw(tr(TR_END, TrFsck, "} %d\n", b_to_clean)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
618 ttw(ttr(TTrInitLow, "} %d" NL, b_to_clean)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
619 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
620 return b_to_clean; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
621 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
622 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
623 // Set fs.inodes and fs.inodes_addr |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
624 void inodes_set(iref_t i) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
625 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
626 fs.inodes = i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
627 fs.inodes_addr = (struct inode_s *) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
628 (offset2addr(dev.binfo[fs.inodes].offset) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
629 + dev.atomsize - sizeof(struct inode_s)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
630 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
631 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
632 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
633 /****************************************************************************** |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
634 * inodes_fsck() |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
635 ******************************************************************************/ |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
636 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
637 // Now for each inode in the inodes block, update the bstat array |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
638 // information: free, used, objects. Also, locate the root inode. We could |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
639 // optimize this a little, because bstat[binodes].used gives an inidication |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
640 // of how many inodes are actually present in the system. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
641 iref_t inodes_fsck(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
642 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
643 iref_t i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
644 struct inode_s *ip; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
645 char *addr; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
646 bref_t block; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
647 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
648 ttw(str(TTrInitLow, "inodes_fsck {" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
649 tw(tr(TR_BEGIN, TrFsck, "inodes_fsck() {\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
650 tw(tr(TR_FUNC, TrFsck, "inodes in block %d:\n", fs.inodes)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
651 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
652 // the fields of the bstat entry for the inodes have the meaning: |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
653 // used = total number of used inodes (valid, erased, invalid) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
654 // lost = total number of lost inodes (erased, invalid) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
655 // objects = index of first free inode (used by inode_alloc()) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
656 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
657 fs.root = 0; // default to root inode not found |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
658 fs.ijournal = 0; // default to journal file inode not found |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
659 bstat[fs.inodes].objects = 1; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
660 bstat[fs.inodes].used = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
661 bstat[fs.inodes].lost = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
662 fs.sequence = 0; // just for debug (fun) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
663 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
664 // we must set some default value for this, so we set it to max possible! |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
665 fs.inodes_max = dev.blocksize / sizeof(struct inode_s); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
666 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
667 ip = inode_addr(1); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
668 tw(tr(TR_FUNC, TrFsck, " i addr cld sib seq upd flag size name\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
669 for (i = 1; i < fs.inodes_max; i++, ip++) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
670 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
671 // just for debug (fun) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
672 if (ip->sequence > fs.sequence) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
673 fs.sequence = ip->sequence; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
674 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
675 // compute block index and total data space occupied |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
676 block = offset2block(location2offset(ip->location)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
677 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
678 // Only scan used inodes. blocks_fsck() accounted all used space as |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
679 // also being lost space, so now we subtract from the lost space, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
680 // the space used by valid objects |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
681 if (ip->location != FLASH_NULL32) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
682 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
683 bstat[fs.inodes].used++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
684 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
685 tw(tr(TR_FUNC, TrFsck, "%3d 0x%05X %3d %3d %4d %3d %s%s%s%s%s%s %6d %s\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
686 i, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
687 location2offset(ip->location), |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
688 ip->child, ip->sibling, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
689 ip->sequence, ip->updates, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
690 is_object(ip, OT_DIR) ? "d" : "", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
691 is_object(ip, OT_LINK) ? "l" : "", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
692 is_object(ip, OT_FILE) ? "f" : "", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
693 is_object(ip, OT_SEGMENT) ? "s" : "", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
694 is_object(ip, OT_ERASED) ? " " : "", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
695 IS_BIT_SET(ip->flags, OF_READONLY) && !is_object(ip, OT_ERASED) ? |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
696 "r" : " ", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
697 ip->size, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
698 // Erased chunks do not have any name so we can not trace erased objects! |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
699 (ip->size && !is_object(ip, OT_SEGMENT) && !is_object(ip, OT_ERASED) ? |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
700 addr2name(offset2addr(location2offset(ip->location))) : "") |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
701 )); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
702 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
703 if (is_object_valid(ip)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
704 // This inode is valid, so we account the data space as used |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
705 // and the inode as used too. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
706 bstat[block].lost -= ip->size; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
707 bstat[block].objects++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
708 // test if this is the root inode. store index if it is. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
709 if (!is_object(ip, OT_SEGMENT)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
710 addr = addr2name(offset2addr(location2offset(ip->location))); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
711 if (*addr == '/') |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
712 fs.root = i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
713 else if (*addr == '.' && |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
714 ffs_strcmp(addr, FFS_JOURNAL_NAME) == 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
715 fs.ijournal = i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
716 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
717 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
718 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
719 else if (is_object(ip, OT_ERASED)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
720 // this inode's data is deleted, so we account the data |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
721 // space as used and lost and the inode as lost too. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
722 bstat[fs.inodes].lost++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
723 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
724 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
725 // This is an invalid object, so we account the data space |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
726 // as used and lost and the inode as lost too. NOTEME: error |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
727 // what should we do? Perhaps we should record semi-lost |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
728 // inodes? Can we safely account for it here if this is an |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
729 // object to be recovered because another inode.copied is |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
730 // referring to this? Will used/lost etc. be updated |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
731 // correctly then? |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
732 bstat[fs.inodes].lost++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
733 tw(tr(TR_NULL, TrFsck, "(invalid = %d)\n", ip->flags & OT_MASK)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
734 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
735 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
736 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
737 ttw(ttr(TTrInit, "fs.root=%d, journal=%d" NL, fs.root, fs.ijournal)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
738 tw(tr(TR_END, TrFsck, "} used: %d, lost: %d, root: %d, journal: %d\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
739 bstat[fs.inodes].used, bstat[fs.inodes].lost, fs.root, fs.ijournal)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
740 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
741 fs.sequence++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
742 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
743 tw(tr_bstat()); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
744 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
745 if (fs.root == 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
746 ttw(ttr(TTrInitLow, "} %d" NL, EFFS_NOFORMAT)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
747 return EFFS_NOFORMAT; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
748 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
749 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
750 ttw(str(TTrInitLow, "} 0" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
751 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
752 return EFFS_OK; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
753 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
754 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
755 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
756 /****************************************************************************** |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
757 * Preformat and format |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
758 ******************************************************************************/ |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
759 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
760 // Prepare all blocks for fs_format(). Because ffs_is_formattable() has |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
761 // already been called prior to this function, we know that no sector erase |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
762 // is in progress! The blocks are prepared by putting them into the 'Free' |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
763 // state. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
764 effs_t fs_preformat(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
765 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
766 bref_t b; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
767 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
768 ttw(str(TTrFormat, "preformat {" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
769 tw(tr(TR_BEGIN, TrFormat, "fs_preformat() {\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
770 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
771 // Mark ffs as being non-formatted from now on. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
772 fs.root = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
773 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
774 // We must initialize bstat[fs.inodes].used and inodes_high, such that |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
775 // inodes_reclaim() isn't triggered in reclaim() on the following |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
776 // fs_format(). |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
777 inodes_set(0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
778 bstat[fs.inodes].used = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
779 bstat[fs.inodes].lost = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
780 bstat[fs.inodes].objects = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
781 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
782 // While format is in progress, we make FFS inaccessible to other |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
783 // functions... |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
784 fs.initerror = EFFS_NOFORMAT; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
785 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
786 if (dev.manufact == 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
787 b = EFFS_NODEVICE; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
788 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
789 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
790 for (b = 0; b < dev.numblocks; b++) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
791 if (is_block(b, BF_IS_EMPTY)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
792 if ((bstat[b].used = block_used(b)) == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
793 block_preformat(b, 0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
794 else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
795 block_free(b); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
796 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
797 else if (!is_block(b, BF_IS_FREE)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
798 block_free(b); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
799 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
800 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
801 b = EFFS_OK; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
802 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
803 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
804 tw(tr(TR_END, TrFormat, "} %d\n", b)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
805 ttw(ttr(TTrFormat, "} %d" NL, b)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
806 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
807 return b; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
808 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
809 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
810 // Preformat a single block thus taking it from the 'Empty' state into |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
811 // 'Free' state. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
812 void block_preformat(bref_t b, age_t age) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
813 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
814 int set_age_max; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
815 struct block_header_s *bhp = |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
816 (struct block_header_s *) offset2addr(dev.binfo[b].offset); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
817 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
818 tw(tr(TR_BEGIN, TrFormat, "fs_block_preformat(%d, %d)\n", b, age)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
819 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
820 if (age == 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
821 age = fs.age_max; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
822 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
823 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
824 // We schedule an update of fs.age_max. Due to proper handling of |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
825 // age wrap-around, we can not actually set it now. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
826 set_age_max = (age == fs.age_max); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
827 age++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
828 if (age == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
829 age++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
830 if (set_age_max) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
831 fs.age_max = age; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
832 tw(tr(TR_FUNC, TrFormat, "new fs.age_max = %d\n", fs.age_max)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
833 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
834 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
835 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
836 ffsdrv.write_halfword(&bhp->age, age); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
837 ffsdrv.write_halfword(&bhp->version, FFS_FORMAT_VERSION); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
838 ffsdrv.write_halfword(&bhp->magic_low, BLOCK_MAGIC_LOW); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
839 ffsdrv.write_halfword(&bhp->magic_high, BLOCK_MAGIC_HIGH); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
840 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
841 bstat[b].flags = BF_IS_EMPTY; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
842 bstat[b].used = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
843 bstat[b].lost = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
844 bstat[b].objects = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
845 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
846 block_flags_write(b, BF_FREE); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
847 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
848 tw(tr(TR_END, TrFormat, "")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
849 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
850 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
851 // After preformat() has erased two blocks, this function can be called to |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
852 // initialize ffs by writing fs data and metadata. Note that ffs_begin() is |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
853 // *not* called before this function in ffs.c. Otherwise we would never |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
854 // enter this function because fs.root is zero. NOTEME: this is also a bug |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
855 // as this means we risk that this operation is started while an erase (or a |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
856 // write) is in progress! How the flash device reacts to this is currently |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
857 // unknown. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
858 effs_t fs_format(const char *name) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
859 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
860 bref_t i, b; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
861 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
862 ttw(str(TTrFormat, "format {" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
863 tw(tr(TR_BEGIN, TrFormat, "fs_format('%s') {\n", name)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
864 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
865 // Initialize file system parameters. It should be safe to change these |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
866 // now, as the format cannot fail at this point onwards. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
867 fs_params_init(name); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
868 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
869 // Make the first block be the inodes block |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
870 if ((fs.inodes = block_alloc(1, BF_COPYING)) < 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
871 return EFFS_AGAIN; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
872 block_flags_write(fs.inodes, BF_INODES); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
873 inodes_set(fs.inodes); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
874 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
875 // Make all block as data blocks except from the free_min and inode block |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
876 for (i = 0; i < dev.numblocks - fs.blocks_free_min - 1; i++) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
877 if ((b = block_alloc(0, BF_DATA)) < 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
878 return EFFS_AGAIN; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
879 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
880 // Restart object sequencing (debug feature only) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
881 fs.sequence = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
882 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
883 // Create root directory |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
884 journal_begin(0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
885 if ((fs.root = object_create(name, 0, 0, 0)) < 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
886 tw(tr(TR_END, TrFormat, "} %d\n", fs.root)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
887 return fs.root; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
888 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
889 journal_commit(OT_DIR); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
890 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
891 if ((fs.ijournal = journal_create(0)) < 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
892 tw(tr(TR_END, TrFormat, "} %d\n", fs.ijournal)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
893 return fs.ijournal; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
894 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
895 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
896 fs.initerror = ffs_initialize(); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
897 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
898 ttw(ttr(TTrFormat, "} %d" NL, fs.initerror)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
899 tw(tr(TR_END, TrFormat, "} %d\n", fs.initerror)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
900 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
901 return fs.initerror; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
902 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
903 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
904 // Check if we are ready to preformat (flag = 0) or format (flag = 1) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
905 // |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
906 // For a format, we must first ensure no blocks are valid e.g. a preformat |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
907 // has already been run. Next, we must ensure we have preformatted all |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
908 // blocks e.g. all blocks are in the 'Free' state. This is actually the same |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
909 // thing but it sure helps the user because it yields a more precise error |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
910 // code when the format fails. In future we might be able to start a format |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
911 // when only two blocks have been preformatted, but this is harder because |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
912 // we have to make sure not to read from the physical sector that we are |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
913 // erasing, and this is exactly what ffs_ffs_initialize() currently does |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
914 // (when it is called at the end of format()). |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
915 // |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
916 // For a preformat, we must ensure an erase is not in progress (because we |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
917 // don't know how the device will react to a new erase when an erase is |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
918 // currently suspended). |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
919 effs_t is_formattable(int8 flag) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
920 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
921 bref_t i, free, valid; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
922 effs_t error = EFFS_OK; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
923 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
924 tw(tr(TR_FUNC, TrFormat, "is_formattable() ")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
925 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
926 // Count the number of valid and free blocks. These numbers will later |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
927 // be checked to see if we are really ready for a (pre)format(). Note |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
928 // that we *only* read block flags from the bstat[] array. We must not |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
929 // read directly from the flash sectors because an erase might be in |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
930 // progress! |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
931 for (i = 0, free = 0, valid = 0; i < dev.numblocks; i++) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
932 if (is_block(i, BF_IS_DATA) || is_block(i, BF_IS_INODES)) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
933 valid++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
934 if (is_block(i, BF_IS_FREE)) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
935 free++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
936 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
937 if (flag == 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
938 // In the case of a preformat, ensure an erase is not in |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
939 // progress (because we don't know how the device will react to a new |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
940 // erase when an erase is currently suspended). |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
941 if (dev.state == DEV_ERASE || dev.state == DEV_ERASE_SUSPEND) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
942 tw(tr(TR_NULL, TrFormat, "(%d)\n", EFFS_AGAIN)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
943 return EFFS_AGAIN; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
944 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
945 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
946 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
947 if (valid > 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
948 // Ensure we have preformatted prior to a format. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
949 error = EFFS_NOPREFORMAT; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
950 else if (free < dev.numblocks) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
951 // Ensure all blocks are free before a format(). If not, a |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
952 // preformat() is currently in progress. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
953 error = EFFS_AGAIN; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
954 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
955 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
956 tw(tr(TR_NULL, TrFormat, "(%d)\n", error)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
957 return error; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
958 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
959 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
960 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
961 /****************************************************************************** |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
962 * Journalling |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
963 ******************************************************************************/ |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
964 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
965 // The following matrix illustrates how the members of an inode change for |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
966 // the various (journalled) operations: |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
967 // |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
968 // | flags | size | loc | child | siblg | dir | oldi | updates |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
969 // ---------+-------+------+-----+-------+-------+-----+------+-------- |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
970 // create | new | new | new | - | - | ins | n/a | 0 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
971 // fupdate | o | new | new | o | - | ins | del | old+1 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
972 // relocate | o | o | new | o | - | ins | del | old+1 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
973 // fctrl | new | o | o | o | - | ins | del | old+1 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
974 // remove | n/a | n/a | n/a | n/a | n/a | n/a | del | n/a |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
975 // |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
976 // - = leave empty (0xFFFF) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
977 // ins = insert/append into directory |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
978 // o = old value |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
979 // |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
980 // We don't have to store child member in the journal entry because either |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
981 // it is EMPTY (fs.journal.oldi = 0) or it is retrieved from oldip->child. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
982 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
983 // NOTEME: With journalling implemented, object_relocate might be able just |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
984 // to make a simple data copy! |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
985 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
986 // block_clean() is safe (without journalling), now that only ip->size is |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
987 // set to zero. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
988 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
989 // Begin a new journal. Either a fresh object create (oldi == 0) or an |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
990 // update of an existing object (oldi == iref of old object) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
991 void journal_begin(iref_t oldi) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
992 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
993 tw(tr(TR_FUNC, TrJournal, "journal_begin(%d)\n", oldi)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
994 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
995 fs.journal.i = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
996 fs.journal.state = JOURNAL_IS_EMPTY; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
997 fs.journal.repli = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
998 fs.link_child = 1; //Default link child in journal_commit() |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
999 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1000 if (oldi == 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1001 fs.journal.flags = 0xFF; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1002 fs.journal.diri = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1003 fs.journal.oldi = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1004 fs.journal.location = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1005 fs.journal.size = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1006 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1007 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1008 struct inode_s *oldip = inode_addr(oldi); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1009 fs.journal.flags = oldip->flags; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1010 fs.journal.diri = oldi; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1011 fs.journal.oldi = oldi; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1012 fs.journal.location = oldip->location; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1013 fs.journal.size = oldip->size; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1014 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1015 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1016 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1017 // NOTEME: We have compressed the macro code because it will NOT compile on |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1018 // Unix otherwise. So until we find out why, we use this as a work-around. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1019 #if (FFS_TEST == 1) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1020 #define JOURNAL_TEST(testcase, text) if (fs.testflags == testcase) { tw(tr(TR_END, TrJournal, "} (" text ")\n")); return; } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1021 #else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1022 #define JOURNAL_TEST(testcase, text) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1023 #endif |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1024 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1025 // NOTEME: Should we empty journal file when we are anyway relocating it in |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1026 // data_reclaim()? |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1027 void journal_end(uint8 type) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1028 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1029 struct inode_s *ip = inode_addr(fs.ijournal); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1030 struct journal_s *addr = (struct journal_s *) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1031 offset2addr(location2offset(ip->location) + fs.journal_pos); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1032 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1033 tw(tr(TR_BEGIN, TrJournal, "journal_end(0x%x) {\n", type)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1034 tw(tr(TR_FUNC, TrJournal, "journal_pos = 0x%04x (%d)\n", fs.journal_pos, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1035 (fs.journal_pos - JOURNAL_POS_INITIAL) / sizeof(struct journal_s))); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1036 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1037 // If this is a create, set the object type |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1038 if (type != 0 && fs.journal.oldi == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1039 fs.journal.flags = (fs.journal.flags & OF_MASK) | type; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1040 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1041 // If there is no journal file, we can do without it, although we |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1042 // certainly don't like it! |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1043 if (fs.ijournal == 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1044 journal_commit(0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1045 tw(tr(TR_END, TrJournal, "} No jounal file\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1046 return; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1047 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1048 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1049 JOURNAL_TEST(JOURNAL_TEST_EMPTY, "Oops in JOURNAL_IS_EMPTY"); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1050 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1051 // Write RAM journal to journal file. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1052 if (fs.journal.state == (uint8) JOURNAL_IS_EMPTY) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1053 fs.journal.state = JOURNAL_IS_WRITING; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1054 ffsdrv.write(addr, &fs.journal, sizeof(fs.journal)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1055 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1056 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1057 JOURNAL_TEST(JOURNAL_TEST_WRITING, "Oops in JOURNAL_IS_WRITING"); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1058 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1059 // Advance journal file's state |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1060 if (fs.journal.state == (uint8) JOURNAL_IS_WRITING) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1061 fs.journal.state = JOURNAL_IS_READY; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1062 ffsdrv_write_byte(&addr->state, fs.journal.state); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1063 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1064 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1065 JOURNAL_TEST(JOURNAL_TEST_READY, "Oops in JOURNAL_IS_READY"); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1066 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1067 journal_commit(0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1068 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1069 JOURNAL_TEST(JOURNAL_TEST_COMMITTING, "Oops in JOURNAL_TEST_COMMITTING"); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1070 JOURNAL_TEST(JOURNAL_TEST_COMMITTED, "Oops in JOURNAL_COMMITTED"); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1071 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1072 // Advance journal file's state |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1073 ffsdrv_write_byte(&addr->state, JOURNAL_IS_DONE); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1074 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1075 JOURNAL_TEST(JOURNAL_TEST_DONE, "Oops in JOURNAL_IS_DONE"); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1076 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1077 // Advance journal |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1078 fs.journal_pos += sizeof(struct journal_s); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1079 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1080 // Unless we are currently relocating the journal file itself, check if |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1081 // journal file is near full and relocate it if it is. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1082 if (fs.journal_pos >= fs.journal_size - FFS_JOURNAL_MARGIN * |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
1083 sizeof(struct journal_s) && fs.journal.oldi != fs.ijournal) { |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1084 tw(tr(TR_FUNC, TrJournal, "Journal file (near) full!\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1085 journal_create(fs.ijournal); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1086 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1087 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1088 // Check if we have just committed the journal file itself |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1089 if (fs.journal.oldi == fs.ijournal) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1090 fs.journal_pos = JOURNAL_POS_INITIAL; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1091 fs.ijournal = fs.journal.i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1092 tw(tr(TR_FUNC, TrJournal, "Journal file re-created, fs.ijournal = %d\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1093 fs.ijournal)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1094 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1095 tw(tr(TR_END, TrJournal, "}\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1096 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1097 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1098 // Write contents of fs.journal to FFS meta data (inodes). Note that we do |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1099 // NOT traverse ip->copied as we used to do in the old |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1100 // object_update_commit(). Also, we do not check if object has been |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1101 // erased after traversing ip->copied. All this code has been removed |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1102 // because we will very soon have full callback functionality and thus the |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1103 // code is redundant. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1104 void journal_commit(uint8 type) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1105 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1106 struct inode_s *ip = inode_addr(fs.journal.i); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1107 struct inode_s *oldip = inode_addr(fs.journal.oldi); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1108 struct inode_s *dp; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1109 bref_t b; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1110 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1111 tw(tr(TR_BEGIN, TrJournal, "journal_commit(%d) {\n", type)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1112 tw(tr(TR_FUNC, TrJournal, "i = %d\n", fs.journal.i)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1113 ttw(ttr(TTrObj, "jc(){" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1114 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1115 if (fs.journal.i) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1116 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1117 // If this is a create, set the object type |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1118 if (type != 0 && fs.journal.oldi == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1119 fs.journal.flags = (fs.journal.flags & OF_MASK) | type; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1120 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1121 tw(tr(TR_FUNC, TrJournal, "loc = 0x%04x, size = %d\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1122 fs.journal.location, fs.journal.size)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1123 ffsdrv.write((uint32 *) &ip->location, (uint32 *) &fs.journal.location, sizeof(location_t)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1124 ffsdrv.write_halfword((uint16 *) &ip->size, fs.journal.size); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1125 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1126 if (fs.journal.oldi != 0 && fs.link_child != 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1127 // If this is an update, we copy the child member from old |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1128 // inode. We must do this before we validate the new object, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1129 // otherwise an intermediate readdir() will detect an empty |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1130 // directory! |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1131 ffsdrv.write_halfword((uint16*) &ip->child, oldip->child); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1132 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1133 tw(tr(TR_FUNC, TrJournal, "seq = %d\n", fs.sequence)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1134 // We must check if sequence is already written because if this |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1135 // commit was inititiated by journal_init(), we don't know exactly |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1136 // what was written |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1137 if (ip->sequence == FLASH_NULL16) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1138 ffsdrv.write_halfword(&ip->sequence, fs.sequence++); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1139 if (fs.journal.oldi == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1140 ffsdrv.write_halfword(&ip->updates, 0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1141 else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1142 ffsdrv.write_halfword(&ip->updates, oldip->updates + 1); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1143 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1144 JOURNAL_TEST(JOURNAL_TEST_COMMITTING, "Oops in JOURNAL_TEST_COMMITTING") |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1145 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1146 // Insert object into directory structure. We must do this before |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1147 // deleting old object, otherwise an intermediate readdir() will |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1148 // fail with EFFS_NOTFOUND. Note that when the root directory is |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1149 // created, fs.journal.diri is zero --- thus the test! |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1150 if (fs.journal.diri != 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1151 tw(tr(TR_FUNC, TrJournal, "diri = %d ", fs.journal.diri)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1152 if (fs.journal.diri < 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1153 tw(tr(TR_NULL, TrJournal, "child\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1154 dp = inode_addr(-fs.journal.diri); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1155 ffsdrv.write_halfword((uint16 *) &dp->child, fs.journal.i); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1156 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1157 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1158 tw(tr(TR_NULL, TrJournal, "sibling\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1159 dp = inode_addr(fs.journal.diri); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1160 ffsdrv.write_halfword((uint16 *) &dp->sibling, fs.journal.i); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1161 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1162 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1163 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1164 // The new object is validated before the old object is deleted. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1165 // This is in order to avoid an interrupting stat or read operation |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1166 // to fail with EFFS_NOTFOUND |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1167 tw(tr(TR_FUNC, TrJournal, "flags = 0x%02x\n", fs.journal.flags)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1168 ffsdrv_write_byte(&ip->flags, fs.journal.flags); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1169 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1170 // Update bstat[] appropriately |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1171 b = offset2block(location2offset(ip->location)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1172 bstat[b].objects++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1173 tw(tr(TR_FUNC, TrJournal, "bstat[%d].objects = %d\n", b, bstat[b].objects)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1174 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1175 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1176 tw(tr(TR_FUNC, TrJournal, "oldi = %d\n", fs.journal.oldi)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1177 if (fs.journal.oldi != 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1178 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1179 // If this is an update or an erase, we erase the old object |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1180 ffsdrv_write_byte(&oldip->flags, OT_ERASED); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1181 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1182 // Update bstat according to deletion of the old object. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1183 b = offset2block(location2offset(oldip->location)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1184 bstat[b].objects--; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1185 tw(tr(TR_FUNC, TrJournal, "bstat[%d].objects = %d\n", b, bstat[b].objects)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1186 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1187 // If we moved the data (all cases, except fcontrol), update lost |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1188 if (fs.journal.location != oldip->location) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1189 bstat[b].lost += oldip->size; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1190 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1191 bstat[fs.inodes].lost++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1192 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1193 // If we renamed a file to an existing filename, remove the replaced file. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1194 if (fs.journal.repli > 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1195 object_remove(fs.journal.repli); // Ignore error! |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1196 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1197 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1198 tw(tr(TR_END, TrJournal, "}\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1199 ttw(ttr(TTrObj, "}" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1200 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1201 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1202 // Save the current journal into "old" journal. We need this because an |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1203 // object_create() can call data_reclaim() which can call object_relocate() |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1204 // which uses the journal system. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1205 int journal_push(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1206 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1207 memcpy(&fs.ojournal, &fs.journal, sizeof(struct journal_s)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1208 fs.journal_depth++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1209 if (fs.journal_depth > 1) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1210 tw(tr(TR_FUNC, TrAll, "FATAL: journal_push() to depth %d\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1211 fs.journal_depth)); |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
1212 return -1; |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
1213 } |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1214 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1215 tw(tr(TR_FUNC, TrJournal, "journal_push() to depth %d\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1216 fs.journal_depth)); |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
1217 |
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
1218 return EFFS_OK; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1219 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1220 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1221 // Recall "old" journal into current journal |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1222 int journal_pop(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1223 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1224 tw(tr(TR_FUNC, TrJournal, "journal_pop() from depth %d\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1225 fs.journal_depth)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1226 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1227 fs.journal_depth--; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1228 if (fs.journal_depth < 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1229 tw(tr(TR_FUNC, TrAll, "FATAL: journal_pop() to depth %d\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1230 fs.journal_depth)); |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
1231 return -1; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1232 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1233 memcpy(&fs.journal, &fs.ojournal, sizeof(struct journal_s)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1234 |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
1235 return EFFS_OK; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1236 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1237 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1238 // Initialize the journalling system. Create journal file if it not already |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1239 // exist. Commit/write pending journal if such exists --- return 1 in that |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1240 // case. Otherwise, if journal file is clean (no journals pending) and all |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1241 // is fine, return EFFS_OK. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1242 effs_t journal_init(iref_t i) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1243 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1244 int j; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1245 struct inode_s *ip = inode_addr(i); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1246 struct journal_s *addr; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1247 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1248 if (i == 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1249 // Journal file does not exist, so create it |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1250 if ((i = journal_create(0)) <= 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1251 fs.ijournal = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1252 return i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1253 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1254 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1255 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1256 fs.journal_depth = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1257 fs.journal_pos = JOURNAL_POS_INITIAL; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1258 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1259 addr = (struct journal_s *) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1260 offset2addr(location2offset(ip->location) + fs.journal_pos); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1261 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1262 tw(tr(TR_BEGIN, TrJournal, "journal_init(%d) {\n", i)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1263 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1264 fs.ijournal = i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1265 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1266 // Search for first non-completed journal entry. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1267 for (j = 0; /* FIXME: limit to end of journal */; j++, addr++) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1268 if (addr->state != (uint8) JOURNAL_IS_DONE) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1269 break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1270 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1271 tw(tr(TR_FUNC, TrJournal, "entry %d is in state 0x%x\n", j, addr->state)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1272 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1273 fs.journal_pos += j * sizeof(fs.journal); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1274 i = EFFS_OK; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1275 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1276 if (addr->state == (uint8) JOURNAL_IS_EMPTY) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1277 tw(tr(TR_FUNC, TrJournal, "Last journal is in EMPTY state\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1278 // Journal file is proper, so just record position |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1279 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1280 else if (addr->state == (uint8) JOURNAL_IS_READY) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1281 // Copy the entry into fs.journal. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1282 tw(tr(TR_FUNC, TrJournal, "Last journal is in READY state\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1283 memcpy(&fs.journal, addr, sizeof(fs.journal)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1284 journal_end(0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1285 i = 1; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1286 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1287 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1288 // Journal entry wasn't finished, so just ignore it after updating |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1289 // its state to JOURNAL_IS_DONE. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1290 tw(tr(TR_FUNC, TrJournal, "Last journal is between EMPTY and READY\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1291 ffsdrv_write_byte(&addr->state, JOURNAL_IS_DONE); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1292 fs.journal_pos += sizeof(fs.journal); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1293 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1294 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1295 if (ip->size != fs.journal_size + atomalign(sizeof(FFS_JOURNAL_NAME) + 1)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1296 tw(tr(TR_FUNC, TrJournal, "Wrong journal size, create new\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1297 // Journal size do not match default size, so create new. This |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1298 // should only happen if we use an old FFS image with a newer FFS |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1299 // version. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1300 if ((i = journal_create(fs.ijournal)) <= 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1301 fs.ijournal = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1302 return i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1303 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1304 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1305 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1306 tw(tr(TR_FUNC, TrJournal, "journal_pos = 0x%04x\n", fs.journal_pos)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1307 tw(tr(TR_END, TrJournal, "} %d\n", i)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1308 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1309 return i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1310 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1311 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1312 // Create the journal file from scratch or relocate an existing one. It is |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1313 // marked read-only just for clarity --- it cannot be deleted anyway! |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1314 // fs_format() calls this function. Note that no data are written in |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1315 // object_create() because the journal file is handled specially in that |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1316 // function. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1317 iref_t journal_create(iref_t oldi) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1318 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1319 iref_t i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1320 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1321 tw(tr(TR_BEGIN, TrJournal, "journal_create(%d) {\n", oldi)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1322 tw(tr(TR_FUNC, TrJournal, "journal file size = %d\n", fs.journal_size)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1323 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1324 if (fs.journal_size == 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1325 tw(tr(TR_FUNC, TrJournal, "Journal file creation aborted because fs.journal_size = 0 (No journal file wanted)\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1326 tw(tr(TR_END, TrJournal, "} %d\n", 0)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1327 return 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1328 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1329 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1330 // If we are working on a write-once file system, we do not need a |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1331 // journal. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1332 if (fs.blocks_free_min == 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1333 tw(tr(TR_FUNC, TrJournal, "Journal file creation aborted because fs.blocks_free_min = 0 (write-once system)\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1334 tw(tr(TR_END, TrJournal, "} %d\n", 0)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1335 return 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1336 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1337 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1338 journal_begin(oldi); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1339 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1340 i = object_create(FFS_JOURNAL_NAME, 0, fs.journal_size, -fs.root); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1341 if (i < 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1342 tw(tr(TR_END, TrJournal, "} %d\n", i)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1343 return i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1344 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1345 fs.journal.flags = BIT_SET(fs.journal.flags, OF_READONLY); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1346 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1347 // commit the creation or relocation |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1348 if (oldi != 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1349 journal_end(0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1350 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1351 journal_commit(OT_FILE); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1352 fs.journal_pos = JOURNAL_POS_INITIAL; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1353 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1354 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1355 tw(tr(TR_END, TrJournal, "} %d\n", i)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1356 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1357 return i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1358 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1359 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1360 /****************************************************************************** |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1361 * FFS Begin and End |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1362 ******************************************************************************/ |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1363 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1364 // The following two functions should surround the code of every API |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1365 // function in ffs.c (except preformat and format). The functions |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1366 // ensures that the operation about to be executed can be made without |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1367 // race-conditions or other problems. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1368 #if (TARGET == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1369 int debug_suspend = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1370 #endif |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1371 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1372 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1373 // Check if ffs has been initialized. Suspend an erase operation. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1374 effs_t ffs_begin(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1375 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1376 #if (TARGET == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1377 if (debug_suspend > 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1378 tw(tr(TR_FUNC, TrAll, "FATAL: Previous erase_suspend was not resumed\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1379 return EFFS_CORRUPTED; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1380 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1381 // tw(tr(TR_FUNC, TrHelper, "Set debug_suspend\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1382 debug_suspend = 1; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1383 #endif |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1384 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1385 if (fs.initerror != EFFS_OK) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1386 return fs.initerror; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1387 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1388 // Suspend an erase in progress (only applicable if we are using a |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1389 // multi-bank device driver) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1390 if (dev.state == DEV_ERASE) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1391 ffsdrv.erase_suspend(); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1392 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1393 else if (dev.state == DEV_WRITE) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1394 ffsdrv.write_end(); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1395 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1396 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1397 return EFFS_OK; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1398 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1399 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1400 // Resume an erase operation that was in progress. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1401 int ffs_end(int error) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1402 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1403 #if (TARGET == 1) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1404 // Resume an erase in progress (only applicable if we are using a |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1405 // multi-bank device driver) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1406 if (dev.state == DEV_ERASE_SUSPEND) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1407 ffsdrv.erase_resume(); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1408 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1409 #else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1410 debug_suspend = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1411 #endif |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1412 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1413 return error; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1414 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1415 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1416 /****************************************************************************** |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1417 * FFS Statistics functions |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1418 ******************************************************************************/ |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1419 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1420 // Not implemented: |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1421 int statistics_file_create(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1422 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1423 return 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1424 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1425 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1426 // Not implemented: |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1427 // Rewrite the statistics file if it exists. Otherwise return error |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1428 // code. The function is called after each data and inodes reclaim (after |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1429 // writing the file that provoked the reclaim). |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1430 int statistics_write(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1431 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1432 return 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1433 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1434 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1435 // Read the statistics file if it exists. Otherwise reset all statistics to |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1436 // zero and set the magic. This function is called from ffs_init(). |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1437 void statistics_init(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1438 { |
215
517dd86b45b1
gsm-fw/services/ffs: fsck.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
1439 memset(&stats, 0, sizeof(struct ffs_stats_s)); |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1440 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1441 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1442 void statistics_update_drec(int valid, int lost, int candidate) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1443 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1444 unsigned int old; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1445 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1446 switch (candidate) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1447 case MOST_LOST: stats.drec.most_lost++; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1448 case MOST_UNUSED: stats.drec.most_unused++; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1449 case YOUNGEST: stats.drec.youngest++; break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1450 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1451 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1452 // Increment Most Significant Word if overflow is detected |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1453 old = stats.drec.valid[0]; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1454 stats.drec.valid[0] += valid; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1455 if (old > stats.drec.valid[0]) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1456 stats.drec.valid[1]++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1457 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1458 old = stats.drec.lost[0]; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1459 stats.drec.lost[0] += lost; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1460 if (old > stats.drec.lost[0]) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1461 stats.drec.lost[1]++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1462 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1463 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1464 void statistics_update_irec(int valid, int lost) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1465 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1466 stats.irec.num++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1467 stats.irec.valid += valid; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1468 stats.irec.lost += lost; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1469 } |