annotate gsm-fw/services/ffs/fsck.c @ 213:ef7d7da61c56

FFS code integration: remaining C files imported, but not yet integrated
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 06 Jan 2014 04:20:29 +0000
parents
children 517dd86b45b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #ifndef TARGET
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "ffs.cfg"
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #endif
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 #include <string.h>
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 #include <assert.h>
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 #include "ffs/ffs.h"
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 #include "ffs/board/core.h"
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 #include "ffs/board/drv.h"
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 #include "ffs/board/ffstrace.h"
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 /******************************************************************************
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 * Functions
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 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
28 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
29
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 /******************************************************************************
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 * Init and Exit
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 ******************************************************************************/
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 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
35 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 bref_t b;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 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
38 int i;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 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
41 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
42 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
43 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
44
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 // 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
46 fs.root = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 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
48 fs.testflags = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 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
51 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
52 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
53 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
54 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
55 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
56 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
57 return fs.initerror;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 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
61 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 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
63 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
64 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
65 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
66 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
67 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
68 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
69 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
70 return fs.initerror;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81 return fs.initerror;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 }
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 // 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
85 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
86 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
87
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 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
89 break;
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
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 // Init all file_descriptors to zero
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 memset(fs.fd, 0, sizeof(struct file_descriptor_s) * fs.fd_max);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 // 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
96 // 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
97 if (b > 0) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 block_clean(b - 1);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 block_free(b - 1);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 statistics_init();
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 // 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
105 // 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
106 // 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
107 // 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
108
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 #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
110 #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
111 blocks_reclaim();
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 #endif
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 #else
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 blocks_reclaim();
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 #endif
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 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
117 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
118 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
119
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 return EFFS_OK;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 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
124 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 uint8 opt, digit;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 uint32 n;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 int numdatablocks;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 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
130
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131 // Compiled default values
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132 fs.filename_max = FFS_FILENAME_MAX;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133 fs.path_depth_max = FFS_PATH_DEPTH_MAX;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 fs.fd_max = FFS_FD_MAX;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 fs.journal_size = FFS_JOURNAL_SIZE_IN256THS;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 fs.flags = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 fs.testflags = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 // Flag that it not has been changed by an input arg.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 fs.block_files_max = 0;
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 // 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
143 // is approx. 90%.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 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
145
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 // 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
147 // 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
148 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
149
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 // Don't count free and inodes blocks
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 numdatablocks = dev.numblocks - fs.blocks_free_min - 1;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 // Abselute max number of inodes.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 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
155 if (fs.inodes_max > FFS_INODES_MAX)
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 fs.inodes_max = FFS_INODES_MAX;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 // MUST be true: objects_max <= inodes_max - block_files_max, this is do
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 // to the fact that we always need to have block_files_max number of
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 // inodes left when we run a data reclaim.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 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
162
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 // Find a suitable chunk_size
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 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
165 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
166 else
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 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
168 ? (dev.blocksize / 8)
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169 : 2048);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170 fs.fd_buf_size = 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
171
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172 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
173 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
174 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
175
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176 // 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
177 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
178 - 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
179
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180 // 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
181 // 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
182 // 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
183 // reserved_space.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
184 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
185 fs.block_files_max = fs.objects_max / 2 - 4;
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 // 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
188 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
189 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
190
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
191 // 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
192 // 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
193 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
194 numdatablocks * dev.blocksize / 16 + RESERVED_LOW;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
195
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
196 // 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
197 n = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
198 while (*p) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
199 if (*p++ == '/') {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
200 n++;
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 break;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
203 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
204 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
205 if (n == 2) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
206 // 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
207 while (*p) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
208 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
209 // collect option value...
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
210 n = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
211 while ((digit = *p)) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
212 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
213 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
214 p++;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
215 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
216 else
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
217 break;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
218 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
219 switch (opt) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
220 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
221 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
222 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
223 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
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231 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
232 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
233 // 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
234 default:
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
235 break;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
236 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
237 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
238 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
239
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
240 // 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
241
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
242 // No journal file thuse no reserved space.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
243 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
244 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
245 fs.reserved_space = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
246 fs.block_files_reserved = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
247 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
248
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
249 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
250 // 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
251 // input arg, recalculate.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
252 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
253 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
254
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
255 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
256 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
257
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
258 // Only one reserved is needed however we want a margin and set it to two
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
259 fs.block_files_reserved = 2;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
260 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
261
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
262 // Don't count free blocks, inode block, reserved space, block headers
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
263 // and the size of one filename.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
264 fs.filesize_max = numdatablocks * dev.blocksize - fs.reserved_space -
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
265 numdatablocks * BHEADER_SIZE - FFS_FILENAME_MAX;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
266
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
267 // Furthermore don't count the overhead from each chunk (alignment)
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
268 fs.filesize_max -= ((fs.filesize_max / fs.chunk_size_max) * dev.atomsize
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
269 + dev.atomsize);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
270
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
271 // NOTEME: chunk_size_min is never used
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
272 fs.chunk_size_min = numdatablocks / fs.objects_max;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
273
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, "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
275 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
276 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
277 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
278 tw(tr(TR_FUNC, TrFsck, "fs.block_files_max = %d\n", 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
279 tw(tr(TR_FUNC, TrFsck, "fs.block_files_reserved = %d\n", fs.block_files_reserved));
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.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
281 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
282 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
283 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
284 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
285 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
286 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
287 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
288 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
289 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
290 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
291
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
292 // 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
293 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
294 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
295 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
296
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
297
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
298 return EFFS_OK;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
299 }
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 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
302 // 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
303 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
304 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
305 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
306 return fs.initerror;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
307
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
308 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
309 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
310
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
311 // 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
312 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
313 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
314 char *name;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
315 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
316
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
317 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
318 return fs.initerror;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
319
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
320 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
321 return i;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
322
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
323 journal_begin(i);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
324
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
325 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
326 return i;
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 journal_end(0);
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 return EFFS_OK;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
331 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
332 #endif
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 /******************************************************************************
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
335 * blocks_fsck()
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
336 ******************************************************************************/
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
337
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
338 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
339 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
340 blocksize_t used;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
341 uint32 *p, *q;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
342
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
343 tlw(led_toggle(LED_BLOCKS_FSCK));
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
344
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
345 // 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
346 // 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
347 // 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
348 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
349 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
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 break;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
352 }
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 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
355 q += 4;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
356 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
357
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
358 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
359
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
360 return used;
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
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 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
365 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
366 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
367
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
368 if (a > 0x8000)
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
369 a = -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 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
372
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
373 return a;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
374 }
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 // 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
377 // 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
378 // 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
379 //
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
380 // 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
381 // 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
382 // 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
383 // 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
384 // 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
385 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
386 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
387 bref_t b, b_to_clean, b_inode_lost;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
388 int age_valid;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
389 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
390 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
391 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
392
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
393 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
394 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
395
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
396 // 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
397 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
398
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
399 fs.format = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
400 fs.inodes = -1;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
401 fs.newinodes = -1;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
402 b_inode_lost = -1;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
403 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
404
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
405 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
406 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
407 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
408
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
409 // 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
410 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
411 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
412
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
413 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
414 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
415 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
416 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
417
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
418 age_valid = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
419
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
420 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
421 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
422 // 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
423 // 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
424 // 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
425 // 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
426 // (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
427 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
428 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
429 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
430 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
431 // 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
432 // 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
433 // 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
434 // 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
435 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
436 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
437 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
438 // 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
439 // 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
440 // 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
441 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
442 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
443 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
444 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
445 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
446 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
447 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
448 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
449 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
450 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
451 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
452 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
453 // 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
454 // 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
455 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
456 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
457 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
458 block_free(b);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
459 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
460 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
461 }
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 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
464 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
465 age_valid = 1;
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 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
468 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
469 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
470 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
471
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
472 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
473 // 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
474 // 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
475 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
476 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
477 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
478 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
479
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_DATA)) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
482 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
483 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
484 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
485 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
486 // 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
487 // 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
488 // 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
489 // 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
490 // 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
491 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
492 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
493 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
494 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
495 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
496 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
497 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
498 fs.newinodes = b;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
499 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
500 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
501 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
502 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
503 fs.inodes = b;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
504 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
505 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
506 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
507 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
508 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
509 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
510 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
511 block_free(b);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
512 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
513 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
514 }
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
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
517 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
518 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
519
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
520 if (age_valid) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
521 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
522 // 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
523 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
524 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
525 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
526 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
527 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
528 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
529 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
530 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
531 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
532 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
533 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
534 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
535 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
536 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
537 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
538 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
539 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
540 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
541 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
542 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
543 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
544 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
545 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
546 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
547 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
548 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
549 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
550 // 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
551 // 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
552 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
553 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
554
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
555 // 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
556 // 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
557 // incorrect.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
558 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
559 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
560 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
561 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
562 }
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 // 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
565 // 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
566 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
567
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
568 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
569 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
570 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
571 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
572 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
573 tw(tr(TR_FUNC, TrFsck, "age min, max = %d, %d\n", age_min, age_max));
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
574
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
575 // 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
576 // 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
577 // 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
578 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
579 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
580 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
581 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
582 else
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
583 block_free(b);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
584 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
585 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
586
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
587 if (fs.inodes >= 0) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
588 // The 'old' inode block is still valid thus we keep it.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
589 if (fs.newinodes >= 0)
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
590 // 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
591 // we free the block
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
592 block_free(fs.newinodes);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
593 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
594 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
595 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
596 // Copying must have been finished
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
597 if (fs.newinodes >= 0 && b_inode_lost >= 0) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
598 // 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
599 // 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
600 // the new block as the valid inode block.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
601 fs.inodes = b_inode_lost;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
602 block_commit();
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
603
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
604 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
605 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
606 // No old or new Inode block!
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
607 tw(tr(TR_END, TrFsck, "} %d\n", EFFS_NOFORMAT));
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
608 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
609 return EFFS_NOFORMAT;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
610 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
611 }
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 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
614 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
615 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
616 return EFFS_BADFORMAT;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
617 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
618
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
619 // 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
620 // * FFS_AGE_DISTANCE)?
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 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
623 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
624
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
625 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
626 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
627
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
628 // 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
629 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
630 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
631 fs.inodes = i;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
632 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
633 (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
634 + 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
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
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
638 /******************************************************************************
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
639 * inodes_fsck()
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
640 ******************************************************************************/
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
641
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
642 // 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
643 // 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
644 // 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
645 // 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
646 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
647 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
648 iref_t i;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
649 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
650 char *addr;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
651 bref_t block;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
652
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
653 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
654 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
655 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
656
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
657 // 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
658 // 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
659 // 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
660 // 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
661
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
662 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
663 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
664 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
665 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
666 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
667 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
668
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
669 // 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
670 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
671
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
672 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
673 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
674 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
675 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
676 // 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
677 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
678 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
679
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
680 // 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
681 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
682
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
683 // 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
684 // 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
685 // 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
686 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
687 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
688 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
689
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
690 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
691 i,
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
692 location2offset(ip->location),
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
693 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
694 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
695 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
696 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
697 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
698 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
699 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 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
701 "r" : " ",
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
702 ip->size,
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
703 // 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
704 (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
705 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
706 ));
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
707
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
708 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
709 // 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
710 // 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
711 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
712 bstat[block].objects++;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
713 // 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
714 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
715 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
716 if (*addr == '/')
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
717 fs.root = i;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
718 else if (*addr == '.' &&
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
719 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
720 fs.ijournal = i;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
721 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
722 }
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 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
725 // 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
726 // 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
727 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
728 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
729 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
730 // 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
731 // 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
732 // 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
733 // 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
734 // 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
735 // 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
736 // correctly then?
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
737 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
738 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
739 }
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 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
742 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
743 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
744 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
745
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
746 fs.sequence++;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
747
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
748 tw(tr_bstat());
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 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
751 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
752 return EFFS_NOFORMAT;
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 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
756
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
757 return EFFS_OK;
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
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
761 /******************************************************************************
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
762 * Preformat and format
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
763 ******************************************************************************/
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
764
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
765 // 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
766 // 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
767 // 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
768 // state.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
769 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
770 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
771 bref_t b;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
772
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
773 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
774 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
775
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
776 // 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
777 fs.root = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
778
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
779 // 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
780 // 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
781 // fs_format().
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
782 inodes_set(0);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
783 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
784 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
785 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
786
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
787 // 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
788 // functions...
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
789 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
790
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
791 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
792 b = EFFS_NODEVICE;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
793 }
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 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
796 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
797 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
798 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
799 else
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
800 block_free(b);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
801 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
802 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
803 block_free(b);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
804 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
805 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
806 b = EFFS_OK;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
807 }
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 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
810 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
811
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
812 return b;
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
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
815 // 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
816 // 'Free' state.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
817 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
818 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
819 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
820 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
821 (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
822
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
823 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
824
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
825 if (age == 0) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
826 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 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
828 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
829 // 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
830 // 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
831 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
832 age++;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
833 if (age == 0)
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
834 age++;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
835 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
836 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
837 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
838 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
839 }
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 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
842 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
843 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
844 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
845
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
846 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
847 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
848 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
849 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
850
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
851 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
852
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
853 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
854 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
855
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
856 // 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
857 // 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
858 // *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
859 // 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
860 // 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
861 // 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
862 // unknown.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
863 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
864 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
865 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
866
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
867 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
868 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
869
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
870 // 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
871 // 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
872 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
873
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
874 // 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
875 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
876 return EFFS_AGAIN;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
877 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
878 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
879
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
880 // 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
881 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
882 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
883 return EFFS_AGAIN;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
884
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
885 // 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
886 fs.sequence = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
887
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
888 // Create root directory
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
889 journal_begin(0);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
890 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
891 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
892 return fs.root;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
893 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
894 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
895
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
896 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
897 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
898 return fs.ijournal;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
899 }
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 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
902
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
903 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
904 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
905
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
906 return fs.initerror;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
907 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
908
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
909 // 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
910 //
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
911 // 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
912 // 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
913 // 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
914 // 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
915 // 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
916 // 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
917 // 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
918 // 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
919 // (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
920 //
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
921 // 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
922 // 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
923 // currently suspended).
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
924 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
925 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
926 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
927 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
928
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
929 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
930
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
931 // 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
932 // 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
933 // 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
934 // 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
935 // progress!
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
936 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
937 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
938 valid++;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
939 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
940 free++;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
941 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
942 if (flag == 0) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
943 // 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
944 // 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
945 // 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
946 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
947 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
948 return EFFS_AGAIN;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
949 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
950 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
951 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
952 if (valid > 0)
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
953 // 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
954 error = EFFS_NOPREFORMAT;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
955 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
956 // 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
957 // 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
958 error = EFFS_AGAIN;
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 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
962 return error;
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
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
966 /******************************************************************************
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
967 * Journalling
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
968 ******************************************************************************/
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 // 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
971 // 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
972 //
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
973 // | 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
974 // ---------+-------+------+-----+-------+-------+-----+------+--------
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
975 // 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
976 // 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
977 // 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
978 // 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
979 // 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
980 //
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
981 // - = leave empty (0xFFFF)
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
982 // 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
983 // o = old value
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
984 //
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
985 // 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
986 // 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
987
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
988 // 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
989 // 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
990
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
991 // 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
992 // set to zero.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
993
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
994 // 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
995 // 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
996 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
997 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
998 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
999
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1000 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
1001 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
1002 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
1003 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
1004
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1005 if (oldi == 0) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1006 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
1007 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
1008 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
1009 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
1010 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
1011 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1012 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1013 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
1014 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
1015 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
1016 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
1017 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
1018 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
1019 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1020 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1021
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1022 // 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
1023 // 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
1024 #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
1025 #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
1026 #else
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1027 #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
1028 #endif
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1029
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1030 // 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
1031 // data_reclaim()?
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1032 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
1033 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1034 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
1035 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
1036 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
1037
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1038 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
1039 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
1040 (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
1041
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1042 // 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
1043 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
1044 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
1045
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1046 // 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
1047 // 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
1048 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
1049 journal_commit(0);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1050 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
1051 return;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1052 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1053
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1054 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
1055
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1056 // 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
1057 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
1058 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
1059 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
1060 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1061
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1062 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
1063
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1064 // 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
1065 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
1066 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
1067 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
1068 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1069
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_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
1071
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1072 journal_commit(0);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1073
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1074 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
1075 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
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 file's state
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1078 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
1079
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1080 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
1081
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1082 // Advance journal
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1083 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
1084
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1085 // 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
1086 // 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
1087 if (fs.journal_pos >= fs.journal_size - FFS_JOURNAL_MARGIN *
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1088 sizeof(struct journal_s) && 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
1089 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
1090 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
1091 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1092
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1093 // 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
1094 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
1095 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
1096 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
1097 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
1098 fs.ijournal));
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1099 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1100 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
1101 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1102
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1103 // 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
1104 // 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
1105 // 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
1106 // 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
1107 // 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
1108 // code is redundant.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1109 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
1110 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1111 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
1112 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
1113 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
1114 bref_t b;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1115
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1116 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
1117 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
1118 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
1119
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1120 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
1121 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1122 // 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
1123 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
1124 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
1125
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1126 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
1127 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
1128 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
1129 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
1130
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1131 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
1132 // 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
1133 // 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
1134 // 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
1135 // directory!
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1136 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
1137
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1138 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
1139 // 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
1140 // 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
1141 // what was written
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1142 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
1143 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
1144 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
1145 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
1146 else
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1147 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
1148
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1149 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
1150
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1151 // 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
1152 // 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
1153 // 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
1154 // 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
1155 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
1156 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
1157 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
1158 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
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->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
1161 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1162 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1163 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
1164 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
1165 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
1166 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1167 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1168
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1169 // 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
1170 // 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
1171 // 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
1172 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
1173 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
1174
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1175 // Update bstat[] appropriately
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1176 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
1177 bstat[b].objects++;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1178 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
1179 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1180
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1181 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
1182 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
1183 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1184 // 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
1185 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
1186
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1187 // 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
1188 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
1189 bstat[b].objects--;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1190 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
1191
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1192 // 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
1193 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
1194 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
1195
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1196 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
1197
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1198 // 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
1199 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
1200 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
1201 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1202
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1203 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
1204 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
1205 }
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 // 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
1208 // 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
1209 // 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
1210 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
1211 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1212 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
1213 fs.journal_depth++;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1214 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
1215 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
1216 fs.journal_depth));
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1217 return -1;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1218 }
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 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
1221 fs.journal_depth));
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1222
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1223 return EFFS_OK;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1224 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1225
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1226 // 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
1227 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
1228 {
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, 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
1230 fs.journal_depth));
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1231
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1232 fs.journal_depth--;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1233 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
1234 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
1235 fs.journal_depth));
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1236 return -1;
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 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
1239
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1240 return EFFS_OK;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1241 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1242
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1243 // 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
1244 // 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
1245 // 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
1246 // 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
1247 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
1248 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1249 int j;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1250 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
1251 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
1252
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1253 if (i == 0) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1254 // 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
1255 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
1256 fs.ijournal = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1257 return i;
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 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1260
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1261 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
1262 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
1263
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1264 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
1265 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
1266
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1267 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
1268
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1269 fs.ijournal = i;
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 // 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
1272 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
1273 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
1274 break;
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 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
1277
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1278 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
1279 i = EFFS_OK;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1280
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1281 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
1282 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
1283 // 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
1284 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1285 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
1286 // 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
1287 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
1288 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
1289 journal_end(0);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1290 i = 1;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1291 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1292 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1293 // 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
1294 // 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
1295 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
1296 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
1297 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
1298 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1299
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1300 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
1301 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
1302 // 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
1303 // 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
1304 // version.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1305 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
1306 fs.ijournal = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1307 return 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 }
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 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
1312 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
1313
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1314 return i;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1315 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1316
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1317 // 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
1318 // 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
1319 // 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
1320 // 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
1321 // function.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1322 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
1323 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1324 iref_t i;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1325
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_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
1327 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
1328
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1329 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
1330 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
1331 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
1332 return 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1333 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1334
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1335 // 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
1336 // journal.
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1337 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
1338 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
1339 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
1340 return 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1341 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1342
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1343 journal_begin(oldi);
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 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
1346 if (i < 0) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1347 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
1348 return i;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1349 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1350 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
1351
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1352 // 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
1353 if (oldi != 0)
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1354 journal_end(0);
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1355 else {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1356 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
1357 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
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 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
1361
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1362 return i;
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
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1365 /******************************************************************************
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1366 * 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
1367 ******************************************************************************/
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1368
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1369 // 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
1370 // 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
1371 // 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
1372 // 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
1373 #if (TARGET == 0)
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1374 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
1375 #endif
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1376
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1377
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1378 // 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
1379 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
1380 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1381 #if (TARGET == 0)
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1382 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
1383 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
1384 return EFFS_CORRUPTED;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1385 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1386 // 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
1387 debug_suspend = 1;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1388 #endif
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1389
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1390 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
1391 return fs.initerror;
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 // 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
1394 // 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
1395 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
1396 ffsdrv.erase_suspend();
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1397 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1398 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
1399 ffsdrv.write_end();
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1400 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1401
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1402 return EFFS_OK;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1403 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1404
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1405 // 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
1406 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
1407 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1408 #if (TARGET == 1)
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1409 // 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
1410 // 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
1411 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
1412 ffsdrv.erase_resume();
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1413 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1414 #else
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1415 debug_suspend = 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1416 #endif
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1417
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1418 return error;
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
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1421 /******************************************************************************
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1422 * FFS Statistics functions
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1423 ******************************************************************************/
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 // Not implemented:
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1426 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
1427 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1428 return 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1429 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1430
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1431 // Not implemented:
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1432 // 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
1433 // 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
1434 // 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
1435 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
1436 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1437 return 0;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1438 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1439
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1440 // 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
1441 // 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
1442 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
1443 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1444 memset(&stats, 0, sizeof(struct ffs_stats_s));
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
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1447 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
1448 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1449 unsigned int old;
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 switch (candidate) {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1452 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
1453 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
1454 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
1455 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1456
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1457 // 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
1458 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
1459 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
1460 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
1461 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
1462
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1463 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
1464 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
1465 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
1466 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
1467 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1468
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1469 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
1470 {
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1471 stats.irec.num++;
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1472 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
1473 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
1474 }
ef7d7da61c56 FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1475