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 int udf_check_valid(struct super_block
*, int, int);
87 static int udf_vrs(struct super_block
*sb
, int silent
);
88 static void udf_load_logicalvolint(struct super_block
*, struct kernel_extent_ad
);
89 static void udf_find_anchor(struct super_block
*);
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 vfsmount
*);
99 static void udf_error(struct super_block
*sb
, const char *function
,
100 const char *fmt
, ...);
102 struct logicalVolIntegrityDescImpUse
*udf_sb_lvidiu(struct udf_sb_info
*sbi
)
104 struct logicalVolIntegrityDesc
*lvid
=
105 (struct logicalVolIntegrityDesc
*)sbi
->s_lvid_bh
->b_data
;
106 __u32 number_of_partitions
= le32_to_cpu(lvid
->numOfPartitions
);
107 __u32 offset
= number_of_partitions
* 2 *
108 sizeof(uint32_t)/sizeof(uint8_t);
109 return (struct logicalVolIntegrityDescImpUse
*)&(lvid
->impUse
[offset
]);
112 /* UDF filesystem type */
113 static int udf_get_sb(struct file_system_type
*fs_type
,
114 int flags
, const char *dev_name
, void *data
,
115 struct vfsmount
*mnt
)
117 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, udf_fill_super
, mnt
);
120 static struct file_system_type udf_fstype
= {
121 .owner
= THIS_MODULE
,
123 .get_sb
= udf_get_sb
,
124 .kill_sb
= kill_block_super
,
125 .fs_flags
= FS_REQUIRES_DEV
,
128 static struct kmem_cache
*udf_inode_cachep
;
130 static struct inode
*udf_alloc_inode(struct super_block
*sb
)
132 struct udf_inode_info
*ei
;
133 ei
= kmem_cache_alloc(udf_inode_cachep
, GFP_KERNEL
);
138 ei
->i_lenExtents
= 0;
139 ei
->i_next_alloc_block
= 0;
140 ei
->i_next_alloc_goal
= 0;
143 return &ei
->vfs_inode
;
146 static void udf_destroy_inode(struct inode
*inode
)
148 kmem_cache_free(udf_inode_cachep
, UDF_I(inode
));
151 static void init_once(void *foo
)
153 struct udf_inode_info
*ei
= (struct udf_inode_info
*)foo
;
155 ei
->i_ext
.i_data
= NULL
;
156 inode_init_once(&ei
->vfs_inode
);
159 static int init_inodecache(void)
161 udf_inode_cachep
= kmem_cache_create("udf_inode_cache",
162 sizeof(struct udf_inode_info
),
163 0, (SLAB_RECLAIM_ACCOUNT
|
166 if (!udf_inode_cachep
)
171 static void destroy_inodecache(void)
173 kmem_cache_destroy(udf_inode_cachep
);
176 /* Superblock operations */
177 static const struct super_operations udf_sb_ops
= {
178 .alloc_inode
= udf_alloc_inode
,
179 .destroy_inode
= udf_destroy_inode
,
180 .write_inode
= udf_write_inode
,
181 .delete_inode
= udf_delete_inode
,
182 .clear_inode
= udf_clear_inode
,
183 .put_super
= udf_put_super
,
184 .write_super
= udf_write_super
,
185 .statfs
= udf_statfs
,
186 .remount_fs
= udf_remount_fs
,
187 .show_options
= udf_show_options
,
192 unsigned int blocksize
;
193 unsigned int session
;
194 unsigned int lastblock
;
197 unsigned short partition
;
198 unsigned int fileset
;
199 unsigned int rootdir
;
206 struct nls_table
*nls_map
;
209 static int __init
init_udf_fs(void)
213 err
= init_inodecache();
216 err
= register_filesystem(&udf_fstype
);
223 destroy_inodecache();
229 static void __exit
exit_udf_fs(void)
231 unregister_filesystem(&udf_fstype
);
232 destroy_inodecache();
235 module_init(init_udf_fs
)
236 module_exit(exit_udf_fs
)
238 static int udf_sb_alloc_partition_maps(struct super_block
*sb
, u32 count
)
240 struct udf_sb_info
*sbi
= UDF_SB(sb
);
242 sbi
->s_partmaps
= kcalloc(count
, sizeof(struct udf_part_map
),
244 if (!sbi
->s_partmaps
) {
245 udf_error(sb
, __func__
,
246 "Unable to allocate space for %d partition maps",
248 sbi
->s_partitions
= 0;
252 sbi
->s_partitions
= count
;
256 static int udf_show_options(struct seq_file
*seq
, struct vfsmount
*mnt
)
258 struct super_block
*sb
= mnt
->mnt_sb
;
259 struct udf_sb_info
*sbi
= UDF_SB(sb
);
261 if (!UDF_QUERY_FLAG(sb
, UDF_FLAG_STRICT
))
262 seq_puts(seq
, ",nostrict");
263 if (sb
->s_blocksize
!= UDF_DEFAULT_BLOCKSIZE
)
264 seq_printf(seq
, ",bs=%lu", sb
->s_blocksize
);
265 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UNHIDE
))
266 seq_puts(seq
, ",unhide");
267 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UNDELETE
))
268 seq_puts(seq
, ",undelete");
269 if (!UDF_QUERY_FLAG(sb
, UDF_FLAG_USE_AD_IN_ICB
))
270 seq_puts(seq
, ",noadinicb");
271 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_USE_SHORT_AD
))
272 seq_puts(seq
, ",shortad");
273 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_FORGET
))
274 seq_puts(seq
, ",uid=forget");
275 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_IGNORE
))
276 seq_puts(seq
, ",uid=ignore");
277 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_FORGET
))
278 seq_puts(seq
, ",gid=forget");
279 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_IGNORE
))
280 seq_puts(seq
, ",gid=ignore");
281 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_SET
))
282 seq_printf(seq
, ",uid=%u", sbi
->s_uid
);
283 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_SET
))
284 seq_printf(seq
, ",gid=%u", sbi
->s_gid
);
285 if (sbi
->s_umask
!= 0)
286 seq_printf(seq
, ",umask=%o", sbi
->s_umask
);
287 if (sbi
->s_fmode
!= -1)
288 seq_printf(seq
, ",mode=%o", sbi
->s_fmode
);
289 if (sbi
->s_dmode
!= -1)
290 seq_printf(seq
, ",dmode=%o", sbi
->s_dmode
);
291 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_SESSION_SET
))
292 seq_printf(seq
, ",session=%u", sbi
->s_session
);
293 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_LASTBLOCK_SET
))
294 seq_printf(seq
, ",lastblock=%u", sbi
->s_last_block
);
296 * s_anchor[2] could be zeroed out in case there is no anchor
297 * in the specified block, but then the "anchor=N" option
298 * originally given by the user wasn't effective, so it's OK
299 * if we don't show it.
301 if (sbi
->s_anchor
[2] != 0)
302 seq_printf(seq
, ",anchor=%u", sbi
->s_anchor
[2]);
304 * volume, partition, fileset and rootdir seem to be ignored
307 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UTF8
))
308 seq_puts(seq
, ",utf8");
309 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
) && sbi
->s_nls_map
)
310 seq_printf(seq
, ",iocharset=%s", sbi
->s_nls_map
->charset
);
319 * Parse mount options.
322 * The following mount options are supported:
324 * gid= Set the default group.
325 * umask= Set the default umask.
326 * mode= Set the default file permissions.
327 * dmode= Set the default directory permissions.
328 * uid= Set the default user.
329 * bs= Set the block size.
330 * unhide Show otherwise hidden files.
331 * undelete Show deleted files in lists.
332 * adinicb Embed data in the inode (default)
333 * noadinicb Don't embed data in the inode
334 * shortad Use short ad's
335 * longad Use long ad's (default)
336 * nostrict Unset strict conformance
337 * iocharset= Set the NLS character set
339 * The remaining are for debugging and disaster recovery:
341 * novrs Skip volume sequence recognition
343 * The following expect a offset from 0.
345 * session= Set the CDROM session (default= last session)
346 * anchor= Override standard anchor location. (default= 256)
347 * volume= Override the VolumeDesc location. (unused)
348 * partition= Override the PartitionDesc location. (unused)
349 * lastblock= Set the last block of the filesystem/
351 * The following expect a offset from the partition root.
353 * fileset= Override the fileset block location. (unused)
354 * rootdir= Override the root directory location. (unused)
355 * WARNING: overriding the rootdir to a non-directory may
356 * yield highly unpredictable results.
359 * options Pointer to mount options string.
360 * uopts Pointer to mount options variable.
363 * <return> 1 Mount options parsed okay.
364 * <return> 0 Error parsing mount options.
367 * July 1, 1997 - Andrew E. Mileski
368 * Written, tested, and released.
372 Opt_novrs
, Opt_nostrict
, Opt_bs
, Opt_unhide
, Opt_undelete
,
373 Opt_noadinicb
, Opt_adinicb
, Opt_shortad
, Opt_longad
,
374 Opt_gid
, Opt_uid
, Opt_umask
, Opt_session
, Opt_lastblock
,
375 Opt_anchor
, Opt_volume
, Opt_partition
, Opt_fileset
,
376 Opt_rootdir
, Opt_utf8
, Opt_iocharset
,
377 Opt_err
, Opt_uforget
, Opt_uignore
, Opt_gforget
, Opt_gignore
,
381 static const match_table_t tokens
= {
382 {Opt_novrs
, "novrs"},
383 {Opt_nostrict
, "nostrict"},
385 {Opt_unhide
, "unhide"},
386 {Opt_undelete
, "undelete"},
387 {Opt_noadinicb
, "noadinicb"},
388 {Opt_adinicb
, "adinicb"},
389 {Opt_shortad
, "shortad"},
390 {Opt_longad
, "longad"},
391 {Opt_uforget
, "uid=forget"},
392 {Opt_uignore
, "uid=ignore"},
393 {Opt_gforget
, "gid=forget"},
394 {Opt_gignore
, "gid=ignore"},
397 {Opt_umask
, "umask=%o"},
398 {Opt_session
, "session=%u"},
399 {Opt_lastblock
, "lastblock=%u"},
400 {Opt_anchor
, "anchor=%u"},
401 {Opt_volume
, "volume=%u"},
402 {Opt_partition
, "partition=%u"},
403 {Opt_fileset
, "fileset=%u"},
404 {Opt_rootdir
, "rootdir=%u"},
406 {Opt_iocharset
, "iocharset=%s"},
407 {Opt_fmode
, "mode=%o"},
408 {Opt_dmode
, "dmode=%o"},
412 static int udf_parse_options(char *options
, struct udf_options
*uopt
,
419 uopt
->blocksize
= UDF_DEFAULT_BLOCKSIZE
;
420 uopt
->partition
= 0xFFFF;
421 uopt
->session
= 0xFFFFFFFF;
424 uopt
->volume
= 0xFFFFFFFF;
425 uopt
->rootdir
= 0xFFFFFFFF;
426 uopt
->fileset
= 0xFFFFFFFF;
427 uopt
->nls_map
= NULL
;
432 while ((p
= strsep(&options
, ",")) != NULL
) {
433 substring_t args
[MAX_OPT_ARGS
];
438 token
= match_token(p
, tokens
, args
);
443 if (match_int(&args
[0], &option
))
445 uopt
->blocksize
= option
;
448 uopt
->flags
|= (1 << UDF_FLAG_UNHIDE
);
451 uopt
->flags
|= (1 << UDF_FLAG_UNDELETE
);
454 uopt
->flags
&= ~(1 << UDF_FLAG_USE_AD_IN_ICB
);
457 uopt
->flags
|= (1 << UDF_FLAG_USE_AD_IN_ICB
);
460 uopt
->flags
|= (1 << UDF_FLAG_USE_SHORT_AD
);
463 uopt
->flags
&= ~(1 << UDF_FLAG_USE_SHORT_AD
);
466 if (match_int(args
, &option
))
469 uopt
->flags
|= (1 << UDF_FLAG_GID_SET
);
472 if (match_int(args
, &option
))
475 uopt
->flags
|= (1 << UDF_FLAG_UID_SET
);
478 if (match_octal(args
, &option
))
480 uopt
->umask
= option
;
483 uopt
->flags
&= ~(1 << UDF_FLAG_STRICT
);
486 if (match_int(args
, &option
))
488 uopt
->session
= option
;
490 uopt
->flags
|= (1 << UDF_FLAG_SESSION_SET
);
493 if (match_int(args
, &option
))
495 uopt
->lastblock
= option
;
497 uopt
->flags
|= (1 << UDF_FLAG_LASTBLOCK_SET
);
500 if (match_int(args
, &option
))
502 uopt
->anchor
= option
;
505 if (match_int(args
, &option
))
507 uopt
->volume
= option
;
510 if (match_int(args
, &option
))
512 uopt
->partition
= option
;
515 if (match_int(args
, &option
))
517 uopt
->fileset
= option
;
520 if (match_int(args
, &option
))
522 uopt
->rootdir
= option
;
525 uopt
->flags
|= (1 << UDF_FLAG_UTF8
);
527 #ifdef CONFIG_UDF_NLS
529 uopt
->nls_map
= load_nls(args
[0].from
);
530 uopt
->flags
|= (1 << UDF_FLAG_NLS_MAP
);
534 uopt
->flags
|= (1 << UDF_FLAG_UID_IGNORE
);
537 uopt
->flags
|= (1 << UDF_FLAG_UID_FORGET
);
540 uopt
->flags
|= (1 << UDF_FLAG_GID_IGNORE
);
543 uopt
->flags
|= (1 << UDF_FLAG_GID_FORGET
);
546 if (match_octal(args
, &option
))
548 uopt
->fmode
= option
& 0777;
551 if (match_octal(args
, &option
))
553 uopt
->dmode
= option
& 0777;
556 printk(KERN_ERR
"udf: bad mount option \"%s\" "
557 "or missing value\n", p
);
564 static void udf_write_super(struct super_block
*sb
)
568 if (!(sb
->s_flags
& MS_RDONLY
))
575 static int udf_remount_fs(struct super_block
*sb
, int *flags
, char *options
)
577 struct udf_options uopt
;
578 struct udf_sb_info
*sbi
= UDF_SB(sb
);
580 uopt
.flags
= sbi
->s_flags
;
581 uopt
.uid
= sbi
->s_uid
;
582 uopt
.gid
= sbi
->s_gid
;
583 uopt
.umask
= sbi
->s_umask
;
584 uopt
.fmode
= sbi
->s_fmode
;
585 uopt
.dmode
= sbi
->s_dmode
;
587 if (!udf_parse_options(options
, &uopt
, true))
590 sbi
->s_flags
= uopt
.flags
;
591 sbi
->s_uid
= uopt
.uid
;
592 sbi
->s_gid
= uopt
.gid
;
593 sbi
->s_umask
= uopt
.umask
;
594 sbi
->s_fmode
= uopt
.fmode
;
595 sbi
->s_dmode
= uopt
.dmode
;
597 if (sbi
->s_lvid_bh
) {
598 int write_rev
= le16_to_cpu(udf_sb_lvidiu(sbi
)->minUDFWriteRev
);
599 if (write_rev
> UDF_MAX_WRITE_VERSION
)
603 if ((*flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
))
605 if (*flags
& MS_RDONLY
)
613 static int udf_vrs(struct super_block
*sb
, int silent
)
615 struct volStructDesc
*vsd
= NULL
;
616 loff_t sector
= 32768;
618 struct buffer_head
*bh
= NULL
;
622 struct udf_sb_info
*sbi
;
624 /* Block size must be a multiple of 512 */
625 if (sb
->s_blocksize
& 511)
629 if (sb
->s_blocksize
< sizeof(struct volStructDesc
))
630 sectorsize
= sizeof(struct volStructDesc
);
632 sectorsize
= sb
->s_blocksize
;
634 sector
+= (sbi
->s_session
<< sb
->s_blocksize_bits
);
636 udf_debug("Starting at sector %u (%ld byte sectors)\n",
637 (unsigned int)(sector
>> sb
->s_blocksize_bits
),
639 /* Process the sequence (if applicable) */
640 for (; !nsr02
&& !nsr03
; sector
+= sectorsize
) {
642 bh
= udf_tread(sb
, sector
>> sb
->s_blocksize_bits
);
646 /* Look for ISO descriptors */
647 vsd
= (struct volStructDesc
*)(bh
->b_data
+
648 (sector
& (sb
->s_blocksize
- 1)));
650 if (vsd
->stdIdent
[0] == 0) {
653 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_CD001
,
656 switch (vsd
->structType
) {
658 udf_debug("ISO9660 Boot Record found\n");
661 udf_debug("ISO9660 Primary Volume Descriptor "
665 udf_debug("ISO9660 Supplementary Volume "
666 "Descriptor found\n");
669 udf_debug("ISO9660 Volume Partition Descriptor "
673 udf_debug("ISO9660 Volume Descriptor Set "
674 "Terminator found\n");
677 udf_debug("ISO9660 VRS (%u) found\n",
681 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_BEA01
,
684 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_TEA01
,
688 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR02
,
691 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR03
,
701 else if (sector
- (sbi
->s_session
<< sb
->s_blocksize_bits
) == 32768)
708 * Check whether there is an anchor block in the given block
710 static int udf_check_anchor_block(struct super_block
*sb
, sector_t block
)
712 struct buffer_head
*bh
;
715 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_VARCONV
) &&
716 udf_fixed_to_variable(block
) >=
717 sb
->s_bdev
->bd_inode
->i_size
>> sb
->s_blocksize_bits
)
720 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
725 return ident
== TAG_IDENT_AVDP
;
728 /* Search for an anchor volume descriptor pointer */
729 static sector_t
udf_scan_anchors(struct super_block
*sb
, sector_t lastblock
)
733 struct udf_sb_info
*sbi
= UDF_SB(sb
);
736 last
[1] = last
[0] - 1;
737 last
[2] = last
[0] + 1;
738 last
[3] = last
[0] - 2;
739 last
[4] = last
[0] - 150;
740 last
[5] = last
[0] - 152;
742 /* according to spec, anchor is in either:
746 * however, if the disc isn't closed, it could be 512 */
748 for (i
= 0; i
< ARRAY_SIZE(last
); i
++) {
751 if (last
[i
] >= sb
->s_bdev
->bd_inode
->i_size
>>
752 sb
->s_blocksize_bits
)
755 if (udf_check_anchor_block(sb
, last
[i
])) {
756 sbi
->s_anchor
[0] = last
[i
];
757 sbi
->s_anchor
[1] = last
[i
] - 256;
764 if (udf_check_anchor_block(sb
, last
[i
] - 256)) {
765 sbi
->s_anchor
[1] = last
[i
] - 256;
770 if (udf_check_anchor_block(sb
, sbi
->s_session
+ 256)) {
771 sbi
->s_anchor
[0] = sbi
->s_session
+ 256;
774 if (udf_check_anchor_block(sb
, sbi
->s_session
+ 512)) {
775 sbi
->s_anchor
[0] = sbi
->s_session
+ 512;
782 * Find an anchor volume descriptor. The function expects sbi->s_lastblock to
783 * be the last block on the media.
785 * Return 1 if not found, 0 if ok
788 static void udf_find_anchor(struct super_block
*sb
)
791 struct buffer_head
*bh
= NULL
;
794 struct udf_sb_info
*sbi
= UDF_SB(sb
);
796 lastblock
= udf_scan_anchors(sb
, sbi
->s_last_block
);
800 /* No anchor found? Try VARCONV conversion of block numbers */
801 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
802 /* Firstly, we try to not convert number of the last block */
803 lastblock
= udf_scan_anchors(sb
,
804 udf_variable_to_fixed(sbi
->s_last_block
));
808 /* Secondly, we try with converted number of the last block */
809 lastblock
= udf_scan_anchors(sb
, sbi
->s_last_block
);
811 /* VARCONV didn't help. Clear it. */
812 UDF_CLEAR_FLAG(sb
, UDF_FLAG_VARCONV
);
817 * Check located anchors and the anchor block supplied via
820 for (i
= 0; i
< ARRAY_SIZE(sbi
->s_anchor
); i
++) {
821 if (!sbi
->s_anchor
[i
])
823 bh
= udf_read_tagged(sb
, sbi
->s_anchor
[i
],
824 sbi
->s_anchor
[i
], &ident
);
826 sbi
->s_anchor
[i
] = 0;
829 if (ident
!= TAG_IDENT_AVDP
)
830 sbi
->s_anchor
[i
] = 0;
834 sbi
->s_last_block
= lastblock
;
837 static int udf_find_fileset(struct super_block
*sb
,
838 struct kernel_lb_addr
*fileset
,
839 struct kernel_lb_addr
*root
)
841 struct buffer_head
*bh
= NULL
;
844 struct udf_sb_info
*sbi
;
846 if (fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
847 fileset
->partitionReferenceNum
!= 0xFFFF) {
848 bh
= udf_read_ptagged(sb
, fileset
, 0, &ident
);
852 } else if (ident
!= TAG_IDENT_FSD
) {
861 /* Search backwards through the partitions */
862 struct kernel_lb_addr newfileset
;
864 /* --> cvg: FIXME - is it reasonable? */
867 for (newfileset
.partitionReferenceNum
= sbi
->s_partitions
- 1;
868 (newfileset
.partitionReferenceNum
!= 0xFFFF &&
869 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
870 fileset
->partitionReferenceNum
== 0xFFFF);
871 newfileset
.partitionReferenceNum
--) {
872 lastblock
= sbi
->s_partmaps
873 [newfileset
.partitionReferenceNum
]
875 newfileset
.logicalBlockNum
= 0;
878 bh
= udf_read_ptagged(sb
, &newfileset
, 0,
881 newfileset
.logicalBlockNum
++;
888 struct spaceBitmapDesc
*sp
;
889 sp
= (struct spaceBitmapDesc
*)
891 newfileset
.logicalBlockNum
+= 1 +
892 ((le32_to_cpu(sp
->numOfBytes
) +
893 sizeof(struct spaceBitmapDesc
)
894 - 1) >> sb
->s_blocksize_bits
);
899 *fileset
= newfileset
;
902 newfileset
.logicalBlockNum
++;
907 } while (newfileset
.logicalBlockNum
< lastblock
&&
908 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
909 fileset
->partitionReferenceNum
== 0xFFFF);
913 if ((fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
914 fileset
->partitionReferenceNum
!= 0xFFFF) && bh
) {
915 udf_debug("Fileset at block=%d, partition=%d\n",
916 fileset
->logicalBlockNum
,
917 fileset
->partitionReferenceNum
);
919 sbi
->s_partition
= fileset
->partitionReferenceNum
;
920 udf_load_fileset(sb
, bh
, root
);
927 static int udf_load_pvoldesc(struct super_block
*sb
, sector_t block
)
929 struct primaryVolDesc
*pvoldesc
;
930 struct ustr
*instr
, *outstr
;
931 struct buffer_head
*bh
;
935 instr
= kmalloc(sizeof(struct ustr
), GFP_NOFS
);
939 outstr
= kmalloc(sizeof(struct ustr
), GFP_NOFS
);
943 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
947 BUG_ON(ident
!= TAG_IDENT_PVD
);
949 pvoldesc
= (struct primaryVolDesc
*)bh
->b_data
;
951 if (udf_disk_stamp_to_time(&UDF_SB(sb
)->s_record_time
,
952 pvoldesc
->recordingDateAndTime
)) {
954 struct timestamp
*ts
= &pvoldesc
->recordingDateAndTime
;
955 udf_debug("recording time %04u/%02u/%02u"
957 le16_to_cpu(ts
->year
), ts
->month
, ts
->day
, ts
->hour
,
958 ts
->minute
, le16_to_cpu(ts
->typeAndTimezone
));
962 if (!udf_build_ustr(instr
, pvoldesc
->volIdent
, 32))
963 if (udf_CS0toUTF8(outstr
, instr
)) {
964 strncpy(UDF_SB(sb
)->s_volume_ident
, outstr
->u_name
,
965 outstr
->u_len
> 31 ? 31 : outstr
->u_len
);
966 udf_debug("volIdent[] = '%s'\n",
967 UDF_SB(sb
)->s_volume_ident
);
970 if (!udf_build_ustr(instr
, pvoldesc
->volSetIdent
, 128))
971 if (udf_CS0toUTF8(outstr
, instr
))
972 udf_debug("volSetIdent[] = '%s'\n", outstr
->u_name
);
983 static int udf_load_metadata_files(struct super_block
*sb
, int partition
)
985 struct udf_sb_info
*sbi
= UDF_SB(sb
);
986 struct udf_part_map
*map
;
987 struct udf_meta_data
*mdata
;
988 struct kernel_lb_addr addr
;
991 map
= &sbi
->s_partmaps
[partition
];
992 mdata
= &map
->s_type_specific
.s_metadata
;
994 /* metadata address */
995 addr
.logicalBlockNum
= mdata
->s_meta_file_loc
;
996 addr
.partitionReferenceNum
= map
->s_partition_num
;
998 udf_debug("Metadata file location: block = %d part = %d\n",
999 addr
.logicalBlockNum
, addr
.partitionReferenceNum
);
1001 mdata
->s_metadata_fe
= udf_iget(sb
, &addr
);
1003 if (mdata
->s_metadata_fe
== NULL
) {
1004 udf_warning(sb
, __func__
, "metadata inode efe not found, "
1005 "will try mirror inode.");
1007 } else if (UDF_I(mdata
->s_metadata_fe
)->i_alloc_type
!=
1008 ICBTAG_FLAG_AD_SHORT
) {
1009 udf_warning(sb
, __func__
, "metadata inode efe does not have "
1010 "short allocation descriptors!");
1012 iput(mdata
->s_metadata_fe
);
1013 mdata
->s_metadata_fe
= NULL
;
1016 /* mirror file entry */
1017 addr
.logicalBlockNum
= mdata
->s_mirror_file_loc
;
1018 addr
.partitionReferenceNum
= map
->s_partition_num
;
1020 udf_debug("Mirror metadata file location: block = %d part = %d\n",
1021 addr
.logicalBlockNum
, addr
.partitionReferenceNum
);
1023 mdata
->s_mirror_fe
= udf_iget(sb
, &addr
);
1025 if (mdata
->s_mirror_fe
== NULL
) {
1027 udf_error(sb
, __func__
, "mirror inode efe not found "
1028 "and metadata inode is missing too, exiting...");
1031 udf_warning(sb
, __func__
, "mirror inode efe not found,"
1032 " but metadata inode is OK");
1033 } else if (UDF_I(mdata
->s_mirror_fe
)->i_alloc_type
!=
1034 ICBTAG_FLAG_AD_SHORT
) {
1035 udf_warning(sb
, __func__
, "mirror inode efe does not have "
1036 "short allocation descriptors!");
1037 iput(mdata
->s_mirror_fe
);
1038 mdata
->s_mirror_fe
= NULL
;
1046 * Load only if bitmap file location differs from 0xFFFFFFFF (DCN-5102)
1048 if (mdata
->s_bitmap_file_loc
!= 0xFFFFFFFF) {
1049 addr
.logicalBlockNum
= mdata
->s_bitmap_file_loc
;
1050 addr
.partitionReferenceNum
= map
->s_partition_num
;
1052 udf_debug("Bitmap file location: block = %d part = %d\n",
1053 addr
.logicalBlockNum
, addr
.partitionReferenceNum
);
1055 mdata
->s_bitmap_fe
= udf_iget(sb
, &addr
);
1057 if (mdata
->s_bitmap_fe
== NULL
) {
1058 if (sb
->s_flags
& MS_RDONLY
)
1059 udf_warning(sb
, __func__
, "bitmap inode efe "
1060 "not found but it's ok since the disc"
1061 " is mounted read-only");
1063 udf_error(sb
, __func__
, "bitmap inode efe not "
1064 "found and attempted read-write mount");
1070 udf_debug("udf_load_metadata_files Ok\n");
1078 static void udf_load_fileset(struct super_block
*sb
, struct buffer_head
*bh
,
1079 struct kernel_lb_addr
*root
)
1081 struct fileSetDesc
*fset
;
1083 fset
= (struct fileSetDesc
*)bh
->b_data
;
1085 *root
= lelb_to_cpu(fset
->rootDirectoryICB
.extLocation
);
1087 UDF_SB(sb
)->s_serial_number
= le16_to_cpu(fset
->descTag
.tagSerialNum
);
1089 udf_debug("Rootdir at block=%d, partition=%d\n",
1090 root
->logicalBlockNum
, root
->partitionReferenceNum
);
1093 int udf_compute_nr_groups(struct super_block
*sb
, u32 partition
)
1095 struct udf_part_map
*map
= &UDF_SB(sb
)->s_partmaps
[partition
];
1096 return DIV_ROUND_UP(map
->s_partition_len
+
1097 (sizeof(struct spaceBitmapDesc
) << 3),
1098 sb
->s_blocksize
* 8);
1101 static struct udf_bitmap
*udf_sb_alloc_bitmap(struct super_block
*sb
, u32 index
)
1103 struct udf_bitmap
*bitmap
;
1107 nr_groups
= udf_compute_nr_groups(sb
, index
);
1108 size
= sizeof(struct udf_bitmap
) +
1109 (sizeof(struct buffer_head
*) * nr_groups
);
1111 if (size
<= PAGE_SIZE
)
1112 bitmap
= kmalloc(size
, GFP_KERNEL
);
1114 bitmap
= vmalloc(size
); /* TODO: get rid of vmalloc */
1116 if (bitmap
== NULL
) {
1117 udf_error(sb
, __func__
,
1118 "Unable to allocate space for bitmap "
1119 "and %d buffer_head pointers", nr_groups
);
1123 memset(bitmap
, 0x00, size
);
1124 bitmap
->s_block_bitmap
= (struct buffer_head
**)(bitmap
+ 1);
1125 bitmap
->s_nr_groups
= nr_groups
;
1129 static int udf_fill_partdesc_info(struct super_block
*sb
,
1130 struct partitionDesc
*p
, int p_index
)
1132 struct udf_part_map
*map
;
1133 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1134 struct partitionHeaderDesc
*phd
;
1136 map
= &sbi
->s_partmaps
[p_index
];
1138 map
->s_partition_len
= le32_to_cpu(p
->partitionLength
); /* blocks */
1139 map
->s_partition_root
= le32_to_cpu(p
->partitionStartingLocation
);
1141 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY
))
1142 map
->s_partition_flags
|= UDF_PART_FLAG_READ_ONLY
;
1143 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE
))
1144 map
->s_partition_flags
|= UDF_PART_FLAG_WRITE_ONCE
;
1145 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE
))
1146 map
->s_partition_flags
|= UDF_PART_FLAG_REWRITABLE
;
1147 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE
))
1148 map
->s_partition_flags
|= UDF_PART_FLAG_OVERWRITABLE
;
1150 udf_debug("Partition (%d type %x) starts at physical %d, "
1151 "block length %d\n", p_index
,
1152 map
->s_partition_type
, map
->s_partition_root
,
1153 map
->s_partition_len
);
1155 if (strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR02
) &&
1156 strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR03
))
1159 phd
= (struct partitionHeaderDesc
*)p
->partitionContentsUse
;
1160 if (phd
->unallocSpaceTable
.extLength
) {
1161 struct kernel_lb_addr loc
= {
1162 .logicalBlockNum
= le32_to_cpu(
1163 phd
->unallocSpaceTable
.extPosition
),
1164 .partitionReferenceNum
= p_index
,
1167 map
->s_uspace
.s_table
= udf_iget(sb
, &loc
);
1168 if (!map
->s_uspace
.s_table
) {
1169 udf_debug("cannot load unallocSpaceTable (part %d)\n",
1173 map
->s_partition_flags
|= UDF_PART_FLAG_UNALLOC_TABLE
;
1174 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
1175 p_index
, map
->s_uspace
.s_table
->i_ino
);
1178 if (phd
->unallocSpaceBitmap
.extLength
) {
1179 struct udf_bitmap
*bitmap
= udf_sb_alloc_bitmap(sb
, p_index
);
1182 map
->s_uspace
.s_bitmap
= bitmap
;
1183 bitmap
->s_extLength
= le32_to_cpu(
1184 phd
->unallocSpaceBitmap
.extLength
);
1185 bitmap
->s_extPosition
= le32_to_cpu(
1186 phd
->unallocSpaceBitmap
.extPosition
);
1187 map
->s_partition_flags
|= UDF_PART_FLAG_UNALLOC_BITMAP
;
1188 udf_debug("unallocSpaceBitmap (part %d) @ %d\n", p_index
,
1189 bitmap
->s_extPosition
);
1192 if (phd
->partitionIntegrityTable
.extLength
)
1193 udf_debug("partitionIntegrityTable (part %d)\n", p_index
);
1195 if (phd
->freedSpaceTable
.extLength
) {
1196 struct kernel_lb_addr loc
= {
1197 .logicalBlockNum
= le32_to_cpu(
1198 phd
->freedSpaceTable
.extPosition
),
1199 .partitionReferenceNum
= p_index
,
1202 map
->s_fspace
.s_table
= udf_iget(sb
, &loc
);
1203 if (!map
->s_fspace
.s_table
) {
1204 udf_debug("cannot load freedSpaceTable (part %d)\n",
1209 map
->s_partition_flags
|= UDF_PART_FLAG_FREED_TABLE
;
1210 udf_debug("freedSpaceTable (part %d) @ %ld\n",
1211 p_index
, map
->s_fspace
.s_table
->i_ino
);
1214 if (phd
->freedSpaceBitmap
.extLength
) {
1215 struct udf_bitmap
*bitmap
= udf_sb_alloc_bitmap(sb
, p_index
);
1218 map
->s_fspace
.s_bitmap
= bitmap
;
1219 bitmap
->s_extLength
= le32_to_cpu(
1220 phd
->freedSpaceBitmap
.extLength
);
1221 bitmap
->s_extPosition
= le32_to_cpu(
1222 phd
->freedSpaceBitmap
.extPosition
);
1223 map
->s_partition_flags
|= UDF_PART_FLAG_FREED_BITMAP
;
1224 udf_debug("freedSpaceBitmap (part %d) @ %d\n", p_index
,
1225 bitmap
->s_extPosition
);
1230 static int udf_load_vat(struct super_block
*sb
, int p_index
, int type1_index
)
1232 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1233 struct udf_part_map
*map
= &sbi
->s_partmaps
[p_index
];
1234 struct kernel_lb_addr ino
;
1235 struct buffer_head
*bh
= NULL
;
1236 struct udf_inode_info
*vati
;
1238 struct virtualAllocationTable20
*vat20
;
1240 /* VAT file entry is in the last recorded block */
1241 ino
.partitionReferenceNum
= type1_index
;
1242 ino
.logicalBlockNum
= sbi
->s_last_block
- map
->s_partition_root
;
1243 sbi
->s_vat_inode
= udf_iget(sb
, &ino
);
1244 if (!sbi
->s_vat_inode
)
1247 if (map
->s_partition_type
== UDF_VIRTUAL_MAP15
) {
1248 map
->s_type_specific
.s_virtual
.s_start_offset
= 0;
1249 map
->s_type_specific
.s_virtual
.s_num_entries
=
1250 (sbi
->s_vat_inode
->i_size
- 36) >> 2;
1251 } else if (map
->s_partition_type
== UDF_VIRTUAL_MAP20
) {
1252 vati
= UDF_I(sbi
->s_vat_inode
);
1253 if (vati
->i_alloc_type
!= ICBTAG_FLAG_AD_IN_ICB
) {
1254 pos
= udf_block_map(sbi
->s_vat_inode
, 0);
1255 bh
= sb_bread(sb
, pos
);
1258 vat20
= (struct virtualAllocationTable20
*)bh
->b_data
;
1260 vat20
= (struct virtualAllocationTable20
*)
1264 map
->s_type_specific
.s_virtual
.s_start_offset
=
1265 le16_to_cpu(vat20
->lengthHeader
);
1266 map
->s_type_specific
.s_virtual
.s_num_entries
=
1267 (sbi
->s_vat_inode
->i_size
-
1268 map
->s_type_specific
.s_virtual
.
1269 s_start_offset
) >> 2;
1275 static int udf_load_partdesc(struct super_block
*sb
, sector_t block
)
1277 struct buffer_head
*bh
;
1278 struct partitionDesc
*p
;
1279 struct udf_part_map
*map
;
1280 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1282 uint16_t partitionNumber
;
1286 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1289 if (ident
!= TAG_IDENT_PD
)
1292 p
= (struct partitionDesc
*)bh
->b_data
;
1293 partitionNumber
= le16_to_cpu(p
->partitionNumber
);
1295 /* First scan for TYPE1, SPARABLE and METADATA partitions */
1296 for (i
= 0; i
< sbi
->s_partitions
; i
++) {
1297 map
= &sbi
->s_partmaps
[i
];
1298 udf_debug("Searching map: (%d == %d)\n",
1299 map
->s_partition_num
, partitionNumber
);
1300 if (map
->s_partition_num
== partitionNumber
&&
1301 (map
->s_partition_type
== UDF_TYPE1_MAP15
||
1302 map
->s_partition_type
== UDF_SPARABLE_MAP15
))
1306 if (i
>= sbi
->s_partitions
) {
1307 udf_debug("Partition (%d) not found in partition map\n",
1312 ret
= udf_fill_partdesc_info(sb
, p
, i
);
1315 * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and
1316 * PHYSICAL partitions are already set up
1319 for (i
= 0; i
< sbi
->s_partitions
; i
++) {
1320 map
= &sbi
->s_partmaps
[i
];
1322 if (map
->s_partition_num
== partitionNumber
&&
1323 (map
->s_partition_type
== UDF_VIRTUAL_MAP15
||
1324 map
->s_partition_type
== UDF_VIRTUAL_MAP20
||
1325 map
->s_partition_type
== UDF_METADATA_MAP25
))
1329 if (i
>= sbi
->s_partitions
)
1332 ret
= udf_fill_partdesc_info(sb
, p
, i
);
1336 if (map
->s_partition_type
== UDF_METADATA_MAP25
) {
1337 ret
= udf_load_metadata_files(sb
, i
);
1339 printk(KERN_ERR
"UDF-fs: error loading MetaData "
1340 "partition map %d\n", i
);
1344 ret
= udf_load_vat(sb
, i
, type1_idx
);
1348 * Mark filesystem read-only if we have a partition with
1349 * virtual map since we don't handle writing to it (we
1350 * overwrite blocks instead of relocating them).
1352 sb
->s_flags
|= MS_RDONLY
;
1353 printk(KERN_NOTICE
"UDF-fs: Filesystem marked read-only "
1354 "because writing to pseudooverwrite partition is "
1355 "not implemented.\n");
1358 /* In case loading failed, we handle cleanup in udf_fill_super */
1363 static int udf_load_logicalvol(struct super_block
*sb
, sector_t block
,
1364 struct kernel_lb_addr
*fileset
)
1366 struct logicalVolDesc
*lvd
;
1369 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1370 struct genericPartitionMap
*gpm
;
1372 struct buffer_head
*bh
;
1375 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1378 BUG_ON(ident
!= TAG_IDENT_LVD
);
1379 lvd
= (struct logicalVolDesc
*)bh
->b_data
;
1381 i
= udf_sb_alloc_partition_maps(sb
, le32_to_cpu(lvd
->numPartitionMaps
));
1387 for (i
= 0, offset
= 0;
1388 i
< sbi
->s_partitions
&& offset
< le32_to_cpu(lvd
->mapTableLength
);
1389 i
++, offset
+= gpm
->partitionMapLength
) {
1390 struct udf_part_map
*map
= &sbi
->s_partmaps
[i
];
1391 gpm
= (struct genericPartitionMap
*)
1392 &(lvd
->partitionMaps
[offset
]);
1393 type
= gpm
->partitionMapType
;
1395 struct genericPartitionMap1
*gpm1
=
1396 (struct genericPartitionMap1
*)gpm
;
1397 map
->s_partition_type
= UDF_TYPE1_MAP15
;
1398 map
->s_volumeseqnum
= le16_to_cpu(gpm1
->volSeqNum
);
1399 map
->s_partition_num
= le16_to_cpu(gpm1
->partitionNum
);
1400 map
->s_partition_func
= NULL
;
1401 } else if (type
== 2) {
1402 struct udfPartitionMap2
*upm2
=
1403 (struct udfPartitionMap2
*)gpm
;
1404 if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_VIRTUAL
,
1405 strlen(UDF_ID_VIRTUAL
))) {
1407 le16_to_cpu(((__le16
*)upm2
->partIdent
.
1410 map
->s_partition_type
=
1412 map
->s_partition_func
=
1413 udf_get_pblock_virt15
;
1415 map
->s_partition_type
=
1417 map
->s_partition_func
=
1418 udf_get_pblock_virt20
;
1420 } else if (!strncmp(upm2
->partIdent
.ident
,
1422 strlen(UDF_ID_SPARABLE
))) {
1424 struct sparingTable
*st
;
1425 struct sparablePartitionMap
*spm
=
1426 (struct sparablePartitionMap
*)gpm
;
1428 map
->s_partition_type
= UDF_SPARABLE_MAP15
;
1429 map
->s_type_specific
.s_sparing
.s_packet_len
=
1430 le16_to_cpu(spm
->packetLength
);
1431 for (j
= 0; j
< spm
->numSparingTables
; j
++) {
1432 struct buffer_head
*bh2
;
1435 spm
->locSparingTable
[j
]);
1436 bh2
= udf_read_tagged(sb
, loc
, loc
,
1438 map
->s_type_specific
.s_sparing
.
1439 s_spar_map
[j
] = bh2
;
1444 st
= (struct sparingTable
*)bh2
->b_data
;
1445 if (ident
!= 0 || strncmp(
1446 st
->sparingIdent
.ident
,
1448 strlen(UDF_ID_SPARING
))) {
1450 map
->s_type_specific
.s_sparing
.
1451 s_spar_map
[j
] = NULL
;
1454 map
->s_partition_func
= udf_get_pblock_spar15
;
1455 } else if (!strncmp(upm2
->partIdent
.ident
,
1457 strlen(UDF_ID_METADATA
))) {
1458 struct udf_meta_data
*mdata
=
1459 &map
->s_type_specific
.s_metadata
;
1460 struct metadataPartitionMap
*mdm
=
1461 (struct metadataPartitionMap
*)
1462 &(lvd
->partitionMaps
[offset
]);
1463 udf_debug("Parsing Logical vol part %d "
1464 "type %d id=%s\n", i
, type
,
1467 map
->s_partition_type
= UDF_METADATA_MAP25
;
1468 map
->s_partition_func
= udf_get_pblock_meta25
;
1470 mdata
->s_meta_file_loc
=
1471 le32_to_cpu(mdm
->metadataFileLoc
);
1472 mdata
->s_mirror_file_loc
=
1473 le32_to_cpu(mdm
->metadataMirrorFileLoc
);
1474 mdata
->s_bitmap_file_loc
=
1475 le32_to_cpu(mdm
->metadataBitmapFileLoc
);
1476 mdata
->s_alloc_unit_size
=
1477 le32_to_cpu(mdm
->allocUnitSize
);
1478 mdata
->s_align_unit_size
=
1479 le16_to_cpu(mdm
->alignUnitSize
);
1480 mdata
->s_dup_md_flag
=
1483 udf_debug("Metadata Ident suffix=0x%x\n",
1486 mdm
->partIdent
.identSuffix
)[0])));
1487 udf_debug("Metadata part num=%d\n",
1488 le16_to_cpu(mdm
->partitionNum
));
1489 udf_debug("Metadata part alloc unit size=%d\n",
1490 le32_to_cpu(mdm
->allocUnitSize
));
1491 udf_debug("Metadata file loc=%d\n",
1492 le32_to_cpu(mdm
->metadataFileLoc
));
1493 udf_debug("Mirror file loc=%d\n",
1494 le32_to_cpu(mdm
->metadataMirrorFileLoc
));
1495 udf_debug("Bitmap file loc=%d\n",
1496 le32_to_cpu(mdm
->metadataBitmapFileLoc
));
1497 udf_debug("Duplicate Flag: %d %d\n",
1498 mdata
->s_dup_md_flag
, mdm
->flags
);
1500 udf_debug("Unknown ident: %s\n",
1501 upm2
->partIdent
.ident
);
1504 map
->s_volumeseqnum
= le16_to_cpu(upm2
->volSeqNum
);
1505 map
->s_partition_num
= le16_to_cpu(upm2
->partitionNum
);
1507 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1508 i
, map
->s_partition_num
, type
,
1509 map
->s_volumeseqnum
);
1513 struct long_ad
*la
= (struct long_ad
*)&(lvd
->logicalVolContentsUse
[0]);
1515 *fileset
= lelb_to_cpu(la
->extLocation
);
1516 udf_debug("FileSet found in LogicalVolDesc at block=%d, "
1517 "partition=%d\n", fileset
->logicalBlockNum
,
1518 fileset
->partitionReferenceNum
);
1520 if (lvd
->integritySeqExt
.extLength
)
1521 udf_load_logicalvolint(sb
, leea_to_cpu(lvd
->integritySeqExt
));
1529 * udf_load_logicalvolint
1532 static void udf_load_logicalvolint(struct super_block
*sb
, struct kernel_extent_ad loc
)
1534 struct buffer_head
*bh
= NULL
;
1536 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1537 struct logicalVolIntegrityDesc
*lvid
;
1539 while (loc
.extLength
> 0 &&
1540 (bh
= udf_read_tagged(sb
, loc
.extLocation
,
1541 loc
.extLocation
, &ident
)) &&
1542 ident
== TAG_IDENT_LVID
) {
1543 sbi
->s_lvid_bh
= bh
;
1544 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1546 if (lvid
->nextIntegrityExt
.extLength
)
1547 udf_load_logicalvolint(sb
,
1548 leea_to_cpu(lvid
->nextIntegrityExt
));
1550 if (sbi
->s_lvid_bh
!= bh
)
1552 loc
.extLength
-= sb
->s_blocksize
;
1555 if (sbi
->s_lvid_bh
!= bh
)
1560 * udf_process_sequence
1563 * Process a main/reserve volume descriptor sequence.
1566 * sb Pointer to _locked_ superblock.
1567 * block First block of first extent of the sequence.
1568 * lastblock Lastblock of first extent of the sequence.
1571 * July 1, 1997 - Andrew E. Mileski
1572 * Written, tested, and released.
1574 static noinline
int udf_process_sequence(struct super_block
*sb
, long block
,
1575 long lastblock
, struct kernel_lb_addr
*fileset
)
1577 struct buffer_head
*bh
= NULL
;
1578 struct udf_vds_record vds
[VDS_POS_LENGTH
];
1579 struct udf_vds_record
*curr
;
1580 struct generic_desc
*gd
;
1581 struct volDescPtr
*vdp
;
1585 long next_s
= 0, next_e
= 0;
1587 memset(vds
, 0, sizeof(struct udf_vds_record
) * VDS_POS_LENGTH
);
1590 * Read the main descriptor sequence and find which descriptors
1593 for (; (!done
&& block
<= lastblock
); block
++) {
1595 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1597 printk(KERN_ERR
"udf: Block %Lu of volume descriptor "
1598 "sequence is corrupted or we could not read "
1599 "it.\n", (unsigned long long)block
);
1603 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1604 gd
= (struct generic_desc
*)bh
->b_data
;
1605 vdsn
= le32_to_cpu(gd
->volDescSeqNum
);
1607 case TAG_IDENT_PVD
: /* ISO 13346 3/10.1 */
1608 curr
= &vds
[VDS_POS_PRIMARY_VOL_DESC
];
1609 if (vdsn
>= curr
->volDescSeqNum
) {
1610 curr
->volDescSeqNum
= vdsn
;
1611 curr
->block
= block
;
1614 case TAG_IDENT_VDP
: /* ISO 13346 3/10.3 */
1615 curr
= &vds
[VDS_POS_VOL_DESC_PTR
];
1616 if (vdsn
>= curr
->volDescSeqNum
) {
1617 curr
->volDescSeqNum
= vdsn
;
1618 curr
->block
= block
;
1620 vdp
= (struct volDescPtr
*)bh
->b_data
;
1621 next_s
= le32_to_cpu(
1622 vdp
->nextVolDescSeqExt
.extLocation
);
1623 next_e
= le32_to_cpu(
1624 vdp
->nextVolDescSeqExt
.extLength
);
1625 next_e
= next_e
>> sb
->s_blocksize_bits
;
1629 case TAG_IDENT_IUVD
: /* ISO 13346 3/10.4 */
1630 curr
= &vds
[VDS_POS_IMP_USE_VOL_DESC
];
1631 if (vdsn
>= curr
->volDescSeqNum
) {
1632 curr
->volDescSeqNum
= vdsn
;
1633 curr
->block
= block
;
1636 case TAG_IDENT_PD
: /* ISO 13346 3/10.5 */
1637 curr
= &vds
[VDS_POS_PARTITION_DESC
];
1639 curr
->block
= block
;
1641 case TAG_IDENT_LVD
: /* ISO 13346 3/10.6 */
1642 curr
= &vds
[VDS_POS_LOGICAL_VOL_DESC
];
1643 if (vdsn
>= curr
->volDescSeqNum
) {
1644 curr
->volDescSeqNum
= vdsn
;
1645 curr
->block
= block
;
1648 case TAG_IDENT_USD
: /* ISO 13346 3/10.8 */
1649 curr
= &vds
[VDS_POS_UNALLOC_SPACE_DESC
];
1650 if (vdsn
>= curr
->volDescSeqNum
) {
1651 curr
->volDescSeqNum
= vdsn
;
1652 curr
->block
= block
;
1655 case TAG_IDENT_TD
: /* ISO 13346 3/10.9 */
1656 vds
[VDS_POS_TERMINATING_DESC
].block
= block
;
1660 next_s
= next_e
= 0;
1668 * Now read interesting descriptors again and process them
1669 * in a suitable order
1671 if (!vds
[VDS_POS_PRIMARY_VOL_DESC
].block
) {
1672 printk(KERN_ERR
"udf: Primary Volume Descriptor not found!\n");
1675 if (udf_load_pvoldesc(sb
, vds
[VDS_POS_PRIMARY_VOL_DESC
].block
))
1678 if (vds
[VDS_POS_LOGICAL_VOL_DESC
].block
&& udf_load_logicalvol(sb
,
1679 vds
[VDS_POS_LOGICAL_VOL_DESC
].block
, fileset
))
1682 if (vds
[VDS_POS_PARTITION_DESC
].block
) {
1684 * We rescan the whole descriptor sequence to find
1685 * partition descriptor blocks and process them.
1687 for (block
= vds
[VDS_POS_PARTITION_DESC
].block
;
1688 block
< vds
[VDS_POS_TERMINATING_DESC
].block
;
1690 if (udf_load_partdesc(sb
, block
))
1700 static int udf_check_valid(struct super_block
*sb
, int novrs
, int silent
)
1703 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1706 udf_debug("Validity check skipped because of novrs option\n");
1709 /* Check that it is NSR02 compliant */
1710 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1711 block
= udf_vrs(sb
, silent
);
1713 udf_debug("Failed to read byte 32768. Assuming open "
1714 "disc. Skipping validity check\n");
1715 if (block
&& !sbi
->s_last_block
)
1716 sbi
->s_last_block
= udf_get_last_block(sb
);
1720 static int udf_load_sequence(struct super_block
*sb
, struct kernel_lb_addr
*fileset
)
1722 struct anchorVolDescPtr
*anchor
;
1724 struct buffer_head
*bh
;
1725 long main_s
, main_e
, reserve_s
, reserve_e
;
1727 struct udf_sb_info
*sbi
;
1733 for (i
= 0; i
< ARRAY_SIZE(sbi
->s_anchor
); i
++) {
1734 if (!sbi
->s_anchor
[i
])
1737 bh
= udf_read_tagged(sb
, sbi
->s_anchor
[i
], sbi
->s_anchor
[i
],
1742 anchor
= (struct anchorVolDescPtr
*)bh
->b_data
;
1744 /* Locate the main sequence */
1745 main_s
= le32_to_cpu(anchor
->mainVolDescSeqExt
.extLocation
);
1746 main_e
= le32_to_cpu(anchor
->mainVolDescSeqExt
.extLength
);
1747 main_e
= main_e
>> sb
->s_blocksize_bits
;
1750 /* Locate the reserve sequence */
1751 reserve_s
= le32_to_cpu(
1752 anchor
->reserveVolDescSeqExt
.extLocation
);
1753 reserve_e
= le32_to_cpu(
1754 anchor
->reserveVolDescSeqExt
.extLength
);
1755 reserve_e
= reserve_e
>> sb
->s_blocksize_bits
;
1756 reserve_e
+= reserve_s
;
1760 /* Process the main & reserve sequences */
1761 /* responsible for finding the PartitionDesc(s) */
1762 if (!(udf_process_sequence(sb
, main_s
, main_e
,
1764 udf_process_sequence(sb
, reserve_s
, reserve_e
,
1769 if (i
== ARRAY_SIZE(sbi
->s_anchor
)) {
1770 udf_debug("No Anchor block found\n");
1773 udf_debug("Using anchor in block %d\n", sbi
->s_anchor
[i
]);
1778 static void udf_open_lvid(struct super_block
*sb
)
1780 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1781 struct buffer_head
*bh
= sbi
->s_lvid_bh
;
1782 struct logicalVolIntegrityDesc
*lvid
;
1783 struct logicalVolIntegrityDescImpUse
*lvidiu
;
1787 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1788 lvidiu
= udf_sb_lvidiu(sbi
);
1790 lvidiu
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1791 lvidiu
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1792 udf_time_to_disk_stamp(&lvid
->recordingDateAndTime
,
1794 lvid
->integrityType
= LVID_INTEGRITY_TYPE_OPEN
;
1796 lvid
->descTag
.descCRC
= cpu_to_le16(
1797 crc_itu_t(0, (char *)lvid
+ sizeof(struct tag
),
1798 le16_to_cpu(lvid
->descTag
.descCRCLength
)));
1800 lvid
->descTag
.tagChecksum
= udf_tag_checksum(&lvid
->descTag
);
1801 mark_buffer_dirty(bh
);
1804 static void udf_close_lvid(struct super_block
*sb
)
1806 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1807 struct buffer_head
*bh
= sbi
->s_lvid_bh
;
1808 struct logicalVolIntegrityDesc
*lvid
;
1809 struct logicalVolIntegrityDescImpUse
*lvidiu
;
1814 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1816 if (lvid
->integrityType
!= LVID_INTEGRITY_TYPE_OPEN
)
1819 lvidiu
= udf_sb_lvidiu(sbi
);
1820 lvidiu
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1821 lvidiu
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1822 udf_time_to_disk_stamp(&lvid
->recordingDateAndTime
, CURRENT_TIME
);
1823 if (UDF_MAX_WRITE_VERSION
> le16_to_cpu(lvidiu
->maxUDFWriteRev
))
1824 lvidiu
->maxUDFWriteRev
= cpu_to_le16(UDF_MAX_WRITE_VERSION
);
1825 if (sbi
->s_udfrev
> le16_to_cpu(lvidiu
->minUDFReadRev
))
1826 lvidiu
->minUDFReadRev
= cpu_to_le16(sbi
->s_udfrev
);
1827 if (sbi
->s_udfrev
> le16_to_cpu(lvidiu
->minUDFWriteRev
))
1828 lvidiu
->minUDFWriteRev
= cpu_to_le16(sbi
->s_udfrev
);
1829 lvid
->integrityType
= cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE
);
1831 lvid
->descTag
.descCRC
= cpu_to_le16(
1832 crc_itu_t(0, (char *)lvid
+ sizeof(struct tag
),
1833 le16_to_cpu(lvid
->descTag
.descCRCLength
)));
1835 lvid
->descTag
.tagChecksum
= udf_tag_checksum(&lvid
->descTag
);
1836 mark_buffer_dirty(bh
);
1839 static void udf_sb_free_bitmap(struct udf_bitmap
*bitmap
)
1842 int nr_groups
= bitmap
->s_nr_groups
;
1843 int size
= sizeof(struct udf_bitmap
) + (sizeof(struct buffer_head
*) *
1846 for (i
= 0; i
< nr_groups
; i
++)
1847 if (bitmap
->s_block_bitmap
[i
])
1848 brelse(bitmap
->s_block_bitmap
[i
]);
1850 if (size
<= PAGE_SIZE
)
1856 static void udf_free_partition(struct udf_part_map
*map
)
1859 struct udf_meta_data
*mdata
;
1861 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
)
1862 iput(map
->s_uspace
.s_table
);
1863 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
)
1864 iput(map
->s_fspace
.s_table
);
1865 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
)
1866 udf_sb_free_bitmap(map
->s_uspace
.s_bitmap
);
1867 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
)
1868 udf_sb_free_bitmap(map
->s_fspace
.s_bitmap
);
1869 if (map
->s_partition_type
== UDF_SPARABLE_MAP15
)
1870 for (i
= 0; i
< 4; i
++)
1871 brelse(map
->s_type_specific
.s_sparing
.s_spar_map
[i
]);
1872 else if (map
->s_partition_type
== UDF_METADATA_MAP25
) {
1873 mdata
= &map
->s_type_specific
.s_metadata
;
1874 iput(mdata
->s_metadata_fe
);
1875 mdata
->s_metadata_fe
= NULL
;
1877 iput(mdata
->s_mirror_fe
);
1878 mdata
->s_mirror_fe
= NULL
;
1880 iput(mdata
->s_bitmap_fe
);
1881 mdata
->s_bitmap_fe
= NULL
;
1885 static int udf_fill_super(struct super_block
*sb
, void *options
, int silent
)
1888 struct inode
*inode
= NULL
;
1889 struct udf_options uopt
;
1890 struct kernel_lb_addr rootdir
, fileset
;
1891 struct udf_sb_info
*sbi
;
1893 uopt
.flags
= (1 << UDF_FLAG_USE_AD_IN_ICB
) | (1 << UDF_FLAG_STRICT
);
1900 sbi
= kzalloc(sizeof(struct udf_sb_info
), GFP_KERNEL
);
1904 sb
->s_fs_info
= sbi
;
1906 mutex_init(&sbi
->s_alloc_mutex
);
1908 if (!udf_parse_options((char *)options
, &uopt
, false))
1911 if (uopt
.flags
& (1 << UDF_FLAG_UTF8
) &&
1912 uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) {
1913 udf_error(sb
, "udf_read_super",
1914 "utf8 cannot be combined with iocharset\n");
1917 #ifdef CONFIG_UDF_NLS
1918 if ((uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) && !uopt
.nls_map
) {
1919 uopt
.nls_map
= load_nls_default();
1921 uopt
.flags
&= ~(1 << UDF_FLAG_NLS_MAP
);
1923 udf_debug("Using default NLS map\n");
1926 if (!(uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)))
1927 uopt
.flags
|= (1 << UDF_FLAG_UTF8
);
1929 fileset
.logicalBlockNum
= 0xFFFFFFFF;
1930 fileset
.partitionReferenceNum
= 0xFFFF;
1932 sbi
->s_flags
= uopt
.flags
;
1933 sbi
->s_uid
= uopt
.uid
;
1934 sbi
->s_gid
= uopt
.gid
;
1935 sbi
->s_umask
= uopt
.umask
;
1936 sbi
->s_fmode
= uopt
.fmode
;
1937 sbi
->s_dmode
= uopt
.dmode
;
1938 sbi
->s_nls_map
= uopt
.nls_map
;
1940 /* Set the block size for all transfers */
1941 if (!sb_min_blocksize(sb
, uopt
.blocksize
)) {
1942 udf_debug("Bad block size (%d)\n", uopt
.blocksize
);
1943 printk(KERN_ERR
"udf: bad block size (%d)\n", uopt
.blocksize
);
1947 if (uopt
.session
== 0xFFFFFFFF)
1948 sbi
->s_session
= udf_get_last_session(sb
);
1950 sbi
->s_session
= uopt
.session
;
1952 udf_debug("Multi-session=%d\n", sbi
->s_session
);
1954 sbi
->s_last_block
= uopt
.lastblock
;
1955 sbi
->s_anchor
[0] = sbi
->s_anchor
[1] = 0;
1956 sbi
->s_anchor
[2] = uopt
.anchor
;
1958 if (udf_check_valid(sb
, uopt
.novrs
, silent
)) {
1959 /* read volume recognition sequences */
1960 printk(KERN_WARNING
"UDF-fs: No VRS found\n");
1964 udf_find_anchor(sb
);
1966 /* Fill in the rest of the superblock */
1967 sb
->s_op
= &udf_sb_ops
;
1968 sb
->s_export_op
= &udf_export_ops
;
1971 sb
->s_magic
= UDF_SUPER_MAGIC
;
1972 sb
->s_time_gran
= 1000;
1974 if (udf_load_sequence(sb
, &fileset
)) {
1975 printk(KERN_WARNING
"UDF-fs: No partition found (1)\n");
1979 udf_debug("Lastblock=%d\n", sbi
->s_last_block
);
1981 if (sbi
->s_lvid_bh
) {
1982 struct logicalVolIntegrityDescImpUse
*lvidiu
=
1984 uint16_t minUDFReadRev
= le16_to_cpu(lvidiu
->minUDFReadRev
);
1985 uint16_t minUDFWriteRev
= le16_to_cpu(lvidiu
->minUDFWriteRev
);
1986 /* uint16_t maxUDFWriteRev =
1987 le16_to_cpu(lvidiu->maxUDFWriteRev); */
1989 if (minUDFReadRev
> UDF_MAX_READ_VERSION
) {
1990 printk(KERN_ERR
"UDF-fs: minUDFReadRev=%x "
1992 le16_to_cpu(lvidiu
->minUDFReadRev
),
1993 UDF_MAX_READ_VERSION
);
1995 } else if (minUDFWriteRev
> UDF_MAX_WRITE_VERSION
)
1996 sb
->s_flags
|= MS_RDONLY
;
1998 sbi
->s_udfrev
= minUDFWriteRev
;
2000 if (minUDFReadRev
>= UDF_VERS_USE_EXTENDED_FE
)
2001 UDF_SET_FLAG(sb
, UDF_FLAG_USE_EXTENDED_FE
);
2002 if (minUDFReadRev
>= UDF_VERS_USE_STREAMS
)
2003 UDF_SET_FLAG(sb
, UDF_FLAG_USE_STREAMS
);
2006 if (!sbi
->s_partitions
) {
2007 printk(KERN_WARNING
"UDF-fs: No partition found (2)\n");
2011 if (sbi
->s_partmaps
[sbi
->s_partition
].s_partition_flags
&
2012 UDF_PART_FLAG_READ_ONLY
) {
2013 printk(KERN_NOTICE
"UDF-fs: Partition marked readonly; "
2014 "forcing readonly mount\n");
2015 sb
->s_flags
|= MS_RDONLY
;
2018 if (udf_find_fileset(sb
, &fileset
, &rootdir
)) {
2019 printk(KERN_WARNING
"UDF-fs: No fileset found\n");
2024 struct timestamp ts
;
2025 udf_time_to_disk_stamp(&ts
, sbi
->s_record_time
);
2026 udf_info("UDF: Mounting volume '%s', "
2027 "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
2028 sbi
->s_volume_ident
, le16_to_cpu(ts
.year
), ts
.month
, ts
.day
,
2029 ts
.hour
, ts
.minute
, le16_to_cpu(ts
.typeAndTimezone
));
2031 if (!(sb
->s_flags
& MS_RDONLY
))
2034 /* Assign the root inode */
2035 /* assign inodes by physical block number */
2036 /* perhaps it's not extensible enough, but for now ... */
2037 inode
= udf_iget(sb
, &rootdir
);
2039 printk(KERN_ERR
"UDF-fs: Error in udf_iget, block=%d, "
2041 rootdir
.logicalBlockNum
, rootdir
.partitionReferenceNum
);
2045 /* Allocate a dentry for the root inode */
2046 sb
->s_root
= d_alloc_root(inode
);
2048 printk(KERN_ERR
"UDF-fs: Couldn't allocate root dentry\n");
2052 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
2056 if (sbi
->s_vat_inode
)
2057 iput(sbi
->s_vat_inode
);
2058 if (sbi
->s_partitions
)
2059 for (i
= 0; i
< sbi
->s_partitions
; i
++)
2060 udf_free_partition(&sbi
->s_partmaps
[i
]);
2061 #ifdef CONFIG_UDF_NLS
2062 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
2063 unload_nls(sbi
->s_nls_map
);
2065 if (!(sb
->s_flags
& MS_RDONLY
))
2067 brelse(sbi
->s_lvid_bh
);
2069 kfree(sbi
->s_partmaps
);
2071 sb
->s_fs_info
= NULL
;
2076 static void udf_error(struct super_block
*sb
, const char *function
,
2077 const char *fmt
, ...)
2081 if (!(sb
->s_flags
& MS_RDONLY
)) {
2085 va_start(args
, fmt
);
2086 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
2088 printk(KERN_CRIT
"UDF-fs error (device %s): %s: %s\n",
2089 sb
->s_id
, function
, error_buf
);
2092 void udf_warning(struct super_block
*sb
, const char *function
,
2093 const char *fmt
, ...)
2097 va_start(args
, fmt
);
2098 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
2100 printk(KERN_WARNING
"UDF-fs warning (device %s): %s: %s\n",
2101 sb
->s_id
, function
, error_buf
);
2104 static void udf_put_super(struct super_block
*sb
)
2107 struct udf_sb_info
*sbi
;
2110 if (sbi
->s_vat_inode
)
2111 iput(sbi
->s_vat_inode
);
2112 if (sbi
->s_partitions
)
2113 for (i
= 0; i
< sbi
->s_partitions
; i
++)
2114 udf_free_partition(&sbi
->s_partmaps
[i
]);
2115 #ifdef CONFIG_UDF_NLS
2116 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
2117 unload_nls(sbi
->s_nls_map
);
2119 if (!(sb
->s_flags
& MS_RDONLY
))
2121 brelse(sbi
->s_lvid_bh
);
2122 kfree(sbi
->s_partmaps
);
2123 kfree(sb
->s_fs_info
);
2124 sb
->s_fs_info
= NULL
;
2127 static int udf_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
2129 struct super_block
*sb
= dentry
->d_sb
;
2130 struct udf_sb_info
*sbi
= UDF_SB(sb
);
2131 struct logicalVolIntegrityDescImpUse
*lvidiu
;
2133 if (sbi
->s_lvid_bh
!= NULL
)
2134 lvidiu
= udf_sb_lvidiu(sbi
);
2138 buf
->f_type
= UDF_SUPER_MAGIC
;
2139 buf
->f_bsize
= sb
->s_blocksize
;
2140 buf
->f_blocks
= sbi
->s_partmaps
[sbi
->s_partition
].s_partition_len
;
2141 buf
->f_bfree
= udf_count_free(sb
);
2142 buf
->f_bavail
= buf
->f_bfree
;
2143 buf
->f_files
= (lvidiu
!= NULL
? (le32_to_cpu(lvidiu
->numFiles
) +
2144 le32_to_cpu(lvidiu
->numDirs
)) : 0)
2146 buf
->f_ffree
= buf
->f_bfree
;
2147 /* __kernel_fsid_t f_fsid */
2148 buf
->f_namelen
= UDF_NAME_LEN
- 2;
2153 static unsigned int udf_count_free_bitmap(struct super_block
*sb
,
2154 struct udf_bitmap
*bitmap
)
2156 struct buffer_head
*bh
= NULL
;
2157 unsigned int accum
= 0;
2159 int block
= 0, newblock
;
2160 struct kernel_lb_addr loc
;
2164 struct spaceBitmapDesc
*bm
;
2168 loc
.logicalBlockNum
= bitmap
->s_extPosition
;
2169 loc
.partitionReferenceNum
= UDF_SB(sb
)->s_partition
;
2170 bh
= udf_read_ptagged(sb
, &loc
, 0, &ident
);
2173 printk(KERN_ERR
"udf: udf_count_free failed\n");
2175 } else if (ident
!= TAG_IDENT_SBD
) {
2177 printk(KERN_ERR
"udf: udf_count_free failed\n");
2181 bm
= (struct spaceBitmapDesc
*)bh
->b_data
;
2182 bytes
= le32_to_cpu(bm
->numOfBytes
);
2183 index
= sizeof(struct spaceBitmapDesc
); /* offset in first block only */
2184 ptr
= (uint8_t *)bh
->b_data
;
2187 u32 cur_bytes
= min_t(u32
, bytes
, sb
->s_blocksize
- index
);
2188 accum
+= bitmap_weight((const unsigned long *)(ptr
+ index
),
2193 newblock
= udf_get_lb_pblock(sb
, &loc
, ++block
);
2194 bh
= udf_tread(sb
, newblock
);
2196 udf_debug("read failed\n");
2200 ptr
= (uint8_t *)bh
->b_data
;
2211 static unsigned int udf_count_free_table(struct super_block
*sb
,
2212 struct inode
*table
)
2214 unsigned int accum
= 0;
2216 struct kernel_lb_addr eloc
;
2218 struct extent_position epos
;
2222 epos
.block
= UDF_I(table
)->i_location
;
2223 epos
.offset
= sizeof(struct unallocSpaceEntry
);
2226 while ((etype
= udf_next_aext(table
, &epos
, &eloc
, &elen
, 1)) != -1)
2227 accum
+= (elen
>> table
->i_sb
->s_blocksize_bits
);
2236 static unsigned int udf_count_free(struct super_block
*sb
)
2238 unsigned int accum
= 0;
2239 struct udf_sb_info
*sbi
;
2240 struct udf_part_map
*map
;
2243 if (sbi
->s_lvid_bh
) {
2244 struct logicalVolIntegrityDesc
*lvid
=
2245 (struct logicalVolIntegrityDesc
*)
2246 sbi
->s_lvid_bh
->b_data
;
2247 if (le32_to_cpu(lvid
->numOfPartitions
) > sbi
->s_partition
) {
2248 accum
= le32_to_cpu(
2249 lvid
->freeSpaceTable
[sbi
->s_partition
]);
2250 if (accum
== 0xFFFFFFFF)
2258 map
= &sbi
->s_partmaps
[sbi
->s_partition
];
2259 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
) {
2260 accum
+= udf_count_free_bitmap(sb
,
2261 map
->s_uspace
.s_bitmap
);
2263 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
) {
2264 accum
+= udf_count_free_bitmap(sb
,
2265 map
->s_fspace
.s_bitmap
);
2270 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
) {
2271 accum
+= udf_count_free_table(sb
,
2272 map
->s_uspace
.s_table
);
2274 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
) {
2275 accum
+= udf_count_free_table(sb
,
2276 map
->s_fspace
.s_table
);