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 <asm/byteorder.h>
64 #include <linux/init.h>
65 #include <asm/uaccess.h>
67 #define VDS_POS_PRIMARY_VOL_DESC 0
68 #define VDS_POS_UNALLOC_SPACE_DESC 1
69 #define VDS_POS_LOGICAL_VOL_DESC 2
70 #define VDS_POS_PARTITION_DESC 3
71 #define VDS_POS_IMP_USE_VOL_DESC 4
72 #define VDS_POS_VOL_DESC_PTR 5
73 #define VDS_POS_TERMINATING_DESC 6
74 #define VDS_POS_LENGTH 7
76 #define UDF_DEFAULT_BLOCKSIZE 2048
78 static char error_buf
[1024];
80 /* These are the "meat" - everything else is stuffing */
81 static int udf_fill_super(struct super_block
*, void *, int);
82 static void udf_put_super(struct super_block
*);
83 static void udf_write_super(struct super_block
*);
84 static int udf_remount_fs(struct super_block
*, int *, char *);
85 static int udf_check_valid(struct super_block
*, int, int);
86 static int udf_vrs(struct super_block
*sb
, int silent
);
87 static int udf_load_partition(struct super_block
*, kernel_lb_addr
*);
88 static void udf_load_logicalvolint(struct super_block
*, kernel_extent_ad
);
89 static void udf_find_anchor(struct super_block
*);
90 static int udf_find_fileset(struct super_block
*, kernel_lb_addr
*,
92 static void udf_load_fileset(struct super_block
*, struct buffer_head
*,
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(struct kmem_cache
*cachep
, 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
;
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
, __FUNCTION__
,
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 (sb
->s_blocksize
!= UDF_DEFAULT_BLOCKSIZE
)
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 (UDF_QUERY_FLAG(sb
, UDF_FLAG_SESSION_SET
))
286 seq_printf(seq
, ",session=%u", sbi
->s_session
);
287 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_LASTBLOCK_SET
))
288 seq_printf(seq
, ",lastblock=%u", sbi
->s_last_block
);
290 * s_anchor[2] could be zeroed out in case there is no anchor
291 * in the specified block, but then the "anchor=N" option
292 * originally given by the user wasn't effective, so it's OK
293 * if we don't show it.
295 if (sbi
->s_anchor
[2] != 0)
296 seq_printf(seq
, ",anchor=%u", sbi
->s_anchor
[2]);
298 * volume, partition, fileset and rootdir seem to be ignored
301 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UTF8
))
302 seq_puts(seq
, ",utf8");
303 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
) && sbi
->s_nls_map
)
304 seq_printf(seq
, ",iocharset=%s", sbi
->s_nls_map
->charset
);
313 * Parse mount options.
316 * The following mount options are supported:
318 * gid= Set the default group.
319 * umask= Set the default umask.
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
372 static match_table_t tokens
= {
373 {Opt_novrs
, "novrs"},
374 {Opt_nostrict
, "nostrict"},
376 {Opt_unhide
, "unhide"},
377 {Opt_undelete
, "undelete"},
378 {Opt_noadinicb
, "noadinicb"},
379 {Opt_adinicb
, "adinicb"},
380 {Opt_shortad
, "shortad"},
381 {Opt_longad
, "longad"},
382 {Opt_uforget
, "uid=forget"},
383 {Opt_uignore
, "uid=ignore"},
384 {Opt_gforget
, "gid=forget"},
385 {Opt_gignore
, "gid=ignore"},
388 {Opt_umask
, "umask=%o"},
389 {Opt_session
, "session=%u"},
390 {Opt_lastblock
, "lastblock=%u"},
391 {Opt_anchor
, "anchor=%u"},
392 {Opt_volume
, "volume=%u"},
393 {Opt_partition
, "partition=%u"},
394 {Opt_fileset
, "fileset=%u"},
395 {Opt_rootdir
, "rootdir=%u"},
397 {Opt_iocharset
, "iocharset=%s"},
401 static int udf_parse_options(char *options
, struct udf_options
*uopt
,
408 uopt
->blocksize
= UDF_DEFAULT_BLOCKSIZE
;
409 uopt
->partition
= 0xFFFF;
410 uopt
->session
= 0xFFFFFFFF;
413 uopt
->volume
= 0xFFFFFFFF;
414 uopt
->rootdir
= 0xFFFFFFFF;
415 uopt
->fileset
= 0xFFFFFFFF;
416 uopt
->nls_map
= NULL
;
421 while ((p
= strsep(&options
, ",")) != NULL
) {
422 substring_t args
[MAX_OPT_ARGS
];
427 token
= match_token(p
, tokens
, args
);
432 if (match_int(&args
[0], &option
))
434 uopt
->blocksize
= option
;
437 uopt
->flags
|= (1 << UDF_FLAG_UNHIDE
);
440 uopt
->flags
|= (1 << UDF_FLAG_UNDELETE
);
443 uopt
->flags
&= ~(1 << UDF_FLAG_USE_AD_IN_ICB
);
446 uopt
->flags
|= (1 << UDF_FLAG_USE_AD_IN_ICB
);
449 uopt
->flags
|= (1 << UDF_FLAG_USE_SHORT_AD
);
452 uopt
->flags
&= ~(1 << UDF_FLAG_USE_SHORT_AD
);
455 if (match_int(args
, &option
))
458 uopt
->flags
|= (1 << UDF_FLAG_GID_SET
);
461 if (match_int(args
, &option
))
464 uopt
->flags
|= (1 << UDF_FLAG_UID_SET
);
467 if (match_octal(args
, &option
))
469 uopt
->umask
= option
;
472 uopt
->flags
&= ~(1 << UDF_FLAG_STRICT
);
475 if (match_int(args
, &option
))
477 uopt
->session
= option
;
479 uopt
->flags
|= (1 << UDF_FLAG_SESSION_SET
);
482 if (match_int(args
, &option
))
484 uopt
->lastblock
= option
;
486 uopt
->flags
|= (1 << UDF_FLAG_LASTBLOCK_SET
);
489 if (match_int(args
, &option
))
491 uopt
->anchor
= option
;
494 if (match_int(args
, &option
))
496 uopt
->volume
= option
;
499 if (match_int(args
, &option
))
501 uopt
->partition
= option
;
504 if (match_int(args
, &option
))
506 uopt
->fileset
= option
;
509 if (match_int(args
, &option
))
511 uopt
->rootdir
= option
;
514 uopt
->flags
|= (1 << UDF_FLAG_UTF8
);
516 #ifdef CONFIG_UDF_NLS
518 uopt
->nls_map
= load_nls(args
[0].from
);
519 uopt
->flags
|= (1 << UDF_FLAG_NLS_MAP
);
523 uopt
->flags
|= (1 << UDF_FLAG_UID_IGNORE
);
526 uopt
->flags
|= (1 << UDF_FLAG_UID_FORGET
);
529 uopt
->flags
|= (1 << UDF_FLAG_GID_IGNORE
);
532 uopt
->flags
|= (1 << UDF_FLAG_GID_FORGET
);
535 printk(KERN_ERR
"udf: bad mount option \"%s\" "
536 "or missing value\n", p
);
543 static void udf_write_super(struct super_block
*sb
)
547 if (!(sb
->s_flags
& MS_RDONLY
))
554 static int udf_remount_fs(struct super_block
*sb
, int *flags
, char *options
)
556 struct udf_options uopt
;
557 struct udf_sb_info
*sbi
= UDF_SB(sb
);
559 uopt
.flags
= sbi
->s_flags
;
560 uopt
.uid
= sbi
->s_uid
;
561 uopt
.gid
= sbi
->s_gid
;
562 uopt
.umask
= sbi
->s_umask
;
564 if (!udf_parse_options(options
, &uopt
, true))
567 sbi
->s_flags
= uopt
.flags
;
568 sbi
->s_uid
= uopt
.uid
;
569 sbi
->s_gid
= uopt
.gid
;
570 sbi
->s_umask
= uopt
.umask
;
572 if (sbi
->s_lvid_bh
) {
573 int write_rev
= le16_to_cpu(udf_sb_lvidiu(sbi
)->minUDFWriteRev
);
574 if (write_rev
> UDF_MAX_WRITE_VERSION
)
578 if ((*flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
))
580 if (*flags
& MS_RDONLY
)
588 static int udf_vrs(struct super_block
*sb
, int silent
)
590 struct volStructDesc
*vsd
= NULL
;
593 struct buffer_head
*bh
= NULL
;
597 struct udf_sb_info
*sbi
;
599 /* Block size must be a multiple of 512 */
600 if (sb
->s_blocksize
& 511)
604 if (sb
->s_blocksize
< sizeof(struct volStructDesc
))
605 sectorsize
= sizeof(struct volStructDesc
);
607 sectorsize
= sb
->s_blocksize
;
609 sector
+= (sbi
->s_session
<< sb
->s_blocksize_bits
);
611 udf_debug("Starting at sector %u (%ld byte sectors)\n",
612 (sector
>> sb
->s_blocksize_bits
), sb
->s_blocksize
);
613 /* Process the sequence (if applicable) */
614 for (; !nsr02
&& !nsr03
; sector
+= sectorsize
) {
616 bh
= udf_tread(sb
, sector
>> sb
->s_blocksize_bits
);
620 /* Look for ISO descriptors */
621 vsd
= (struct volStructDesc
*)(bh
->b_data
+
622 (sector
& (sb
->s_blocksize
- 1)));
624 if (vsd
->stdIdent
[0] == 0) {
627 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_CD001
,
630 switch (vsd
->structType
) {
632 udf_debug("ISO9660 Boot Record found\n");
635 udf_debug("ISO9660 Primary Volume Descriptor "
639 udf_debug("ISO9660 Supplementary Volume "
640 "Descriptor found\n");
643 udf_debug("ISO9660 Volume Partition Descriptor "
647 udf_debug("ISO9660 Volume Descriptor Set "
648 "Terminator found\n");
651 udf_debug("ISO9660 VRS (%u) found\n",
655 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_BEA01
,
658 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_TEA01
,
662 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR02
,
665 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR03
,
675 else if (sector
- (sbi
->s_session
<< sb
->s_blocksize_bits
) == 32768)
685 * Find an anchor volume descriptor.
688 * sb Pointer to _locked_ superblock.
689 * lastblock Last block on media.
692 * <return> 1 if not found, 0 if ok
695 * July 1, 1997 - Andrew E. Mileski
696 * Written, tested, and released.
698 static void udf_find_anchor(struct super_block
*sb
)
701 struct buffer_head
*bh
= NULL
;
705 struct udf_sb_info
*sbi
;
708 lastblock
= sbi
->s_last_block
;
711 int varlastblock
= udf_variable_to_fixed(lastblock
);
712 int last
[] = { lastblock
, lastblock
- 2,
713 lastblock
- 150, lastblock
- 152,
714 varlastblock
, varlastblock
- 2,
715 varlastblock
- 150, varlastblock
- 152 };
719 /* Search for an anchor volume descriptor pointer */
721 /* according to spec, anchor is in either:
725 * however, if the disc isn't closed, it could be 512 */
727 for (i
= 0; !lastblock
&& i
< ARRAY_SIZE(last
); i
++) {
728 ident
= location
= 0;
730 bh
= sb_bread(sb
, last
[i
]);
732 tag
*t
= (tag
*)bh
->b_data
;
733 ident
= le16_to_cpu(t
->tagIdent
);
734 location
= le32_to_cpu(t
->tagLocation
);
739 if (ident
== TAG_IDENT_AVDP
) {
740 if (location
== last
[i
] - sbi
->s_session
) {
741 lastblock
= last
[i
] - sbi
->s_session
;
742 sbi
->s_anchor
[0] = lastblock
;
743 sbi
->s_anchor
[1] = lastblock
- 256;
744 } else if (location
==
745 udf_variable_to_fixed(last
[i
]) -
747 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
749 udf_variable_to_fixed(last
[i
]) -
751 sbi
->s_anchor
[0] = lastblock
;
752 sbi
->s_anchor
[1] = lastblock
- 256 -
755 udf_debug("Anchor found at block %d, "
756 "location mismatch %d.\n",
759 } else if (ident
== TAG_IDENT_FE
||
760 ident
== TAG_IDENT_EFE
) {
762 sbi
->s_anchor
[3] = 512;
764 ident
= location
= 0;
765 if (last
[i
] >= 256) {
766 bh
= sb_bread(sb
, last
[i
] - 256);
768 tag
*t
= (tag
*)bh
->b_data
;
771 location
= le32_to_cpu(
777 if (ident
== TAG_IDENT_AVDP
&&
778 location
== last
[i
] - 256 -
781 sbi
->s_anchor
[1] = last
[i
] - 256;
783 ident
= location
= 0;
784 if (last
[i
] >= 312 + sbi
->s_session
) {
793 location
= le32_to_cpu(
799 if (ident
== TAG_IDENT_AVDP
&&
800 location
== udf_variable_to_fixed(last
[i
]) - 256) {
803 lastblock
= udf_variable_to_fixed(last
[i
]);
804 sbi
->s_anchor
[1] = lastblock
- 256;
812 /* We haven't found the lastblock. check 312 */
813 bh
= sb_bread(sb
, 312 + sbi
->s_session
);
815 tag
*t
= (tag
*)bh
->b_data
;
816 ident
= le16_to_cpu(t
->tagIdent
);
817 location
= le32_to_cpu(t
->tagLocation
);
820 if (ident
== TAG_IDENT_AVDP
&& location
== 256)
821 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
825 for (i
= 0; i
< ARRAY_SIZE(sbi
->s_anchor
); i
++) {
826 if (!sbi
->s_anchor
[i
])
828 bh
= udf_read_tagged(sb
, sbi
->s_anchor
[i
],
829 sbi
->s_anchor
[i
], &ident
);
831 sbi
->s_anchor
[i
] = 0;
834 if ((ident
!= TAG_IDENT_AVDP
) &&
835 (i
|| (ident
!= TAG_IDENT_FE
&&
836 ident
!= TAG_IDENT_EFE
)))
837 sbi
->s_anchor
[i
] = 0;
841 sbi
->s_last_block
= lastblock
;
844 static int udf_find_fileset(struct super_block
*sb
,
845 kernel_lb_addr
*fileset
,
846 kernel_lb_addr
*root
)
848 struct buffer_head
*bh
= NULL
;
851 struct udf_sb_info
*sbi
;
853 if (fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
854 fileset
->partitionReferenceNum
!= 0xFFFF) {
855 bh
= udf_read_ptagged(sb
, *fileset
, 0, &ident
);
859 } else if (ident
!= TAG_IDENT_FSD
) {
868 /* Search backwards through the partitions */
869 kernel_lb_addr newfileset
;
871 /* --> cvg: FIXME - is it reasonable? */
874 for (newfileset
.partitionReferenceNum
= sbi
->s_partitions
- 1;
875 (newfileset
.partitionReferenceNum
!= 0xFFFF &&
876 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
877 fileset
->partitionReferenceNum
== 0xFFFF);
878 newfileset
.partitionReferenceNum
--) {
879 lastblock
= sbi
->s_partmaps
880 [newfileset
.partitionReferenceNum
]
882 newfileset
.logicalBlockNum
= 0;
885 bh
= udf_read_ptagged(sb
, newfileset
, 0,
888 newfileset
.logicalBlockNum
++;
895 struct spaceBitmapDesc
*sp
;
896 sp
= (struct spaceBitmapDesc
*)
898 newfileset
.logicalBlockNum
+= 1 +
899 ((le32_to_cpu(sp
->numOfBytes
) +
900 sizeof(struct spaceBitmapDesc
)
901 - 1) >> sb
->s_blocksize_bits
);
906 *fileset
= newfileset
;
909 newfileset
.logicalBlockNum
++;
914 } while (newfileset
.logicalBlockNum
< lastblock
&&
915 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
916 fileset
->partitionReferenceNum
== 0xFFFF);
920 if ((fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
921 fileset
->partitionReferenceNum
!= 0xFFFF) && bh
) {
922 udf_debug("Fileset at block=%d, partition=%d\n",
923 fileset
->logicalBlockNum
,
924 fileset
->partitionReferenceNum
);
926 sbi
->s_partition
= fileset
->partitionReferenceNum
;
927 udf_load_fileset(sb
, bh
, root
);
934 static int udf_load_pvoldesc(struct super_block
*sb
, sector_t block
)
936 struct primaryVolDesc
*pvoldesc
;
939 struct buffer_head
*bh
;
942 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
945 BUG_ON(ident
!= TAG_IDENT_PVD
);
947 pvoldesc
= (struct primaryVolDesc
*)bh
->b_data
;
949 if (udf_disk_stamp_to_time(&UDF_SB(sb
)->s_record_time
,
950 pvoldesc
->recordingDateAndTime
)) {
952 timestamp
*ts
= &pvoldesc
->recordingDateAndTime
;
953 udf_debug("recording time %04u/%02u/%02u"
955 le16_to_cpu(ts
->year
), ts
->month
, ts
->day
, ts
->hour
,
956 ts
->minute
, le16_to_cpu(ts
->typeAndTimezone
));
960 if (!udf_build_ustr(&instr
, pvoldesc
->volIdent
, 32))
961 if (udf_CS0toUTF8(&outstr
, &instr
)) {
962 strncpy(UDF_SB(sb
)->s_volume_ident
, outstr
.u_name
,
963 outstr
.u_len
> 31 ? 31 : outstr
.u_len
);
964 udf_debug("volIdent[] = '%s'\n",
965 UDF_SB(sb
)->s_volume_ident
);
968 if (!udf_build_ustr(&instr
, pvoldesc
->volSetIdent
, 128))
969 if (udf_CS0toUTF8(&outstr
, &instr
))
970 udf_debug("volSetIdent[] = '%s'\n", outstr
.u_name
);
976 static void udf_load_fileset(struct super_block
*sb
, struct buffer_head
*bh
,
977 kernel_lb_addr
*root
)
979 struct fileSetDesc
*fset
;
981 fset
= (struct fileSetDesc
*)bh
->b_data
;
983 *root
= lelb_to_cpu(fset
->rootDirectoryICB
.extLocation
);
985 UDF_SB(sb
)->s_serial_number
= le16_to_cpu(fset
->descTag
.tagSerialNum
);
987 udf_debug("Rootdir at block=%d, partition=%d\n",
988 root
->logicalBlockNum
, root
->partitionReferenceNum
);
991 int udf_compute_nr_groups(struct super_block
*sb
, u32 partition
)
993 struct udf_part_map
*map
= &UDF_SB(sb
)->s_partmaps
[partition
];
994 return DIV_ROUND_UP(map
->s_partition_len
+
995 (sizeof(struct spaceBitmapDesc
) << 3),
996 sb
->s_blocksize
* 8);
999 static struct udf_bitmap
*udf_sb_alloc_bitmap(struct super_block
*sb
, u32 index
)
1001 struct udf_bitmap
*bitmap
;
1005 nr_groups
= udf_compute_nr_groups(sb
, index
);
1006 size
= sizeof(struct udf_bitmap
) +
1007 (sizeof(struct buffer_head
*) * nr_groups
);
1009 if (size
<= PAGE_SIZE
)
1010 bitmap
= kmalloc(size
, GFP_KERNEL
);
1012 bitmap
= vmalloc(size
); /* TODO: get rid of vmalloc */
1014 if (bitmap
== NULL
) {
1015 udf_error(sb
, __FUNCTION__
,
1016 "Unable to allocate space for bitmap "
1017 "and %d buffer_head pointers", nr_groups
);
1021 memset(bitmap
, 0x00, size
);
1022 bitmap
->s_block_bitmap
= (struct buffer_head
**)(bitmap
+ 1);
1023 bitmap
->s_nr_groups
= nr_groups
;
1027 static int udf_fill_partdesc_info(struct super_block
*sb
,
1028 struct partitionDesc
*p
, int p_index
)
1030 struct udf_part_map
*map
;
1031 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1032 struct partitionHeaderDesc
*phd
;
1034 map
= &sbi
->s_partmaps
[p_index
];
1036 map
->s_partition_len
= le32_to_cpu(p
->partitionLength
); /* blocks */
1037 map
->s_partition_root
= le32_to_cpu(p
->partitionStartingLocation
);
1039 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY
))
1040 map
->s_partition_flags
|= UDF_PART_FLAG_READ_ONLY
;
1041 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE
))
1042 map
->s_partition_flags
|= UDF_PART_FLAG_WRITE_ONCE
;
1043 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE
))
1044 map
->s_partition_flags
|= UDF_PART_FLAG_REWRITABLE
;
1045 if (p
->accessType
== cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE
))
1046 map
->s_partition_flags
|= UDF_PART_FLAG_OVERWRITABLE
;
1048 udf_debug("Partition (%d:%d type %x) starts at physical %d, "
1049 "block length %d\n", partitionNumber
, p_index
,
1050 map
->s_partition_type
, map
->s_partition_root
,
1051 map
->s_partition_len
);
1053 if (strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR02
) &&
1054 strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR03
))
1057 phd
= (struct partitionHeaderDesc
*)p
->partitionContentsUse
;
1058 if (phd
->unallocSpaceTable
.extLength
) {
1059 kernel_lb_addr loc
= {
1060 .logicalBlockNum
= le32_to_cpu(
1061 phd
->unallocSpaceTable
.extPosition
),
1062 .partitionReferenceNum
= p_index
,
1065 map
->s_uspace
.s_table
= udf_iget(sb
, loc
);
1066 if (!map
->s_uspace
.s_table
) {
1067 udf_debug("cannot load unallocSpaceTable (part %d)\n",
1071 map
->s_partition_flags
|= UDF_PART_FLAG_UNALLOC_TABLE
;
1072 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
1073 p_index
, map
->s_uspace
.s_table
->i_ino
);
1076 if (phd
->unallocSpaceBitmap
.extLength
) {
1077 struct udf_bitmap
*bitmap
= udf_sb_alloc_bitmap(sb
, p_index
);
1080 map
->s_uspace
.s_bitmap
= bitmap
;
1081 bitmap
->s_extLength
= le32_to_cpu(
1082 phd
->unallocSpaceBitmap
.extLength
);
1083 bitmap
->s_extPosition
= le32_to_cpu(
1084 phd
->unallocSpaceBitmap
.extPosition
);
1085 map
->s_partition_flags
|= UDF_PART_FLAG_UNALLOC_BITMAP
;
1086 udf_debug("unallocSpaceBitmap (part %d) @ %d\n", p_index
,
1087 bitmap
->s_extPosition
);
1090 if (phd
->partitionIntegrityTable
.extLength
)
1091 udf_debug("partitionIntegrityTable (part %d)\n", p_index
);
1093 if (phd
->freedSpaceTable
.extLength
) {
1094 kernel_lb_addr loc
= {
1095 .logicalBlockNum
= le32_to_cpu(
1096 phd
->freedSpaceTable
.extPosition
),
1097 .partitionReferenceNum
= p_index
,
1100 map
->s_fspace
.s_table
= udf_iget(sb
, loc
);
1101 if (!map
->s_fspace
.s_table
) {
1102 udf_debug("cannot load freedSpaceTable (part %d)\n",
1107 map
->s_partition_flags
|= UDF_PART_FLAG_FREED_TABLE
;
1108 udf_debug("freedSpaceTable (part %d) @ %ld\n",
1109 p_index
, map
->s_fspace
.s_table
->i_ino
);
1112 if (phd
->freedSpaceBitmap
.extLength
) {
1113 struct udf_bitmap
*bitmap
= udf_sb_alloc_bitmap(sb
, p_index
);
1116 map
->s_fspace
.s_bitmap
= bitmap
;
1117 bitmap
->s_extLength
= le32_to_cpu(
1118 phd
->freedSpaceBitmap
.extLength
);
1119 bitmap
->s_extPosition
= le32_to_cpu(
1120 phd
->freedSpaceBitmap
.extPosition
);
1121 map
->s_partition_flags
|= UDF_PART_FLAG_FREED_BITMAP
;
1122 udf_debug("freedSpaceBitmap (part %d) @ %d\n", p_index
,
1123 bitmap
->s_extPosition
);
1128 static int udf_load_partdesc(struct super_block
*sb
, sector_t block
)
1130 struct buffer_head
*bh
;
1131 struct partitionDesc
*p
;
1132 struct udf_part_map
*map
;
1133 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1136 uint16_t partitionNumber
;
1140 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1143 if (ident
!= TAG_IDENT_PD
)
1146 p
= (struct partitionDesc
*)bh
->b_data
;
1147 partitionNumber
= le16_to_cpu(p
->partitionNumber
);
1148 for (i
= 0; i
< sbi
->s_partitions
; i
++) {
1149 map
= &sbi
->s_partmaps
[i
];
1150 udf_debug("Searching map: (%d == %d)\n",
1151 map
->s_partition_num
, partitionNumber
);
1152 found
= map
->s_partition_num
== partitionNumber
;
1158 udf_debug("Partition (%d) not found in partition map\n",
1163 ret
= udf_fill_partdesc_info(sb
, p
, i
);
1165 /* In case loading failed, we handle cleanup in udf_fill_super */
1170 static int udf_load_logicalvol(struct super_block
*sb
, sector_t block
,
1171 kernel_lb_addr
*fileset
)
1173 struct logicalVolDesc
*lvd
;
1176 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1177 struct genericPartitionMap
*gpm
;
1179 struct buffer_head
*bh
;
1182 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1185 BUG_ON(ident
!= TAG_IDENT_LVD
);
1186 lvd
= (struct logicalVolDesc
*)bh
->b_data
;
1188 i
= udf_sb_alloc_partition_maps(sb
, le32_to_cpu(lvd
->numPartitionMaps
));
1194 for (i
= 0, offset
= 0;
1195 i
< sbi
->s_partitions
&& offset
< le32_to_cpu(lvd
->mapTableLength
);
1196 i
++, offset
+= gpm
->partitionMapLength
) {
1197 struct udf_part_map
*map
= &sbi
->s_partmaps
[i
];
1198 gpm
= (struct genericPartitionMap
*)
1199 &(lvd
->partitionMaps
[offset
]);
1200 type
= gpm
->partitionMapType
;
1202 struct genericPartitionMap1
*gpm1
=
1203 (struct genericPartitionMap1
*)gpm
;
1204 map
->s_partition_type
= UDF_TYPE1_MAP15
;
1205 map
->s_volumeseqnum
= le16_to_cpu(gpm1
->volSeqNum
);
1206 map
->s_partition_num
= le16_to_cpu(gpm1
->partitionNum
);
1207 map
->s_partition_func
= NULL
;
1208 } else if (type
== 2) {
1209 struct udfPartitionMap2
*upm2
=
1210 (struct udfPartitionMap2
*)gpm
;
1211 if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_VIRTUAL
,
1212 strlen(UDF_ID_VIRTUAL
))) {
1214 le16_to_cpu(((__le16
*)upm2
->partIdent
.
1216 if (suf
== 0x0150) {
1217 map
->s_partition_type
=
1219 map
->s_partition_func
=
1220 udf_get_pblock_virt15
;
1221 } else if (suf
== 0x0200) {
1222 map
->s_partition_type
=
1224 map
->s_partition_func
=
1225 udf_get_pblock_virt20
;
1227 } else if (!strncmp(upm2
->partIdent
.ident
,
1229 strlen(UDF_ID_SPARABLE
))) {
1231 struct sparingTable
*st
;
1232 struct sparablePartitionMap
*spm
=
1233 (struct sparablePartitionMap
*)gpm
;
1235 map
->s_partition_type
= UDF_SPARABLE_MAP15
;
1236 map
->s_type_specific
.s_sparing
.s_packet_len
=
1237 le16_to_cpu(spm
->packetLength
);
1238 for (j
= 0; j
< spm
->numSparingTables
; j
++) {
1239 struct buffer_head
*bh2
;
1242 spm
->locSparingTable
[j
]);
1243 bh2
= udf_read_tagged(sb
, loc
, loc
,
1245 map
->s_type_specific
.s_sparing
.
1246 s_spar_map
[j
] = bh2
;
1251 st
= (struct sparingTable
*)bh2
->b_data
;
1252 if (ident
!= 0 || strncmp(
1253 st
->sparingIdent
.ident
,
1255 strlen(UDF_ID_SPARING
))) {
1257 map
->s_type_specific
.s_sparing
.
1258 s_spar_map
[j
] = NULL
;
1261 map
->s_partition_func
= udf_get_pblock_spar15
;
1263 udf_debug("Unknown ident: %s\n",
1264 upm2
->partIdent
.ident
);
1267 map
->s_volumeseqnum
= le16_to_cpu(upm2
->volSeqNum
);
1268 map
->s_partition_num
= le16_to_cpu(upm2
->partitionNum
);
1270 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1271 i
, map
->s_partition_num
, type
,
1272 map
->s_volumeseqnum
);
1276 long_ad
*la
= (long_ad
*)&(lvd
->logicalVolContentsUse
[0]);
1278 *fileset
= lelb_to_cpu(la
->extLocation
);
1279 udf_debug("FileSet found in LogicalVolDesc at block=%d, "
1280 "partition=%d\n", fileset
->logicalBlockNum
,
1281 fileset
->partitionReferenceNum
);
1283 if (lvd
->integritySeqExt
.extLength
)
1284 udf_load_logicalvolint(sb
, leea_to_cpu(lvd
->integritySeqExt
));
1292 * udf_load_logicalvolint
1295 static void udf_load_logicalvolint(struct super_block
*sb
, kernel_extent_ad loc
)
1297 struct buffer_head
*bh
= NULL
;
1299 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1300 struct logicalVolIntegrityDesc
*lvid
;
1302 while (loc
.extLength
> 0 &&
1303 (bh
= udf_read_tagged(sb
, loc
.extLocation
,
1304 loc
.extLocation
, &ident
)) &&
1305 ident
== TAG_IDENT_LVID
) {
1306 sbi
->s_lvid_bh
= bh
;
1307 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1309 if (lvid
->nextIntegrityExt
.extLength
)
1310 udf_load_logicalvolint(sb
,
1311 leea_to_cpu(lvid
->nextIntegrityExt
));
1313 if (sbi
->s_lvid_bh
!= bh
)
1315 loc
.extLength
-= sb
->s_blocksize
;
1318 if (sbi
->s_lvid_bh
!= bh
)
1323 * udf_process_sequence
1326 * Process a main/reserve volume descriptor sequence.
1329 * sb Pointer to _locked_ superblock.
1330 * block First block of first extent of the sequence.
1331 * lastblock Lastblock of first extent of the sequence.
1334 * July 1, 1997 - Andrew E. Mileski
1335 * Written, tested, and released.
1337 static noinline
int udf_process_sequence(struct super_block
*sb
, long block
,
1338 long lastblock
, kernel_lb_addr
*fileset
)
1340 struct buffer_head
*bh
= NULL
;
1341 struct udf_vds_record vds
[VDS_POS_LENGTH
];
1342 struct udf_vds_record
*curr
;
1343 struct generic_desc
*gd
;
1344 struct volDescPtr
*vdp
;
1348 long next_s
= 0, next_e
= 0;
1350 memset(vds
, 0, sizeof(struct udf_vds_record
) * VDS_POS_LENGTH
);
1353 * Read the main descriptor sequence and find which descriptors
1356 for (; (!done
&& block
<= lastblock
); block
++) {
1358 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1360 printk(KERN_ERR
"udf: Block %Lu of volume descriptor "
1361 "sequence is corrupted or we could not read "
1362 "it.\n", (unsigned long long)block
);
1366 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1367 gd
= (struct generic_desc
*)bh
->b_data
;
1368 vdsn
= le32_to_cpu(gd
->volDescSeqNum
);
1370 case TAG_IDENT_PVD
: /* ISO 13346 3/10.1 */
1371 curr
= &vds
[VDS_POS_PRIMARY_VOL_DESC
];
1372 if (vdsn
>= curr
->volDescSeqNum
) {
1373 curr
->volDescSeqNum
= vdsn
;
1374 curr
->block
= block
;
1377 case TAG_IDENT_VDP
: /* ISO 13346 3/10.3 */
1378 curr
= &vds
[VDS_POS_VOL_DESC_PTR
];
1379 if (vdsn
>= curr
->volDescSeqNum
) {
1380 curr
->volDescSeqNum
= vdsn
;
1381 curr
->block
= block
;
1383 vdp
= (struct volDescPtr
*)bh
->b_data
;
1384 next_s
= le32_to_cpu(
1385 vdp
->nextVolDescSeqExt
.extLocation
);
1386 next_e
= le32_to_cpu(
1387 vdp
->nextVolDescSeqExt
.extLength
);
1388 next_e
= next_e
>> sb
->s_blocksize_bits
;
1392 case TAG_IDENT_IUVD
: /* ISO 13346 3/10.4 */
1393 curr
= &vds
[VDS_POS_IMP_USE_VOL_DESC
];
1394 if (vdsn
>= curr
->volDescSeqNum
) {
1395 curr
->volDescSeqNum
= vdsn
;
1396 curr
->block
= block
;
1399 case TAG_IDENT_PD
: /* ISO 13346 3/10.5 */
1400 curr
= &vds
[VDS_POS_PARTITION_DESC
];
1402 curr
->block
= block
;
1404 case TAG_IDENT_LVD
: /* ISO 13346 3/10.6 */
1405 curr
= &vds
[VDS_POS_LOGICAL_VOL_DESC
];
1406 if (vdsn
>= curr
->volDescSeqNum
) {
1407 curr
->volDescSeqNum
= vdsn
;
1408 curr
->block
= block
;
1411 case TAG_IDENT_USD
: /* ISO 13346 3/10.8 */
1412 curr
= &vds
[VDS_POS_UNALLOC_SPACE_DESC
];
1413 if (vdsn
>= curr
->volDescSeqNum
) {
1414 curr
->volDescSeqNum
= vdsn
;
1415 curr
->block
= block
;
1418 case TAG_IDENT_TD
: /* ISO 13346 3/10.9 */
1419 vds
[VDS_POS_TERMINATING_DESC
].block
= block
;
1423 next_s
= next_e
= 0;
1431 * Now read interesting descriptors again and process them
1432 * in a suitable order
1434 if (!vds
[VDS_POS_PRIMARY_VOL_DESC
].block
) {
1435 printk(KERN_ERR
"udf: Primary Volume Descriptor not found!\n");
1438 if (udf_load_pvoldesc(sb
, vds
[VDS_POS_PRIMARY_VOL_DESC
].block
))
1441 if (vds
[VDS_POS_LOGICAL_VOL_DESC
].block
&& udf_load_logicalvol(sb
,
1442 vds
[VDS_POS_LOGICAL_VOL_DESC
].block
, fileset
))
1445 if (vds
[VDS_POS_PARTITION_DESC
].block
) {
1447 * We rescan the whole descriptor sequence to find
1448 * partition descriptor blocks and process them.
1450 for (block
= vds
[VDS_POS_PARTITION_DESC
].block
;
1451 block
< vds
[VDS_POS_TERMINATING_DESC
].block
;
1453 if (udf_load_partdesc(sb
, block
))
1463 static int udf_check_valid(struct super_block
*sb
, int novrs
, int silent
)
1466 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1469 udf_debug("Validity check skipped because of novrs option\n");
1472 /* Check that it is NSR02 compliant */
1473 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1474 block
= udf_vrs(sb
, silent
);
1476 udf_debug("Failed to read byte 32768. Assuming open "
1477 "disc. Skipping validity check\n");
1478 if (block
&& !sbi
->s_last_block
)
1479 sbi
->s_last_block
= udf_get_last_block(sb
);
1483 static int udf_load_partition(struct super_block
*sb
, kernel_lb_addr
*fileset
)
1485 struct anchorVolDescPtr
*anchor
;
1487 struct buffer_head
*bh
;
1488 long main_s
, main_e
, reserve_s
, reserve_e
;
1490 struct udf_sb_info
*sbi
;
1496 for (i
= 0; i
< ARRAY_SIZE(sbi
->s_anchor
); i
++) {
1497 if (!sbi
->s_anchor
[i
])
1500 bh
= udf_read_tagged(sb
, sbi
->s_anchor
[i
], sbi
->s_anchor
[i
],
1505 anchor
= (struct anchorVolDescPtr
*)bh
->b_data
;
1507 /* Locate the main sequence */
1508 main_s
= le32_to_cpu(anchor
->mainVolDescSeqExt
.extLocation
);
1509 main_e
= le32_to_cpu(anchor
->mainVolDescSeqExt
.extLength
);
1510 main_e
= main_e
>> sb
->s_blocksize_bits
;
1513 /* Locate the reserve sequence */
1514 reserve_s
= le32_to_cpu(
1515 anchor
->reserveVolDescSeqExt
.extLocation
);
1516 reserve_e
= le32_to_cpu(
1517 anchor
->reserveVolDescSeqExt
.extLength
);
1518 reserve_e
= reserve_e
>> sb
->s_blocksize_bits
;
1519 reserve_e
+= reserve_s
;
1523 /* Process the main & reserve sequences */
1524 /* responsible for finding the PartitionDesc(s) */
1525 if (!(udf_process_sequence(sb
, main_s
, main_e
,
1527 udf_process_sequence(sb
, reserve_s
, reserve_e
,
1532 if (i
== ARRAY_SIZE(sbi
->s_anchor
)) {
1533 udf_debug("No Anchor block found\n");
1536 udf_debug("Using anchor in block %d\n", sbi
->s_anchor
[i
]);
1538 for (i
= 0; i
< sbi
->s_partitions
; i
++) {
1539 kernel_lb_addr
uninitialized_var(ino
);
1540 struct udf_part_map
*map
= &sbi
->s_partmaps
[i
];
1542 if (map
->s_partition_type
!= UDF_VIRTUAL_MAP15
&&
1543 map
->s_partition_type
!= UDF_VIRTUAL_MAP20
)
1546 if (!sbi
->s_last_block
) {
1547 sbi
->s_last_block
= udf_get_last_block(sb
);
1548 udf_find_anchor(sb
);
1551 if (!sbi
->s_last_block
) {
1552 udf_debug("Unable to determine Lastblock (For "
1553 "Virtual Partition)\n");
1557 for (j
= 0; j
< sbi
->s_partitions
; j
++) {
1558 struct udf_part_map
*map2
= &sbi
->s_partmaps
[j
];
1560 map
->s_volumeseqnum
==
1561 map2
->s_volumeseqnum
&&
1562 map
->s_partition_num
==
1563 map2
->s_partition_num
) {
1564 ino
.partitionReferenceNum
= j
;
1565 ino
.logicalBlockNum
=
1567 map2
->s_partition_root
;
1572 if (j
== sbi
->s_partitions
)
1575 sbi
->s_vat_inode
= udf_iget(sb
, ino
);
1576 if (!sbi
->s_vat_inode
)
1579 if (map
->s_partition_type
== UDF_VIRTUAL_MAP15
) {
1580 map
->s_type_specific
.s_virtual
.s_start_offset
=
1581 udf_ext0_offset(sbi
->s_vat_inode
);
1582 map
->s_type_specific
.s_virtual
.s_num_entries
=
1583 (sbi
->s_vat_inode
->i_size
- 36) >> 2;
1584 } else if (map
->s_partition_type
== UDF_VIRTUAL_MAP20
) {
1586 struct virtualAllocationTable20
*vat20
;
1588 pos
= udf_block_map(sbi
->s_vat_inode
, 0);
1589 bh
= sb_bread(sb
, pos
);
1592 vat20
= (struct virtualAllocationTable20
*)
1594 udf_ext0_offset(sbi
->s_vat_inode
);
1595 map
->s_type_specific
.s_virtual
.s_start_offset
=
1596 le16_to_cpu(vat20
->lengthHeader
) +
1597 udf_ext0_offset(sbi
->s_vat_inode
);
1598 map
->s_type_specific
.s_virtual
.s_num_entries
=
1599 (sbi
->s_vat_inode
->i_size
-
1600 map
->s_type_specific
.s_virtual
.
1601 s_start_offset
) >> 2;
1604 map
->s_partition_root
= udf_get_pblock(sb
, 0, i
, 0);
1605 map
->s_partition_len
=
1606 sbi
->s_partmaps
[ino
.partitionReferenceNum
].
1612 static void udf_open_lvid(struct super_block
*sb
)
1614 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1615 struct buffer_head
*bh
= sbi
->s_lvid_bh
;
1616 struct logicalVolIntegrityDesc
*lvid
;
1617 struct logicalVolIntegrityDescImpUse
*lvidiu
;
1621 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1622 lvidiu
= udf_sb_lvidiu(sbi
);
1624 lvidiu
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1625 lvidiu
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1626 udf_time_to_disk_stamp(&lvid
->recordingDateAndTime
,
1628 lvid
->integrityType
= LVID_INTEGRITY_TYPE_OPEN
;
1630 lvid
->descTag
.descCRC
= cpu_to_le16(
1631 udf_crc((char *)lvid
+ sizeof(tag
),
1632 le16_to_cpu(lvid
->descTag
.descCRCLength
), 0));
1634 lvid
->descTag
.tagChecksum
= udf_tag_checksum(&lvid
->descTag
);
1635 mark_buffer_dirty(bh
);
1638 static void udf_close_lvid(struct super_block
*sb
)
1640 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1641 struct buffer_head
*bh
= sbi
->s_lvid_bh
;
1642 struct logicalVolIntegrityDesc
*lvid
;
1643 struct logicalVolIntegrityDescImpUse
*lvidiu
;
1648 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1650 if (lvid
->integrityType
!= LVID_INTEGRITY_TYPE_OPEN
)
1653 lvidiu
= udf_sb_lvidiu(sbi
);
1654 lvidiu
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1655 lvidiu
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1656 udf_time_to_disk_stamp(&lvid
->recordingDateAndTime
, CURRENT_TIME
);
1657 if (UDF_MAX_WRITE_VERSION
> le16_to_cpu(lvidiu
->maxUDFWriteRev
))
1658 lvidiu
->maxUDFWriteRev
= cpu_to_le16(UDF_MAX_WRITE_VERSION
);
1659 if (sbi
->s_udfrev
> le16_to_cpu(lvidiu
->minUDFReadRev
))
1660 lvidiu
->minUDFReadRev
= cpu_to_le16(sbi
->s_udfrev
);
1661 if (sbi
->s_udfrev
> le16_to_cpu(lvidiu
->minUDFWriteRev
))
1662 lvidiu
->minUDFWriteRev
= cpu_to_le16(sbi
->s_udfrev
);
1663 lvid
->integrityType
= cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE
);
1665 lvid
->descTag
.descCRC
= cpu_to_le16(
1666 udf_crc((char *)lvid
+ sizeof(tag
),
1667 le16_to_cpu(lvid
->descTag
.descCRCLength
),
1670 lvid
->descTag
.tagChecksum
= udf_tag_checksum(&lvid
->descTag
);
1671 mark_buffer_dirty(bh
);
1674 static void udf_sb_free_bitmap(struct udf_bitmap
*bitmap
)
1677 int nr_groups
= bitmap
->s_nr_groups
;
1678 int size
= sizeof(struct udf_bitmap
) + (sizeof(struct buffer_head
*) *
1681 for (i
= 0; i
< nr_groups
; i
++)
1682 if (bitmap
->s_block_bitmap
[i
])
1683 brelse(bitmap
->s_block_bitmap
[i
]);
1685 if (size
<= PAGE_SIZE
)
1691 static void udf_free_partition(struct udf_part_map
*map
)
1695 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
)
1696 iput(map
->s_uspace
.s_table
);
1697 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
)
1698 iput(map
->s_fspace
.s_table
);
1699 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
)
1700 udf_sb_free_bitmap(map
->s_uspace
.s_bitmap
);
1701 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
)
1702 udf_sb_free_bitmap(map
->s_fspace
.s_bitmap
);
1703 if (map
->s_partition_type
== UDF_SPARABLE_MAP15
)
1704 for (i
= 0; i
< 4; i
++)
1705 brelse(map
->s_type_specific
.s_sparing
.s_spar_map
[i
]);
1708 static int udf_fill_super(struct super_block
*sb
, void *options
, int silent
)
1711 struct inode
*inode
= NULL
;
1712 struct udf_options uopt
;
1713 kernel_lb_addr rootdir
, fileset
;
1714 struct udf_sb_info
*sbi
;
1716 uopt
.flags
= (1 << UDF_FLAG_USE_AD_IN_ICB
) | (1 << UDF_FLAG_STRICT
);
1721 sbi
= kzalloc(sizeof(struct udf_sb_info
), GFP_KERNEL
);
1725 sb
->s_fs_info
= sbi
;
1727 mutex_init(&sbi
->s_alloc_mutex
);
1729 if (!udf_parse_options((char *)options
, &uopt
, false))
1732 if (uopt
.flags
& (1 << UDF_FLAG_UTF8
) &&
1733 uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) {
1734 udf_error(sb
, "udf_read_super",
1735 "utf8 cannot be combined with iocharset\n");
1738 #ifdef CONFIG_UDF_NLS
1739 if ((uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) && !uopt
.nls_map
) {
1740 uopt
.nls_map
= load_nls_default();
1742 uopt
.flags
&= ~(1 << UDF_FLAG_NLS_MAP
);
1744 udf_debug("Using default NLS map\n");
1747 if (!(uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)))
1748 uopt
.flags
|= (1 << UDF_FLAG_UTF8
);
1750 fileset
.logicalBlockNum
= 0xFFFFFFFF;
1751 fileset
.partitionReferenceNum
= 0xFFFF;
1753 sbi
->s_flags
= uopt
.flags
;
1754 sbi
->s_uid
= uopt
.uid
;
1755 sbi
->s_gid
= uopt
.gid
;
1756 sbi
->s_umask
= uopt
.umask
;
1757 sbi
->s_nls_map
= uopt
.nls_map
;
1759 /* Set the block size for all transfers */
1760 if (!sb_min_blocksize(sb
, uopt
.blocksize
)) {
1761 udf_debug("Bad block size (%d)\n", uopt
.blocksize
);
1762 printk(KERN_ERR
"udf: bad block size (%d)\n", uopt
.blocksize
);
1766 if (uopt
.session
== 0xFFFFFFFF)
1767 sbi
->s_session
= udf_get_last_session(sb
);
1769 sbi
->s_session
= uopt
.session
;
1771 udf_debug("Multi-session=%d\n", sbi
->s_session
);
1773 sbi
->s_last_block
= uopt
.lastblock
;
1774 sbi
->s_anchor
[0] = sbi
->s_anchor
[1] = 0;
1775 sbi
->s_anchor
[2] = uopt
.anchor
;
1776 sbi
->s_anchor
[3] = 256;
1778 if (udf_check_valid(sb
, uopt
.novrs
, silent
)) {
1779 /* read volume recognition sequences */
1780 printk(KERN_WARNING
"UDF-fs: No VRS found\n");
1784 udf_find_anchor(sb
);
1786 /* Fill in the rest of the superblock */
1787 sb
->s_op
= &udf_sb_ops
;
1790 sb
->s_magic
= UDF_SUPER_MAGIC
;
1791 sb
->s_time_gran
= 1000;
1793 if (udf_load_partition(sb
, &fileset
)) {
1794 printk(KERN_WARNING
"UDF-fs: No partition found (1)\n");
1798 udf_debug("Lastblock=%d\n", sbi
->s_last_block
);
1800 if (sbi
->s_lvid_bh
) {
1801 struct logicalVolIntegrityDescImpUse
*lvidiu
=
1803 uint16_t minUDFReadRev
= le16_to_cpu(lvidiu
->minUDFReadRev
);
1804 uint16_t minUDFWriteRev
= le16_to_cpu(lvidiu
->minUDFWriteRev
);
1805 /* uint16_t maxUDFWriteRev =
1806 le16_to_cpu(lvidiu->maxUDFWriteRev); */
1808 if (minUDFReadRev
> UDF_MAX_READ_VERSION
) {
1809 printk(KERN_ERR
"UDF-fs: minUDFReadRev=%x "
1811 le16_to_cpu(lvidiu
->minUDFReadRev
),
1812 UDF_MAX_READ_VERSION
);
1814 } else if (minUDFWriteRev
> UDF_MAX_WRITE_VERSION
)
1815 sb
->s_flags
|= MS_RDONLY
;
1817 sbi
->s_udfrev
= minUDFWriteRev
;
1819 if (minUDFReadRev
>= UDF_VERS_USE_EXTENDED_FE
)
1820 UDF_SET_FLAG(sb
, UDF_FLAG_USE_EXTENDED_FE
);
1821 if (minUDFReadRev
>= UDF_VERS_USE_STREAMS
)
1822 UDF_SET_FLAG(sb
, UDF_FLAG_USE_STREAMS
);
1825 if (!sbi
->s_partitions
) {
1826 printk(KERN_WARNING
"UDF-fs: No partition found (2)\n");
1830 if (sbi
->s_partmaps
[sbi
->s_partition
].s_partition_flags
&
1831 UDF_PART_FLAG_READ_ONLY
) {
1832 printk(KERN_NOTICE
"UDF-fs: Partition marked readonly; "
1833 "forcing readonly mount\n");
1834 sb
->s_flags
|= MS_RDONLY
;
1837 if (udf_find_fileset(sb
, &fileset
, &rootdir
)) {
1838 printk(KERN_WARNING
"UDF-fs: No fileset found\n");
1844 udf_time_to_disk_stamp(&ts
, sbi
->s_record_time
);
1845 udf_info("UDF: Mounting volume '%s', "
1846 "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1847 sbi
->s_volume_ident
, le16_to_cpu(ts
.year
), ts
.month
, ts
.day
,
1848 ts
.hour
, ts
.minute
, le16_to_cpu(ts
.typeAndTimezone
));
1850 if (!(sb
->s_flags
& MS_RDONLY
))
1853 /* Assign the root inode */
1854 /* assign inodes by physical block number */
1855 /* perhaps it's not extensible enough, but for now ... */
1856 inode
= udf_iget(sb
, rootdir
);
1858 printk(KERN_ERR
"UDF-fs: Error in udf_iget, block=%d, "
1860 rootdir
.logicalBlockNum
, rootdir
.partitionReferenceNum
);
1864 /* Allocate a dentry for the root inode */
1865 sb
->s_root
= d_alloc_root(inode
);
1867 printk(KERN_ERR
"UDF-fs: Couldn't allocate root dentry\n");
1871 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
1875 if (sbi
->s_vat_inode
)
1876 iput(sbi
->s_vat_inode
);
1877 if (sbi
->s_partitions
)
1878 for (i
= 0; i
< sbi
->s_partitions
; i
++)
1879 udf_free_partition(&sbi
->s_partmaps
[i
]);
1880 #ifdef CONFIG_UDF_NLS
1881 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
1882 unload_nls(sbi
->s_nls_map
);
1884 if (!(sb
->s_flags
& MS_RDONLY
))
1886 brelse(sbi
->s_lvid_bh
);
1888 kfree(sbi
->s_partmaps
);
1890 sb
->s_fs_info
= NULL
;
1895 static void udf_error(struct super_block
*sb
, const char *function
,
1896 const char *fmt
, ...)
1900 if (!(sb
->s_flags
& MS_RDONLY
)) {
1904 va_start(args
, fmt
);
1905 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
1907 printk(KERN_CRIT
"UDF-fs error (device %s): %s: %s\n",
1908 sb
->s_id
, function
, error_buf
);
1911 void udf_warning(struct super_block
*sb
, const char *function
,
1912 const char *fmt
, ...)
1916 va_start(args
, fmt
);
1917 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
1919 printk(KERN_WARNING
"UDF-fs warning (device %s): %s: %s\n",
1920 sb
->s_id
, function
, error_buf
);
1923 static void udf_put_super(struct super_block
*sb
)
1926 struct udf_sb_info
*sbi
;
1929 if (sbi
->s_vat_inode
)
1930 iput(sbi
->s_vat_inode
);
1931 if (sbi
->s_partitions
)
1932 for (i
= 0; i
< sbi
->s_partitions
; i
++)
1933 udf_free_partition(&sbi
->s_partmaps
[i
]);
1934 #ifdef CONFIG_UDF_NLS
1935 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
1936 unload_nls(sbi
->s_nls_map
);
1938 if (!(sb
->s_flags
& MS_RDONLY
))
1940 brelse(sbi
->s_lvid_bh
);
1941 kfree(sbi
->s_partmaps
);
1942 kfree(sb
->s_fs_info
);
1943 sb
->s_fs_info
= NULL
;
1946 static int udf_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
1948 struct super_block
*sb
= dentry
->d_sb
;
1949 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1950 struct logicalVolIntegrityDescImpUse
*lvidiu
;
1952 if (sbi
->s_lvid_bh
!= NULL
)
1953 lvidiu
= udf_sb_lvidiu(sbi
);
1957 buf
->f_type
= UDF_SUPER_MAGIC
;
1958 buf
->f_bsize
= sb
->s_blocksize
;
1959 buf
->f_blocks
= sbi
->s_partmaps
[sbi
->s_partition
].s_partition_len
;
1960 buf
->f_bfree
= udf_count_free(sb
);
1961 buf
->f_bavail
= buf
->f_bfree
;
1962 buf
->f_files
= (lvidiu
!= NULL
? (le32_to_cpu(lvidiu
->numFiles
) +
1963 le32_to_cpu(lvidiu
->numDirs
)) : 0)
1965 buf
->f_ffree
= buf
->f_bfree
;
1966 /* __kernel_fsid_t f_fsid */
1967 buf
->f_namelen
= UDF_NAME_LEN
- 2;
1972 static unsigned int udf_count_free_bitmap(struct super_block
*sb
,
1973 struct udf_bitmap
*bitmap
)
1975 struct buffer_head
*bh
= NULL
;
1976 unsigned int accum
= 0;
1978 int block
= 0, newblock
;
1983 struct spaceBitmapDesc
*bm
;
1987 loc
.logicalBlockNum
= bitmap
->s_extPosition
;
1988 loc
.partitionReferenceNum
= UDF_SB(sb
)->s_partition
;
1989 bh
= udf_read_ptagged(sb
, loc
, 0, &ident
);
1992 printk(KERN_ERR
"udf: udf_count_free failed\n");
1994 } else if (ident
!= TAG_IDENT_SBD
) {
1996 printk(KERN_ERR
"udf: udf_count_free failed\n");
2000 bm
= (struct spaceBitmapDesc
*)bh
->b_data
;
2001 bytes
= le32_to_cpu(bm
->numOfBytes
);
2002 index
= sizeof(struct spaceBitmapDesc
); /* offset in first block only */
2003 ptr
= (uint8_t *)bh
->b_data
;
2006 u32 cur_bytes
= min_t(u32
, bytes
, sb
->s_blocksize
- index
);
2007 accum
+= bitmap_weight((const unsigned long *)(ptr
+ index
),
2012 newblock
= udf_get_lb_pblock(sb
, loc
, ++block
);
2013 bh
= udf_tread(sb
, newblock
);
2015 udf_debug("read failed\n");
2019 ptr
= (uint8_t *)bh
->b_data
;
2030 static unsigned int udf_count_free_table(struct super_block
*sb
,
2031 struct inode
*table
)
2033 unsigned int accum
= 0;
2035 kernel_lb_addr eloc
;
2037 struct extent_position epos
;
2041 epos
.block
= UDF_I(table
)->i_location
;
2042 epos
.offset
= sizeof(struct unallocSpaceEntry
);
2045 while ((etype
= udf_next_aext(table
, &epos
, &eloc
, &elen
, 1)) != -1)
2046 accum
+= (elen
>> table
->i_sb
->s_blocksize_bits
);
2055 static unsigned int udf_count_free(struct super_block
*sb
)
2057 unsigned int accum
= 0;
2058 struct udf_sb_info
*sbi
;
2059 struct udf_part_map
*map
;
2062 if (sbi
->s_lvid_bh
) {
2063 struct logicalVolIntegrityDesc
*lvid
=
2064 (struct logicalVolIntegrityDesc
*)
2065 sbi
->s_lvid_bh
->b_data
;
2066 if (le32_to_cpu(lvid
->numOfPartitions
) > sbi
->s_partition
) {
2067 accum
= le32_to_cpu(
2068 lvid
->freeSpaceTable
[sbi
->s_partition
]);
2069 if (accum
== 0xFFFFFFFF)
2077 map
= &sbi
->s_partmaps
[sbi
->s_partition
];
2078 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
) {
2079 accum
+= udf_count_free_bitmap(sb
,
2080 map
->s_uspace
.s_bitmap
);
2082 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
) {
2083 accum
+= udf_count_free_bitmap(sb
,
2084 map
->s_fspace
.s_bitmap
);
2089 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
) {
2090 accum
+= udf_count_free_table(sb
,
2091 map
->s_uspace
.s_table
);
2093 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
) {
2094 accum
+= udf_count_free_table(sb
,
2095 map
->s_fspace
.s_table
);