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/buffer_head.h>
52 #include <linux/vfs.h>
53 #include <linux/vmalloc.h>
54 #include <linux/errno.h>
55 #include <linux/mount.h>
56 #include <linux/seq_file.h>
57 #include <linux/bitmap.h>
58 #include <linux/crc-itu-t.h>
59 #include <linux/log2.h>
60 #include <asm/byteorder.h>
65 #include <linux/init.h>
66 #include <asm/uaccess.h>
68 #define VDS_POS_PRIMARY_VOL_DESC 0
69 #define VDS_POS_UNALLOC_SPACE_DESC 1
70 #define VDS_POS_LOGICAL_VOL_DESC 2
71 #define VDS_POS_PARTITION_DESC 3
72 #define VDS_POS_IMP_USE_VOL_DESC 4
73 #define VDS_POS_VOL_DESC_PTR 5
74 #define VDS_POS_TERMINATING_DESC 6
75 #define VDS_POS_LENGTH 7
77 #define UDF_DEFAULT_BLOCKSIZE 2048
79 #define VSD_FIRST_SECTOR_OFFSET 32768
80 #define VSD_MAX_SECTOR_OFFSET 0x800000
82 enum { UDF_MAX_LINKS
= 0xffff };
84 /* These are the "meat" - everything else is stuffing */
85 static int udf_fill_super(struct super_block
*, void *, int);
86 static void udf_put_super(struct super_block
*);
87 static int udf_sync_fs(struct super_block
*, int);
88 static int udf_remount_fs(struct super_block
*, int *, char *);
89 static void udf_load_logicalvolint(struct super_block
*, struct kernel_extent_ad
);
90 static int udf_find_fileset(struct super_block
*, struct kernel_lb_addr
*,
91 struct kernel_lb_addr
*);
92 static void udf_load_fileset(struct super_block
*, struct buffer_head
*,
93 struct kernel_lb_addr
*);
94 static void udf_open_lvid(struct super_block
*);
95 static void udf_close_lvid(struct super_block
*);
96 static unsigned int udf_count_free(struct super_block
*);
97 static int udf_statfs(struct dentry
*, struct kstatfs
*);
98 static int udf_show_options(struct seq_file
*, struct dentry
*);
100 struct logicalVolIntegrityDescImpUse
*udf_sb_lvidiu(struct super_block
*sb
)
102 struct logicalVolIntegrityDesc
*lvid
;
103 unsigned int partnum
;
106 if (!UDF_SB(sb
)->s_lvid_bh
)
108 lvid
= (struct logicalVolIntegrityDesc
*)UDF_SB(sb
)->s_lvid_bh
->b_data
;
109 partnum
= le32_to_cpu(lvid
->numOfPartitions
);
110 if ((sb
->s_blocksize
- sizeof(struct logicalVolIntegrityDescImpUse
) -
111 offsetof(struct logicalVolIntegrityDesc
, impUse
)) /
112 (2 * sizeof(uint32_t)) < partnum
) {
113 udf_err(sb
, "Logical volume integrity descriptor corrupted "
114 "(numOfPartitions = %u)!\n", partnum
);
117 /* The offset is to skip freeSpaceTable and sizeTable arrays */
118 offset
= partnum
* 2 * sizeof(uint32_t);
119 return (struct logicalVolIntegrityDescImpUse
*)&(lvid
->impUse
[offset
]);
122 /* UDF filesystem type */
123 static struct dentry
*udf_mount(struct file_system_type
*fs_type
,
124 int flags
, const char *dev_name
, void *data
)
126 return mount_bdev(fs_type
, flags
, dev_name
, data
, udf_fill_super
);
129 static struct file_system_type udf_fstype
= {
130 .owner
= THIS_MODULE
,
133 .kill_sb
= kill_block_super
,
134 .fs_flags
= FS_REQUIRES_DEV
,
136 MODULE_ALIAS_FS("udf");
138 static struct kmem_cache
*udf_inode_cachep
;
140 static struct inode
*udf_alloc_inode(struct super_block
*sb
)
142 struct udf_inode_info
*ei
;
143 ei
= kmem_cache_alloc(udf_inode_cachep
, GFP_KERNEL
);
148 ei
->i_lenExtents
= 0;
149 ei
->i_next_alloc_block
= 0;
150 ei
->i_next_alloc_goal
= 0;
152 init_rwsem(&ei
->i_data_sem
);
153 ei
->cached_extent
.lstart
= -1;
154 spin_lock_init(&ei
->i_extent_cache_lock
);
156 return &ei
->vfs_inode
;
159 static void udf_i_callback(struct rcu_head
*head
)
161 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
162 kmem_cache_free(udf_inode_cachep
, UDF_I(inode
));
165 static void udf_destroy_inode(struct inode
*inode
)
167 call_rcu(&inode
->i_rcu
, udf_i_callback
);
170 static void init_once(void *foo
)
172 struct udf_inode_info
*ei
= (struct udf_inode_info
*)foo
;
174 ei
->i_ext
.i_data
= NULL
;
175 inode_init_once(&ei
->vfs_inode
);
178 static int init_inodecache(void)
180 udf_inode_cachep
= kmem_cache_create("udf_inode_cache",
181 sizeof(struct udf_inode_info
),
182 0, (SLAB_RECLAIM_ACCOUNT
|
185 if (!udf_inode_cachep
)
190 static void destroy_inodecache(void)
193 * Make sure all delayed rcu free inodes are flushed before we
197 kmem_cache_destroy(udf_inode_cachep
);
200 /* Superblock operations */
201 static const struct super_operations udf_sb_ops
= {
202 .alloc_inode
= udf_alloc_inode
,
203 .destroy_inode
= udf_destroy_inode
,
204 .write_inode
= udf_write_inode
,
205 .evict_inode
= udf_evict_inode
,
206 .put_super
= udf_put_super
,
207 .sync_fs
= udf_sync_fs
,
208 .statfs
= udf_statfs
,
209 .remount_fs
= udf_remount_fs
,
210 .show_options
= udf_show_options
,
215 unsigned int blocksize
;
216 unsigned int session
;
217 unsigned int lastblock
;
220 unsigned short partition
;
221 unsigned int fileset
;
222 unsigned int rootdir
;
229 struct nls_table
*nls_map
;
232 static int __init
init_udf_fs(void)
236 err
= init_inodecache();
239 err
= register_filesystem(&udf_fstype
);
246 destroy_inodecache();
252 static void __exit
exit_udf_fs(void)
254 unregister_filesystem(&udf_fstype
);
255 destroy_inodecache();
258 module_init(init_udf_fs
)
259 module_exit(exit_udf_fs
)
261 static int udf_sb_alloc_partition_maps(struct super_block
*sb
, u32 count
)
263 struct udf_sb_info
*sbi
= UDF_SB(sb
);
265 sbi
->s_partmaps
= kcalloc(count
, sizeof(struct udf_part_map
),
267 if (!sbi
->s_partmaps
) {
268 udf_err(sb
, "Unable to allocate space for %d partition maps\n",
270 sbi
->s_partitions
= 0;
274 sbi
->s_partitions
= count
;
278 static void udf_sb_free_bitmap(struct udf_bitmap
*bitmap
)
281 int nr_groups
= bitmap
->s_nr_groups
;
282 int size
= sizeof(struct udf_bitmap
) + (sizeof(struct buffer_head
*) *
285 for (i
= 0; i
< nr_groups
; i
++)
286 if (bitmap
->s_block_bitmap
[i
])
287 brelse(bitmap
->s_block_bitmap
[i
]);
289 if (size
<= PAGE_SIZE
)
295 static void udf_free_partition(struct udf_part_map
*map
)
298 struct udf_meta_data
*mdata
;
300 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
)
301 iput(map
->s_uspace
.s_table
);
302 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
)
303 iput(map
->s_fspace
.s_table
);
304 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
)
305 udf_sb_free_bitmap(map
->s_uspace
.s_bitmap
);
306 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
)
307 udf_sb_free_bitmap(map
->s_fspace
.s_bitmap
);
308 if (map
->s_partition_type
== UDF_SPARABLE_MAP15
)
309 for (i
= 0; i
< 4; i
++)
310 brelse(map
->s_type_specific
.s_sparing
.s_spar_map
[i
]);
311 else if (map
->s_partition_type
== UDF_METADATA_MAP25
) {
312 mdata
= &map
->s_type_specific
.s_metadata
;
313 iput(mdata
->s_metadata_fe
);
314 mdata
->s_metadata_fe
= NULL
;
316 iput(mdata
->s_mirror_fe
);
317 mdata
->s_mirror_fe
= NULL
;
319 iput(mdata
->s_bitmap_fe
);
320 mdata
->s_bitmap_fe
= NULL
;
324 static void udf_sb_free_partitions(struct super_block
*sb
)
326 struct udf_sb_info
*sbi
= UDF_SB(sb
);
328 if (sbi
->s_partmaps
== NULL
)
330 for (i
= 0; i
< sbi
->s_partitions
; i
++)
331 udf_free_partition(&sbi
->s_partmaps
[i
]);
332 kfree(sbi
->s_partmaps
);
333 sbi
->s_partmaps
= NULL
;
336 static int udf_show_options(struct seq_file
*seq
, struct dentry
*root
)
338 struct super_block
*sb
= root
->d_sb
;
339 struct udf_sb_info
*sbi
= UDF_SB(sb
);
341 if (!UDF_QUERY_FLAG(sb
, UDF_FLAG_STRICT
))
342 seq_puts(seq
, ",nostrict");
343 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_BLOCKSIZE_SET
))
344 seq_printf(seq
, ",bs=%lu", sb
->s_blocksize
);
345 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UNHIDE
))
346 seq_puts(seq
, ",unhide");
347 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UNDELETE
))
348 seq_puts(seq
, ",undelete");
349 if (!UDF_QUERY_FLAG(sb
, UDF_FLAG_USE_AD_IN_ICB
))
350 seq_puts(seq
, ",noadinicb");
351 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_USE_SHORT_AD
))
352 seq_puts(seq
, ",shortad");
353 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_FORGET
))
354 seq_puts(seq
, ",uid=forget");
355 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_IGNORE
))
356 seq_puts(seq
, ",uid=ignore");
357 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_FORGET
))
358 seq_puts(seq
, ",gid=forget");
359 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_IGNORE
))
360 seq_puts(seq
, ",gid=ignore");
361 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_SET
))
362 seq_printf(seq
, ",uid=%u", from_kuid(&init_user_ns
, sbi
->s_uid
));
363 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_SET
))
364 seq_printf(seq
, ",gid=%u", from_kgid(&init_user_ns
, sbi
->s_gid
));
365 if (sbi
->s_umask
!= 0)
366 seq_printf(seq
, ",umask=%ho", sbi
->s_umask
);
367 if (sbi
->s_fmode
!= UDF_INVALID_MODE
)
368 seq_printf(seq
, ",mode=%ho", sbi
->s_fmode
);
369 if (sbi
->s_dmode
!= UDF_INVALID_MODE
)
370 seq_printf(seq
, ",dmode=%ho", sbi
->s_dmode
);
371 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_SESSION_SET
))
372 seq_printf(seq
, ",session=%u", sbi
->s_session
);
373 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_LASTBLOCK_SET
))
374 seq_printf(seq
, ",lastblock=%u", sbi
->s_last_block
);
375 if (sbi
->s_anchor
!= 0)
376 seq_printf(seq
, ",anchor=%u", sbi
->s_anchor
);
378 * volume, partition, fileset and rootdir seem to be ignored
381 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UTF8
))
382 seq_puts(seq
, ",utf8");
383 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
) && sbi
->s_nls_map
)
384 seq_printf(seq
, ",iocharset=%s", sbi
->s_nls_map
->charset
);
393 * Parse mount options.
396 * The following mount options are supported:
398 * gid= Set the default group.
399 * umask= Set the default umask.
400 * mode= Set the default file permissions.
401 * dmode= Set the default directory permissions.
402 * uid= Set the default user.
403 * bs= Set the block size.
404 * unhide Show otherwise hidden files.
405 * undelete Show deleted files in lists.
406 * adinicb Embed data in the inode (default)
407 * noadinicb Don't embed data in the inode
408 * shortad Use short ad's
409 * longad Use long ad's (default)
410 * nostrict Unset strict conformance
411 * iocharset= Set the NLS character set
413 * The remaining are for debugging and disaster recovery:
415 * novrs Skip volume sequence recognition
417 * The following expect a offset from 0.
419 * session= Set the CDROM session (default= last session)
420 * anchor= Override standard anchor location. (default= 256)
421 * volume= Override the VolumeDesc location. (unused)
422 * partition= Override the PartitionDesc location. (unused)
423 * lastblock= Set the last block of the filesystem/
425 * The following expect a offset from the partition root.
427 * fileset= Override the fileset block location. (unused)
428 * rootdir= Override the root directory location. (unused)
429 * WARNING: overriding the rootdir to a non-directory may
430 * yield highly unpredictable results.
433 * options Pointer to mount options string.
434 * uopts Pointer to mount options variable.
437 * <return> 1 Mount options parsed okay.
438 * <return> 0 Error parsing mount options.
441 * July 1, 1997 - Andrew E. Mileski
442 * Written, tested, and released.
446 Opt_novrs
, Opt_nostrict
, Opt_bs
, Opt_unhide
, Opt_undelete
,
447 Opt_noadinicb
, Opt_adinicb
, Opt_shortad
, Opt_longad
,
448 Opt_gid
, Opt_uid
, Opt_umask
, Opt_session
, Opt_lastblock
,
449 Opt_anchor
, Opt_volume
, Opt_partition
, Opt_fileset
,
450 Opt_rootdir
, Opt_utf8
, Opt_iocharset
,
451 Opt_err
, Opt_uforget
, Opt_uignore
, Opt_gforget
, Opt_gignore
,
455 static const match_table_t tokens
= {
456 {Opt_novrs
, "novrs"},
457 {Opt_nostrict
, "nostrict"},
459 {Opt_unhide
, "unhide"},
460 {Opt_undelete
, "undelete"},
461 {Opt_noadinicb
, "noadinicb"},
462 {Opt_adinicb
, "adinicb"},
463 {Opt_shortad
, "shortad"},
464 {Opt_longad
, "longad"},
465 {Opt_uforget
, "uid=forget"},
466 {Opt_uignore
, "uid=ignore"},
467 {Opt_gforget
, "gid=forget"},
468 {Opt_gignore
, "gid=ignore"},
471 {Opt_umask
, "umask=%o"},
472 {Opt_session
, "session=%u"},
473 {Opt_lastblock
, "lastblock=%u"},
474 {Opt_anchor
, "anchor=%u"},
475 {Opt_volume
, "volume=%u"},
476 {Opt_partition
, "partition=%u"},
477 {Opt_fileset
, "fileset=%u"},
478 {Opt_rootdir
, "rootdir=%u"},
480 {Opt_iocharset
, "iocharset=%s"},
481 {Opt_fmode
, "mode=%o"},
482 {Opt_dmode
, "dmode=%o"},
486 static int udf_parse_options(char *options
, struct udf_options
*uopt
,
493 uopt
->partition
= 0xFFFF;
494 uopt
->session
= 0xFFFFFFFF;
497 uopt
->volume
= 0xFFFFFFFF;
498 uopt
->rootdir
= 0xFFFFFFFF;
499 uopt
->fileset
= 0xFFFFFFFF;
500 uopt
->nls_map
= NULL
;
505 while ((p
= strsep(&options
, ",")) != NULL
) {
506 substring_t args
[MAX_OPT_ARGS
];
511 token
= match_token(p
, tokens
, args
);
517 if (match_int(&args
[0], &option
))
519 uopt
->blocksize
= option
;
520 uopt
->flags
|= (1 << UDF_FLAG_BLOCKSIZE_SET
);
523 uopt
->flags
|= (1 << UDF_FLAG_UNHIDE
);
526 uopt
->flags
|= (1 << UDF_FLAG_UNDELETE
);
529 uopt
->flags
&= ~(1 << UDF_FLAG_USE_AD_IN_ICB
);
532 uopt
->flags
|= (1 << UDF_FLAG_USE_AD_IN_ICB
);
535 uopt
->flags
|= (1 << UDF_FLAG_USE_SHORT_AD
);
538 uopt
->flags
&= ~(1 << UDF_FLAG_USE_SHORT_AD
);
541 if (match_int(args
, &option
))
543 uopt
->gid
= make_kgid(current_user_ns(), option
);
544 if (!gid_valid(uopt
->gid
))
546 uopt
->flags
|= (1 << UDF_FLAG_GID_SET
);
549 if (match_int(args
, &option
))
551 uopt
->uid
= make_kuid(current_user_ns(), option
);
552 if (!uid_valid(uopt
->uid
))
554 uopt
->flags
|= (1 << UDF_FLAG_UID_SET
);
557 if (match_octal(args
, &option
))
559 uopt
->umask
= option
;
562 uopt
->flags
&= ~(1 << UDF_FLAG_STRICT
);
565 if (match_int(args
, &option
))
567 uopt
->session
= option
;
569 uopt
->flags
|= (1 << UDF_FLAG_SESSION_SET
);
572 if (match_int(args
, &option
))
574 uopt
->lastblock
= option
;
576 uopt
->flags
|= (1 << UDF_FLAG_LASTBLOCK_SET
);
579 if (match_int(args
, &option
))
581 uopt
->anchor
= option
;
584 if (match_int(args
, &option
))
586 uopt
->volume
= option
;
589 if (match_int(args
, &option
))
591 uopt
->partition
= option
;
594 if (match_int(args
, &option
))
596 uopt
->fileset
= option
;
599 if (match_int(args
, &option
))
601 uopt
->rootdir
= option
;
604 uopt
->flags
|= (1 << UDF_FLAG_UTF8
);
606 #ifdef CONFIG_UDF_NLS
608 uopt
->nls_map
= load_nls(args
[0].from
);
609 uopt
->flags
|= (1 << UDF_FLAG_NLS_MAP
);
613 uopt
->flags
|= (1 << UDF_FLAG_UID_IGNORE
);
616 uopt
->flags
|= (1 << UDF_FLAG_UID_FORGET
);
619 uopt
->flags
|= (1 << UDF_FLAG_GID_IGNORE
);
622 uopt
->flags
|= (1 << UDF_FLAG_GID_FORGET
);
625 if (match_octal(args
, &option
))
627 uopt
->fmode
= option
& 0777;
630 if (match_octal(args
, &option
))
632 uopt
->dmode
= option
& 0777;
635 pr_err("bad mount option \"%s\" or missing value\n", p
);
642 static int udf_remount_fs(struct super_block
*sb
, int *flags
, char *options
)
644 struct udf_options uopt
;
645 struct udf_sb_info
*sbi
= UDF_SB(sb
);
647 struct logicalVolIntegrityDescImpUse
*lvidiu
= udf_sb_lvidiu(sb
);
651 int write_rev
= le16_to_cpu(lvidiu
->minUDFWriteRev
);
652 if (write_rev
> UDF_MAX_WRITE_VERSION
&& !(*flags
& MS_RDONLY
))
656 uopt
.flags
= sbi
->s_flags
;
657 uopt
.uid
= sbi
->s_uid
;
658 uopt
.gid
= sbi
->s_gid
;
659 uopt
.umask
= sbi
->s_umask
;
660 uopt
.fmode
= sbi
->s_fmode
;
661 uopt
.dmode
= sbi
->s_dmode
;
663 if (!udf_parse_options(options
, &uopt
, true))
666 write_lock(&sbi
->s_cred_lock
);
667 sbi
->s_flags
= uopt
.flags
;
668 sbi
->s_uid
= uopt
.uid
;
669 sbi
->s_gid
= uopt
.gid
;
670 sbi
->s_umask
= uopt
.umask
;
671 sbi
->s_fmode
= uopt
.fmode
;
672 sbi
->s_dmode
= uopt
.dmode
;
673 write_unlock(&sbi
->s_cred_lock
);
675 if ((*flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
))
678 if (*flags
& MS_RDONLY
)
687 /* Check Volume Structure Descriptors (ECMA 167 2/9.1) */
688 /* We also check any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
689 static loff_t
udf_check_vsd(struct super_block
*sb
)
691 struct volStructDesc
*vsd
= NULL
;
692 loff_t sector
= VSD_FIRST_SECTOR_OFFSET
;
694 struct buffer_head
*bh
= NULL
;
697 struct udf_sb_info
*sbi
;
700 if (sb
->s_blocksize
< sizeof(struct volStructDesc
))
701 sectorsize
= sizeof(struct volStructDesc
);
703 sectorsize
= sb
->s_blocksize
;
705 sector
+= (sbi
->s_session
<< sb
->s_blocksize_bits
);
707 udf_debug("Starting at sector %u (%ld byte sectors)\n",
708 (unsigned int)(sector
>> sb
->s_blocksize_bits
),
710 /* Process the sequence (if applicable). The hard limit on the sector
711 * offset is arbitrary, hopefully large enough so that all valid UDF
712 * filesystems will be recognised. There is no mention of an upper
713 * bound to the size of the volume recognition area in the standard.
714 * The limit will prevent the code to read all the sectors of a
715 * specially crafted image (like a bluray disc full of CD001 sectors),
716 * potentially causing minutes or even hours of uninterruptible I/O
717 * activity. This actually happened with uninitialised SSD partitions
718 * (all 0xFF) before the check for the limit and all valid IDs were
720 for (; !nsr02
&& !nsr03
&& sector
< VSD_MAX_SECTOR_OFFSET
;
721 sector
+= sectorsize
) {
723 bh
= udf_tread(sb
, sector
>> sb
->s_blocksize_bits
);
727 /* Look for ISO descriptors */
728 vsd
= (struct volStructDesc
*)(bh
->b_data
+
729 (sector
& (sb
->s_blocksize
- 1)));
731 if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_CD001
,
733 switch (vsd
->structType
) {
735 udf_debug("ISO9660 Boot Record found\n");
738 udf_debug("ISO9660 Primary Volume Descriptor found\n");
741 udf_debug("ISO9660 Supplementary Volume Descriptor found\n");
744 udf_debug("ISO9660 Volume Partition Descriptor found\n");
747 udf_debug("ISO9660 Volume Descriptor Set Terminator found\n");
750 udf_debug("ISO9660 VRS (%u) found\n",
754 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_BEA01
,
757 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_TEA01
,
761 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR02
,
764 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR03
,
767 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_BOOT2
,
770 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_CDW02
,
774 /* invalid id : end of volume recognition area */
785 else if (!bh
&& sector
- (sbi
->s_session
<< sb
->s_blocksize_bits
) ==
786 VSD_FIRST_SECTOR_OFFSET
)
792 static int udf_find_fileset(struct super_block
*sb
,
793 struct kernel_lb_addr
*fileset
,
794 struct kernel_lb_addr
*root
)
796 struct buffer_head
*bh
= NULL
;
799 struct udf_sb_info
*sbi
;
801 if (fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
802 fileset
->partitionReferenceNum
!= 0xFFFF) {
803 bh
= udf_read_ptagged(sb
, fileset
, 0, &ident
);
807 } else if (ident
!= TAG_IDENT_FSD
) {
816 /* Search backwards through the partitions */
817 struct kernel_lb_addr newfileset
;
819 /* --> cvg: FIXME - is it reasonable? */
822 for (newfileset
.partitionReferenceNum
= sbi
->s_partitions
- 1;
823 (newfileset
.partitionReferenceNum
!= 0xFFFF &&
824 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
825 fileset
->partitionReferenceNum
== 0xFFFF);
826 newfileset
.partitionReferenceNum
--) {
827 lastblock
= sbi
->s_partmaps
828 [newfileset
.partitionReferenceNum
]
830 newfileset
.logicalBlockNum
= 0;
833 bh
= udf_read_ptagged(sb
, &newfileset
, 0,
836 newfileset
.logicalBlockNum
++;
843 struct spaceBitmapDesc
*sp
;
844 sp
= (struct spaceBitmapDesc
*)
846 newfileset
.logicalBlockNum
+= 1 +
847 ((le32_to_cpu(sp
->numOfBytes
) +
848 sizeof(struct spaceBitmapDesc
)
849 - 1) >> sb
->s_blocksize_bits
);
854 *fileset
= newfileset
;
857 newfileset
.logicalBlockNum
++;
862 } while (newfileset
.logicalBlockNum
< lastblock
&&
863 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
864 fileset
->partitionReferenceNum
== 0xFFFF);
868 if ((fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
869 fileset
->partitionReferenceNum
!= 0xFFFF) && bh
) {
870 udf_debug("Fileset at block=%d, partition=%d\n",
871 fileset
->logicalBlockNum
,
872 fileset
->partitionReferenceNum
);
874 sbi
->s_partition
= fileset
->partitionReferenceNum
;
875 udf_load_fileset(sb
, bh
, root
);
883 * Load primary Volume Descriptor Sequence
885 * Return <0 on error, 0 on success. -EAGAIN is special meaning next sequence
888 static int udf_load_pvoldesc(struct super_block
*sb
, sector_t block
)
890 struct primaryVolDesc
*pvoldesc
;
891 struct ustr
*instr
, *outstr
;
892 struct buffer_head
*bh
;
896 instr
= kmalloc(sizeof(struct ustr
), GFP_NOFS
);
900 outstr
= kmalloc(sizeof(struct ustr
), GFP_NOFS
);
904 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
910 if (ident
!= TAG_IDENT_PVD
) {
915 pvoldesc
= (struct primaryVolDesc
*)bh
->b_data
;
917 if (udf_disk_stamp_to_time(&UDF_SB(sb
)->s_record_time
,
918 pvoldesc
->recordingDateAndTime
)) {
920 struct timestamp
*ts
= &pvoldesc
->recordingDateAndTime
;
921 udf_debug("recording time %04u/%02u/%02u %02u:%02u (%x)\n",
922 le16_to_cpu(ts
->year
), ts
->month
, ts
->day
, ts
->hour
,
923 ts
->minute
, le16_to_cpu(ts
->typeAndTimezone
));
927 if (!udf_build_ustr(instr
, pvoldesc
->volIdent
, 32))
928 if (udf_CS0toUTF8(outstr
, instr
)) {
929 strncpy(UDF_SB(sb
)->s_volume_ident
, outstr
->u_name
,
930 outstr
->u_len
> 31 ? 31 : outstr
->u_len
);
931 udf_debug("volIdent[] = '%s'\n",
932 UDF_SB(sb
)->s_volume_ident
);
935 if (!udf_build_ustr(instr
, pvoldesc
->volSetIdent
, 128))
936 if (udf_CS0toUTF8(outstr
, instr
))
937 udf_debug("volSetIdent[] = '%s'\n", outstr
->u_name
);
949 struct inode
*udf_find_metadata_inode_efe(struct super_block
*sb
,
950 u32 meta_file_loc
, u32 partition_num
)
952 struct kernel_lb_addr addr
;
953 struct inode
*metadata_fe
;
955 addr
.logicalBlockNum
= meta_file_loc
;
956 addr
.partitionReferenceNum
= partition_num
;
958 metadata_fe
= udf_iget(sb
, &addr
);
960 if (metadata_fe
== NULL
)
961 udf_warn(sb
, "metadata inode efe not found\n");
962 else if (UDF_I(metadata_fe
)->i_alloc_type
!= ICBTAG_FLAG_AD_SHORT
) {
963 udf_warn(sb
, "metadata inode efe does not have short allocation descriptors!\n");
971 static int udf_load_metadata_files(struct super_block
*sb
, int partition
)
973 struct udf_sb_info
*sbi
= UDF_SB(sb
);
974 struct udf_part_map
*map
;
975 struct udf_meta_data
*mdata
;
976 struct kernel_lb_addr addr
;
978 map
= &sbi
->s_partmaps
[partition
];
979 mdata
= &map
->s_type_specific
.s_metadata
;
981 /* metadata address */
982 udf_debug("Metadata file location: block = %d part = %d\n",
983 mdata
->s_meta_file_loc
, map
->s_partition_num
);
985 mdata
->s_metadata_fe
= udf_find_metadata_inode_efe(sb
,
986 mdata
->s_meta_file_loc
, map
->s_partition_num
);
988 if (mdata
->s_metadata_fe
== NULL
) {
989 /* mirror file entry */
990 udf_debug("Mirror metadata file location: block = %d part = %d\n",
991 mdata
->s_mirror_file_loc
, map
->s_partition_num
);
993 mdata
->s_mirror_fe
= udf_find_metadata_inode_efe(sb
,
994 mdata
->s_mirror_file_loc
, map
->s_partition_num
);
996 if (mdata
->s_mirror_fe
== NULL
) {
997 udf_err(sb
, "Both metadata and mirror metadata inode efe can not found\n");
1005 * Load only if bitmap file location differs from 0xFFFFFFFF (DCN-5102)
1007 if (mdata
->s_bitmap_file_loc
!= 0xFFFFFFFF) {
1008 addr
.logicalBlockNum
= mdata
->s_bitmap_file_loc
;
1009 addr
.partitionReferenceNum
= map
->s_partition_num
;
1011 udf_debug("Bitmap file location: block = %d part = %d\n",
1012 addr
.logicalBlockNum
, addr
.partitionReferenceNum
);
1014 mdata
->s_bitmap_fe
= udf_iget(sb
, &addr
);
1015 if (mdata
->s_bitmap_fe
== NULL
) {
1016 if (sb
->s_flags
& MS_RDONLY
)
1017 udf_warn(sb
, "bitmap inode efe not found but it's ok since the disc is mounted read-only\n");
1019 udf_err(sb
, "bitmap inode efe not found and attempted read-write mount\n");
1025 udf_debug("udf_load_metadata_files Ok\n");
1029 static void udf_load_fileset(struct super_block
*sb
, struct buffer_head
*bh
,
1030 struct kernel_lb_addr
*root
)
1032 struct fileSetDesc
*fset
;
1034 fset
= (struct fileSetDesc
*)bh
->b_data
;
1036 *root
= lelb_to_cpu(fset
->rootDirectoryICB
.extLocation
);
1038 UDF_SB(sb
)->s_serial_number
= le16_to_cpu(fset
->descTag
.tagSerialNum
);
1040 udf_debug("Rootdir at block=%d, partition=%d\n",
1041 root
->logicalBlockNum
, root
->partitionReferenceNum
);
1044 int udf_compute_nr_groups(struct super_block
*sb
, u32 partition
)
1046 struct udf_part_map
*map
= &UDF_SB(sb
)->s_partmaps
[partition
];
1047 return DIV_ROUND_UP(map
->s_partition_len
+
1048 (sizeof(struct spaceBitmapDesc
) << 3),
1049 sb
->s_blocksize
* 8);
1052 static struct udf_bitmap
*udf_sb_alloc_bitmap(struct super_block
*sb
, u32 index
)
1054 struct udf_bitmap
*bitmap
;
1058 nr_groups
= udf_compute_nr_groups(sb
, index
);
1059 size
= sizeof(struct udf_bitmap
) +
1060 (sizeof(struct buffer_head
*) * nr_groups
);
1062 if (size
<= PAGE_SIZE
)
1063 bitmap
= kzalloc(size
, GFP_KERNEL
);
1065 bitmap
= vzalloc(size
); /* TODO: get rid of vzalloc */
1070 bitmap
->s_nr_groups
= nr_groups
;
1074 static int udf_fill_partdesc_info(struct super_block
*sb
,
1075 struct partitionDesc
*p
, int p_index
)
1077 struct udf_part_map
*map
;
1078 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1079 struct partitionHeaderDesc
*phd
;
1081 map
= &sbi
->s_partmaps
[p_index
];
1083 map
->s_partition_len
= le32_to_cpu(p
->partitionLength
); /* blocks */
1084 map
->s_partition_root
= le32_to_cpu(p
->partitionStartingLocation
);
1086 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY
))
1087 map
->s_partition_flags
|= UDF_PART_FLAG_READ_ONLY
;
1088 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE
))
1089 map
->s_partition_flags
|= UDF_PART_FLAG_WRITE_ONCE
;
1090 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE
))
1091 map
->s_partition_flags
|= UDF_PART_FLAG_REWRITABLE
;
1092 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE
))
1093 map
->s_partition_flags
|= UDF_PART_FLAG_OVERWRITABLE
;
1095 udf_debug("Partition (%d type %x) starts at physical %d, block length %d\n",
1096 p_index
, map
->s_partition_type
,
1097 map
->s_partition_root
, map
->s_partition_len
);
1099 if (strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR02
) &&
1100 strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR03
))
1103 phd
= (struct partitionHeaderDesc
*)p
->partitionContentsUse
;
1104 if (phd
->unallocSpaceTable
.extLength
) {
1105 struct kernel_lb_addr loc
= {
1106 .logicalBlockNum
= le32_to_cpu(
1107 phd
->unallocSpaceTable
.extPosition
),
1108 .partitionReferenceNum
= p_index
,
1111 map
->s_uspace
.s_table
= udf_iget(sb
, &loc
);
1112 if (!map
->s_uspace
.s_table
) {
1113 udf_debug("cannot load unallocSpaceTable (part %d)\n",
1117 map
->s_partition_flags
|= UDF_PART_FLAG_UNALLOC_TABLE
;
1118 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
1119 p_index
, map
->s_uspace
.s_table
->i_ino
);
1122 if (phd
->unallocSpaceBitmap
.extLength
) {
1123 struct udf_bitmap
*bitmap
= udf_sb_alloc_bitmap(sb
, p_index
);
1126 map
->s_uspace
.s_bitmap
= bitmap
;
1127 bitmap
->s_extPosition
= le32_to_cpu(
1128 phd
->unallocSpaceBitmap
.extPosition
);
1129 map
->s_partition_flags
|= UDF_PART_FLAG_UNALLOC_BITMAP
;
1130 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
1131 p_index
, bitmap
->s_extPosition
);
1134 if (phd
->partitionIntegrityTable
.extLength
)
1135 udf_debug("partitionIntegrityTable (part %d)\n", p_index
);
1137 if (phd
->freedSpaceTable
.extLength
) {
1138 struct kernel_lb_addr loc
= {
1139 .logicalBlockNum
= le32_to_cpu(
1140 phd
->freedSpaceTable
.extPosition
),
1141 .partitionReferenceNum
= p_index
,
1144 map
->s_fspace
.s_table
= udf_iget(sb
, &loc
);
1145 if (!map
->s_fspace
.s_table
) {
1146 udf_debug("cannot load freedSpaceTable (part %d)\n",
1151 map
->s_partition_flags
|= UDF_PART_FLAG_FREED_TABLE
;
1152 udf_debug("freedSpaceTable (part %d) @ %ld\n",
1153 p_index
, map
->s_fspace
.s_table
->i_ino
);
1156 if (phd
->freedSpaceBitmap
.extLength
) {
1157 struct udf_bitmap
*bitmap
= udf_sb_alloc_bitmap(sb
, p_index
);
1160 map
->s_fspace
.s_bitmap
= bitmap
;
1161 bitmap
->s_extPosition
= le32_to_cpu(
1162 phd
->freedSpaceBitmap
.extPosition
);
1163 map
->s_partition_flags
|= UDF_PART_FLAG_FREED_BITMAP
;
1164 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
1165 p_index
, bitmap
->s_extPosition
);
1170 static void udf_find_vat_block(struct super_block
*sb
, int p_index
,
1171 int type1_index
, sector_t start_block
)
1173 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1174 struct udf_part_map
*map
= &sbi
->s_partmaps
[p_index
];
1176 struct kernel_lb_addr ino
;
1179 * VAT file entry is in the last recorded block. Some broken disks have
1180 * it a few blocks before so try a bit harder...
1182 ino
.partitionReferenceNum
= type1_index
;
1183 for (vat_block
= start_block
;
1184 vat_block
>= map
->s_partition_root
&&
1185 vat_block
>= start_block
- 3 &&
1186 !sbi
->s_vat_inode
; vat_block
--) {
1187 ino
.logicalBlockNum
= vat_block
- map
->s_partition_root
;
1188 sbi
->s_vat_inode
= udf_iget(sb
, &ino
);
1192 static int udf_load_vat(struct super_block
*sb
, int p_index
, int type1_index
)
1194 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1195 struct udf_part_map
*map
= &sbi
->s_partmaps
[p_index
];
1196 struct buffer_head
*bh
= NULL
;
1197 struct udf_inode_info
*vati
;
1199 struct virtualAllocationTable20
*vat20
;
1200 sector_t blocks
= sb
->s_bdev
->bd_inode
->i_size
>> sb
->s_blocksize_bits
;
1202 udf_find_vat_block(sb
, p_index
, type1_index
, sbi
->s_last_block
);
1203 if (!sbi
->s_vat_inode
&&
1204 sbi
->s_last_block
!= blocks
- 1) {
1205 pr_notice("Failed to read VAT inode from the last recorded block (%lu), retrying with the last block of the device (%lu).\n",
1206 (unsigned long)sbi
->s_last_block
,
1207 (unsigned long)blocks
- 1);
1208 udf_find_vat_block(sb
, p_index
, type1_index
, blocks
- 1);
1210 if (!sbi
->s_vat_inode
)
1213 if (map
->s_partition_type
== UDF_VIRTUAL_MAP15
) {
1214 map
->s_type_specific
.s_virtual
.s_start_offset
= 0;
1215 map
->s_type_specific
.s_virtual
.s_num_entries
=
1216 (sbi
->s_vat_inode
->i_size
- 36) >> 2;
1217 } else if (map
->s_partition_type
== UDF_VIRTUAL_MAP20
) {
1218 vati
= UDF_I(sbi
->s_vat_inode
);
1219 if (vati
->i_alloc_type
!= ICBTAG_FLAG_AD_IN_ICB
) {
1220 pos
= udf_block_map(sbi
->s_vat_inode
, 0);
1221 bh
= sb_bread(sb
, pos
);
1224 vat20
= (struct virtualAllocationTable20
*)bh
->b_data
;
1226 vat20
= (struct virtualAllocationTable20
*)
1230 map
->s_type_specific
.s_virtual
.s_start_offset
=
1231 le16_to_cpu(vat20
->lengthHeader
);
1232 map
->s_type_specific
.s_virtual
.s_num_entries
=
1233 (sbi
->s_vat_inode
->i_size
-
1234 map
->s_type_specific
.s_virtual
.
1235 s_start_offset
) >> 2;
1242 * Load partition descriptor block
1244 * Returns <0 on error, 0 on success, -EAGAIN is special - try next descriptor
1247 static int udf_load_partdesc(struct super_block
*sb
, sector_t block
)
1249 struct buffer_head
*bh
;
1250 struct partitionDesc
*p
;
1251 struct udf_part_map
*map
;
1252 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1254 uint16_t partitionNumber
;
1258 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1261 if (ident
!= TAG_IDENT_PD
) {
1266 p
= (struct partitionDesc
*)bh
->b_data
;
1267 partitionNumber
= le16_to_cpu(p
->partitionNumber
);
1269 /* First scan for TYPE1, SPARABLE and METADATA partitions */
1270 for (i
= 0; i
< sbi
->s_partitions
; i
++) {
1271 map
= &sbi
->s_partmaps
[i
];
1272 udf_debug("Searching map: (%d == %d)\n",
1273 map
->s_partition_num
, partitionNumber
);
1274 if (map
->s_partition_num
== partitionNumber
&&
1275 (map
->s_partition_type
== UDF_TYPE1_MAP15
||
1276 map
->s_partition_type
== UDF_SPARABLE_MAP15
))
1280 if (i
>= sbi
->s_partitions
) {
1281 udf_debug("Partition (%d) not found in partition map\n",
1287 ret
= udf_fill_partdesc_info(sb
, p
, i
);
1292 * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and
1293 * PHYSICAL partitions are already set up
1297 map
= NULL
; /* supress 'maybe used uninitialized' warning */
1299 for (i
= 0; i
< sbi
->s_partitions
; i
++) {
1300 map
= &sbi
->s_partmaps
[i
];
1302 if (map
->s_partition_num
== partitionNumber
&&
1303 (map
->s_partition_type
== UDF_VIRTUAL_MAP15
||
1304 map
->s_partition_type
== UDF_VIRTUAL_MAP20
||
1305 map
->s_partition_type
== UDF_METADATA_MAP25
))
1309 if (i
>= sbi
->s_partitions
) {
1314 ret
= udf_fill_partdesc_info(sb
, p
, i
);
1318 if (map
->s_partition_type
== UDF_METADATA_MAP25
) {
1319 ret
= udf_load_metadata_files(sb
, i
);
1321 udf_err(sb
, "error loading MetaData partition map %d\n",
1327 * If we have a partition with virtual map, we don't handle
1328 * writing to it (we overwrite blocks instead of relocating
1331 if (!(sb
->s_flags
& MS_RDONLY
)) {
1335 ret
= udf_load_vat(sb
, i
, type1_idx
);
1341 /* In case loading failed, we handle cleanup in udf_fill_super */
1346 static int udf_load_sparable_map(struct super_block
*sb
,
1347 struct udf_part_map
*map
,
1348 struct sparablePartitionMap
*spm
)
1352 struct sparingTable
*st
;
1353 struct udf_sparing_data
*sdata
= &map
->s_type_specific
.s_sparing
;
1355 struct buffer_head
*bh
;
1357 map
->s_partition_type
= UDF_SPARABLE_MAP15
;
1358 sdata
->s_packet_len
= le16_to_cpu(spm
->packetLength
);
1359 if (!is_power_of_2(sdata
->s_packet_len
)) {
1360 udf_err(sb
, "error loading logical volume descriptor: "
1361 "Invalid packet length %u\n",
1362 (unsigned)sdata
->s_packet_len
);
1365 if (spm
->numSparingTables
> 4) {
1366 udf_err(sb
, "error loading logical volume descriptor: "
1367 "Too many sparing tables (%d)\n",
1368 (int)spm
->numSparingTables
);
1372 for (i
= 0; i
< spm
->numSparingTables
; i
++) {
1373 loc
= le32_to_cpu(spm
->locSparingTable
[i
]);
1374 bh
= udf_read_tagged(sb
, loc
, loc
, &ident
);
1378 st
= (struct sparingTable
*)bh
->b_data
;
1380 strncmp(st
->sparingIdent
.ident
, UDF_ID_SPARING
,
1381 strlen(UDF_ID_SPARING
)) ||
1382 sizeof(*st
) + le16_to_cpu(st
->reallocationTableLen
) >
1388 sdata
->s_spar_map
[i
] = bh
;
1390 map
->s_partition_func
= udf_get_pblock_spar15
;
1394 static int udf_load_logicalvol(struct super_block
*sb
, sector_t block
,
1395 struct kernel_lb_addr
*fileset
)
1397 struct logicalVolDesc
*lvd
;
1400 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1401 struct genericPartitionMap
*gpm
;
1403 struct buffer_head
*bh
;
1404 unsigned int table_len
;
1407 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1410 BUG_ON(ident
!= TAG_IDENT_LVD
);
1411 lvd
= (struct logicalVolDesc
*)bh
->b_data
;
1412 table_len
= le32_to_cpu(lvd
->mapTableLength
);
1413 if (table_len
> sb
->s_blocksize
- sizeof(*lvd
)) {
1414 udf_err(sb
, "error loading logical volume descriptor: "
1415 "Partition table too long (%u > %lu)\n", table_len
,
1416 sb
->s_blocksize
- sizeof(*lvd
));
1421 ret
= udf_sb_alloc_partition_maps(sb
, le32_to_cpu(lvd
->numPartitionMaps
));
1425 for (i
= 0, offset
= 0;
1426 i
< sbi
->s_partitions
&& offset
< table_len
;
1427 i
++, offset
+= gpm
->partitionMapLength
) {
1428 struct udf_part_map
*map
= &sbi
->s_partmaps
[i
];
1429 gpm
= (struct genericPartitionMap
*)
1430 &(lvd
->partitionMaps
[offset
]);
1431 type
= gpm
->partitionMapType
;
1433 struct genericPartitionMap1
*gpm1
=
1434 (struct genericPartitionMap1
*)gpm
;
1435 map
->s_partition_type
= UDF_TYPE1_MAP15
;
1436 map
->s_volumeseqnum
= le16_to_cpu(gpm1
->volSeqNum
);
1437 map
->s_partition_num
= le16_to_cpu(gpm1
->partitionNum
);
1438 map
->s_partition_func
= NULL
;
1439 } else if (type
== 2) {
1440 struct udfPartitionMap2
*upm2
=
1441 (struct udfPartitionMap2
*)gpm
;
1442 if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_VIRTUAL
,
1443 strlen(UDF_ID_VIRTUAL
))) {
1445 le16_to_cpu(((__le16
*)upm2
->partIdent
.
1448 map
->s_partition_type
=
1450 map
->s_partition_func
=
1451 udf_get_pblock_virt15
;
1453 map
->s_partition_type
=
1455 map
->s_partition_func
=
1456 udf_get_pblock_virt20
;
1458 } else if (!strncmp(upm2
->partIdent
.ident
,
1460 strlen(UDF_ID_SPARABLE
))) {
1461 ret
= udf_load_sparable_map(sb
, map
,
1462 (struct sparablePartitionMap
*)gpm
);
1465 } else if (!strncmp(upm2
->partIdent
.ident
,
1467 strlen(UDF_ID_METADATA
))) {
1468 struct udf_meta_data
*mdata
=
1469 &map
->s_type_specific
.s_metadata
;
1470 struct metadataPartitionMap
*mdm
=
1471 (struct metadataPartitionMap
*)
1472 &(lvd
->partitionMaps
[offset
]);
1473 udf_debug("Parsing Logical vol part %d type %d id=%s\n",
1474 i
, type
, UDF_ID_METADATA
);
1476 map
->s_partition_type
= UDF_METADATA_MAP25
;
1477 map
->s_partition_func
= udf_get_pblock_meta25
;
1479 mdata
->s_meta_file_loc
=
1480 le32_to_cpu(mdm
->metadataFileLoc
);
1481 mdata
->s_mirror_file_loc
=
1482 le32_to_cpu(mdm
->metadataMirrorFileLoc
);
1483 mdata
->s_bitmap_file_loc
=
1484 le32_to_cpu(mdm
->metadataBitmapFileLoc
);
1485 mdata
->s_alloc_unit_size
=
1486 le32_to_cpu(mdm
->allocUnitSize
);
1487 mdata
->s_align_unit_size
=
1488 le16_to_cpu(mdm
->alignUnitSize
);
1489 if (mdm
->flags
& 0x01)
1490 mdata
->s_flags
|= MF_DUPLICATE_MD
;
1492 udf_debug("Metadata Ident suffix=0x%x\n",
1493 le16_to_cpu(*(__le16
*)
1494 mdm
->partIdent
.identSuffix
));
1495 udf_debug("Metadata part num=%d\n",
1496 le16_to_cpu(mdm
->partitionNum
));
1497 udf_debug("Metadata part alloc unit size=%d\n",
1498 le32_to_cpu(mdm
->allocUnitSize
));
1499 udf_debug("Metadata file loc=%d\n",
1500 le32_to_cpu(mdm
->metadataFileLoc
));
1501 udf_debug("Mirror file loc=%d\n",
1502 le32_to_cpu(mdm
->metadataMirrorFileLoc
));
1503 udf_debug("Bitmap file loc=%d\n",
1504 le32_to_cpu(mdm
->metadataBitmapFileLoc
));
1505 udf_debug("Flags: %d %d\n",
1506 mdata
->s_flags
, mdm
->flags
);
1508 udf_debug("Unknown ident: %s\n",
1509 upm2
->partIdent
.ident
);
1512 map
->s_volumeseqnum
= le16_to_cpu(upm2
->volSeqNum
);
1513 map
->s_partition_num
= le16_to_cpu(upm2
->partitionNum
);
1515 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1516 i
, map
->s_partition_num
, type
, map
->s_volumeseqnum
);
1520 struct long_ad
*la
= (struct long_ad
*)&(lvd
->logicalVolContentsUse
[0]);
1522 *fileset
= lelb_to_cpu(la
->extLocation
);
1523 udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
1524 fileset
->logicalBlockNum
,
1525 fileset
->partitionReferenceNum
);
1527 if (lvd
->integritySeqExt
.extLength
)
1528 udf_load_logicalvolint(sb
, leea_to_cpu(lvd
->integritySeqExt
));
1536 * udf_load_logicalvolint
1539 static void udf_load_logicalvolint(struct super_block
*sb
, struct kernel_extent_ad loc
)
1541 struct buffer_head
*bh
= NULL
;
1543 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1544 struct logicalVolIntegrityDesc
*lvid
;
1546 while (loc
.extLength
> 0 &&
1547 (bh
= udf_read_tagged(sb
, loc
.extLocation
,
1548 loc
.extLocation
, &ident
)) &&
1549 ident
== TAG_IDENT_LVID
) {
1550 sbi
->s_lvid_bh
= bh
;
1551 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1553 if (lvid
->nextIntegrityExt
.extLength
)
1554 udf_load_logicalvolint(sb
,
1555 leea_to_cpu(lvid
->nextIntegrityExt
));
1557 if (sbi
->s_lvid_bh
!= bh
)
1559 loc
.extLength
-= sb
->s_blocksize
;
1562 if (sbi
->s_lvid_bh
!= bh
)
1567 * Process a main/reserve volume descriptor sequence.
1568 * @block First block of first extent of the sequence.
1569 * @lastblock Lastblock of first extent of the sequence.
1570 * @fileset There we store extent containing root fileset
1572 * Returns <0 on error, 0 on success. -EAGAIN is special - try next descriptor
1575 static noinline
int udf_process_sequence(
1576 struct super_block
*sb
,
1577 sector_t block
, sector_t lastblock
,
1578 struct kernel_lb_addr
*fileset
)
1580 struct buffer_head
*bh
= NULL
;
1581 struct udf_vds_record vds
[VDS_POS_LENGTH
];
1582 struct udf_vds_record
*curr
;
1583 struct generic_desc
*gd
;
1584 struct volDescPtr
*vdp
;
1588 long next_s
= 0, next_e
= 0;
1591 memset(vds
, 0, sizeof(struct udf_vds_record
) * VDS_POS_LENGTH
);
1594 * Read the main descriptor sequence and find which descriptors
1597 for (; (!done
&& block
<= lastblock
); block
++) {
1599 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1602 "Block %llu of volume descriptor sequence is corrupted or we could not read it\n",
1603 (unsigned long long)block
);
1607 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1608 gd
= (struct generic_desc
*)bh
->b_data
;
1609 vdsn
= le32_to_cpu(gd
->volDescSeqNum
);
1611 case TAG_IDENT_PVD
: /* ISO 13346 3/10.1 */
1612 curr
= &vds
[VDS_POS_PRIMARY_VOL_DESC
];
1613 if (vdsn
>= curr
->volDescSeqNum
) {
1614 curr
->volDescSeqNum
= vdsn
;
1615 curr
->block
= block
;
1618 case TAG_IDENT_VDP
: /* ISO 13346 3/10.3 */
1619 curr
= &vds
[VDS_POS_VOL_DESC_PTR
];
1620 if (vdsn
>= curr
->volDescSeqNum
) {
1621 curr
->volDescSeqNum
= vdsn
;
1622 curr
->block
= block
;
1624 vdp
= (struct volDescPtr
*)bh
->b_data
;
1625 next_s
= le32_to_cpu(
1626 vdp
->nextVolDescSeqExt
.extLocation
);
1627 next_e
= le32_to_cpu(
1628 vdp
->nextVolDescSeqExt
.extLength
);
1629 next_e
= next_e
>> sb
->s_blocksize_bits
;
1633 case TAG_IDENT_IUVD
: /* ISO 13346 3/10.4 */
1634 curr
= &vds
[VDS_POS_IMP_USE_VOL_DESC
];
1635 if (vdsn
>= curr
->volDescSeqNum
) {
1636 curr
->volDescSeqNum
= vdsn
;
1637 curr
->block
= block
;
1640 case TAG_IDENT_PD
: /* ISO 13346 3/10.5 */
1641 curr
= &vds
[VDS_POS_PARTITION_DESC
];
1643 curr
->block
= block
;
1645 case TAG_IDENT_LVD
: /* ISO 13346 3/10.6 */
1646 curr
= &vds
[VDS_POS_LOGICAL_VOL_DESC
];
1647 if (vdsn
>= curr
->volDescSeqNum
) {
1648 curr
->volDescSeqNum
= vdsn
;
1649 curr
->block
= block
;
1652 case TAG_IDENT_USD
: /* ISO 13346 3/10.8 */
1653 curr
= &vds
[VDS_POS_UNALLOC_SPACE_DESC
];
1654 if (vdsn
>= curr
->volDescSeqNum
) {
1655 curr
->volDescSeqNum
= vdsn
;
1656 curr
->block
= block
;
1659 case TAG_IDENT_TD
: /* ISO 13346 3/10.9 */
1660 vds
[VDS_POS_TERMINATING_DESC
].block
= block
;
1664 next_s
= next_e
= 0;
1672 * Now read interesting descriptors again and process them
1673 * in a suitable order
1675 if (!vds
[VDS_POS_PRIMARY_VOL_DESC
].block
) {
1676 udf_err(sb
, "Primary Volume Descriptor not found!\n");
1679 ret
= udf_load_pvoldesc(sb
, vds
[VDS_POS_PRIMARY_VOL_DESC
].block
);
1683 if (vds
[VDS_POS_LOGICAL_VOL_DESC
].block
) {
1684 ret
= udf_load_logicalvol(sb
,
1685 vds
[VDS_POS_LOGICAL_VOL_DESC
].block
,
1691 if (vds
[VDS_POS_PARTITION_DESC
].block
) {
1693 * We rescan the whole descriptor sequence to find
1694 * partition descriptor blocks and process them.
1696 for (block
= vds
[VDS_POS_PARTITION_DESC
].block
;
1697 block
< vds
[VDS_POS_TERMINATING_DESC
].block
;
1699 ret
= udf_load_partdesc(sb
, block
);
1709 * Load Volume Descriptor Sequence described by anchor in bh
1711 * Returns <0 on error, 0 on success
1713 static int udf_load_sequence(struct super_block
*sb
, struct buffer_head
*bh
,
1714 struct kernel_lb_addr
*fileset
)
1716 struct anchorVolDescPtr
*anchor
;
1717 sector_t main_s
, main_e
, reserve_s
, reserve_e
;
1720 anchor
= (struct anchorVolDescPtr
*)bh
->b_data
;
1722 /* Locate the main sequence */
1723 main_s
= le32_to_cpu(anchor
->mainVolDescSeqExt
.extLocation
);
1724 main_e
= le32_to_cpu(anchor
->mainVolDescSeqExt
.extLength
);
1725 main_e
= main_e
>> sb
->s_blocksize_bits
;
1728 /* Locate the reserve sequence */
1729 reserve_s
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLocation
);
1730 reserve_e
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLength
);
1731 reserve_e
= reserve_e
>> sb
->s_blocksize_bits
;
1732 reserve_e
+= reserve_s
;
1734 /* Process the main & reserve sequences */
1735 /* responsible for finding the PartitionDesc(s) */
1736 ret
= udf_process_sequence(sb
, main_s
, main_e
, fileset
);
1739 udf_sb_free_partitions(sb
);
1740 ret
= udf_process_sequence(sb
, reserve_s
, reserve_e
, fileset
);
1742 udf_sb_free_partitions(sb
);
1743 /* No sequence was OK, return -EIO */
1751 * Check whether there is an anchor block in the given block and
1752 * load Volume Descriptor Sequence if so.
1754 * Returns <0 on error, 0 on success, -EAGAIN is special - try next anchor
1757 static int udf_check_anchor_block(struct super_block
*sb
, sector_t block
,
1758 struct kernel_lb_addr
*fileset
)
1760 struct buffer_head
*bh
;
1764 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_VARCONV
) &&
1765 udf_fixed_to_variable(block
) >=
1766 sb
->s_bdev
->bd_inode
->i_size
>> sb
->s_blocksize_bits
)
1769 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1772 if (ident
!= TAG_IDENT_AVDP
) {
1776 ret
= udf_load_sequence(sb
, bh
, fileset
);
1782 * Search for an anchor volume descriptor pointer.
1784 * Returns < 0 on error, 0 on success. -EAGAIN is special - try next set
1787 static int udf_scan_anchors(struct super_block
*sb
, sector_t
*lastblock
,
1788 struct kernel_lb_addr
*fileset
)
1792 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1796 /* First try user provided anchor */
1797 if (sbi
->s_anchor
) {
1798 ret
= udf_check_anchor_block(sb
, sbi
->s_anchor
, fileset
);
1803 * according to spec, anchor is in either:
1807 * however, if the disc isn't closed, it could be 512.
1809 ret
= udf_check_anchor_block(sb
, sbi
->s_session
+ 256, fileset
);
1813 * The trouble is which block is the last one. Drives often misreport
1814 * this so we try various possibilities.
1816 last
[last_count
++] = *lastblock
;
1817 if (*lastblock
>= 1)
1818 last
[last_count
++] = *lastblock
- 1;
1819 last
[last_count
++] = *lastblock
+ 1;
1820 if (*lastblock
>= 2)
1821 last
[last_count
++] = *lastblock
- 2;
1822 if (*lastblock
>= 150)
1823 last
[last_count
++] = *lastblock
- 150;
1824 if (*lastblock
>= 152)
1825 last
[last_count
++] = *lastblock
- 152;
1827 for (i
= 0; i
< last_count
; i
++) {
1828 if (last
[i
] >= sb
->s_bdev
->bd_inode
->i_size
>>
1829 sb
->s_blocksize_bits
)
1831 ret
= udf_check_anchor_block(sb
, last
[i
], fileset
);
1832 if (ret
!= -EAGAIN
) {
1834 *lastblock
= last
[i
];
1839 ret
= udf_check_anchor_block(sb
, last
[i
] - 256, fileset
);
1840 if (ret
!= -EAGAIN
) {
1842 *lastblock
= last
[i
];
1847 /* Finally try block 512 in case media is open */
1848 return udf_check_anchor_block(sb
, sbi
->s_session
+ 512, fileset
);
1852 * Find an anchor volume descriptor and load Volume Descriptor Sequence from
1853 * area specified by it. The function expects sbi->s_lastblock to be the last
1854 * block on the media.
1856 * Return <0 on error, 0 if anchor found. -EAGAIN is special meaning anchor
1859 static int udf_find_anchor(struct super_block
*sb
,
1860 struct kernel_lb_addr
*fileset
)
1862 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1863 sector_t lastblock
= sbi
->s_last_block
;
1866 ret
= udf_scan_anchors(sb
, &lastblock
, fileset
);
1870 /* No anchor found? Try VARCONV conversion of block numbers */
1871 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
1872 lastblock
= udf_variable_to_fixed(sbi
->s_last_block
);
1873 /* Firstly, we try to not convert number of the last block */
1874 ret
= udf_scan_anchors(sb
, &lastblock
, fileset
);
1878 lastblock
= sbi
->s_last_block
;
1879 /* Secondly, we try with converted number of the last block */
1880 ret
= udf_scan_anchors(sb
, &lastblock
, fileset
);
1882 /* VARCONV didn't help. Clear it. */
1883 UDF_CLEAR_FLAG(sb
, UDF_FLAG_VARCONV
);
1887 sbi
->s_last_block
= lastblock
;
1892 * Check Volume Structure Descriptor, find Anchor block and load Volume
1893 * Descriptor Sequence.
1895 * Returns < 0 on error, 0 on success. -EAGAIN is special meaning anchor
1896 * block was not found.
1898 static int udf_load_vrs(struct super_block
*sb
, struct udf_options
*uopt
,
1899 int silent
, struct kernel_lb_addr
*fileset
)
1901 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1905 if (!sb_set_blocksize(sb
, uopt
->blocksize
)) {
1907 udf_warn(sb
, "Bad block size\n");
1910 sbi
->s_last_block
= uopt
->lastblock
;
1912 /* Check that it is NSR02 compliant */
1913 nsr_off
= udf_check_vsd(sb
);
1916 udf_warn(sb
, "No VRS found\n");
1920 udf_debug("Failed to read sector at offset %d. "
1921 "Assuming open disc. Skipping validity "
1922 "check\n", VSD_FIRST_SECTOR_OFFSET
);
1923 if (!sbi
->s_last_block
)
1924 sbi
->s_last_block
= udf_get_last_block(sb
);
1926 udf_debug("Validity check skipped because of novrs option\n");
1929 /* Look for anchor block and load Volume Descriptor Sequence */
1930 sbi
->s_anchor
= uopt
->anchor
;
1931 ret
= udf_find_anchor(sb
, fileset
);
1933 if (!silent
&& ret
== -EAGAIN
)
1934 udf_warn(sb
, "No anchor found\n");
1940 static void udf_open_lvid(struct super_block
*sb
)
1942 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1943 struct buffer_head
*bh
= sbi
->s_lvid_bh
;
1944 struct logicalVolIntegrityDesc
*lvid
;
1945 struct logicalVolIntegrityDescImpUse
*lvidiu
;
1949 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1950 lvidiu
= udf_sb_lvidiu(sb
);
1954 mutex_lock(&sbi
->s_alloc_mutex
);
1955 lvidiu
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1956 lvidiu
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1957 udf_time_to_disk_stamp(&lvid
->recordingDateAndTime
,
1959 lvid
->integrityType
= cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN
);
1961 lvid
->descTag
.descCRC
= cpu_to_le16(
1962 crc_itu_t(0, (char *)lvid
+ sizeof(struct tag
),
1963 le16_to_cpu(lvid
->descTag
.descCRCLength
)));
1965 lvid
->descTag
.tagChecksum
= udf_tag_checksum(&lvid
->descTag
);
1966 mark_buffer_dirty(bh
);
1967 sbi
->s_lvid_dirty
= 0;
1968 mutex_unlock(&sbi
->s_alloc_mutex
);
1969 /* Make opening of filesystem visible on the media immediately */
1970 sync_dirty_buffer(bh
);
1973 static void udf_close_lvid(struct super_block
*sb
)
1975 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1976 struct buffer_head
*bh
= sbi
->s_lvid_bh
;
1977 struct logicalVolIntegrityDesc
*lvid
;
1978 struct logicalVolIntegrityDescImpUse
*lvidiu
;
1982 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1983 lvidiu
= udf_sb_lvidiu(sb
);
1987 mutex_lock(&sbi
->s_alloc_mutex
);
1988 lvidiu
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1989 lvidiu
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1990 udf_time_to_disk_stamp(&lvid
->recordingDateAndTime
, CURRENT_TIME
);
1991 if (UDF_MAX_WRITE_VERSION
> le16_to_cpu(lvidiu
->maxUDFWriteRev
))
1992 lvidiu
->maxUDFWriteRev
= cpu_to_le16(UDF_MAX_WRITE_VERSION
);
1993 if (sbi
->s_udfrev
> le16_to_cpu(lvidiu
->minUDFReadRev
))
1994 lvidiu
->minUDFReadRev
= cpu_to_le16(sbi
->s_udfrev
);
1995 if (sbi
->s_udfrev
> le16_to_cpu(lvidiu
->minUDFWriteRev
))
1996 lvidiu
->minUDFWriteRev
= cpu_to_le16(sbi
->s_udfrev
);
1997 lvid
->integrityType
= cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE
);
1999 lvid
->descTag
.descCRC
= cpu_to_le16(
2000 crc_itu_t(0, (char *)lvid
+ sizeof(struct tag
),
2001 le16_to_cpu(lvid
->descTag
.descCRCLength
)));
2003 lvid
->descTag
.tagChecksum
= udf_tag_checksum(&lvid
->descTag
);
2005 * We set buffer uptodate unconditionally here to avoid spurious
2006 * warnings from mark_buffer_dirty() when previous EIO has marked
2007 * the buffer as !uptodate
2009 set_buffer_uptodate(bh
);
2010 mark_buffer_dirty(bh
);
2011 sbi
->s_lvid_dirty
= 0;
2012 mutex_unlock(&sbi
->s_alloc_mutex
);
2013 /* Make closing of filesystem visible on the media immediately */
2014 sync_dirty_buffer(bh
);
2017 u64
lvid_get_unique_id(struct super_block
*sb
)
2019 struct buffer_head
*bh
;
2020 struct udf_sb_info
*sbi
= UDF_SB(sb
);
2021 struct logicalVolIntegrityDesc
*lvid
;
2022 struct logicalVolHeaderDesc
*lvhd
;
2026 bh
= sbi
->s_lvid_bh
;
2030 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
2031 lvhd
= (struct logicalVolHeaderDesc
*)lvid
->logicalVolContentsUse
;
2033 mutex_lock(&sbi
->s_alloc_mutex
);
2034 ret
= uniqueID
= le64_to_cpu(lvhd
->uniqueID
);
2035 if (!(++uniqueID
& 0xFFFFFFFF))
2037 lvhd
->uniqueID
= cpu_to_le64(uniqueID
);
2038 mutex_unlock(&sbi
->s_alloc_mutex
);
2039 mark_buffer_dirty(bh
);
2044 static int udf_fill_super(struct super_block
*sb
, void *options
, int silent
)
2047 struct inode
*inode
= NULL
;
2048 struct udf_options uopt
;
2049 struct kernel_lb_addr rootdir
, fileset
;
2050 struct udf_sb_info
*sbi
;
2052 uopt
.flags
= (1 << UDF_FLAG_USE_AD_IN_ICB
) | (1 << UDF_FLAG_STRICT
);
2053 uopt
.uid
= INVALID_UID
;
2054 uopt
.gid
= INVALID_GID
;
2056 uopt
.fmode
= UDF_INVALID_MODE
;
2057 uopt
.dmode
= UDF_INVALID_MODE
;
2059 sbi
= kzalloc(sizeof(struct udf_sb_info
), GFP_KERNEL
);
2063 sb
->s_fs_info
= sbi
;
2065 mutex_init(&sbi
->s_alloc_mutex
);
2067 if (!udf_parse_options((char *)options
, &uopt
, false))
2070 if (uopt
.flags
& (1 << UDF_FLAG_UTF8
) &&
2071 uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) {
2072 udf_err(sb
, "utf8 cannot be combined with iocharset\n");
2075 #ifdef CONFIG_UDF_NLS
2076 if ((uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) && !uopt
.nls_map
) {
2077 uopt
.nls_map
= load_nls_default();
2079 uopt
.flags
&= ~(1 << UDF_FLAG_NLS_MAP
);
2081 udf_debug("Using default NLS map\n");
2084 if (!(uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)))
2085 uopt
.flags
|= (1 << UDF_FLAG_UTF8
);
2087 fileset
.logicalBlockNum
= 0xFFFFFFFF;
2088 fileset
.partitionReferenceNum
= 0xFFFF;
2090 sbi
->s_flags
= uopt
.flags
;
2091 sbi
->s_uid
= uopt
.uid
;
2092 sbi
->s_gid
= uopt
.gid
;
2093 sbi
->s_umask
= uopt
.umask
;
2094 sbi
->s_fmode
= uopt
.fmode
;
2095 sbi
->s_dmode
= uopt
.dmode
;
2096 sbi
->s_nls_map
= uopt
.nls_map
;
2097 rwlock_init(&sbi
->s_cred_lock
);
2099 if (uopt
.session
== 0xFFFFFFFF)
2100 sbi
->s_session
= udf_get_last_session(sb
);
2102 sbi
->s_session
= uopt
.session
;
2104 udf_debug("Multi-session=%d\n", sbi
->s_session
);
2106 /* Fill in the rest of the superblock */
2107 sb
->s_op
= &udf_sb_ops
;
2108 sb
->s_export_op
= &udf_export_ops
;
2110 sb
->s_magic
= UDF_SUPER_MAGIC
;
2111 sb
->s_time_gran
= 1000;
2113 if (uopt
.flags
& (1 << UDF_FLAG_BLOCKSIZE_SET
)) {
2114 ret
= udf_load_vrs(sb
, &uopt
, silent
, &fileset
);
2116 uopt
.blocksize
= bdev_logical_block_size(sb
->s_bdev
);
2117 ret
= udf_load_vrs(sb
, &uopt
, silent
, &fileset
);
2118 if (ret
== -EAGAIN
&& uopt
.blocksize
!= UDF_DEFAULT_BLOCKSIZE
) {
2120 pr_notice("Rescanning with blocksize %d\n",
2121 UDF_DEFAULT_BLOCKSIZE
);
2122 brelse(sbi
->s_lvid_bh
);
2123 sbi
->s_lvid_bh
= NULL
;
2124 uopt
.blocksize
= UDF_DEFAULT_BLOCKSIZE
;
2125 ret
= udf_load_vrs(sb
, &uopt
, silent
, &fileset
);
2129 if (ret
== -EAGAIN
) {
2130 udf_warn(sb
, "No partition found (1)\n");
2136 udf_debug("Lastblock=%d\n", sbi
->s_last_block
);
2138 if (sbi
->s_lvid_bh
) {
2139 struct logicalVolIntegrityDescImpUse
*lvidiu
=
2141 uint16_t minUDFReadRev
;
2142 uint16_t minUDFWriteRev
;
2148 minUDFReadRev
= le16_to_cpu(lvidiu
->minUDFReadRev
);
2149 minUDFWriteRev
= le16_to_cpu(lvidiu
->minUDFWriteRev
);
2150 if (minUDFReadRev
> UDF_MAX_READ_VERSION
) {
2151 udf_err(sb
, "minUDFReadRev=%x (max is %x)\n",
2153 UDF_MAX_READ_VERSION
);
2156 } else if (minUDFWriteRev
> UDF_MAX_WRITE_VERSION
&&
2157 !(sb
->s_flags
& MS_RDONLY
)) {
2162 sbi
->s_udfrev
= minUDFWriteRev
;
2164 if (minUDFReadRev
>= UDF_VERS_USE_EXTENDED_FE
)
2165 UDF_SET_FLAG(sb
, UDF_FLAG_USE_EXTENDED_FE
);
2166 if (minUDFReadRev
>= UDF_VERS_USE_STREAMS
)
2167 UDF_SET_FLAG(sb
, UDF_FLAG_USE_STREAMS
);
2170 if (!sbi
->s_partitions
) {
2171 udf_warn(sb
, "No partition found (2)\n");
2176 if (sbi
->s_partmaps
[sbi
->s_partition
].s_partition_flags
&
2177 UDF_PART_FLAG_READ_ONLY
&&
2178 !(sb
->s_flags
& MS_RDONLY
)) {
2183 if (udf_find_fileset(sb
, &fileset
, &rootdir
)) {
2184 udf_warn(sb
, "No fileset found\n");
2190 struct timestamp ts
;
2191 udf_time_to_disk_stamp(&ts
, sbi
->s_record_time
);
2192 udf_info("Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
2193 sbi
->s_volume_ident
,
2194 le16_to_cpu(ts
.year
), ts
.month
, ts
.day
,
2195 ts
.hour
, ts
.minute
, le16_to_cpu(ts
.typeAndTimezone
));
2197 if (!(sb
->s_flags
& MS_RDONLY
))
2200 /* Assign the root inode */
2201 /* assign inodes by physical block number */
2202 /* perhaps it's not extensible enough, but for now ... */
2203 inode
= udf_iget(sb
, &rootdir
);
2205 udf_err(sb
, "Error in udf_iget, block=%d, partition=%d\n",
2206 rootdir
.logicalBlockNum
, rootdir
.partitionReferenceNum
);
2211 /* Allocate a dentry for the root inode */
2212 sb
->s_root
= d_make_root(inode
);
2214 udf_err(sb
, "Couldn't allocate root dentry\n");
2218 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
2219 sb
->s_max_links
= UDF_MAX_LINKS
;
2223 if (sbi
->s_vat_inode
)
2224 iput(sbi
->s_vat_inode
);
2225 #ifdef CONFIG_UDF_NLS
2226 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
2227 unload_nls(sbi
->s_nls_map
);
2229 if (!(sb
->s_flags
& MS_RDONLY
))
2231 brelse(sbi
->s_lvid_bh
);
2232 udf_sb_free_partitions(sb
);
2234 sb
->s_fs_info
= NULL
;
2239 void _udf_err(struct super_block
*sb
, const char *function
,
2240 const char *fmt
, ...)
2242 struct va_format vaf
;
2245 va_start(args
, fmt
);
2250 pr_err("error (device %s): %s: %pV", sb
->s_id
, function
, &vaf
);
2255 void _udf_warn(struct super_block
*sb
, const char *function
,
2256 const char *fmt
, ...)
2258 struct va_format vaf
;
2261 va_start(args
, fmt
);
2266 pr_warn("warning (device %s): %s: %pV", sb
->s_id
, function
, &vaf
);
2271 static void udf_put_super(struct super_block
*sb
)
2273 struct udf_sb_info
*sbi
;
2277 if (sbi
->s_vat_inode
)
2278 iput(sbi
->s_vat_inode
);
2279 #ifdef CONFIG_UDF_NLS
2280 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
2281 unload_nls(sbi
->s_nls_map
);
2283 if (!(sb
->s_flags
& MS_RDONLY
))
2285 brelse(sbi
->s_lvid_bh
);
2286 udf_sb_free_partitions(sb
);
2287 kfree(sb
->s_fs_info
);
2288 sb
->s_fs_info
= NULL
;
2291 static int udf_sync_fs(struct super_block
*sb
, int wait
)
2293 struct udf_sb_info
*sbi
= UDF_SB(sb
);
2295 mutex_lock(&sbi
->s_alloc_mutex
);
2296 if (sbi
->s_lvid_dirty
) {
2298 * Blockdevice will be synced later so we don't have to submit
2301 mark_buffer_dirty(sbi
->s_lvid_bh
);
2302 sbi
->s_lvid_dirty
= 0;
2304 mutex_unlock(&sbi
->s_alloc_mutex
);
2309 static int udf_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
2311 struct super_block
*sb
= dentry
->d_sb
;
2312 struct udf_sb_info
*sbi
= UDF_SB(sb
);
2313 struct logicalVolIntegrityDescImpUse
*lvidiu
;
2314 u64 id
= huge_encode_dev(sb
->s_bdev
->bd_dev
);
2316 lvidiu
= udf_sb_lvidiu(sb
);
2317 buf
->f_type
= UDF_SUPER_MAGIC
;
2318 buf
->f_bsize
= sb
->s_blocksize
;
2319 buf
->f_blocks
= sbi
->s_partmaps
[sbi
->s_partition
].s_partition_len
;
2320 buf
->f_bfree
= udf_count_free(sb
);
2321 buf
->f_bavail
= buf
->f_bfree
;
2322 buf
->f_files
= (lvidiu
!= NULL
? (le32_to_cpu(lvidiu
->numFiles
) +
2323 le32_to_cpu(lvidiu
->numDirs
)) : 0)
2325 buf
->f_ffree
= buf
->f_bfree
;
2326 buf
->f_namelen
= UDF_NAME_LEN
- 2;
2327 buf
->f_fsid
.val
[0] = (u32
)id
;
2328 buf
->f_fsid
.val
[1] = (u32
)(id
>> 32);
2333 static unsigned int udf_count_free_bitmap(struct super_block
*sb
,
2334 struct udf_bitmap
*bitmap
)
2336 struct buffer_head
*bh
= NULL
;
2337 unsigned int accum
= 0;
2339 int block
= 0, newblock
;
2340 struct kernel_lb_addr loc
;
2344 struct spaceBitmapDesc
*bm
;
2346 loc
.logicalBlockNum
= bitmap
->s_extPosition
;
2347 loc
.partitionReferenceNum
= UDF_SB(sb
)->s_partition
;
2348 bh
= udf_read_ptagged(sb
, &loc
, 0, &ident
);
2351 udf_err(sb
, "udf_count_free failed\n");
2353 } else if (ident
!= TAG_IDENT_SBD
) {
2355 udf_err(sb
, "udf_count_free failed\n");
2359 bm
= (struct spaceBitmapDesc
*)bh
->b_data
;
2360 bytes
= le32_to_cpu(bm
->numOfBytes
);
2361 index
= sizeof(struct spaceBitmapDesc
); /* offset in first block only */
2362 ptr
= (uint8_t *)bh
->b_data
;
2365 u32 cur_bytes
= min_t(u32
, bytes
, sb
->s_blocksize
- index
);
2366 accum
+= bitmap_weight((const unsigned long *)(ptr
+ index
),
2371 newblock
= udf_get_lb_pblock(sb
, &loc
, ++block
);
2372 bh
= udf_tread(sb
, newblock
);
2374 udf_debug("read failed\n");
2378 ptr
= (uint8_t *)bh
->b_data
;
2386 static unsigned int udf_count_free_table(struct super_block
*sb
,
2387 struct inode
*table
)
2389 unsigned int accum
= 0;
2391 struct kernel_lb_addr eloc
;
2393 struct extent_position epos
;
2395 mutex_lock(&UDF_SB(sb
)->s_alloc_mutex
);
2396 epos
.block
= UDF_I(table
)->i_location
;
2397 epos
.offset
= sizeof(struct unallocSpaceEntry
);
2400 while ((etype
= udf_next_aext(table
, &epos
, &eloc
, &elen
, 1)) != -1)
2401 accum
+= (elen
>> table
->i_sb
->s_blocksize_bits
);
2404 mutex_unlock(&UDF_SB(sb
)->s_alloc_mutex
);
2409 static unsigned int udf_count_free(struct super_block
*sb
)
2411 unsigned int accum
= 0;
2412 struct udf_sb_info
*sbi
;
2413 struct udf_part_map
*map
;
2416 if (sbi
->s_lvid_bh
) {
2417 struct logicalVolIntegrityDesc
*lvid
=
2418 (struct logicalVolIntegrityDesc
*)
2419 sbi
->s_lvid_bh
->b_data
;
2420 if (le32_to_cpu(lvid
->numOfPartitions
) > sbi
->s_partition
) {
2421 accum
= le32_to_cpu(
2422 lvid
->freeSpaceTable
[sbi
->s_partition
]);
2423 if (accum
== 0xFFFFFFFF)
2431 map
= &sbi
->s_partmaps
[sbi
->s_partition
];
2432 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
) {
2433 accum
+= udf_count_free_bitmap(sb
,
2434 map
->s_uspace
.s_bitmap
);
2436 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
) {
2437 accum
+= udf_count_free_bitmap(sb
,
2438 map
->s_fspace
.s_bitmap
);
2443 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
) {
2444 accum
+= udf_count_free_table(sb
,
2445 map
->s_uspace
.s_table
);
2447 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
) {
2448 accum
+= udf_count_free_table(sb
,
2449 map
->s_fspace
.s_table
);