1 |
1275 |
phoenix |
/*
|
2 |
|
|
* linux/fs/hfsplus/super.c
|
3 |
|
|
*
|
4 |
|
|
* Copyright (C) 2001
|
5 |
|
|
* Brad Boyer (flar@allandria.com)
|
6 |
|
|
* (C) 2003 Ardis Technologies <roman@ardistech.com>
|
7 |
|
|
*
|
8 |
|
|
*/
|
9 |
|
|
|
10 |
|
|
#include <linux/config.h>
|
11 |
|
|
#include <linux/module.h>
|
12 |
|
|
#include <linux/init.h>
|
13 |
|
|
#include <linux/fs.h>
|
14 |
|
|
#include <linux/sched.h>
|
15 |
|
|
#include <linux/slab.h>
|
16 |
|
|
#include <linux/version.h>
|
17 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
|
18 |
|
|
#include <linux/locks.h>
|
19 |
|
|
#else
|
20 |
|
|
#include <linux/buffer_head.h>
|
21 |
|
|
#include <linux/vfs.h>
|
22 |
|
|
|
23 |
|
|
static struct inode *hfsplus_alloc_inode(struct super_block *sb);
|
24 |
|
|
static void hfsplus_destroy_inode(struct inode *inode);
|
25 |
|
|
#endif
|
26 |
|
|
|
27 |
|
|
#include "hfsplus_fs.h"
|
28 |
|
|
|
29 |
|
|
void hfsplus_inode_check(struct super_block *sb)
|
30 |
|
|
{
|
31 |
|
|
#if 0
|
32 |
|
|
u32 cnt = atomic_read(&HFSPLUS_SB(sb).inode_cnt);
|
33 |
|
|
u32 last_cnt = HFSPLUS_SB(sb).last_inode_cnt;
|
34 |
|
|
|
35 |
|
|
if (cnt <= (last_cnt / 2) ||
|
36 |
|
|
cnt >= (last_cnt * 2)) {
|
37 |
|
|
HFSPLUS_SB(sb).last_inode_cnt = cnt;
|
38 |
|
|
printk("inode_check: %u,%u,%u\n", cnt, last_cnt,
|
39 |
|
|
HFSPLUS_SB(sb).cat_tree ? HFSPLUS_SB(sb).cat_tree->node_hash_cnt : 0);
|
40 |
|
|
}
|
41 |
|
|
#endif
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
static void hfsplus_read_inode(struct inode *inode)
|
45 |
|
|
{
|
46 |
|
|
struct hfsplus_find_data fd;
|
47 |
|
|
struct hfsplus_vh *vhdr;
|
48 |
|
|
int err;
|
49 |
|
|
|
50 |
|
|
atomic_inc(&HFSPLUS_SB(inode->i_sb).inode_cnt);
|
51 |
|
|
hfsplus_inode_check(inode->i_sb);
|
52 |
|
|
if (inode->i_ino >= HFSPLUS_FIRSTUSER_CNID) {
|
53 |
|
|
read_inode:
|
54 |
|
|
HFSPLUS_I(inode).flags = 0;
|
55 |
|
|
hfsplus_find_init(HFSPLUS_SB(inode->i_sb).cat_tree, &fd);
|
56 |
|
|
err = hfsplus_find_cat(inode->i_sb, inode->i_ino, &fd);
|
57 |
|
|
if (!err)
|
58 |
|
|
err = hfsplus_cat_read_inode(inode, &fd);
|
59 |
|
|
hfsplus_find_exit(&fd);
|
60 |
|
|
if (err)
|
61 |
|
|
goto bad_inode;
|
62 |
|
|
return;
|
63 |
|
|
}
|
64 |
|
|
vhdr = HFSPLUS_SB(inode->i_sb).s_vhdr;
|
65 |
|
|
switch(inode->i_ino) {
|
66 |
|
|
case HFSPLUS_ROOT_CNID:
|
67 |
|
|
goto read_inode;
|
68 |
|
|
case HFSPLUS_EXT_CNID:
|
69 |
|
|
hfsplus_inode_read_fork(inode, &vhdr->ext_file);
|
70 |
|
|
inode->i_mapping->a_ops = &hfsplus_btree_aops;
|
71 |
|
|
break;
|
72 |
|
|
case HFSPLUS_CAT_CNID:
|
73 |
|
|
hfsplus_inode_read_fork(inode, &vhdr->cat_file);
|
74 |
|
|
inode->i_mapping->a_ops = &hfsplus_btree_aops;
|
75 |
|
|
break;
|
76 |
|
|
case HFSPLUS_ALLOC_CNID:
|
77 |
|
|
hfsplus_inode_read_fork(inode, &vhdr->alloc_file);
|
78 |
|
|
break;
|
79 |
|
|
case HFSPLUS_START_CNID:
|
80 |
|
|
hfsplus_inode_read_fork(inode, &vhdr->start_file);
|
81 |
|
|
break;
|
82 |
|
|
case HFSPLUS_ATTR_CNID:
|
83 |
|
|
hfsplus_inode_read_fork(inode, &vhdr->attr_file);
|
84 |
|
|
inode->i_mapping->a_ops = &hfsplus_btree_aops;
|
85 |
|
|
break;
|
86 |
|
|
default:
|
87 |
|
|
goto bad_inode;
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
return;
|
91 |
|
|
|
92 |
|
|
bad_inode:
|
93 |
|
|
make_bad_inode(inode);
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
void hfsplus_write_inode(struct inode *inode, int unused)
|
97 |
|
|
{
|
98 |
|
|
struct hfsplus_vh *vhdr;
|
99 |
|
|
|
100 |
|
|
dprint(DBG_INODE, "hfsplus_write_inode: %lu\n", inode->i_ino);
|
101 |
|
|
if (inode->i_ino >= HFSPLUS_FIRSTUSER_CNID) {
|
102 |
|
|
hfsplus_cat_write_inode(inode);
|
103 |
|
|
return;
|
104 |
|
|
}
|
105 |
|
|
vhdr = HFSPLUS_SB(inode->i_sb).s_vhdr;
|
106 |
|
|
switch (inode->i_ino) {
|
107 |
|
|
case HFSPLUS_ROOT_CNID:
|
108 |
|
|
hfsplus_cat_write_inode(inode);
|
109 |
|
|
break;
|
110 |
|
|
case HFSPLUS_EXT_CNID:
|
111 |
|
|
if (vhdr->ext_file.total_size != cpu_to_be64(inode->i_size)) {
|
112 |
|
|
HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
|
113 |
|
|
inode->i_sb->s_dirt = 1;
|
114 |
|
|
}
|
115 |
|
|
hfsplus_inode_write_fork(inode, &vhdr->ext_file);
|
116 |
|
|
hfsplus_write_btree(HFSPLUS_SB(inode->i_sb).ext_tree);
|
117 |
|
|
break;
|
118 |
|
|
case HFSPLUS_CAT_CNID:
|
119 |
|
|
if (vhdr->cat_file.total_size != cpu_to_be64(inode->i_size)) {
|
120 |
|
|
HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
|
121 |
|
|
inode->i_sb->s_dirt = 1;
|
122 |
|
|
}
|
123 |
|
|
hfsplus_inode_write_fork(inode, &vhdr->cat_file);
|
124 |
|
|
hfsplus_write_btree(HFSPLUS_SB(inode->i_sb).cat_tree);
|
125 |
|
|
break;
|
126 |
|
|
case HFSPLUS_ALLOC_CNID:
|
127 |
|
|
if (vhdr->alloc_file.total_size != cpu_to_be64(inode->i_size)) {
|
128 |
|
|
HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
|
129 |
|
|
inode->i_sb->s_dirt = 1;
|
130 |
|
|
}
|
131 |
|
|
hfsplus_inode_write_fork(inode, &vhdr->alloc_file);
|
132 |
|
|
break;
|
133 |
|
|
case HFSPLUS_START_CNID:
|
134 |
|
|
if (vhdr->start_file.total_size != cpu_to_be64(inode->i_size)) {
|
135 |
|
|
HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
|
136 |
|
|
inode->i_sb->s_dirt = 1;
|
137 |
|
|
}
|
138 |
|
|
hfsplus_inode_write_fork(inode, &vhdr->start_file);
|
139 |
|
|
break;
|
140 |
|
|
case HFSPLUS_ATTR_CNID:
|
141 |
|
|
if (vhdr->attr_file.total_size != cpu_to_be64(inode->i_size)) {
|
142 |
|
|
HFSPLUS_SB(inode->i_sb).flags |= HFSPLUS_SB_WRITEBACKUP;
|
143 |
|
|
inode->i_sb->s_dirt = 1;
|
144 |
|
|
}
|
145 |
|
|
hfsplus_inode_write_fork(inode, &vhdr->attr_file);
|
146 |
|
|
hfsplus_write_btree(HFSPLUS_SB(inode->i_sb).attr_tree);
|
147 |
|
|
break;
|
148 |
|
|
}
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
static void hfsplus_clear_inode(struct inode *inode)
|
152 |
|
|
{
|
153 |
|
|
atomic_dec(&HFSPLUS_SB(inode->i_sb).inode_cnt);
|
154 |
|
|
if (HFSPLUS_IS_RSRC(inode)) {
|
155 |
|
|
HFSPLUS_I(HFSPLUS_I(inode).rsrc_inode).rsrc_inode = NULL;
|
156 |
|
|
iput(HFSPLUS_I(inode).rsrc_inode);
|
157 |
|
|
}
|
158 |
|
|
hfsplus_inode_check(inode->i_sb);
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
static void hfsplus_write_super(struct super_block *sb)
|
162 |
|
|
{
|
163 |
|
|
struct hfsplus_vh *vhdr = HFSPLUS_SB(sb).s_vhdr;
|
164 |
|
|
|
165 |
|
|
dprint(DBG_SUPER, "hfsplus_write_super\n");
|
166 |
|
|
sb->s_dirt = 0;
|
167 |
|
|
if (sb->s_flags & MS_RDONLY)
|
168 |
|
|
/* warn? */
|
169 |
|
|
return;
|
170 |
|
|
|
171 |
|
|
vhdr->free_blocks = cpu_to_be32(HFSPLUS_SB(sb).free_blocks);
|
172 |
|
|
vhdr->next_alloc = cpu_to_be32(HFSPLUS_SB(sb).next_alloc);
|
173 |
|
|
vhdr->next_cnid = cpu_to_be32(HFSPLUS_SB(sb).next_cnid);
|
174 |
|
|
vhdr->folder_count = cpu_to_be32(HFSPLUS_SB(sb).folder_count);
|
175 |
|
|
vhdr->file_count = cpu_to_be32(HFSPLUS_SB(sb).file_count);
|
176 |
|
|
|
177 |
|
|
mark_buffer_dirty(HFSPLUS_SB(sb).s_vhbh);
|
178 |
|
|
if (HFSPLUS_SB(sb).flags & HFSPLUS_SB_WRITEBACKUP) {
|
179 |
|
|
if (HFSPLUS_SB(sb).sect_count) {
|
180 |
|
|
struct buffer_head *bh;
|
181 |
|
|
u32 block, offset;
|
182 |
|
|
|
183 |
|
|
block = HFSPLUS_SB(sb).blockoffset;
|
184 |
|
|
block += (HFSPLUS_SB(sb).sect_count - 2) >> (sb->s_blocksize_bits - 9);
|
185 |
|
|
offset = ((HFSPLUS_SB(sb).sect_count - 2) << 9) & (sb->s_blocksize - 1);
|
186 |
|
|
//printk("backup: %u,%u,%u,%u\n", HFSPLUS_SB(sb).blockoffset,
|
187 |
|
|
// HFSPLUS_SB(sb).sect_count, block, offset);
|
188 |
|
|
bh = sb_bread(sb, block);
|
189 |
|
|
vhdr = (struct hfsplus_vh *)(bh->b_data + offset);
|
190 |
|
|
if (be16_to_cpu(vhdr->signature) == HFSPLUS_VOLHEAD_SIG) {
|
191 |
|
|
memcpy(vhdr, HFSPLUS_SB(sb).s_vhdr, sizeof(*vhdr));
|
192 |
|
|
mark_buffer_dirty(bh);
|
193 |
|
|
brelse(bh);
|
194 |
|
|
} else
|
195 |
|
|
printk("backup not found!\n");
|
196 |
|
|
}
|
197 |
|
|
HFSPLUS_SB(sb).flags &= ~HFSPLUS_SB_WRITEBACKUP;
|
198 |
|
|
}
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
static void hfsplus_put_super(struct super_block *sb)
|
202 |
|
|
{
|
203 |
|
|
dprint(DBG_SUPER, "hfsplus_put_super\n");
|
204 |
|
|
if (!(sb->s_flags & MS_RDONLY)) {
|
205 |
|
|
struct hfsplus_vh *vhdr = HFSPLUS_SB(sb).s_vhdr;
|
206 |
|
|
|
207 |
|
|
vhdr->modify_date = hfsp_now2mt();
|
208 |
|
|
vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_UNMNT);
|
209 |
|
|
vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_INCNSTNT);
|
210 |
|
|
mark_buffer_dirty(HFSPLUS_SB(sb).s_vhbh);
|
211 |
|
|
ll_rw_block(WRITE, 1, &HFSPLUS_SB(sb).s_vhbh);
|
212 |
|
|
wait_on_buffer(HFSPLUS_SB(sb).s_vhbh);
|
213 |
|
|
}
|
214 |
|
|
|
215 |
|
|
hfsplus_close_btree(HFSPLUS_SB(sb).cat_tree);
|
216 |
|
|
hfsplus_close_btree(HFSPLUS_SB(sb).ext_tree);
|
217 |
|
|
iput(HFSPLUS_SB(sb).alloc_file);
|
218 |
|
|
iput(HFSPLUS_SB(sb).hidden_dir);
|
219 |
|
|
brelse(HFSPLUS_SB(sb).s_vhbh);
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
static int hfsplus_statfs(struct super_block *sb, struct statfs *buf)
|
223 |
|
|
{
|
224 |
|
|
buf->f_type = HFSPLUS_SUPER_MAGIC;
|
225 |
|
|
buf->f_bsize = sb->s_blocksize;
|
226 |
|
|
buf->f_blocks = be32_to_cpu(HFSPLUS_SB(sb).s_vhdr->total_blocks);
|
227 |
|
|
buf->f_bfree = HFSPLUS_SB(sb).free_blocks;
|
228 |
|
|
buf->f_bavail = buf->f_bfree;
|
229 |
|
|
buf->f_files = 0xFFFFFFFF;
|
230 |
|
|
buf->f_ffree = 0xFFFFFFFF - HFSPLUS_SB(sb).next_cnid;
|
231 |
|
|
buf->f_namelen = HFSPLUS_MAX_STRLEN;
|
232 |
|
|
|
233 |
|
|
return 0;
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
int hfsplus_remount(struct super_block *sb, int *flags, char *data)
|
237 |
|
|
{
|
238 |
|
|
if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
|
239 |
|
|
return 0;
|
240 |
|
|
if (!(*flags & MS_RDONLY)) {
|
241 |
|
|
struct hfsplus_vh *vhdr = HFSPLUS_SB(sb).s_vhdr;
|
242 |
|
|
|
243 |
|
|
if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_INCNSTNT)) ||
|
244 |
|
|
!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
|
245 |
|
|
printk("HFS+-fs warning: Filesystem was not cleanly unmounted, "
|
246 |
|
|
"running fsck.hfsplus is recommended. leaving read-only.\n");
|
247 |
|
|
sb->s_flags |= MS_RDONLY;
|
248 |
|
|
*flags |= MS_RDONLY;
|
249 |
|
|
} else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
|
250 |
|
|
printk("HFS+-fs: Filesystem is marked locked, leaving read-only.\n");
|
251 |
|
|
sb->s_flags |= MS_RDONLY;
|
252 |
|
|
*flags |= MS_RDONLY;
|
253 |
|
|
}
|
254 |
|
|
}
|
255 |
|
|
return 0;
|
256 |
|
|
}
|
257 |
|
|
|
258 |
|
|
static struct super_operations hfsplus_sops = {
|
259 |
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
|
260 |
|
|
.alloc_inode = hfsplus_alloc_inode,
|
261 |
|
|
.destroy_inode = hfsplus_destroy_inode,
|
262 |
|
|
#endif
|
263 |
|
|
.read_inode = hfsplus_read_inode,
|
264 |
|
|
.write_inode = hfsplus_write_inode,
|
265 |
|
|
.clear_inode = hfsplus_clear_inode,
|
266 |
|
|
.put_super = hfsplus_put_super,
|
267 |
|
|
.write_super = hfsplus_write_super,
|
268 |
|
|
.statfs = hfsplus_statfs,
|
269 |
|
|
.remount_fs = hfsplus_remount,
|
270 |
|
|
};
|
271 |
|
|
|
272 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
|
273 |
|
|
struct super_block *hfsplus_read_super(struct super_block *sb, void *data,
|
274 |
|
|
int silent)
|
275 |
|
|
#else
|
276 |
|
|
static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
|
277 |
|
|
#endif
|
278 |
|
|
{
|
279 |
|
|
struct hfsplus_vh *vhdr;
|
280 |
|
|
struct hfsplus_sb_info *sbi;
|
281 |
|
|
hfsplus_cat_entry entry;
|
282 |
|
|
struct hfsplus_find_data fd;
|
283 |
|
|
struct qstr str;
|
284 |
|
|
int err = -EINVAL;
|
285 |
|
|
|
286 |
|
|
sbi = kmalloc(sizeof(struct hfsplus_sb_info), GFP_KERNEL);
|
287 |
|
|
if (!sbi) {
|
288 |
|
|
err = -ENOMEM;
|
289 |
|
|
goto out2;
|
290 |
|
|
}
|
291 |
|
|
memset(sbi, 0, sizeof(HFSPLUS_SB(sb)));
|
292 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
|
293 |
|
|
if (sizeof(struct inode) - offsetof(struct inode, u) < sizeof(struct hfsplus_inode_info)) {
|
294 |
|
|
extern void hfsplus_inode_info_exceeded_space_in_inode_error(void);
|
295 |
|
|
hfsplus_inode_info_exceeded_space_in_inode_error();
|
296 |
|
|
}
|
297 |
|
|
|
298 |
|
|
if (sizeof(struct super_block) - offsetof(struct super_block, u) < sizeof(struct hfsplus_sb_info)) {
|
299 |
|
|
extern void hfsplus_sb_info_exceeded_space_in_super_block_error(void);
|
300 |
|
|
hfsplus_sb_info_exceeded_space_in_super_block_error();
|
301 |
|
|
}
|
302 |
|
|
|
303 |
|
|
INIT_LIST_HEAD(&HFSPLUS_SB(sb).rsrc_inodes);
|
304 |
|
|
#else
|
305 |
|
|
sb->s_fs_info = sbi;
|
306 |
|
|
INIT_HLIST_HEAD(&sbi->rsrc_inodes);
|
307 |
|
|
#endif
|
308 |
|
|
fill_defaults(sbi);
|
309 |
|
|
if (!parse_options(data, sbi)) {
|
310 |
|
|
if (!silent)
|
311 |
|
|
printk("HFS+-fs: unable to parse mount options\n");
|
312 |
|
|
err = -EINVAL;
|
313 |
|
|
goto out2;
|
314 |
|
|
}
|
315 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
|
316 |
|
|
fill_current(sbi, &HFSPLUS_SB(sb));
|
317 |
|
|
kfree(sbi);
|
318 |
|
|
#endif
|
319 |
|
|
|
320 |
|
|
/* Grab the volume header */
|
321 |
|
|
if (hfsplus_read_wrapper(sb)) {
|
322 |
|
|
if (!silent)
|
323 |
|
|
printk("HFS+-fs: unable to find HFS+ superblock\n");
|
324 |
|
|
err = -EINVAL;
|
325 |
|
|
goto out2;
|
326 |
|
|
}
|
327 |
|
|
vhdr = HFSPLUS_SB(sb).s_vhdr;
|
328 |
|
|
|
329 |
|
|
/* Copy parts of the volume header into the superblock */
|
330 |
|
|
sb->s_magic = be16_to_cpu(vhdr->signature);
|
331 |
|
|
if (be16_to_cpu(vhdr->version) != HFSPLUS_CURRENT_VERSION) {
|
332 |
|
|
if (!silent)
|
333 |
|
|
printk("HFS+-fs: wrong filesystem version\n");
|
334 |
|
|
goto cleanup;
|
335 |
|
|
}
|
336 |
|
|
HFSPLUS_SB(sb).total_blocks = be32_to_cpu(vhdr->total_blocks);
|
337 |
|
|
HFSPLUS_SB(sb).free_blocks = be32_to_cpu(vhdr->free_blocks);
|
338 |
|
|
HFSPLUS_SB(sb).next_alloc = be32_to_cpu(vhdr->next_alloc);
|
339 |
|
|
HFSPLUS_SB(sb).next_cnid = be32_to_cpu(vhdr->next_cnid);
|
340 |
|
|
HFSPLUS_SB(sb).file_count = be32_to_cpu(vhdr->file_count);
|
341 |
|
|
HFSPLUS_SB(sb).folder_count = be32_to_cpu(vhdr->folder_count);
|
342 |
|
|
|
343 |
|
|
/* Set up operations so we can load metadata */
|
344 |
|
|
sb->s_op = &hfsplus_sops;
|
345 |
|
|
|
346 |
|
|
if ((vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_INCNSTNT)) ||
|
347 |
|
|
!(vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_UNMNT))) {
|
348 |
|
|
if (!silent)
|
349 |
|
|
printk("HFS+-fs warning: Filesystem was not cleanly unmounted, "
|
350 |
|
|
"running fsck.hfsplus is recommended. mounting read-only.\n");
|
351 |
|
|
sb->s_flags |= MS_RDONLY;
|
352 |
|
|
} else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
|
353 |
|
|
if (!silent)
|
354 |
|
|
printk("HFS+-fs: Filesystem is marked locked, mounting read-only.\n");
|
355 |
|
|
sb->s_flags |= MS_RDONLY;
|
356 |
|
|
}
|
357 |
|
|
|
358 |
|
|
/* Load metadata objects (B*Trees) */
|
359 |
|
|
HFSPLUS_SB(sb).ext_tree = hfsplus_open_btree(sb, HFSPLUS_EXT_CNID);
|
360 |
|
|
if (!HFSPLUS_SB(sb).ext_tree) {
|
361 |
|
|
if (!silent)
|
362 |
|
|
printk("HFS+-fs: failed to load extents file\n");
|
363 |
|
|
goto cleanup;
|
364 |
|
|
}
|
365 |
|
|
HFSPLUS_SB(sb).cat_tree = hfsplus_open_btree(sb, HFSPLUS_CAT_CNID);
|
366 |
|
|
if (!HFSPLUS_SB(sb).cat_tree) {
|
367 |
|
|
if (!silent)
|
368 |
|
|
printk("HFS+-fs: failed to load catalog file\n");
|
369 |
|
|
goto cleanup;
|
370 |
|
|
}
|
371 |
|
|
|
372 |
|
|
HFSPLUS_SB(sb).alloc_file = iget(sb, HFSPLUS_ALLOC_CNID);
|
373 |
|
|
if (!HFSPLUS_SB(sb).alloc_file) {
|
374 |
|
|
if (!silent)
|
375 |
|
|
printk("HFS+-fs: failed to load allocation file\n");
|
376 |
|
|
goto cleanup;
|
377 |
|
|
}
|
378 |
|
|
|
379 |
|
|
/* Load the root directory */
|
380 |
|
|
sb->s_root = d_alloc_root(iget(sb, HFSPLUS_ROOT_CNID));
|
381 |
|
|
if (!sb->s_root) {
|
382 |
|
|
if (!silent)
|
383 |
|
|
printk("HFS+-fs: failed to load root directory\n");
|
384 |
|
|
goto cleanup;
|
385 |
|
|
}
|
386 |
|
|
|
387 |
|
|
str.len = sizeof(HFSP_HIDDENDIR_NAME) - 1;
|
388 |
|
|
str.name = HFSP_HIDDENDIR_NAME;
|
389 |
|
|
hfsplus_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
|
390 |
|
|
hfsplus_fill_cat_key(fd.search_key, HFSPLUS_ROOT_CNID, &str);
|
391 |
|
|
if (!hfsplus_btree_find_entry(&fd, &entry, sizeof(entry))) {
|
392 |
|
|
hfsplus_find_exit(&fd);
|
393 |
|
|
if (entry.type != cpu_to_be16(HFSPLUS_FOLDER))
|
394 |
|
|
goto cleanup;
|
395 |
|
|
HFSPLUS_SB(sb).hidden_dir = iget(sb, be32_to_cpu(entry.folder.id));
|
396 |
|
|
if (!HFSPLUS_SB(sb).hidden_dir)
|
397 |
|
|
goto cleanup;
|
398 |
|
|
} else
|
399 |
|
|
hfsplus_find_exit(&fd);
|
400 |
|
|
|
401 |
|
|
if (sb->s_flags & MS_RDONLY)
|
402 |
|
|
goto out;
|
403 |
|
|
|
404 |
|
|
/* H+LX == hfsplusutils, H+Lx == this driver, H+lx is unused
|
405 |
|
|
* all three are registered with Apple for our use
|
406 |
|
|
*/
|
407 |
|
|
vhdr->last_mount_vers = cpu_to_be32(HFSP_MOUNT_VERSION);
|
408 |
|
|
vhdr->modify_date = hfsp_now2mt();
|
409 |
|
|
vhdr->write_count = cpu_to_be32(be32_to_cpu(vhdr->write_count) + 1);
|
410 |
|
|
vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_UNMNT);
|
411 |
|
|
vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT);
|
412 |
|
|
mark_buffer_dirty(HFSPLUS_SB(sb).s_vhbh);
|
413 |
|
|
ll_rw_block(WRITE, 1, &HFSPLUS_SB(sb).s_vhbh);
|
414 |
|
|
wait_on_buffer(HFSPLUS_SB(sb).s_vhbh);
|
415 |
|
|
|
416 |
|
|
if (!HFSPLUS_SB(sb).hidden_dir) {
|
417 |
|
|
printk("HFS+: create hidden dir...\n");
|
418 |
|
|
HFSPLUS_SB(sb).hidden_dir = hfsplus_new_inode(sb, S_IFDIR);
|
419 |
|
|
hfsplus_create_cat(HFSPLUS_SB(sb).hidden_dir->i_ino, sb->s_root->d_inode,
|
420 |
|
|
&str, HFSPLUS_SB(sb).hidden_dir);
|
421 |
|
|
mark_inode_dirty(HFSPLUS_SB(sb).hidden_dir);
|
422 |
|
|
}
|
423 |
|
|
out:
|
424 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
|
425 |
|
|
return sb;
|
426 |
|
|
#else
|
427 |
|
|
return 0;
|
428 |
|
|
#endif
|
429 |
|
|
|
430 |
|
|
cleanup:
|
431 |
|
|
hfsplus_put_super(sb);
|
432 |
|
|
out2:
|
433 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
|
434 |
|
|
return NULL;
|
435 |
|
|
#else
|
436 |
|
|
return err;
|
437 |
|
|
#endif
|
438 |
|
|
}
|
439 |
|
|
|
440 |
|
|
MODULE_AUTHOR("Brad Boyer");
|
441 |
|
|
MODULE_DESCRIPTION("Extended Macintosh Filesystem");
|
442 |
|
|
MODULE_LICENSE("GPL");
|
443 |
|
|
|
444 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
|
445 |
|
|
|
446 |
|
|
static DECLARE_FSTYPE_DEV(hfsplus_fs_type, "hfsplus", hfsplus_read_super);
|
447 |
|
|
|
448 |
|
|
static int __init init_hfsplus_fs(void)
|
449 |
|
|
{
|
450 |
|
|
return register_filesystem(&hfsplus_fs_type);
|
451 |
|
|
}
|
452 |
|
|
|
453 |
|
|
static void __exit exit_hfsplus_fs(void)
|
454 |
|
|
{
|
455 |
|
|
unregister_filesystem(&hfsplus_fs_type);
|
456 |
|
|
}
|
457 |
|
|
|
458 |
|
|
EXPORT_NO_SYMBOLS;
|
459 |
|
|
|
460 |
|
|
#else
|
461 |
|
|
|
462 |
|
|
static kmem_cache_t * hfsplus_inode_cachep;
|
463 |
|
|
|
464 |
|
|
static void init_once(void *p, kmem_cache_t *cachep, unsigned long flags)
|
465 |
|
|
{
|
466 |
|
|
struct hfsplus_inode_info *i = (struct hfsplus_inode_info *)p;
|
467 |
|
|
|
468 |
|
|
if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR) {
|
469 |
|
|
inode_init_once(&i->vfs_inode);
|
470 |
|
|
}
|
471 |
|
|
}
|
472 |
|
|
|
473 |
|
|
static struct inode *hfsplus_alloc_inode(struct super_block *sb)
|
474 |
|
|
{
|
475 |
|
|
struct hfsplus_inode_info *i;
|
476 |
|
|
i = (struct hfsplus_inode_info *)kmem_cache_alloc(hfsplus_inode_cachep, SLAB_KERNEL);
|
477 |
|
|
return i ? &i->vfs_inode : NULL;
|
478 |
|
|
}
|
479 |
|
|
|
480 |
|
|
static void hfsplus_destroy_inode(struct inode *inode)
|
481 |
|
|
{
|
482 |
|
|
kmem_cache_free(hfsplus_inode_cachep, &HFSPLUS_I(inode));
|
483 |
|
|
}
|
484 |
|
|
|
485 |
|
|
static struct super_block *hfsplus_get_sb(struct file_system_type *fs_type,
|
486 |
|
|
int flags, char *dev_name, void *data)
|
487 |
|
|
{
|
488 |
|
|
return get_sb_bdev(fs_type, flags, dev_name, data, hfsplus_fill_super);
|
489 |
|
|
}
|
490 |
|
|
|
491 |
|
|
static struct file_system_type hfsplus_fs_type = {
|
492 |
|
|
.owner = THIS_MODULE,
|
493 |
|
|
.name = "hfsplus",
|
494 |
|
|
.get_sb = hfsplus_get_sb,
|
495 |
|
|
.kill_sb = kill_block_super,
|
496 |
|
|
.fs_flags = FS_REQUIRES_DEV,
|
497 |
|
|
};
|
498 |
|
|
|
499 |
|
|
static int __init init_hfsplus_fs(void)
|
500 |
|
|
{
|
501 |
|
|
int err;
|
502 |
|
|
|
503 |
|
|
hfsplus_inode_cachep = kmem_cache_create("hfsplus_inode_cache",
|
504 |
|
|
sizeof(struct hfsplus_inode_info), 0, SLAB_HWCACHE_ALIGN,
|
505 |
|
|
init_once, NULL);
|
506 |
|
|
if (!hfsplus_inode_cachep)
|
507 |
|
|
return -ENOMEM;
|
508 |
|
|
err = register_filesystem(&hfsplus_fs_type);
|
509 |
|
|
if (err)
|
510 |
|
|
kmem_cache_destroy(hfsplus_inode_cachep);
|
511 |
|
|
return err;
|
512 |
|
|
}
|
513 |
|
|
|
514 |
|
|
static void __exit exit_hfsplus_fs(void)
|
515 |
|
|
{
|
516 |
|
|
unregister_filesystem(&hfsplus_fs_type);
|
517 |
|
|
if (kmem_cache_destroy(hfsplus_inode_cachep))
|
518 |
|
|
printk(KERN_INFO "hfsplus_inode_cache: not all structures were freed\n");
|
519 |
|
|
}
|
520 |
|
|
#endif
|
521 |
|
|
|
522 |
|
|
module_init(init_hfsplus_fs)
|
523 |
|
|
module_exit(exit_hfsplus_fs)
|