[OpenWrt-Devel] fstools: factory reset on power failure during startup
John Crispin
blogic at openwrt.org
Thu Nov 26 04:25:47 EST 2015
On 26/11/2015 09:24, Florian Eckert wrote:
> Hi,
>
> I am using openwrt CC and an ubifs filesystem on top of ubi.
> If I plug off the power during startup, some times my configuration
> get lost and i am back to factory reset.
>
> In the package fstools there is the bin "mount_root" it is called
> twice during startup.
> 1. S10boot at line 10
> 2. S95done at line 6
>
> this calles edit the ./fs_state link
>
> S10boot/S95done:
> ---
> Because ubifs is doing filesystem handling in a background process
> "ubi_bgt0d", could it be possible,
> that (see code) ./.fs_state is not rewritten written anymore?
> So that at next boot the system thinks he is in upgrade mode?
>
> If I add a sleep(10) between unlink and symlink function call i can
> reproduce the failure if i unplug the power.
> I think the first think what should be done is to call
> "snprintf(valstr, sizeof(valstr), "%d", state);" before "unlink(path).
>
> Or this this a deeper Problem?
interesting bug. felix recently added this "i crashed during firstboot,
lets retry" feature recently but it seesm that this works well on
classical (spi-)nor flash but fails on nand/ubi.
i've made a note and will look at this, however i am porting a new
target today so might not happen till start of the week. (unless felix
has time to look at it beforehand)
John
>
> int fs_state_set(const char *dir, enum fs_state state)
> {
> char valstr[16];
> char *path;
>
> -> path = alloca(strlen(dir) + 1 + sizeof("/.fs_state"));
> -> sprintf(path, "%s/.fs_state", dir);
> -> unlink(path);
> -> snprintf(valstr, sizeof(valstr), "%d", state);
>
> return symlink(valstr, path);
> }
>
> Regards
> Flo
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
>
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list