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/quotaops.h>
58 #include <linux/seq_file.h>
59 #include <linux/bitmap.h>
60 #include <linux/crc-itu-t.h>
61 #include <asm/byteorder.h>
66 #include <linux/init.h>
67 #include <asm/uaccess.h>
69 #define VDS_POS_PRIMARY_VOL_DESC 0
70 #define VDS_POS_UNALLOC_SPACE_DESC 1
71 #define VDS_POS_LOGICAL_VOL_DESC 2
72 #define VDS_POS_PARTITION_DESC 3
73 #define VDS_POS_IMP_USE_VOL_DESC 4
74 #define VDS_POS_VOL_DESC_PTR 5
75 #define VDS_POS_TERMINATING_DESC 6
76 #define VDS_POS_LENGTH 7
78 #define UDF_DEFAULT_BLOCKSIZE 2048
80 static char error_buf[1024];
82 /* These are the "meat" - everything else is stuffing */
83 static int udf_fill_super(struct super_block *, void *, int);
84 static void udf_put_super(struct super_block *);
85 static int udf_sync_fs(struct super_block *, int);
86 static int udf_remount_fs(struct super_block *, int *, char *);
87 static void udf_load_logicalvolint(struct super_block *, struct kernel_extent_ad);
88 static int udf_find_fileset(struct super_block *, struct kernel_lb_addr *,
89 struct kernel_lb_addr *);
90 static void udf_load_fileset(struct super_block *, struct buffer_head *,
91 struct kernel_lb_addr *);
92 static void udf_open_lvid(struct super_block *);
93 static void udf_close_lvid(struct super_block *);
94 static unsigned int udf_count_free(struct super_block *);
95 static int udf_statfs(struct dentry *, struct kstatfs *);
96 static int udf_show_options(struct seq_file *, struct vfsmount *);
97 static void udf_error(struct super_block *sb, const char *function,
98 const char *fmt, ...);
100 struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi)
102 struct logicalVolIntegrityDesc *lvid =
103 (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data;
104 __u32 number_of_partitions = le32_to_cpu(lvid->numOfPartitions);
105 __u32 offset = number_of_partitions * 2 *
106 sizeof(uint32_t)/sizeof(uint8_t);
107 return (struct logicalVolIntegrityDescImpUse *)&(lvid->impUse[offset]);
110 /* UDF filesystem type */
111 static int udf_get_sb(struct file_system_type *fs_type,
112 int flags, const char *dev_name, void *data,
113 struct vfsmount *mnt)
115 return get_sb_bdev(fs_type, flags, dev_name, data, udf_fill_super, mnt);
118 static struct file_system_type udf_fstype = {
119 .owner = THIS_MODULE,
121 .get_sb = udf_get_sb,
122 .kill_sb = kill_block_super,
123 .fs_flags = FS_REQUIRES_DEV,
126 static struct kmem_cache *udf_inode_cachep;
128 static struct inode *udf_alloc_inode(struct super_block *sb)
130 struct udf_inode_info *ei;
131 ei = kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL);
136 ei->i_lenExtents = 0;
137 ei->i_next_alloc_block = 0;
138 ei->i_next_alloc_goal = 0;
141 return &ei->vfs_inode;
144 static void udf_destroy_inode(struct inode *inode)
146 kmem_cache_free(udf_inode_cachep, UDF_I(inode));
149 static void init_once(void *foo)
151 struct udf_inode_info *ei = (struct udf_inode_info *)foo;
153 ei->i_ext.i_data = NULL;
154 inode_init_once(&ei->vfs_inode);
157 static int init_inodecache(void)
159 udf_inode_cachep = kmem_cache_create("udf_inode_cache",
160 sizeof(struct udf_inode_info),
161 0, (SLAB_RECLAIM_ACCOUNT |
164 if (!udf_inode_cachep)
169 static void destroy_inodecache(void)
171 kmem_cache_destroy(udf_inode_cachep);
174 /* Superblock operations */
175 static const struct super_operations udf_sb_ops = {
176 .alloc_inode = udf_alloc_inode,
177 .destroy_inode = udf_destroy_inode,
178 .write_inode = udf_write_inode,
179 .delete_inode = udf_delete_inode,
180 .clear_inode = udf_clear_inode,
181 .put_super = udf_put_super,
182 .sync_fs = udf_sync_fs,
183 .statfs = udf_statfs,
184 .remount_fs = udf_remount_fs,
185 .show_options = udf_show_options,
190 unsigned int blocksize;
191 unsigned int session;
192 unsigned int lastblock;
195 unsigned short partition;
196 unsigned int fileset;
197 unsigned int rootdir;
204 struct nls_table *nls_map;
207 static int __init init_udf_fs(void)
211 err = init_inodecache();
214 err = register_filesystem(&udf_fstype);
221 destroy_inodecache();
227 static void __exit exit_udf_fs(void)
229 unregister_filesystem(&udf_fstype);
230 destroy_inodecache();
233 module_init(init_udf_fs)
234 module_exit(exit_udf_fs)
236 static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count)
238 struct udf_sb_info *sbi = UDF_SB(sb);
240 sbi->s_partmaps = kcalloc(count, sizeof(struct udf_part_map),
242 if (!sbi->s_partmaps) {
243 udf_error(sb, __func__,
244 "Unable to allocate space for %d partition maps",
246 sbi->s_partitions = 0;
250 sbi->s_partitions = count;
254 static int udf_show_options(struct seq_file *seq, struct vfsmount *mnt)
256 struct super_block *sb = mnt->mnt_sb;
257 struct udf_sb_info *sbi = UDF_SB(sb);
259 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT))
260 seq_puts(seq, ",nostrict");
261 if (UDF_QUERY_FLAG(sb, UDF_FLAG_BLOCKSIZE_SET))
262 seq_printf(seq, ",bs=%lu", sb->s_blocksize);
263 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE))
264 seq_puts(seq, ",unhide");
265 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE))
266 seq_puts(seq, ",undelete");
267 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_USE_AD_IN_ICB))
268 seq_puts(seq, ",noadinicb");
269 if (UDF_QUERY_FLAG(sb, UDF_FLAG_USE_SHORT_AD))
270 seq_puts(seq, ",shortad");
271 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_FORGET))
272 seq_puts(seq, ",uid=forget");
273 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_IGNORE))
274 seq_puts(seq, ",uid=ignore");
275 if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_FORGET))
276 seq_puts(seq, ",gid=forget");
277 if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_IGNORE))
278 seq_puts(seq, ",gid=ignore");
279 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET))
280 seq_printf(seq, ",uid=%u", sbi->s_uid);
281 if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET))
282 seq_printf(seq, ",gid=%u", sbi->s_gid);
283 if (sbi->s_umask != 0)
284 seq_printf(seq, ",umask=%o", sbi->s_umask);
285 if (sbi->s_fmode != UDF_INVALID_MODE)
286 seq_printf(seq, ",mode=%o", sbi->s_fmode);
287 if (sbi->s_dmode != UDF_INVALID_MODE)
288 seq_printf(seq, ",dmode=%o", sbi->s_dmode);
289 if (UDF_QUERY_FLAG(sb, UDF_FLAG_SESSION_SET))
290 seq_printf(seq, ",session=%u", sbi->s_session);
291 if (UDF_QUERY_FLAG(sb, UDF_FLAG_LASTBLOCK_SET))
292 seq_printf(seq, ",lastblock=%u", sbi->s_last_block);
293 if (sbi->s_anchor != 0)
294 seq_printf(seq, ",anchor=%u", sbi->s_anchor);
296 * volume, partition, fileset and rootdir seem to be ignored
299 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8))
300 seq_puts(seq, ",utf8");
301 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP) && sbi->s_nls_map)
302 seq_printf(seq, ",iocharset=%s", sbi->s_nls_map->charset);
311 * Parse mount options.
314 * The following mount options are supported:
316 * gid= Set the default group.
317 * umask= Set the default umask.
318 * mode= Set the default file permissions.
319 * dmode= Set the default directory permissions.
320 * uid= Set the default user.
321 * bs= Set the block size.
322 * unhide Show otherwise hidden files.
323 * undelete Show deleted files in lists.
324 * adinicb Embed data in the inode (default)
325 * noadinicb Don't embed data in the inode
326 * shortad Use short ad's
327 * longad Use long ad's (default)
328 * nostrict Unset strict conformance
329 * iocharset= Set the NLS character set
331 * The remaining are for debugging and disaster recovery:
333 * novrs Skip volume sequence recognition
335 * The following expect a offset from 0.
337 * session= Set the CDROM session (default= last session)
338 * anchor= Override standard anchor location. (default= 256)
339 * volume= Override the VolumeDesc location. (unused)
340 * partition= Override the PartitionDesc location. (unused)
341 * lastblock= Set the last block of the filesystem/
343 * The following expect a offset from the partition root.
345 * fileset= Override the fileset block location. (unused)
346 * rootdir= Override the root directory location. (unused)
347 * WARNING: overriding the rootdir to a non-directory may
348 * yield highly unpredictable results.
351 * options Pointer to mount options string.
352 * uopts Pointer to mount options variable.
355 * <return> 1 Mount options parsed okay.
356 * <return> 0 Error parsing mount options.
359 * July 1, 1997 - Andrew E. Mileski
360 * Written, tested, and released.
364 Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete,
365 Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad,
366 Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock,
367 Opt_anchor, Opt_volume, Opt_partition, Opt_fileset,
368 Opt_rootdir, Opt_utf8, Opt_iocharset,
369 Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore,
373 static const match_table_t tokens = {
374 {Opt_novrs, "novrs"},
375 {Opt_nostrict, "nostrict"},
377 {Opt_unhide, "unhide"},
378 {Opt_undelete, "undelete"},
379 {Opt_noadinicb, "noadinicb"},
380 {Opt_adinicb, "adinicb"},
381 {Opt_shortad, "shortad"},
382 {Opt_longad, "longad"},
383 {Opt_uforget, "uid=forget"},
384 {Opt_uignore, "uid=ignore"},
385 {Opt_gforget, "gid=forget"},
386 {Opt_gignore, "gid=ignore"},
389 {Opt_umask, "umask=%o"},
390 {Opt_session, "session=%u"},
391 {Opt_lastblock, "lastblock=%u"},
392 {Opt_anchor, "anchor=%u"},
393 {Opt_volume, "volume=%u"},
394 {Opt_partition, "partition=%u"},
395 {Opt_fileset, "fileset=%u"},
396 {Opt_rootdir, "rootdir=%u"},
398 {Opt_iocharset, "iocharset=%s"},
399 {Opt_fmode, "mode=%o"},
400 {Opt_dmode, "dmode=%o"},
404 static int udf_parse_options(char *options, struct udf_options *uopt,
411 uopt->partition = 0xFFFF;
412 uopt->session = 0xFFFFFFFF;
415 uopt->volume = 0xFFFFFFFF;
416 uopt->rootdir = 0xFFFFFFFF;
417 uopt->fileset = 0xFFFFFFFF;
418 uopt->nls_map = NULL;
423 while ((p = strsep(&options, ",")) != NULL) {
424 substring_t args[MAX_OPT_ARGS];
429 token = match_token(p, tokens, args);
435 if (match_int(&args[0], &option))
437 uopt->blocksize = option;
438 uopt->flags |= (1 << UDF_FLAG_BLOCKSIZE_SET);
441 uopt->flags |= (1 << UDF_FLAG_UNHIDE);
444 uopt->flags |= (1 << UDF_FLAG_UNDELETE);
447 uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
450 uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
453 uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
456 uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
459 if (match_int(args, &option))
462 uopt->flags |= (1 << UDF_FLAG_GID_SET);
465 if (match_int(args, &option))
468 uopt->flags |= (1 << UDF_FLAG_UID_SET);
471 if (match_octal(args, &option))
473 uopt->umask = option;
476 uopt->flags &= ~(1 << UDF_FLAG_STRICT);
479 if (match_int(args, &option))
481 uopt->session = option;
483 uopt->flags |= (1 << UDF_FLAG_SESSION_SET);
486 if (match_int(args, &option))
488 uopt->lastblock = option;
490 uopt->flags |= (1 << UDF_FLAG_LASTBLOCK_SET);
493 if (match_int(args, &option))
495 uopt->anchor = option;
498 if (match_int(args, &option))
500 uopt->volume = option;
503 if (match_int(args, &option))
505 uopt->partition = option;
508 if (match_int(args, &option))
510 uopt->fileset = option;
513 if (match_int(args, &option))
515 uopt->rootdir = option;
518 uopt->flags |= (1 << UDF_FLAG_UTF8);
520 #ifdef CONFIG_UDF_NLS
522 uopt->nls_map = load_nls(args[0].from);
523 uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
527 uopt->flags |= (1 << UDF_FLAG_UID_IGNORE);
530 uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
533 uopt->flags |= (1 << UDF_FLAG_GID_IGNORE);
536 uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
539 if (match_octal(args, &option))
541 uopt->fmode = option & 0777;
544 if (match_octal(args, &option))
546 uopt->dmode = option & 0777;
549 printk(KERN_ERR "udf: bad mount option \"%s\" "
550 "or missing value\n", p);
557 static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
559 struct udf_options uopt;
560 struct udf_sb_info *sbi = UDF_SB(sb);
563 uopt.flags = sbi->s_flags;
564 uopt.uid = sbi->s_uid;
565 uopt.gid = sbi->s_gid;
566 uopt.umask = sbi->s_umask;
567 uopt.fmode = sbi->s_fmode;
568 uopt.dmode = sbi->s_dmode;
570 if (!udf_parse_options(options, &uopt, true))
574 sbi->s_flags = uopt.flags;
575 sbi->s_uid = uopt.uid;
576 sbi->s_gid = uopt.gid;
577 sbi->s_umask = uopt.umask;
578 sbi->s_fmode = uopt.fmode;
579 sbi->s_dmode = uopt.dmode;
581 if (sbi->s_lvid_bh) {
582 int write_rev = le16_to_cpu(udf_sb_lvidiu(sbi)->minUDFWriteRev);
583 if (write_rev > UDF_MAX_WRITE_VERSION)
587 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
590 if (*flags & MS_RDONLY) {
593 error = vfs_dq_off(sb, 1);
594 if (error < 0 && error != -ENOSYS)
599 /* mark the fs r/w for quota activity */
600 sb->s_flags &= ~MS_RDONLY;
601 vfs_dq_quota_on_remount(sb);
609 /* Check Volume Structure Descriptors (ECMA 167 2/9.1) */
610 /* We also check any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
611 static loff_t udf_check_vsd(struct super_block *sb)
613 struct volStructDesc *vsd = NULL;
614 loff_t sector = 32768;
616 struct buffer_head *bh = NULL;
619 struct udf_sb_info *sbi;
622 if (sb->s_blocksize < sizeof(struct volStructDesc))
623 sectorsize = sizeof(struct volStructDesc);
625 sectorsize = sb->s_blocksize;
627 sector += (sbi->s_session << sb->s_blocksize_bits);
629 udf_debug("Starting at sector %u (%ld byte sectors)\n",
630 (unsigned int)(sector >> sb->s_blocksize_bits),
632 /* Process the sequence (if applicable) */
633 for (; !nsr02 && !nsr03; sector += sectorsize) {
635 bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
639 /* Look for ISO descriptors */
640 vsd = (struct volStructDesc *)(bh->b_data +
641 (sector & (sb->s_blocksize - 1)));
643 if (vsd->stdIdent[0] == 0) {
646 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001,
648 switch (vsd->structType) {
650 udf_debug("ISO9660 Boot Record found\n");
653 udf_debug("ISO9660 Primary Volume Descriptor "
657 udf_debug("ISO9660 Supplementary Volume "
658 "Descriptor found\n");
661 udf_debug("ISO9660 Volume Partition Descriptor "
665 udf_debug("ISO9660 Volume Descriptor Set "
666 "Terminator found\n");
669 udf_debug("ISO9660 VRS (%u) found\n",
673 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01,
676 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01,
680 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02,
683 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03,
693 else if (sector - (sbi->s_session << sb->s_blocksize_bits) == 32768)
699 static int udf_find_fileset(struct super_block *sb,
700 struct kernel_lb_addr *fileset,
701 struct kernel_lb_addr *root)
703 struct buffer_head *bh = NULL;
706 struct udf_sb_info *sbi;
708 if (fileset->logicalBlockNum != 0xFFFFFFFF ||
709 fileset->partitionReferenceNum != 0xFFFF) {
710 bh = udf_read_ptagged(sb, fileset, 0, &ident);
714 } else if (ident != TAG_IDENT_FSD) {
723 /* Search backwards through the partitions */
724 struct kernel_lb_addr newfileset;
726 /* --> cvg: FIXME - is it reasonable? */
729 for (newfileset.partitionReferenceNum = sbi->s_partitions - 1;
730 (newfileset.partitionReferenceNum != 0xFFFF &&
731 fileset->logicalBlockNum == 0xFFFFFFFF &&
732 fileset->partitionReferenceNum == 0xFFFF);
733 newfileset.partitionReferenceNum--) {
734 lastblock = sbi->s_partmaps
735 [newfileset.partitionReferenceNum]
737 newfileset.logicalBlockNum = 0;
740 bh = udf_read_ptagged(sb, &newfileset, 0,
743 newfileset.logicalBlockNum++;
750 struct spaceBitmapDesc *sp;
751 sp = (struct spaceBitmapDesc *)
753 newfileset.logicalBlockNum += 1 +
754 ((le32_to_cpu(sp->numOfBytes) +
755 sizeof(struct spaceBitmapDesc)
756 - 1) >> sb->s_blocksize_bits);
761 *fileset = newfileset;
764 newfileset.logicalBlockNum++;
769 } while (newfileset.logicalBlockNum < lastblock &&
770 fileset->logicalBlockNum == 0xFFFFFFFF &&
771 fileset->partitionReferenceNum == 0xFFFF);
775 if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
776 fileset->partitionReferenceNum != 0xFFFF) && bh) {
777 udf_debug("Fileset at block=%d, partition=%d\n",
778 fileset->logicalBlockNum,
779 fileset->partitionReferenceNum);
781 sbi->s_partition = fileset->partitionReferenceNum;
782 udf_load_fileset(sb, bh, root);
789 static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
791 struct primaryVolDesc *pvoldesc;
792 struct ustr *instr, *outstr;
793 struct buffer_head *bh;
797 instr = kmalloc(sizeof(struct ustr), GFP_NOFS);
801 outstr = kmalloc(sizeof(struct ustr), GFP_NOFS);
805 bh = udf_read_tagged(sb, block, block, &ident);
809 BUG_ON(ident != TAG_IDENT_PVD);
811 pvoldesc = (struct primaryVolDesc *)bh->b_data;
813 if (udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time,
814 pvoldesc->recordingDateAndTime)) {
816 struct timestamp *ts = &pvoldesc->recordingDateAndTime;
817 udf_debug("recording time %04u/%02u/%02u"
819 le16_to_cpu(ts->year), ts->month, ts->day, ts->hour,
820 ts->minute, le16_to_cpu(ts->typeAndTimezone));
824 if (!udf_build_ustr(instr, pvoldesc->volIdent, 32))
825 if (udf_CS0toUTF8(outstr, instr)) {
826 strncpy(UDF_SB(sb)->s_volume_ident, outstr->u_name,
827 outstr->u_len > 31 ? 31 : outstr->u_len);
828 udf_debug("volIdent[] = '%s'\n",
829 UDF_SB(sb)->s_volume_ident);
832 if (!udf_build_ustr(instr, pvoldesc->volSetIdent, 128))
833 if (udf_CS0toUTF8(outstr, instr))
834 udf_debug("volSetIdent[] = '%s'\n", outstr->u_name);
845 static int udf_load_metadata_files(struct super_block *sb, int partition)
847 struct udf_sb_info *sbi = UDF_SB(sb);
848 struct udf_part_map *map;
849 struct udf_meta_data *mdata;
850 struct kernel_lb_addr addr;
853 map = &sbi->s_partmaps[partition];
854 mdata = &map->s_type_specific.s_metadata;
856 /* metadata address */
857 addr.logicalBlockNum = mdata->s_meta_file_loc;
858 addr.partitionReferenceNum = map->s_partition_num;
860 udf_debug("Metadata file location: block = %d part = %d\n",
861 addr.logicalBlockNum, addr.partitionReferenceNum);
863 mdata->s_metadata_fe = udf_iget(sb, &addr);
865 if (mdata->s_metadata_fe == NULL) {
866 udf_warning(sb, __func__, "metadata inode efe not found, "
867 "will try mirror inode.");
869 } else if (UDF_I(mdata->s_metadata_fe)->i_alloc_type !=
870 ICBTAG_FLAG_AD_SHORT) {
871 udf_warning(sb, __func__, "metadata inode efe does not have "
872 "short allocation descriptors!");
874 iput(mdata->s_metadata_fe);
875 mdata->s_metadata_fe = NULL;
878 /* mirror file entry */
879 addr.logicalBlockNum = mdata->s_mirror_file_loc;
880 addr.partitionReferenceNum = map->s_partition_num;
882 udf_debug("Mirror metadata file location: block = %d part = %d\n",
883 addr.logicalBlockNum, addr.partitionReferenceNum);
885 mdata->s_mirror_fe = udf_iget(sb, &addr);
887 if (mdata->s_mirror_fe == NULL) {
889 udf_error(sb, __func__, "mirror inode efe not found "
890 "and metadata inode is missing too, exiting...");
893 udf_warning(sb, __func__, "mirror inode efe not found,"
894 " but metadata inode is OK");
895 } else if (UDF_I(mdata->s_mirror_fe)->i_alloc_type !=
896 ICBTAG_FLAG_AD_SHORT) {
897 udf_warning(sb, __func__, "mirror inode efe does not have "
898 "short allocation descriptors!");
899 iput(mdata->s_mirror_fe);
900 mdata->s_mirror_fe = NULL;
908 * Load only if bitmap file location differs from 0xFFFFFFFF (DCN-5102)
910 if (mdata->s_bitmap_file_loc != 0xFFFFFFFF) {
911 addr.logicalBlockNum = mdata->s_bitmap_file_loc;
912 addr.partitionReferenceNum = map->s_partition_num;
914 udf_debug("Bitmap file location: block = %d part = %d\n",
915 addr.logicalBlockNum, addr.partitionReferenceNum);
917 mdata->s_bitmap_fe = udf_iget(sb, &addr);
919 if (mdata->s_bitmap_fe == NULL) {
920 if (sb->s_flags & MS_RDONLY)
921 udf_warning(sb, __func__, "bitmap inode efe "
922 "not found but it's ok since the disc"
923 " is mounted read-only");
925 udf_error(sb, __func__, "bitmap inode efe not "
926 "found and attempted read-write mount");
932 udf_debug("udf_load_metadata_files Ok\n");
940 static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
941 struct kernel_lb_addr *root)
943 struct fileSetDesc *fset;
945 fset = (struct fileSetDesc *)bh->b_data;
947 *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
949 UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum);
951 udf_debug("Rootdir at block=%d, partition=%d\n",
952 root->logicalBlockNum, root->partitionReferenceNum);
955 int udf_compute_nr_groups(struct super_block *sb, u32 partition)
957 struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
958 return DIV_ROUND_UP(map->s_partition_len +
959 (sizeof(struct spaceBitmapDesc) << 3),
960 sb->s_blocksize * 8);
963 static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
965 struct udf_bitmap *bitmap;
969 nr_groups = udf_compute_nr_groups(sb, index);
970 size = sizeof(struct udf_bitmap) +
971 (sizeof(struct buffer_head *) * nr_groups);
973 if (size <= PAGE_SIZE)
974 bitmap = kmalloc(size, GFP_KERNEL);
976 bitmap = vmalloc(size); /* TODO: get rid of vmalloc */
978 if (bitmap == NULL) {
979 udf_error(sb, __func__,
980 "Unable to allocate space for bitmap "
981 "and %d buffer_head pointers", nr_groups);
985 memset(bitmap, 0x00, size);
986 bitmap->s_block_bitmap = (struct buffer_head **)(bitmap + 1);
987 bitmap->s_nr_groups = nr_groups;
991 static int udf_fill_partdesc_info(struct super_block *sb,
992 struct partitionDesc *p, int p_index)
994 struct udf_part_map *map;
995 struct udf_sb_info *sbi = UDF_SB(sb);
996 struct partitionHeaderDesc *phd;
998 map = &sbi->s_partmaps[p_index];
1000 map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */
1001 map->s_partition_root = le32_to_cpu(p->partitionStartingLocation);
1003 if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
1004 map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
1005 if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
1006 map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
1007 if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
1008 map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
1009 if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
1010 map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
1012 udf_debug("Partition (%d type %x) starts at physical %d, "
1013 "block length %d\n", p_index,
1014 map->s_partition_type, map->s_partition_root,
1015 map->s_partition_len);
1017 if (strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) &&
1018 strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03))
1021 phd = (struct partitionHeaderDesc *)p->partitionContentsUse;
1022 if (phd->unallocSpaceTable.extLength) {
1023 struct kernel_lb_addr loc = {
1024 .logicalBlockNum = le32_to_cpu(
1025 phd->unallocSpaceTable.extPosition),
1026 .partitionReferenceNum = p_index,
1029 map->s_uspace.s_table = udf_iget(sb, &loc);
1030 if (!map->s_uspace.s_table) {
1031 udf_debug("cannot load unallocSpaceTable (part %d)\n",
1035 map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE;
1036 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
1037 p_index, map->s_uspace.s_table->i_ino);
1040 if (phd->unallocSpaceBitmap.extLength) {
1041 struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
1044 map->s_uspace.s_bitmap = bitmap;
1045 bitmap->s_extLength = le32_to_cpu(
1046 phd->unallocSpaceBitmap.extLength);
1047 bitmap->s_extPosition = le32_to_cpu(
1048 phd->unallocSpaceBitmap.extPosition);
1049 map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
1050 udf_debug("unallocSpaceBitmap (part %d) @ %d\n", p_index,
1051 bitmap->s_extPosition);
1054 if (phd->partitionIntegrityTable.extLength)
1055 udf_debug("partitionIntegrityTable (part %d)\n", p_index);
1057 if (phd->freedSpaceTable.extLength) {
1058 struct kernel_lb_addr loc = {
1059 .logicalBlockNum = le32_to_cpu(
1060 phd->freedSpaceTable.extPosition),
1061 .partitionReferenceNum = p_index,
1064 map->s_fspace.s_table = udf_iget(sb, &loc);
1065 if (!map->s_fspace.s_table) {
1066 udf_debug("cannot load freedSpaceTable (part %d)\n",
1071 map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE;
1072 udf_debug("freedSpaceTable (part %d) @ %ld\n",
1073 p_index, map->s_fspace.s_table->i_ino);
1076 if (phd->freedSpaceBitmap.extLength) {
1077 struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
1080 map->s_fspace.s_bitmap = bitmap;
1081 bitmap->s_extLength = le32_to_cpu(
1082 phd->freedSpaceBitmap.extLength);
1083 bitmap->s_extPosition = le32_to_cpu(
1084 phd->freedSpaceBitmap.extPosition);
1085 map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
1086 udf_debug("freedSpaceBitmap (part %d) @ %d\n", p_index,
1087 bitmap->s_extPosition);
1092 static void udf_find_vat_block(struct super_block *sb, int p_index,
1093 int type1_index, sector_t start_block)
1095 struct udf_sb_info *sbi = UDF_SB(sb);
1096 struct udf_part_map *map = &sbi->s_partmaps[p_index];
1098 struct kernel_lb_addr ino;
1101 * VAT file entry is in the last recorded block. Some broken disks have
1102 * it a few blocks before so try a bit harder...
1104 ino.partitionReferenceNum = type1_index;
1105 for (vat_block = start_block;
1106 vat_block >= map->s_partition_root &&
1107 vat_block >= start_block - 3 &&
1108 !sbi->s_vat_inode; vat_block--) {
1109 ino.logicalBlockNum = vat_block - map->s_partition_root;
1110 sbi->s_vat_inode = udf_iget(sb, &ino);
1114 static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
1116 struct udf_sb_info *sbi = UDF_SB(sb);
1117 struct udf_part_map *map = &sbi->s_partmaps[p_index];
1118 struct buffer_head *bh = NULL;
1119 struct udf_inode_info *vati;
1121 struct virtualAllocationTable20 *vat20;
1122 sector_t blocks = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits;
1124 udf_find_vat_block(sb, p_index, type1_index, sbi->s_last_block);
1125 if (!sbi->s_vat_inode &&
1126 sbi->s_last_block != blocks - 1) {
1127 printk(KERN_NOTICE "UDF-fs: Failed to read VAT inode from the"
1128 " last recorded block (%lu), retrying with the last "
1129 "block of the device (%lu).\n",
1130 (unsigned long)sbi->s_last_block,
1131 (unsigned long)blocks - 1);
1132 udf_find_vat_block(sb, p_index, type1_index, blocks - 1);
1134 if (!sbi->s_vat_inode)
1137 if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
1138 map->s_type_specific.s_virtual.s_start_offset = 0;
1139 map->s_type_specific.s_virtual.s_num_entries =
1140 (sbi->s_vat_inode->i_size - 36) >> 2;
1141 } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
1142 vati = UDF_I(sbi->s_vat_inode);
1143 if (vati->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
1144 pos = udf_block_map(sbi->s_vat_inode, 0);
1145 bh = sb_bread(sb, pos);
1148 vat20 = (struct virtualAllocationTable20 *)bh->b_data;
1150 vat20 = (struct virtualAllocationTable20 *)
1154 map->s_type_specific.s_virtual.s_start_offset =
1155 le16_to_cpu(vat20->lengthHeader);
1156 map->s_type_specific.s_virtual.s_num_entries =
1157 (sbi->s_vat_inode->i_size -
1158 map->s_type_specific.s_virtual.
1159 s_start_offset) >> 2;
1165 static int udf_load_partdesc(struct super_block *sb, sector_t block)
1167 struct buffer_head *bh;
1168 struct partitionDesc *p;
1169 struct udf_part_map *map;
1170 struct udf_sb_info *sbi = UDF_SB(sb);
1172 uint16_t partitionNumber;
1176 bh = udf_read_tagged(sb, block, block, &ident);
1179 if (ident != TAG_IDENT_PD)
1182 p = (struct partitionDesc *)bh->b_data;
1183 partitionNumber = le16_to_cpu(p->partitionNumber);
1185 /* First scan for TYPE1, SPARABLE and METADATA partitions */
1186 for (i = 0; i < sbi->s_partitions; i++) {
1187 map = &sbi->s_partmaps[i];
1188 udf_debug("Searching map: (%d == %d)\n",
1189 map->s_partition_num, partitionNumber);
1190 if (map->s_partition_num == partitionNumber &&
1191 (map->s_partition_type == UDF_TYPE1_MAP15 ||
1192 map->s_partition_type == UDF_SPARABLE_MAP15))
1196 if (i >= sbi->s_partitions) {
1197 udf_debug("Partition (%d) not found in partition map\n",
1202 ret = udf_fill_partdesc_info(sb, p, i);
1205 * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and
1206 * PHYSICAL partitions are already set up
1209 for (i = 0; i < sbi->s_partitions; i++) {
1210 map = &sbi->s_partmaps[i];
1212 if (map->s_partition_num == partitionNumber &&
1213 (map->s_partition_type == UDF_VIRTUAL_MAP15 ||
1214 map->s_partition_type == UDF_VIRTUAL_MAP20 ||
1215 map->s_partition_type == UDF_METADATA_MAP25))
1219 if (i >= sbi->s_partitions)
1222 ret = udf_fill_partdesc_info(sb, p, i);
1226 if (map->s_partition_type == UDF_METADATA_MAP25) {
1227 ret = udf_load_metadata_files(sb, i);
1229 printk(KERN_ERR "UDF-fs: error loading MetaData "
1230 "partition map %d\n", i);
1234 ret = udf_load_vat(sb, i, type1_idx);
1238 * Mark filesystem read-only if we have a partition with
1239 * virtual map since we don't handle writing to it (we
1240 * overwrite blocks instead of relocating them).
1242 sb->s_flags |= MS_RDONLY;
1243 printk(KERN_NOTICE "UDF-fs: Filesystem marked read-only "
1244 "because writing to pseudooverwrite partition is "
1245 "not implemented.\n");
1248 /* In case loading failed, we handle cleanup in udf_fill_super */
1253 static int udf_load_logicalvol(struct super_block *sb, sector_t block,
1254 struct kernel_lb_addr *fileset)
1256 struct logicalVolDesc *lvd;
1259 struct udf_sb_info *sbi = UDF_SB(sb);
1260 struct genericPartitionMap *gpm;
1262 struct buffer_head *bh;
1265 bh = udf_read_tagged(sb, block, block, &ident);
1268 BUG_ON(ident != TAG_IDENT_LVD);
1269 lvd = (struct logicalVolDesc *)bh->b_data;
1271 i = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
1277 for (i = 0, offset = 0;
1278 i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength);
1279 i++, offset += gpm->partitionMapLength) {
1280 struct udf_part_map *map = &sbi->s_partmaps[i];
1281 gpm = (struct genericPartitionMap *)
1282 &(lvd->partitionMaps[offset]);
1283 type = gpm->partitionMapType;
1285 struct genericPartitionMap1 *gpm1 =
1286 (struct genericPartitionMap1 *)gpm;
1287 map->s_partition_type = UDF_TYPE1_MAP15;
1288 map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum);
1289 map->s_partition_num = le16_to_cpu(gpm1->partitionNum);
1290 map->s_partition_func = NULL;
1291 } else if (type == 2) {
1292 struct udfPartitionMap2 *upm2 =
1293 (struct udfPartitionMap2 *)gpm;
1294 if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL,
1295 strlen(UDF_ID_VIRTUAL))) {
1297 le16_to_cpu(((__le16 *)upm2->partIdent.
1300 map->s_partition_type =
1302 map->s_partition_func =
1303 udf_get_pblock_virt15;
1305 map->s_partition_type =
1307 map->s_partition_func =
1308 udf_get_pblock_virt20;
1310 } else if (!strncmp(upm2->partIdent.ident,
1312 strlen(UDF_ID_SPARABLE))) {
1314 struct sparingTable *st;
1315 struct sparablePartitionMap *spm =
1316 (struct sparablePartitionMap *)gpm;
1318 map->s_partition_type = UDF_SPARABLE_MAP15;
1319 map->s_type_specific.s_sparing.s_packet_len =
1320 le16_to_cpu(spm->packetLength);
1321 for (j = 0; j < spm->numSparingTables; j++) {
1322 struct buffer_head *bh2;
1325 spm->locSparingTable[j]);
1326 bh2 = udf_read_tagged(sb, loc, loc,
1328 map->s_type_specific.s_sparing.
1329 s_spar_map[j] = bh2;
1334 st = (struct sparingTable *)bh2->b_data;
1335 if (ident != 0 || strncmp(
1336 st->sparingIdent.ident,
1338 strlen(UDF_ID_SPARING))) {
1340 map->s_type_specific.s_sparing.
1341 s_spar_map[j] = NULL;
1344 map->s_partition_func = udf_get_pblock_spar15;
1345 } else if (!strncmp(upm2->partIdent.ident,
1347 strlen(UDF_ID_METADATA))) {
1348 struct udf_meta_data *mdata =
1349 &map->s_type_specific.s_metadata;
1350 struct metadataPartitionMap *mdm =
1351 (struct metadataPartitionMap *)
1352 &(lvd->partitionMaps[offset]);
1353 udf_debug("Parsing Logical vol part %d "
1354 "type %d id=%s\n", i, type,
1357 map->s_partition_type = UDF_METADATA_MAP25;
1358 map->s_partition_func = udf_get_pblock_meta25;
1360 mdata->s_meta_file_loc =
1361 le32_to_cpu(mdm->metadataFileLoc);
1362 mdata->s_mirror_file_loc =
1363 le32_to_cpu(mdm->metadataMirrorFileLoc);
1364 mdata->s_bitmap_file_loc =
1365 le32_to_cpu(mdm->metadataBitmapFileLoc);
1366 mdata->s_alloc_unit_size =
1367 le32_to_cpu(mdm->allocUnitSize);
1368 mdata->s_align_unit_size =
1369 le16_to_cpu(mdm->alignUnitSize);
1370 mdata->s_dup_md_flag =
1373 udf_debug("Metadata Ident suffix=0x%x\n",
1376 mdm->partIdent.identSuffix)[0])));
1377 udf_debug("Metadata part num=%d\n",
1378 le16_to_cpu(mdm->partitionNum));
1379 udf_debug("Metadata part alloc unit size=%d\n",
1380 le32_to_cpu(mdm->allocUnitSize));
1381 udf_debug("Metadata file loc=%d\n",
1382 le32_to_cpu(mdm->metadataFileLoc));
1383 udf_debug("Mirror file loc=%d\n",
1384 le32_to_cpu(mdm->metadataMirrorFileLoc));
1385 udf_debug("Bitmap file loc=%d\n",
1386 le32_to_cpu(mdm->metadataBitmapFileLoc));
1387 udf_debug("Duplicate Flag: %d %d\n",
1388 mdata->s_dup_md_flag, mdm->flags);
1390 udf_debug("Unknown ident: %s\n",
1391 upm2->partIdent.ident);
1394 map->s_volumeseqnum = le16_to_cpu(upm2->volSeqNum);
1395 map->s_partition_num = le16_to_cpu(upm2->partitionNum);
1397 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1398 i, map->s_partition_num, type,
1399 map->s_volumeseqnum);
1403 struct long_ad *la = (struct long_ad *)&(lvd->logicalVolContentsUse[0]);
1405 *fileset = lelb_to_cpu(la->extLocation);
1406 udf_debug("FileSet found in LogicalVolDesc at block=%d, "
1407 "partition=%d\n", fileset->logicalBlockNum,
1408 fileset->partitionReferenceNum);
1410 if (lvd->integritySeqExt.extLength)
1411 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
1419 * udf_load_logicalvolint
1422 static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_ad loc)
1424 struct buffer_head *bh = NULL;
1426 struct udf_sb_info *sbi = UDF_SB(sb);
1427 struct logicalVolIntegrityDesc *lvid;
1429 while (loc.extLength > 0 &&
1430 (bh = udf_read_tagged(sb, loc.extLocation,
1431 loc.extLocation, &ident)) &&
1432 ident == TAG_IDENT_LVID) {
1433 sbi->s_lvid_bh = bh;
1434 lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
1436 if (lvid->nextIntegrityExt.extLength)
1437 udf_load_logicalvolint(sb,
1438 leea_to_cpu(lvid->nextIntegrityExt));
1440 if (sbi->s_lvid_bh != bh)
1442 loc.extLength -= sb->s_blocksize;
1445 if (sbi->s_lvid_bh != bh)
1450 * udf_process_sequence
1453 * Process a main/reserve volume descriptor sequence.
1456 * sb Pointer to _locked_ superblock.
1457 * block First block of first extent of the sequence.
1458 * lastblock Lastblock of first extent of the sequence.
1461 * July 1, 1997 - Andrew E. Mileski
1462 * Written, tested, and released.
1464 static noinline int udf_process_sequence(struct super_block *sb, long block,
1465 long lastblock, struct kernel_lb_addr *fileset)
1467 struct buffer_head *bh = NULL;
1468 struct udf_vds_record vds[VDS_POS_LENGTH];
1469 struct udf_vds_record *curr;
1470 struct generic_desc *gd;
1471 struct volDescPtr *vdp;
1475 long next_s = 0, next_e = 0;
1477 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
1480 * Read the main descriptor sequence and find which descriptors
1483 for (; (!done && block <= lastblock); block++) {
1485 bh = udf_read_tagged(sb, block, block, &ident);
1487 printk(KERN_ERR "udf: Block %Lu of volume descriptor "
1488 "sequence is corrupted or we could not read "
1489 "it.\n", (unsigned long long)block);
1493 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1494 gd = (struct generic_desc *)bh->b_data;
1495 vdsn = le32_to_cpu(gd->volDescSeqNum);
1497 case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
1498 curr = &vds[VDS_POS_PRIMARY_VOL_DESC];
1499 if (vdsn >= curr->volDescSeqNum) {
1500 curr->volDescSeqNum = vdsn;
1501 curr->block = block;
1504 case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
1505 curr = &vds[VDS_POS_VOL_DESC_PTR];
1506 if (vdsn >= curr->volDescSeqNum) {
1507 curr->volDescSeqNum = vdsn;
1508 curr->block = block;
1510 vdp = (struct volDescPtr *)bh->b_data;
1511 next_s = le32_to_cpu(
1512 vdp->nextVolDescSeqExt.extLocation);
1513 next_e = le32_to_cpu(
1514 vdp->nextVolDescSeqExt.extLength);
1515 next_e = next_e >> sb->s_blocksize_bits;
1519 case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
1520 curr = &vds[VDS_POS_IMP_USE_VOL_DESC];
1521 if (vdsn >= curr->volDescSeqNum) {
1522 curr->volDescSeqNum = vdsn;
1523 curr->block = block;
1526 case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
1527 curr = &vds[VDS_POS_PARTITION_DESC];
1529 curr->block = block;
1531 case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
1532 curr = &vds[VDS_POS_LOGICAL_VOL_DESC];
1533 if (vdsn >= curr->volDescSeqNum) {
1534 curr->volDescSeqNum = vdsn;
1535 curr->block = block;
1538 case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
1539 curr = &vds[VDS_POS_UNALLOC_SPACE_DESC];
1540 if (vdsn >= curr->volDescSeqNum) {
1541 curr->volDescSeqNum = vdsn;
1542 curr->block = block;
1545 case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
1546 vds[VDS_POS_TERMINATING_DESC].block = block;
1550 next_s = next_e = 0;
1558 * Now read interesting descriptors again and process them
1559 * in a suitable order
1561 if (!vds[VDS_POS_PRIMARY_VOL_DESC].block) {
1562 printk(KERN_ERR "udf: Primary Volume Descriptor not found!\n");
1565 if (udf_load_pvoldesc(sb, vds[VDS_POS_PRIMARY_VOL_DESC].block))
1568 if (vds[VDS_POS_LOGICAL_VOL_DESC].block && udf_load_logicalvol(sb,
1569 vds[VDS_POS_LOGICAL_VOL_DESC].block, fileset))
1572 if (vds[VDS_POS_PARTITION_DESC].block) {
1574 * We rescan the whole descriptor sequence to find
1575 * partition descriptor blocks and process them.
1577 for (block = vds[VDS_POS_PARTITION_DESC].block;
1578 block < vds[VDS_POS_TERMINATING_DESC].block;
1580 if (udf_load_partdesc(sb, block))
1587 static int udf_load_sequence(struct super_block *sb, struct buffer_head *bh,
1588 struct kernel_lb_addr *fileset)
1590 struct anchorVolDescPtr *anchor;
1591 long main_s, main_e, reserve_s, reserve_e;
1592 struct udf_sb_info *sbi;
1595 anchor = (struct anchorVolDescPtr *)bh->b_data;
1597 /* Locate the main sequence */
1598 main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
1599 main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength);
1600 main_e = main_e >> sb->s_blocksize_bits;
1603 /* Locate the reserve sequence */
1604 reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation);
1605 reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
1606 reserve_e = reserve_e >> sb->s_blocksize_bits;
1607 reserve_e += reserve_s;
1609 /* Process the main & reserve sequences */
1610 /* responsible for finding the PartitionDesc(s) */
1611 if (!udf_process_sequence(sb, main_s, main_e, fileset))
1613 return !udf_process_sequence(sb, reserve_s, reserve_e, fileset);
1617 * Check whether there is an anchor block in the given block and
1618 * load Volume Descriptor Sequence if so.
1620 static int udf_check_anchor_block(struct super_block *sb, sector_t block,
1621 struct kernel_lb_addr *fileset)
1623 struct buffer_head *bh;
1627 if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) &&
1628 udf_fixed_to_variable(block) >=
1629 sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits)
1632 bh = udf_read_tagged(sb, block, block, &ident);
1635 if (ident != TAG_IDENT_AVDP) {
1639 ret = udf_load_sequence(sb, bh, fileset);
1644 /* Search for an anchor volume descriptor pointer */
1645 static sector_t udf_scan_anchors(struct super_block *sb, sector_t lastblock,
1646 struct kernel_lb_addr *fileset)
1650 struct udf_sb_info *sbi = UDF_SB(sb);
1653 /* First try user provided anchor */
1654 if (sbi->s_anchor) {
1655 if (udf_check_anchor_block(sb, sbi->s_anchor, fileset))
1659 * according to spec, anchor is in either:
1663 * however, if the disc isn't closed, it could be 512.
1665 if (udf_check_anchor_block(sb, sbi->s_session + 256, fileset))
1668 * The trouble is which block is the last one. Drives often misreport
1669 * this so we try various possibilities.
1671 last[last_count++] = lastblock;
1673 last[last_count++] = lastblock - 1;
1674 last[last_count++] = lastblock + 1;
1676 last[last_count++] = lastblock - 2;
1677 if (lastblock >= 150)
1678 last[last_count++] = lastblock - 150;
1679 if (lastblock >= 152)
1680 last[last_count++] = lastblock - 152;
1682 for (i = 0; i < last_count; i++) {
1683 if (last[i] >= sb->s_bdev->bd_inode->i_size >>
1684 sb->s_blocksize_bits)
1686 if (udf_check_anchor_block(sb, last[i], fileset))
1690 if (udf_check_anchor_block(sb, last[i] - 256, fileset))
1694 /* Finally try block 512 in case media is open */
1695 if (udf_check_anchor_block(sb, sbi->s_session + 512, fileset))
1701 * Find an anchor volume descriptor and load Volume Descriptor Sequence from
1702 * area specified by it. The function expects sbi->s_lastblock to be the last
1703 * block on the media.
1705 * Return 1 if ok, 0 if not found.
1708 static int udf_find_anchor(struct super_block *sb,
1709 struct kernel_lb_addr *fileset)
1712 struct udf_sb_info *sbi = UDF_SB(sb);
1714 lastblock = udf_scan_anchors(sb, sbi->s_last_block, fileset);
1718 /* No anchor found? Try VARCONV conversion of block numbers */
1719 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
1720 /* Firstly, we try to not convert number of the last block */
1721 lastblock = udf_scan_anchors(sb,
1722 udf_variable_to_fixed(sbi->s_last_block),
1727 /* Secondly, we try with converted number of the last block */
1728 lastblock = udf_scan_anchors(sb, sbi->s_last_block, fileset);
1730 /* VARCONV didn't help. Clear it. */
1731 UDF_CLEAR_FLAG(sb, UDF_FLAG_VARCONV);
1735 sbi->s_last_block = lastblock;
1740 * Check Volume Structure Descriptor, find Anchor block and load Volume
1741 * Descriptor Sequence
1743 static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt,
1744 int silent, struct kernel_lb_addr *fileset)
1746 struct udf_sb_info *sbi = UDF_SB(sb);
1749 if (!sb_set_blocksize(sb, uopt->blocksize)) {
1751 printk(KERN_WARNING "UDF-fs: Bad block size\n");
1754 sbi->s_last_block = uopt->lastblock;
1756 /* Check that it is NSR02 compliant */
1757 nsr_off = udf_check_vsd(sb);
1760 printk(KERN_WARNING "UDF-fs: No VRS found\n");
1764 udf_debug("Failed to read byte 32768. Assuming open "
1765 "disc. Skipping validity check\n");
1766 if (!sbi->s_last_block)
1767 sbi->s_last_block = udf_get_last_block(sb);
1769 udf_debug("Validity check skipped because of novrs option\n");
1772 /* Look for anchor block and load Volume Descriptor Sequence */
1773 sbi->s_anchor = uopt->anchor;
1774 if (!udf_find_anchor(sb, fileset)) {
1776 printk(KERN_WARNING "UDF-fs: No anchor found\n");
1782 static void udf_open_lvid(struct super_block *sb)
1784 struct udf_sb_info *sbi = UDF_SB(sb);
1785 struct buffer_head *bh = sbi->s_lvid_bh;
1786 struct logicalVolIntegrityDesc *lvid;
1787 struct logicalVolIntegrityDescImpUse *lvidiu;
1791 lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
1792 lvidiu = udf_sb_lvidiu(sbi);
1794 lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1795 lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1796 udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
1798 lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN);
1800 lvid->descTag.descCRC = cpu_to_le16(
1801 crc_itu_t(0, (char *)lvid + sizeof(struct tag),
1802 le16_to_cpu(lvid->descTag.descCRCLength)));
1804 lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
1805 mark_buffer_dirty(bh);
1806 sbi->s_lvid_dirty = 0;
1809 static void udf_close_lvid(struct super_block *sb)
1811 struct udf_sb_info *sbi = UDF_SB(sb);
1812 struct buffer_head *bh = sbi->s_lvid_bh;
1813 struct logicalVolIntegrityDesc *lvid;
1814 struct logicalVolIntegrityDescImpUse *lvidiu;
1819 lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
1820 lvidiu = udf_sb_lvidiu(sbi);
1821 lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1822 lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1823 udf_time_to_disk_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
1824 if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
1825 lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
1826 if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
1827 lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
1828 if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
1829 lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
1830 lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
1832 lvid->descTag.descCRC = cpu_to_le16(
1833 crc_itu_t(0, (char *)lvid + sizeof(struct tag),
1834 le16_to_cpu(lvid->descTag.descCRCLength)));
1836 lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
1837 mark_buffer_dirty(bh);
1838 sbi->s_lvid_dirty = 0;
1841 static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
1844 int nr_groups = bitmap->s_nr_groups;
1845 int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) *
1848 for (i = 0; i < nr_groups; i++)
1849 if (bitmap->s_block_bitmap[i])
1850 brelse(bitmap->s_block_bitmap[i]);
1852 if (size <= PAGE_SIZE)
1858 static void udf_free_partition(struct udf_part_map *map)
1861 struct udf_meta_data *mdata;
1863 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
1864 iput(map->s_uspace.s_table);
1865 if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
1866 iput(map->s_fspace.s_table);
1867 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
1868 udf_sb_free_bitmap(map->s_uspace.s_bitmap);
1869 if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
1870 udf_sb_free_bitmap(map->s_fspace.s_bitmap);
1871 if (map->s_partition_type == UDF_SPARABLE_MAP15)
1872 for (i = 0; i < 4; i++)
1873 brelse(map->s_type_specific.s_sparing.s_spar_map[i]);
1874 else if (map->s_partition_type == UDF_METADATA_MAP25) {
1875 mdata = &map->s_type_specific.s_metadata;
1876 iput(mdata->s_metadata_fe);
1877 mdata->s_metadata_fe = NULL;
1879 iput(mdata->s_mirror_fe);
1880 mdata->s_mirror_fe = NULL;
1882 iput(mdata->s_bitmap_fe);
1883 mdata->s_bitmap_fe = NULL;
1887 static int udf_fill_super(struct super_block *sb, void *options, int silent)
1891 struct inode *inode = NULL;
1892 struct udf_options uopt;
1893 struct kernel_lb_addr rootdir, fileset;
1894 struct udf_sb_info *sbi;
1896 uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
1900 uopt.fmode = UDF_INVALID_MODE;
1901 uopt.dmode = UDF_INVALID_MODE;
1903 sbi = kzalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
1907 sb->s_fs_info = sbi;
1909 mutex_init(&sbi->s_alloc_mutex);
1911 if (!udf_parse_options((char *)options, &uopt, false))
1914 if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
1915 uopt.flags & (1 << UDF_FLAG_NLS_MAP)) {
1916 udf_error(sb, "udf_read_super",
1917 "utf8 cannot be combined with iocharset\n");
1920 #ifdef CONFIG_UDF_NLS
1921 if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) {
1922 uopt.nls_map = load_nls_default();
1924 uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
1926 udf_debug("Using default NLS map\n");
1929 if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
1930 uopt.flags |= (1 << UDF_FLAG_UTF8);
1932 fileset.logicalBlockNum = 0xFFFFFFFF;
1933 fileset.partitionReferenceNum = 0xFFFF;
1935 sbi->s_flags = uopt.flags;
1936 sbi->s_uid = uopt.uid;
1937 sbi->s_gid = uopt.gid;
1938 sbi->s_umask = uopt.umask;
1939 sbi->s_fmode = uopt.fmode;
1940 sbi->s_dmode = uopt.dmode;
1941 sbi->s_nls_map = uopt.nls_map;
1943 if (uopt.session == 0xFFFFFFFF)
1944 sbi->s_session = udf_get_last_session(sb);
1946 sbi->s_session = uopt.session;
1948 udf_debug("Multi-session=%d\n", sbi->s_session);
1950 /* Fill in the rest of the superblock */
1951 sb->s_op = &udf_sb_ops;
1952 sb->s_export_op = &udf_export_ops;
1955 sb->s_magic = UDF_SUPER_MAGIC;
1956 sb->s_time_gran = 1000;
1958 if (uopt.flags & (1 << UDF_FLAG_BLOCKSIZE_SET)) {
1959 ret = udf_load_vrs(sb, &uopt, silent, &fileset);
1961 uopt.blocksize = bdev_logical_block_size(sb->s_bdev);
1962 ret = udf_load_vrs(sb, &uopt, silent, &fileset);
1963 if (!ret && uopt.blocksize != UDF_DEFAULT_BLOCKSIZE) {
1966 "UDF-fs: Rescanning with blocksize "
1967 "%d\n", UDF_DEFAULT_BLOCKSIZE);
1968 uopt.blocksize = UDF_DEFAULT_BLOCKSIZE;
1969 ret = udf_load_vrs(sb, &uopt, silent, &fileset);
1973 printk(KERN_WARNING "UDF-fs: No partition found (1)\n");
1977 udf_debug("Lastblock=%d\n", sbi->s_last_block);
1979 if (sbi->s_lvid_bh) {
1980 struct logicalVolIntegrityDescImpUse *lvidiu =
1982 uint16_t minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev);
1983 uint16_t minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev);
1984 /* uint16_t maxUDFWriteRev =
1985 le16_to_cpu(lvidiu->maxUDFWriteRev); */
1987 if (minUDFReadRev > UDF_MAX_READ_VERSION) {
1988 printk(KERN_ERR "UDF-fs: minUDFReadRev=%x "
1990 le16_to_cpu(lvidiu->minUDFReadRev),
1991 UDF_MAX_READ_VERSION);
1993 } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
1994 sb->s_flags |= MS_RDONLY;
1996 sbi->s_udfrev = minUDFWriteRev;
1998 if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
1999 UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
2000 if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
2001 UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
2004 if (!sbi->s_partitions) {
2005 printk(KERN_WARNING "UDF-fs: No partition found (2)\n");
2009 if (sbi->s_partmaps[sbi->s_partition].s_partition_flags &
2010 UDF_PART_FLAG_READ_ONLY) {
2011 printk(KERN_NOTICE "UDF-fs: Partition marked readonly; "
2012 "forcing readonly mount\n");
2013 sb->s_flags |= MS_RDONLY;
2016 if (udf_find_fileset(sb, &fileset, &rootdir)) {
2017 printk(KERN_WARNING "UDF-fs: No fileset found\n");
2022 struct timestamp ts;
2023 udf_time_to_disk_stamp(&ts, sbi->s_record_time);
2024 udf_info("UDF: Mounting volume '%s', "
2025 "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
2026 sbi->s_volume_ident, le16_to_cpu(ts.year), ts.month, ts.day,
2027 ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone));
2029 if (!(sb->s_flags & MS_RDONLY))
2032 /* Assign the root inode */
2033 /* assign inodes by physical block number */
2034 /* perhaps it's not extensible enough, but for now ... */
2035 inode = udf_iget(sb, &rootdir);
2037 printk(KERN_ERR "UDF-fs: Error in udf_iget, block=%d, "
2039 rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
2043 /* Allocate a dentry for the root inode */
2044 sb->s_root = d_alloc_root(inode);
2046 printk(KERN_ERR "UDF-fs: Couldn't allocate root dentry\n");
2050 sb->s_maxbytes = MAX_LFS_FILESIZE;
2054 if (sbi->s_vat_inode)
2055 iput(sbi->s_vat_inode);
2056 if (sbi->s_partitions)
2057 for (i = 0; i < sbi->s_partitions; i++)
2058 udf_free_partition(&sbi->s_partmaps[i]);
2059 #ifdef CONFIG_UDF_NLS
2060 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
2061 unload_nls(sbi->s_nls_map);
2063 if (!(sb->s_flags & MS_RDONLY))
2065 brelse(sbi->s_lvid_bh);
2067 kfree(sbi->s_partmaps);
2069 sb->s_fs_info = NULL;
2074 static void udf_error(struct super_block *sb, const char *function,
2075 const char *fmt, ...)
2079 if (!(sb->s_flags & MS_RDONLY)) {
2083 va_start(args, fmt);
2084 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
2086 printk(KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
2087 sb->s_id, function, error_buf);
2090 void udf_warning(struct super_block *sb, const char *function,
2091 const char *fmt, ...)
2095 va_start(args, fmt);
2096 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
2098 printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
2099 sb->s_id, function, error_buf);
2102 static void udf_put_super(struct super_block *sb)
2105 struct udf_sb_info *sbi;
2111 if (sbi->s_vat_inode)
2112 iput(sbi->s_vat_inode);
2113 if (sbi->s_partitions)
2114 for (i = 0; i < sbi->s_partitions; i++)
2115 udf_free_partition(&sbi->s_partmaps[i]);
2116 #ifdef CONFIG_UDF_NLS
2117 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
2118 unload_nls(sbi->s_nls_map);
2120 if (!(sb->s_flags & MS_RDONLY))
2122 brelse(sbi->s_lvid_bh);
2123 kfree(sbi->s_partmaps);
2124 kfree(sb->s_fs_info);
2125 sb->s_fs_info = NULL;
2130 static int udf_sync_fs(struct super_block *sb, int wait)
2132 struct udf_sb_info *sbi = UDF_SB(sb);
2134 mutex_lock(&sbi->s_alloc_mutex);
2135 if (sbi->s_lvid_dirty) {
2137 * Blockdevice will be synced later so we don't have to submit
2140 mark_buffer_dirty(sbi->s_lvid_bh);
2142 sbi->s_lvid_dirty = 0;
2144 mutex_unlock(&sbi->s_alloc_mutex);
2149 static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
2151 struct super_block *sb = dentry->d_sb;
2152 struct udf_sb_info *sbi = UDF_SB(sb);
2153 struct logicalVolIntegrityDescImpUse *lvidiu;
2154 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
2156 if (sbi->s_lvid_bh != NULL)
2157 lvidiu = udf_sb_lvidiu(sbi);
2161 buf->f_type = UDF_SUPER_MAGIC;
2162 buf->f_bsize = sb->s_blocksize;
2163 buf->f_blocks = sbi->s_partmaps[sbi->s_partition].s_partition_len;
2164 buf->f_bfree = udf_count_free(sb);
2165 buf->f_bavail = buf->f_bfree;
2166 buf->f_files = (lvidiu != NULL ? (le32_to_cpu(lvidiu->numFiles) +
2167 le32_to_cpu(lvidiu->numDirs)) : 0)
2169 buf->f_ffree = buf->f_bfree;
2170 buf->f_namelen = UDF_NAME_LEN - 2;
2171 buf->f_fsid.val[0] = (u32)id;
2172 buf->f_fsid.val[1] = (u32)(id >> 32);
2177 static unsigned int udf_count_free_bitmap(struct super_block *sb,
2178 struct udf_bitmap *bitmap)
2180 struct buffer_head *bh = NULL;
2181 unsigned int accum = 0;
2183 int block = 0, newblock;
2184 struct kernel_lb_addr loc;
2188 struct spaceBitmapDesc *bm;
2192 loc.logicalBlockNum = bitmap->s_extPosition;
2193 loc.partitionReferenceNum = UDF_SB(sb)->s_partition;
2194 bh = udf_read_ptagged(sb, &loc, 0, &ident);
2197 printk(KERN_ERR "udf: udf_count_free failed\n");
2199 } else if (ident != TAG_IDENT_SBD) {
2201 printk(KERN_ERR "udf: udf_count_free failed\n");
2205 bm = (struct spaceBitmapDesc *)bh->b_data;
2206 bytes = le32_to_cpu(bm->numOfBytes);
2207 index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
2208 ptr = (uint8_t *)bh->b_data;
2211 u32 cur_bytes = min_t(u32, bytes, sb->s_blocksize - index);
2212 accum += bitmap_weight((const unsigned long *)(ptr + index),
2217 newblock = udf_get_lb_pblock(sb, &loc, ++block);
2218 bh = udf_tread(sb, newblock);
2220 udf_debug("read failed\n");
2224 ptr = (uint8_t *)bh->b_data;
2235 static unsigned int udf_count_free_table(struct super_block *sb,
2236 struct inode *table)
2238 unsigned int accum = 0;
2240 struct kernel_lb_addr eloc;
2242 struct extent_position epos;
2246 epos.block = UDF_I(table)->i_location;
2247 epos.offset = sizeof(struct unallocSpaceEntry);
2250 while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
2251 accum += (elen >> table->i_sb->s_blocksize_bits);
2260 static unsigned int udf_count_free(struct super_block *sb)
2262 unsigned int accum = 0;
2263 struct udf_sb_info *sbi;
2264 struct udf_part_map *map;
2267 if (sbi->s_lvid_bh) {
2268 struct logicalVolIntegrityDesc *lvid =
2269 (struct logicalVolIntegrityDesc *)
2270 sbi->s_lvid_bh->b_data;
2271 if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) {
2272 accum = le32_to_cpu(
2273 lvid->freeSpaceTable[sbi->s_partition]);
2274 if (accum == 0xFFFFFFFF)
2282 map = &sbi->s_partmaps[sbi->s_partition];
2283 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
2284 accum += udf_count_free_bitmap(sb,
2285 map->s_uspace.s_bitmap);
2287 if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) {
2288 accum += udf_count_free_bitmap(sb,
2289 map->s_fspace.s_bitmap);
2294 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
2295 accum += udf_count_free_table(sb,
2296 map->s_uspace.s_table);
2298 if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) {
2299 accum += udf_count_free_table(sb,
2300 map->s_fspace.s_table);