Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
0ee1ab68
Commit
0ee1ab68
authored
Oct 25, 2016
by
Philip Gladstone
Committed by
Marcel Stör
Oct 25, 2016
Browse files
Improve reliability of FS detection. (#1528)
* Version to make filesystem detection more reliable * Improve bad fs detection
parent
6e38cc4b
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/spiffs/spiffs_nucleus.c
View file @
0ee1ab68
...
...
@@ -292,27 +292,60 @@ s32_t spiffs_probe(
SPIFFS_CHECK_RES
(
res
);
}
// check that we have sane number of blocks
if
(
bix_count
[
0
]
<
3
)
return
SPIFFS_ERR_PROBE_TOO_FEW_BLOCKS
;
// check that the order is correct, take aborted erases in calculation
// Note that bix_count[0] should be blockcnt, [1] should be blockcnt - 1
// and [2] should be blockcnt - 3
// first block aborted erase
if
(
magic
[
0
]
==
(
spiffs_obj_id
)(
-
1
)
&&
bix_count
[
1
]
-
bix_count
[
2
]
==
1
)
{
return
(
bix_count
[
1
]
+
1
)
*
cfg
->
log_block_size
;
}
int
fs_size
;
if
(
magic
[
0
]
==
(
spiffs_obj_id
)(
-
1
)
&&
bix_count
[
1
]
-
bix_count
[
2
]
==
2
)
{
fs_size
=
bix_count
[
1
]
+
1
;
}
else
// second block aborted erase
if
(
magic
[
1
]
==
(
spiffs_obj_id
)(
-
1
)
&&
bix_count
[
0
]
-
bix_count
[
2
]
==
2
)
{
return
bix_count
[
0
]
*
cfg
->
log_block_size
;
}
if
(
magic
[
1
]
==
(
spiffs_obj_id
)(
-
1
)
&&
bix_count
[
0
]
-
bix_count
[
2
]
==
3
)
{
fs_size
=
bix_count
[
0
];
}
else
// third block aborted erase
if
(
magic
[
2
]
==
(
spiffs_obj_id
)(
-
1
)
&&
bix_count
[
0
]
-
bix_count
[
1
]
==
1
)
{
return
bix_count
[
0
]
*
cfg
->
log_block_size
;
}
fs_size
=
bix_count
[
0
];
}
else
// no block has aborted erase
if
(
bix_count
[
0
]
-
bix_count
[
1
]
==
1
&&
bix_count
[
1
]
-
bix_count
[
2
]
==
1
)
{
return
bix_count
[
0
]
*
cfg
->
log_block_size
;
if
(
bix_count
[
0
]
-
bix_count
[
1
]
==
1
&&
bix_count
[
1
]
-
bix_count
[
2
]
==
2
)
{
fs_size
=
bix_count
[
0
];
}
else
{
return
SPIFFS_ERR_PROBE_NOT_A_FS
;
}
// check that we have sane number of blocks
if
(
fs_size
<
3
)
return
SPIFFS_ERR_PROBE_TOO_FEW_BLOCKS
;
dummy_fs
.
block_count
=
fs_size
;
// Now verify that there is at least one good block at the end
for
(
bix
=
fs_size
-
1
;
bix
>=
3
;
bix
--
)
{
spiffs_obj_id
end_magic
;
paddr
=
SPIFFS_MAGIC_PADDR
(
&
dummy_fs
,
bix
);
#if SPIFFS_HAL_CALLBACK_EXTRA
// not any proper fs to report here, so callback with null
// (cross fingers that no-one gets angry)
res
=
cfg
->
hal_read_f
((
void
*
)
0
,
paddr
,
sizeof
(
spiffs_obj_id
),
(
u8_t
*
)
&
end_magic
);
#else
res
=
cfg
->
hal_read_f
(
paddr
,
sizeof
(
spiffs_obj_id
),
(
u8_t
*
)
&
end_magic
);
#endif
if
(
res
<
0
)
{
return
SPIFFS_ERR_PROBE_NOT_A_FS
;
}
if
(
end_magic
==
(
spiffs_obj_id
)(
-
1
))
{
if
(
bix
<
fs_size
-
1
)
{
return
SPIFFS_ERR_PROBE_NOT_A_FS
;
}
}
else
if
(
end_magic
!=
SPIFFS_MAGIC
(
&
dummy_fs
,
bix
))
{
return
SPIFFS_ERR_PROBE_NOT_A_FS
;
}
else
{
break
;
}
}
return
SPIFFS_ERR_PROBE_NOT_A_FS
;
return
fs_size
*
cfg
->
log_block_size
;
}
#endif // SPIFFS_USE_MAGIC && SPIFFS_USE_MAGIC_LENGTH && SPIFFS_SINGLETON==0
...
...
app/spiffs/spiffs_nucleus.h
View file @
0ee1ab68
...
...
@@ -137,7 +137,7 @@
((spiffs_obj_id)(0x20140529 ^ SPIFFS_CFG_LOG_PAGE_SZ(fs)))
#else // SPIFFS_USE_MAGIC_LENGTH
#define SPIFFS_MAGIC(fs, bix) \
((spiffs_obj_id)(0x20140529 ^ SPIFFS_CFG_LOG_PAGE_SZ(fs) ^ ((fs)->block_count - (bix))))
((spiffs_obj_id)(0x20140529 ^ SPIFFS_CFG_LOG_PAGE_SZ(fs) ^ ((fs)->block_count -
(
(bix)
< 3 ? (1<<(bix)) - 1 : (bix)<<2)
)))
#endif // SPIFFS_USE_MAGIC_LENGTH
#endif // SPIFFS_USE_MAGIC
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment