summaryrefslogtreecommitdiff
path: root/squashfs_utils
diff options
context:
space:
mode:
authorMohamad Ayyash <mkayyash@google.com>2015-04-01 19:25:28 -0700
committerSimon Wilson <simonwilson@google.com>2015-06-16 13:21:53 -0700
commit01e42b24c9b56b3ca88a2cf563a8c695d5a74534 (patch)
tree266b4e80fc98cab19a41a2ec3550deb054fee787 /squashfs_utils
parenteca016ebf90d625a331d94bfda03d61717deaf73 (diff)
downloadextras-01e42b24c9b56b3ca88a2cf563a8c695d5a74534.tar.gz
Introduce squashfs-utils that includes helper functions
For example: extracting filesystem size from superblock Change-Id: I97c79d80ebb767a977c8ca27f7e0877b5ead8fdc Signed-off-by: Mohamad Ayyash <mkayyash@google.com>
Diffstat (limited to 'squashfs_utils')
-rw-r--r--squashfs_utils/Android.mk7
-rw-r--r--squashfs_utils/squashfs_utils.c63
-rw-r--r--squashfs_utils/squashfs_utils.h39
3 files changed, 109 insertions, 0 deletions
diff --git a/squashfs_utils/Android.mk b/squashfs_utils/Android.mk
index 7808ec0d..c3d2f2d1 100644
--- a/squashfs_utils/Android.mk
+++ b/squashfs_utils/Android.mk
@@ -2,6 +2,13 @@
LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := squashfs_utils.c
+LOCAL_STATIC_LIBRARIES := libcutils
+LOCAL_C_INCLUDES := external/squashfs-tools/squashfs-tools
+LOCAL_MODULE := libsquashfs_utils
+include $(BUILD_STATIC_LIBRARY)
+
ifeq ($(HOST_OS),linux)
include $(CLEAR_VARS)
diff --git a/squashfs_utils/squashfs_utils.c b/squashfs_utils/squashfs_utils.c
new file mode 100644
index 00000000..128a3ef8
--- /dev/null
+++ b/squashfs_utils/squashfs_utils.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "squashfs_utils.h"
+
+#include <cutils/klog.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "squashfs_fs.h"
+
+#define ERROR(x...) KLOG_ERROR("squashfs_utils", x)
+
+int squashfs_parse_sb(char *blk_device, struct squashfs_info *info) {
+ int ret = 0;
+ struct squashfs_super_block sb;
+ int data_device;
+
+ data_device = TEMP_FAILURE_RETRY(open(blk_device, O_RDONLY | O_CLOEXEC));
+ if (data_device == -1) {
+ ERROR("Error opening block device (%s)\n", strerror(errno));
+ return -1;
+ }
+
+ if (TEMP_FAILURE_RETRY(read(data_device, &sb, sizeof(sb)))
+ != sizeof(sb)) {
+ ERROR("Error reading superblock\n");
+ ret = -1;
+ goto cleanup;
+ }
+ if (sb.s_magic != SQUASHFS_MAGIC) {
+ 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:
+ TEMP_FAILURE_RETRY(close(data_device));
+ return ret;
+}
diff --git a/squashfs_utils/squashfs_utils.h b/squashfs_utils/squashfs_utils.h
new file mode 100644
index 00000000..ccad32dd
--- /dev/null
+++ b/squashfs_utils/squashfs_utils.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _SQUASHFS_UTILS_H_
+#define _SQUASHFS_UTILS_H_
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct squashfs_info {
+ uint32_t block_size;
+ uint32_t inodes;
+ uint64_t bytes_used;
+ uint64_t bytes_used_4K_padded;
+};
+
+int squashfs_parse_sb(char *blk_device, struct squashfs_info *info);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif