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 <linux/bitmap.h>
59 #include <linux/crc-itu-t.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 static char error_buf
[1024];
81 /* These are the "meat" - everything else is stuffing */
82 static int udf_fill_super(struct super_block
*, void *, int);
83 static void udf_put_super(struct super_block
*);
84 static void udf_write_super(struct super_block
*);
85 static int udf_remount_fs(struct super_block
*, int *, char *);
86 static void udf_load_logicalvolint(struct super_block
*, struct kernel_extent_ad
);
87 static int udf_find_fileset(struct super_block
*, struct kernel_lb_addr
*,
88 struct kernel_lb_addr
*);
89 static void udf_load_fileset(struct super_block
*, struct buffer_head
*,
90 struct kernel_lb_addr
*);
91 static void udf_open_lvid(struct super_block
*);
92 static void udf_close_lvid(struct super_block
*);
93 static unsigned int udf_count_free(struct super_block
*);
94 static int udf_statfs(struct dentry
*, struct kstatfs
*);
95 static int udf_show_options(struct seq_file
*, struct vfsmount
*);
96 static void udf_error(struct super_block
*sb
, const char *function
,
97 const char *fmt
, ...);
99 struct logicalVolIntegrityDescImpUse
*udf_sb_lvidiu(struct udf_sb_info
*sbi
)
101 struct logicalVolIntegrityDesc
*lvid
=
102 (struct logicalVolIntegrityDesc
*)sbi
->s_lvid_bh
->b_data
;
103 __u32 number_of_partitions
= le32_to_cpu(lvid
->numOfPartitions
);
104 __u32 offset
= number_of_partitions
* 2 *
105 sizeof(uint32_t)/sizeof(uint8_t);
106 return (struct logicalVolIntegrityDescImpUse
*)&(lvid
->impUse
[offset
]);
109 /* UDF filesystem type */
110 static int udf_get_sb(struct file_system_type
*fs_type
,
111 int flags
, const char *dev_name
, void *data
,
112 struct vfsmount
*mnt
)
114 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, udf_fill_super
, mnt
);
117 static struct file_system_type udf_fstype
= {
118 .owner
= THIS_MODULE
,
120 .get_sb
= udf_get_sb
,
121 .kill_sb
= kill_block_super
,
122 .fs_flags
= FS_REQUIRES_DEV
,
125 static struct kmem_cache
*udf_inode_cachep
;
127 static struct inode
*udf_alloc_inode(struct super_block
*sb
)
129 struct udf_inode_info
*ei
;
130 ei
= kmem_cache_alloc(udf_inode_cachep
, GFP_KERNEL
);
135 ei
->i_lenExtents
= 0;
136 ei
->i_next_alloc_block
= 0;
137 ei
->i_next_alloc_goal
= 0;
140 return &ei
->vfs_inode
;
143 static void udf_destroy_inode(struct inode
*inode
)
145 kmem_cache_free(udf_inode_cachep
, UDF_I(inode
));
148 static void init_once(void *foo
)
150 struct udf_inode_info
*ei
= (struct udf_inode_info
*)foo
;
152 ei
->i_ext
.i_data
= NULL
;
153 inode_init_once(&ei
->vfs_inode
);
156 static int init_inodecache(void)
158 udf_inode_cachep
= kmem_cache_create("udf_inode_cache",
159 sizeof(struct udf_inode_info
),
160 0, (SLAB_RECLAIM_ACCOUNT
|
163 if (!udf_inode_cachep
)
168 static void destroy_inodecache(void)
170 kmem_cache_destroy(udf_inode_cachep
);
173 /* Superblock operations */
174 static const struct super_operations udf_sb_ops
= {
175 .alloc_inode
= udf_alloc_inode
,
176 .destroy_inode
= udf_destroy_inode
,
177 .write_inode
= udf_write_inode
,
178 .delete_inode
= udf_delete_inode
,
179 .clear_inode
= udf_clear_inode
,
180 .put_super
= udf_put_super
,
181 .write_super
= udf_write_super
,
182 .statfs
= udf_statfs
,
183 .remount_fs
= udf_remount_fs
,
184 .show_options
= udf_show_options
,
189 unsigned int blocksize
;
190 unsigned int session
;
191 unsigned int lastblock
;
194 unsigned short partition
;
195 unsigned int fileset
;
196 unsigned int rootdir
;
203 struct nls_table
*nls_map
;
206 static int __init
init_udf_fs(void)
210 err
= init_inodecache();
213 err
= register_filesystem(&udf_fstype
);
220 destroy_inodecache();
226 static void __exit
exit_udf_fs(void)
228 unregister_filesystem(&udf_fstype
);
229 destroy_inodecache();
232 module_init(init_udf_fs
)
233 module_exit(exit_udf_fs
)
235 static int udf_sb_alloc_partition_maps(struct super_block
*sb
, u32 count
)
237 struct udf_sb_info
*sbi
= UDF_SB(sb
);
239 sbi
->s_partmaps
= kcalloc(count
, sizeof(struct udf_part_map
),
241 if (!sbi
->s_partmaps
) {
242 udf_error(sb
, __func__
,
243 "Unable to allocate space for %d partition maps",
245 sbi
->s_partitions
= 0;
249 sbi
->s_partitions
= count
;
253 static int udf_show_options(struct seq_file
*seq
, struct vfsmount
*mnt
)
255 struct super_block
*sb
= mnt
->mnt_sb
;
256 struct udf_sb_info
*sbi
= UDF_SB(sb
);
258 if (!UDF_QUERY_FLAG(sb
, UDF_FLAG_STRICT
))
259 seq_puts(seq
, ",nostrict");
260 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_BLOCKSIZE_SET
))
261 seq_printf(seq
, ",bs=%lu", sb
->s_blocksize
);
262 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UNHIDE
))
263 seq_puts(seq
, ",unhide");
264 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UNDELETE
))
265 seq_puts(seq
, ",undelete");
266 if (!UDF_QUERY_FLAG(sb
, UDF_FLAG_USE_AD_IN_ICB
))
267 seq_puts(seq
, ",noadinicb");
268 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_USE_SHORT_AD
))
269 seq_puts(seq
, ",shortad");
270 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_FORGET
))
271 seq_puts(seq
, ",uid=forget");
272 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_IGNORE
))
273 seq_puts(seq
, ",uid=ignore");
274 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_FORGET
))
275 seq_puts(seq
, ",gid=forget");
276 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_IGNORE
))
277 seq_puts(seq
, ",gid=ignore");
278 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_SET
))
279 seq_printf(seq
, ",uid=%u", sbi
->s_uid
);
280 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_SET
))
281 seq_printf(seq
, ",gid=%u", sbi
->s_gid
);
282 if (sbi
->s_umask
!= 0)
283 seq_printf(seq
, ",umask=%o", sbi
->s_umask
);
284 if (sbi
->s_fmode
!= UDF_INVALID_MODE
)
285 seq_printf(seq
, ",mode=%o", sbi
->s_fmode
);
286 if (sbi
->s_dmode
!= UDF_INVALID_MODE
)
287 seq_printf(seq
, ",dmode=%o", sbi
->s_dmode
);
288 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_SESSION_SET
))
289 seq_printf(seq
, ",session=%u", sbi
->s_session
);
290 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_LASTBLOCK_SET
))
291 seq_printf(seq
, ",lastblock=%u", sbi
->s_last_block
);
292 if (sbi
->s_anchor
!= 0)
293 seq_printf(seq
, ",anchor=%u", sbi
->s_anchor
);
295 * volume, partition, fileset and rootdir seem to be ignored
298 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UTF8
))
299 seq_puts(seq
, ",utf8");
300 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
) && sbi
->s_nls_map
)
301 seq_printf(seq
, ",iocharset=%s", sbi
->s_nls_map
->charset
);
310 * Parse mount options.
313 * The following mount options are supported:
315 * gid= Set the default group.
316 * umask= Set the default umask.
317 * mode= Set the default file permissions.
318 * dmode= Set the default directory permissions.
319 * uid= Set the default user.
320 * bs= Set the block size.
321 * unhide Show otherwise hidden files.
322 * undelete Show deleted files in lists.
323 * adinicb Embed data in the inode (default)
324 * noadinicb Don't embed data in the inode
325 * shortad Use short ad's
326 * longad Use long ad's (default)
327 * nostrict Unset strict conformance
328 * iocharset= Set the NLS character set
330 * The remaining are for debugging and disaster recovery:
332 * novrs Skip volume sequence recognition
334 * The following expect a offset from 0.
336 * session= Set the CDROM session (default= last session)
337 * anchor= Override standard anchor location. (default= 256)
338 * volume= Override the VolumeDesc location. (unused)
339 * partition= Override the PartitionDesc location. (unused)
340 * lastblock= Set the last block of the filesystem/
342 * The following expect a offset from the partition root.
344 * fileset= Override the fileset block location. (unused)
345 * rootdir= Override the root directory location. (unused)
346 * WARNING: overriding the rootdir to a non-directory may
347 * yield highly unpredictable results.
350 * options Pointer to mount options string.
351 * uopts Pointer to mount options variable.
354 * <return> 1 Mount options parsed okay.
355 * <return> 0 Error parsing mount options.
358 * July 1, 1997 - Andrew E. Mileski
359 * Written, tested, and released.
363 Opt_novrs
, Opt_nostrict
, Opt_bs
, Opt_unhide
, Opt_undelete
,
364 Opt_noadinicb
, Opt_adinicb
, Opt_shortad
, Opt_longad
,
365 Opt_gid
, Opt_uid
, Opt_umask
, Opt_session
, Opt_lastblock
,
366 Opt_anchor
, Opt_volume
, Opt_partition
, Opt_fileset
,
367 Opt_rootdir
, Opt_utf8
, Opt_iocharset
,
368 Opt_err
, Opt_uforget
, Opt_uignore
, Opt_gforget
, Opt_gignore
,
372 static const match_table_t tokens
= {
373 {Opt_novrs
, "novrs"},
374 {Opt_nostrict
, "nostrict"},
376 {Opt_unhide
, "unhide"},
377 {Opt_undelete
, "undelete"},
378 {Opt_noadinicb
, "noadinicb"},
379 {Opt_adinicb
, "adinicb"},
380 {Opt_shortad
, "shortad"},
381 {Opt_longad
, "longad"},
382 {Opt_uforget
, "uid=forget"},
383 {Opt_uignore
, "uid=ignore"},
384 {Opt_gforget
, "gid=forget"},
385 {Opt_gignore
, "gid=ignore"},
388 {Opt_umask
, "umask=%o"},
389 {Opt_session
, "session=%u"},
390 {Opt_lastblock
, "lastblock=%u"},
391 {Opt_anchor
, "anchor=%u"},
392 {Opt_volume
, "volume=%u"},
393 {Opt_partition
, "partition=%u"},
394 {Opt_fileset
, "fileset=%u"},
395 {Opt_rootdir
, "rootdir=%u"},
397 {Opt_iocharset
, "iocharset=%s"},
398 {Opt_fmode
, "mode=%o"},
399 {Opt_dmode
, "dmode=%o"},
403 static int udf_parse_options(char *options
, struct udf_options
*uopt
,
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
);
434 if (match_int(&args
[0], &option
))
436 uopt
->blocksize
= option
;
437 uopt
->flags
|= (1 << UDF_FLAG_BLOCKSIZE_SET
);
440 uopt
->flags
|= (1 << UDF_FLAG_UNHIDE
);
443 uopt
->flags
|= (1 << UDF_FLAG_UNDELETE
);
446 uopt
->flags
&= ~(1 << UDF_FLAG_USE_AD_IN_ICB
);
449 uopt
->flags
|= (1 << UDF_FLAG_USE_AD_IN_ICB
);
452 uopt
->flags
|= (1 << UDF_FLAG_USE_SHORT_AD
);
455 uopt
->flags
&= ~(1 << UDF_FLAG_USE_SHORT_AD
);
458 if (match_int(args
, &option
))
461 uopt
->flags
|= (1 << UDF_FLAG_GID_SET
);
464 if (match_int(args
, &option
))
467 uopt
->flags
|= (1 << UDF_FLAG_UID_SET
);
470 if (match_octal(args
, &option
))
472 uopt
->umask
= option
;
475 uopt
->flags
&= ~(1 << UDF_FLAG_STRICT
);
478 if (match_int(args
, &option
))
480 uopt
->session
= option
;
482 uopt
->flags
|= (1 << UDF_FLAG_SESSION_SET
);
485 if (match_int(args
, &option
))
487 uopt
->lastblock
= option
;
489 uopt
->flags
|= (1 << UDF_FLAG_LASTBLOCK_SET
);
492 if (match_int(args
, &option
))
494 uopt
->anchor
= option
;
497 if (match_int(args
, &option
))
499 uopt
->volume
= option
;
502 if (match_int(args
, &option
))
504 uopt
->partition
= option
;
507 if (match_int(args
, &option
))
509 uopt
->fileset
= option
;
512 if (match_int(args
, &option
))
514 uopt
->rootdir
= option
;
517 uopt
->flags
|= (1 << UDF_FLAG_UTF8
);
519 #ifdef CONFIG_UDF_NLS
521 uopt
->nls_map
= load_nls(args
[0].from
);
522 uopt
->flags
|= (1 << UDF_FLAG_NLS_MAP
);
526 uopt
->flags
|= (1 << UDF_FLAG_UID_IGNORE
);
529 uopt
->flags
|= (1 << UDF_FLAG_UID_FORGET
);
532 uopt
->flags
|= (1 << UDF_FLAG_GID_IGNORE
);
535 uopt
->flags
|= (1 << UDF_FLAG_GID_FORGET
);
538 if (match_octal(args
, &option
))
540 uopt
->fmode
= option
& 0777;
543 if (match_octal(args
, &option
))
545 uopt
->dmode
= option
& 0777;
548 printk(KERN_ERR
"udf: bad mount option \"%s\" "
549 "or missing value\n", p
);
556 static void udf_write_super(struct super_block
*sb
)
560 if (!(sb
->s_flags
& MS_RDONLY
))
567 static int udf_remount_fs(struct super_block
*sb
, int *flags
, char *options
)
569 struct udf_options uopt
;
570 struct udf_sb_info
*sbi
= UDF_SB(sb
);
572 uopt
.flags
= sbi
->s_flags
;
573 uopt
.uid
= sbi
->s_uid
;
574 uopt
.gid
= sbi
->s_gid
;
575 uopt
.umask
= sbi
->s_umask
;
576 uopt
.fmode
= sbi
->s_fmode
;
577 uopt
.dmode
= sbi
->s_dmode
;
579 if (!udf_parse_options(options
, &uopt
, true))
582 sbi
->s_flags
= uopt
.flags
;
583 sbi
->s_uid
= uopt
.uid
;
584 sbi
->s_gid
= uopt
.gid
;
585 sbi
->s_umask
= uopt
.umask
;
586 sbi
->s_fmode
= uopt
.fmode
;
587 sbi
->s_dmode
= uopt
.dmode
;
589 if (sbi
->s_lvid_bh
) {
590 int write_rev
= le16_to_cpu(udf_sb_lvidiu(sbi
)->minUDFWriteRev
);
591 if (write_rev
> UDF_MAX_WRITE_VERSION
)
595 if ((*flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
))
597 if (*flags
& MS_RDONLY
)
605 /* Check Volume Structure Descriptors (ECMA 167 2/9.1) */
606 /* We also check any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
607 static loff_t
udf_check_vsd(struct super_block
*sb
)
609 struct volStructDesc
*vsd
= NULL
;
610 loff_t sector
= 32768;
612 struct buffer_head
*bh
= NULL
;
615 struct udf_sb_info
*sbi
;
618 if (sb
->s_blocksize
< sizeof(struct volStructDesc
))
619 sectorsize
= sizeof(struct volStructDesc
);
621 sectorsize
= sb
->s_blocksize
;
623 sector
+= (sbi
->s_session
<< sb
->s_blocksize_bits
);
625 udf_debug("Starting at sector %u (%ld byte sectors)\n",
626 (unsigned int)(sector
>> sb
->s_blocksize_bits
),
628 /* Process the sequence (if applicable) */
629 for (; !nsr02
&& !nsr03
; sector
+= sectorsize
) {
631 bh
= udf_tread(sb
, sector
>> sb
->s_blocksize_bits
);
635 /* Look for ISO descriptors */
636 vsd
= (struct volStructDesc
*)(bh
->b_data
+
637 (sector
& (sb
->s_blocksize
- 1)));
639 if (vsd
->stdIdent
[0] == 0) {
642 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_CD001
,
644 switch (vsd
->structType
) {
646 udf_debug("ISO9660 Boot Record found\n");
649 udf_debug("ISO9660 Primary Volume Descriptor "
653 udf_debug("ISO9660 Supplementary Volume "
654 "Descriptor found\n");
657 udf_debug("ISO9660 Volume Partition Descriptor "
661 udf_debug("ISO9660 Volume Descriptor Set "
662 "Terminator found\n");
665 udf_debug("ISO9660 VRS (%u) found\n",
669 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_BEA01
,
672 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_TEA01
,
676 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR02
,
679 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR03
,
689 else if (sector
- (sbi
->s_session
<< sb
->s_blocksize_bits
) == 32768)
695 static int udf_find_fileset(struct super_block
*sb
,
696 struct kernel_lb_addr
*fileset
,
697 struct kernel_lb_addr
*root
)
699 struct buffer_head
*bh
= NULL
;
702 struct udf_sb_info
*sbi
;
704 if (fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
705 fileset
->partitionReferenceNum
!= 0xFFFF) {
706 bh
= udf_read_ptagged(sb
, fileset
, 0, &ident
);
710 } else if (ident
!= TAG_IDENT_FSD
) {
719 /* Search backwards through the partitions */
720 struct kernel_lb_addr newfileset
;
722 /* --> cvg: FIXME - is it reasonable? */
725 for (newfileset
.partitionReferenceNum
= sbi
->s_partitions
- 1;
726 (newfileset
.partitionReferenceNum
!= 0xFFFF &&
727 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
728 fileset
->partitionReferenceNum
== 0xFFFF);
729 newfileset
.partitionReferenceNum
--) {
730 lastblock
= sbi
->s_partmaps
731 [newfileset
.partitionReferenceNum
]
733 newfileset
.logicalBlockNum
= 0;
736 bh
= udf_read_ptagged(sb
, &newfileset
, 0,
739 newfileset
.logicalBlockNum
++;
746 struct spaceBitmapDesc
*sp
;
747 sp
= (struct spaceBitmapDesc
*)
749 newfileset
.logicalBlockNum
+= 1 +
750 ((le32_to_cpu(sp
->numOfBytes
) +
751 sizeof(struct spaceBitmapDesc
)
752 - 1) >> sb
->s_blocksize_bits
);
757 *fileset
= newfileset
;
760 newfileset
.logicalBlockNum
++;
765 } while (newfileset
.logicalBlockNum
< lastblock
&&
766 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
767 fileset
->partitionReferenceNum
== 0xFFFF);
771 if ((fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
772 fileset
->partitionReferenceNum
!= 0xFFFF) && bh
) {
773 udf_debug("Fileset at block=%d, partition=%d\n",
774 fileset
->logicalBlockNum
,
775 fileset
->partitionReferenceNum
);
777 sbi
->s_partition
= fileset
->partitionReferenceNum
;
778 udf_load_fileset(sb
, bh
, root
);
785 static int udf_load_pvoldesc(struct super_block
*sb
, sector_t block
)
787 struct primaryVolDesc
*pvoldesc
;
788 struct ustr
*instr
, *outstr
;
789 struct buffer_head
*bh
;
793 instr
= kmalloc(sizeof(struct ustr
), GFP_NOFS
);
797 outstr
= kmalloc(sizeof(struct ustr
), GFP_NOFS
);
801 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
805 BUG_ON(ident
!= TAG_IDENT_PVD
);
807 pvoldesc
= (struct primaryVolDesc
*)bh
->b_data
;
809 if (udf_disk_stamp_to_time(&UDF_SB(sb
)->s_record_time
,
810 pvoldesc
->recordingDateAndTime
)) {
812 struct timestamp
*ts
= &pvoldesc
->recordingDateAndTime
;
813 udf_debug("recording time %04u/%02u/%02u"
815 le16_to_cpu(ts
->year
), ts
->month
, ts
->day
, ts
->hour
,
816 ts
->minute
, le16_to_cpu(ts
->typeAndTimezone
));
820 if (!udf_build_ustr(instr
, pvoldesc
->volIdent
, 32))
821 if (udf_CS0toUTF8(outstr
, instr
)) {
822 strncpy(UDF_SB(sb
)->s_volume_ident
, outstr
->u_name
,
823 outstr
->u_len
> 31 ? 31 : outstr
->u_len
);
824 udf_debug("volIdent[] = '%s'\n",
825 UDF_SB(sb
)->s_volume_ident
);
828 if (!udf_build_ustr(instr
, pvoldesc
->volSetIdent
, 128))
829 if (udf_CS0toUTF8(outstr
, instr
))
830 udf_debug("volSetIdent[] = '%s'\n", outstr
->u_name
);
841 static int udf_load_metadata_files(struct super_block
*sb
, int partition
)
843 struct udf_sb_info
*sbi
= UDF_SB(sb
);
844 struct udf_part_map
*map
;
845 struct udf_meta_data
*mdata
;
846 struct kernel_lb_addr addr
;
849 map
= &sbi
->s_partmaps
[partition
];
850 mdata
= &map
->s_type_specific
.s_metadata
;
852 /* metadata address */
853 addr
.logicalBlockNum
= mdata
->s_meta_file_loc
;
854 addr
.partitionReferenceNum
= map
->s_partition_num
;
856 udf_debug("Metadata file location: block = %d part = %d\n",
857 addr
.logicalBlockNum
, addr
.partitionReferenceNum
);
859 mdata
->s_metadata_fe
= udf_iget(sb
, &addr
);
861 if (mdata
->s_metadata_fe
== NULL
) {
862 udf_warning(sb
, __func__
, "metadata inode efe not found, "
863 "will try mirror inode.");
865 } else if (UDF_I(mdata
->s_metadata_fe
)->i_alloc_type
!=
866 ICBTAG_FLAG_AD_SHORT
) {
867 udf_warning(sb
, __func__
, "metadata inode efe does not have "
868 "short allocation descriptors!");
870 iput(mdata
->s_metadata_fe
);
871 mdata
->s_metadata_fe
= NULL
;
874 /* mirror file entry */
875 addr
.logicalBlockNum
= mdata
->s_mirror_file_loc
;
876 addr
.partitionReferenceNum
= map
->s_partition_num
;
878 udf_debug("Mirror metadata file location: block = %d part = %d\n",
879 addr
.logicalBlockNum
, addr
.partitionReferenceNum
);
881 mdata
->s_mirror_fe
= udf_iget(sb
, &addr
);
883 if (mdata
->s_mirror_fe
== NULL
) {
885 udf_error(sb
, __func__
, "mirror inode efe not found "
886 "and metadata inode is missing too, exiting...");
889 udf_warning(sb
, __func__
, "mirror inode efe not found,"
890 " but metadata inode is OK");
891 } else if (UDF_I(mdata
->s_mirror_fe
)->i_alloc_type
!=
892 ICBTAG_FLAG_AD_SHORT
) {
893 udf_warning(sb
, __func__
, "mirror inode efe does not have "
894 "short allocation descriptors!");
895 iput(mdata
->s_mirror_fe
);
896 mdata
->s_mirror_fe
= NULL
;
904 * Load only if bitmap file location differs from 0xFFFFFFFF (DCN-5102)
906 if (mdata
->s_bitmap_file_loc
!= 0xFFFFFFFF) {
907 addr
.logicalBlockNum
= mdata
->s_bitmap_file_loc
;
908 addr
.partitionReferenceNum
= map
->s_partition_num
;
910 udf_debug("Bitmap file location: block = %d part = %d\n",
911 addr
.logicalBlockNum
, addr
.partitionReferenceNum
);
913 mdata
->s_bitmap_fe
= udf_iget(sb
, &addr
);
915 if (mdata
->s_bitmap_fe
== NULL
) {
916 if (sb
->s_flags
& MS_RDONLY
)
917 udf_warning(sb
, __func__
, "bitmap inode efe "
918 "not found but it's ok since the disc"
919 " is mounted read-only");
921 udf_error(sb
, __func__
, "bitmap inode efe not "
922 "found and attempted read-write mount");
928 udf_debug("udf_load_metadata_files Ok\n");
936 static void udf_load_fileset(struct super_block
*sb
, struct buffer_head
*bh
,
937 struct kernel_lb_addr
*root
)
939 struct fileSetDesc
*fset
;
941 fset
= (struct fileSetDesc
*)bh
->b_data
;
943 *root
= lelb_to_cpu(fset
->rootDirectoryICB
.extLocation
);
945 UDF_SB(sb
)->s_serial_number
= le16_to_cpu(fset
->descTag
.tagSerialNum
);
947 udf_debug("Rootdir at block=%d, partition=%d\n",
948 root
->logicalBlockNum
, root
->partitionReferenceNum
);
951 int udf_compute_nr_groups(struct super_block
*sb
, u32 partition
)
953 struct udf_part_map
*map
= &UDF_SB(sb
)->s_partmaps
[partition
];
954 return DIV_ROUND_UP(map
->s_partition_len
+
955 (sizeof(struct spaceBitmapDesc
) << 3),
956 sb
->s_blocksize
* 8);
959 static struct udf_bitmap
*udf_sb_alloc_bitmap(struct super_block
*sb
, u32 index
)
961 struct udf_bitmap
*bitmap
;
965 nr_groups
= udf_compute_nr_groups(sb
, index
);
966 size
= sizeof(struct udf_bitmap
) +
967 (sizeof(struct buffer_head
*) * nr_groups
);
969 if (size
<= PAGE_SIZE
)
970 bitmap
= kmalloc(size
, GFP_KERNEL
);
972 bitmap
= vmalloc(size
); /* TODO: get rid of vmalloc */
974 if (bitmap
== NULL
) {
975 udf_error(sb
, __func__
,
976 "Unable to allocate space for bitmap "
977 "and %d buffer_head pointers", nr_groups
);
981 memset(bitmap
, 0x00, size
);
982 bitmap
->s_block_bitmap
= (struct buffer_head
**)(bitmap
+ 1);
983 bitmap
->s_nr_groups
= nr_groups
;
987 static int udf_fill_partdesc_info(struct super_block
*sb
,
988 struct partitionDesc
*p
, int p_index
)
990 struct udf_part_map
*map
;
991 struct udf_sb_info
*sbi
= UDF_SB(sb
);
992 struct partitionHeaderDesc
*phd
;
994 map
= &sbi
->s_partmaps
[p_index
];
996 map
->s_partition_len
= le32_to_cpu(p
->partitionLength
); /* blocks */
997 map
->s_partition_root
= le32_to_cpu(p
->partitionStartingLocation
);
999 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY
))
1000 map
->s_partition_flags
|= UDF_PART_FLAG_READ_ONLY
;
1001 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE
))
1002 map
->s_partition_flags
|= UDF_PART_FLAG_WRITE_ONCE
;
1003 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE
))
1004 map
->s_partition_flags
|= UDF_PART_FLAG_REWRITABLE
;
1005 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE
))
1006 map
->s_partition_flags
|= UDF_PART_FLAG_OVERWRITABLE
;
1008 udf_debug("Partition (%d type %x) starts at physical %d, "
1009 "block length %d\n", p_index
,
1010 map
->s_partition_type
, map
->s_partition_root
,
1011 map
->s_partition_len
);
1013 if (strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR02
) &&
1014 strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR03
))
1017 phd
= (struct partitionHeaderDesc
*)p
->partitionContentsUse
;
1018 if (phd
->unallocSpaceTable
.extLength
) {
1019 struct kernel_lb_addr loc
= {
1020 .logicalBlockNum
= le32_to_cpu(
1021 phd
->unallocSpaceTable
.extPosition
),
1022 .partitionReferenceNum
= p_index
,
1025 map
->s_uspace
.s_table
= udf_iget(sb
, &loc
);
1026 if (!map
->s_uspace
.s_table
) {
1027 udf_debug("cannot load unallocSpaceTable (part %d)\n",
1031 map
->s_partition_flags
|= UDF_PART_FLAG_UNALLOC_TABLE
;
1032 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
1033 p_index
, map
->s_uspace
.s_table
->i_ino
);
1036 if (phd
->unallocSpaceBitmap
.extLength
) {
1037 struct udf_bitmap
*bitmap
= udf_sb_alloc_bitmap(sb
, p_index
);
1040 map
->s_uspace
.s_bitmap
= bitmap
;
1041 bitmap
->s_extLength
= le32_to_cpu(
1042 phd
->unallocSpaceBitmap
.extLength
);
1043 bitmap
->s_extPosition
= le32_to_cpu(
1044 phd
->unallocSpaceBitmap
.extPosition
);
1045 map
->s_partition_flags
|= UDF_PART_FLAG_UNALLOC_BITMAP
;
1046 udf_debug("unallocSpaceBitmap (part %d) @ %d\n", p_index
,
1047 bitmap
->s_extPosition
);
1050 if (phd
->partitionIntegrityTable
.extLength
)
1051 udf_debug("partitionIntegrityTable (part %d)\n", p_index
);
1053 if (phd
->freedSpaceTable
.extLength
) {
1054 struct kernel_lb_addr loc
= {
1055 .logicalBlockNum
= le32_to_cpu(
1056 phd
->freedSpaceTable
.extPosition
),
1057 .partitionReferenceNum
= p_index
,
1060 map
->s_fspace
.s_table
= udf_iget(sb
, &loc
);
1061 if (!map
->s_fspace
.s_table
) {
1062 udf_debug("cannot load freedSpaceTable (part %d)\n",
1067 map
->s_partition_flags
|= UDF_PART_FLAG_FREED_TABLE
;
1068 udf_debug("freedSpaceTable (part %d) @ %ld\n",
1069 p_index
, map
->s_fspace
.s_table
->i_ino
);
1072 if (phd
->freedSpaceBitmap
.extLength
) {
1073 struct udf_bitmap
*bitmap
= udf_sb_alloc_bitmap(sb
, p_index
);
1076 map
->s_fspace
.s_bitmap
= bitmap
;
1077 bitmap
->s_extLength
= le32_to_cpu(
1078 phd
->freedSpaceBitmap
.extLength
);
1079 bitmap
->s_extPosition
= le32_to_cpu(
1080 phd
->freedSpaceBitmap
.extPosition
);
1081 map
->s_partition_flags
|= UDF_PART_FLAG_FREED_BITMAP
;
1082 udf_debug("freedSpaceBitmap (part %d) @ %d\n", p_index
,
1083 bitmap
->s_extPosition
);
1088 static int udf_load_vat(struct super_block
*sb
, int p_index
, int type1_index
)
1090 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1091 struct udf_part_map
*map
= &sbi
->s_partmaps
[p_index
];
1092 struct kernel_lb_addr ino
;
1093 struct buffer_head
*bh
= NULL
;
1094 struct udf_inode_info
*vati
;
1096 struct virtualAllocationTable20
*vat20
;
1098 /* VAT file entry is in the last recorded block */
1099 ino
.partitionReferenceNum
= type1_index
;
1100 ino
.logicalBlockNum
= sbi
->s_last_block
- map
->s_partition_root
;
1101 sbi
->s_vat_inode
= udf_iget(sb
, &ino
);
1102 if (!sbi
->s_vat_inode
)
1105 if (map
->s_partition_type
== UDF_VIRTUAL_MAP15
) {
1106 map
->s_type_specific
.s_virtual
.s_start_offset
= 0;
1107 map
->s_type_specific
.s_virtual
.s_num_entries
=
1108 (sbi
->s_vat_inode
->i_size
- 36) >> 2;
1109 } else if (map
->s_partition_type
== UDF_VIRTUAL_MAP20
) {
1110 vati
= UDF_I(sbi
->s_vat_inode
);
1111 if (vati
->i_alloc_type
!= ICBTAG_FLAG_AD_IN_ICB
) {
1112 pos
= udf_block_map(sbi
->s_vat_inode
, 0);
1113 bh
= sb_bread(sb
, pos
);
1116 vat20
= (struct virtualAllocationTable20
*)bh
->b_data
;
1118 vat20
= (struct virtualAllocationTable20
*)
1122 map
->s_type_specific
.s_virtual
.s_start_offset
=
1123 le16_to_cpu(vat20
->lengthHeader
);
1124 map
->s_type_specific
.s_virtual
.s_num_entries
=
1125 (sbi
->s_vat_inode
->i_size
-
1126 map
->s_type_specific
.s_virtual
.
1127 s_start_offset
) >> 2;
1133 static int udf_load_partdesc(struct super_block
*sb
, sector_t block
)
1135 struct buffer_head
*bh
;
1136 struct partitionDesc
*p
;
1137 struct udf_part_map
*map
;
1138 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1140 uint16_t partitionNumber
;
1144 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1147 if (ident
!= TAG_IDENT_PD
)
1150 p
= (struct partitionDesc
*)bh
->b_data
;
1151 partitionNumber
= le16_to_cpu(p
->partitionNumber
);
1153 /* First scan for TYPE1, SPARABLE and METADATA partitions */
1154 for (i
= 0; i
< sbi
->s_partitions
; i
++) {
1155 map
= &sbi
->s_partmaps
[i
];
1156 udf_debug("Searching map: (%d == %d)\n",
1157 map
->s_partition_num
, partitionNumber
);
1158 if (map
->s_partition_num
== partitionNumber
&&
1159 (map
->s_partition_type
== UDF_TYPE1_MAP15
||
1160 map
->s_partition_type
== UDF_SPARABLE_MAP15
))
1164 if (i
>= sbi
->s_partitions
) {
1165 udf_debug("Partition (%d) not found in partition map\n",
1170 ret
= udf_fill_partdesc_info(sb
, p
, i
);
1173 * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and
1174 * PHYSICAL partitions are already set up
1177 for (i
= 0; i
< sbi
->s_partitions
; i
++) {
1178 map
= &sbi
->s_partmaps
[i
];
1180 if (map
->s_partition_num
== partitionNumber
&&
1181 (map
->s_partition_type
== UDF_VIRTUAL_MAP15
||
1182 map
->s_partition_type
== UDF_VIRTUAL_MAP20
||
1183 map
->s_partition_type
== UDF_METADATA_MAP25
))
1187 if (i
>= sbi
->s_partitions
)
1190 ret
= udf_fill_partdesc_info(sb
, p
, i
);
1194 if (map
->s_partition_type
== UDF_METADATA_MAP25
) {
1195 ret
= udf_load_metadata_files(sb
, i
);
1197 printk(KERN_ERR
"UDF-fs: error loading MetaData "
1198 "partition map %d\n", i
);
1202 ret
= udf_load_vat(sb
, i
, type1_idx
);
1206 * Mark filesystem read-only if we have a partition with
1207 * virtual map since we don't handle writing to it (we
1208 * overwrite blocks instead of relocating them).
1210 sb
->s_flags
|= MS_RDONLY
;
1211 printk(KERN_NOTICE
"UDF-fs: Filesystem marked read-only "
1212 "because writing to pseudooverwrite partition is "
1213 "not implemented.\n");
1216 /* In case loading failed, we handle cleanup in udf_fill_super */
1221 static int udf_load_logicalvol(struct super_block
*sb
, sector_t block
,
1222 struct kernel_lb_addr
*fileset
)
1224 struct logicalVolDesc
*lvd
;
1227 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1228 struct genericPartitionMap
*gpm
;
1230 struct buffer_head
*bh
;
1233 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1236 BUG_ON(ident
!= TAG_IDENT_LVD
);
1237 lvd
= (struct logicalVolDesc
*)bh
->b_data
;
1239 i
= udf_sb_alloc_partition_maps(sb
, le32_to_cpu(lvd
->numPartitionMaps
));
1245 for (i
= 0, offset
= 0;
1246 i
< sbi
->s_partitions
&& offset
< le32_to_cpu(lvd
->mapTableLength
);
1247 i
++, offset
+= gpm
->partitionMapLength
) {
1248 struct udf_part_map
*map
= &sbi
->s_partmaps
[i
];
1249 gpm
= (struct genericPartitionMap
*)
1250 &(lvd
->partitionMaps
[offset
]);
1251 type
= gpm
->partitionMapType
;
1253 struct genericPartitionMap1
*gpm1
=
1254 (struct genericPartitionMap1
*)gpm
;
1255 map
->s_partition_type
= UDF_TYPE1_MAP15
;
1256 map
->s_volumeseqnum
= le16_to_cpu(gpm1
->volSeqNum
);
1257 map
->s_partition_num
= le16_to_cpu(gpm1
->partitionNum
);
1258 map
->s_partition_func
= NULL
;
1259 } else if (type
== 2) {
1260 struct udfPartitionMap2
*upm2
=
1261 (struct udfPartitionMap2
*)gpm
;
1262 if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_VIRTUAL
,
1263 strlen(UDF_ID_VIRTUAL
))) {
1265 le16_to_cpu(((__le16
*)upm2
->partIdent
.
1268 map
->s_partition_type
=
1270 map
->s_partition_func
=
1271 udf_get_pblock_virt15
;
1273 map
->s_partition_type
=
1275 map
->s_partition_func
=
1276 udf_get_pblock_virt20
;
1278 } else if (!strncmp(upm2
->partIdent
.ident
,
1280 strlen(UDF_ID_SPARABLE
))) {
1282 struct sparingTable
*st
;
1283 struct sparablePartitionMap
*spm
=
1284 (struct sparablePartitionMap
*)gpm
;
1286 map
->s_partition_type
= UDF_SPARABLE_MAP15
;
1287 map
->s_type_specific
.s_sparing
.s_packet_len
=
1288 le16_to_cpu(spm
->packetLength
);
1289 for (j
= 0; j
< spm
->numSparingTables
; j
++) {
1290 struct buffer_head
*bh2
;
1293 spm
->locSparingTable
[j
]);
1294 bh2
= udf_read_tagged(sb
, loc
, loc
,
1296 map
->s_type_specific
.s_sparing
.
1297 s_spar_map
[j
] = bh2
;
1302 st
= (struct sparingTable
*)bh2
->b_data
;
1303 if (ident
!= 0 || strncmp(
1304 st
->sparingIdent
.ident
,
1306 strlen(UDF_ID_SPARING
))) {
1308 map
->s_type_specific
.s_sparing
.
1309 s_spar_map
[j
] = NULL
;
1312 map
->s_partition_func
= udf_get_pblock_spar15
;
1313 } else if (!strncmp(upm2
->partIdent
.ident
,
1315 strlen(UDF_ID_METADATA
))) {
1316 struct udf_meta_data
*mdata
=
1317 &map
->s_type_specific
.s_metadata
;
1318 struct metadataPartitionMap
*mdm
=
1319 (struct metadataPartitionMap
*)
1320 &(lvd
->partitionMaps
[offset
]);
1321 udf_debug("Parsing Logical vol part %d "
1322 "type %d id=%s\n", i
, type
,
1325 map
->s_partition_type
= UDF_METADATA_MAP25
;
1326 map
->s_partition_func
= udf_get_pblock_meta25
;
1328 mdata
->s_meta_file_loc
=
1329 le32_to_cpu(mdm
->metadataFileLoc
);
1330 mdata
->s_mirror_file_loc
=
1331 le32_to_cpu(mdm
->metadataMirrorFileLoc
);
1332 mdata
->s_bitmap_file_loc
=
1333 le32_to_cpu(mdm
->metadataBitmapFileLoc
);
1334 mdata
->s_alloc_unit_size
=
1335 le32_to_cpu(mdm
->allocUnitSize
);
1336 mdata
->s_align_unit_size
=
1337 le16_to_cpu(mdm
->alignUnitSize
);
1338 mdata
->s_dup_md_flag
=
1341 udf_debug("Metadata Ident suffix=0x%x\n",
1344 mdm
->partIdent
.identSuffix
)[0])));
1345 udf_debug("Metadata part num=%d\n",
1346 le16_to_cpu(mdm
->partitionNum
));
1347 udf_debug("Metadata part alloc unit size=%d\n",
1348 le32_to_cpu(mdm
->allocUnitSize
));
1349 udf_debug("Metadata file loc=%d\n",
1350 le32_to_cpu(mdm
->metadataFileLoc
));
1351 udf_debug("Mirror file loc=%d\n",
1352 le32_to_cpu(mdm
->metadataMirrorFileLoc
));
1353 udf_debug("Bitmap file loc=%d\n",
1354 le32_to_cpu(mdm
->metadataBitmapFileLoc
));
1355 udf_debug("Duplicate Flag: %d %d\n",
1356 mdata
->s_dup_md_flag
, mdm
->flags
);
1358 udf_debug("Unknown ident: %s\n",
1359 upm2
->partIdent
.ident
);
1362 map
->s_volumeseqnum
= le16_to_cpu(upm2
->volSeqNum
);
1363 map
->s_partition_num
= le16_to_cpu(upm2
->partitionNum
);
1365 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1366 i
, map
->s_partition_num
, type
,
1367 map
->s_volumeseqnum
);
1371 struct long_ad
*la
= (struct long_ad
*)&(lvd
->logicalVolContentsUse
[0]);
1373 *fileset
= lelb_to_cpu(la
->extLocation
);
1374 udf_debug("FileSet found in LogicalVolDesc at block=%d, "
1375 "partition=%d\n", fileset
->logicalBlockNum
,
1376 fileset
->partitionReferenceNum
);
1378 if (lvd
->integritySeqExt
.extLength
)
1379 udf_load_logicalvolint(sb
, leea_to_cpu(lvd
->integritySeqExt
));
1387 * udf_load_logicalvolint
1390 static void udf_load_logicalvolint(struct super_block
*sb
, struct kernel_extent_ad loc
)
1392 struct buffer_head
*bh
= NULL
;
1394 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1395 struct logicalVolIntegrityDesc
*lvid
;
1397 while (loc
.extLength
> 0 &&
1398 (bh
= udf_read_tagged(sb
, loc
.extLocation
,
1399 loc
.extLocation
, &ident
)) &&
1400 ident
== TAG_IDENT_LVID
) {
1401 sbi
->s_lvid_bh
= bh
;
1402 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1404 if (lvid
->nextIntegrityExt
.extLength
)
1405 udf_load_logicalvolint(sb
,
1406 leea_to_cpu(lvid
->nextIntegrityExt
));
1408 if (sbi
->s_lvid_bh
!= bh
)
1410 loc
.extLength
-= sb
->s_blocksize
;
1413 if (sbi
->s_lvid_bh
!= bh
)
1418 * udf_process_sequence
1421 * Process a main/reserve volume descriptor sequence.
1424 * sb Pointer to _locked_ superblock.
1425 * block First block of first extent of the sequence.
1426 * lastblock Lastblock of first extent of the sequence.
1429 * July 1, 1997 - Andrew E. Mileski
1430 * Written, tested, and released.
1432 static noinline
int udf_process_sequence(struct super_block
*sb
, long block
,
1433 long lastblock
, struct kernel_lb_addr
*fileset
)
1435 struct buffer_head
*bh
= NULL
;
1436 struct udf_vds_record vds
[VDS_POS_LENGTH
];
1437 struct udf_vds_record
*curr
;
1438 struct generic_desc
*gd
;
1439 struct volDescPtr
*vdp
;
1443 long next_s
= 0, next_e
= 0;
1445 memset(vds
, 0, sizeof(struct udf_vds_record
) * VDS_POS_LENGTH
);
1448 * Read the main descriptor sequence and find which descriptors
1451 for (; (!done
&& block
<= lastblock
); block
++) {
1453 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1455 printk(KERN_ERR
"udf: Block %Lu of volume descriptor "
1456 "sequence is corrupted or we could not read "
1457 "it.\n", (unsigned long long)block
);
1461 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1462 gd
= (struct generic_desc
*)bh
->b_data
;
1463 vdsn
= le32_to_cpu(gd
->volDescSeqNum
);
1465 case TAG_IDENT_PVD
: /* ISO 13346 3/10.1 */
1466 curr
= &vds
[VDS_POS_PRIMARY_VOL_DESC
];
1467 if (vdsn
>= curr
->volDescSeqNum
) {
1468 curr
->volDescSeqNum
= vdsn
;
1469 curr
->block
= block
;
1472 case TAG_IDENT_VDP
: /* ISO 13346 3/10.3 */
1473 curr
= &vds
[VDS_POS_VOL_DESC_PTR
];
1474 if (vdsn
>= curr
->volDescSeqNum
) {
1475 curr
->volDescSeqNum
= vdsn
;
1476 curr
->block
= block
;
1478 vdp
= (struct volDescPtr
*)bh
->b_data
;
1479 next_s
= le32_to_cpu(
1480 vdp
->nextVolDescSeqExt
.extLocation
);
1481 next_e
= le32_to_cpu(
1482 vdp
->nextVolDescSeqExt
.extLength
);
1483 next_e
= next_e
>> sb
->s_blocksize_bits
;
1487 case TAG_IDENT_IUVD
: /* ISO 13346 3/10.4 */
1488 curr
= &vds
[VDS_POS_IMP_USE_VOL_DESC
];
1489 if (vdsn
>= curr
->volDescSeqNum
) {
1490 curr
->volDescSeqNum
= vdsn
;
1491 curr
->block
= block
;
1494 case TAG_IDENT_PD
: /* ISO 13346 3/10.5 */
1495 curr
= &vds
[VDS_POS_PARTITION_DESC
];
1497 curr
->block
= block
;
1499 case TAG_IDENT_LVD
: /* ISO 13346 3/10.6 */
1500 curr
= &vds
[VDS_POS_LOGICAL_VOL_DESC
];
1501 if (vdsn
>= curr
->volDescSeqNum
) {
1502 curr
->volDescSeqNum
= vdsn
;
1503 curr
->block
= block
;
1506 case TAG_IDENT_USD
: /* ISO 13346 3/10.8 */
1507 curr
= &vds
[VDS_POS_UNALLOC_SPACE_DESC
];
1508 if (vdsn
>= curr
->volDescSeqNum
) {
1509 curr
->volDescSeqNum
= vdsn
;
1510 curr
->block
= block
;
1513 case TAG_IDENT_TD
: /* ISO 13346 3/10.9 */
1514 vds
[VDS_POS_TERMINATING_DESC
].block
= block
;
1518 next_s
= next_e
= 0;
1526 * Now read interesting descriptors again and process them
1527 * in a suitable order
1529 if (!vds
[VDS_POS_PRIMARY_VOL_DESC
].block
) {
1530 printk(KERN_ERR
"udf: Primary Volume Descriptor not found!\n");
1533 if (udf_load_pvoldesc(sb
, vds
[VDS_POS_PRIMARY_VOL_DESC
].block
))
1536 if (vds
[VDS_POS_LOGICAL_VOL_DESC
].block
&& udf_load_logicalvol(sb
,
1537 vds
[VDS_POS_LOGICAL_VOL_DESC
].block
, fileset
))
1540 if (vds
[VDS_POS_PARTITION_DESC
].block
) {
1542 * We rescan the whole descriptor sequence to find
1543 * partition descriptor blocks and process them.
1545 for (block
= vds
[VDS_POS_PARTITION_DESC
].block
;
1546 block
< vds
[VDS_POS_TERMINATING_DESC
].block
;
1548 if (udf_load_partdesc(sb
, block
))
1555 static int udf_load_sequence(struct super_block
*sb
, struct buffer_head
*bh
,
1556 struct kernel_lb_addr
*fileset
)
1558 struct anchorVolDescPtr
*anchor
;
1559 long main_s
, main_e
, reserve_s
, reserve_e
;
1560 struct udf_sb_info
*sbi
;
1563 anchor
= (struct anchorVolDescPtr
*)bh
->b_data
;
1565 /* Locate the main sequence */
1566 main_s
= le32_to_cpu(anchor
->mainVolDescSeqExt
.extLocation
);
1567 main_e
= le32_to_cpu(anchor
->mainVolDescSeqExt
.extLength
);
1568 main_e
= main_e
>> sb
->s_blocksize_bits
;
1571 /* Locate the reserve sequence */
1572 reserve_s
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLocation
);
1573 reserve_e
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLength
);
1574 reserve_e
= reserve_e
>> sb
->s_blocksize_bits
;
1575 reserve_e
+= reserve_s
;
1577 /* Process the main & reserve sequences */
1578 /* responsible for finding the PartitionDesc(s) */
1579 if (!udf_process_sequence(sb
, main_s
, main_e
, fileset
))
1581 return !udf_process_sequence(sb
, reserve_s
, reserve_e
, fileset
);
1585 * Check whether there is an anchor block in the given block and
1586 * load Volume Descriptor Sequence if so.
1588 static int udf_check_anchor_block(struct super_block
*sb
, sector_t block
,
1589 struct kernel_lb_addr
*fileset
)
1591 struct buffer_head
*bh
;
1595 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_VARCONV
) &&
1596 udf_fixed_to_variable(block
) >=
1597 sb
->s_bdev
->bd_inode
->i_size
>> sb
->s_blocksize_bits
)
1600 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1603 if (ident
!= TAG_IDENT_AVDP
) {
1607 ret
= udf_load_sequence(sb
, bh
, fileset
);
1612 /* Search for an anchor volume descriptor pointer */
1613 static sector_t
udf_scan_anchors(struct super_block
*sb
, sector_t lastblock
,
1614 struct kernel_lb_addr
*fileset
)
1618 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1621 /* First try user provided anchor */
1622 if (sbi
->s_anchor
) {
1623 if (udf_check_anchor_block(sb
, sbi
->s_anchor
, fileset
))
1627 * according to spec, anchor is in either:
1631 * however, if the disc isn't closed, it could be 512.
1633 if (udf_check_anchor_block(sb
, sbi
->s_session
+ 256, fileset
))
1636 * The trouble is which block is the last one. Drives often misreport
1637 * this so we try various possibilities.
1639 last
[last_count
++] = lastblock
;
1641 last
[last_count
++] = lastblock
- 1;
1642 last
[last_count
++] = lastblock
+ 1;
1644 last
[last_count
++] = lastblock
- 2;
1645 if (lastblock
>= 150)
1646 last
[last_count
++] = lastblock
- 150;
1647 if (lastblock
>= 152)
1648 last
[last_count
++] = lastblock
- 152;
1650 for (i
= 0; i
< last_count
; i
++) {
1651 if (last
[i
] >= sb
->s_bdev
->bd_inode
->i_size
>>
1652 sb
->s_blocksize_bits
)
1654 if (udf_check_anchor_block(sb
, last
[i
], fileset
))
1658 if (udf_check_anchor_block(sb
, last
[i
] - 256, fileset
))
1662 /* Finally try block 512 in case media is open */
1663 if (udf_check_anchor_block(sb
, sbi
->s_session
+ 512, fileset
))
1669 * Find an anchor volume descriptor and load Volume Descriptor Sequence from
1670 * area specified by it. The function expects sbi->s_lastblock to be the last
1671 * block on the media.
1673 * Return 1 if ok, 0 if not found.
1676 static int udf_find_anchor(struct super_block
*sb
,
1677 struct kernel_lb_addr
*fileset
)
1680 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1682 lastblock
= udf_scan_anchors(sb
, sbi
->s_last_block
, fileset
);
1686 /* No anchor found? Try VARCONV conversion of block numbers */
1687 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
1688 /* Firstly, we try to not convert number of the last block */
1689 lastblock
= udf_scan_anchors(sb
,
1690 udf_variable_to_fixed(sbi
->s_last_block
),
1695 /* Secondly, we try with converted number of the last block */
1696 lastblock
= udf_scan_anchors(sb
, sbi
->s_last_block
, fileset
);
1698 /* VARCONV didn't help. Clear it. */
1699 UDF_CLEAR_FLAG(sb
, UDF_FLAG_VARCONV
);
1703 sbi
->s_last_block
= lastblock
;
1708 * Check Volume Structure Descriptor, find Anchor block and load Volume
1709 * Descriptor Sequence
1711 static int udf_load_vrs(struct super_block
*sb
, struct udf_options
*uopt
,
1712 int silent
, struct kernel_lb_addr
*fileset
)
1714 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1717 if (!sb_set_blocksize(sb
, uopt
->blocksize
)) {
1719 printk(KERN_WARNING
"UDF-fs: Bad block size\n");
1722 sbi
->s_last_block
= uopt
->lastblock
;
1724 /* Check that it is NSR02 compliant */
1725 nsr_off
= udf_check_vsd(sb
);
1728 printk(KERN_WARNING
"UDF-fs: No VRS found\n");
1732 udf_debug("Failed to read byte 32768. Assuming open "
1733 "disc. Skipping validity check\n");
1734 if (!sbi
->s_last_block
)
1735 sbi
->s_last_block
= udf_get_last_block(sb
);
1737 udf_debug("Validity check skipped because of novrs option\n");
1740 /* Look for anchor block and load Volume Descriptor Sequence */
1741 sbi
->s_anchor
= uopt
->anchor
;
1742 if (!udf_find_anchor(sb
, fileset
)) {
1744 printk(KERN_WARNING
"UDF-fs: No anchor found\n");
1750 static void udf_open_lvid(struct super_block
*sb
)
1752 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1753 struct buffer_head
*bh
= sbi
->s_lvid_bh
;
1754 struct logicalVolIntegrityDesc
*lvid
;
1755 struct logicalVolIntegrityDescImpUse
*lvidiu
;
1759 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1760 lvidiu
= udf_sb_lvidiu(sbi
);
1762 lvidiu
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1763 lvidiu
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1764 udf_time_to_disk_stamp(&lvid
->recordingDateAndTime
,
1766 lvid
->integrityType
= LVID_INTEGRITY_TYPE_OPEN
;
1768 lvid
->descTag
.descCRC
= cpu_to_le16(
1769 crc_itu_t(0, (char *)lvid
+ sizeof(struct tag
),
1770 le16_to_cpu(lvid
->descTag
.descCRCLength
)));
1772 lvid
->descTag
.tagChecksum
= udf_tag_checksum(&lvid
->descTag
);
1773 mark_buffer_dirty(bh
);
1776 static void udf_close_lvid(struct super_block
*sb
)
1778 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1779 struct buffer_head
*bh
= sbi
->s_lvid_bh
;
1780 struct logicalVolIntegrityDesc
*lvid
;
1781 struct logicalVolIntegrityDescImpUse
*lvidiu
;
1786 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1788 if (lvid
->integrityType
!= LVID_INTEGRITY_TYPE_OPEN
)
1791 lvidiu
= udf_sb_lvidiu(sbi
);
1792 lvidiu
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1793 lvidiu
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1794 udf_time_to_disk_stamp(&lvid
->recordingDateAndTime
, CURRENT_TIME
);
1795 if (UDF_MAX_WRITE_VERSION
> le16_to_cpu(lvidiu
->maxUDFWriteRev
))
1796 lvidiu
->maxUDFWriteRev
= cpu_to_le16(UDF_MAX_WRITE_VERSION
);
1797 if (sbi
->s_udfrev
> le16_to_cpu(lvidiu
->minUDFReadRev
))
1798 lvidiu
->minUDFReadRev
= cpu_to_le16(sbi
->s_udfrev
);
1799 if (sbi
->s_udfrev
> le16_to_cpu(lvidiu
->minUDFWriteRev
))
1800 lvidiu
->minUDFWriteRev
= cpu_to_le16(sbi
->s_udfrev
);
1801 lvid
->integrityType
= cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE
);
1803 lvid
->descTag
.descCRC
= cpu_to_le16(
1804 crc_itu_t(0, (char *)lvid
+ sizeof(struct tag
),
1805 le16_to_cpu(lvid
->descTag
.descCRCLength
)));
1807 lvid
->descTag
.tagChecksum
= udf_tag_checksum(&lvid
->descTag
);
1808 mark_buffer_dirty(bh
);
1811 static void udf_sb_free_bitmap(struct udf_bitmap
*bitmap
)
1814 int nr_groups
= bitmap
->s_nr_groups
;
1815 int size
= sizeof(struct udf_bitmap
) + (sizeof(struct buffer_head
*) *
1818 for (i
= 0; i
< nr_groups
; i
++)
1819 if (bitmap
->s_block_bitmap
[i
])
1820 brelse(bitmap
->s_block_bitmap
[i
]);
1822 if (size
<= PAGE_SIZE
)
1828 static void udf_free_partition(struct udf_part_map
*map
)
1831 struct udf_meta_data
*mdata
;
1833 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
)
1834 iput(map
->s_uspace
.s_table
);
1835 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
)
1836 iput(map
->s_fspace
.s_table
);
1837 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
)
1838 udf_sb_free_bitmap(map
->s_uspace
.s_bitmap
);
1839 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
)
1840 udf_sb_free_bitmap(map
->s_fspace
.s_bitmap
);
1841 if (map
->s_partition_type
== UDF_SPARABLE_MAP15
)
1842 for (i
= 0; i
< 4; i
++)
1843 brelse(map
->s_type_specific
.s_sparing
.s_spar_map
[i
]);
1844 else if (map
->s_partition_type
== UDF_METADATA_MAP25
) {
1845 mdata
= &map
->s_type_specific
.s_metadata
;
1846 iput(mdata
->s_metadata_fe
);
1847 mdata
->s_metadata_fe
= NULL
;
1849 iput(mdata
->s_mirror_fe
);
1850 mdata
->s_mirror_fe
= NULL
;
1852 iput(mdata
->s_bitmap_fe
);
1853 mdata
->s_bitmap_fe
= NULL
;
1857 static int udf_fill_super(struct super_block
*sb
, void *options
, int silent
)
1861 struct inode
*inode
= NULL
;
1862 struct udf_options uopt
;
1863 struct kernel_lb_addr rootdir
, fileset
;
1864 struct udf_sb_info
*sbi
;
1866 uopt
.flags
= (1 << UDF_FLAG_USE_AD_IN_ICB
) | (1 << UDF_FLAG_STRICT
);
1870 uopt
.fmode
= UDF_INVALID_MODE
;
1871 uopt
.dmode
= UDF_INVALID_MODE
;
1873 sbi
= kzalloc(sizeof(struct udf_sb_info
), GFP_KERNEL
);
1877 sb
->s_fs_info
= sbi
;
1879 mutex_init(&sbi
->s_alloc_mutex
);
1881 if (!udf_parse_options((char *)options
, &uopt
, false))
1884 if (uopt
.flags
& (1 << UDF_FLAG_UTF8
) &&
1885 uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) {
1886 udf_error(sb
, "udf_read_super",
1887 "utf8 cannot be combined with iocharset\n");
1890 #ifdef CONFIG_UDF_NLS
1891 if ((uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) && !uopt
.nls_map
) {
1892 uopt
.nls_map
= load_nls_default();
1894 uopt
.flags
&= ~(1 << UDF_FLAG_NLS_MAP
);
1896 udf_debug("Using default NLS map\n");
1899 if (!(uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)))
1900 uopt
.flags
|= (1 << UDF_FLAG_UTF8
);
1902 fileset
.logicalBlockNum
= 0xFFFFFFFF;
1903 fileset
.partitionReferenceNum
= 0xFFFF;
1905 sbi
->s_flags
= uopt
.flags
;
1906 sbi
->s_uid
= uopt
.uid
;
1907 sbi
->s_gid
= uopt
.gid
;
1908 sbi
->s_umask
= uopt
.umask
;
1909 sbi
->s_fmode
= uopt
.fmode
;
1910 sbi
->s_dmode
= uopt
.dmode
;
1911 sbi
->s_nls_map
= uopt
.nls_map
;
1913 if (uopt
.session
== 0xFFFFFFFF)
1914 sbi
->s_session
= udf_get_last_session(sb
);
1916 sbi
->s_session
= uopt
.session
;
1918 udf_debug("Multi-session=%d\n", sbi
->s_session
);
1920 /* Fill in the rest of the superblock */
1921 sb
->s_op
= &udf_sb_ops
;
1922 sb
->s_export_op
= &udf_export_ops
;
1925 sb
->s_magic
= UDF_SUPER_MAGIC
;
1926 sb
->s_time_gran
= 1000;
1928 if (uopt
.flags
& (1 << UDF_FLAG_BLOCKSIZE_SET
)) {
1929 ret
= udf_load_vrs(sb
, &uopt
, silent
, &fileset
);
1931 uopt
.blocksize
= bdev_hardsect_size(sb
->s_bdev
);
1932 ret
= udf_load_vrs(sb
, &uopt
, silent
, &fileset
);
1933 if (!ret
&& uopt
.blocksize
!= UDF_DEFAULT_BLOCKSIZE
) {
1936 "UDF-fs: Rescanning with blocksize "
1937 "%d\n", UDF_DEFAULT_BLOCKSIZE
);
1938 uopt
.blocksize
= UDF_DEFAULT_BLOCKSIZE
;
1939 ret
= udf_load_vrs(sb
, &uopt
, silent
, &fileset
);
1943 printk(KERN_WARNING
"UDF-fs: No partition found (1)\n");
1947 udf_debug("Lastblock=%d\n", sbi
->s_last_block
);
1949 if (sbi
->s_lvid_bh
) {
1950 struct logicalVolIntegrityDescImpUse
*lvidiu
=
1952 uint16_t minUDFReadRev
= le16_to_cpu(lvidiu
->minUDFReadRev
);
1953 uint16_t minUDFWriteRev
= le16_to_cpu(lvidiu
->minUDFWriteRev
);
1954 /* uint16_t maxUDFWriteRev =
1955 le16_to_cpu(lvidiu->maxUDFWriteRev); */
1957 if (minUDFReadRev
> UDF_MAX_READ_VERSION
) {
1958 printk(KERN_ERR
"UDF-fs: minUDFReadRev=%x "
1960 le16_to_cpu(lvidiu
->minUDFReadRev
),
1961 UDF_MAX_READ_VERSION
);
1963 } else if (minUDFWriteRev
> UDF_MAX_WRITE_VERSION
)
1964 sb
->s_flags
|= MS_RDONLY
;
1966 sbi
->s_udfrev
= minUDFWriteRev
;
1968 if (minUDFReadRev
>= UDF_VERS_USE_EXTENDED_FE
)
1969 UDF_SET_FLAG(sb
, UDF_FLAG_USE_EXTENDED_FE
);
1970 if (minUDFReadRev
>= UDF_VERS_USE_STREAMS
)
1971 UDF_SET_FLAG(sb
, UDF_FLAG_USE_STREAMS
);
1974 if (!sbi
->s_partitions
) {
1975 printk(KERN_WARNING
"UDF-fs: No partition found (2)\n");
1979 if (sbi
->s_partmaps
[sbi
->s_partition
].s_partition_flags
&
1980 UDF_PART_FLAG_READ_ONLY
) {
1981 printk(KERN_NOTICE
"UDF-fs: Partition marked readonly; "
1982 "forcing readonly mount\n");
1983 sb
->s_flags
|= MS_RDONLY
;
1986 if (udf_find_fileset(sb
, &fileset
, &rootdir
)) {
1987 printk(KERN_WARNING
"UDF-fs: No fileset found\n");
1992 struct timestamp ts
;
1993 udf_time_to_disk_stamp(&ts
, sbi
->s_record_time
);
1994 udf_info("UDF: Mounting volume '%s', "
1995 "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1996 sbi
->s_volume_ident
, le16_to_cpu(ts
.year
), ts
.month
, ts
.day
,
1997 ts
.hour
, ts
.minute
, le16_to_cpu(ts
.typeAndTimezone
));
1999 if (!(sb
->s_flags
& MS_RDONLY
))
2002 /* Assign the root inode */
2003 /* assign inodes by physical block number */
2004 /* perhaps it's not extensible enough, but for now ... */
2005 inode
= udf_iget(sb
, &rootdir
);
2007 printk(KERN_ERR
"UDF-fs: Error in udf_iget, block=%d, "
2009 rootdir
.logicalBlockNum
, rootdir
.partitionReferenceNum
);
2013 /* Allocate a dentry for the root inode */
2014 sb
->s_root
= d_alloc_root(inode
);
2016 printk(KERN_ERR
"UDF-fs: Couldn't allocate root dentry\n");
2020 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
2024 if (sbi
->s_vat_inode
)
2025 iput(sbi
->s_vat_inode
);
2026 if (sbi
->s_partitions
)
2027 for (i
= 0; i
< sbi
->s_partitions
; i
++)
2028 udf_free_partition(&sbi
->s_partmaps
[i
]);
2029 #ifdef CONFIG_UDF_NLS
2030 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
2031 unload_nls(sbi
->s_nls_map
);
2033 if (!(sb
->s_flags
& MS_RDONLY
))
2035 brelse(sbi
->s_lvid_bh
);
2037 kfree(sbi
->s_partmaps
);
2039 sb
->s_fs_info
= NULL
;
2044 static void udf_error(struct super_block
*sb
, const char *function
,
2045 const char *fmt
, ...)
2049 if (!(sb
->s_flags
& MS_RDONLY
)) {
2053 va_start(args
, fmt
);
2054 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
2056 printk(KERN_CRIT
"UDF-fs error (device %s): %s: %s\n",
2057 sb
->s_id
, function
, error_buf
);
2060 void udf_warning(struct super_block
*sb
, const char *function
,
2061 const char *fmt
, ...)
2065 va_start(args
, fmt
);
2066 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
2068 printk(KERN_WARNING
"UDF-fs warning (device %s): %s: %s\n",
2069 sb
->s_id
, function
, error_buf
);
2072 static void udf_put_super(struct super_block
*sb
)
2075 struct udf_sb_info
*sbi
;
2078 if (sbi
->s_vat_inode
)
2079 iput(sbi
->s_vat_inode
);
2080 if (sbi
->s_partitions
)
2081 for (i
= 0; i
< sbi
->s_partitions
; i
++)
2082 udf_free_partition(&sbi
->s_partmaps
[i
]);
2083 #ifdef CONFIG_UDF_NLS
2084 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
2085 unload_nls(sbi
->s_nls_map
);
2087 if (!(sb
->s_flags
& MS_RDONLY
))
2089 brelse(sbi
->s_lvid_bh
);
2090 kfree(sbi
->s_partmaps
);
2091 kfree(sb
->s_fs_info
);
2092 sb
->s_fs_info
= NULL
;
2095 static int udf_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
2097 struct super_block
*sb
= dentry
->d_sb
;
2098 struct udf_sb_info
*sbi
= UDF_SB(sb
);
2099 struct logicalVolIntegrityDescImpUse
*lvidiu
;
2100 u64 id
= huge_encode_dev(sb
->s_bdev
->bd_dev
);
2102 if (sbi
->s_lvid_bh
!= NULL
)
2103 lvidiu
= udf_sb_lvidiu(sbi
);
2107 buf
->f_type
= UDF_SUPER_MAGIC
;
2108 buf
->f_bsize
= sb
->s_blocksize
;
2109 buf
->f_blocks
= sbi
->s_partmaps
[sbi
->s_partition
].s_partition_len
;
2110 buf
->f_bfree
= udf_count_free(sb
);
2111 buf
->f_bavail
= buf
->f_bfree
;
2112 buf
->f_files
= (lvidiu
!= NULL
? (le32_to_cpu(lvidiu
->numFiles
) +
2113 le32_to_cpu(lvidiu
->numDirs
)) : 0)
2115 buf
->f_ffree
= buf
->f_bfree
;
2116 buf
->f_namelen
= UDF_NAME_LEN
- 2;
2117 buf
->f_fsid
.val
[0] = (u32
)id
;
2118 buf
->f_fsid
.val
[1] = (u32
)(id
>> 32);
2123 static unsigned int udf_count_free_bitmap(struct super_block
*sb
,
2124 struct udf_bitmap
*bitmap
)
2126 struct buffer_head
*bh
= NULL
;
2127 unsigned int accum
= 0;
2129 int block
= 0, newblock
;
2130 struct kernel_lb_addr loc
;
2134 struct spaceBitmapDesc
*bm
;
2138 loc
.logicalBlockNum
= bitmap
->s_extPosition
;
2139 loc
.partitionReferenceNum
= UDF_SB(sb
)->s_partition
;
2140 bh
= udf_read_ptagged(sb
, &loc
, 0, &ident
);
2143 printk(KERN_ERR
"udf: udf_count_free failed\n");
2145 } else if (ident
!= TAG_IDENT_SBD
) {
2147 printk(KERN_ERR
"udf: udf_count_free failed\n");
2151 bm
= (struct spaceBitmapDesc
*)bh
->b_data
;
2152 bytes
= le32_to_cpu(bm
->numOfBytes
);
2153 index
= sizeof(struct spaceBitmapDesc
); /* offset in first block only */
2154 ptr
= (uint8_t *)bh
->b_data
;
2157 u32 cur_bytes
= min_t(u32
, bytes
, sb
->s_blocksize
- index
);
2158 accum
+= bitmap_weight((const unsigned long *)(ptr
+ index
),
2163 newblock
= udf_get_lb_pblock(sb
, &loc
, ++block
);
2164 bh
= udf_tread(sb
, newblock
);
2166 udf_debug("read failed\n");
2170 ptr
= (uint8_t *)bh
->b_data
;
2181 static unsigned int udf_count_free_table(struct super_block
*sb
,
2182 struct inode
*table
)
2184 unsigned int accum
= 0;
2186 struct kernel_lb_addr eloc
;
2188 struct extent_position epos
;
2192 epos
.block
= UDF_I(table
)->i_location
;
2193 epos
.offset
= sizeof(struct unallocSpaceEntry
);
2196 while ((etype
= udf_next_aext(table
, &epos
, &eloc
, &elen
, 1)) != -1)
2197 accum
+= (elen
>> table
->i_sb
->s_blocksize_bits
);
2206 static unsigned int udf_count_free(struct super_block
*sb
)
2208 unsigned int accum
= 0;
2209 struct udf_sb_info
*sbi
;
2210 struct udf_part_map
*map
;
2213 if (sbi
->s_lvid_bh
) {
2214 struct logicalVolIntegrityDesc
*lvid
=
2215 (struct logicalVolIntegrityDesc
*)
2216 sbi
->s_lvid_bh
->b_data
;
2217 if (le32_to_cpu(lvid
->numOfPartitions
) > sbi
->s_partition
) {
2218 accum
= le32_to_cpu(
2219 lvid
->freeSpaceTable
[sbi
->s_partition
]);
2220 if (accum
== 0xFFFFFFFF)
2228 map
= &sbi
->s_partmaps
[sbi
->s_partition
];
2229 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
) {
2230 accum
+= udf_count_free_bitmap(sb
,
2231 map
->s_uspace
.s_bitmap
);
2233 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
) {
2234 accum
+= udf_count_free_bitmap(sb
,
2235 map
->s_fspace
.s_bitmap
);
2240 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
) {
2241 accum
+= udf_count_free_table(sb
,
2242 map
->s_uspace
.s_table
);
2244 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
) {
2245 accum
+= udf_count_free_table(sb
,
2246 map
->s_fspace
.s_table
);