2 * Copyright (C) 2015 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "squashfs_utils.h"
19 #include <cutils/klog.h>
26 #include "squashfs_fs.h"
28 #define ERROR(x...) KLOG_ERROR("squashfs_utils", x)
30 int squashfs_parse_sb(char *blk_device, struct squashfs_info *info) {
32 struct squashfs_super_block sb;
35 data_device = TEMP_FAILURE_RETRY(open(blk_device, O_RDONLY | O_CLOEXEC));
36 if (data_device == -1) {
37 ERROR("Error opening block device (%s)\n", strerror(errno));
41 if (TEMP_FAILURE_RETRY(read(data_device, &sb, sizeof(sb)))
43 ERROR("Error reading superblock\n");
47 if (sb.s_magic != SQUASHFS_MAGIC) {
48 ERROR("Not a valid squashfs filesystem\n");
53 info->block_size = sb.block_size;
54 info->inodes = sb.inodes;
55 info->bytes_used = sb.bytes_used;
56 // by default mksquashfs pads the filesystem to 4K blocks
57 info->bytes_used_4K_padded =
58 sb.bytes_used + (4096 - (sb.bytes_used & (4096 - 1)));
61 TEMP_FAILURE_RETRY(close(data_device));