This source file includes following definitions.
- squashfs_inode_lookup
- squashfs_export_iget
- squashfs_fh_to_dentry
- squashfs_fh_to_parent
- squashfs_get_parent
- squashfs_read_inode_lookup_table
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include <linux/fs.h>
26 #include <linux/vfs.h>
27 #include <linux/dcache.h>
28 #include <linux/exportfs.h>
29 #include <linux/slab.h>
30
31 #include "squashfs_fs.h"
32 #include "squashfs_fs_sb.h"
33 #include "squashfs_fs_i.h"
34 #include "squashfs.h"
35
36
37
38
39 static long long squashfs_inode_lookup(struct super_block *sb, int ino_num)
40 {
41 struct squashfs_sb_info *msblk = sb->s_fs_info;
42 int blk = SQUASHFS_LOOKUP_BLOCK(ino_num - 1);
43 int offset = SQUASHFS_LOOKUP_BLOCK_OFFSET(ino_num - 1);
44 u64 start = le64_to_cpu(msblk->inode_lookup_table[blk]);
45 __le64 ino;
46 int err;
47
48 TRACE("Entered squashfs_inode_lookup, inode_number = %d\n", ino_num);
49
50 err = squashfs_read_metadata(sb, &ino, &start, &offset, sizeof(ino));
51 if (err < 0)
52 return err;
53
54 TRACE("squashfs_inode_lookup, inode = 0x%llx\n",
55 (u64) le64_to_cpu(ino));
56
57 return le64_to_cpu(ino);
58 }
59
60
61 static struct dentry *squashfs_export_iget(struct super_block *sb,
62 unsigned int ino_num)
63 {
64 long long ino;
65 struct dentry *dentry = ERR_PTR(-ENOENT);
66
67 TRACE("Entered squashfs_export_iget\n");
68
69 ino = squashfs_inode_lookup(sb, ino_num);
70 if (ino >= 0)
71 dentry = d_obtain_alias(squashfs_iget(sb, ino, ino_num));
72
73 return dentry;
74 }
75
76
77 static struct dentry *squashfs_fh_to_dentry(struct super_block *sb,
78 struct fid *fid, int fh_len, int fh_type)
79 {
80 if ((fh_type != FILEID_INO32_GEN && fh_type != FILEID_INO32_GEN_PARENT)
81 || fh_len < 2)
82 return NULL;
83
84 return squashfs_export_iget(sb, fid->i32.ino);
85 }
86
87
88 static struct dentry *squashfs_fh_to_parent(struct super_block *sb,
89 struct fid *fid, int fh_len, int fh_type)
90 {
91 if (fh_type != FILEID_INO32_GEN_PARENT || fh_len < 4)
92 return NULL;
93
94 return squashfs_export_iget(sb, fid->i32.parent_ino);
95 }
96
97
98 static struct dentry *squashfs_get_parent(struct dentry *child)
99 {
100 struct inode *inode = d_inode(child);
101 unsigned int parent_ino = squashfs_i(inode)->parent;
102
103 return squashfs_export_iget(inode->i_sb, parent_ino);
104 }
105
106
107
108
109
110 __le64 *squashfs_read_inode_lookup_table(struct super_block *sb,
111 u64 lookup_table_start, u64 next_table, unsigned int inodes)
112 {
113 unsigned int length = SQUASHFS_LOOKUP_BLOCK_BYTES(inodes);
114 __le64 *table;
115
116 TRACE("In read_inode_lookup_table, length %d\n", length);
117
118
119
120
121 if (inodes == 0)
122 return ERR_PTR(-EINVAL);
123
124
125
126
127
128 if (lookup_table_start + length > next_table)
129 return ERR_PTR(-EINVAL);
130
131 table = squashfs_read_table(sb, lookup_table_start, length);
132
133
134
135
136
137 if (!IS_ERR(table) && le64_to_cpu(table[0]) >= lookup_table_start) {
138 kfree(table);
139 return ERR_PTR(-EINVAL);
140 }
141
142 return table;
143 }
144
145
146 const struct export_operations squashfs_export_ops = {
147 .fh_to_dentry = squashfs_fh_to_dentry,
148 .fh_to_parent = squashfs_fh_to_parent,
149 .get_parent = squashfs_get_parent
150 };