0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <linux/fs.h>
0022 #include <linux/vfs.h>
0023 #include <linux/slab.h>
0024
0025 #include "squashfs_fs.h"
0026 #include "squashfs_fs_sb.h"
0027 #include "squashfs.h"
0028
0029
0030
0031
0032 int squashfs_get_id(struct super_block *sb, unsigned int index,
0033 unsigned int *id)
0034 {
0035 struct squashfs_sb_info *msblk = sb->s_fs_info;
0036 int block = SQUASHFS_ID_BLOCK(index);
0037 int offset = SQUASHFS_ID_BLOCK_OFFSET(index);
0038 u64 start_block;
0039 __le32 disk_id;
0040 int err;
0041
0042 if (index >= msblk->ids)
0043 return -EINVAL;
0044
0045 start_block = le64_to_cpu(msblk->id_table[block]);
0046
0047 err = squashfs_read_metadata(sb, &disk_id, &start_block, &offset,
0048 sizeof(disk_id));
0049 if (err < 0)
0050 return err;
0051
0052 *id = le32_to_cpu(disk_id);
0053 return 0;
0054 }
0055
0056
0057
0058
0059
0060 __le64 *squashfs_read_id_index_table(struct super_block *sb,
0061 u64 id_table_start, u64 next_table, unsigned short no_ids)
0062 {
0063 unsigned int length = SQUASHFS_ID_BLOCK_BYTES(no_ids);
0064 unsigned int indexes = SQUASHFS_ID_BLOCKS(no_ids);
0065 int n;
0066 __le64 *table;
0067 u64 start, end;
0068
0069 TRACE("In read_id_index_table, length %d\n", length);
0070
0071
0072
0073
0074 if (no_ids == 0)
0075 return ERR_PTR(-EINVAL);
0076
0077
0078
0079
0080
0081 if (length != (next_table - id_table_start))
0082 return ERR_PTR(-EINVAL);
0083
0084 table = squashfs_read_table(sb, id_table_start, length);
0085 if (IS_ERR(table))
0086 return table;
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 for (n = 0; n < (indexes - 1); n++) {
0097 start = le64_to_cpu(table[n]);
0098 end = le64_to_cpu(table[n + 1]);
0099
0100 if (start >= end || (end - start) >
0101 (SQUASHFS_METADATA_SIZE + SQUASHFS_BLOCK_OFFSET)) {
0102 kfree(table);
0103 return ERR_PTR(-EINVAL);
0104 }
0105 }
0106
0107 start = le64_to_cpu(table[indexes - 1]);
0108 if (start >= id_table_start || (id_table_start - start) >
0109 (SQUASHFS_METADATA_SIZE + SQUASHFS_BLOCK_OFFSET)) {
0110 kfree(table);
0111 return ERR_PTR(-EINVAL);
0112 }
0113
0114 return table;
0115 }