diff options
Diffstat (limited to 'fs/cramfs')
-rw-r--r-- | fs/cramfs/inode.c | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c index 7fe85415ae7c..8ad52f5bf255 100644 --- a/fs/cramfs/inode.c +++ b/fs/cramfs/inode.c | |||
@@ -36,7 +36,7 @@ static DECLARE_MUTEX(read_mutex); | |||
36 | 36 | ||
37 | /* These two macros may change in future, to provide better st_ino | 37 | /* These two macros may change in future, to provide better st_ino |
38 | semantics. */ | 38 | semantics. */ |
39 | #define CRAMINO(x) ((x)->offset?(x)->offset<<2:1) | 39 | #define CRAMINO(x) (((x)->offset && (x)->size)?(x)->offset<<2:1) |
40 | #define OFFSET(x) ((x)->i_ino) | 40 | #define OFFSET(x) ((x)->i_ino) |
41 | 41 | ||
42 | 42 | ||
@@ -66,8 +66,36 @@ static int cramfs_iget5_test(struct inode *inode, void *opaque) | |||
66 | 66 | ||
67 | static int cramfs_iget5_set(struct inode *inode, void *opaque) | 67 | static int cramfs_iget5_set(struct inode *inode, void *opaque) |
68 | { | 68 | { |
69 | static struct timespec zerotime; | ||
69 | struct cramfs_inode *cramfs_inode = opaque; | 70 | struct cramfs_inode *cramfs_inode = opaque; |
71 | inode->i_mode = cramfs_inode->mode; | ||
72 | inode->i_uid = cramfs_inode->uid; | ||
73 | inode->i_size = cramfs_inode->size; | ||
74 | inode->i_blocks = (cramfs_inode->size - 1) / 512 + 1; | ||
75 | inode->i_blksize = PAGE_CACHE_SIZE; | ||
76 | inode->i_gid = cramfs_inode->gid; | ||
77 | /* Struct copy intentional */ | ||
78 | inode->i_mtime = inode->i_atime = inode->i_ctime = zerotime; | ||
70 | inode->i_ino = CRAMINO(cramfs_inode); | 79 | inode->i_ino = CRAMINO(cramfs_inode); |
80 | /* inode->i_nlink is left 1 - arguably wrong for directories, | ||
81 | but it's the best we can do without reading the directory | ||
82 | contents. 1 yields the right result in GNU find, even | ||
83 | without -noleaf option. */ | ||
84 | if (S_ISREG(inode->i_mode)) { | ||
85 | inode->i_fop = &generic_ro_fops; | ||
86 | inode->i_data.a_ops = &cramfs_aops; | ||
87 | } else if (S_ISDIR(inode->i_mode)) { | ||
88 | inode->i_op = &cramfs_dir_inode_operations; | ||
89 | inode->i_fop = &cramfs_directory_operations; | ||
90 | } else if (S_ISLNK(inode->i_mode)) { | ||
91 | inode->i_op = &page_symlink_inode_operations; | ||
92 | inode->i_data.a_ops = &cramfs_aops; | ||
93 | } else { | ||
94 | inode->i_size = 0; | ||
95 | inode->i_blocks = 0; | ||
96 | init_special_inode(inode, inode->i_mode, | ||
97 | old_decode_dev(cramfs_inode->size)); | ||
98 | } | ||
71 | return 0; | 99 | return 0; |
72 | } | 100 | } |
73 | 101 | ||
@@ -77,37 +105,7 @@ static struct inode *get_cramfs_inode(struct super_block *sb, | |||
77 | struct inode *inode = iget5_locked(sb, CRAMINO(cramfs_inode), | 105 | struct inode *inode = iget5_locked(sb, CRAMINO(cramfs_inode), |
78 | cramfs_iget5_test, cramfs_iget5_set, | 106 | cramfs_iget5_test, cramfs_iget5_set, |
79 | cramfs_inode); | 107 | cramfs_inode); |
80 | static struct timespec zerotime; | ||
81 | |||
82 | if (inode && (inode->i_state & I_NEW)) { | 108 | if (inode && (inode->i_state & I_NEW)) { |
83 | inode->i_mode = cramfs_inode->mode; | ||
84 | inode->i_uid = cramfs_inode->uid; | ||
85 | inode->i_size = cramfs_inode->size; | ||
86 | inode->i_blocks = (cramfs_inode->size - 1) / 512 + 1; | ||
87 | inode->i_blksize = PAGE_CACHE_SIZE; | ||
88 | inode->i_gid = cramfs_inode->gid; | ||
89 | /* Struct copy intentional */ | ||
90 | inode->i_mtime = inode->i_atime = inode->i_ctime = zerotime; | ||
91 | inode->i_ino = CRAMINO(cramfs_inode); | ||
92 | /* inode->i_nlink is left 1 - arguably wrong for directories, | ||
93 | but it's the best we can do without reading the directory | ||
94 | contents. 1 yields the right result in GNU find, even | ||
95 | without -noleaf option. */ | ||
96 | if (S_ISREG(inode->i_mode)) { | ||
97 | inode->i_fop = &generic_ro_fops; | ||
98 | inode->i_data.a_ops = &cramfs_aops; | ||
99 | } else if (S_ISDIR(inode->i_mode)) { | ||
100 | inode->i_op = &cramfs_dir_inode_operations; | ||
101 | inode->i_fop = &cramfs_directory_operations; | ||
102 | } else if (S_ISLNK(inode->i_mode)) { | ||
103 | inode->i_op = &page_symlink_inode_operations; | ||
104 | inode->i_data.a_ops = &cramfs_aops; | ||
105 | } else { | ||
106 | inode->i_size = 0; | ||
107 | inode->i_blocks = 0; | ||
108 | init_special_inode(inode, inode->i_mode, | ||
109 | old_decode_dev(cramfs_inode->size)); | ||
110 | } | ||
111 | unlock_new_inode(inode); | 109 | unlock_new_inode(inode); |
112 | } | 110 | } |
113 | return inode; | 111 | return inode; |