From: Felix Fietkau Date: Mon, 25 May 2015 21:55:07 +0000 (+0200) Subject: mount_root: use symlink instead of xattr to store initialization state X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=09027fc86babc3986027a0e677aca1b6999a9e14;p=oweals%2Ffstools.git mount_root: use symlink instead of xattr to store initialization state xattr seems to be unreliable with jffs2 Signed-off-by: Felix Fietkau --- diff --git a/libfstools/overlay.c b/libfstools/overlay.c index 0677c34..62a99f8 100644 --- a/libfstools/overlay.c +++ b/libfstools/overlay.c @@ -14,7 +14,6 @@ #include #include #include -#include #include @@ -35,18 +34,6 @@ static bool keep_sysupgrade; -static ssize_t -fs_getxattr(const char *path, const char *name, void *value, size_t size) -{ - return syscall(__NR_getxattr, path, name, value, size); -} - -static ssize_t -fs_setxattr(const char *path, const char *name, const void *value, size_t size, int flags) -{ - return syscall(__NR_setxattr, path, name, value, size, flags); -} - static int handle_rmdir(const char *dir) { @@ -290,11 +277,20 @@ static int overlay_mount_fs(struct volume *v) enum fs_state fs_state_get(const char *dir) { + char *path; + char valstr[16]; uint32_t val; + ssize_t len; - if (fs_getxattr(dir, "user.fs_state", &val, sizeof(val)) != sizeof(val)) + path = alloca(strlen(dir) + 1 + sizeof("/.fs_state")); + sprintf(path, "%s/.fs_state", dir); + len = readlink(path, valstr, sizeof(valstr) - 1); + if (len < 0) return FS_STATE_UNKNOWN; + valstr[len] = 0; + val = atoi(valstr); + if (val > __FS_STATE_LAST) return FS_STATE_UNKNOWN; @@ -304,9 +300,15 @@ enum fs_state fs_state_get(const char *dir) int fs_state_set(const char *dir, enum fs_state state) { - uint32_t val = 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 fs_setxattr(dir, "user.fs_state", &val, sizeof(val), 0); + return symlink(valstr, path); }