5 * Super block routines for the OSTA-UDF(tm) filesystem.
8 * OSTA-UDF(tm) = Optical Storage Technology Association
9 * Universal Disk Format.
11 * This code is based on version 2.00 of the UDF specification,
12 * and revision 3 of the ECMA 167 standard [equivalent to ISO 13346].
13 * http://www.osta.org/
18 * This file is distributed under the terms of the GNU General Public
19 * License (GPL). Copies of the GPL can be obtained from:
20 * ftp://prep.ai.mit.edu/pub/gnu/GPL
21 * Each contributing author retains all rights to their own work.
23 * (C) 1998 Dave Boynton
24 * (C) 1998-2004 Ben Fennema
25 * (C) 2000 Stelias Computing Inc
29 * 09/24/98 dgb changed to allow compiling outside of kernel, and
30 * added some debugging.
31 * 10/01/98 dgb updated to allow (some) possibility of compiling w/2.0.34
32 * 10/16/98 attempting some multi-session support
33 * 10/17/98 added freespace count for "df"
34 * 11/11/98 gr added novrs option
35 * 11/26/98 dgb added fileset,anchor mount options
36 * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced
37 * vol descs. rewrote option handling based on isofs
38 * 12/20/98 find the free space bitmap (if it exists)
43 #include <linux/blkdev.h>
44 #include <linux/slab.h>
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/parser.h>
48 #include <linux/stat.h>
49 #include <linux/cdrom.h>
50 #include <linux/nls.h>
51 #include <linux/smp_lock.h>
52 #include <linux/buffer_head.h>
53 #include <linux/vfs.h>
54 #include <linux/vmalloc.h>
55 #include <linux/errno.h>
56 #include <linux/mount.h>
57 #include <linux/seq_file.h>
58 #include <asm/byteorder.h>
63 #include <linux/init.h>
64 #include <asm/uaccess.h>
66 #define VDS_POS_PRIMARY_VOL_DESC 0
67 #define VDS_POS_UNALLOC_SPACE_DESC 1
68 #define VDS_POS_LOGICAL_VOL_DESC 2
69 #define VDS_POS_PARTITION_DESC 3
70 #define VDS_POS_IMP_USE_VOL_DESC 4
71 #define VDS_POS_VOL_DESC_PTR 5
72 #define VDS_POS_TERMINATING_DESC 6
73 #define VDS_POS_LENGTH 7
75 #define UDF_DEFAULT_BLOCKSIZE 2048
77 static char error_buf
[1024];
79 /* These are the "meat" - everything else is stuffing */
80 static int udf_fill_super(struct super_block
*, void *, int);
81 static void udf_put_super(struct super_block
*);
82 static void udf_write_super(struct super_block
*);
83 static int udf_remount_fs(struct super_block
*, int *, char *);
84 static int udf_check_valid(struct super_block
*, int, int);
85 static int udf_vrs(struct super_block
*sb
, int silent
);
86 static int udf_load_partition(struct super_block
*, kernel_lb_addr
*);
87 static int udf_load_logicalvol(struct super_block
*, struct buffer_head
*,
89 static void udf_load_logicalvolint(struct super_block
*, kernel_extent_ad
);
90 static void udf_find_anchor(struct super_block
*);
91 static int udf_find_fileset(struct super_block
*, kernel_lb_addr
*,
93 static void udf_load_pvoldesc(struct super_block
*, struct buffer_head
*);
94 static void udf_load_fileset(struct super_block
*, struct buffer_head
*,
96 static int udf_load_partdesc(struct super_block
*, struct buffer_head
*);
97 static void udf_open_lvid(struct super_block
*);
98 static void udf_close_lvid(struct super_block
*);
99 static unsigned int udf_count_free(struct super_block
*);
100 static int udf_statfs(struct dentry
*, struct kstatfs
*);
101 static int udf_show_options(struct seq_file
*, struct vfsmount
*);
103 struct logicalVolIntegrityDescImpUse
*udf_sb_lvidiu(struct udf_sb_info
*sbi
)
105 struct logicalVolIntegrityDesc
*lvid
=
106 (struct logicalVolIntegrityDesc
*)sbi
->s_lvid_bh
->b_data
;
107 __u32 number_of_partitions
= le32_to_cpu(lvid
->numOfPartitions
);
108 __u32 offset
= number_of_partitions
* 2 *
109 sizeof(uint32_t)/sizeof(uint8_t);
110 return (struct logicalVolIntegrityDescImpUse
*)&(lvid
->impUse
[offset
]);
113 /* UDF filesystem type */
114 static int udf_get_sb(struct file_system_type
*fs_type
,
115 int flags
, const char *dev_name
, void *data
,
116 struct vfsmount
*mnt
)
118 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, udf_fill_super
, mnt
);
121 static struct file_system_type udf_fstype
= {
122 .owner
= THIS_MODULE
,
124 .get_sb
= udf_get_sb
,
125 .kill_sb
= kill_block_super
,
126 .fs_flags
= FS_REQUIRES_DEV
,
129 static struct kmem_cache
*udf_inode_cachep
;
131 static struct inode
*udf_alloc_inode(struct super_block
*sb
)
133 struct udf_inode_info
*ei
;
134 ei
= kmem_cache_alloc(udf_inode_cachep
, GFP_KERNEL
);
139 ei
->i_lenExtents
= 0;
140 ei
->i_next_alloc_block
= 0;
141 ei
->i_next_alloc_goal
= 0;
144 return &ei
->vfs_inode
;
147 static void udf_destroy_inode(struct inode
*inode
)
149 kmem_cache_free(udf_inode_cachep
, UDF_I(inode
));
152 static void init_once(struct kmem_cache
*cachep
, void *foo
)
154 struct udf_inode_info
*ei
= (struct udf_inode_info
*)foo
;
156 ei
->i_ext
.i_data
= NULL
;
157 inode_init_once(&ei
->vfs_inode
);
160 static int init_inodecache(void)
162 udf_inode_cachep
= kmem_cache_create("udf_inode_cache",
163 sizeof(struct udf_inode_info
),
164 0, (SLAB_RECLAIM_ACCOUNT
|
167 if (!udf_inode_cachep
)
172 static void destroy_inodecache(void)
174 kmem_cache_destroy(udf_inode_cachep
);
177 /* Superblock operations */
178 static const struct super_operations udf_sb_ops
= {
179 .alloc_inode
= udf_alloc_inode
,
180 .destroy_inode
= udf_destroy_inode
,
181 .write_inode
= udf_write_inode
,
182 .delete_inode
= udf_delete_inode
,
183 .clear_inode
= udf_clear_inode
,
184 .put_super
= udf_put_super
,
185 .write_super
= udf_write_super
,
186 .statfs
= udf_statfs
,
187 .remount_fs
= udf_remount_fs
,
188 .show_options
= udf_show_options
,
193 unsigned int blocksize
;
194 unsigned int session
;
195 unsigned int lastblock
;
198 unsigned short partition
;
199 unsigned int fileset
;
200 unsigned int rootdir
;
205 struct nls_table
*nls_map
;
208 static int __init
init_udf_fs(void)
212 err
= init_inodecache();
215 err
= register_filesystem(&udf_fstype
);
222 destroy_inodecache();
228 static void __exit
exit_udf_fs(void)
230 unregister_filesystem(&udf_fstype
);
231 destroy_inodecache();
234 module_init(init_udf_fs
)
235 module_exit(exit_udf_fs
)
237 static int udf_sb_alloc_partition_maps(struct super_block
*sb
, u32 count
)
239 struct udf_sb_info
*sbi
= UDF_SB(sb
);
241 sbi
->s_partmaps
= kcalloc(count
, sizeof(struct udf_part_map
),
243 if (!sbi
->s_partmaps
) {
244 udf_error(sb
, __FUNCTION__
,
245 "Unable to allocate space for %d partition maps",
247 sbi
->s_partitions
= 0;
251 sbi
->s_partitions
= count
;
255 static int udf_show_options(struct seq_file
*seq
, struct vfsmount
*mnt
)
257 struct super_block
*sb
= mnt
->mnt_sb
;
258 struct udf_sb_info
*sbi
= UDF_SB(sb
);
260 if (!UDF_QUERY_FLAG(sb
, UDF_FLAG_STRICT
))
261 seq_puts(seq
, ",nostrict");
262 if (sb
->s_blocksize
!= UDF_DEFAULT_BLOCKSIZE
)
263 seq_printf(seq
, ",bs=%lu", sb
->s_blocksize
);
264 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UNHIDE
))
265 seq_puts(seq
, ",unhide");
266 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UNDELETE
))
267 seq_puts(seq
, ",undelete");
268 if (!UDF_QUERY_FLAG(sb
, UDF_FLAG_USE_AD_IN_ICB
))
269 seq_puts(seq
, ",noadinicb");
270 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_USE_SHORT_AD
))
271 seq_puts(seq
, ",shortad");
272 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_FORGET
))
273 seq_puts(seq
, ",uid=forget");
274 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_IGNORE
))
275 seq_puts(seq
, ",uid=ignore");
276 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_FORGET
))
277 seq_puts(seq
, ",gid=forget");
278 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_IGNORE
))
279 seq_puts(seq
, ",gid=ignore");
280 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_SET
))
281 seq_printf(seq
, ",uid=%u", sbi
->s_uid
);
282 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_SET
))
283 seq_printf(seq
, ",gid=%u", sbi
->s_gid
);
284 if (sbi
->s_umask
!= 0)
285 seq_printf(seq
, ",umask=%o", sbi
->s_umask
);
286 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_SESSION_SET
))
287 seq_printf(seq
, ",session=%u", sbi
->s_session
);
288 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_LASTBLOCK_SET
))
289 seq_printf(seq
, ",lastblock=%u", sbi
->s_last_block
);
291 * s_anchor[2] could be zeroed out in case there is no anchor
292 * in the specified block, but then the "anchor=N" option
293 * originally given by the user wasn't effective, so it's OK
294 * if we don't show it.
296 if (sbi
->s_anchor
[2] != 0)
297 seq_printf(seq
, ",anchor=%u", sbi
->s_anchor
[2]);
299 * volume, partition, fileset and rootdir seem to be ignored
302 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UTF8
))
303 seq_puts(seq
, ",utf8");
304 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
) && sbi
->s_nls_map
)
305 seq_printf(seq
, ",iocharset=%s", sbi
->s_nls_map
->charset
);
314 * Parse mount options.
317 * The following mount options are supported:
319 * gid= Set the default group.
320 * umask= Set the default umask.
321 * uid= Set the default user.
322 * bs= Set the block size.
323 * unhide Show otherwise hidden files.
324 * undelete Show deleted files in lists.
325 * adinicb Embed data in the inode (default)
326 * noadinicb Don't embed data in the inode
327 * shortad Use short ad's
328 * longad Use long ad's (default)
329 * nostrict Unset strict conformance
330 * iocharset= Set the NLS character set
332 * The remaining are for debugging and disaster recovery:
334 * novrs Skip volume sequence recognition
336 * The following expect a offset from 0.
338 * session= Set the CDROM session (default= last session)
339 * anchor= Override standard anchor location. (default= 256)
340 * volume= Override the VolumeDesc location. (unused)
341 * partition= Override the PartitionDesc location. (unused)
342 * lastblock= Set the last block of the filesystem/
344 * The following expect a offset from the partition root.
346 * fileset= Override the fileset block location. (unused)
347 * rootdir= Override the root directory location. (unused)
348 * WARNING: overriding the rootdir to a non-directory may
349 * yield highly unpredictable results.
352 * options Pointer to mount options string.
353 * uopts Pointer to mount options variable.
356 * <return> 1 Mount options parsed okay.
357 * <return> 0 Error parsing mount options.
360 * July 1, 1997 - Andrew E. Mileski
361 * Written, tested, and released.
365 Opt_novrs
, Opt_nostrict
, Opt_bs
, Opt_unhide
, Opt_undelete
,
366 Opt_noadinicb
, Opt_adinicb
, Opt_shortad
, Opt_longad
,
367 Opt_gid
, Opt_uid
, Opt_umask
, Opt_session
, Opt_lastblock
,
368 Opt_anchor
, Opt_volume
, Opt_partition
, Opt_fileset
,
369 Opt_rootdir
, Opt_utf8
, Opt_iocharset
,
370 Opt_err
, Opt_uforget
, Opt_uignore
, Opt_gforget
, Opt_gignore
373 static match_table_t tokens
= {
374 {Opt_novrs
, "novrs"},
375 {Opt_nostrict
, "nostrict"},
377 {Opt_unhide
, "unhide"},
378 {Opt_undelete
, "undelete"},
379 {Opt_noadinicb
, "noadinicb"},
380 {Opt_adinicb
, "adinicb"},
381 {Opt_shortad
, "shortad"},
382 {Opt_longad
, "longad"},
383 {Opt_uforget
, "uid=forget"},
384 {Opt_uignore
, "uid=ignore"},
385 {Opt_gforget
, "gid=forget"},
386 {Opt_gignore
, "gid=ignore"},
389 {Opt_umask
, "umask=%o"},
390 {Opt_session
, "session=%u"},
391 {Opt_lastblock
, "lastblock=%u"},
392 {Opt_anchor
, "anchor=%u"},
393 {Opt_volume
, "volume=%u"},
394 {Opt_partition
, "partition=%u"},
395 {Opt_fileset
, "fileset=%u"},
396 {Opt_rootdir
, "rootdir=%u"},
398 {Opt_iocharset
, "iocharset=%s"},
402 static int udf_parse_options(char *options
, struct udf_options
*uopt
,
409 uopt
->blocksize
= UDF_DEFAULT_BLOCKSIZE
;
410 uopt
->partition
= 0xFFFF;
411 uopt
->session
= 0xFFFFFFFF;
414 uopt
->volume
= 0xFFFFFFFF;
415 uopt
->rootdir
= 0xFFFFFFFF;
416 uopt
->fileset
= 0xFFFFFFFF;
417 uopt
->nls_map
= NULL
;
422 while ((p
= strsep(&options
, ",")) != NULL
) {
423 substring_t args
[MAX_OPT_ARGS
];
428 token
= match_token(p
, tokens
, args
);
433 if (match_int(&args
[0], &option
))
435 uopt
->blocksize
= option
;
438 uopt
->flags
|= (1 << UDF_FLAG_UNHIDE
);
441 uopt
->flags
|= (1 << UDF_FLAG_UNDELETE
);
444 uopt
->flags
&= ~(1 << UDF_FLAG_USE_AD_IN_ICB
);
447 uopt
->flags
|= (1 << UDF_FLAG_USE_AD_IN_ICB
);
450 uopt
->flags
|= (1 << UDF_FLAG_USE_SHORT_AD
);
453 uopt
->flags
&= ~(1 << UDF_FLAG_USE_SHORT_AD
);
456 if (match_int(args
, &option
))
459 uopt
->flags
|= (1 << UDF_FLAG_GID_SET
);
462 if (match_int(args
, &option
))
465 uopt
->flags
|= (1 << UDF_FLAG_UID_SET
);
468 if (match_octal(args
, &option
))
470 uopt
->umask
= option
;
473 uopt
->flags
&= ~(1 << UDF_FLAG_STRICT
);
476 if (match_int(args
, &option
))
478 uopt
->session
= option
;
480 uopt
->flags
|= (1 << UDF_FLAG_SESSION_SET
);
483 if (match_int(args
, &option
))
485 uopt
->lastblock
= option
;
487 uopt
->flags
|= (1 << UDF_FLAG_LASTBLOCK_SET
);
490 if (match_int(args
, &option
))
492 uopt
->anchor
= option
;
495 if (match_int(args
, &option
))
497 uopt
->volume
= option
;
500 if (match_int(args
, &option
))
502 uopt
->partition
= option
;
505 if (match_int(args
, &option
))
507 uopt
->fileset
= option
;
510 if (match_int(args
, &option
))
512 uopt
->rootdir
= option
;
515 uopt
->flags
|= (1 << UDF_FLAG_UTF8
);
517 #ifdef CONFIG_UDF_NLS
519 uopt
->nls_map
= load_nls(args
[0].from
);
520 uopt
->flags
|= (1 << UDF_FLAG_NLS_MAP
);
524 uopt
->flags
|= (1 << UDF_FLAG_UID_IGNORE
);
527 uopt
->flags
|= (1 << UDF_FLAG_UID_FORGET
);
530 uopt
->flags
|= (1 << UDF_FLAG_GID_IGNORE
);
533 uopt
->flags
|= (1 << UDF_FLAG_GID_FORGET
);
536 printk(KERN_ERR
"udf: bad mount option \"%s\" "
537 "or missing value\n", p
);
544 static void udf_write_super(struct super_block
*sb
)
548 if (!(sb
->s_flags
& MS_RDONLY
))
555 static int udf_remount_fs(struct super_block
*sb
, int *flags
, char *options
)
557 struct udf_options uopt
;
558 struct udf_sb_info
*sbi
= UDF_SB(sb
);
560 uopt
.flags
= sbi
->s_flags
;
561 uopt
.uid
= sbi
->s_uid
;
562 uopt
.gid
= sbi
->s_gid
;
563 uopt
.umask
= sbi
->s_umask
;
565 if (!udf_parse_options(options
, &uopt
, true))
568 sbi
->s_flags
= uopt
.flags
;
569 sbi
->s_uid
= uopt
.uid
;
570 sbi
->s_gid
= uopt
.gid
;
571 sbi
->s_umask
= uopt
.umask
;
573 if (sbi
->s_lvid_bh
) {
574 int write_rev
= le16_to_cpu(udf_sb_lvidiu(sbi
)->minUDFWriteRev
);
575 if (write_rev
> UDF_MAX_WRITE_VERSION
)
579 if ((*flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
))
581 if (*flags
& MS_RDONLY
)
589 static int udf_vrs(struct super_block
*sb
, int silent
)
591 struct volStructDesc
*vsd
= NULL
;
594 struct buffer_head
*bh
= NULL
;
598 struct udf_sb_info
*sbi
;
600 /* Block size must be a multiple of 512 */
601 if (sb
->s_blocksize
& 511)
605 if (sb
->s_blocksize
< sizeof(struct volStructDesc
))
606 sectorsize
= sizeof(struct volStructDesc
);
608 sectorsize
= sb
->s_blocksize
;
610 sector
+= (sbi
->s_session
<< sb
->s_blocksize_bits
);
612 udf_debug("Starting at sector %u (%ld byte sectors)\n",
613 (sector
>> sb
->s_blocksize_bits
), sb
->s_blocksize
);
614 /* Process the sequence (if applicable) */
615 for (; !nsr02
&& !nsr03
; sector
+= sectorsize
) {
617 bh
= udf_tread(sb
, sector
>> sb
->s_blocksize_bits
);
621 /* Look for ISO descriptors */
622 vsd
= (struct volStructDesc
*)(bh
->b_data
+
623 (sector
& (sb
->s_blocksize
- 1)));
625 if (vsd
->stdIdent
[0] == 0) {
628 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_CD001
,
631 switch (vsd
->structType
) {
633 udf_debug("ISO9660 Boot Record found\n");
636 udf_debug("ISO9660 Primary Volume Descriptor "
640 udf_debug("ISO9660 Supplementary Volume "
641 "Descriptor found\n");
644 udf_debug("ISO9660 Volume Partition Descriptor "
648 udf_debug("ISO9660 Volume Descriptor Set "
649 "Terminator found\n");
652 udf_debug("ISO9660 VRS (%u) found\n",
656 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_BEA01
,
659 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_TEA01
,
663 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR02
,
666 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR03
,
676 else if (sector
- (sbi
->s_session
<< sb
->s_blocksize_bits
) == 32768)
686 * Find an anchor volume descriptor.
689 * sb Pointer to _locked_ superblock.
690 * lastblock Last block on media.
693 * <return> 1 if not found, 0 if ok
696 * July 1, 1997 - Andrew E. Mileski
697 * Written, tested, and released.
699 static void udf_find_anchor(struct super_block
*sb
)
702 struct buffer_head
*bh
= NULL
;
706 struct udf_sb_info
*sbi
;
709 lastblock
= sbi
->s_last_block
;
712 int varlastblock
= udf_variable_to_fixed(lastblock
);
713 int last
[] = { lastblock
, lastblock
- 2,
714 lastblock
- 150, lastblock
- 152,
715 varlastblock
, varlastblock
- 2,
716 varlastblock
- 150, varlastblock
- 152 };
720 /* Search for an anchor volume descriptor pointer */
722 /* according to spec, anchor is in either:
726 * however, if the disc isn't closed, it could be 512 */
728 for (i
= 0; !lastblock
&& i
< ARRAY_SIZE(last
); i
++) {
729 ident
= location
= 0;
731 bh
= sb_bread(sb
, last
[i
]);
733 tag
*t
= (tag
*)bh
->b_data
;
734 ident
= le16_to_cpu(t
->tagIdent
);
735 location
= le32_to_cpu(t
->tagLocation
);
740 if (ident
== TAG_IDENT_AVDP
) {
741 if (location
== last
[i
] - sbi
->s_session
) {
742 lastblock
= last
[i
] - sbi
->s_session
;
743 sbi
->s_anchor
[0] = lastblock
;
744 sbi
->s_anchor
[1] = lastblock
- 256;
745 } else if (location
==
746 udf_variable_to_fixed(last
[i
]) -
748 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
750 udf_variable_to_fixed(last
[i
]) -
752 sbi
->s_anchor
[0] = lastblock
;
753 sbi
->s_anchor
[1] = lastblock
- 256 -
756 udf_debug("Anchor found at block %d, "
757 "location mismatch %d.\n",
760 } else if (ident
== TAG_IDENT_FE
||
761 ident
== TAG_IDENT_EFE
) {
763 sbi
->s_anchor
[3] = 512;
765 ident
= location
= 0;
766 if (last
[i
] >= 256) {
767 bh
= sb_bread(sb
, last
[i
] - 256);
769 tag
*t
= (tag
*)bh
->b_data
;
772 location
= le32_to_cpu(
778 if (ident
== TAG_IDENT_AVDP
&&
779 location
== last
[i
] - 256 -
782 sbi
->s_anchor
[1] = last
[i
] - 256;
784 ident
= location
= 0;
785 if (last
[i
] >= 312 + sbi
->s_session
) {
794 location
= le32_to_cpu(
800 if (ident
== TAG_IDENT_AVDP
&&
801 location
== udf_variable_to_fixed(last
[i
]) - 256) {
804 lastblock
= udf_variable_to_fixed(last
[i
]);
805 sbi
->s_anchor
[1] = lastblock
- 256;
813 /* We haven't found the lastblock. check 312 */
814 bh
= sb_bread(sb
, 312 + sbi
->s_session
);
816 tag
*t
= (tag
*)bh
->b_data
;
817 ident
= le16_to_cpu(t
->tagIdent
);
818 location
= le32_to_cpu(t
->tagLocation
);
821 if (ident
== TAG_IDENT_AVDP
&& location
== 256)
822 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
826 for (i
= 0; i
< ARRAY_SIZE(sbi
->s_anchor
); i
++) {
827 if (sbi
->s_anchor
[i
]) {
828 bh
= udf_read_tagged(sb
, sbi
->s_anchor
[i
],
829 sbi
->s_anchor
[i
], &ident
);
831 sbi
->s_anchor
[i
] = 0;
834 if ((ident
!= TAG_IDENT_AVDP
) &&
835 (i
|| (ident
!= TAG_IDENT_FE
&&
836 ident
!= TAG_IDENT_EFE
)))
837 sbi
->s_anchor
[i
] = 0;
842 sbi
->s_last_block
= lastblock
;
845 static int udf_find_fileset(struct super_block
*sb
,
846 kernel_lb_addr
*fileset
,
847 kernel_lb_addr
*root
)
849 struct buffer_head
*bh
= NULL
;
852 struct udf_sb_info
*sbi
;
854 if (fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
855 fileset
->partitionReferenceNum
!= 0xFFFF) {
856 bh
= udf_read_ptagged(sb
, *fileset
, 0, &ident
);
860 } else if (ident
!= TAG_IDENT_FSD
) {
869 /* Search backwards through the partitions */
870 kernel_lb_addr newfileset
;
872 /* --> cvg: FIXME - is it reasonable? */
875 for (newfileset
.partitionReferenceNum
= sbi
->s_partitions
- 1;
876 (newfileset
.partitionReferenceNum
!= 0xFFFF &&
877 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
878 fileset
->partitionReferenceNum
== 0xFFFF);
879 newfileset
.partitionReferenceNum
--) {
880 lastblock
= sbi
->s_partmaps
881 [newfileset
.partitionReferenceNum
]
883 newfileset
.logicalBlockNum
= 0;
886 bh
= udf_read_ptagged(sb
, newfileset
, 0,
889 newfileset
.logicalBlockNum
++;
896 struct spaceBitmapDesc
*sp
;
897 sp
= (struct spaceBitmapDesc
*)
899 newfileset
.logicalBlockNum
+= 1 +
900 ((le32_to_cpu(sp
->numOfBytes
) +
901 sizeof(struct spaceBitmapDesc
)
902 - 1) >> sb
->s_blocksize_bits
);
907 *fileset
= newfileset
;
910 newfileset
.logicalBlockNum
++;
915 } while (newfileset
.logicalBlockNum
< lastblock
&&
916 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
917 fileset
->partitionReferenceNum
== 0xFFFF);
921 if ((fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
922 fileset
->partitionReferenceNum
!= 0xFFFF) && bh
) {
923 udf_debug("Fileset at block=%d, partition=%d\n",
924 fileset
->logicalBlockNum
,
925 fileset
->partitionReferenceNum
);
927 sbi
->s_partition
= fileset
->partitionReferenceNum
;
928 udf_load_fileset(sb
, bh
, root
);
935 static void udf_load_pvoldesc(struct super_block
*sb
, struct buffer_head
*bh
)
937 struct primaryVolDesc
*pvoldesc
;
943 pvoldesc
= (struct primaryVolDesc
*)bh
->b_data
;
945 if (udf_stamp_to_time(&recording
, &recording_usec
,
946 lets_to_cpu(pvoldesc
->recordingDateAndTime
))) {
948 ts
= lets_to_cpu(pvoldesc
->recordingDateAndTime
);
949 udf_debug("recording time %ld/%ld, %04u/%02u/%02u"
951 recording
, recording_usec
,
952 ts
.year
, ts
.month
, ts
.day
, ts
.hour
,
953 ts
.minute
, ts
.typeAndTimezone
);
954 UDF_SB(sb
)->s_record_time
.tv_sec
= recording
;
955 UDF_SB(sb
)->s_record_time
.tv_nsec
= recording_usec
* 1000;
958 if (!udf_build_ustr(&instr
, pvoldesc
->volIdent
, 32))
959 if (udf_CS0toUTF8(&outstr
, &instr
)) {
960 strncpy(UDF_SB(sb
)->s_volume_ident
, outstr
.u_name
,
961 outstr
.u_len
> 31 ? 31 : outstr
.u_len
);
962 udf_debug("volIdent[] = '%s'\n",
963 UDF_SB(sb
)->s_volume_ident
);
966 if (!udf_build_ustr(&instr
, pvoldesc
->volSetIdent
, 128))
967 if (udf_CS0toUTF8(&outstr
, &instr
))
968 udf_debug("volSetIdent[] = '%s'\n", outstr
.u_name
);
971 static void udf_load_fileset(struct super_block
*sb
, struct buffer_head
*bh
,
972 kernel_lb_addr
*root
)
974 struct fileSetDesc
*fset
;
976 fset
= (struct fileSetDesc
*)bh
->b_data
;
978 *root
= lelb_to_cpu(fset
->rootDirectoryICB
.extLocation
);
980 UDF_SB(sb
)->s_serial_number
= le16_to_cpu(fset
->descTag
.tagSerialNum
);
982 udf_debug("Rootdir at block=%d, partition=%d\n",
983 root
->logicalBlockNum
, root
->partitionReferenceNum
);
986 int udf_compute_nr_groups(struct super_block
*sb
, u32 partition
)
988 struct udf_part_map
*map
= &UDF_SB(sb
)->s_partmaps
[partition
];
989 return (map
->s_partition_len
+
990 (sizeof(struct spaceBitmapDesc
) << 3) +
991 (sb
->s_blocksize
* 8) - 1) /
992 (sb
->s_blocksize
* 8);
995 static struct udf_bitmap
*udf_sb_alloc_bitmap(struct super_block
*sb
, u32 index
)
997 struct udf_bitmap
*bitmap
;
1001 nr_groups
= udf_compute_nr_groups(sb
, index
);
1002 size
= sizeof(struct udf_bitmap
) +
1003 (sizeof(struct buffer_head
*) * nr_groups
);
1005 if (size
<= PAGE_SIZE
)
1006 bitmap
= kmalloc(size
, GFP_KERNEL
);
1008 bitmap
= vmalloc(size
); /* TODO: get rid of vmalloc */
1010 if (bitmap
== NULL
) {
1011 udf_error(sb
, __FUNCTION__
,
1012 "Unable to allocate space for bitmap "
1013 "and %d buffer_head pointers", nr_groups
);
1017 memset(bitmap
, 0x00, size
);
1018 bitmap
->s_block_bitmap
= (struct buffer_head
**)(bitmap
+ 1);
1019 bitmap
->s_nr_groups
= nr_groups
;
1023 static int udf_load_partdesc(struct super_block
*sb
, struct buffer_head
*bh
)
1025 struct partitionDesc
*p
;
1027 struct udf_part_map
*map
;
1028 struct udf_sb_info
*sbi
;
1030 p
= (struct partitionDesc
*)bh
->b_data
;
1033 for (i
= 0; i
< sbi
->s_partitions
; i
++) {
1034 map
= &sbi
->s_partmaps
[i
];
1035 udf_debug("Searching map: (%d == %d)\n",
1036 map
->s_partition_num
,
1037 le16_to_cpu(p
->partitionNumber
));
1038 if (map
->s_partition_num
==
1039 le16_to_cpu(p
->partitionNumber
)) {
1040 map
->s_partition_len
=
1041 le32_to_cpu(p
->partitionLength
); /* blocks */
1042 map
->s_partition_root
=
1043 le32_to_cpu(p
->partitionStartingLocation
);
1044 if (p
->accessType
==
1045 cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY
))
1046 map
->s_partition_flags
|=
1047 UDF_PART_FLAG_READ_ONLY
;
1048 if (p
->accessType
==
1049 cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE
))
1050 map
->s_partition_flags
|=
1051 UDF_PART_FLAG_WRITE_ONCE
;
1052 if (p
->accessType
==
1053 cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE
))
1054 map
->s_partition_flags
|=
1055 UDF_PART_FLAG_REWRITABLE
;
1056 if (p
->accessType
==
1057 cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE
))
1058 map
->s_partition_flags
|=
1059 UDF_PART_FLAG_OVERWRITABLE
;
1061 if (!strcmp(p
->partitionContents
.ident
,
1062 PD_PARTITION_CONTENTS_NSR02
) ||
1063 !strcmp(p
->partitionContents
.ident
,
1064 PD_PARTITION_CONTENTS_NSR03
)) {
1065 struct partitionHeaderDesc
*phd
;
1067 phd
= (struct partitionHeaderDesc
*)
1068 (p
->partitionContentsUse
);
1069 if (phd
->unallocSpaceTable
.extLength
) {
1070 kernel_lb_addr loc
= {
1071 .logicalBlockNum
= le32_to_cpu(phd
->unallocSpaceTable
.extPosition
),
1072 .partitionReferenceNum
= i
,
1075 map
->s_uspace
.s_table
=
1077 if (!map
->s_uspace
.s_table
) {
1078 udf_debug("cannot load unallocSpaceTable (part %d)\n", i
);
1081 map
->s_partition_flags
|=
1082 UDF_PART_FLAG_UNALLOC_TABLE
;
1083 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
1084 i
, map
->s_uspace
.s_table
->i_ino
);
1086 if (phd
->unallocSpaceBitmap
.extLength
) {
1087 struct udf_bitmap
*bitmap
=
1088 udf_sb_alloc_bitmap(sb
, i
);
1089 map
->s_uspace
.s_bitmap
= bitmap
;
1090 if (bitmap
!= NULL
) {
1091 bitmap
->s_extLength
=
1092 le32_to_cpu(phd
->unallocSpaceBitmap
.extLength
);
1093 bitmap
->s_extPosition
=
1094 le32_to_cpu(phd
->unallocSpaceBitmap
.extPosition
);
1095 map
->s_partition_flags
|= UDF_PART_FLAG_UNALLOC_BITMAP
;
1096 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
1097 i
, bitmap
->s_extPosition
);
1100 if (phd
->partitionIntegrityTable
.extLength
)
1101 udf_debug("partitionIntegrityTable (part %d)\n", i
);
1102 if (phd
->freedSpaceTable
.extLength
) {
1103 kernel_lb_addr loc
= {
1104 .logicalBlockNum
= le32_to_cpu(phd
->freedSpaceTable
.extPosition
),
1105 .partitionReferenceNum
= i
,
1108 map
->s_fspace
.s_table
=
1110 if (!map
->s_fspace
.s_table
) {
1111 udf_debug("cannot load freedSpaceTable (part %d)\n", i
);
1114 map
->s_partition_flags
|=
1115 UDF_PART_FLAG_FREED_TABLE
;
1116 udf_debug("freedSpaceTable (part %d) @ %ld\n",
1117 i
, map
->s_fspace
.s_table
->i_ino
);
1119 if (phd
->freedSpaceBitmap
.extLength
) {
1120 struct udf_bitmap
*bitmap
=
1121 udf_sb_alloc_bitmap(sb
, i
);
1122 map
->s_fspace
.s_bitmap
= bitmap
;
1123 if (bitmap
!= NULL
) {
1124 bitmap
->s_extLength
=
1125 le32_to_cpu(phd
->freedSpaceBitmap
.extLength
);
1126 bitmap
->s_extPosition
=
1127 le32_to_cpu(phd
->freedSpaceBitmap
.extPosition
);
1128 map
->s_partition_flags
|= UDF_PART_FLAG_FREED_BITMAP
;
1129 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
1130 i
, bitmap
->s_extPosition
);
1137 if (i
== sbi
->s_partitions
)
1138 udf_debug("Partition (%d) not found in partition map\n",
1139 le16_to_cpu(p
->partitionNumber
));
1141 udf_debug("Partition (%d:%d type %x) starts at physical %d, "
1142 "block length %d\n",
1143 le16_to_cpu(p
->partitionNumber
), i
,
1144 map
->s_partition_type
,
1145 map
->s_partition_root
,
1146 map
->s_partition_len
);
1150 static int udf_load_logicalvol(struct super_block
*sb
, struct buffer_head
*bh
,
1151 kernel_lb_addr
*fileset
)
1153 struct logicalVolDesc
*lvd
;
1156 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1157 struct genericPartitionMap
*gpm
;
1159 lvd
= (struct logicalVolDesc
*)bh
->b_data
;
1161 i
= udf_sb_alloc_partition_maps(sb
, le32_to_cpu(lvd
->numPartitionMaps
));
1165 for (i
= 0, offset
= 0;
1166 i
< sbi
->s_partitions
&& offset
< le32_to_cpu(lvd
->mapTableLength
);
1167 i
++, offset
+= gpm
->partitionMapLength
) {
1168 struct udf_part_map
*map
= &sbi
->s_partmaps
[i
];
1169 gpm
= (struct genericPartitionMap
*)
1170 &(lvd
->partitionMaps
[offset
]);
1171 type
= gpm
->partitionMapType
;
1173 struct genericPartitionMap1
*gpm1
=
1174 (struct genericPartitionMap1
*)gpm
;
1175 map
->s_partition_type
= UDF_TYPE1_MAP15
;
1176 map
->s_volumeseqnum
= le16_to_cpu(gpm1
->volSeqNum
);
1177 map
->s_partition_num
= le16_to_cpu(gpm1
->partitionNum
);
1178 map
->s_partition_func
= NULL
;
1179 } else if (type
== 2) {
1180 struct udfPartitionMap2
*upm2
=
1181 (struct udfPartitionMap2
*)gpm
;
1182 if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_VIRTUAL
,
1183 strlen(UDF_ID_VIRTUAL
))) {
1185 le16_to_cpu(((__le16
*)upm2
->partIdent
.
1187 if (suf
== 0x0150) {
1188 map
->s_partition_type
=
1190 map
->s_partition_func
=
1191 udf_get_pblock_virt15
;
1192 } else if (suf
== 0x0200) {
1193 map
->s_partition_type
=
1195 map
->s_partition_func
=
1196 udf_get_pblock_virt20
;
1198 } else if (!strncmp(upm2
->partIdent
.ident
,
1200 strlen(UDF_ID_SPARABLE
))) {
1203 struct sparingTable
*st
;
1204 struct sparablePartitionMap
*spm
=
1205 (struct sparablePartitionMap
*)gpm
;
1207 map
->s_partition_type
= UDF_SPARABLE_MAP15
;
1208 map
->s_type_specific
.s_sparing
.s_packet_len
=
1209 le16_to_cpu(spm
->packetLength
);
1210 for (j
= 0; j
< spm
->numSparingTables
; j
++) {
1211 struct buffer_head
*bh2
;
1214 spm
->locSparingTable
[j
]);
1215 bh2
= udf_read_tagged(sb
, loc
, loc
,
1217 map
->s_type_specific
.s_sparing
.
1218 s_spar_map
[j
] = bh2
;
1221 st
= (struct sparingTable
*)
1223 if (ident
!= 0 || strncmp(
1224 st
->sparingIdent
.ident
,
1226 strlen(UDF_ID_SPARING
))) {
1228 map
->s_type_specific
.
1235 map
->s_partition_func
= udf_get_pblock_spar15
;
1237 udf_debug("Unknown ident: %s\n",
1238 upm2
->partIdent
.ident
);
1241 map
->s_volumeseqnum
= le16_to_cpu(upm2
->volSeqNum
);
1242 map
->s_partition_num
= le16_to_cpu(upm2
->partitionNum
);
1244 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1245 i
, map
->s_partition_num
, type
,
1246 map
->s_volumeseqnum
);
1250 long_ad
*la
= (long_ad
*)&(lvd
->logicalVolContentsUse
[0]);
1252 *fileset
= lelb_to_cpu(la
->extLocation
);
1253 udf_debug("FileSet found in LogicalVolDesc at block=%d, "
1254 "partition=%d\n", fileset
->logicalBlockNum
,
1255 fileset
->partitionReferenceNum
);
1257 if (lvd
->integritySeqExt
.extLength
)
1258 udf_load_logicalvolint(sb
, leea_to_cpu(lvd
->integritySeqExt
));
1264 * udf_load_logicalvolint
1267 static void udf_load_logicalvolint(struct super_block
*sb
, kernel_extent_ad loc
)
1269 struct buffer_head
*bh
= NULL
;
1271 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1272 struct logicalVolIntegrityDesc
*lvid
;
1274 while (loc
.extLength
> 0 &&
1275 (bh
= udf_read_tagged(sb
, loc
.extLocation
,
1276 loc
.extLocation
, &ident
)) &&
1277 ident
== TAG_IDENT_LVID
) {
1278 sbi
->s_lvid_bh
= bh
;
1279 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1281 if (lvid
->nextIntegrityExt
.extLength
)
1282 udf_load_logicalvolint(sb
,
1283 leea_to_cpu(lvid
->nextIntegrityExt
));
1285 if (sbi
->s_lvid_bh
!= bh
)
1287 loc
.extLength
-= sb
->s_blocksize
;
1290 if (sbi
->s_lvid_bh
!= bh
)
1295 * udf_process_sequence
1298 * Process a main/reserve volume descriptor sequence.
1301 * sb Pointer to _locked_ superblock.
1302 * block First block of first extent of the sequence.
1303 * lastblock Lastblock of first extent of the sequence.
1306 * July 1, 1997 - Andrew E. Mileski
1307 * Written, tested, and released.
1309 static int udf_process_sequence(struct super_block
*sb
, long block
,
1310 long lastblock
, kernel_lb_addr
*fileset
)
1312 struct buffer_head
*bh
= NULL
;
1313 struct udf_vds_record vds
[VDS_POS_LENGTH
];
1314 struct udf_vds_record
*curr
;
1315 struct generic_desc
*gd
;
1316 struct volDescPtr
*vdp
;
1321 long next_s
= 0, next_e
= 0;
1323 memset(vds
, 0, sizeof(struct udf_vds_record
) * VDS_POS_LENGTH
);
1325 /* Read the main descriptor sequence */
1326 for (; (!done
&& block
<= lastblock
); block
++) {
1328 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1332 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1333 gd
= (struct generic_desc
*)bh
->b_data
;
1334 vdsn
= le32_to_cpu(gd
->volDescSeqNum
);
1336 case TAG_IDENT_PVD
: /* ISO 13346 3/10.1 */
1337 curr
= &vds
[VDS_POS_PRIMARY_VOL_DESC
];
1338 if (vdsn
>= curr
->volDescSeqNum
) {
1339 curr
->volDescSeqNum
= vdsn
;
1340 curr
->block
= block
;
1343 case TAG_IDENT_VDP
: /* ISO 13346 3/10.3 */
1344 curr
= &vds
[VDS_POS_VOL_DESC_PTR
];
1345 if (vdsn
>= curr
->volDescSeqNum
) {
1346 curr
->volDescSeqNum
= vdsn
;
1347 curr
->block
= block
;
1349 vdp
= (struct volDescPtr
*)bh
->b_data
;
1350 next_s
= le32_to_cpu(
1351 vdp
->nextVolDescSeqExt
.extLocation
);
1352 next_e
= le32_to_cpu(
1353 vdp
->nextVolDescSeqExt
.extLength
);
1354 next_e
= next_e
>> sb
->s_blocksize_bits
;
1358 case TAG_IDENT_IUVD
: /* ISO 13346 3/10.4 */
1359 curr
= &vds
[VDS_POS_IMP_USE_VOL_DESC
];
1360 if (vdsn
>= curr
->volDescSeqNum
) {
1361 curr
->volDescSeqNum
= vdsn
;
1362 curr
->block
= block
;
1365 case TAG_IDENT_PD
: /* ISO 13346 3/10.5 */
1366 curr
= &vds
[VDS_POS_PARTITION_DESC
];
1368 curr
->block
= block
;
1370 case TAG_IDENT_LVD
: /* ISO 13346 3/10.6 */
1371 curr
= &vds
[VDS_POS_LOGICAL_VOL_DESC
];
1372 if (vdsn
>= curr
->volDescSeqNum
) {
1373 curr
->volDescSeqNum
= vdsn
;
1374 curr
->block
= block
;
1377 case TAG_IDENT_USD
: /* ISO 13346 3/10.8 */
1378 curr
= &vds
[VDS_POS_UNALLOC_SPACE_DESC
];
1379 if (vdsn
>= curr
->volDescSeqNum
) {
1380 curr
->volDescSeqNum
= vdsn
;
1381 curr
->block
= block
;
1384 case TAG_IDENT_TD
: /* ISO 13346 3/10.9 */
1385 vds
[VDS_POS_TERMINATING_DESC
].block
= block
;
1389 next_s
= next_e
= 0;
1396 for (i
= 0; i
< VDS_POS_LENGTH
; i
++) {
1398 bh
= udf_read_tagged(sb
, vds
[i
].block
, vds
[i
].block
,
1401 if (i
== VDS_POS_PRIMARY_VOL_DESC
) {
1402 udf_load_pvoldesc(sb
, bh
);
1403 } else if (i
== VDS_POS_LOGICAL_VOL_DESC
) {
1404 if (udf_load_logicalvol(sb
, bh
, fileset
)) {
1408 } else if (i
== VDS_POS_PARTITION_DESC
) {
1409 struct buffer_head
*bh2
= NULL
;
1410 if (udf_load_partdesc(sb
, bh
)) {
1414 for (j
= vds
[i
].block
+ 1;
1415 j
< vds
[VDS_POS_TERMINATING_DESC
].block
;
1417 bh2
= udf_read_tagged(sb
, j
, j
, &ident
);
1418 gd
= (struct generic_desc
*)bh2
->b_data
;
1419 if (ident
== TAG_IDENT_PD
)
1420 if (udf_load_partdesc(sb
,
1439 static int udf_check_valid(struct super_block
*sb
, int novrs
, int silent
)
1444 udf_debug("Validity check skipped because of novrs option\n");
1447 /* Check that it is NSR02 compliant */
1448 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1450 block
= udf_vrs(sb
, silent
);
1452 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1453 udf_debug("Failed to read byte 32768. Assuming open "
1454 "disc. Skipping validity check\n");
1455 if (!sbi
->s_last_block
)
1456 sbi
->s_last_block
= udf_get_last_block(sb
);
1463 static int udf_load_partition(struct super_block
*sb
, kernel_lb_addr
*fileset
)
1465 struct anchorVolDescPtr
*anchor
;
1467 struct buffer_head
*bh
;
1468 long main_s
, main_e
, reserve_s
, reserve_e
;
1470 struct udf_sb_info
*sbi
;
1476 for (i
= 0; i
< ARRAY_SIZE(sbi
->s_anchor
); i
++) {
1477 if (!sbi
->s_anchor
[i
])
1479 bh
= udf_read_tagged(sb
, sbi
->s_anchor
[i
], sbi
->s_anchor
[i
],
1484 anchor
= (struct anchorVolDescPtr
*)bh
->b_data
;
1486 /* Locate the main sequence */
1487 main_s
= le32_to_cpu(anchor
->mainVolDescSeqExt
.extLocation
);
1488 main_e
= le32_to_cpu(anchor
->mainVolDescSeqExt
.extLength
);
1489 main_e
= main_e
>> sb
->s_blocksize_bits
;
1492 /* Locate the reserve sequence */
1493 reserve_s
= le32_to_cpu(
1494 anchor
->reserveVolDescSeqExt
.extLocation
);
1495 reserve_e
= le32_to_cpu(
1496 anchor
->reserveVolDescSeqExt
.extLength
);
1497 reserve_e
= reserve_e
>> sb
->s_blocksize_bits
;
1498 reserve_e
+= reserve_s
;
1502 /* Process the main & reserve sequences */
1503 /* responsible for finding the PartitionDesc(s) */
1504 if (!(udf_process_sequence(sb
, main_s
, main_e
,
1506 udf_process_sequence(sb
, reserve_s
, reserve_e
,
1511 if (i
== ARRAY_SIZE(sbi
->s_anchor
)) {
1512 udf_debug("No Anchor block found\n");
1515 udf_debug("Using anchor in block %d\n", sbi
->s_anchor
[i
]);
1517 for (i
= 0; i
< sbi
->s_partitions
; i
++) {
1518 kernel_lb_addr
uninitialized_var(ino
);
1519 struct udf_part_map
*map
= &sbi
->s_partmaps
[i
];
1520 switch (map
->s_partition_type
) {
1521 case UDF_VIRTUAL_MAP15
:
1522 case UDF_VIRTUAL_MAP20
:
1523 if (!sbi
->s_last_block
) {
1524 sbi
->s_last_block
= udf_get_last_block(sb
);
1525 udf_find_anchor(sb
);
1528 if (!sbi
->s_last_block
) {
1529 udf_debug("Unable to determine Lastblock (For "
1530 "Virtual Partition)\n");
1534 for (j
= 0; j
< sbi
->s_partitions
; j
++) {
1535 struct udf_part_map
*map2
= &sbi
->s_partmaps
[j
];
1537 map
->s_volumeseqnum
==
1538 map2
->s_volumeseqnum
&&
1539 map
->s_partition_num
==
1540 map2
->s_partition_num
) {
1541 ino
.partitionReferenceNum
= j
;
1542 ino
.logicalBlockNum
=
1544 map2
->s_partition_root
;
1549 if (j
== sbi
->s_partitions
)
1552 sbi
->s_vat_inode
= udf_iget(sb
, ino
);
1553 if (!sbi
->s_vat_inode
)
1556 if (map
->s_partition_type
== UDF_VIRTUAL_MAP15
) {
1557 map
->s_type_specific
.s_virtual
.s_start_offset
=
1558 udf_ext0_offset(sbi
->s_vat_inode
);
1559 map
->s_type_specific
.s_virtual
.s_num_entries
=
1560 (sbi
->s_vat_inode
->i_size
- 36) >> 2;
1561 } else if (map
->s_partition_type
== UDF_VIRTUAL_MAP20
) {
1563 struct virtualAllocationTable20
*vat20
;
1565 pos
= udf_block_map(sbi
->s_vat_inode
, 0);
1566 bh
= sb_bread(sb
, pos
);
1569 vat20
= (struct virtualAllocationTable20
*)
1571 udf_ext0_offset(sbi
->s_vat_inode
);
1572 map
->s_type_specific
.s_virtual
.s_start_offset
=
1573 le16_to_cpu(vat20
->lengthHeader
) +
1574 udf_ext0_offset(sbi
->s_vat_inode
);
1575 map
->s_type_specific
.s_virtual
.s_num_entries
=
1576 (sbi
->s_vat_inode
->i_size
-
1577 map
->s_type_specific
.s_virtual
.
1578 s_start_offset
) >> 2;
1581 map
->s_partition_root
= udf_get_pblock(sb
, 0, i
, 0);
1582 map
->s_partition_len
=
1583 sbi
->s_partmaps
[ino
.partitionReferenceNum
].
1590 static void udf_open_lvid(struct super_block
*sb
)
1592 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1593 struct buffer_head
*bh
= sbi
->s_lvid_bh
;
1595 kernel_timestamp cpu_time
;
1596 struct logicalVolIntegrityDesc
*lvid
=
1597 (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1598 struct logicalVolIntegrityDescImpUse
*lvidiu
=
1601 lvidiu
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1602 lvidiu
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1603 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
))
1604 lvid
->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1605 lvid
->integrityType
= LVID_INTEGRITY_TYPE_OPEN
;
1607 lvid
->descTag
.descCRC
= cpu_to_le16(
1608 udf_crc((char *)lvid
+ sizeof(tag
),
1609 le16_to_cpu(lvid
->descTag
.descCRCLength
),
1612 lvid
->descTag
.tagChecksum
= udf_tag_checksum(&lvid
->descTag
);
1613 mark_buffer_dirty(bh
);
1617 static void udf_close_lvid(struct super_block
*sb
)
1619 kernel_timestamp cpu_time
;
1620 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1621 struct buffer_head
*bh
= sbi
->s_lvid_bh
;
1622 struct logicalVolIntegrityDesc
*lvid
;
1627 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1629 if (lvid
->integrityType
== LVID_INTEGRITY_TYPE_OPEN
) {
1630 struct logicalVolIntegrityDescImpUse
*lvidiu
=
1632 lvidiu
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1633 lvidiu
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1634 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
))
1635 lvid
->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1636 if (UDF_MAX_WRITE_VERSION
> le16_to_cpu(lvidiu
->maxUDFWriteRev
))
1637 lvidiu
->maxUDFWriteRev
=
1638 cpu_to_le16(UDF_MAX_WRITE_VERSION
);
1639 if (sbi
->s_udfrev
> le16_to_cpu(lvidiu
->minUDFReadRev
))
1640 lvidiu
->minUDFReadRev
= cpu_to_le16(sbi
->s_udfrev
);
1641 if (sbi
->s_udfrev
> le16_to_cpu(lvidiu
->minUDFWriteRev
))
1642 lvidiu
->minUDFWriteRev
= cpu_to_le16(sbi
->s_udfrev
);
1643 lvid
->integrityType
= cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE
);
1645 lvid
->descTag
.descCRC
= cpu_to_le16(
1646 udf_crc((char *)lvid
+ sizeof(tag
),
1647 le16_to_cpu(lvid
->descTag
.descCRCLength
),
1650 lvid
->descTag
.tagChecksum
= udf_tag_checksum(&lvid
->descTag
);
1651 mark_buffer_dirty(bh
);
1655 static void udf_sb_free_bitmap(struct udf_bitmap
*bitmap
)
1658 int nr_groups
= bitmap
->s_nr_groups
;
1659 int size
= sizeof(struct udf_bitmap
) + (sizeof(struct buffer_head
*) *
1662 for (i
= 0; i
< nr_groups
; i
++)
1663 if (bitmap
->s_block_bitmap
[i
])
1664 brelse(bitmap
->s_block_bitmap
[i
]);
1666 if (size
<= PAGE_SIZE
)
1672 static int udf_fill_super(struct super_block
*sb
, void *options
, int silent
)
1675 struct inode
*inode
= NULL
;
1676 struct udf_options uopt
;
1677 kernel_lb_addr rootdir
, fileset
;
1678 struct udf_sb_info
*sbi
;
1680 uopt
.flags
= (1 << UDF_FLAG_USE_AD_IN_ICB
) | (1 << UDF_FLAG_STRICT
);
1685 sbi
= kzalloc(sizeof(struct udf_sb_info
), GFP_KERNEL
);
1689 sb
->s_fs_info
= sbi
;
1691 mutex_init(&sbi
->s_alloc_mutex
);
1693 if (!udf_parse_options((char *)options
, &uopt
, false))
1696 if (uopt
.flags
& (1 << UDF_FLAG_UTF8
) &&
1697 uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) {
1698 udf_error(sb
, "udf_read_super",
1699 "utf8 cannot be combined with iocharset\n");
1702 #ifdef CONFIG_UDF_NLS
1703 if ((uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) && !uopt
.nls_map
) {
1704 uopt
.nls_map
= load_nls_default();
1706 uopt
.flags
&= ~(1 << UDF_FLAG_NLS_MAP
);
1708 udf_debug("Using default NLS map\n");
1711 if (!(uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)))
1712 uopt
.flags
|= (1 << UDF_FLAG_UTF8
);
1714 fileset
.logicalBlockNum
= 0xFFFFFFFF;
1715 fileset
.partitionReferenceNum
= 0xFFFF;
1717 sbi
->s_flags
= uopt
.flags
;
1718 sbi
->s_uid
= uopt
.uid
;
1719 sbi
->s_gid
= uopt
.gid
;
1720 sbi
->s_umask
= uopt
.umask
;
1721 sbi
->s_nls_map
= uopt
.nls_map
;
1723 /* Set the block size for all transfers */
1724 if (!sb_min_blocksize(sb
, uopt
.blocksize
)) {
1725 udf_debug("Bad block size (%d)\n", uopt
.blocksize
);
1726 printk(KERN_ERR
"udf: bad block size (%d)\n", uopt
.blocksize
);
1730 if (uopt
.session
== 0xFFFFFFFF)
1731 sbi
->s_session
= udf_get_last_session(sb
);
1733 sbi
->s_session
= uopt
.session
;
1735 udf_debug("Multi-session=%d\n", sbi
->s_session
);
1737 sbi
->s_last_block
= uopt
.lastblock
;
1738 sbi
->s_anchor
[0] = sbi
->s_anchor
[1] = 0;
1739 sbi
->s_anchor
[2] = uopt
.anchor
;
1740 sbi
->s_anchor
[3] = 256;
1742 if (udf_check_valid(sb
, uopt
.novrs
, silent
)) {
1743 /* read volume recognition sequences */
1744 printk(KERN_WARNING
"UDF-fs: No VRS found\n");
1748 udf_find_anchor(sb
);
1750 /* Fill in the rest of the superblock */
1751 sb
->s_op
= &udf_sb_ops
;
1754 sb
->s_magic
= UDF_SUPER_MAGIC
;
1755 sb
->s_time_gran
= 1000;
1757 if (udf_load_partition(sb
, &fileset
)) {
1758 printk(KERN_WARNING
"UDF-fs: No partition found (1)\n");
1762 udf_debug("Lastblock=%d\n", sbi
->s_last_block
);
1764 if (sbi
->s_lvid_bh
) {
1765 struct logicalVolIntegrityDescImpUse
*lvidiu
=
1767 uint16_t minUDFReadRev
= le16_to_cpu(lvidiu
->minUDFReadRev
);
1768 uint16_t minUDFWriteRev
= le16_to_cpu(lvidiu
->minUDFWriteRev
);
1769 /* uint16_t maxUDFWriteRev =
1770 le16_to_cpu(lvidiu->maxUDFWriteRev); */
1772 if (minUDFReadRev
> UDF_MAX_READ_VERSION
) {
1773 printk(KERN_ERR
"UDF-fs: minUDFReadRev=%x "
1775 le16_to_cpu(lvidiu
->minUDFReadRev
),
1776 UDF_MAX_READ_VERSION
);
1778 } else if (minUDFWriteRev
> UDF_MAX_WRITE_VERSION
)
1779 sb
->s_flags
|= MS_RDONLY
;
1781 sbi
->s_udfrev
= minUDFWriteRev
;
1783 if (minUDFReadRev
>= UDF_VERS_USE_EXTENDED_FE
)
1784 UDF_SET_FLAG(sb
, UDF_FLAG_USE_EXTENDED_FE
);
1785 if (minUDFReadRev
>= UDF_VERS_USE_STREAMS
)
1786 UDF_SET_FLAG(sb
, UDF_FLAG_USE_STREAMS
);
1789 if (!sbi
->s_partitions
) {
1790 printk(KERN_WARNING
"UDF-fs: No partition found (2)\n");
1794 if (sbi
->s_partmaps
[sbi
->s_partition
].s_partition_flags
&
1795 UDF_PART_FLAG_READ_ONLY
) {
1796 printk(KERN_NOTICE
"UDF-fs: Partition marked readonly; "
1797 "forcing readonly mount\n");
1798 sb
->s_flags
|= MS_RDONLY
;
1801 if (udf_find_fileset(sb
, &fileset
, &rootdir
)) {
1802 printk(KERN_WARNING
"UDF-fs: No fileset found\n");
1807 kernel_timestamp ts
;
1808 udf_time_to_stamp(&ts
, sbi
->s_record_time
);
1809 udf_info("UDF: Mounting volume '%s', "
1810 "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1811 sbi
->s_volume_ident
, ts
.year
, ts
.month
, ts
.day
,
1812 ts
.hour
, ts
.minute
, ts
.typeAndTimezone
);
1814 if (!(sb
->s_flags
& MS_RDONLY
))
1817 /* Assign the root inode */
1818 /* assign inodes by physical block number */
1819 /* perhaps it's not extensible enough, but for now ... */
1820 inode
= udf_iget(sb
, rootdir
);
1822 printk(KERN_ERR
"UDF-fs: Error in udf_iget, block=%d, "
1824 rootdir
.logicalBlockNum
, rootdir
.partitionReferenceNum
);
1828 /* Allocate a dentry for the root inode */
1829 sb
->s_root
= d_alloc_root(inode
);
1831 printk(KERN_ERR
"UDF-fs: Couldn't allocate root dentry\n");
1835 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
1839 if (sbi
->s_vat_inode
)
1840 iput(sbi
->s_vat_inode
);
1841 if (sbi
->s_partitions
) {
1842 struct udf_part_map
*map
= &sbi
->s_partmaps
[sbi
->s_partition
];
1843 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
)
1844 iput(map
->s_uspace
.s_table
);
1845 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
)
1846 iput(map
->s_fspace
.s_table
);
1847 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
)
1848 udf_sb_free_bitmap(map
->s_uspace
.s_bitmap
);
1849 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
)
1850 udf_sb_free_bitmap(map
->s_fspace
.s_bitmap
);
1851 if (map
->s_partition_type
== UDF_SPARABLE_MAP15
)
1852 for (i
= 0; i
< 4; i
++)
1853 brelse(map
->s_type_specific
.s_sparing
.
1856 #ifdef CONFIG_UDF_NLS
1857 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
1858 unload_nls(sbi
->s_nls_map
);
1860 if (!(sb
->s_flags
& MS_RDONLY
))
1862 brelse(sbi
->s_lvid_bh
);
1864 kfree(sbi
->s_partmaps
);
1866 sb
->s_fs_info
= NULL
;
1871 void udf_error(struct super_block
*sb
, const char *function
,
1872 const char *fmt
, ...)
1876 if (!(sb
->s_flags
& MS_RDONLY
)) {
1880 va_start(args
, fmt
);
1881 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
1883 printk(KERN_CRIT
"UDF-fs error (device %s): %s: %s\n",
1884 sb
->s_id
, function
, error_buf
);
1887 void udf_warning(struct super_block
*sb
, const char *function
,
1888 const char *fmt
, ...)
1892 va_start(args
, fmt
);
1893 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
1895 printk(KERN_WARNING
"UDF-fs warning (device %s): %s: %s\n",
1896 sb
->s_id
, function
, error_buf
);
1899 static void udf_put_super(struct super_block
*sb
)
1902 struct udf_sb_info
*sbi
;
1905 if (sbi
->s_vat_inode
)
1906 iput(sbi
->s_vat_inode
);
1907 if (sbi
->s_partitions
) {
1908 struct udf_part_map
*map
= &sbi
->s_partmaps
[sbi
->s_partition
];
1909 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
)
1910 iput(map
->s_uspace
.s_table
);
1911 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
)
1912 iput(map
->s_fspace
.s_table
);
1913 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
)
1914 udf_sb_free_bitmap(map
->s_uspace
.s_bitmap
);
1915 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
)
1916 udf_sb_free_bitmap(map
->s_fspace
.s_bitmap
);
1917 if (map
->s_partition_type
== UDF_SPARABLE_MAP15
)
1918 for (i
= 0; i
< 4; i
++)
1919 brelse(map
->s_type_specific
.s_sparing
.
1922 #ifdef CONFIG_UDF_NLS
1923 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
1924 unload_nls(sbi
->s_nls_map
);
1926 if (!(sb
->s_flags
& MS_RDONLY
))
1928 brelse(sbi
->s_lvid_bh
);
1929 kfree(sbi
->s_partmaps
);
1930 kfree(sb
->s_fs_info
);
1931 sb
->s_fs_info
= NULL
;
1934 static int udf_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
1936 struct super_block
*sb
= dentry
->d_sb
;
1937 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1938 struct logicalVolIntegrityDescImpUse
*lvidiu
;
1940 if (sbi
->s_lvid_bh
!= NULL
)
1941 lvidiu
= udf_sb_lvidiu(sbi
);
1945 buf
->f_type
= UDF_SUPER_MAGIC
;
1946 buf
->f_bsize
= sb
->s_blocksize
;
1947 buf
->f_blocks
= sbi
->s_partmaps
[sbi
->s_partition
].s_partition_len
;
1948 buf
->f_bfree
= udf_count_free(sb
);
1949 buf
->f_bavail
= buf
->f_bfree
;
1950 buf
->f_files
= (lvidiu
!= NULL
? (le32_to_cpu(lvidiu
->numFiles
) +
1951 le32_to_cpu(lvidiu
->numDirs
)) : 0)
1953 buf
->f_ffree
= buf
->f_bfree
;
1954 /* __kernel_fsid_t f_fsid */
1955 buf
->f_namelen
= UDF_NAME_LEN
- 2;
1960 static unsigned char udf_bitmap_lookup
[16] = {
1961 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
1964 static unsigned int udf_count_free_bitmap(struct super_block
*sb
,
1965 struct udf_bitmap
*bitmap
)
1967 struct buffer_head
*bh
= NULL
;
1968 unsigned int accum
= 0;
1970 int block
= 0, newblock
;
1976 struct spaceBitmapDesc
*bm
;
1980 loc
.logicalBlockNum
= bitmap
->s_extPosition
;
1981 loc
.partitionReferenceNum
= UDF_SB(sb
)->s_partition
;
1982 bh
= udf_read_ptagged(sb
, loc
, 0, &ident
);
1985 printk(KERN_ERR
"udf: udf_count_free failed\n");
1987 } else if (ident
!= TAG_IDENT_SBD
) {
1989 printk(KERN_ERR
"udf: udf_count_free failed\n");
1993 bm
= (struct spaceBitmapDesc
*)bh
->b_data
;
1994 bytes
= le32_to_cpu(bm
->numOfBytes
);
1995 index
= sizeof(struct spaceBitmapDesc
); /* offset in first block only */
1996 ptr
= (uint8_t *)bh
->b_data
;
1999 while ((bytes
> 0) && (index
< sb
->s_blocksize
)) {
2001 accum
+= udf_bitmap_lookup
[value
& 0x0f];
2002 accum
+= udf_bitmap_lookup
[value
>> 4];
2008 newblock
= udf_get_lb_pblock(sb
, loc
, ++block
);
2009 bh
= udf_tread(sb
, newblock
);
2011 udf_debug("read failed\n");
2015 ptr
= (uint8_t *)bh
->b_data
;
2026 static unsigned int udf_count_free_table(struct super_block
*sb
,
2027 struct inode
*table
)
2029 unsigned int accum
= 0;
2031 kernel_lb_addr eloc
;
2033 struct extent_position epos
;
2037 epos
.block
= UDF_I(table
)->i_location
;
2038 epos
.offset
= sizeof(struct unallocSpaceEntry
);
2041 while ((etype
= udf_next_aext(table
, &epos
, &eloc
, &elen
, 1)) != -1)
2042 accum
+= (elen
>> table
->i_sb
->s_blocksize_bits
);
2051 static unsigned int udf_count_free(struct super_block
*sb
)
2053 unsigned int accum
= 0;
2054 struct udf_sb_info
*sbi
;
2055 struct udf_part_map
*map
;
2058 if (sbi
->s_lvid_bh
) {
2059 struct logicalVolIntegrityDesc
*lvid
=
2060 (struct logicalVolIntegrityDesc
*)
2061 sbi
->s_lvid_bh
->b_data
;
2062 if (le32_to_cpu(lvid
->numOfPartitions
) > sbi
->s_partition
) {
2063 accum
= le32_to_cpu(
2064 lvid
->freeSpaceTable
[sbi
->s_partition
]);
2065 if (accum
== 0xFFFFFFFF)
2073 map
= &sbi
->s_partmaps
[sbi
->s_partition
];
2074 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
) {
2075 accum
+= udf_count_free_bitmap(sb
,
2076 map
->s_uspace
.s_bitmap
);
2078 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
) {
2079 accum
+= udf_count_free_bitmap(sb
,
2080 map
->s_fspace
.s_bitmap
);
2085 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
) {
2086 accum
+= udf_count_free_table(sb
,
2087 map
->s_uspace
.s_table
);
2089 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
) {
2090 accum
+= udf_count_free_table(sb
,
2091 map
->s_fspace
.s_table
);