summaryrefslogtreecommitdiff
path: root/squashfs_utils
diff options
context:
space:
mode:
authorSami Tolvanen <samitolvanen@google.com>2015-06-01 10:46:06 +0100
committerSami Tolvanen <samitolvanen@google.com>2015-06-25 16:08:52 +0100
commitd640b023a6272852551550df15c2de01c335d43d (patch)
treebd0c82cb3d180fae7ee03a0f15367e7419226681 /squashfs_utils
parent1ad2d5aa16b08b5955bfe0f883bc26c396313916 (diff)
downloadextras-d640b023a6272852551550df15c2de01c335d43d.tar.gz
squashfs_utils: Add host library and parsing from buffer
Allow the squashfs_utils library to be used on host and add a function to parse the super block from a buffer. Change-Id: I7cc59cba9882e159faeb0b203df20aaefb5c6e16
Diffstat (limited to 'squashfs_utils')
-rw-r--r--squashfs_utils/Android.mk8
-rw-r--r--squashfs_utils/squashfs_utils.c42
-rw-r--r--squashfs_utils/squashfs_utils.h5
3 files changed, 45 insertions, 10 deletions
diff --git a/squashfs_utils/Android.mk b/squashfs_utils/Android.mk
index c3d2f2d1..2e0456a1 100644
--- a/squashfs_utils/Android.mk
+++ b/squashfs_utils/Android.mk
@@ -9,6 +9,14 @@ LOCAL_C_INCLUDES := external/squashfs-tools/squashfs-tools
LOCAL_MODULE := libsquashfs_utils
include $(BUILD_STATIC_LIBRARY)
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := squashfs_utils.c
+LOCAL_STATIC_LIBRARIES := libcutils
+LOCAL_C_INCLUDES := external/squashfs-tools/squashfs-tools
+LOCAL_CFLAGS := -Wall -Werror -D_GNU_SOURCE -DSQUASHFS_NO_KLOG
+LOCAL_MODULE := libsquashfs_utils_host
+include $(BUILD_HOST_STATIC_LIBRARY)
+
ifeq ($(HOST_OS),linux)
include $(CLEAR_VARS)
diff --git a/squashfs_utils/squashfs_utils.c b/squashfs_utils/squashfs_utils.c
index 61891895..1d619ce5 100644
--- a/squashfs_utils/squashfs_utils.c
+++ b/squashfs_utils/squashfs_utils.c
@@ -25,9 +25,39 @@
#include "squashfs_fs.h"
+#ifdef SQUASHFS_NO_KLOG
+#include <stdio.h>
+#define ERROR(x...) fprintf(stderr, x)
+#else
#define ERROR(x...) KLOG_ERROR("squashfs_utils", x)
+#endif
-int squashfs_parse_sb(char *blk_device, struct squashfs_info *info) {
+size_t squashfs_get_sb_size()
+{
+ return sizeof(struct squashfs_super_block);
+}
+
+int squashfs_parse_sb_buffer(const void *buf, struct squashfs_info *info)
+{
+ const struct squashfs_super_block *sb =
+ (const struct squashfs_super_block *)buf;
+
+ if (sb->s_magic != SQUASHFS_MAGIC) {
+ return -1;
+ }
+
+ info->block_size = sb->block_size;
+ info->inodes = sb->inodes;
+ info->bytes_used = sb->bytes_used;
+ // by default mksquashfs pads the filesystem to 4K blocks
+ info->bytes_used_4K_padded =
+ sb->bytes_used + (4096 - (sb->bytes_used & (4096 - 1)));
+
+ return 0;
+}
+
+int squashfs_parse_sb(const char *blk_device, struct squashfs_info *info)
+{
int ret = 0;
struct squashfs_super_block sb;
int data_device;
@@ -44,19 +74,13 @@ int squashfs_parse_sb(char *blk_device, struct squashfs_info *info) {
ret = -1;
goto cleanup;
}
- if (sb.s_magic != SQUASHFS_MAGIC) {
+
+ if (squashfs_parse_sb_buffer(&sb, info) == -1) {
ERROR("Not a valid squashfs filesystem\n");
ret = -1;
goto cleanup;
}
- info->block_size = sb.block_size;
- info->inodes = sb.inodes;
- info->bytes_used = sb.bytes_used;
- // by default mksquashfs pads the filesystem to 4K blocks
- info->bytes_used_4K_padded =
- sb.bytes_used + (4096 - (sb.bytes_used & (4096 - 1)));
-
cleanup:
close(data_device);
return ret;
diff --git a/squashfs_utils/squashfs_utils.h b/squashfs_utils/squashfs_utils.h
index ccad32dd..465429fb 100644
--- a/squashfs_utils/squashfs_utils.h
+++ b/squashfs_utils/squashfs_utils.h
@@ -17,6 +17,7 @@
#ifndef _SQUASHFS_UTILS_H_
#define _SQUASHFS_UTILS_H_
+#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
@@ -30,7 +31,9 @@ struct squashfs_info {
uint64_t bytes_used_4K_padded;
};
-int squashfs_parse_sb(char *blk_device, struct squashfs_info *info);
+size_t squashfs_get_sb_size();
+int squashfs_parse_sb_buffer(const void *data, struct squashfs_info *info);
+int squashfs_parse_sb(const char *blk_device, struct squashfs_info *info);
#ifdef __cplusplus
}