aboutsummaryrefslogtreecommitdiffstats
path: root/fs/squashfs
diff options
context:
space:
mode:
authorPhillip Lougher <phillip@lougher.demon.co.uk>2010-05-16 23:06:56 -0400
committerPhillip Lougher <phillip@lougher.demon.co.uk>2010-05-17 14:54:06 -0400
commit67f66cc6c728de183d9d43c243cb163c1ebd8e04 (patch)
treebd175ed5f66594ad76d099461560c3fe8a01181c /fs/squashfs
parentf41d207cbedecd82f797adcce83890aa96f1c9e9 (diff)
squashfs: add new extended inode types
Add new extended inode types that store the xattr_id field. Also add the necessary code changes to make xattrs visibile. Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
Diffstat (limited to 'fs/squashfs')
-rw-r--r--fs/squashfs/inode.c91
-rw-r--r--fs/squashfs/namei.c5
-rw-r--r--fs/squashfs/squashfs.h12
-rw-r--r--fs/squashfs/squashfs_fs.h25
-rw-r--r--fs/squashfs/super.c8
-rw-r--r--fs/squashfs/symlink.c10
6 files changed, 135 insertions, 16 deletions
diff --git a/fs/squashfs/inode.c b/fs/squashfs/inode.c
index 49daaf669e41..250701180a3b 100644
--- a/fs/squashfs/inode.c
+++ b/fs/squashfs/inode.c
@@ -40,6 +40,7 @@
40 40
41#include <linux/fs.h> 41#include <linux/fs.h>
42#include <linux/vfs.h> 42#include <linux/vfs.h>
43#include <linux/xattr.h>
43 44
44#include "squashfs_fs.h" 45#include "squashfs_fs.h"
45#include "squashfs_fs_sb.h" 46#include "squashfs_fs_sb.h"
@@ -111,6 +112,7 @@ int squashfs_read_inode(struct inode *inode, long long ino)
111 int err, type, offset = SQUASHFS_INODE_OFFSET(ino); 112 int err, type, offset = SQUASHFS_INODE_OFFSET(ino);
112 union squashfs_inode squashfs_ino; 113 union squashfs_inode squashfs_ino;
113 struct squashfs_base_inode *sqshb_ino = &squashfs_ino.base; 114 struct squashfs_base_inode *sqshb_ino = &squashfs_ino.base;
115 int xattr_id = SQUASHFS_INVALID_XATTR;
114 116
115 TRACE("Entered squashfs_read_inode\n"); 117 TRACE("Entered squashfs_read_inode\n");
116 118
@@ -199,8 +201,10 @@ int squashfs_read_inode(struct inode *inode, long long ino)
199 frag_offset = 0; 201 frag_offset = 0;
200 } 202 }
201 203
204 xattr_id = le32_to_cpu(sqsh_ino->xattr);
202 inode->i_nlink = le32_to_cpu(sqsh_ino->nlink); 205 inode->i_nlink = le32_to_cpu(sqsh_ino->nlink);
203 inode->i_size = le64_to_cpu(sqsh_ino->file_size); 206 inode->i_size = le64_to_cpu(sqsh_ino->file_size);
207 inode->i_op = &squashfs_inode_ops;
204 inode->i_fop = &generic_ro_fops; 208 inode->i_fop = &generic_ro_fops;
205 inode->i_mode |= S_IFREG; 209 inode->i_mode |= S_IFREG;
206 inode->i_blocks = ((inode->i_size - 210 inode->i_blocks = ((inode->i_size -
@@ -251,6 +255,7 @@ int squashfs_read_inode(struct inode *inode, long long ino)
251 if (err < 0) 255 if (err < 0)
252 goto failed_read; 256 goto failed_read;
253 257
258 xattr_id = le32_to_cpu(sqsh_ino->xattr);
254 inode->i_nlink = le32_to_cpu(sqsh_ino->nlink); 259 inode->i_nlink = le32_to_cpu(sqsh_ino->nlink);
255 inode->i_size = le32_to_cpu(sqsh_ino->file_size); 260 inode->i_size = le32_to_cpu(sqsh_ino->file_size);
256 inode->i_op = &squashfs_dir_inode_ops; 261 inode->i_op = &squashfs_dir_inode_ops;
@@ -280,21 +285,33 @@ int squashfs_read_inode(struct inode *inode, long long ino)
280 285
281 inode->i_nlink = le32_to_cpu(sqsh_ino->nlink); 286 inode->i_nlink = le32_to_cpu(sqsh_ino->nlink);
282 inode->i_size = le32_to_cpu(sqsh_ino->symlink_size); 287 inode->i_size = le32_to_cpu(sqsh_ino->symlink_size);
283 inode->i_op = &page_symlink_inode_operations; 288 inode->i_op = &squashfs_symlink_inode_ops;
284 inode->i_data.a_ops = &squashfs_symlink_aops; 289 inode->i_data.a_ops = &squashfs_symlink_aops;
285 inode->i_mode |= S_IFLNK; 290 inode->i_mode |= S_IFLNK;
286 squashfs_i(inode)->start = block; 291 squashfs_i(inode)->start = block;
287 squashfs_i(inode)->offset = offset; 292 squashfs_i(inode)->offset = offset;
288 293
294 if (type == SQUASHFS_LSYMLINK_TYPE) {
295 __le32 xattr;
296
297 err = squashfs_read_metadata(sb, NULL, &block,
298 &offset, inode->i_size);
299 if (err < 0)
300 goto failed_read;
301 err = squashfs_read_metadata(sb, &xattr, &block,
302 &offset, sizeof(xattr));
303 if (err < 0)
304 goto failed_read;
305 xattr_id = le32_to_cpu(xattr);
306 }
307
289 TRACE("Symbolic link inode %x:%x, start_block %llx, offset " 308 TRACE("Symbolic link inode %x:%x, start_block %llx, offset "
290 "%x\n", SQUASHFS_INODE_BLK(ino), offset, 309 "%x\n", SQUASHFS_INODE_BLK(ino), offset,
291 block, offset); 310 block, offset);
292 break; 311 break;
293 } 312 }
294 case SQUASHFS_BLKDEV_TYPE: 313 case SQUASHFS_BLKDEV_TYPE:
295 case SQUASHFS_CHRDEV_TYPE: 314 case SQUASHFS_CHRDEV_TYPE: {
296 case SQUASHFS_LBLKDEV_TYPE:
297 case SQUASHFS_LCHRDEV_TYPE: {
298 struct squashfs_dev_inode *sqsh_ino = &squashfs_ino.dev; 315 struct squashfs_dev_inode *sqsh_ino = &squashfs_ino.dev;
299 unsigned int rdev; 316 unsigned int rdev;
300 317
@@ -315,10 +332,32 @@ int squashfs_read_inode(struct inode *inode, long long ino)
315 SQUASHFS_INODE_BLK(ino), offset, rdev); 332 SQUASHFS_INODE_BLK(ino), offset, rdev);
316 break; 333 break;
317 } 334 }
335 case SQUASHFS_LBLKDEV_TYPE:
336 case SQUASHFS_LCHRDEV_TYPE: {
337 struct squashfs_ldev_inode *sqsh_ino = &squashfs_ino.ldev;
338 unsigned int rdev;
339
340 err = squashfs_read_metadata(sb, sqsh_ino, &block, &offset,
341 sizeof(*sqsh_ino));
342 if (err < 0)
343 goto failed_read;
344
345 if (type == SQUASHFS_LCHRDEV_TYPE)
346 inode->i_mode |= S_IFCHR;
347 else
348 inode->i_mode |= S_IFBLK;
349 xattr_id = le32_to_cpu(sqsh_ino->xattr);
350 inode->i_op = &squashfs_inode_ops;
351 inode->i_nlink = le32_to_cpu(sqsh_ino->nlink);
352 rdev = le32_to_cpu(sqsh_ino->rdev);
353 init_special_inode(inode, inode->i_mode, new_decode_dev(rdev));
354
355 TRACE("Device inode %x:%x, rdev %x\n",
356 SQUASHFS_INODE_BLK(ino), offset, rdev);
357 break;
358 }
318 case SQUASHFS_FIFO_TYPE: 359 case SQUASHFS_FIFO_TYPE:
319 case SQUASHFS_SOCKET_TYPE: 360 case SQUASHFS_SOCKET_TYPE: {
320 case SQUASHFS_LFIFO_TYPE:
321 case SQUASHFS_LSOCKET_TYPE: {
322 struct squashfs_ipc_inode *sqsh_ino = &squashfs_ino.ipc; 361 struct squashfs_ipc_inode *sqsh_ino = &squashfs_ino.ipc;
323 362
324 err = squashfs_read_metadata(sb, sqsh_ino, &block, &offset, 363 err = squashfs_read_metadata(sb, sqsh_ino, &block, &offset,
@@ -334,14 +373,52 @@ int squashfs_read_inode(struct inode *inode, long long ino)
334 init_special_inode(inode, inode->i_mode, 0); 373 init_special_inode(inode, inode->i_mode, 0);
335 break; 374 break;
336 } 375 }
376 case SQUASHFS_LFIFO_TYPE:
377 case SQUASHFS_LSOCKET_TYPE: {
378 struct squashfs_lipc_inode *sqsh_ino = &squashfs_ino.lipc;
379
380 err = squashfs_read_metadata(sb, sqsh_ino, &block, &offset,
381 sizeof(*sqsh_ino));
382 if (err < 0)
383 goto failed_read;
384
385 if (type == SQUASHFS_LFIFO_TYPE)
386 inode->i_mode |= S_IFIFO;
387 else
388 inode->i_mode |= S_IFSOCK;
389 xattr_id = le32_to_cpu(sqsh_ino->xattr);
390 inode->i_op = &squashfs_inode_ops;
391 inode->i_nlink = le32_to_cpu(sqsh_ino->nlink);
392 init_special_inode(inode, inode->i_mode, 0);
393 break;
394 }
337 default: 395 default:
338 ERROR("Unknown inode type %d in squashfs_iget!\n", type); 396 ERROR("Unknown inode type %d in squashfs_iget!\n", type);
339 return -EINVAL; 397 return -EINVAL;
340 } 398 }
341 399
400 if (xattr_id != SQUASHFS_INVALID_XATTR && msblk->xattr_id_table) {
401 err = squashfs_xattr_lookup(sb, xattr_id,
402 &squashfs_i(inode)->xattr_count,
403 &squashfs_i(inode)->xattr_size,
404 &squashfs_i(inode)->xattr);
405 if (err < 0)
406 goto failed_read;
407 inode->i_blocks += ((squashfs_i(inode)->xattr_size - 1) >> 9)
408 + 1;
409 } else
410 squashfs_i(inode)->xattr_count = 0;
411
342 return 0; 412 return 0;
343 413
344failed_read: 414failed_read:
345 ERROR("Unable to read inode 0x%llx\n", ino); 415 ERROR("Unable to read inode 0x%llx\n", ino);
346 return err; 416 return err;
347} 417}
418
419
420const struct inode_operations squashfs_inode_ops = {
421 .getxattr = generic_getxattr,
422 .listxattr = squashfs_listxattr
423};
424
diff --git a/fs/squashfs/namei.c b/fs/squashfs/namei.c
index 5266bd8ad932..32f5b54d1cec 100644
--- a/fs/squashfs/namei.c
+++ b/fs/squashfs/namei.c
@@ -57,6 +57,7 @@
57#include <linux/slab.h> 57#include <linux/slab.h>
58#include <linux/string.h> 58#include <linux/string.h>
59#include <linux/dcache.h> 59#include <linux/dcache.h>
60#include <linux/xattr.h>
60 61
61#include "squashfs_fs.h" 62#include "squashfs_fs.h"
62#include "squashfs_fs_sb.h" 63#include "squashfs_fs_sb.h"
@@ -237,5 +238,7 @@ failed:
237 238
238 239
239const struct inode_operations squashfs_dir_inode_ops = { 240const struct inode_operations squashfs_dir_inode_ops = {
240 .lookup = squashfs_lookup 241 .lookup = squashfs_lookup,
242 .getxattr = generic_getxattr,
243 .listxattr = squashfs_listxattr
241}; 244};
diff --git a/fs/squashfs/squashfs.h b/fs/squashfs/squashfs.h
index 133befe2f8b8..7d2381070581 100644
--- a/fs/squashfs/squashfs.h
+++ b/fs/squashfs/squashfs.h
@@ -73,6 +73,9 @@ extern struct inode *squashfs_iget(struct super_block *, long long,
73 unsigned int); 73 unsigned int);
74extern int squashfs_read_inode(struct inode *, long long); 74extern int squashfs_read_inode(struct inode *, long long);
75 75
76/* xattr.c */
77extern ssize_t squashfs_listxattr(struct dentry *, char *, size_t);
78
76/* xattr_id.c */ 79/* xattr_id.c */
77extern int squashfs_xattr_lookup(struct super_block *, unsigned int, int *, 80extern int squashfs_xattr_lookup(struct super_block *, unsigned int, int *,
78 int *, long long *); 81 int *, long long *);
@@ -80,7 +83,7 @@ extern __le64 *squashfs_read_xattr_id_table(struct super_block *, u64,
80 u64 *, int *); 83 u64 *, int *);
81 84
82/* 85/*
83 * Inodes, files and decompressor operations 86 * Inodes, files, decompressor and xattr operations
84 */ 87 */
85 88
86/* dir.c */ 89/* dir.c */
@@ -92,11 +95,18 @@ extern const struct export_operations squashfs_export_ops;
92/* file.c */ 95/* file.c */
93extern const struct address_space_operations squashfs_aops; 96extern const struct address_space_operations squashfs_aops;
94 97
98/* inode.c */
99extern const struct inode_operations squashfs_inode_ops;
100
95/* namei.c */ 101/* namei.c */
96extern const struct inode_operations squashfs_dir_inode_ops; 102extern const struct inode_operations squashfs_dir_inode_ops;
97 103
98/* symlink.c */ 104/* symlink.c */
99extern const struct address_space_operations squashfs_symlink_aops; 105extern const struct address_space_operations squashfs_symlink_aops;
106extern const struct inode_operations squashfs_symlink_inode_ops;
107
108/* xattr.c */
109extern struct xattr_handler *squashfs_xattr_handlers[];
100 110
101/* zlib_wrapper.c */ 111/* zlib_wrapper.c */
102extern const struct squashfs_decompressor squashfs_zlib_comp_ops; 112extern const struct squashfs_decompressor squashfs_zlib_comp_ops;
diff --git a/fs/squashfs/squashfs_fs.h b/fs/squashfs/squashfs_fs.h
index 6fe940cf9011..8eabb808b78d 100644
--- a/fs/squashfs/squashfs_fs.h
+++ b/fs/squashfs/squashfs_fs.h
@@ -287,6 +287,17 @@ struct squashfs_ipc_inode {
287 __le32 nlink; 287 __le32 nlink;
288}; 288};
289 289
290struct squashfs_lipc_inode {
291 __le16 inode_type;
292 __le16 mode;
293 __le16 uid;
294 __le16 guid;
295 __le32 mtime;
296 __le32 inode_number;
297 __le32 nlink;
298 __le32 xattr;
299};
300
290struct squashfs_dev_inode { 301struct squashfs_dev_inode {
291 __le16 inode_type; 302 __le16 inode_type;
292 __le16 mode; 303 __le16 mode;
@@ -298,6 +309,18 @@ struct squashfs_dev_inode {
298 __le32 rdev; 309 __le32 rdev;
299}; 310};
300 311
312struct squashfs_ldev_inode {
313 __le16 inode_type;
314 __le16 mode;
315 __le16 uid;
316 __le16 guid;
317 __le32 mtime;
318 __le32 inode_number;
319 __le32 nlink;
320 __le32 rdev;
321 __le32 xattr;
322};
323
301struct squashfs_symlink_inode { 324struct squashfs_symlink_inode {
302 __le16 inode_type; 325 __le16 inode_type;
303 __le16 mode; 326 __le16 mode;
@@ -375,12 +398,14 @@ struct squashfs_ldir_inode {
375union squashfs_inode { 398union squashfs_inode {
376 struct squashfs_base_inode base; 399 struct squashfs_base_inode base;
377 struct squashfs_dev_inode dev; 400 struct squashfs_dev_inode dev;
401 struct squashfs_ldev_inode ldev;
378 struct squashfs_symlink_inode symlink; 402 struct squashfs_symlink_inode symlink;
379 struct squashfs_reg_inode reg; 403 struct squashfs_reg_inode reg;
380 struct squashfs_lreg_inode lreg; 404 struct squashfs_lreg_inode lreg;
381 struct squashfs_dir_inode dir; 405 struct squashfs_dir_inode dir;
382 struct squashfs_ldir_inode ldir; 406 struct squashfs_ldir_inode ldir;
383 struct squashfs_ipc_inode ipc; 407 struct squashfs_ipc_inode ipc;
408 struct squashfs_lipc_inode lipc;
384}; 409};
385 410
386struct squashfs_dir_entry { 411struct squashfs_dir_entry {
diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index c4dfc393fa52..b6425ac1c2ae 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -140,13 +140,6 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
140 if (msblk->decompressor == NULL) 140 if (msblk->decompressor == NULL)
141 goto failed_mount; 141 goto failed_mount;
142 142
143 /*
144 * Check if there's xattrs in the filesystem. These are not
145 * supported in this version, so warn that they will be ignored.
146 */
147 if (le64_to_cpu(sblk->xattr_id_table_start) != SQUASHFS_INVALID_BLK)
148 ERROR("Xattrs in filesystem, these will be ignored\n");
149
150 /* Check the filesystem does not extend beyond the end of the 143 /* Check the filesystem does not extend beyond the end of the
151 block device */ 144 block device */
152 msblk->bytes_used = le64_to_cpu(sblk->bytes_used); 145 msblk->bytes_used = le64_to_cpu(sblk->bytes_used);
@@ -268,6 +261,7 @@ allocate_lookup_table:
268 sb->s_export_op = &squashfs_export_ops; 261 sb->s_export_op = &squashfs_export_ops;
269 262
270allocate_xattr_table: 263allocate_xattr_table:
264 sb->s_xattr = squashfs_xattr_handlers;
271 xattr_id_table_start = le64_to_cpu(sblk->xattr_id_table_start); 265 xattr_id_table_start = le64_to_cpu(sblk->xattr_id_table_start);
272 if (xattr_id_table_start == SQUASHFS_INVALID_BLK) 266 if (xattr_id_table_start == SQUASHFS_INVALID_BLK)
273 goto allocate_root; 267 goto allocate_root;
diff --git a/fs/squashfs/symlink.c b/fs/squashfs/symlink.c
index 32b911f4ee39..a7ee68a8621b 100644
--- a/fs/squashfs/symlink.c
+++ b/fs/squashfs/symlink.c
@@ -35,6 +35,7 @@
35#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/string.h> 36#include <linux/string.h>
37#include <linux/pagemap.h> 37#include <linux/pagemap.h>
38#include <linux/xattr.h>
38 39
39#include "squashfs_fs.h" 40#include "squashfs_fs.h"
40#include "squashfs_fs_sb.h" 41#include "squashfs_fs_sb.h"
@@ -114,3 +115,12 @@ error_out:
114const struct address_space_operations squashfs_symlink_aops = { 115const struct address_space_operations squashfs_symlink_aops = {
115 .readpage = squashfs_symlink_readpage 116 .readpage = squashfs_symlink_readpage
116}; 117};
118
119const struct inode_operations squashfs_symlink_inode_ops = {
120 .readlink = generic_readlink,
121 .follow_link = page_follow_link_light,
122 .put_link = page_put_link,
123 .getxattr = generic_getxattr,
124 .listxattr = squashfs_listxattr
125};
126