FreeCalypso > hg > freecalypso-sw
annotate gsm-fw/services/ffs/reclaim.c @ 980:a0879ce32d2c
fc-tmsh omr command: always interpret both arguments as hex
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Thu, 10 Dec 2015 04:28:52 +0000 |
parents | 2beb88a3d528 |
children |
rev | line source |
---|---|
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /****************************************************************************** |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * Flash File System (ffs) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * Idea, design and coding by Mads Meisner-Jensen, mmj@ti.com |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 * |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 * FFS core reclaim functionality |
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: reclaim.c 1.4.1.28 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 |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
11 #include "ffs.h" |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
12 #include "core.h" |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
13 #include "drv.h" |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
14 #include "ffstrace.h" |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 |
219
2beb88a3d528
gsm-fw links with FFS included
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
216
diff
changeset
|
16 extern int rand(); |
213
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 /****************************************************************************** |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 * Inodes Reclaim |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 ******************************************************************************/ |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 void inodes_recurse(iref_t i) |
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 iref_t pi; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 struct inode_s *ip, *newip; |
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 tw(tr(TR_BEGIN, TrReclaimLow, "inodes_recurse(%d) {\n", i)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 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
|
30 newip = (struct inode_s *) offset2addr(dev.binfo[fs.newinodes].offset) + i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 // copy inode dir to new block, except child, sibling and copied |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 ffsdrv.write((uint32*) &newip->location, (uint32*) &ip->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
|
34 ffsdrv.write_halfword((uint16*) &newip->size, ip->size); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 ffsdrv_write_byte (&newip->flags, ip->flags); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 ffsdrv.write_halfword((uint16*) &newip->sequence, ip->sequence); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 ffsdrv.write_halfword((uint16*) &newip->updates, ip->updates); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 bstat[fs.newinodes].used++; |
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 // if no children of this dir, we have no more work to do |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 if (ip->child == (iref_t) IREF_NULL) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 tw(tr(TR_END, TrReclaimLow, "}\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 return; |
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 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 pi = -i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 i = ip->child; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 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
|
49 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 do { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 tw(tr(TR_FUNC, TrReclaimLow, "pi = %d, i = %d", pi, i)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 tw(tr(TR_NULL, TrReclaimLow, ", size = %d, location = 0x%x", ip->size, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 ip->location)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 tw(tr(TR_NULL, TrReclaimLow, ", name_addr = 0x%x", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 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
|
58 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 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
|
60 tw(tr(TR_NULL, TrReclaimLow, ", (segment)\n")); |
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 else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 tw(tr(TR_NULL, TrReclaimLow, ", '%s'\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 (ip->size ? 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
|
65 : "(cleaned)"))); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 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
|
68 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 if (is_object(ip, OT_DIR)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 tw(tr(TR_NULL, TrReclaimLow, "recursing...\n", i)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 inodes_recurse(i); |
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 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 tw(tr(TR_NULL, TrReclaimLow, "copying...\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 // copy inode to new block, except child, sibling and copied |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 newip = (struct inode_s *) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 offset2addr(dev.binfo[fs.newinodes].offset) + i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 ffsdrv.write((uint32*) &newip->location, (uint32*) &ip->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
|
79 ffsdrv.write_halfword((uint16*) &newip->size, ip->size); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 ffsdrv_write_byte (&newip->flags, ip->flags); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 ffsdrv.write_halfword((uint16*) &newip->sequence, ip->sequence); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 ffsdrv.write_halfword((uint16*) &newip->updates, ip->updates); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 bstat[fs.newinodes].used++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 tw(tr(TR_FUNC, TrReclaimLow, "Linking: %d->%d\n",pi, i)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 // now write the child or sibling link of previous inode |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 newip = (struct inode_s *) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 offset2addr(dev.binfo[fs.newinodes].offset); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 if (pi > 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 ffsdrv.write_halfword((uint16*) &(newip + pi)->sibling, i); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 ffsdrv.write_halfword((uint16*) &(newip + (-pi))->child, i); |
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 pi = i; // save index of previous inode |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 if (ip->child != (iref_t) IREF_NULL && is_object(ip, OT_FILE)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 iref_t pis, is; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 struct inode_s *ips; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 pis = i; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 ips = ip; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 tw(tr(TR_FUNC, TrReclaimLow, "Follow segment head\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 // While child is valid |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 while ((is = ips->child) != (iref_t) IREF_NULL) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 // Get child |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 is = ips->child; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 ips = inode_addr(is); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 tw(tr(TR_FUNC, TrReclaimLow, "Child ok, got new child i = %d\n", is)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 // While object not is valid |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 while (!is_object_valid(ips)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
113 tw(tr(TR_FUNC, TrReclaimLow, "pi = %d, i = %d c(cleaned)\n", pis, is)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
114 // If sibling are valid |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
115 if (ips->sibling != (iref_t) IREF_NULL) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
116 // Get sibling |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
117 is = ips->sibling; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
118 ips = inode_addr(is); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
119 tw(tr(TR_FUNC, TrReclaimLow, "Sibling ok, got new sibling i = %d\n", is)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
120 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
121 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
122 tw(tr(TR_FUNC, TrReclaimLow, "Sibling = FF (%d)\n", ips->sibling)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
123 break; // Nothing more todo, child and sibling = FF |
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 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
126 // If object is valid |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
127 if (is_object_valid(ips)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
128 tw(tr(TR_NULL, TrReclaimLow, "copying...\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
129 // copy inode to new block, except child, sibling and copied |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 newip = (struct inode_s *) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
131 offset2addr(dev.binfo[fs.newinodes].offset) + is; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
132 ffsdrv.write((uint32*) &newip->location, (uint32*) &ips->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
|
133 ffsdrv.write_halfword((uint16*) &newip->size, ips->size); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
134 ffsdrv_write_byte (&newip->flags, ips->flags); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
135 ffsdrv.write_halfword((uint16*) &newip->sequence, ips->sequence); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
136 ffsdrv.write_halfword((uint16*) &newip->updates, ips->updates); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
137 bstat[fs.newinodes].used++; |
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 tw(tr(TR_FUNC, TrReclaimLow, "Linking child: %d->%d\n",pis, is)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
140 // now write the child link of previous inode |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
141 newip = (struct inode_s *) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
142 offset2addr(dev.binfo[fs.newinodes].offset); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
143 ffsdrv.write_halfword((uint16*) &(newip + (pis))->child, is); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
144 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
145 pis = is; // save index of previous inode |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
146 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
147 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
148 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
149 tw(tr(TR_FUNC, TrReclaimLow, "Sibling = FF (%d, %d)\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
150 ips->sibling, ips->child)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
151 } |
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 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
154 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
155 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
156 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
157 tw(tr(TR_NULL, TrReclaimLow, "(ignoring)\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
158 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
159 i = ip->sibling; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
160 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
|
161 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
162 } while (i != (iref_t) IREF_NULL); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
163 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
164 tw(tr(TR_END, TrReclaimLow, "}\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
165 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
166 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
167 // Reclaim inodes, eg. move inodes to another block and erase old one. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
168 effs_t inodes_reclaim(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
169 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
170 tw(tr(TR_BEGIN, TrIReclaim, "inodes_reclaim() {\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
171 ttw(str(TTrRec, "irec{")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
172 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
173 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
|
174 tw(tr(TR_END, TrIReclaim, "} %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
|
175 ttw(ttr(TTrRec, "} %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
|
176 return fs.initerror; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
177 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
178 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
179 if ((fs.newinodes = 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
|
180 tw(tr(TR_END, TrIReclaim, "} %d\n", EFFS_NOBLOCKS)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
181 ttw(ttr(TTrRec, "} %d" NL, EFFS_NOBLOCKS)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
182 return EFFS_NOBLOCKS; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
183 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
184 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
185 statistics_update_irec(bstat[fs.inodes].used - 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
|
186 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
|
187 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
188 // copy all inodes... |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
189 bstat[fs.newinodes].used = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
190 inodes_recurse(fs.root); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
191 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
192 block_commit(); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
193 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
194 tw(tr(TR_END, TrIReclaim, "} 0\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
195 ttw(str(TTrRec, "} 0" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
196 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
197 return EFFS_OK; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
198 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
199 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
200 #if (FFS_TEST == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
201 #define BLOCK_COMMIT_TEST(testcase, text) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
202 #else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
203 #if (TARGET == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
204 // 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
|
205 // 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
|
206 #define BLOCK_COMMIT_TEST(testcase, text) if (fs.testflags == testcase) { tw(tr(TR_FUNC, TrData, "} (" text ")\n")); return; } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
207 #else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
208 #define BLOCK_COMMIT_TEST(testcase, text) if (fs.testflags == testcase) { ttw(ttr(TTrData, "} (" text ")\n")); return; } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
209 #endif |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
210 #endif |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
211 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
212 // Inode -> Lost, Copying -> Inode, Lost -> Free |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
213 void block_commit(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
214 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
215 int oldinodes = fs.inodes; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
216 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
217 tw(tr(TR_BEGIN, TrIReclaim, "block_commit(%d -> %d) {\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
218 oldinodes, fs.newinodes)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
219 ttw(ttr(TTrRec, "block_commit(%d -> %d) {\n" NL, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
220 oldinodes, fs.newinodes)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
221 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
222 BLOCK_COMMIT_TEST(BLOCK_COMMIT_BEFORE, "Oops before commit"); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
223 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
224 block_flags_write(oldinodes, BF_LOST); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
225 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
226 BLOCK_COMMIT_TEST(BLOCK_COMMIT_NO_VALID, "Oops no valid inode block"); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
227 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
228 // Validate new block as an inodes block |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
229 block_flags_write(fs.newinodes, BF_INODES); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
230 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
231 bstat[fs.newinodes].lost = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
232 bstat[fs.newinodes].objects = 1; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
233 inodes_set(fs.newinodes); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
234 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
235 // Free old inodes block |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
236 block_free(oldinodes); |
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 BLOCK_COMMIT_TEST(BLOCK_COMMIT_OLD_FREE, "Oops after freeing old block"); |
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 BLOCK_COMMIT_TEST(BLOCK_COMMIT_AFTER, "Oops after commit"); |
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 ttw(str(TTrRec, "} 0" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
243 tw(tr(TR_END, TrIReclaim, "}\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
244 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
245 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
246 |
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 * Data Reclaim |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
249 ******************************************************************************/ |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
250 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
251 // Important note: We must NOT perform a data reclaim when we are in the |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
252 // process of creating the journal file! |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
253 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
254 // Reclaim a data block, eg. move files to other blocks and erase old one. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
255 // When the reclaim is done, we must completely delete the old inodes which |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
256 // are pointing into the old data sector which is going to be erased now. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
257 iref_t data_reclaim(int space) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
258 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
259 iref_t error; |
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 tw(tr(TR_BEGIN, TrDReclaim, "data_reclaim(%d) {\n", space)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
262 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
263 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
|
264 tw(tr(TR_END, TrDReclaim, "} %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
|
265 return fs.initerror; |
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 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
268 error = data_reclaim_try(space); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
269 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
270 tw(tr(TR_END, TrDReclaim, "} (data_reclaim) %d\n", error)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
271 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
272 return error; |
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 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
275 int dage_max_reached(int dage_blk, int agegain) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
276 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
277 int reclaim, early, log2, mask; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
278 |
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_BEGIN, TrDReclaim, "young(%d, %d) {\n", dage_blk, agegain)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
280 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
281 // Simple algorithm |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
282 reclaim = (dage_blk + agegain - 2 * FFS_DAGE_MAX >= 0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
283 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
284 // Early exponential probability based reclaim |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
285 early = FFS_DAGE_MAX - dage_blk; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
286 if (agegain > dage_blk - 4 && 0 < early && early <= FFS_DAGE_EARLY_WIDTH) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
287 if (early < 4) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
288 early = 2; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
289 if (early < FFS_DAGE_EARLY_WIDTH) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
290 // Now make an exponential probability distributon by |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
291 // generating a bitmask of a size relative to (dage_blk |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
292 // - DAGE_EARLY_WIDTH) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
293 log2 = -1; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
294 while (early > 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
295 early >>= 1; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
296 log2++; |
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 reclaim = log2; |
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 mask = (1 << (log2 + 1)) - 1; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
301 reclaim = ((rand() & mask) == 0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
302 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
303 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
304 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
305 // Do not perform a reclaim unless we gain a certain minimum |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
306 if (agegain < FFS_DAGE_GAIN_MIN) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
307 reclaim = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
308 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
309 tw(tr(TR_END, TrDReclaim, "} (%d)\n", reclaim)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
310 return reclaim; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
311 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
312 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
313 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
314 // Try to reclaim at least <space> bytes of data space. On success, return |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
315 // the number of bytes actually reclaimed. Otherwise, on failure, return a |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
316 // (negative) error. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
317 int data_reclaim_try(int space) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
318 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
319 // 1. Find a suitable block to reclaim. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
320 // |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
321 // 2. Relocate each valid object from old block (to another block). An |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
322 // object relocation is similar to a normal file update, e.g. similar to |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
323 // fupdate(). |
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 // 3. If there is not enough space to relocate a file, we must alloc a |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
326 // new block then data_format() it. |
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 // 4. set BF_CLEANING flag of old block. |
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 // 5. ALL inodes (also invalid an erased ones) referring into reclaimed |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
331 // block must now be totally wiped out. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
332 // |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
333 // 6. Free (invalidate) old block. |
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 int result = 0, reserved_ok = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
336 bref_t b, blocks_free; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
337 bref_t brc_young_b, brc_lost_b, brc_unused_b; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
338 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
339 blocksize_t brc_lost_lost, brc_lost_unused; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
340 blocksize_t brc_unused_unused; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
341 blocksize_t unused, unused_total, lost, lost_total, free; |
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 age_t brc_young_dage, free_dage, dage; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
344 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
|
345 // Note gain can be negative if the free block is younger than the youngest data block |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
346 int age_gain; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
347 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
348 tw(tr(TR_BEGIN, TrDReclaim, "data_reclaim_try(%d) {\n", space)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
349 ttw(str(TTrRec, "drec{" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
350 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
351 // While searching for a block to reclaim, we maintain three block |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
352 // reclaim candidates (brc): One with the maximum number of lost bytes, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
353 // one with the maximum number of unused bytes and another for the |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
354 // youngest block, e.g. the one with the largest age distance to |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
355 // fs.age_max. The candidates are tried in the order mentioned. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
356 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
357 // This counts free blocks, so we initialize to number of blocks minus |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
358 // one for inodes. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
359 blocks_free = dev.numblocks - 1; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
360 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
361 // Initialize Block Reclaim Candidate (brc) variables |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
362 brc_lost_b = -1; brc_lost_unused = 0; brc_lost_lost = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
363 brc_unused_b = -1; brc_unused_unused = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
364 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
365 brc_young_b = -1; brc_young_dage = 0; free_dage = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
366 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
367 lost_total = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
368 unused_total = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
369 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
370 tw(tr(TR_FUNC, TrDReclaim, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
371 "blk unused lost w/age age dist objs\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
372 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
|
373 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
374 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
|
375 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
376 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
|
377 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
378 // Record number of lost bytes and number of unused bytes, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
379 // eg. total space that would be freed if this block was |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
380 // reclaimed |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
381 lost = bstat[b].lost; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
382 unused = dev.blocksize - (bstat[b].used - bstat[b].lost); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
383 free = dev.blocksize - bstat[b].used; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
384 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
385 lost_total += lost; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
386 unused_total += unused; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
387 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
388 if (free >= RESERVED_LOW) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
389 reserved_ok = 1; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
390 if (lost > brc_lost_lost) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
391 brc_lost_b = b; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
392 brc_lost_lost = lost; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
393 brc_lost_unused = unused; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
394 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
395 if (unused > brc_unused_unused) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
396 brc_unused_b = b; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
397 brc_unused_unused = unused; |
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 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
400 tw(tr(TR_FUNC, TrDReclaim, "%3d %7d %7d ", b, unused, lost)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
401 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
402 dage = saturate_dage(fs.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
|
403 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
404 tw(tr(TR_NULL, TrDReclaim, "%6d %5d %4d %3d\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
405 lost, bhp->age, dage, bstat[b].objects)); |
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 if (dage >= brc_young_dage) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
408 brc_young_b = b; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
409 brc_young_dage = dage; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
410 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
411 blocks_free--; |
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 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
|
414 unused_total += dev.blocksize; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
415 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
416 // Find youngest free block (in must cases we will only have one free b) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
417 dage = saturate_dage(fs.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
|
418 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
419 if (dage >= free_dage) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
420 free_dage = dage; // Delta age of youngest free block |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
421 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
422 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
423 tw(tr(TR_FUNC, TrDReclaim, "sum %7d %7d\n", unused_total, lost_total)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
424 tw(tr(TR_FUNC, TrDReclaim, "blocks_free = %d, fs.age_max = %d\n", blocks_free, fs.age_max)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
425 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
426 age_gain = brc_young_dage - free_dage; // Same as free - block age |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
427 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
428 if (space > unused_total) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
429 // We will never be able to reclaim this amount... |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
430 result = 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
431 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
432 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
433 // No additional blocks (apart from spare block) are free... |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
434 tw(tr(TR_FUNC, TrDReclaim, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
435 "brc_young_dage = %d, brc_lost_unused = %d, brc_unused_unused = %d\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
436 brc_young_dage, brc_lost_unused, brc_unused_unused)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
437 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
438 if (reserved_ok == 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
439 tw(tr(TR_FUNC, TrDReclaim, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
440 "No reserved, reclaim most-lost block (%d)\n", brc_unused_b)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
441 result = data_block_reclaim(brc_lost_b, MOST_LOST); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
442 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
443 else if (dage_max_reached(brc_young_dage, age_gain) > 0 ) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
444 tw(tr(TR_FUNC, TrDReclaim, "Reclaiming youngest block (%d)\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
445 brc_young_b)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
446 result = data_block_reclaim(brc_young_b, YOUNGEST); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
447 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
448 else if (brc_lost_unused >= space) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
449 tw(tr(TR_FUNC, TrDReclaim, "Reclaiming most-lost block (%d)\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
450 brc_lost_b)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
451 result = data_block_reclaim(brc_lost_b, MOST_LOST); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
452 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
453 else if (brc_unused_unused >= space) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
454 tw(tr(TR_FUNC, TrDReclaim, "Reclaiming most-unused block (%d)\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
455 brc_unused_b)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
456 result = data_block_reclaim(brc_unused_b, MOST_UNUSED); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
457 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
458 else { |
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, TrDReclaim, "Reclaiming most-lost blockx (%d)\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
460 brc_lost_b)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
461 result = data_block_reclaim(brc_lost_b, MOST_LOST); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
462 if (result >= 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
463 result = 0; // We reclaimed a block but we still need more space |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
464 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
465 |
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 tw(tr(TR_END, TrDReclaim, "} (data_reclaim_try) %d\n", result)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
468 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
469 return result; |
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 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
473 #if (FFS_TEST == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
474 #define BLOCK_RECLAIM_TEST(testcase, text) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
475 #else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
476 #if (TARGET == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
477 // 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
|
478 // 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
|
479 #define BLOCK_RECLAIM_TEST(testcase, text) if (fs.testflags == testcase) { tw(tr(TR_FUNC, TrTestHigh, "(" text ")\n")); tw(tr(TR_END, TrDReclaim, "} (Test) -100\n", result));return -100; } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
480 #else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
481 #define BLOCK_RECLAIM_TEST(testcase, text) if (fs.testflags == testcase) { ttw(ttr(TTrData, "} (" text ")"NL)); ttw(ttr(TTrRec, "} (Test) -100" NL));return -100; } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
482 #endif |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
483 #endif |
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 #if (FFS_TEST == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
486 #define BLOCK_RECOVER_TEST_INIT(testcase, text) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
487 #define BLOCK_RECOVER_TEST(testcase, text) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
488 #else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
489 #if (TARGET == 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
490 #define BLOCK_RECOVER_TEST_INIT(testcase, text) int rand_object; if (fs.testflags == testcase) { rand_object = rand() % bstat[b].objects; tw(tr(TR_FUNC, TrTestHigh, "Fail when object nr %d is relocated\n", rand_object)); } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
491 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
492 #define BLOCK_RECOVER_TEST(testcase, text) if (fs.testflags == testcase) {if (rand_object == n) { tw(tr(TR_FUNC, TrTestHigh, "(" text ")\n")); tw(tr(TR_END, TrDReclaim, "} (Test) -101\n", result)); return -101; } } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
493 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
494 #else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
495 #define BLOCK_RECOVER_TEST_INIT(testcase, text) int rand_object; if (fs.testflags == testcase) { rand_object = rand() % bstat[b].objects; ttw(ttr(TTrData, "Fail when object nr %d is relocated" NL, rand_object)); } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
496 #define BLOCK_RECOVER_TEST(testcase, text) if (fs.testflags == testcase) {if (rand_object == n) { ttw(ttr(TTrData, "(" text ")" NL)); ttw(ttr(TTrRec, "} (Test) -101" NL, result)); return -101; } } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
497 #endif |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
498 #endif |
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 iref_t data_block_reclaim(bref_t b, int candidate) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
501 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
502 iref_t i, n, j; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
503 blocksize_t used_old, lost_old; |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
504 int org_res_space, result = 0; |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
505 iref_t org_block_files_reserved; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
506 offset_t lower, upper; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
507 struct inode_s *ip; |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
508 static int is_reclaim_running = 0; |
213
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 tw(tr(TR_BEGIN, TrDReclaim, "data_block_reclaim(%d) {\n", b)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
511 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
512 // In case of no free blocks (after sudden power off) or if the file |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
513 // system is near full we risk to be reentered (infinity recursively |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
514 // loop) and we can not allow that, so just return. |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
515 if (is_reclaim_running == 1) { |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
516 tw(tr(TR_END, TrDReclaim, "} (reenteret skip reclaim) 0\n")); |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
517 return EFFS_RECLAIMLOOP; |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
518 } |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
519 |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
520 is_reclaim_running = 1; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
521 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
522 // If there are more objects in this block than there are remaining |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
523 // free inodes, we have to make an inodes_reclaim() first. |
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, TrDReclaim, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
525 "block_objects, fs.inodes_max, inodes: used, free\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
526 tw(tr(TR_FUNC, TrDReclaim, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
527 "%10d, %13d, %15d, %4d\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
528 bstat[b].objects, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
529 fs.inodes_max, 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
|
530 fs.inodes_max - (bstat[fs.inodes].used + 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
|
531 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
532 if (bstat[b].objects >= (fs.inodes_max - (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
|
533 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
|
534 FFS_INODES_MARGIN))) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
535 tw(tr(TR_FUNC, TrInode, "NOTE: Will run out of free inodes...\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
536 inodes_reclaim(); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
537 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
538 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
539 // Allocate a new block. NOTE: we don't return an error because if we |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
540 // get in the situation where we don't have any free blocks this is the |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
541 // only way to recover. |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
542 if ((result = block_alloc(1, BF_DATA)) < 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
543 tw(tr(TR_FUNC, TrAll, "WARNING: block_alloc failed\n")); |
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 |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
546 BLOCK_RECLAIM_TEST(BLOCK_RECLAIM_ALLOC, "Oops after ffs_block_alloc()"); |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
547 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
548 // If there are any objects at all to reclaim... |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
549 if (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
|
550 { |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
551 BLOCK_RECOVER_TEST_INIT(BLOCK_RECOVER_OBJECTS, "Dummy") |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
552 // Save the current journal state |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
553 if (journal_push() != EFFS_OK) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
554 is_reclaim_running = 0; // NOTEME: change to goto? |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
555 return EFFS_CORRUPTED; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
556 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
557 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
558 // We simulate that this block is completely full, such that we |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
559 // don't relocate files to the end of the block |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
560 used_old = bstat[b].used; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
561 lost_old = bstat[b].lost; // For statistics |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
562 bstat[b].used = dev.blocksize - 1; |
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 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
565 // Compute lower (inclusive) and upper (exclusive) bounds of the |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
566 // location of files in this block |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
567 lower = offset2location(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
|
568 upper = offset2location(dev.binfo[b].offset + dev.blocksize); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
569 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
570 tw(tr(TR_FUNC, TrDReclaim, "Block addr range = 0x%X..0x%X\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
571 location2offset(lower), location2offset(upper))); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
572 |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
573 // This is the only time we are allowed to use the reserved |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
574 org_block_files_reserved= fs.block_files_reserved; |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
575 fs.block_files_reserved = 0; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
576 |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
577 org_res_space = fs.reserved_space; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
578 fs.reserved_space = RESERVED_NONE; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
579 |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
580 ip = inode_addr(1); |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
581 for (i = 1, n = 0; 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
|
582 { |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
583 BLOCK_RECOVER_TEST(BLOCK_RECOVER_OBJECTS, "Oops before relocate all objects"); |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
584 // Ensure object is valid and within the block to be reclaimed |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
585 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
|
586 lower <= ip->location && ip->location < upper) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
587 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
588 if ((result = object_relocate(i)) < 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
589 tw(tr(TR_FUNC, TrAll, "FATAL object_relocate failed\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
590 break; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
591 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
592 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
593 // If we reclaim a segment head or wch that is in use we must |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
594 // update the file descriptor as well |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
595 for (j = 0; j < fs.fd_max; j++) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
596 if (i == fs.fd[j].seghead) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
597 tw(tr(TR_FUNC, TrDReclaim, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
598 "Updated seghead %d -> %d \n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
599 fs.fd[j].seghead, result)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
600 fs.fd[j].seghead = result; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
601 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
602 if (i == fs.fd[j].wch) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
603 tw(tr(TR_FUNC, TrDReclaim, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
604 "Updated wch %d -> %d \n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
605 fs.fd[j].wch, result)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
606 fs.fd[j].wch = result; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
607 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
608 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
609 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
610 // If we have just reclaimed an object which we started on |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
611 // updating we must also update ojournal |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
612 if (i == fs.ojournal.oldi) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
613 struct inode_s *ip = inode_addr(result); |
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_FUNC, TrDReclaim, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
615 "Updated ojournal oldi %d -> %d \n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
616 fs.ojournal.oldi, result)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
617 fs.ojournal.oldi = result; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
618 fs.ojournal.location = ip->location; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
619 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
620 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
621 if (i == fs.ojournal.diri || i == -fs.ojournal.diri) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
622 fs.ojournal.diri = (fs.ojournal.diri < 0 ? -result : result); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
623 tw(tr(TR_FUNC, TrDReclaim, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
624 "Updated ojournal: diri %d -> %d \n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
625 i, fs.ojournal.diri)); |
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 if (i == fs.ojournal.repli || i == -fs.ojournal.repli) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
629 fs.ojournal.repli = (fs.ojournal.repli < 0 ? -result : result); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
630 tw(tr(TR_FUNC, TrDReclaim, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
631 "Updated ojournal: repli %d -> %d \n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
632 i, fs.ojournal.repli)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
633 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
634 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
635 if (i == fs.i_backup || i == -fs.i_backup) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
636 fs.i_backup = (fs.i_backup < 0 ? -result : result); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
637 tw(tr(TR_FUNC, TrDReclaim, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
638 "Updated i_backup: %d -> %d \n", i, fs.i_backup)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
639 } |
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 n++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
642 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
643 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
644 |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
645 fs.block_files_reserved = org_block_files_reserved; // Restore |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
646 fs.reserved_space = org_res_space; |
213
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 tw(tr(TR_FUNC, TrDReclaim, "Reclaimed %d objects\n", n)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
649 if (result >= 0) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
650 result = n; // We return number of objects relocated |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
651 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
652 if (i < fs.inodes_max) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
653 // We did not finish, so restore the old bstat[].used of the block. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
654 bstat[b].used = used_old; |
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, TrAll, |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
656 "WARNING: data_block_reclaim() not completed\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
657 result = EFFS_DBR; |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
658 } |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
659 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
660 // Restore the saved journal state |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
661 if (journal_pop() != EFFS_OK) { |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
662 is_reclaim_running = 0; // NOTEME: change to goto? |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
663 return EFFS_CORRUPTED; |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
664 } |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
665 } |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
666 BLOCK_RECLAIM_TEST(BLOCK_RECLAIM_NO_CLEAN, "Oops before clean old data block"); |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
667 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
668 if (result >= 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
669 // Clean the block (remove all inodes that refer to this block) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
670 block_flags_write(b, BF_CLEANING); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
671 block_clean(b); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
672 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
673 statistics_update_drec(used_old - lost_old, lost_old, candidate); |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
674 |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
675 BLOCK_RECLAIM_TEST(BLOCK_RECLAIM_CLEANING, "Oops before free old data block"); |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
676 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
677 // Free the old block |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
678 block_free(b); |
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 |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
681 is_reclaim_running = 0; |
213
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 tw(tr(TR_END, TrDReclaim, "} (data_block_reclaim) %d\n", result)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
684 ttw(ttr(TTrRec, "} %d" NL, result)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
685 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
686 return result; |
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 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
689 // Relocate object represented by inode reference <i>. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
690 iref_t object_relocate(iref_t oldi) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
691 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
692 iref_t newi; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
693 struct inode_s *oldip; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
694 char *olddata, *oldname; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
695 int oldsize; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
696 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
697 tw(tr(TR_BEGIN, TrReclaimLow, "object_relocate(%d) {\n", oldi)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
698 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
699 journal_begin(oldi); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
700 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
701 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
|
702 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
703 oldsize = segment_datasize(oldip); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
704 olddata = offset2addr(location2offset(oldip->location)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
705 oldname = addr2name(olddata); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
706 olddata = addr2data(olddata, oldip); |
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(oldip, OT_SEGMENT)) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
709 newi = segment_create(olddata, oldsize, -oldi); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
710 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
711 // root inode is a special case |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
712 if (*oldname == '/') |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
713 newi = object_create(oldname, olddata, oldsize, 0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
714 else |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
715 newi = object_create(oldname, olddata, oldsize, oldi); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
716 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
717 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
718 if (newi < 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
719 tw(tr(TR_END, TrReclaimLow, "} %d\n", newi)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
720 return newi; |
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 // root inode is a special case |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
724 if ((*oldname == '/') && !is_object(oldip, OT_SEGMENT)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
725 tw(tr(TR_FUNC, TrDReclaim, "Relocating fs.root: %d->%d\n", oldi, newi)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
726 fs.root = newi; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
727 } |
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 journal_end(0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
730 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
731 tw(tr(TR_END, TrReclaimLow, "} %d\n", newi)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
732 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
733 return newi; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
734 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
735 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
736 // Clean a block, eg. erase all inodes that refer to this block. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
737 iref_t block_clean(bref_t b) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
738 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
739 iref_t i, n; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
740 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
|
741 offset_t lower, upper; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
742 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
743 tw(tr(TR_FUNC, TrDReclaim, "block_clean(%d) { ", b)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
744 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
745 // Compute lower (inclusive) and upper (exclusive) bounds of the |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
746 // location of files in this block |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
747 lower = offset2location(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
|
748 upper = offset2location(dev.binfo[b].offset + dev.blocksize); |
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 tw(tr(TR_FUNC, TrDReclaim, "offset range = 0x%X..0x%X: ", lower, upper)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
751 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
752 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
|
753 for (i = 1, n = 0; 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
|
754 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
755 // Ensure object is within the block to be reclaimed. Note: if ffs |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
756 // is conf. with 1MB or above will all not used inodes default have |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
757 // the location to FFFF which will trigger a clean and make a error! |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
758 if (lower <= ip->location && upper > ip->location) |
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 tw(tr(TR_NULL, TrReclaimLow, "%d ", i)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
761 // Set the size to zero so it won't be counted in ffs_initialize() |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
762 ffsdrv.write_halfword((uint16 *) &ip->size, 0); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
763 n++; |
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 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
766 tw(tr(TR_NULL, TrDReclaim, "} %d\n", n)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
767 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
768 return n; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
769 } |
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 |
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 * Main and block reclaim |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
774 ******************************************************************************/ |
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 // Reclaim (erase) all blocks that are marked as invalid/reclaimable. Each |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
777 // time a block is erased, its age is incremented so as to support wear |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
778 // levelling. Also, the global age limits are updated. FIXME: Should we |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
779 // avoid having ffs_initialize() do a block_reclaim() because it delays reboot?. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
780 int blocks_reclaim(void) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
781 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
782 bref_t b, n, b_lost_space; |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
783 int blocks_free = 0, lost_space; |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
784 int free_space, b_free_space; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
785 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
786 tw(tr(TR_BEGIN, TrBlock, "blocks_reclaim() {\n")); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
787 ttw(str(TTrRec, "blocks_reclaim() {" NL)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
788 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
789 // Testing of fs.testflags is for the sake of testing block_commit() |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
790 if ((fs.testflags & BLOCK_COMMIT_BASE) != 0) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
791 tw(tr(TR_FUNC, TrBlock, "Bailing out because fs.testflags = 0x%X\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
792 fs.testflags)); |
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, n = 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_flag(b, BF_LOST)) { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
797 block_reclaim(b); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
798 n++; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
799 } |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
800 if (is_block(b, BF_IS_FREE)) { |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
801 blocks_free++; |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
802 } |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
803 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
804 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
805 |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
806 // If the number of free blocks is less than fs.blocks_free_min we |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
807 // call data_block_reclaim(). We will reclaim the block with most lost |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
808 // space. This should only happend if we got a sudden power off/reset |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
809 // while we reclaimed a block. |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
810 if (blocks_free < fs.blocks_free_min) { |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
811 lost_space = 0; |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
812 free_space = 0; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
813 |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
814 // We most never reclaim the block with most free space because this |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
815 // is the only block we can relocate the objects to. |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
816 for (b = 0; b < dev.numblocks; b++) { |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
817 if (is_block_flag(b, BF_DATA)) { |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
818 if ((dev.blocksize - bstat[b].used) > free_space) { |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
819 free_space = dev.blocksize - bstat[b].used; |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
820 b_free_space = b; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
821 } |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
822 } |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
823 } |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
824 tw(tr(TR_FUNC, TrBlock, "most free space: %d in block: %d \n", |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
825 free_space, b_free_space)); |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
826 |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
827 for (b = 0; b < dev.numblocks; b++) { |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
828 if (is_block_flag(b, BF_DATA) && b != b_free_space) { |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
829 if (bstat[b].lost > lost_space) { |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
830 lost_space = bstat[b].lost; |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
831 b_lost_space = b; |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
832 } |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
833 } |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
834 } |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
835 tw(tr(TR_FUNC, TrBlock, "most lost space: %d in block: %d \n", |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
836 lost_space, b_lost_space)); |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
837 |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
838 data_block_reclaim(b_lost_space, MOST_LOST); |
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
839 } |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
840 tw(tr(TR_END, TrBlock, "} %d\n", n)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
841 ttw(ttr(TTrRec, "} %d" NL, n)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
842 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
843 return n; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
844 } |
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 int block_reclaim(bref_t b) |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
847 { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
848 age_t age; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
849 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
|
850 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
851 tw(tr(TR_BEGIN, TrBlock, "block_reclaim(%d) {\n", b)); |
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 // In ffs_initialize() we set fs.initerror = EFFS_INVALID while we call |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
854 // blocks_fsck(). We test for that condition now, in order to avoid |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
855 // doing sector erases that will delay the whole target boot process. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
856 if (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
|
857 tw(tr(TR_END, TrBlock, "} %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
|
858 return fs.initerror; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
859 } |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
860 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
861 // Testing of fs.testflags is for the sake of testing block_commit() |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
862 if ((fs.testflags & BLOCK_COMMIT_BASE) != 0 && |
216
0eb85790c0ed
gsm-fw/services/ffs: reclaim.c compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
213
diff
changeset
|
863 fs.testflags != BLOCK_COMMIT_OLD_FREE) { |
213
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
864 tw(tr(TR_FUNC, TrBlock, "Bailing out because fs.testflags = 0x%X\n", |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
865 fs.testflags)); |
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 else { |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
868 // We must read block's age before we erase it. |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
869 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
|
870 age = bhp->age; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
871 ffsdrv.erase(b); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
872 block_preformat(b, age); |
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 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
875 tw(tr(TR_END, TrBlock, "} %d\n", 0)); |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
876 |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
877 return 0; |
ef7d7da61c56
FFS code integration: remaining C files imported, but not yet integrated
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
878 } |