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 <asm/byteorder.h>
60 #include <linux/udf_fs.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 int udf_load_logicalvol(struct super_block
*, struct buffer_head
*,
90 static void udf_load_logicalvolint(struct super_block
*, kernel_extent_ad
);
91 static void udf_find_anchor(struct super_block
*);
92 static int udf_find_fileset(struct super_block
*, kernel_lb_addr
*,
94 static void udf_load_pvoldesc(struct super_block
*, struct buffer_head
*);
95 static void udf_load_fileset(struct super_block
*, struct buffer_head
*,
97 static int udf_load_partdesc(struct super_block
*, struct buffer_head
*);
98 static void udf_open_lvid(struct super_block
*);
99 static void udf_close_lvid(struct super_block
*);
100 static unsigned int udf_count_free(struct super_block
*);
101 static int udf_statfs(struct dentry
*, struct kstatfs
*);
102 static int udf_show_options(struct seq_file
*, struct vfsmount
*);
104 struct logicalVolIntegrityDescImpUse
*udf_sb_lvidiu(struct udf_sb_info
*sbi
)
106 struct logicalVolIntegrityDesc
*lvid
=
107 (struct logicalVolIntegrityDesc
*)sbi
->s_lvid_bh
->b_data
;
108 __u32 number_of_partitions
= le32_to_cpu(lvid
->numOfPartitions
);
109 __u32 offset
= number_of_partitions
* 2 *
110 sizeof(uint32_t)/sizeof(uint8_t);
111 return (struct logicalVolIntegrityDescImpUse
*)&(lvid
->impUse
[offset
]);
114 /* UDF filesystem type */
115 static int udf_get_sb(struct file_system_type
*fs_type
,
116 int flags
, const char *dev_name
, void *data
,
117 struct vfsmount
*mnt
)
119 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, udf_fill_super
, mnt
);
122 static struct file_system_type udf_fstype
= {
123 .owner
= THIS_MODULE
,
125 .get_sb
= udf_get_sb
,
126 .kill_sb
= kill_block_super
,
127 .fs_flags
= FS_REQUIRES_DEV
,
130 static struct kmem_cache
*udf_inode_cachep
;
132 static struct inode
*udf_alloc_inode(struct super_block
*sb
)
134 struct udf_inode_info
*ei
;
135 ei
= kmem_cache_alloc(udf_inode_cachep
, GFP_KERNEL
);
140 ei
->i_lenExtents
= 0;
141 ei
->i_next_alloc_block
= 0;
142 ei
->i_next_alloc_goal
= 0;
145 return &ei
->vfs_inode
;
148 static void udf_destroy_inode(struct inode
*inode
)
150 kmem_cache_free(udf_inode_cachep
, UDF_I(inode
));
153 static void init_once(struct kmem_cache
*cachep
, void *foo
)
155 struct udf_inode_info
*ei
= (struct udf_inode_info
*)foo
;
157 ei
->i_ext
.i_data
= NULL
;
158 inode_init_once(&ei
->vfs_inode
);
161 static int init_inodecache(void)
163 udf_inode_cachep
= kmem_cache_create("udf_inode_cache",
164 sizeof(struct udf_inode_info
),
165 0, (SLAB_RECLAIM_ACCOUNT
|
168 if (!udf_inode_cachep
)
173 static void destroy_inodecache(void)
175 kmem_cache_destroy(udf_inode_cachep
);
178 /* Superblock operations */
179 static const struct super_operations udf_sb_ops
= {
180 .alloc_inode
= udf_alloc_inode
,
181 .destroy_inode
= udf_destroy_inode
,
182 .write_inode
= udf_write_inode
,
183 .delete_inode
= udf_delete_inode
,
184 .clear_inode
= udf_clear_inode
,
185 .put_super
= udf_put_super
,
186 .write_super
= udf_write_super
,
187 .statfs
= udf_statfs
,
188 .remount_fs
= udf_remount_fs
,
189 .show_options
= udf_show_options
,
194 unsigned int blocksize
;
195 unsigned int session
;
196 unsigned int lastblock
;
199 unsigned short partition
;
200 unsigned int fileset
;
201 unsigned int rootdir
;
206 struct nls_table
*nls_map
;
209 static int __init
init_udf_fs(void)
213 err
= init_inodecache();
216 err
= register_filesystem(&udf_fstype
);
223 destroy_inodecache();
229 static void __exit
exit_udf_fs(void)
231 unregister_filesystem(&udf_fstype
);
232 destroy_inodecache();
235 module_init(init_udf_fs
)
236 module_exit(exit_udf_fs
)
238 static int udf_sb_alloc_partition_maps(struct super_block
*sb
, u32 count
)
240 struct udf_sb_info
*sbi
= UDF_SB(sb
);
242 sbi
->s_partmaps
= kcalloc(count
, sizeof(struct udf_part_map
),
244 if (!sbi
->s_partmaps
) {
245 udf_error(sb
, __FUNCTION__
,
246 "Unable to allocate space for %d partition maps",
248 sbi
->s_partitions
= 0;
252 sbi
->s_partitions
= count
;
256 static int udf_show_options(struct seq_file
*seq
, struct vfsmount
*mnt
)
258 struct super_block
*sb
= mnt
->mnt_sb
;
259 struct udf_sb_info
*sbi
= UDF_SB(sb
);
261 if (!UDF_QUERY_FLAG(sb
, UDF_FLAG_STRICT
))
262 seq_puts(seq
, ",nostrict");
263 if (sb
->s_blocksize
!= UDF_DEFAULT_BLOCKSIZE
)
264 seq_printf(seq
, ",bs=%lu", sb
->s_blocksize
);
265 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UNHIDE
))
266 seq_puts(seq
, ",unhide");
267 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UNDELETE
))
268 seq_puts(seq
, ",undelete");
269 if (!UDF_QUERY_FLAG(sb
, UDF_FLAG_USE_AD_IN_ICB
))
270 seq_puts(seq
, ",noadinicb");
271 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_USE_SHORT_AD
))
272 seq_puts(seq
, ",shortad");
273 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_FORGET
))
274 seq_puts(seq
, ",uid=forget");
275 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_IGNORE
))
276 seq_puts(seq
, ",uid=ignore");
277 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_FORGET
))
278 seq_puts(seq
, ",gid=forget");
279 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_IGNORE
))
280 seq_puts(seq
, ",gid=ignore");
281 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UID_SET
))
282 seq_printf(seq
, ",uid=%u", sbi
->s_uid
);
283 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_GID_SET
))
284 seq_printf(seq
, ",gid=%u", sbi
->s_gid
);
285 if (sbi
->s_umask
!= 0)
286 seq_printf(seq
, ",umask=%o", sbi
->s_umask
);
287 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_SESSION_SET
))
288 seq_printf(seq
, ",session=%u", sbi
->s_session
);
289 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_LASTBLOCK_SET
))
290 seq_printf(seq
, ",lastblock=%u", sbi
->s_last_block
);
292 * s_anchor[2] could be zeroed out in case there is no anchor
293 * in the specified block, but then the "anchor=N" option
294 * originally given by the user wasn't effective, so it's OK
295 * if we don't show it.
297 if (sbi
->s_anchor
[2] != 0)
298 seq_printf(seq
, ",anchor=%u", sbi
->s_anchor
[2]);
300 * volume, partition, fileset and rootdir seem to be ignored
303 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_UTF8
))
304 seq_puts(seq
, ",utf8");
305 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
) && sbi
->s_nls_map
)
306 seq_printf(seq
, ",iocharset=%s", sbi
->s_nls_map
->charset
);
315 * Parse mount options.
318 * The following mount options are supported:
320 * gid= Set the default group.
321 * umask= Set the default umask.
322 * uid= Set the default user.
323 * bs= Set the block size.
324 * unhide Show otherwise hidden files.
325 * undelete Show deleted files in lists.
326 * adinicb Embed data in the inode (default)
327 * noadinicb Don't embed data in the inode
328 * shortad Use short ad's
329 * longad Use long ad's (default)
330 * nostrict Unset strict conformance
331 * iocharset= Set the NLS character set
333 * The remaining are for debugging and disaster recovery:
335 * novrs Skip volume sequence recognition
337 * The following expect a offset from 0.
339 * session= Set the CDROM session (default= last session)
340 * anchor= Override standard anchor location. (default= 256)
341 * volume= Override the VolumeDesc location. (unused)
342 * partition= Override the PartitionDesc location. (unused)
343 * lastblock= Set the last block of the filesystem/
345 * The following expect a offset from the partition root.
347 * fileset= Override the fileset block location. (unused)
348 * rootdir= Override the root directory location. (unused)
349 * WARNING: overriding the rootdir to a non-directory may
350 * yield highly unpredictable results.
353 * options Pointer to mount options string.
354 * uopts Pointer to mount options variable.
357 * <return> 1 Mount options parsed okay.
358 * <return> 0 Error parsing mount options.
361 * July 1, 1997 - Andrew E. Mileski
362 * Written, tested, and released.
366 Opt_novrs
, Opt_nostrict
, Opt_bs
, Opt_unhide
, Opt_undelete
,
367 Opt_noadinicb
, Opt_adinicb
, Opt_shortad
, Opt_longad
,
368 Opt_gid
, Opt_uid
, Opt_umask
, Opt_session
, Opt_lastblock
,
369 Opt_anchor
, Opt_volume
, Opt_partition
, Opt_fileset
,
370 Opt_rootdir
, Opt_utf8
, Opt_iocharset
,
371 Opt_err
, Opt_uforget
, Opt_uignore
, Opt_gforget
, Opt_gignore
374 static match_table_t tokens
= {
375 {Opt_novrs
, "novrs"},
376 {Opt_nostrict
, "nostrict"},
378 {Opt_unhide
, "unhide"},
379 {Opt_undelete
, "undelete"},
380 {Opt_noadinicb
, "noadinicb"},
381 {Opt_adinicb
, "adinicb"},
382 {Opt_shortad
, "shortad"},
383 {Opt_longad
, "longad"},
384 {Opt_uforget
, "uid=forget"},
385 {Opt_uignore
, "uid=ignore"},
386 {Opt_gforget
, "gid=forget"},
387 {Opt_gignore
, "gid=ignore"},
390 {Opt_umask
, "umask=%o"},
391 {Opt_session
, "session=%u"},
392 {Opt_lastblock
, "lastblock=%u"},
393 {Opt_anchor
, "anchor=%u"},
394 {Opt_volume
, "volume=%u"},
395 {Opt_partition
, "partition=%u"},
396 {Opt_fileset
, "fileset=%u"},
397 {Opt_rootdir
, "rootdir=%u"},
399 {Opt_iocharset
, "iocharset=%s"},
403 static int udf_parse_options(char *options
, struct udf_options
*uopt
,
410 uopt
->blocksize
= UDF_DEFAULT_BLOCKSIZE
;
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
);
434 if (match_int(&args
[0], &option
))
436 uopt
->blocksize
= option
;
439 uopt
->flags
|= (1 << UDF_FLAG_UNHIDE
);
442 uopt
->flags
|= (1 << UDF_FLAG_UNDELETE
);
445 uopt
->flags
&= ~(1 << UDF_FLAG_USE_AD_IN_ICB
);
448 uopt
->flags
|= (1 << UDF_FLAG_USE_AD_IN_ICB
);
451 uopt
->flags
|= (1 << UDF_FLAG_USE_SHORT_AD
);
454 uopt
->flags
&= ~(1 << UDF_FLAG_USE_SHORT_AD
);
457 if (match_int(args
, &option
))
460 uopt
->flags
|= (1 << UDF_FLAG_GID_SET
);
463 if (match_int(args
, &option
))
466 uopt
->flags
|= (1 << UDF_FLAG_UID_SET
);
469 if (match_octal(args
, &option
))
471 uopt
->umask
= option
;
474 uopt
->flags
&= ~(1 << UDF_FLAG_STRICT
);
477 if (match_int(args
, &option
))
479 uopt
->session
= option
;
481 uopt
->flags
|= (1 << UDF_FLAG_SESSION_SET
);
484 if (match_int(args
, &option
))
486 uopt
->lastblock
= option
;
488 uopt
->flags
|= (1 << UDF_FLAG_LASTBLOCK_SET
);
491 if (match_int(args
, &option
))
493 uopt
->anchor
= option
;
496 if (match_int(args
, &option
))
498 uopt
->volume
= option
;
501 if (match_int(args
, &option
))
503 uopt
->partition
= option
;
506 if (match_int(args
, &option
))
508 uopt
->fileset
= option
;
511 if (match_int(args
, &option
))
513 uopt
->rootdir
= option
;
516 uopt
->flags
|= (1 << UDF_FLAG_UTF8
);
518 #ifdef CONFIG_UDF_NLS
520 uopt
->nls_map
= load_nls(args
[0].from
);
521 uopt
->flags
|= (1 << UDF_FLAG_NLS_MAP
);
525 uopt
->flags
|= (1 << UDF_FLAG_UID_IGNORE
);
528 uopt
->flags
|= (1 << UDF_FLAG_UID_FORGET
);
531 uopt
->flags
|= (1 << UDF_FLAG_GID_IGNORE
);
534 uopt
->flags
|= (1 << UDF_FLAG_GID_FORGET
);
537 printk(KERN_ERR
"udf: bad mount option \"%s\" "
538 "or missing value\n", p
);
545 static void udf_write_super(struct super_block
*sb
)
549 if (!(sb
->s_flags
& MS_RDONLY
))
556 static int udf_remount_fs(struct super_block
*sb
, int *flags
, char *options
)
558 struct udf_options uopt
;
559 struct udf_sb_info
*sbi
= UDF_SB(sb
);
561 uopt
.flags
= sbi
->s_flags
;
562 uopt
.uid
= sbi
->s_uid
;
563 uopt
.gid
= sbi
->s_gid
;
564 uopt
.umask
= sbi
->s_umask
;
566 if (!udf_parse_options(options
, &uopt
, true))
569 sbi
->s_flags
= uopt
.flags
;
570 sbi
->s_uid
= uopt
.uid
;
571 sbi
->s_gid
= uopt
.gid
;
572 sbi
->s_umask
= uopt
.umask
;
574 if (sbi
->s_lvid_bh
) {
575 int write_rev
= le16_to_cpu(udf_sb_lvidiu(sbi
)->minUDFWriteRev
);
576 if (write_rev
> UDF_MAX_WRITE_VERSION
)
580 if ((*flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
))
582 if (*flags
& MS_RDONLY
)
594 * Set the block size to be used in all transfers.
597 * To allow room for a DMA transfer, it is best to guess big when unsure.
598 * This routine picks 2048 bytes as the blocksize when guessing. This
599 * should be adequate until devices with larger block sizes become common.
601 * Note that the Linux kernel can currently only deal with blocksizes of
602 * 512, 1024, 2048, 4096, and 8192 bytes.
605 * sb Pointer to _locked_ superblock.
608 * sb->s_blocksize Blocksize.
609 * sb->s_blocksize_bits log2 of blocksize.
610 * <return> 0 Blocksize is valid.
611 * <return> 1 Blocksize is invalid.
614 * July 1, 1997 - Andrew E. Mileski
615 * Written, tested, and released.
617 static int udf_set_blocksize(struct super_block
*sb
, int bsize
)
619 if (!sb_min_blocksize(sb
, bsize
)) {
620 udf_debug("Bad block size (%d)\n", bsize
);
621 printk(KERN_ERR
"udf: bad block size (%d)\n", bsize
);
625 return sb
->s_blocksize
;
628 static int udf_vrs(struct super_block
*sb
, int silent
)
630 struct volStructDesc
*vsd
= NULL
;
633 struct buffer_head
*bh
= NULL
;
637 struct udf_sb_info
*sbi
;
639 /* Block size must be a multiple of 512 */
640 if (sb
->s_blocksize
& 511)
644 if (sb
->s_blocksize
< sizeof(struct volStructDesc
))
645 sectorsize
= sizeof(struct volStructDesc
);
647 sectorsize
= sb
->s_blocksize
;
649 sector
+= (sbi
->s_session
<< sb
->s_blocksize_bits
);
651 udf_debug("Starting at sector %u (%ld byte sectors)\n",
652 (sector
>> sb
->s_blocksize_bits
), sb
->s_blocksize
);
653 /* Process the sequence (if applicable) */
654 for (; !nsr02
&& !nsr03
; sector
+= sectorsize
) {
656 bh
= udf_tread(sb
, sector
>> sb
->s_blocksize_bits
);
660 /* Look for ISO descriptors */
661 vsd
= (struct volStructDesc
*)(bh
->b_data
+
662 (sector
& (sb
->s_blocksize
- 1)));
664 if (vsd
->stdIdent
[0] == 0) {
667 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_CD001
,
670 switch (vsd
->structType
) {
672 udf_debug("ISO9660 Boot Record found\n");
675 udf_debug("ISO9660 Primary Volume Descriptor "
679 udf_debug("ISO9660 Supplementary Volume "
680 "Descriptor found\n");
683 udf_debug("ISO9660 Volume Partition Descriptor "
687 udf_debug("ISO9660 Volume Descriptor Set "
688 "Terminator found\n");
691 udf_debug("ISO9660 VRS (%u) found\n",
695 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_BEA01
,
698 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_TEA01
,
702 } else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR02
,
705 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR03
,
715 else if (sector
- (sbi
->s_session
<< sb
->s_blocksize_bits
) == 32768)
725 * Find an anchor volume descriptor.
728 * sb Pointer to _locked_ superblock.
729 * lastblock Last block on media.
732 * <return> 1 if not found, 0 if ok
735 * July 1, 1997 - Andrew E. Mileski
736 * Written, tested, and released.
738 static void udf_find_anchor(struct super_block
*sb
)
741 struct buffer_head
*bh
= NULL
;
745 struct udf_sb_info
*sbi
;
748 lastblock
= sbi
->s_last_block
;
751 int varlastblock
= udf_variable_to_fixed(lastblock
);
752 int last
[] = { lastblock
, lastblock
- 2,
753 lastblock
- 150, lastblock
- 152,
754 varlastblock
, varlastblock
- 2,
755 varlastblock
- 150, varlastblock
- 152 };
759 /* Search for an anchor volume descriptor pointer */
761 /* according to spec, anchor is in either:
765 * however, if the disc isn't closed, it could be 512 */
767 for (i
= 0; !lastblock
&& i
< ARRAY_SIZE(last
); i
++) {
768 ident
= location
= 0;
770 bh
= sb_bread(sb
, last
[i
]);
772 tag
*t
= (tag
*)bh
->b_data
;
773 ident
= le16_to_cpu(t
->tagIdent
);
774 location
= le32_to_cpu(t
->tagLocation
);
779 if (ident
== TAG_IDENT_AVDP
) {
780 if (location
== last
[i
] - sbi
->s_session
) {
781 lastblock
= last
[i
] - sbi
->s_session
;
782 sbi
->s_anchor
[0] = lastblock
;
783 sbi
->s_anchor
[1] = lastblock
- 256;
784 } else if (location
==
785 udf_variable_to_fixed(last
[i
]) -
787 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
789 udf_variable_to_fixed(last
[i
]) -
791 sbi
->s_anchor
[0] = lastblock
;
792 sbi
->s_anchor
[1] = lastblock
- 256 -
795 udf_debug("Anchor found at block %d, "
796 "location mismatch %d.\n",
799 } else if (ident
== TAG_IDENT_FE
||
800 ident
== TAG_IDENT_EFE
) {
802 sbi
->s_anchor
[3] = 512;
804 ident
= location
= 0;
805 if (last
[i
] >= 256) {
806 bh
= sb_bread(sb
, last
[i
] - 256);
808 tag
*t
= (tag
*)bh
->b_data
;
811 location
= le32_to_cpu(
817 if (ident
== TAG_IDENT_AVDP
&&
818 location
== last
[i
] - 256 -
821 sbi
->s_anchor
[1] = last
[i
] - 256;
823 ident
= location
= 0;
824 if (last
[i
] >= 312 + sbi
->s_session
) {
833 location
= le32_to_cpu(
839 if (ident
== TAG_IDENT_AVDP
&&
840 location
== udf_variable_to_fixed(last
[i
]) - 256) {
843 lastblock
= udf_variable_to_fixed(last
[i
]);
844 sbi
->s_anchor
[1] = lastblock
- 256;
852 /* We haven't found the lastblock. check 312 */
853 bh
= sb_bread(sb
, 312 + sbi
->s_session
);
855 tag
*t
= (tag
*)bh
->b_data
;
856 ident
= le16_to_cpu(t
->tagIdent
);
857 location
= le32_to_cpu(t
->tagLocation
);
860 if (ident
== TAG_IDENT_AVDP
&& location
== 256)
861 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
865 for (i
= 0; i
< ARRAY_SIZE(sbi
->s_anchor
); i
++) {
866 if (sbi
->s_anchor
[i
]) {
867 bh
= udf_read_tagged(sb
, sbi
->s_anchor
[i
],
868 sbi
->s_anchor
[i
], &ident
);
870 sbi
->s_anchor
[i
] = 0;
873 if ((ident
!= TAG_IDENT_AVDP
) &&
874 (i
|| (ident
!= TAG_IDENT_FE
&&
875 ident
!= TAG_IDENT_EFE
)))
876 sbi
->s_anchor
[i
] = 0;
881 sbi
->s_last_block
= lastblock
;
884 static int udf_find_fileset(struct super_block
*sb
,
885 kernel_lb_addr
*fileset
,
886 kernel_lb_addr
*root
)
888 struct buffer_head
*bh
= NULL
;
891 struct udf_sb_info
*sbi
;
893 if (fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
894 fileset
->partitionReferenceNum
!= 0xFFFF) {
895 bh
= udf_read_ptagged(sb
, *fileset
, 0, &ident
);
899 } else if (ident
!= TAG_IDENT_FSD
) {
908 /* Search backwards through the partitions */
909 kernel_lb_addr newfileset
;
911 /* --> cvg: FIXME - is it reasonable? */
914 for (newfileset
.partitionReferenceNum
= sbi
->s_partitions
- 1;
915 (newfileset
.partitionReferenceNum
!= 0xFFFF &&
916 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
917 fileset
->partitionReferenceNum
== 0xFFFF);
918 newfileset
.partitionReferenceNum
--) {
919 lastblock
= sbi
->s_partmaps
920 [newfileset
.partitionReferenceNum
]
922 newfileset
.logicalBlockNum
= 0;
925 bh
= udf_read_ptagged(sb
, newfileset
, 0,
928 newfileset
.logicalBlockNum
++;
935 struct spaceBitmapDesc
*sp
;
936 sp
= (struct spaceBitmapDesc
*)
938 newfileset
.logicalBlockNum
+= 1 +
939 ((le32_to_cpu(sp
->numOfBytes
) +
940 sizeof(struct spaceBitmapDesc
)
941 - 1) >> sb
->s_blocksize_bits
);
946 *fileset
= newfileset
;
949 newfileset
.logicalBlockNum
++;
954 } while (newfileset
.logicalBlockNum
< lastblock
&&
955 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
956 fileset
->partitionReferenceNum
== 0xFFFF);
960 if ((fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
961 fileset
->partitionReferenceNum
!= 0xFFFF) && bh
) {
962 udf_debug("Fileset at block=%d, partition=%d\n",
963 fileset
->logicalBlockNum
,
964 fileset
->partitionReferenceNum
);
966 sbi
->s_partition
= fileset
->partitionReferenceNum
;
967 udf_load_fileset(sb
, bh
, root
);
974 static void udf_load_pvoldesc(struct super_block
*sb
, struct buffer_head
*bh
)
976 struct primaryVolDesc
*pvoldesc
;
982 pvoldesc
= (struct primaryVolDesc
*)bh
->b_data
;
984 if (udf_stamp_to_time(&recording
, &recording_usec
,
985 lets_to_cpu(pvoldesc
->recordingDateAndTime
))) {
987 ts
= lets_to_cpu(pvoldesc
->recordingDateAndTime
);
988 udf_debug("recording time %ld/%ld, %04u/%02u/%02u"
990 recording
, recording_usec
,
991 ts
.year
, ts
.month
, ts
.day
, ts
.hour
,
992 ts
.minute
, ts
.typeAndTimezone
);
993 UDF_SB(sb
)->s_record_time
.tv_sec
= recording
;
994 UDF_SB(sb
)->s_record_time
.tv_nsec
= recording_usec
* 1000;
997 if (!udf_build_ustr(&instr
, pvoldesc
->volIdent
, 32))
998 if (udf_CS0toUTF8(&outstr
, &instr
)) {
999 strncpy(UDF_SB(sb
)->s_volume_ident
, outstr
.u_name
,
1000 outstr
.u_len
> 31 ? 31 : outstr
.u_len
);
1001 udf_debug("volIdent[] = '%s'\n",
1002 UDF_SB(sb
)->s_volume_ident
);
1005 if (!udf_build_ustr(&instr
, pvoldesc
->volSetIdent
, 128))
1006 if (udf_CS0toUTF8(&outstr
, &instr
))
1007 udf_debug("volSetIdent[] = '%s'\n", outstr
.u_name
);
1010 static void udf_load_fileset(struct super_block
*sb
, struct buffer_head
*bh
,
1011 kernel_lb_addr
*root
)
1013 struct fileSetDesc
*fset
;
1015 fset
= (struct fileSetDesc
*)bh
->b_data
;
1017 *root
= lelb_to_cpu(fset
->rootDirectoryICB
.extLocation
);
1019 UDF_SB(sb
)->s_serial_number
= le16_to_cpu(fset
->descTag
.tagSerialNum
);
1021 udf_debug("Rootdir at block=%d, partition=%d\n",
1022 root
->logicalBlockNum
, root
->partitionReferenceNum
);
1025 int udf_compute_nr_groups(struct super_block
*sb
, u32 partition
)
1027 struct udf_part_map
*map
= &UDF_SB(sb
)->s_partmaps
[partition
];
1028 return (map
->s_partition_len
+
1029 (sizeof(struct spaceBitmapDesc
) << 3) +
1030 (sb
->s_blocksize
* 8) - 1) /
1031 (sb
->s_blocksize
* 8);
1034 static struct udf_bitmap
*udf_sb_alloc_bitmap(struct super_block
*sb
, u32 index
)
1036 struct udf_bitmap
*bitmap
;
1040 nr_groups
= udf_compute_nr_groups(sb
, index
);
1041 size
= sizeof(struct udf_bitmap
) +
1042 (sizeof(struct buffer_head
*) * nr_groups
);
1044 if (size
<= PAGE_SIZE
)
1045 bitmap
= kmalloc(size
, GFP_KERNEL
);
1047 bitmap
= vmalloc(size
); /* TODO: get rid of vmalloc */
1049 if (bitmap
== NULL
) {
1050 udf_error(sb
, __FUNCTION__
,
1051 "Unable to allocate space for bitmap "
1052 "and %d buffer_head pointers", nr_groups
);
1056 memset(bitmap
, 0x00, size
);
1057 bitmap
->s_block_bitmap
= (struct buffer_head
**)(bitmap
+ 1);
1058 bitmap
->s_nr_groups
= nr_groups
;
1062 static int udf_load_partdesc(struct super_block
*sb
, struct buffer_head
*bh
)
1064 struct partitionDesc
*p
;
1066 struct udf_part_map
*map
;
1067 struct udf_sb_info
*sbi
;
1069 p
= (struct partitionDesc
*)bh
->b_data
;
1072 for (i
= 0; i
< sbi
->s_partitions
; i
++) {
1073 map
= &sbi
->s_partmaps
[i
];
1074 udf_debug("Searching map: (%d == %d)\n",
1075 map
->s_partition_num
,
1076 le16_to_cpu(p
->partitionNumber
));
1077 if (map
->s_partition_num
==
1078 le16_to_cpu(p
->partitionNumber
)) {
1079 map
->s_partition_len
=
1080 le32_to_cpu(p
->partitionLength
); /* blocks */
1081 map
->s_partition_root
=
1082 le32_to_cpu(p
->partitionStartingLocation
);
1083 if (p
->accessType
==
1084 cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY
))
1085 map
->s_partition_flags
|=
1086 UDF_PART_FLAG_READ_ONLY
;
1087 if (p
->accessType
==
1088 cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE
))
1089 map
->s_partition_flags
|=
1090 UDF_PART_FLAG_WRITE_ONCE
;
1091 if (p
->accessType
==
1092 cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE
))
1093 map
->s_partition_flags
|=
1094 UDF_PART_FLAG_REWRITABLE
;
1095 if (p
->accessType
==
1096 cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE
))
1097 map
->s_partition_flags
|=
1098 UDF_PART_FLAG_OVERWRITABLE
;
1100 if (!strcmp(p
->partitionContents
.ident
,
1101 PD_PARTITION_CONTENTS_NSR02
) ||
1102 !strcmp(p
->partitionContents
.ident
,
1103 PD_PARTITION_CONTENTS_NSR03
)) {
1104 struct partitionHeaderDesc
*phd
;
1106 phd
= (struct partitionHeaderDesc
*)
1107 (p
->partitionContentsUse
);
1108 if (phd
->unallocSpaceTable
.extLength
) {
1109 kernel_lb_addr loc
= {
1110 .logicalBlockNum
= le32_to_cpu(phd
->unallocSpaceTable
.extPosition
),
1111 .partitionReferenceNum
= i
,
1114 map
->s_uspace
.s_table
=
1116 if (!map
->s_uspace
.s_table
) {
1117 udf_debug("cannot load unallocSpaceTable (part %d)\n", i
);
1120 map
->s_partition_flags
|=
1121 UDF_PART_FLAG_UNALLOC_TABLE
;
1122 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
1123 i
, map
->s_uspace
.s_table
->i_ino
);
1125 if (phd
->unallocSpaceBitmap
.extLength
) {
1126 struct udf_bitmap
*bitmap
=
1127 udf_sb_alloc_bitmap(sb
, i
);
1128 map
->s_uspace
.s_bitmap
= bitmap
;
1129 if (bitmap
!= NULL
) {
1130 bitmap
->s_extLength
=
1131 le32_to_cpu(phd
->unallocSpaceBitmap
.extLength
);
1132 bitmap
->s_extPosition
=
1133 le32_to_cpu(phd
->unallocSpaceBitmap
.extPosition
);
1134 map
->s_partition_flags
|= UDF_PART_FLAG_UNALLOC_BITMAP
;
1135 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
1136 i
, bitmap
->s_extPosition
);
1139 if (phd
->partitionIntegrityTable
.extLength
)
1140 udf_debug("partitionIntegrityTable (part %d)\n", i
);
1141 if (phd
->freedSpaceTable
.extLength
) {
1142 kernel_lb_addr loc
= {
1143 .logicalBlockNum
= le32_to_cpu(phd
->freedSpaceTable
.extPosition
),
1144 .partitionReferenceNum
= i
,
1147 map
->s_fspace
.s_table
=
1149 if (!map
->s_fspace
.s_table
) {
1150 udf_debug("cannot load freedSpaceTable (part %d)\n", i
);
1153 map
->s_partition_flags
|=
1154 UDF_PART_FLAG_FREED_TABLE
;
1155 udf_debug("freedSpaceTable (part %d) @ %ld\n",
1156 i
, map
->s_fspace
.s_table
->i_ino
);
1158 if (phd
->freedSpaceBitmap
.extLength
) {
1159 struct udf_bitmap
*bitmap
=
1160 udf_sb_alloc_bitmap(sb
, i
);
1161 map
->s_fspace
.s_bitmap
= bitmap
;
1162 if (bitmap
!= NULL
) {
1163 bitmap
->s_extLength
=
1164 le32_to_cpu(phd
->freedSpaceBitmap
.extLength
);
1165 bitmap
->s_extPosition
=
1166 le32_to_cpu(phd
->freedSpaceBitmap
.extPosition
);
1167 map
->s_partition_flags
|= UDF_PART_FLAG_FREED_BITMAP
;
1168 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
1169 i
, bitmap
->s_extPosition
);
1176 if (i
== sbi
->s_partitions
)
1177 udf_debug("Partition (%d) not found in partition map\n",
1178 le16_to_cpu(p
->partitionNumber
));
1180 udf_debug("Partition (%d:%d type %x) starts at physical %d, "
1181 "block length %d\n",
1182 le16_to_cpu(p
->partitionNumber
), i
,
1183 map
->s_partition_type
,
1184 map
->s_partition_root
,
1185 map
->s_partition_len
);
1189 static int udf_load_logicalvol(struct super_block
*sb
, struct buffer_head
*bh
,
1190 kernel_lb_addr
*fileset
)
1192 struct logicalVolDesc
*lvd
;
1195 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1196 struct genericPartitionMap
*gpm
;
1198 lvd
= (struct logicalVolDesc
*)bh
->b_data
;
1200 i
= udf_sb_alloc_partition_maps(sb
, le32_to_cpu(lvd
->numPartitionMaps
));
1204 for (i
= 0, offset
= 0;
1205 i
< sbi
->s_partitions
&& offset
< le32_to_cpu(lvd
->mapTableLength
);
1206 i
++, offset
+= gpm
->partitionMapLength
) {
1207 struct udf_part_map
*map
= &sbi
->s_partmaps
[i
];
1208 gpm
= (struct genericPartitionMap
*)
1209 &(lvd
->partitionMaps
[offset
]);
1210 type
= gpm
->partitionMapType
;
1212 struct genericPartitionMap1
*gpm1
=
1213 (struct genericPartitionMap1
*)gpm
;
1214 map
->s_partition_type
= UDF_TYPE1_MAP15
;
1215 map
->s_volumeseqnum
= le16_to_cpu(gpm1
->volSeqNum
);
1216 map
->s_partition_num
= le16_to_cpu(gpm1
->partitionNum
);
1217 map
->s_partition_func
= NULL
;
1218 } else if (type
== 2) {
1219 struct udfPartitionMap2
*upm2
=
1220 (struct udfPartitionMap2
*)gpm
;
1221 if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_VIRTUAL
,
1222 strlen(UDF_ID_VIRTUAL
))) {
1224 le16_to_cpu(((__le16
*)upm2
->partIdent
.
1226 if (suf
== 0x0150) {
1227 map
->s_partition_type
=
1229 map
->s_partition_func
=
1230 udf_get_pblock_virt15
;
1231 } else if (suf
== 0x0200) {
1232 map
->s_partition_type
=
1234 map
->s_partition_func
=
1235 udf_get_pblock_virt20
;
1237 } else if (!strncmp(upm2
->partIdent
.ident
,
1239 strlen(UDF_ID_SPARABLE
))) {
1242 struct sparingTable
*st
;
1243 struct sparablePartitionMap
*spm
=
1244 (struct sparablePartitionMap
*)gpm
;
1246 map
->s_partition_type
= UDF_SPARABLE_MAP15
;
1247 map
->s_type_specific
.s_sparing
.s_packet_len
=
1248 le16_to_cpu(spm
->packetLength
);
1249 for (j
= 0; j
< spm
->numSparingTables
; j
++) {
1250 struct buffer_head
*bh2
;
1253 spm
->locSparingTable
[j
]);
1254 bh2
= udf_read_tagged(sb
, loc
, loc
,
1256 map
->s_type_specific
.s_sparing
.
1257 s_spar_map
[j
] = bh2
;
1260 st
= (struct sparingTable
*)
1262 if (ident
!= 0 || strncmp(
1263 st
->sparingIdent
.ident
,
1265 strlen(UDF_ID_SPARING
))) {
1267 map
->s_type_specific
.
1274 map
->s_partition_func
= udf_get_pblock_spar15
;
1276 udf_debug("Unknown ident: %s\n",
1277 upm2
->partIdent
.ident
);
1280 map
->s_volumeseqnum
= le16_to_cpu(upm2
->volSeqNum
);
1281 map
->s_partition_num
= le16_to_cpu(upm2
->partitionNum
);
1283 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1284 i
, map
->s_partition_num
, type
,
1285 map
->s_volumeseqnum
);
1289 long_ad
*la
= (long_ad
*)&(lvd
->logicalVolContentsUse
[0]);
1291 *fileset
= lelb_to_cpu(la
->extLocation
);
1292 udf_debug("FileSet found in LogicalVolDesc at block=%d, "
1293 "partition=%d\n", fileset
->logicalBlockNum
,
1294 fileset
->partitionReferenceNum
);
1296 if (lvd
->integritySeqExt
.extLength
)
1297 udf_load_logicalvolint(sb
, leea_to_cpu(lvd
->integritySeqExt
));
1303 * udf_load_logicalvolint
1306 static void udf_load_logicalvolint(struct super_block
*sb
, kernel_extent_ad loc
)
1308 struct buffer_head
*bh
= NULL
;
1310 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1311 struct logicalVolIntegrityDesc
*lvid
;
1313 while (loc
.extLength
> 0 &&
1314 (bh
= udf_read_tagged(sb
, loc
.extLocation
,
1315 loc
.extLocation
, &ident
)) &&
1316 ident
== TAG_IDENT_LVID
) {
1317 sbi
->s_lvid_bh
= bh
;
1318 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1320 if (lvid
->nextIntegrityExt
.extLength
)
1321 udf_load_logicalvolint(sb
,
1322 leea_to_cpu(lvid
->nextIntegrityExt
));
1324 if (sbi
->s_lvid_bh
!= bh
)
1326 loc
.extLength
-= sb
->s_blocksize
;
1329 if (sbi
->s_lvid_bh
!= bh
)
1334 * udf_process_sequence
1337 * Process a main/reserve volume descriptor sequence.
1340 * sb Pointer to _locked_ superblock.
1341 * block First block of first extent of the sequence.
1342 * lastblock Lastblock of first extent of the sequence.
1345 * July 1, 1997 - Andrew E. Mileski
1346 * Written, tested, and released.
1348 static int udf_process_sequence(struct super_block
*sb
, long block
,
1349 long lastblock
, kernel_lb_addr
*fileset
)
1351 struct buffer_head
*bh
= NULL
;
1352 struct udf_vds_record vds
[VDS_POS_LENGTH
];
1353 struct udf_vds_record
*curr
;
1354 struct generic_desc
*gd
;
1355 struct volDescPtr
*vdp
;
1360 long next_s
= 0, next_e
= 0;
1362 memset(vds
, 0, sizeof(struct udf_vds_record
) * VDS_POS_LENGTH
);
1364 /* Read the main descriptor sequence */
1365 for (; (!done
&& block
<= lastblock
); block
++) {
1367 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1371 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1372 gd
= (struct generic_desc
*)bh
->b_data
;
1373 vdsn
= le32_to_cpu(gd
->volDescSeqNum
);
1375 case TAG_IDENT_PVD
: /* ISO 13346 3/10.1 */
1376 curr
= &vds
[VDS_POS_PRIMARY_VOL_DESC
];
1377 if (vdsn
>= curr
->volDescSeqNum
) {
1378 curr
->volDescSeqNum
= vdsn
;
1379 curr
->block
= block
;
1382 case TAG_IDENT_VDP
: /* ISO 13346 3/10.3 */
1383 curr
= &vds
[VDS_POS_VOL_DESC_PTR
];
1384 if (vdsn
>= curr
->volDescSeqNum
) {
1385 curr
->volDescSeqNum
= vdsn
;
1386 curr
->block
= block
;
1388 vdp
= (struct volDescPtr
*)bh
->b_data
;
1389 next_s
= le32_to_cpu(
1390 vdp
->nextVolDescSeqExt
.extLocation
);
1391 next_e
= le32_to_cpu(
1392 vdp
->nextVolDescSeqExt
.extLength
);
1393 next_e
= next_e
>> sb
->s_blocksize_bits
;
1397 case TAG_IDENT_IUVD
: /* ISO 13346 3/10.4 */
1398 curr
= &vds
[VDS_POS_IMP_USE_VOL_DESC
];
1399 if (vdsn
>= curr
->volDescSeqNum
) {
1400 curr
->volDescSeqNum
= vdsn
;
1401 curr
->block
= block
;
1404 case TAG_IDENT_PD
: /* ISO 13346 3/10.5 */
1405 curr
= &vds
[VDS_POS_PARTITION_DESC
];
1407 curr
->block
= block
;
1409 case TAG_IDENT_LVD
: /* ISO 13346 3/10.6 */
1410 curr
= &vds
[VDS_POS_LOGICAL_VOL_DESC
];
1411 if (vdsn
>= curr
->volDescSeqNum
) {
1412 curr
->volDescSeqNum
= vdsn
;
1413 curr
->block
= block
;
1416 case TAG_IDENT_USD
: /* ISO 13346 3/10.8 */
1417 curr
= &vds
[VDS_POS_UNALLOC_SPACE_DESC
];
1418 if (vdsn
>= curr
->volDescSeqNum
) {
1419 curr
->volDescSeqNum
= vdsn
;
1420 curr
->block
= block
;
1423 case TAG_IDENT_TD
: /* ISO 13346 3/10.9 */
1424 vds
[VDS_POS_TERMINATING_DESC
].block
= block
;
1428 next_s
= next_e
= 0;
1435 for (i
= 0; i
< VDS_POS_LENGTH
; i
++) {
1437 bh
= udf_read_tagged(sb
, vds
[i
].block
, vds
[i
].block
,
1440 if (i
== VDS_POS_PRIMARY_VOL_DESC
) {
1441 udf_load_pvoldesc(sb
, bh
);
1442 } else if (i
== VDS_POS_LOGICAL_VOL_DESC
) {
1443 if (udf_load_logicalvol(sb
, bh
, fileset
)) {
1447 } else if (i
== VDS_POS_PARTITION_DESC
) {
1448 struct buffer_head
*bh2
= NULL
;
1449 if (udf_load_partdesc(sb
, bh
)) {
1453 for (j
= vds
[i
].block
+ 1;
1454 j
< vds
[VDS_POS_TERMINATING_DESC
].block
;
1456 bh2
= udf_read_tagged(sb
, j
, j
, &ident
);
1457 gd
= (struct generic_desc
*)bh2
->b_data
;
1458 if (ident
== TAG_IDENT_PD
)
1459 if (udf_load_partdesc(sb
,
1478 static int udf_check_valid(struct super_block
*sb
, int novrs
, int silent
)
1483 udf_debug("Validity check skipped because of novrs option\n");
1486 /* Check that it is NSR02 compliant */
1487 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1489 block
= udf_vrs(sb
, silent
);
1491 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1492 udf_debug("Failed to read byte 32768. Assuming open "
1493 "disc. Skipping validity check\n");
1494 if (!sbi
->s_last_block
)
1495 sbi
->s_last_block
= udf_get_last_block(sb
);
1502 static int udf_load_partition(struct super_block
*sb
, kernel_lb_addr
*fileset
)
1504 struct anchorVolDescPtr
*anchor
;
1506 struct buffer_head
*bh
;
1507 long main_s
, main_e
, reserve_s
, reserve_e
;
1509 struct udf_sb_info
*sbi
;
1515 for (i
= 0; i
< ARRAY_SIZE(sbi
->s_anchor
); i
++) {
1516 if (!sbi
->s_anchor
[i
])
1518 bh
= udf_read_tagged(sb
, sbi
->s_anchor
[i
], sbi
->s_anchor
[i
],
1523 anchor
= (struct anchorVolDescPtr
*)bh
->b_data
;
1525 /* Locate the main sequence */
1526 main_s
= le32_to_cpu(anchor
->mainVolDescSeqExt
.extLocation
);
1527 main_e
= le32_to_cpu(anchor
->mainVolDescSeqExt
.extLength
);
1528 main_e
= main_e
>> sb
->s_blocksize_bits
;
1531 /* Locate the reserve sequence */
1532 reserve_s
= le32_to_cpu(
1533 anchor
->reserveVolDescSeqExt
.extLocation
);
1534 reserve_e
= le32_to_cpu(
1535 anchor
->reserveVolDescSeqExt
.extLength
);
1536 reserve_e
= reserve_e
>> sb
->s_blocksize_bits
;
1537 reserve_e
+= reserve_s
;
1541 /* Process the main & reserve sequences */
1542 /* responsible for finding the PartitionDesc(s) */
1543 if (!(udf_process_sequence(sb
, main_s
, main_e
,
1545 udf_process_sequence(sb
, reserve_s
, reserve_e
,
1550 if (i
== ARRAY_SIZE(sbi
->s_anchor
)) {
1551 udf_debug("No Anchor block found\n");
1554 udf_debug("Using anchor in block %d\n", sbi
->s_anchor
[i
]);
1556 for (i
= 0; i
< sbi
->s_partitions
; i
++) {
1557 kernel_lb_addr
uninitialized_var(ino
);
1558 struct udf_part_map
*map
= &sbi
->s_partmaps
[i
];
1559 switch (map
->s_partition_type
) {
1560 case UDF_VIRTUAL_MAP15
:
1561 case UDF_VIRTUAL_MAP20
:
1562 if (!sbi
->s_last_block
) {
1563 sbi
->s_last_block
= udf_get_last_block(sb
);
1564 udf_find_anchor(sb
);
1567 if (!sbi
->s_last_block
) {
1568 udf_debug("Unable to determine Lastblock (For "
1569 "Virtual Partition)\n");
1573 for (j
= 0; j
< sbi
->s_partitions
; j
++) {
1574 struct udf_part_map
*map2
= &sbi
->s_partmaps
[j
];
1576 map
->s_volumeseqnum
==
1577 map2
->s_volumeseqnum
&&
1578 map
->s_partition_num
==
1579 map2
->s_partition_num
) {
1580 ino
.partitionReferenceNum
= j
;
1581 ino
.logicalBlockNum
=
1583 map2
->s_partition_root
;
1588 if (j
== sbi
->s_partitions
)
1591 sbi
->s_vat_inode
= udf_iget(sb
, ino
);
1592 if (!sbi
->s_vat_inode
)
1595 if (map
->s_partition_type
== UDF_VIRTUAL_MAP15
) {
1596 map
->s_type_specific
.s_virtual
.s_start_offset
=
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
- 36) >> 2;
1600 } else if (map
->s_partition_type
== UDF_VIRTUAL_MAP20
) {
1602 struct virtualAllocationTable20
*vat20
;
1604 pos
= udf_block_map(sbi
->s_vat_inode
, 0);
1605 bh
= sb_bread(sb
, pos
);
1608 vat20
= (struct virtualAllocationTable20
*)
1610 udf_ext0_offset(sbi
->s_vat_inode
);
1611 map
->s_type_specific
.s_virtual
.s_start_offset
=
1612 le16_to_cpu(vat20
->lengthHeader
) +
1613 udf_ext0_offset(sbi
->s_vat_inode
);
1614 map
->s_type_specific
.s_virtual
.s_num_entries
=
1615 (sbi
->s_vat_inode
->i_size
-
1616 map
->s_type_specific
.s_virtual
.
1617 s_start_offset
) >> 2;
1620 map
->s_partition_root
= udf_get_pblock(sb
, 0, i
, 0);
1621 map
->s_partition_len
=
1622 sbi
->s_partmaps
[ino
.partitionReferenceNum
].
1629 static void udf_open_lvid(struct super_block
*sb
)
1631 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1632 struct buffer_head
*bh
= sbi
->s_lvid_bh
;
1634 kernel_timestamp cpu_time
;
1635 struct logicalVolIntegrityDesc
*lvid
=
1636 (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1637 struct logicalVolIntegrityDescImpUse
*lvidiu
=
1640 lvidiu
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1641 lvidiu
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1642 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
))
1643 lvid
->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1644 lvid
->integrityType
= LVID_INTEGRITY_TYPE_OPEN
;
1646 lvid
->descTag
.descCRC
= cpu_to_le16(
1647 udf_crc((char *)lvid
+ sizeof(tag
),
1648 le16_to_cpu(lvid
->descTag
.descCRCLength
),
1651 lvid
->descTag
.tagChecksum
= udf_tag_checksum(&lvid
->descTag
);
1652 mark_buffer_dirty(bh
);
1656 static void udf_close_lvid(struct super_block
*sb
)
1658 kernel_timestamp cpu_time
;
1659 struct udf_sb_info
*sbi
= UDF_SB(sb
);
1660 struct buffer_head
*bh
= sbi
->s_lvid_bh
;
1661 struct logicalVolIntegrityDesc
*lvid
;
1666 lvid
= (struct logicalVolIntegrityDesc
*)bh
->b_data
;
1668 if (lvid
->integrityType
== LVID_INTEGRITY_TYPE_OPEN
) {
1669 struct logicalVolIntegrityDescImpUse
*lvidiu
=
1671 lvidiu
->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1672 lvidiu
->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1673 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
))
1674 lvid
->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1675 if (UDF_MAX_WRITE_VERSION
> le16_to_cpu(lvidiu
->maxUDFWriteRev
))
1676 lvidiu
->maxUDFWriteRev
=
1677 cpu_to_le16(UDF_MAX_WRITE_VERSION
);
1678 if (sbi
->s_udfrev
> le16_to_cpu(lvidiu
->minUDFReadRev
))
1679 lvidiu
->minUDFReadRev
= cpu_to_le16(sbi
->s_udfrev
);
1680 if (sbi
->s_udfrev
> le16_to_cpu(lvidiu
->minUDFWriteRev
))
1681 lvidiu
->minUDFWriteRev
= cpu_to_le16(sbi
->s_udfrev
);
1682 lvid
->integrityType
= cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE
);
1684 lvid
->descTag
.descCRC
= cpu_to_le16(
1685 udf_crc((char *)lvid
+ sizeof(tag
),
1686 le16_to_cpu(lvid
->descTag
.descCRCLength
),
1689 lvid
->descTag
.tagChecksum
= udf_tag_checksum(&lvid
->descTag
);
1690 mark_buffer_dirty(bh
);
1694 static void udf_sb_free_bitmap(struct udf_bitmap
*bitmap
)
1697 int nr_groups
= bitmap
->s_nr_groups
;
1698 int size
= sizeof(struct udf_bitmap
) + (sizeof(struct buffer_head
*) *
1701 for (i
= 0; i
< nr_groups
; i
++)
1702 if (bitmap
->s_block_bitmap
[i
])
1703 brelse(bitmap
->s_block_bitmap
[i
]);
1705 if (size
<= PAGE_SIZE
)
1715 * Complete the specified super block.
1718 * sb Pointer to superblock to complete - never NULL.
1719 * sb->s_dev Device to read suberblock from.
1720 * options Pointer to mount options.
1721 * silent Silent flag.
1724 * July 1, 1997 - Andrew E. Mileski
1725 * Written, tested, and released.
1727 static int udf_fill_super(struct super_block
*sb
, void *options
, int silent
)
1730 struct inode
*inode
= NULL
;
1731 struct udf_options uopt
;
1732 kernel_lb_addr rootdir
, fileset
;
1733 struct udf_sb_info
*sbi
;
1735 uopt
.flags
= (1 << UDF_FLAG_USE_AD_IN_ICB
) | (1 << UDF_FLAG_STRICT
);
1740 sbi
= kzalloc(sizeof(struct udf_sb_info
), GFP_KERNEL
);
1744 sb
->s_fs_info
= sbi
;
1746 mutex_init(&sbi
->s_alloc_mutex
);
1748 if (!udf_parse_options((char *)options
, &uopt
, false))
1751 if (uopt
.flags
& (1 << UDF_FLAG_UTF8
) &&
1752 uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) {
1753 udf_error(sb
, "udf_read_super",
1754 "utf8 cannot be combined with iocharset\n");
1757 #ifdef CONFIG_UDF_NLS
1758 if ((uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) && !uopt
.nls_map
) {
1759 uopt
.nls_map
= load_nls_default();
1761 uopt
.flags
&= ~(1 << UDF_FLAG_NLS_MAP
);
1763 udf_debug("Using default NLS map\n");
1766 if (!(uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)))
1767 uopt
.flags
|= (1 << UDF_FLAG_UTF8
);
1769 fileset
.logicalBlockNum
= 0xFFFFFFFF;
1770 fileset
.partitionReferenceNum
= 0xFFFF;
1772 sbi
->s_flags
= uopt
.flags
;
1773 sbi
->s_uid
= uopt
.uid
;
1774 sbi
->s_gid
= uopt
.gid
;
1775 sbi
->s_umask
= uopt
.umask
;
1776 sbi
->s_nls_map
= uopt
.nls_map
;
1778 /* Set the block size for all transfers */
1779 if (!udf_set_blocksize(sb
, uopt
.blocksize
))
1782 if (uopt
.session
== 0xFFFFFFFF)
1783 sbi
->s_session
= udf_get_last_session(sb
);
1785 sbi
->s_session
= uopt
.session
;
1787 udf_debug("Multi-session=%d\n", sbi
->s_session
);
1789 sbi
->s_last_block
= uopt
.lastblock
;
1790 sbi
->s_anchor
[0] = sbi
->s_anchor
[1] = 0;
1791 sbi
->s_anchor
[2] = uopt
.anchor
;
1792 sbi
->s_anchor
[3] = 256;
1794 if (udf_check_valid(sb
, uopt
.novrs
, silent
)) {
1795 /* read volume recognition sequences */
1796 printk(KERN_WARNING
"UDF-fs: No VRS found\n");
1800 udf_find_anchor(sb
);
1802 /* Fill in the rest of the superblock */
1803 sb
->s_op
= &udf_sb_ops
;
1806 sb
->s_magic
= UDF_SUPER_MAGIC
;
1807 sb
->s_time_gran
= 1000;
1809 if (udf_load_partition(sb
, &fileset
)) {
1810 printk(KERN_WARNING
"UDF-fs: No partition found (1)\n");
1814 udf_debug("Lastblock=%d\n", sbi
->s_last_block
);
1816 if (sbi
->s_lvid_bh
) {
1817 struct logicalVolIntegrityDescImpUse
*lvidiu
=
1819 uint16_t minUDFReadRev
= le16_to_cpu(lvidiu
->minUDFReadRev
);
1820 uint16_t minUDFWriteRev
= le16_to_cpu(lvidiu
->minUDFWriteRev
);
1821 /* uint16_t maxUDFWriteRev =
1822 le16_to_cpu(lvidiu->maxUDFWriteRev); */
1824 if (minUDFReadRev
> UDF_MAX_READ_VERSION
) {
1825 printk(KERN_ERR
"UDF-fs: minUDFReadRev=%x "
1827 le16_to_cpu(lvidiu
->minUDFReadRev
),
1828 UDF_MAX_READ_VERSION
);
1830 } else if (minUDFWriteRev
> UDF_MAX_WRITE_VERSION
)
1831 sb
->s_flags
|= MS_RDONLY
;
1833 sbi
->s_udfrev
= minUDFWriteRev
;
1835 if (minUDFReadRev
>= UDF_VERS_USE_EXTENDED_FE
)
1836 UDF_SET_FLAG(sb
, UDF_FLAG_USE_EXTENDED_FE
);
1837 if (minUDFReadRev
>= UDF_VERS_USE_STREAMS
)
1838 UDF_SET_FLAG(sb
, UDF_FLAG_USE_STREAMS
);
1841 if (!sbi
->s_partitions
) {
1842 printk(KERN_WARNING
"UDF-fs: No partition found (2)\n");
1846 if (sbi
->s_partmaps
[sbi
->s_partition
].s_partition_flags
&
1847 UDF_PART_FLAG_READ_ONLY
) {
1848 printk(KERN_NOTICE
"UDF-fs: Partition marked readonly; "
1849 "forcing readonly mount\n");
1850 sb
->s_flags
|= MS_RDONLY
;
1853 if (udf_find_fileset(sb
, &fileset
, &rootdir
)) {
1854 printk(KERN_WARNING
"UDF-fs: No fileset found\n");
1859 kernel_timestamp ts
;
1860 udf_time_to_stamp(&ts
, sbi
->s_record_time
);
1861 udf_info("UDF: Mounting volume '%s', "
1862 "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1863 sbi
->s_volume_ident
, ts
.year
, ts
.month
, ts
.day
,
1864 ts
.hour
, ts
.minute
, ts
.typeAndTimezone
);
1866 if (!(sb
->s_flags
& MS_RDONLY
))
1869 /* Assign the root inode */
1870 /* assign inodes by physical block number */
1871 /* perhaps it's not extensible enough, but for now ... */
1872 inode
= udf_iget(sb
, rootdir
);
1874 printk(KERN_ERR
"UDF-fs: Error in udf_iget, block=%d, "
1876 rootdir
.logicalBlockNum
, rootdir
.partitionReferenceNum
);
1880 /* Allocate a dentry for the root inode */
1881 sb
->s_root
= d_alloc_root(inode
);
1883 printk(KERN_ERR
"UDF-fs: Couldn't allocate root dentry\n");
1887 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
1891 if (sbi
->s_vat_inode
)
1892 iput(sbi
->s_vat_inode
);
1893 if (sbi
->s_partitions
) {
1894 struct udf_part_map
*map
= &sbi
->s_partmaps
[sbi
->s_partition
];
1895 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
)
1896 iput(map
->s_uspace
.s_table
);
1897 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
)
1898 iput(map
->s_fspace
.s_table
);
1899 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
)
1900 udf_sb_free_bitmap(map
->s_uspace
.s_bitmap
);
1901 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
)
1902 udf_sb_free_bitmap(map
->s_fspace
.s_bitmap
);
1903 if (map
->s_partition_type
== UDF_SPARABLE_MAP15
)
1904 for (i
= 0; i
< 4; i
++)
1905 brelse(map
->s_type_specific
.s_sparing
.
1908 #ifdef CONFIG_UDF_NLS
1909 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
1910 unload_nls(sbi
->s_nls_map
);
1912 if (!(sb
->s_flags
& MS_RDONLY
))
1914 brelse(sbi
->s_lvid_bh
);
1916 kfree(sbi
->s_partmaps
);
1918 sb
->s_fs_info
= NULL
;
1923 void udf_error(struct super_block
*sb
, const char *function
,
1924 const char *fmt
, ...)
1928 if (!(sb
->s_flags
& MS_RDONLY
)) {
1932 va_start(args
, fmt
);
1933 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
1935 printk(KERN_CRIT
"UDF-fs error (device %s): %s: %s\n",
1936 sb
->s_id
, function
, error_buf
);
1939 void udf_warning(struct super_block
*sb
, const char *function
,
1940 const char *fmt
, ...)
1944 va_start(args
, fmt
);
1945 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
1947 printk(KERN_WARNING
"UDF-fs warning (device %s): %s: %s\n",
1948 sb
->s_id
, function
, error_buf
);
1955 * Prepare for destruction of the superblock.
1958 * Called before the filesystem is unmounted.
1961 * July 1, 1997 - Andrew E. Mileski
1962 * Written, tested, and released.
1964 static void udf_put_super(struct super_block
*sb
)
1967 struct udf_sb_info
*sbi
;
1970 if (sbi
->s_vat_inode
)
1971 iput(sbi
->s_vat_inode
);
1972 if (sbi
->s_partitions
) {
1973 struct udf_part_map
*map
= &sbi
->s_partmaps
[sbi
->s_partition
];
1974 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
)
1975 iput(map
->s_uspace
.s_table
);
1976 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
)
1977 iput(map
->s_fspace
.s_table
);
1978 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
)
1979 udf_sb_free_bitmap(map
->s_uspace
.s_bitmap
);
1980 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
)
1981 udf_sb_free_bitmap(map
->s_fspace
.s_bitmap
);
1982 if (map
->s_partition_type
== UDF_SPARABLE_MAP15
)
1983 for (i
= 0; i
< 4; i
++)
1984 brelse(map
->s_type_specific
.s_sparing
.
1987 #ifdef CONFIG_UDF_NLS
1988 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
1989 unload_nls(sbi
->s_nls_map
);
1991 if (!(sb
->s_flags
& MS_RDONLY
))
1993 brelse(sbi
->s_lvid_bh
);
1994 kfree(sbi
->s_partmaps
);
1995 kfree(sb
->s_fs_info
);
1996 sb
->s_fs_info
= NULL
;
2003 * Return info about the filesystem.
2006 * Called by sys_statfs()
2009 * July 1, 1997 - Andrew E. Mileski
2010 * Written, tested, and released.
2012 static int udf_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
2014 struct super_block
*sb
= dentry
->d_sb
;
2015 struct udf_sb_info
*sbi
= UDF_SB(sb
);
2016 struct logicalVolIntegrityDescImpUse
*lvidiu
;
2018 if (sbi
->s_lvid_bh
!= NULL
)
2019 lvidiu
= udf_sb_lvidiu(sbi
);
2023 buf
->f_type
= UDF_SUPER_MAGIC
;
2024 buf
->f_bsize
= sb
->s_blocksize
;
2025 buf
->f_blocks
= sbi
->s_partmaps
[sbi
->s_partition
].s_partition_len
;
2026 buf
->f_bfree
= udf_count_free(sb
);
2027 buf
->f_bavail
= buf
->f_bfree
;
2028 buf
->f_files
= (lvidiu
!= NULL
? (le32_to_cpu(lvidiu
->numFiles
) +
2029 le32_to_cpu(lvidiu
->numDirs
)) : 0)
2031 buf
->f_ffree
= buf
->f_bfree
;
2032 /* __kernel_fsid_t f_fsid */
2033 buf
->f_namelen
= UDF_NAME_LEN
- 2;
2038 static unsigned char udf_bitmap_lookup
[16] = {
2039 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
2042 static unsigned int udf_count_free_bitmap(struct super_block
*sb
,
2043 struct udf_bitmap
*bitmap
)
2045 struct buffer_head
*bh
= NULL
;
2046 unsigned int accum
= 0;
2048 int block
= 0, newblock
;
2054 struct spaceBitmapDesc
*bm
;
2058 loc
.logicalBlockNum
= bitmap
->s_extPosition
;
2059 loc
.partitionReferenceNum
= UDF_SB(sb
)->s_partition
;
2060 bh
= udf_read_ptagged(sb
, loc
, 0, &ident
);
2063 printk(KERN_ERR
"udf: udf_count_free failed\n");
2065 } else if (ident
!= TAG_IDENT_SBD
) {
2067 printk(KERN_ERR
"udf: udf_count_free failed\n");
2071 bm
= (struct spaceBitmapDesc
*)bh
->b_data
;
2072 bytes
= le32_to_cpu(bm
->numOfBytes
);
2073 index
= sizeof(struct spaceBitmapDesc
); /* offset in first block only */
2074 ptr
= (uint8_t *)bh
->b_data
;
2077 while ((bytes
> 0) && (index
< sb
->s_blocksize
)) {
2079 accum
+= udf_bitmap_lookup
[value
& 0x0f];
2080 accum
+= udf_bitmap_lookup
[value
>> 4];
2086 newblock
= udf_get_lb_pblock(sb
, loc
, ++block
);
2087 bh
= udf_tread(sb
, newblock
);
2089 udf_debug("read failed\n");
2093 ptr
= (uint8_t *)bh
->b_data
;
2104 static unsigned int udf_count_free_table(struct super_block
*sb
,
2105 struct inode
*table
)
2107 unsigned int accum
= 0;
2109 kernel_lb_addr eloc
;
2111 struct extent_position epos
;
2115 epos
.block
= UDF_I(table
)->i_location
;
2116 epos
.offset
= sizeof(struct unallocSpaceEntry
);
2119 while ((etype
= udf_next_aext(table
, &epos
, &eloc
, &elen
, 1)) != -1)
2120 accum
+= (elen
>> table
->i_sb
->s_blocksize_bits
);
2129 static unsigned int udf_count_free(struct super_block
*sb
)
2131 unsigned int accum
= 0;
2132 struct udf_sb_info
*sbi
;
2133 struct udf_part_map
*map
;
2136 if (sbi
->s_lvid_bh
) {
2137 struct logicalVolIntegrityDesc
*lvid
=
2138 (struct logicalVolIntegrityDesc
*)
2139 sbi
->s_lvid_bh
->b_data
;
2140 if (le32_to_cpu(lvid
->numOfPartitions
) > sbi
->s_partition
) {
2141 accum
= le32_to_cpu(
2142 lvid
->freeSpaceTable
[sbi
->s_partition
]);
2143 if (accum
== 0xFFFFFFFF)
2151 map
= &sbi
->s_partmaps
[sbi
->s_partition
];
2152 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_BITMAP
) {
2153 accum
+= udf_count_free_bitmap(sb
,
2154 map
->s_uspace
.s_bitmap
);
2156 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_BITMAP
) {
2157 accum
+= udf_count_free_bitmap(sb
,
2158 map
->s_fspace
.s_bitmap
);
2163 if (map
->s_partition_flags
& UDF_PART_FLAG_UNALLOC_TABLE
) {
2164 accum
+= udf_count_free_table(sb
,
2165 map
->s_uspace
.s_table
);
2167 if (map
->s_partition_flags
& UDF_PART_FLAG_FREED_TABLE
) {
2168 accum
+= udf_count_free_table(sb
,
2169 map
->s_fspace
.s_table
);