From 08315ab8b728ce4adba62e11ada879b301318dd8 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 25 Feb 2015 21:43:54 +0100 Subject: [PATCH] libfstools: convert to ulog() api Signed-off-by: Jo-Philipp Wich --- libfstools/extroot.c | 9 +++++---- libfstools/find.c | 4 ++-- libfstools/libfstools.h | 1 + libfstools/mount.c | 10 +++++----- libfstools/mtd.c | 34 +++++++++++++++---------------- libfstools/overlay.c | 44 ++++++++++++++++++++--------------------- libfstools/snapshot.c | 40 ++++++++++++++++++------------------- libfstools/ubi.c | 2 +- 8 files changed, 73 insertions(+), 71 deletions(-) diff --git a/libfstools/extroot.c b/libfstools/extroot.c index 73ceae8..e548bb1 100644 --- a/libfstools/extroot.c +++ b/libfstools/extroot.c @@ -60,6 +60,7 @@ int mount_extroot(void) /* set LD_LIBRARY_PATH env var and load kmods from overlay if we found a lib directory there */ if (!stat(ldlib_path, &s) && S_ISDIR(s.st_mode)) { + ULOG_INFO("loading kmods from internal overlay\n"); setenv("LD_LIBRARY_PATH", ldlib_path, 1); snprintf(kmod_loader, sizeof(kmod_loader), "/sbin/kmodloader %s/etc/modules-boot.d/", dirname(ldlib_path)); @@ -86,10 +87,10 @@ int mount_extroot(void) mkdir("/tmp/extroot/mnt/rom", 0755); if (mount_move("/tmp/extroot", "", "/mnt")) { - fprintf(stderr, "moving pivotroot failed - continue normal boot\n"); + ULOG_ERR("moving pivotroot failed - continue normal boot\n"); umount("/tmp/extroot/mnt"); } else if (pivot("/mnt", "/rom")) { - fprintf(stderr, "switching to pivotroot failed - continue normal boot\n"); + ULOG_ERR("switching to pivotroot failed - continue normal boot\n"); umount("/mnt"); } else { umount("/tmp/overlay"); @@ -100,10 +101,10 @@ int mount_extroot(void) } } else if (find_mount("/tmp/extroot/overlay")) { if (mount_move("/tmp/extroot", "", "/overlay")) { - fprintf(stderr, "moving extroot failed - continue normal boot\n"); + ULOG_ERR("moving extroot failed - continue normal boot\n"); umount("/tmp/extroot/overlay"); } else if (fopivot("/overlay", "/rom")) { - fprintf(stderr, "switching to extroot failed - continue normal boot\n"); + ULOG_ERR("switching to extroot failed - continue normal boot\n"); umount("/overlay"); } else { umount("/tmp/overlay"); diff --git a/libfstools/find.c b/libfstools/find.c index 4c69d73..0440052 100644 --- a/libfstools/find.c +++ b/libfstools/find.c @@ -104,7 +104,7 @@ find_mount_point(char *block, int mtd_only) strncmp(t, "jffs2", 5) && strncmp(t, "ubifs", 5)) { fclose(fp); - fprintf(stderr, "block is mounted with wrong fs\n"); + ULOG_ERR("block is mounted with wrong fs\n"); return NULL; } point = p; @@ -126,7 +126,7 @@ find_filesystem(char *fs) int ret = -1; if (!fp) { - fprintf(stderr, "opening /proc/filesystems failed: %s\n", strerror(errno)); + ULOG_ERR("opening /proc/filesystems failed: %s\n", strerror(errno)); goto out; } diff --git a/libfstools/libfstools.h b/libfstools/libfstools.h index b03e432..a9f8576 100644 --- a/libfstools/libfstools.h +++ b/libfstools/libfstools.h @@ -16,6 +16,7 @@ #include #include +#include struct volume; diff --git a/libfstools/mount.c b/libfstools/mount.c index e095455..81176ce 100644 --- a/libfstools/mount.c +++ b/libfstools/mount.c @@ -48,7 +48,7 @@ mount_move(char *oldroot, char *newroot, char *dir) ret = mount(olddir, newdir, NULL, MS_NOATIME | MS_MOVE, NULL); /* if (ret) - fprintf(stderr, "failed %s %s: %s\n", olddir, newdir, strerror(errno));*/ + ULOG_ERR("failed %s %s: %s\n", olddir, newdir, strerror(errno));*/ return ret; } @@ -67,7 +67,7 @@ pivot(char *new, char *old) ret = pivot_root(new, pivotdir); if (ret < 0) { - fprintf(stderr, "pivot_root failed %s %s: %s\n", new, pivotdir, strerror(errno)); + ULOG_ERR("pivot_root failed %s %s: %s\n", new, pivotdir, strerror(errno)); return -1; } @@ -85,7 +85,7 @@ fopivot(char *rw_root, char *ro_root) char overlay[64], lowerdir[64]; if (find_filesystem("overlay")) { - fprintf(stderr, "BUG: no suitable fs found\n"); + ULOG_ERR("BUG: no suitable fs found\n"); return -1; } @@ -124,8 +124,8 @@ fopivot(char *rw_root, char *ro_root) /* Mainlined overlayfs has been renamed to "overlay", try that first */ if (mount(overlay, "/mnt", "overlay", MS_NOATIME, lowerdir)) { if (mount(overlay, "/mnt", "overlayfs", MS_NOATIME, lowerdir)) { - fprintf(stderr, "mount failed: %s, options %s\n", - strerror(errno), lowerdir); + ULOG_ERR("mount failed: %s, options %s\n", + strerror(errno), lowerdir); return -1; } } diff --git a/libfstools/mtd.c b/libfstools/mtd.c index b9daabc..d8637aa 100644 --- a/libfstools/mtd.c +++ b/libfstools/mtd.c @@ -86,13 +86,13 @@ static int mtd_volume_load(struct volume *v) p->fd = mtd_open(p->chr, 0); if (p->fd < 0) { p->fd = 0; - fprintf(stderr, "Could not open mtd device: %s\n", p->chr); + ULOG_ERR("Could not open mtd device: %s\n", p->chr); return -1; } if (ioctl(p->fd, MEMGETINFO, &mtdInfo)) { mtd_volume_close(v); - fprintf(stderr, "Could not get MTD device info from %s\n", p->chr); + ULOG_ERR("Could not get MTD device info from %s\n", p->chr); return -1; } @@ -173,7 +173,7 @@ static int mtd_volume_find(struct volume *v, char *name) p->chr = strdup(buffer); if (mtd_volume_load(v)) { - fprintf(stderr, "reading %s failed\n", v->name); + ULOG_ERR("reading %s failed\n", v->name); return -1; } @@ -188,14 +188,14 @@ static int mtd_volume_identify(struct volume *v) size_t sz; if (mtd_volume_load(v)) { - fprintf(stderr, "reading %s failed\n", v->name); + ULOG_ERR("reading %s failed\n", v->name); return -1; } sz = read(p->fd, &deadc0de, sizeof(deadc0de)); if (sz != sizeof(deadc0de)) { - fprintf(stderr, "reading %s failed: %s\n", v->name, strerror(errno)); + ULOG_ERR("reading %s failed: %s\n", v->name, strerror(errno)); return -1; } @@ -204,22 +204,22 @@ static int mtd_volume_identify(struct volume *v) deadc0de = __be32_to_cpu(deadc0de); if (deadc0de == 0xdeadc0de) { - fprintf(stderr, "jffs2 is not ready - marker found\n"); + ULOG_INFO("jffs2 is not ready - marker found\n"); return FS_DEADCODE; } jffs2 = __be16_to_cpu(deadc0de >> 16); if (jffs2 == 0x1985) { - fprintf(stderr, "jffs2 is ready\n"); + ULOG_INFO("jffs2 is ready\n"); return FS_JFFS2; } if (v->type == UBIVOLUME && deadc0de == 0xffffffff) { - fprintf(stderr, "jffs2 is ready\n"); + ULOG_INFO("jffs2 is ready\n"); return FS_JFFS2; } - fprintf(stderr, "No jffs2 marker was found\n"); + ULOG_INFO("No jffs2 marker was found\n"); return FS_NONE; } @@ -234,7 +234,7 @@ static int mtd_volume_erase(struct volume *v, int offset, int len) return -1; if (offset % v->block_size || len % v->block_size) { - fprintf(stderr, "mtd erase needs to be block aligned\n"); + ULOG_ERR("mtd erase needs to be block aligned\n"); return -1; } @@ -245,10 +245,10 @@ static int mtd_volume_erase(struct volume *v, int offset, int len) for (eiu.start = first_block * v->block_size; eiu.start < v->size && eiu.start < (first_block + num_blocks) * v->block_size; eiu.start += v->block_size) { - fprintf(stderr, "erasing %x %x\n", eiu.start, v->block_size); + ULOG_INFO("erasing %x %x\n", eiu.start, v->block_size); ioctl(p->fd, MEMUNLOCK, &eiu); if (ioctl(p->fd, MEMERASE, &eiu)) - fprintf(stderr, "Failed to erase block at 0x%x\n", eiu.start); + ULOG_ERR("Failed to erase block at 0x%x\n", eiu.start); } mtd_volume_close(v); @@ -275,7 +275,7 @@ static int mtd_volume_init(struct volume *v) ret = ioctl(p->fd, MEMGETINFO, &mtdinfo); if (ret) { - fprintf(stderr, "ioctl(%d, MEMGETINFO) failed: %s\n", p->fd, strerror(errno)); + ULOG_ERR("ioctl(%d, MEMGETINFO) failed: %s\n", p->fd, strerror(errno)); } else { struct erase_info_user mtdlock; @@ -295,12 +295,12 @@ static int mtd_volume_read(struct volume *v, void *buf, int offset, int length) return -1; if (lseek(p->fd, offset, SEEK_SET) == (off_t) -1) { - fprintf(stderr, "lseek/read failed\n"); + ULOG_ERR("lseek/read failed\n"); return -1; } if (read(p->fd, buf, length) == -1) { - fprintf(stderr, "read failed\n"); + ULOG_ERR("read failed\n"); return -1; } @@ -315,13 +315,13 @@ static int mtd_volume_write(struct volume *v, void *buf, int offset, int length) return -1; if (lseek(p->fd, offset, SEEK_SET) == (off_t) -1) { - fprintf(stderr, "lseek/write failed at offset %d\n", offset); + ULOG_ERR("lseek/write failed at offset %d\n", offset); perror("lseek"); return -1; } if (write(p->fd, buf, length) == -1) { - fprintf(stderr, "write failed\n"); + ULOG_ERR("write failed\n"); return -1; } diff --git a/libfstools/overlay.c b/libfstools/overlay.c index 9e830a1..bb506ee 100644 --- a/libfstools/overlay.c +++ b/libfstools/overlay.c @@ -42,7 +42,7 @@ foreachdir(const char *dir, int (*cb)(const char*)) if (dir[strlen(dir) - 1] == '/') snprintf(globdir, 256, "%s*", dir); else - snprintf(globdir, 256, "%s/*", dir); + snprintf(globdir, 256, "%s/*", dir); /**/ if (!glob(globdir, GLOB_NOESCAPE | GLOB_MARK | GLOB_ONLYDIR, NULL, &gl)) for (j = 0; j < gl.gl_pathc; j++) @@ -55,12 +55,12 @@ static int overlay_mount(struct volume *v, char *fs) { if (mkdir("/tmp/overlay", 0755)) { - fprintf(stderr, "failed to mkdir /tmp/overlay: %s\n", strerror(errno)); + ULOG_ERR("failed to mkdir /tmp/overlay: %s\n", strerror(errno)); return -1; } if (mount(v->blk, "/tmp/overlay", fs, MS_NOATIME, NULL)) { - fprintf(stderr, "failed to mount -t %s %s /tmp/overlay: %s\n", fs, v->blk, strerror(errno)); + ULOG_ERR("failed to mount -t %s %s /tmp/overlay: %s\n", fs, v->blk, strerror(errno)); return -1; } @@ -74,7 +74,7 @@ switch2jffs(struct volume *v) int ret; if (!stat(SWITCH_JFFS2, &s)) { - fprintf(stderr, "jffs2 switch already running\n"); + ULOG_ERR("jffs2 switch already running\n"); return -1; } @@ -82,24 +82,24 @@ switch2jffs(struct volume *v) ret = mount(v->blk, "/rom/overlay", "jffs2", MS_NOATIME, NULL); unlink("/tmp/.switch_jffs2"); if (ret) { - fprintf(stderr, "failed - mount -t jffs2 %s /rom/overlay: %s\n", v->blk, strerror(errno)); + ULOG_ERR("failed - mount -t jffs2 %s /rom/overlay: %s\n", v->blk, strerror(errno)); return -1; } if (mount("none", "/", NULL, MS_NOATIME | MS_REMOUNT, 0)) { - fprintf(stderr, "failed - mount -o remount,ro none: %s\n", strerror(errno)); + ULOG_ERR("failed - mount -o remount,ro none: %s\n", strerror(errno)); return -1; } - system("cp -a /tmp/root/* /rom/overlay"); + system("cp -a /tmp/root/* /rom/overlay"); /**/ if (pivot("/rom", "/mnt")) { - fprintf(stderr, "failed - pivot /rom /mnt: %s\n", strerror(errno)); + ULOG_ERR("failed - pivot /rom /mnt: %s\n", strerror(errno)); return -1; } if (mount_move("/mnt", "/tmp/root", "")) { - fprintf(stderr, "failed - mount -o move /mnt /tmp/root %s\n", strerror(errno)); + ULOG_ERR("failed - mount -o move /mnt /tmp/root %s\n", strerror(errno)); return -1; } @@ -152,25 +152,25 @@ jffs2_switch(struct volume *v) return -1; if (find_filesystem("overlay")) { - fprintf(stderr, "overlayfs not found\n"); + ULOG_ERR("overlayfs not supported by kernel\n"); return ret; } mp = find_mount_point(v->blk, 0); if (mp) { - fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", v->blk, mp); + ULOG_ERR("rootfs_data:%s is already mounted as %s\n", v->blk, mp); return -1; } switch (volume_identify(v)) { case FS_NONE: - fprintf(stderr, "no jffs2 marker found\n"); + ULOG_ERR("no jffs2 marker found\n"); /* fall through */ case FS_DEADCODE: ret = switch2jffs(v); if (!ret) { - fprintf(stderr, "doing fo cleanup\n"); + ULOG_INFO("performing overlay whiteout\n"); umount2("/tmp/root", MNT_DETACH); foreachdir("/overlay/", handle_whiteout); } @@ -181,7 +181,7 @@ jffs2_switch(struct volume *v) if (ret) break; if (mount_move("/tmp", "", "/overlay") || fopivot("/overlay", "/rom")) { - fprintf(stderr, "switching to jffs2 failed\n"); + ULOG_ERR("switching to jffs2 failed\n"); ret = -1; } break; @@ -191,7 +191,7 @@ jffs2_switch(struct volume *v) if (ret) break; if (mount_move("/tmp", "", "/overlay") || fopivot("/overlay", "/rom")) { - fprintf(stderr, "switching to ubifs failed\n"); + ULOG_ERR("switching to ubifs failed\n"); ret = -1; } break; @@ -204,7 +204,7 @@ static int overlay_mount_fs(struct volume *v) char *fstype; if (mkdir("/tmp/overlay", 0755)) { - fprintf(stderr, "failed to mkdir /tmp/overlay: %s\n", strerror(errno)); + ULOG_ERR("failed to mkdir /tmp/overlay: %s\n", strerror(errno)); return -1; } @@ -217,8 +217,8 @@ static int overlay_mount_fs(struct volume *v) } if (mount(v->blk, "/tmp/overlay", fstype, MS_NOATIME, NULL)) { - fprintf(stderr, "failed to mount -t %s %s /tmp/overlay: %s\n", - fstype, v->blk, strerror(errno)); + ULOG_ERR("failed to mount -t %s %s /tmp/overlay: %s\n", + fstype, v->blk, strerror(errno)); return -1; } @@ -236,7 +236,7 @@ int mount_overlay(struct volume *v) mp = find_mount_point(v->blk, 0); if (mp) { - fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", v->blk, mp); + ULOG_ERR("rootfs_data:%s is already mounted as %s\n", v->blk, mp); return -1; } @@ -244,13 +244,13 @@ int mount_overlay(struct volume *v) extroot_prefix = "/tmp/overlay"; if (!mount_extroot()) { - fprintf(stderr, "switched to extroot\n"); + ULOG_INFO("switched to extroot\n"); return 0; } - fprintf(stderr, "switching to overlay\n"); + ULOG_INFO("switching to overlay\n"); if (mount_move("/tmp", "", "/overlay") || fopivot("/overlay", "/rom")) { - fprintf(stderr, "switching to jffs2 failed - fallback to ramoverlay\n"); + ULOG_ERR("switching to jffs2 failed - fallback to ramoverlay\n"); return ramoverlay(); } diff --git a/libfstools/snapshot.c b/libfstools/snapshot.c index f2ee0cd..1ec7b87 100644 --- a/libfstools/snapshot.c +++ b/libfstools/snapshot.c @@ -40,12 +40,12 @@ verify_file_hash(char *file, uint32_t *hash) uint32_t md5[4]; if (md5sum(file, md5)) { - fprintf(stderr, "failed to generate md5 sum\n"); + ULOG_ERR("failed to generate md5 sum\n"); return -1; } if (memcmp(md5, hash, sizeof(md5))) { - fprintf(stderr, "failed to verify hash of %s.\n", file); + ULOG_ERR("failed to verify hash of %s.\n", file); return -1; } @@ -62,7 +62,7 @@ snapshot_next_free(struct volume *v, uint32_t *seq) do { if (volume_read(v, &hdr, block * v->block_size, sizeof(struct file_header))) { - fprintf(stderr, "scanning for next free block failed\n"); + ULOG_ERR("scanning for next free block failed\n"); return 0; } @@ -95,7 +95,7 @@ config_find(struct volume *v, struct file_header *conf, struct file_header *sent for (i = (v->size / v->block_size) - 1; i > 0; i--) { if (volume_read(v, sentinel, i * v->block_size, sizeof(*sentinel))) { - fprintf(stderr, "failed to read header\n"); + ULOG_ERR("failed to read header\n"); return -1; } be32_to_hdr(sentinel); @@ -121,12 +121,12 @@ snapshot_write_file(struct volume *v, int block, char *file, uint32_t seq, uint3 int ret = -1; if (stat(file, &s) || md5sum(file, md5)) { - fprintf(stderr, "stat failed on %s\n", file); + ULOG_ERR("stat failed on %s\n", file); goto out; } if ((block * v->block_size) + pad_file_size(v, s.st_size) > v->size) { - fprintf(stderr, "upgrade is too big for the flash\n"); + ULOG_ERR("upgrade is too big for the flash\n"); goto out; } volume_erase(v, block * v->block_size, pad_file_size(v, s.st_size)); @@ -140,13 +140,13 @@ snapshot_write_file(struct volume *v, int block, char *file, uint32_t seq, uint3 hdr_to_be32(&hdr); if (volume_write(v, &hdr, block * v->block_size, sizeof(struct file_header))) { - fprintf(stderr, "failed to write header\n"); + ULOG_ERR("failed to write header\n"); goto out; } in = open(file, O_RDONLY); if (in < 1) { - fprintf(stderr, "failed to open %s\n", file); + ULOG_ERR("failed to open %s\n", file); goto out; } @@ -175,7 +175,7 @@ snapshot_read_file(struct volume *v, int block, char *file, uint32_t type) int out, offset = 0; if (volume_read(v, &hdr, block * v->block_size, sizeof(struct file_header))) { - fprintf(stderr, "failed to read header\n"); + ULOG_ERR("failed to read header\n"); return -1; } be32_to_hdr(&hdr); @@ -191,7 +191,7 @@ snapshot_read_file(struct volume *v, int block, char *file, uint32_t type) out = open(file, O_WRONLY | O_CREAT, 0700); if (!out) { - fprintf(stderr, "failed to open %s\n", file); + ULOG_ERR("failed to open %s\n", file); return -1; } @@ -214,7 +214,7 @@ snapshot_read_file(struct volume *v, int block, char *file, uint32_t type) close(out); if (verify_file_hash(file, hdr.md5)) { - fprintf(stderr, "md5 verification failed\n"); + ULOG_ERR("md5 verification failed\n"); unlink(file); return 0; } @@ -232,7 +232,7 @@ sentinel_write(struct volume *v, uint32_t _seq) uint32_t seq; if (stat("/tmp/config.tar.gz", &s)) { - fprintf(stderr, "failed to stat /tmp/config.tar.gz\n"); + ULOG_ERR("failed to stat /tmp/config.tar.gz\n"); return -1; } @@ -246,9 +246,9 @@ sentinel_write(struct volume *v, uint32_t _seq) ret = snapshot_write_file(v, block, "/tmp/config.tar.gz", seq, CONF); if (ret) - fprintf(stderr, "failed to write sentinel\n"); + ULOG_ERR("failed to write sentinel\n"); else - fprintf(stderr, "wrote /tmp/config.tar.gz sentinel\n"); + ULOG_INFO("wrote /tmp/config.tar.gz sentinel\n"); return ret; } @@ -266,9 +266,9 @@ volatile_write(struct volume *v, uint32_t _seq) ret = snapshot_write_file(v, block, "/tmp/config.tar.gz", seq, CONF); if (ret) - fprintf(stderr, "failed to write /tmp/config.tar.gz\n"); + ULOG_ERR("failed to write /tmp/config.tar.gz\n"); else - fprintf(stderr, "wrote /tmp/config.tar.gz\n"); + ULOG_INFO("wrote /tmp/config.tar.gz\n"); return ret; } @@ -292,7 +292,7 @@ snapshot_sync(struct volume *v) } if (!is_config(&conf) && !is_config(&sentinel)) { - // fprintf(stderr, "no config found\n"); + // ULOG_ERR("no config found\n"); } else if (((is_config(&conf) && is_config(&sentinel)) && (memcmp(conf.md5, sentinel.md5, sizeof(conf.md5)) || (conf.seq != sentinel.seq))) || (is_config(&conf) && !is_config(&sentinel))) { @@ -301,15 +301,15 @@ snapshot_sync(struct volume *v) int ret = snapshot_read_file(v, next, "/tmp/config.tar.gz", CONF); if (ret > 0) { if (sentinel_write(v, conf.seq)) - fprintf(stderr, "failed to write sentinel data"); + ULOG_ERR("failed to write sentinel data"); } } else if (!is_config(&conf) && is_config(&sentinel) && next) { int ret = snapshot_read_file(v, block, "/tmp/config.tar.gz", CONF); if (ret > 0) if (volatile_write(v, sentinel.seq)) - fprintf(stderr, "failed to write sentinel data"); + ULOG_ERR("failed to write sentinel data"); } else - fprintf(stderr, "config in sync\n"); + ULOG_INFO("config in sync\n"); unlink("/tmp/config.tar.gz"); diff --git a/libfstools/ubi.c b/libfstools/ubi.c index 0f6e37a..c5a33df 100644 --- a/libfstools/ubi.c +++ b/libfstools/ubi.c @@ -144,7 +144,7 @@ static int ubi_volume_match(struct volume *v, char *name, int ubi_num, int volid volname = read_string_from_file(voldir, "name"); if (!volname) { - fprintf(stderr, "Couldn't read %s/name\n", voldir); + ULOG_ERR("Couldn't read %s/name\n", voldir); return -1; } -- 2.25.1