[OpenWrt-Devel] fstools: factory reset on power failure during startup

Florian Eckert eckert.florian at googlemail.com
Thu Nov 26 03:24:29 EST 2015


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?

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



More information about the openwrt-devel mailing list