1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020 Bootlin
5 * Author: Joao Marcos Costa <joaomarcos.costa@bootlin.com>
9 #include <linux/types.h>
10 #include <asm/byteorder.h>
15 #include "sqfs_filesystem.h"
16 #include "sqfs_utils.h"
18 bool sqfs_is_dir(u16 type)
20 return type == SQFS_DIR_TYPE || type == SQFS_LDIR_TYPE;
24 * Receives a pointer (void *) to a position in the inode table containing the
25 * directory's inode. Returns directory inode offset into the directory table.
26 * m_list contains each metadata block's position, and m_count is the number of
27 * elements of m_list. Those metadata blocks come from the compressed directory
30 int sqfs_dir_offset(void *dir_i, u32 *m_list, int m_count)
32 struct squashfs_base_inode *base = dir_i;
33 struct squashfs_ldir_inode *ldir;
34 struct squashfs_dir_inode *dir;
38 switch (get_unaligned_le16(&base->inode_type)) {
40 dir = (struct squashfs_dir_inode *)base;
41 start_block = get_unaligned_le32(&dir->start_block);
42 offset = get_unaligned_le16(&dir->offset);
45 ldir = (struct squashfs_ldir_inode *)base;
46 start_block = get_unaligned_le32(&ldir->start_block);
47 offset = get_unaligned_le16(&ldir->offset);
50 printf("Error: this is not a directory.\n");
57 for (j = 0; j < m_count; j++) {
58 if (m_list[j] == start_block)
59 return (++j * SQFS_METADATA_BLOCK_SIZE) + offset;
65 printf("Error: invalid inode reference to directory table.\n");
70 bool sqfs_is_empty_dir(void *dir_i)
72 struct squashfs_base_inode *base = dir_i;
73 struct squashfs_ldir_inode *ldir;
74 struct squashfs_dir_inode *dir;
77 switch (get_unaligned_le16(&base->inode_type)) {
79 dir = (struct squashfs_dir_inode *)base;
80 file_size = get_unaligned_le16(&dir->file_size);
83 ldir = (struct squashfs_ldir_inode *)base;
84 file_size = get_unaligned_le16(&ldir->file_size);
87 printf("Error: this is not a directory.\n");
91 return file_size == SQFS_EMPTY_FILE_SIZE;