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 * E-mail regarding any portion of the Linux UDF file system should be
19 * directed to the development team mailing list (run by majordomo):
20 * linux_udf@hpesjro.fc.hp.com
23 * This file is distributed under the terms of the GNU General Public
24 * License (GPL). Copies of the GPL can be obtained from:
25 * ftp://prep.ai.mit.edu/pub/gnu/GPL
26 * Each contributing author retains all rights to their own work.
28 * (C) 1998 Dave Boynton
29 * (C) 1998-2001 Ben Fennema
30 * (C) 2000 Stelias Computing Inc
34 * 09/24/98 dgb changed to allow compiling outside of kernel, and
35 * added some debugging.
36 * 10/01/98 dgb updated to allow (some) possibility of compiling w/2.0.34
37 * 10/16/98 attempting some multi-session support
38 * 10/17/98 added freespace count for "df"
39 * 11/11/98 gr added novrs option
40 * 11/26/98 dgb added fileset,anchor mount options
41 * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced vol descs
42 * rewrote option handling based on isofs
43 * 12/20/98 find the free space bitmap (if it exists)
48 #include <linux/config.h>
49 #include <linux/blkdev.h>
50 #include <linux/slab.h>
51 #include <linux/kernel.h>
52 #include <linux/module.h>
53 #include <linux/parser.h>
54 #include <linux/stat.h>
55 #include <linux/cdrom.h>
56 #include <linux/nls.h>
57 #include <linux/smp_lock.h>
58 #include <linux/buffer_head.h>
59 #include <linux/vfs.h>
60 #include <asm/byteorder.h>
62 #include <linux/udf_fs.h>
66 #include <linux/init.h>
67 #include <asm/uaccess.h>
69 #define VDS_POS_PRIMARY_VOL_DESC 0
70 #define VDS_POS_UNALLOC_SPACE_DESC 1
71 #define VDS_POS_LOGICAL_VOL_DESC 2
72 #define VDS_POS_PARTITION_DESC 3
73 #define VDS_POS_IMP_USE_VOL_DESC 4
74 #define VDS_POS_VOL_DESC_PTR 5
75 #define VDS_POS_TERMINATING_DESC 6
76 #define VDS_POS_LENGTH 7
78 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
*, lb_addr
*);
88 static int udf_load_logicalvol(struct super_block
*, struct buffer_head
*, lb_addr
*);
89 static void udf_load_logicalvolint(struct super_block
*, extent_ad
);
90 static void udf_find_anchor(struct super_block
*);
91 static int udf_find_fileset(struct super_block
*, lb_addr
*, lb_addr
*);
92 static void udf_load_pvoldesc(struct super_block
*, struct buffer_head
*);
93 static void udf_load_fileset(struct super_block
*, struct buffer_head
*, lb_addr
*);
94 static void udf_load_partdesc(struct super_block
*, struct buffer_head
*);
95 static void udf_open_lvid(struct super_block
*);
96 static void udf_close_lvid(struct super_block
*);
97 static unsigned int udf_count_free(struct super_block
*);
98 static int udf_statfs(struct super_block
*, struct kstatfs
*);
100 /* UDF filesystem type */
101 static struct super_block
*udf_get_sb(struct file_system_type
*fs_type
,
102 int flags
, const char *dev_name
, void *data
)
104 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, udf_fill_super
);
107 static struct file_system_type udf_fstype
= {
108 .owner
= THIS_MODULE
,
110 .get_sb
= udf_get_sb
,
111 .kill_sb
= kill_block_super
,
112 .fs_flags
= FS_REQUIRES_DEV
,
115 static kmem_cache_t
* udf_inode_cachep
;
117 static struct inode
*udf_alloc_inode(struct super_block
*sb
)
119 struct udf_inode_info
*ei
;
120 ei
= (struct udf_inode_info
*)kmem_cache_alloc(udf_inode_cachep
, SLAB_KERNEL
);
123 return &ei
->vfs_inode
;
126 static void udf_destroy_inode(struct inode
*inode
)
128 kmem_cache_free(udf_inode_cachep
, UDF_I(inode
));
131 static void init_once(void * foo
, kmem_cache_t
* cachep
, unsigned long flags
)
133 struct udf_inode_info
*ei
= (struct udf_inode_info
*) foo
;
135 if ((flags
& (SLAB_CTOR_VERIFY
|SLAB_CTOR_CONSTRUCTOR
)) ==
136 SLAB_CTOR_CONSTRUCTOR
) {
137 ei
->i_ext
.i_data
= NULL
;
138 inode_init_once(&ei
->vfs_inode
);
142 static int init_inodecache(void)
144 udf_inode_cachep
= kmem_cache_create("udf_inode_cache",
145 sizeof(struct udf_inode_info
),
146 0, SLAB_HWCACHE_ALIGN
|SLAB_RECLAIM_ACCOUNT
,
148 if (udf_inode_cachep
== NULL
)
153 static void destroy_inodecache(void)
155 if (kmem_cache_destroy(udf_inode_cachep
))
156 printk(KERN_INFO
"udf_inode_cache: not all structures were freed\n");
159 /* Superblock operations */
160 static struct super_operations udf_sb_ops
= {
161 .alloc_inode
= udf_alloc_inode
,
162 .destroy_inode
= udf_destroy_inode
,
163 .read_inode
= udf_read_inode
,
164 .write_inode
= udf_write_inode
,
165 .put_inode
= udf_put_inode
,
166 .delete_inode
= udf_delete_inode
,
167 .clear_inode
= udf_clear_inode
,
168 .put_super
= udf_put_super
,
169 .write_super
= udf_write_super
,
170 .statfs
= udf_statfs
,
171 .remount_fs
= udf_remount_fs
,
177 unsigned int blocksize
;
178 unsigned int session
;
179 unsigned int lastblock
;
182 unsigned short partition
;
183 unsigned int fileset
;
184 unsigned int rootdir
;
189 struct nls_table
*nls_map
;
192 static int __init
init_udf_fs(void)
195 printk(KERN_NOTICE
"udf: registering filesystem\n");
196 err
= init_inodecache();
199 err
= register_filesystem(&udf_fstype
);
204 destroy_inodecache();
209 static void __exit
exit_udf_fs(void)
211 printk(KERN_NOTICE
"udf: unregistering filesystem\n");
212 unregister_filesystem(&udf_fstype
);
213 destroy_inodecache();
216 module_init(init_udf_fs
)
217 module_exit(exit_udf_fs
)
223 * Parse mount options.
226 * The following mount options are supported:
228 * gid= Set the default group.
229 * umask= Set the default umask.
230 * uid= Set the default user.
231 * bs= Set the block size.
232 * unhide Show otherwise hidden files.
233 * undelete Show deleted files in lists.
234 * adinicb Embed data in the inode (default)
235 * noadinicb Don't embed data in the inode
236 * shortad Use short ad's
237 * longad Use long ad's (default)
238 * nostrict Unset strict conformance
239 * iocharset= Set the NLS character set
241 * The remaining are for debugging and disaster recovery:
243 * novrs Skip volume sequence recognition
245 * The following expect a offset from 0.
247 * session= Set the CDROM session (default= last session)
248 * anchor= Override standard anchor location. (default= 256)
249 * volume= Override the VolumeDesc location. (unused)
250 * partition= Override the PartitionDesc location. (unused)
251 * lastblock= Set the last block of the filesystem/
253 * The following expect a offset from the partition root.
255 * fileset= Override the fileset block location. (unused)
256 * rootdir= Override the root directory location. (unused)
257 * WARNING: overriding the rootdir to a non-directory may
258 * yield highly unpredictable results.
261 * options Pointer to mount options string.
262 * uopts Pointer to mount options variable.
265 * <return> 1 Mount options parsed okay.
266 * <return> 0 Error parsing mount options.
269 * July 1, 1997 - Andrew E. Mileski
270 * Written, tested, and released.
274 Opt_novrs
, Opt_nostrict
, Opt_bs
, Opt_unhide
, Opt_undelete
,
275 Opt_noadinicb
, Opt_adinicb
, Opt_shortad
, Opt_longad
,
276 Opt_gid
, Opt_uid
, Opt_umask
, Opt_session
, Opt_lastblock
,
277 Opt_anchor
, Opt_volume
, Opt_partition
, Opt_fileset
,
278 Opt_rootdir
, Opt_utf8
, Opt_iocharset
,
282 static match_table_t tokens
= {
283 {Opt_novrs
, "novrs"},
284 {Opt_nostrict
, "nostrict"},
286 {Opt_unhide
, "unhide"},
287 {Opt_undelete
, "undelete"},
288 {Opt_noadinicb
, "noadinicb"},
289 {Opt_adinicb
, "adinicb"},
290 {Opt_shortad
, "shortad"},
291 {Opt_longad
, "longad"},
294 {Opt_umask
, "umask=%o"},
295 {Opt_session
, "session=%u"},
296 {Opt_lastblock
, "lastblock=%u"},
297 {Opt_anchor
, "anchor=%u"},
298 {Opt_volume
, "volume=%u"},
299 {Opt_partition
, "partition=%u"},
300 {Opt_fileset
, "fileset=%u"},
301 {Opt_rootdir
, "rootdir=%u"},
303 {Opt_iocharset
, "iocharset=%s"},
308 udf_parse_options(char *options
, struct udf_options
*uopt
)
314 uopt
->blocksize
= 2048;
315 uopt
->partition
= 0xFFFF;
316 uopt
->session
= 0xFFFFFFFF;
319 uopt
->volume
= 0xFFFFFFFF;
320 uopt
->rootdir
= 0xFFFFFFFF;
321 uopt
->fileset
= 0xFFFFFFFF;
322 uopt
->nls_map
= NULL
;
327 while ((p
= strsep(&options
, ",")) != NULL
) {
328 substring_t args
[MAX_OPT_ARGS
];
333 token
= match_token(p
, tokens
, args
);
339 if (match_int(&args
[0], &option
))
341 uopt
->blocksize
= option
;
344 uopt
->flags
|= (1 << UDF_FLAG_UNHIDE
);
347 uopt
->flags
|= (1 << UDF_FLAG_UNDELETE
);
350 uopt
->flags
&= ~(1 << UDF_FLAG_USE_AD_IN_ICB
);
353 uopt
->flags
|= (1 << UDF_FLAG_USE_AD_IN_ICB
);
356 uopt
->flags
|= (1 << UDF_FLAG_USE_SHORT_AD
);
359 uopt
->flags
&= ~(1 << UDF_FLAG_USE_SHORT_AD
);
362 if (match_int(args
, &option
))
367 if (match_int(args
, &option
))
372 if (match_octal(args
, &option
))
374 uopt
->umask
= option
;
377 uopt
->flags
&= ~(1 << UDF_FLAG_STRICT
);
380 if (match_int(args
, &option
))
382 uopt
->session
= option
;
385 if (match_int(args
, &option
))
387 uopt
->lastblock
= option
;
390 if (match_int(args
, &option
))
392 uopt
->anchor
= option
;
395 if (match_int(args
, &option
))
397 uopt
->volume
= option
;
400 if (match_int(args
, &option
))
402 uopt
->partition
= option
;
405 if (match_int(args
, &option
))
407 uopt
->fileset
= option
;
410 if (match_int(args
, &option
))
412 uopt
->rootdir
= option
;
415 uopt
->flags
|= (1 << UDF_FLAG_UTF8
);
417 #if defined(CONFIG_NLS) || defined(CONFIG_NLS_MODULE)
419 uopt
->nls_map
= load_nls(args
[0].from
);
420 uopt
->flags
|= (1 << UDF_FLAG_NLS_MAP
);
424 printk(KERN_ERR
"udf: bad mount option \"%s\" "
425 "or missing value\n",
434 udf_write_super(struct super_block
*sb
)
437 if (!(sb
->s_flags
& MS_RDONLY
))
444 udf_remount_fs(struct super_block
*sb
, int *flags
, char *options
)
446 struct udf_options uopt
;
448 uopt
.flags
= UDF_SB(sb
)->s_flags
;
449 uopt
.uid
= UDF_SB(sb
)->s_uid
;
450 uopt
.gid
= UDF_SB(sb
)->s_gid
;
451 uopt
.umask
= UDF_SB(sb
)->s_umask
;
453 if ( !udf_parse_options(options
, &uopt
) )
456 UDF_SB(sb
)->s_flags
= uopt
.flags
;
457 UDF_SB(sb
)->s_uid
= uopt
.uid
;
458 UDF_SB(sb
)->s_gid
= uopt
.gid
;
459 UDF_SB(sb
)->s_umask
= uopt
.umask
;
461 if ((*flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
))
463 if (*flags
& MS_RDONLY
)
475 * Set the block size to be used in all transfers.
478 * To allow room for a DMA transfer, it is best to guess big when unsure.
479 * This routine picks 2048 bytes as the blocksize when guessing. This
480 * should be adequate until devices with larger block sizes become common.
482 * Note that the Linux kernel can currently only deal with blocksizes of
483 * 512, 1024, 2048, 4096, and 8192 bytes.
486 * sb Pointer to _locked_ superblock.
489 * sb->s_blocksize Blocksize.
490 * sb->s_blocksize_bits log2 of blocksize.
491 * <return> 0 Blocksize is valid.
492 * <return> 1 Blocksize is invalid.
495 * July 1, 1997 - Andrew E. Mileski
496 * Written, tested, and released.
499 udf_set_blocksize(struct super_block
*sb
, int bsize
)
501 if (!sb_min_blocksize(sb
, bsize
)) {
502 udf_debug("Bad block size (%d)\n", bsize
);
503 printk(KERN_ERR
"udf: bad block size (%d)\n", bsize
);
506 return sb
->s_blocksize
;
510 udf_vrs(struct super_block
*sb
, int silent
)
512 struct volStructDesc
*vsd
= NULL
;
515 struct buffer_head
*bh
= NULL
;
520 /* Block size must be a multiple of 512 */
521 if (sb
->s_blocksize
& 511)
524 if (sb
->s_blocksize
< sizeof(struct volStructDesc
))
525 sectorsize
= sizeof(struct volStructDesc
);
527 sectorsize
= sb
->s_blocksize
;
529 sector
+= (UDF_SB_SESSION(sb
) << sb
->s_blocksize_bits
);
531 udf_debug("Starting at sector %u (%ld byte sectors)\n",
532 (sector
>> sb
->s_blocksize_bits
), sb
->s_blocksize
);
533 /* Process the sequence (if applicable) */
534 for (;!nsr02
&& !nsr03
; sector
+= sectorsize
)
537 bh
= udf_tread(sb
, sector
>> sb
->s_blocksize_bits
);
541 /* Look for ISO descriptors */
542 vsd
= (struct volStructDesc
*)(bh
->b_data
+
543 (sector
& (sb
->s_blocksize
- 1)));
545 if (vsd
->stdIdent
[0] == 0)
547 udf_release_data(bh
);
550 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_CD001
, VSD_STD_ID_LEN
))
553 switch (vsd
->structType
)
556 udf_debug("ISO9660 Boot Record found\n");
559 udf_debug("ISO9660 Primary Volume Descriptor found\n");
562 udf_debug("ISO9660 Supplementary Volume Descriptor found\n");
565 udf_debug("ISO9660 Volume Partition Descriptor found\n");
568 udf_debug("ISO9660 Volume Descriptor Set Terminator found\n");
571 udf_debug("ISO9660 VRS (%u) found\n", vsd
->structType
);
575 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_BEA01
, VSD_STD_ID_LEN
))
578 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_TEA01
, VSD_STD_ID_LEN
))
580 udf_release_data(bh
);
583 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR02
, VSD_STD_ID_LEN
))
587 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR03
, VSD_STD_ID_LEN
))
591 udf_release_data(bh
);
598 else if (sector
- (UDF_SB_SESSION(sb
) << sb
->s_blocksize_bits
) == 32768)
608 * Find an anchor volume descriptor.
611 * sb Pointer to _locked_ superblock.
612 * lastblock Last block on media.
615 * <return> 1 if not found, 0 if ok
618 * July 1, 1997 - Andrew E. Mileski
619 * Written, tested, and released.
622 udf_find_anchor(struct super_block
*sb
)
624 int lastblock
= UDF_SB_LASTBLOCK(sb
);
625 struct buffer_head
*bh
= NULL
;
632 int varlastblock
= udf_variable_to_fixed(lastblock
);
633 int last
[] = { lastblock
, lastblock
- 2,
634 lastblock
- 150, lastblock
- 152,
635 varlastblock
, varlastblock
- 2,
636 varlastblock
- 150, varlastblock
- 152 };
640 /* Search for an anchor volume descriptor pointer */
642 /* according to spec, anchor is in either:
646 * however, if the disc isn't closed, it could be 512 */
648 for (i
=0; (!lastblock
&& i
<sizeof(last
)/sizeof(int)); i
++)
650 if (last
[i
] < 0 || !(bh
= sb_bread(sb
, last
[i
])))
652 ident
= location
= 0;
656 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
657 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
658 udf_release_data(bh
);
661 if (ident
== TAG_IDENT_AVDP
)
663 if (location
== last
[i
] - UDF_SB_SESSION(sb
))
665 lastblock
= UDF_SB_ANCHOR(sb
)[0] = last
[i
] - UDF_SB_SESSION(sb
);
666 UDF_SB_ANCHOR(sb
)[1] = last
[i
] - 256 - UDF_SB_SESSION(sb
);
668 else if (location
== udf_variable_to_fixed(last
[i
]) - UDF_SB_SESSION(sb
))
670 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
671 lastblock
= UDF_SB_ANCHOR(sb
)[0] = udf_variable_to_fixed(last
[i
]) - UDF_SB_SESSION(sb
);
672 UDF_SB_ANCHOR(sb
)[1] = lastblock
- 256 - UDF_SB_SESSION(sb
);
675 udf_debug("Anchor found at block %d, location mismatch %d.\n",
678 else if (ident
== TAG_IDENT_FE
|| ident
== TAG_IDENT_EFE
)
681 UDF_SB_ANCHOR(sb
)[3] = 512;
685 if (last
[i
] < 256 || !(bh
= sb_bread(sb
, last
[i
] - 256)))
687 ident
= location
= 0;
691 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
692 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
693 udf_release_data(bh
);
696 if (ident
== TAG_IDENT_AVDP
&&
697 location
== last
[i
] - 256 - UDF_SB_SESSION(sb
))
700 UDF_SB_ANCHOR(sb
)[1] = last
[i
] - 256;
704 if (last
[i
] < 312 + UDF_SB_SESSION(sb
) || !(bh
= sb_bread(sb
, last
[i
] - 312 - UDF_SB_SESSION(sb
))))
706 ident
= location
= 0;
710 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
711 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
712 udf_release_data(bh
);
715 if (ident
== TAG_IDENT_AVDP
&&
716 location
== udf_variable_to_fixed(last
[i
]) - 256)
718 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
719 lastblock
= udf_variable_to_fixed(last
[i
]);
720 UDF_SB_ANCHOR(sb
)[1] = lastblock
- 256;
729 /* We havn't found the lastblock. check 312 */
730 if ((bh
= sb_bread(sb
, 312 + UDF_SB_SESSION(sb
))))
732 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
733 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
734 udf_release_data(bh
);
736 if (ident
== TAG_IDENT_AVDP
&& location
== 256)
737 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
741 for (i
=0; i
<sizeof(UDF_SB_ANCHOR(sb
))/sizeof(int); i
++)
743 if (UDF_SB_ANCHOR(sb
)[i
])
745 if (!(bh
= udf_read_tagged(sb
,
746 UDF_SB_ANCHOR(sb
)[i
], UDF_SB_ANCHOR(sb
)[i
], &ident
)))
748 UDF_SB_ANCHOR(sb
)[i
] = 0;
752 udf_release_data(bh
);
753 if ((ident
!= TAG_IDENT_AVDP
) && (i
||
754 (ident
!= TAG_IDENT_FE
&& ident
!= TAG_IDENT_EFE
)))
756 UDF_SB_ANCHOR(sb
)[i
] = 0;
762 UDF_SB_LASTBLOCK(sb
) = lastblock
;
766 udf_find_fileset(struct super_block
*sb
, lb_addr
*fileset
, lb_addr
*root
)
768 struct buffer_head
*bh
= NULL
;
772 if (fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
773 fileset
->partitionReferenceNum
!= 0xFFFF)
775 bh
= udf_read_ptagged(sb
, *fileset
, 0, &ident
);
779 else if (ident
!= TAG_IDENT_FSD
)
781 udf_release_data(bh
);
787 if (!bh
) /* Search backwards through the partitions */
793 for (newfileset
.partitionReferenceNum
=UDF_SB_NUMPARTS(sb
)-1;
794 (newfileset
.partitionReferenceNum
!= 0xFFFF &&
795 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
796 fileset
->partitionReferenceNum
== 0xFFFF);
797 newfileset
.partitionReferenceNum
--)
799 lastblock
= UDF_SB_PARTLEN(sb
, newfileset
.partitionReferenceNum
);
800 newfileset
.logicalBlockNum
= 0;
804 bh
= udf_read_ptagged(sb
, newfileset
, 0, &ident
);
807 newfileset
.logicalBlockNum
++;
815 struct spaceBitmapDesc
*sp
;
816 sp
= (struct spaceBitmapDesc
*)bh
->b_data
;
817 newfileset
.logicalBlockNum
+= 1 +
818 ((le32_to_cpu(sp
->numOfBytes
) + sizeof(struct spaceBitmapDesc
) - 1)
819 >> sb
->s_blocksize_bits
);
820 udf_release_data(bh
);
825 *fileset
= newfileset
;
830 newfileset
.logicalBlockNum
++;
831 udf_release_data(bh
);
837 while (newfileset
.logicalBlockNum
< lastblock
&&
838 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
839 fileset
->partitionReferenceNum
== 0xFFFF);
843 if ((fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
844 fileset
->partitionReferenceNum
!= 0xFFFF) && bh
)
846 udf_debug("Fileset at block=%d, partition=%d\n",
847 fileset
->logicalBlockNum
, fileset
->partitionReferenceNum
);
849 UDF_SB_PARTITION(sb
) = fileset
->partitionReferenceNum
;
850 udf_load_fileset(sb
, bh
, root
);
851 udf_release_data(bh
);
858 udf_load_pvoldesc(struct super_block
*sb
, struct buffer_head
*bh
)
860 struct primaryVolDesc
*pvoldesc
;
866 pvoldesc
= (struct primaryVolDesc
*)bh
->b_data
;
868 if ( udf_stamp_to_time(&recording
, &recording_usec
,
869 lets_to_cpu(pvoldesc
->recordingDateAndTime
)) )
872 ts
= lets_to_cpu(pvoldesc
->recordingDateAndTime
);
873 udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n",
874 recording
, recording_usec
,
875 ts
.year
, ts
.month
, ts
.day
, ts
.hour
, ts
.minute
, ts
.typeAndTimezone
);
876 UDF_SB_RECORDTIME(sb
).tv_sec
= recording
;
877 UDF_SB_RECORDTIME(sb
).tv_nsec
= recording_usec
* 1000;
880 if ( !udf_build_ustr(&instr
, pvoldesc
->volIdent
, 32) )
882 if (udf_CS0toUTF8(&outstr
, &instr
))
884 strncpy( UDF_SB_VOLIDENT(sb
), outstr
.u_name
,
885 outstr
.u_len
> 31 ? 31 : outstr
.u_len
);
886 udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb
));
890 if ( !udf_build_ustr(&instr
, pvoldesc
->volSetIdent
, 128) )
892 if (udf_CS0toUTF8(&outstr
, &instr
))
893 udf_debug("volSetIdent[] = '%s'\n", outstr
.u_name
);
898 udf_load_fileset(struct super_block
*sb
, struct buffer_head
*bh
, lb_addr
*root
)
900 struct fileSetDesc
*fset
;
902 fset
= (struct fileSetDesc
*)bh
->b_data
;
904 *root
= lelb_to_cpu(fset
->rootDirectoryICB
.extLocation
);
906 UDF_SB_SERIALNUM(sb
) = le16_to_cpu(fset
->descTag
.tagSerialNum
);
908 udf_debug("Rootdir at block=%d, partition=%d\n",
909 root
->logicalBlockNum
, root
->partitionReferenceNum
);
913 udf_load_partdesc(struct super_block
*sb
, struct buffer_head
*bh
)
915 struct partitionDesc
*p
;
918 p
= (struct partitionDesc
*)bh
->b_data
;
920 for (i
=0; i
<UDF_SB_NUMPARTS(sb
); i
++)
922 udf_debug("Searching map: (%d == %d)\n",
923 UDF_SB_PARTMAPS(sb
)[i
].s_partition_num
, le16_to_cpu(p
->partitionNumber
));
924 if (UDF_SB_PARTMAPS(sb
)[i
].s_partition_num
== le16_to_cpu(p
->partitionNumber
))
926 UDF_SB_PARTLEN(sb
,i
) = le32_to_cpu(p
->partitionLength
); /* blocks */
927 UDF_SB_PARTROOT(sb
,i
) = le32_to_cpu(p
->partitionStartingLocation
);
928 if (le32_to_cpu(p
->accessType
) == PD_ACCESS_TYPE_READ_ONLY
)
929 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_READ_ONLY
;
930 if (le32_to_cpu(p
->accessType
) == PD_ACCESS_TYPE_WRITE_ONCE
)
931 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_WRITE_ONCE
;
932 if (le32_to_cpu(p
->accessType
) == PD_ACCESS_TYPE_REWRITABLE
)
933 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_REWRITABLE
;
934 if (le32_to_cpu(p
->accessType
) == PD_ACCESS_TYPE_OVERWRITABLE
)
935 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_OVERWRITABLE
;
937 if (!strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR02
) ||
938 !strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR03
))
940 struct partitionHeaderDesc
*phd
;
942 phd
= (struct partitionHeaderDesc
*)(p
->partitionContentsUse
);
943 if (phd
->unallocSpaceTable
.extLength
)
945 lb_addr loc
= { le32_to_cpu(phd
->unallocSpaceTable
.extPosition
), i
};
947 UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_table
=
949 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_UNALLOC_TABLE
;
950 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
951 i
, UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_table
->i_ino
);
953 if (phd
->unallocSpaceBitmap
.extLength
)
955 UDF_SB_ALLOC_BITMAP(sb
, i
, s_uspace
);
956 if (UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_bitmap
!= NULL
)
958 UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_bitmap
->s_extLength
=
959 le32_to_cpu(phd
->unallocSpaceBitmap
.extLength
);
960 UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_bitmap
->s_extPosition
=
961 le32_to_cpu(phd
->unallocSpaceBitmap
.extPosition
);
962 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_UNALLOC_BITMAP
;
963 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
964 i
, UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_bitmap
->s_extPosition
);
967 if (phd
->partitionIntegrityTable
.extLength
)
968 udf_debug("partitionIntegrityTable (part %d)\n", i
);
969 if (phd
->freedSpaceTable
.extLength
)
971 lb_addr loc
= { le32_to_cpu(phd
->freedSpaceTable
.extPosition
), i
};
973 UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_table
=
975 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_FREED_TABLE
;
976 udf_debug("freedSpaceTable (part %d) @ %ld\n",
977 i
, UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_table
->i_ino
);
979 if (phd
->freedSpaceBitmap
.extLength
)
981 UDF_SB_ALLOC_BITMAP(sb
, i
, s_fspace
);
982 if (UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_bitmap
!= NULL
)
984 UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_bitmap
->s_extLength
=
985 le32_to_cpu(phd
->freedSpaceBitmap
.extLength
);
986 UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_bitmap
->s_extPosition
=
987 le32_to_cpu(phd
->freedSpaceBitmap
.extPosition
);
988 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_FREED_BITMAP
;
989 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
990 i
, UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_bitmap
->s_extPosition
);
997 if (i
== UDF_SB_NUMPARTS(sb
))
999 udf_debug("Partition (%d) not found in partition map\n", le16_to_cpu(p
->partitionNumber
));
1003 udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
1004 le16_to_cpu(p
->partitionNumber
), i
, UDF_SB_PARTTYPE(sb
,i
),
1005 UDF_SB_PARTROOT(sb
,i
), UDF_SB_PARTLEN(sb
,i
));
1010 udf_load_logicalvol(struct super_block
*sb
, struct buffer_head
* bh
, lb_addr
*fileset
)
1012 struct logicalVolDesc
*lvd
;
1016 lvd
= (struct logicalVolDesc
*)bh
->b_data
;
1018 UDF_SB_ALLOC_PARTMAPS(sb
, le32_to_cpu(lvd
->numPartitionMaps
));
1021 i
<UDF_SB_NUMPARTS(sb
) && offset
<le32_to_cpu(lvd
->mapTableLength
);
1022 i
++,offset
+=((struct genericPartitionMap
*)&(lvd
->partitionMaps
[offset
]))->partitionMapLength
)
1024 type
= ((struct genericPartitionMap
*)&(lvd
->partitionMaps
[offset
]))->partitionMapType
;
1027 struct genericPartitionMap1
*gpm1
= (struct genericPartitionMap1
*)&(lvd
->partitionMaps
[offset
]);
1028 UDF_SB_PARTTYPE(sb
,i
) = UDF_TYPE1_MAP15
;
1029 UDF_SB_PARTVSN(sb
,i
) = le16_to_cpu(gpm1
->volSeqNum
);
1030 UDF_SB_PARTNUM(sb
,i
) = le16_to_cpu(gpm1
->partitionNum
);
1031 UDF_SB_PARTFUNC(sb
,i
) = NULL
;
1035 struct udfPartitionMap2
*upm2
= (struct udfPartitionMap2
*)&(lvd
->partitionMaps
[offset
]);
1036 if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_VIRTUAL
, strlen(UDF_ID_VIRTUAL
)))
1038 if (le16_to_cpu(((uint16_t *)upm2
->partIdent
.identSuffix
)[0]) == 0x0150)
1040 UDF_SB_PARTTYPE(sb
,i
) = UDF_VIRTUAL_MAP15
;
1041 UDF_SB_PARTFUNC(sb
,i
) = udf_get_pblock_virt15
;
1043 else if (le16_to_cpu(((uint16_t *)upm2
->partIdent
.identSuffix
)[0]) == 0x0200)
1045 UDF_SB_PARTTYPE(sb
,i
) = UDF_VIRTUAL_MAP20
;
1046 UDF_SB_PARTFUNC(sb
,i
) = udf_get_pblock_virt20
;
1049 else if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_SPARABLE
, strlen(UDF_ID_SPARABLE
)))
1053 struct sparingTable
*st
;
1054 struct sparablePartitionMap
*spm
= (struct sparablePartitionMap
*)&(lvd
->partitionMaps
[offset
]);
1056 UDF_SB_PARTTYPE(sb
,i
) = UDF_SPARABLE_MAP15
;
1057 UDF_SB_TYPESPAR(sb
,i
).s_packet_len
= le16_to_cpu(spm
->packetLength
);
1058 for (j
=0; j
<spm
->numSparingTables
; j
++)
1060 loc
= le32_to_cpu(spm
->locSparingTable
[j
]);
1061 UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
] =
1062 udf_read_tagged(sb
, loc
, loc
, &ident
);
1063 if (UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
] != NULL
)
1065 st
= (struct sparingTable
*)UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
]->b_data
;
1067 strncmp(st
->sparingIdent
.ident
, UDF_ID_SPARING
, strlen(UDF_ID_SPARING
)))
1069 udf_release_data(UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
]);
1070 UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
] = NULL
;
1074 UDF_SB_PARTFUNC(sb
,i
) = udf_get_pblock_spar15
;
1078 udf_debug("Unknown ident: %s\n", upm2
->partIdent
.ident
);
1081 UDF_SB_PARTVSN(sb
,i
) = le16_to_cpu(upm2
->volSeqNum
);
1082 UDF_SB_PARTNUM(sb
,i
) = le16_to_cpu(upm2
->partitionNum
);
1084 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1085 i
, UDF_SB_PARTNUM(sb
,i
), type
, UDF_SB_PARTVSN(sb
,i
));
1090 long_ad
*la
= (long_ad
*)&(lvd
->logicalVolContentsUse
[0]);
1092 *fileset
= lelb_to_cpu(la
->extLocation
);
1093 udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
1094 fileset
->logicalBlockNum
,
1095 fileset
->partitionReferenceNum
);
1097 if (lvd
->integritySeqExt
.extLength
)
1098 udf_load_logicalvolint(sb
, leea_to_cpu(lvd
->integritySeqExt
));
1103 * udf_load_logicalvolint
1107 udf_load_logicalvolint(struct super_block
*sb
, extent_ad loc
)
1109 struct buffer_head
*bh
= NULL
;
1112 while (loc
.extLength
> 0 &&
1113 (bh
= udf_read_tagged(sb
, loc
.extLocation
,
1114 loc
.extLocation
, &ident
)) &&
1115 ident
== TAG_IDENT_LVID
)
1117 UDF_SB_LVIDBH(sb
) = bh
;
1119 if (UDF_SB_LVID(sb
)->nextIntegrityExt
.extLength
)
1120 udf_load_logicalvolint(sb
, leea_to_cpu(UDF_SB_LVID(sb
)->nextIntegrityExt
));
1122 if (UDF_SB_LVIDBH(sb
) != bh
)
1123 udf_release_data(bh
);
1124 loc
.extLength
-= sb
->s_blocksize
;
1127 if (UDF_SB_LVIDBH(sb
) != bh
)
1128 udf_release_data(bh
);
1132 * udf_process_sequence
1135 * Process a main/reserve volume descriptor sequence.
1138 * sb Pointer to _locked_ superblock.
1139 * block First block of first extent of the sequence.
1140 * lastblock Lastblock of first extent of the sequence.
1143 * July 1, 1997 - Andrew E. Mileski
1144 * Written, tested, and released.
1147 udf_process_sequence(struct super_block
*sb
, long block
, long lastblock
, lb_addr
*fileset
)
1149 struct buffer_head
*bh
= NULL
;
1150 struct udf_vds_record vds
[VDS_POS_LENGTH
];
1151 struct generic_desc
*gd
;
1152 struct volDescPtr
*vdp
;
1157 long next_s
= 0, next_e
= 0;
1159 memset(vds
, 0, sizeof(struct udf_vds_record
) * VDS_POS_LENGTH
);
1161 /* Read the main descriptor sequence */
1162 for (;(!done
&& block
<= lastblock
); block
++)
1165 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1169 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1170 gd
= (struct generic_desc
*)bh
->b_data
;
1171 vdsn
= le32_to_cpu(gd
->volDescSeqNum
);
1174 case TAG_IDENT_PVD
: /* ISO 13346 3/10.1 */
1175 if (vdsn
>= vds
[VDS_POS_PRIMARY_VOL_DESC
].volDescSeqNum
)
1177 vds
[VDS_POS_PRIMARY_VOL_DESC
].volDescSeqNum
= vdsn
;
1178 vds
[VDS_POS_PRIMARY_VOL_DESC
].block
= block
;
1181 case TAG_IDENT_VDP
: /* ISO 13346 3/10.3 */
1182 if (vdsn
>= vds
[VDS_POS_VOL_DESC_PTR
].volDescSeqNum
)
1184 vds
[VDS_POS_VOL_DESC_PTR
].volDescSeqNum
= vdsn
;
1185 vds
[VDS_POS_VOL_DESC_PTR
].block
= block
;
1187 vdp
= (struct volDescPtr
*)bh
->b_data
;
1188 next_s
= le32_to_cpu(vdp
->nextVolDescSeqExt
.extLocation
);
1189 next_e
= le32_to_cpu(vdp
->nextVolDescSeqExt
.extLength
);
1190 next_e
= next_e
>> sb
->s_blocksize_bits
;
1194 case TAG_IDENT_IUVD
: /* ISO 13346 3/10.4 */
1195 if (vdsn
>= vds
[VDS_POS_IMP_USE_VOL_DESC
].volDescSeqNum
)
1197 vds
[VDS_POS_IMP_USE_VOL_DESC
].volDescSeqNum
= vdsn
;
1198 vds
[VDS_POS_IMP_USE_VOL_DESC
].block
= block
;
1201 case TAG_IDENT_PD
: /* ISO 13346 3/10.5 */
1202 if (!vds
[VDS_POS_PARTITION_DESC
].block
)
1203 vds
[VDS_POS_PARTITION_DESC
].block
= block
;
1205 case TAG_IDENT_LVD
: /* ISO 13346 3/10.6 */
1206 if (vdsn
>= vds
[VDS_POS_LOGICAL_VOL_DESC
].volDescSeqNum
)
1208 vds
[VDS_POS_LOGICAL_VOL_DESC
].volDescSeqNum
= vdsn
;
1209 vds
[VDS_POS_LOGICAL_VOL_DESC
].block
= block
;
1212 case TAG_IDENT_USD
: /* ISO 13346 3/10.8 */
1213 if (vdsn
>= vds
[VDS_POS_UNALLOC_SPACE_DESC
].volDescSeqNum
)
1215 vds
[VDS_POS_UNALLOC_SPACE_DESC
].volDescSeqNum
= vdsn
;
1216 vds
[VDS_POS_UNALLOC_SPACE_DESC
].block
= block
;
1219 case TAG_IDENT_TD
: /* ISO 13346 3/10.9 */
1220 vds
[VDS_POS_TERMINATING_DESC
].block
= block
;
1225 next_s
= next_e
= 0;
1231 udf_release_data(bh
);
1233 for (i
=0; i
<VDS_POS_LENGTH
; i
++)
1237 bh
= udf_read_tagged(sb
, vds
[i
].block
, vds
[i
].block
, &ident
);
1239 if (i
== VDS_POS_PRIMARY_VOL_DESC
)
1240 udf_load_pvoldesc(sb
, bh
);
1241 else if (i
== VDS_POS_LOGICAL_VOL_DESC
)
1242 udf_load_logicalvol(sb
, bh
, fileset
);
1243 else if (i
== VDS_POS_PARTITION_DESC
)
1245 struct buffer_head
*bh2
= NULL
;
1246 udf_load_partdesc(sb
, bh
);
1247 for (j
=vds
[i
].block
+1; j
<vds
[VDS_POS_TERMINATING_DESC
].block
; j
++)
1249 bh2
= udf_read_tagged(sb
, j
, j
, &ident
);
1250 gd
= (struct generic_desc
*)bh2
->b_data
;
1251 if (ident
== TAG_IDENT_PD
)
1252 udf_load_partdesc(sb
, bh2
);
1253 udf_release_data(bh2
);
1256 udf_release_data(bh
);
1267 udf_check_valid(struct super_block
*sb
, int novrs
, int silent
)
1273 udf_debug("Validity check skipped because of novrs option\n");
1276 /* Check that it is NSR02 compliant */
1277 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1278 else if ((block
= udf_vrs(sb
, silent
)) == -1)
1280 udf_debug("Failed to read byte 32768. Assuming open disc. Skipping validity check\n");
1281 if (!UDF_SB_LASTBLOCK(sb
))
1282 UDF_SB_LASTBLOCK(sb
) = udf_get_last_block(sb
);
1290 udf_load_partition(struct super_block
*sb
, lb_addr
*fileset
)
1292 struct anchorVolDescPtr
*anchor
;
1294 struct buffer_head
*bh
;
1295 long main_s
, main_e
, reserve_s
, reserve_e
;
1301 for (i
=0; i
<sizeof(UDF_SB_ANCHOR(sb
))/sizeof(int); i
++)
1303 if (UDF_SB_ANCHOR(sb
)[i
] && (bh
= udf_read_tagged(sb
,
1304 UDF_SB_ANCHOR(sb
)[i
], UDF_SB_ANCHOR(sb
)[i
], &ident
)))
1306 anchor
= (struct anchorVolDescPtr
*)bh
->b_data
;
1308 /* Locate the main sequence */
1309 main_s
= le32_to_cpu( anchor
->mainVolDescSeqExt
.extLocation
);
1310 main_e
= le32_to_cpu( anchor
->mainVolDescSeqExt
.extLength
);
1311 main_e
= main_e
>> sb
->s_blocksize_bits
;
1314 /* Locate the reserve sequence */
1315 reserve_s
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLocation
);
1316 reserve_e
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLength
);
1317 reserve_e
= reserve_e
>> sb
->s_blocksize_bits
;
1318 reserve_e
+= reserve_s
;
1320 udf_release_data(bh
);
1322 /* Process the main & reserve sequences */
1323 /* responsible for finding the PartitionDesc(s) */
1324 if (!(udf_process_sequence(sb
, main_s
, main_e
, fileset
) &&
1325 udf_process_sequence(sb
, reserve_s
, reserve_e
, fileset
)))
1332 if (i
== sizeof(UDF_SB_ANCHOR(sb
))/sizeof(int))
1334 udf_debug("No Anchor block found\n");
1338 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb
)[i
]);
1340 for (i
=0; i
<UDF_SB_NUMPARTS(sb
); i
++)
1342 switch UDF_SB_PARTTYPE(sb
, i
)
1344 case UDF_VIRTUAL_MAP15
:
1345 case UDF_VIRTUAL_MAP20
:
1349 if (!UDF_SB_LASTBLOCK(sb
))
1351 UDF_SB_LASTBLOCK(sb
) = udf_get_last_block(sb
);
1352 udf_find_anchor(sb
);
1355 if (!UDF_SB_LASTBLOCK(sb
))
1357 udf_debug("Unable to determine Lastblock (For Virtual Partition)\n");
1361 for (j
=0; j
<UDF_SB_NUMPARTS(sb
); j
++)
1364 UDF_SB_PARTVSN(sb
,i
) == UDF_SB_PARTVSN(sb
,j
) &&
1365 UDF_SB_PARTNUM(sb
,i
) == UDF_SB_PARTNUM(sb
,j
))
1367 ino
.partitionReferenceNum
= j
;
1368 ino
.logicalBlockNum
= UDF_SB_LASTBLOCK(sb
) -
1369 UDF_SB_PARTROOT(sb
,j
);
1374 if (j
== UDF_SB_NUMPARTS(sb
))
1377 if (!(UDF_SB_VAT(sb
) = udf_iget(sb
, ino
)))
1380 if (UDF_SB_PARTTYPE(sb
,i
) == UDF_VIRTUAL_MAP15
)
1382 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
= udf_ext0_offset(UDF_SB_VAT(sb
));
1383 UDF_SB_TYPEVIRT(sb
,i
).s_num_entries
= (UDF_SB_VAT(sb
)->i_size
- 36) >> 2;
1385 else if (UDF_SB_PARTTYPE(sb
,i
) == UDF_VIRTUAL_MAP20
)
1387 struct buffer_head
*bh
= NULL
;
1390 pos
= udf_block_map(UDF_SB_VAT(sb
), 0);
1391 bh
= sb_bread(sb
, pos
);
1392 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
=
1393 le16_to_cpu(((struct virtualAllocationTable20
*)bh
->b_data
+ udf_ext0_offset(UDF_SB_VAT(sb
)))->lengthHeader
) +
1394 udf_ext0_offset(UDF_SB_VAT(sb
));
1395 UDF_SB_TYPEVIRT(sb
,i
).s_num_entries
= (UDF_SB_VAT(sb
)->i_size
-
1396 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
) >> 2;
1397 udf_release_data(bh
);
1399 UDF_SB_PARTROOT(sb
,i
) = udf_get_pblock(sb
, 0, i
, 0);
1400 UDF_SB_PARTLEN(sb
,i
) = UDF_SB_PARTLEN(sb
,ino
.partitionReferenceNum
);
1407 static void udf_open_lvid(struct super_block
*sb
)
1409 if (UDF_SB_LVIDBH(sb
))
1414 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1415 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1416 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
))
1417 UDF_SB_LVID(sb
)->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1418 UDF_SB_LVID(sb
)->integrityType
= LVID_INTEGRITY_TYPE_OPEN
;
1420 UDF_SB_LVID(sb
)->descTag
.descCRC
=
1421 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb
) + sizeof(tag
),
1422 le16_to_cpu(UDF_SB_LVID(sb
)->descTag
.descCRCLength
), 0));
1424 UDF_SB_LVID(sb
)->descTag
.tagChecksum
= 0;
1425 for (i
=0; i
<16; i
++)
1427 UDF_SB_LVID(sb
)->descTag
.tagChecksum
+=
1428 ((uint8_t *)&(UDF_SB_LVID(sb
)->descTag
))[i
];
1430 mark_buffer_dirty(UDF_SB_LVIDBH(sb
));
1434 static void udf_close_lvid(struct super_block
*sb
)
1436 if (UDF_SB_LVIDBH(sb
) &&
1437 UDF_SB_LVID(sb
)->integrityType
== LVID_INTEGRITY_TYPE_OPEN
)
1442 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1443 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1444 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
))
1445 UDF_SB_LVID(sb
)->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1446 if (UDF_MAX_WRITE_VERSION
> le16_to_cpu(UDF_SB_LVIDIU(sb
)->maxUDFWriteRev
))
1447 UDF_SB_LVIDIU(sb
)->maxUDFWriteRev
= cpu_to_le16(UDF_MAX_WRITE_VERSION
);
1448 if (UDF_SB_UDFREV(sb
) > le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFReadRev
))
1449 UDF_SB_LVIDIU(sb
)->minUDFReadRev
= cpu_to_le16(UDF_SB_UDFREV(sb
));
1450 if (UDF_SB_UDFREV(sb
) > le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFWriteRev
))
1451 UDF_SB_LVIDIU(sb
)->minUDFWriteRev
= cpu_to_le16(UDF_SB_UDFREV(sb
));
1452 UDF_SB_LVID(sb
)->integrityType
= LVID_INTEGRITY_TYPE_CLOSE
;
1454 UDF_SB_LVID(sb
)->descTag
.descCRC
=
1455 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb
) + sizeof(tag
),
1456 le16_to_cpu(UDF_SB_LVID(sb
)->descTag
.descCRCLength
), 0));
1458 UDF_SB_LVID(sb
)->descTag
.tagChecksum
= 0;
1459 for (i
=0; i
<16; i
++)
1461 UDF_SB_LVID(sb
)->descTag
.tagChecksum
+=
1462 ((uint8_t *)&(UDF_SB_LVID(sb
)->descTag
))[i
];
1464 mark_buffer_dirty(UDF_SB_LVIDBH(sb
));
1472 * Complete the specified super block.
1475 * sb Pointer to superblock to complete - never NULL.
1476 * sb->s_dev Device to read suberblock from.
1477 * options Pointer to mount options.
1478 * silent Silent flag.
1481 * July 1, 1997 - Andrew E. Mileski
1482 * Written, tested, and released.
1484 static int udf_fill_super(struct super_block
*sb
, void *options
, int silent
)
1487 struct inode
*inode
=NULL
;
1488 struct udf_options uopt
;
1489 lb_addr rootdir
, fileset
;
1490 struct udf_sb_info
*sbi
;
1492 uopt
.flags
= (1 << UDF_FLAG_USE_AD_IN_ICB
) | (1 << UDF_FLAG_STRICT
);
1497 sbi
= kmalloc(sizeof(struct udf_sb_info
), GFP_KERNEL
);
1500 sb
->s_fs_info
= sbi
;
1501 memset(UDF_SB(sb
), 0x00, sizeof(struct udf_sb_info
));
1503 if (!udf_parse_options((char *)options
, &uopt
))
1506 if (uopt
.flags
& (1 << UDF_FLAG_UTF8
) &&
1507 uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
))
1509 udf_error(sb
, "udf_read_super",
1510 "utf8 cannot be combined with iocharset\n");
1513 #if defined(CONFIG_NLS) || defined(CONFIG_NLS_MODULE)
1514 if ((uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) && !uopt
.nls_map
)
1516 uopt
.nls_map
= load_nls_default();
1518 uopt
.flags
&= ~(1 << UDF_FLAG_NLS_MAP
);
1520 udf_debug("Using default NLS map\n");
1523 if (!(uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)))
1524 uopt
.flags
|= (1 << UDF_FLAG_UTF8
);
1526 fileset
.logicalBlockNum
= 0xFFFFFFFF;
1527 fileset
.partitionReferenceNum
= 0xFFFF;
1529 UDF_SB(sb
)->s_flags
= uopt
.flags
;
1530 UDF_SB(sb
)->s_uid
= uopt
.uid
;
1531 UDF_SB(sb
)->s_gid
= uopt
.gid
;
1532 UDF_SB(sb
)->s_umask
= uopt
.umask
;
1533 UDF_SB(sb
)->s_nls_map
= uopt
.nls_map
;
1535 /* Set the block size for all transfers */
1536 if (!udf_set_blocksize(sb
, uopt
.blocksize
))
1539 if ( uopt
.session
== 0xFFFFFFFF )
1540 UDF_SB_SESSION(sb
) = udf_get_last_session(sb
);
1542 UDF_SB_SESSION(sb
) = uopt
.session
;
1544 udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb
));
1546 UDF_SB_LASTBLOCK(sb
) = uopt
.lastblock
;
1547 UDF_SB_ANCHOR(sb
)[0] = UDF_SB_ANCHOR(sb
)[1] = 0;
1548 UDF_SB_ANCHOR(sb
)[2] = uopt
.anchor
;
1549 UDF_SB_ANCHOR(sb
)[3] = 256;
1551 if (udf_check_valid(sb
, uopt
.novrs
, silent
)) /* read volume recognition sequences */
1553 printk("UDF-fs: No VRS found\n");
1557 udf_find_anchor(sb
);
1559 /* Fill in the rest of the superblock */
1560 sb
->s_op
= &udf_sb_ops
;
1563 sb
->s_magic
= UDF_SUPER_MAGIC
;
1565 if (udf_load_partition(sb
, &fileset
))
1567 printk("UDF-fs: No partition found (1)\n");
1571 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb
));
1573 if ( UDF_SB_LVIDBH(sb
) )
1575 uint16_t minUDFReadRev
= le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFReadRev
);
1576 uint16_t minUDFWriteRev
= le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFWriteRev
);
1577 /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */
1579 if (minUDFReadRev
> UDF_MAX_READ_VERSION
)
1581 printk("UDF-fs: minUDFReadRev=%x (max is %x)\n",
1582 UDF_SB_LVIDIU(sb
)->minUDFReadRev
, UDF_MAX_READ_VERSION
);
1585 else if (minUDFWriteRev
> UDF_MAX_WRITE_VERSION
)
1587 sb
->s_flags
|= MS_RDONLY
;
1590 UDF_SB_UDFREV(sb
) = minUDFWriteRev
;
1592 if (minUDFReadRev
>= UDF_VERS_USE_EXTENDED_FE
)
1593 UDF_SET_FLAG(sb
, UDF_FLAG_USE_EXTENDED_FE
);
1594 if (minUDFReadRev
>= UDF_VERS_USE_STREAMS
)
1595 UDF_SET_FLAG(sb
, UDF_FLAG_USE_STREAMS
);
1598 if ( !UDF_SB_NUMPARTS(sb
) )
1600 printk("UDF-fs: No partition found (2)\n");
1604 if ( udf_find_fileset(sb
, &fileset
, &rootdir
) )
1606 printk("UDF-fs: No fileset found\n");
1613 udf_time_to_stamp(&ts
, UDF_SB_RECORDTIME(sb
));
1614 udf_info("UDF %s (%s) Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1615 UDFFS_VERSION
, UDFFS_DATE
,
1616 UDF_SB_VOLIDENT(sb
), ts
.year
, ts
.month
, ts
.day
, ts
.hour
, ts
.minute
,
1617 ts
.typeAndTimezone
);
1619 if (!(sb
->s_flags
& MS_RDONLY
))
1622 /* Assign the root inode */
1623 /* assign inodes by physical block number */
1624 /* perhaps it's not extensible enough, but for now ... */
1625 inode
= udf_iget(sb
, rootdir
);
1628 printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n",
1629 rootdir
.logicalBlockNum
, rootdir
.partitionReferenceNum
);
1633 /* Allocate a dentry for the root inode */
1634 sb
->s_root
= d_alloc_root(inode
);
1637 printk("UDF-fs: Couldn't allocate root dentry\n");
1641 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
1646 iput(UDF_SB_VAT(sb
));
1647 if (UDF_SB_NUMPARTS(sb
))
1649 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_TABLE
)
1650 iput(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_table
);
1651 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_TABLE
)
1652 iput(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_table
);
1653 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_BITMAP
)
1655 for (i
=0; i
<UDF_SB_BITMAP_NR_GROUPS(sb
,UDF_SB_PARTITION(sb
),s_uspace
); i
++)
1657 if (UDF_SB_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_uspace
,i
))
1658 udf_release_data(UDF_SB_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_uspace
,i
));
1660 kfree(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_bitmap
);
1662 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_BITMAP
)
1664 for (i
=0; i
<UDF_SB_BITMAP_NR_GROUPS(sb
,UDF_SB_PARTITION(sb
),s_fspace
); i
++)
1666 if (UDF_SB_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_fspace
,i
))
1667 udf_release_data(UDF_SB_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_fspace
,i
));
1669 kfree(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_bitmap
);
1671 if (UDF_SB_PARTTYPE(sb
, UDF_SB_PARTITION(sb
)) == UDF_SPARABLE_MAP15
)
1674 udf_release_data(UDF_SB_TYPESPAR(sb
, UDF_SB_PARTITION(sb
)).s_spar_map
[i
]);
1677 #if defined(CONFIG_NLS) || defined(CONFIG_NLS_MODULE)
1678 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
1679 unload_nls(UDF_SB(sb
)->s_nls_map
);
1681 if (!(sb
->s_flags
& MS_RDONLY
))
1683 udf_release_data(UDF_SB_LVIDBH(sb
));
1686 sb
->s_fs_info
= NULL
;
1690 void udf_error(struct super_block
*sb
, const char *function
,
1691 const char *fmt
, ...)
1695 if (!(sb
->s_flags
& MS_RDONLY
))
1700 va_start(args
, fmt
);
1701 vsprintf(error_buf
, fmt
, args
);
1703 printk (KERN_CRIT
"UDF-fs error (device %s): %s: %s\n",
1704 sb
->s_id
, function
, error_buf
);
1707 void udf_warning(struct super_block
*sb
, const char *function
,
1708 const char *fmt
, ...)
1712 va_start (args
, fmt
);
1713 vsprintf(error_buf
, fmt
, args
);
1715 printk(KERN_WARNING
"UDF-fs warning (device %s): %s: %s\n",
1716 sb
->s_id
, function
, error_buf
);
1723 * Prepare for destruction of the superblock.
1726 * Called before the filesystem is unmounted.
1729 * July 1, 1997 - Andrew E. Mileski
1730 * Written, tested, and released.
1733 udf_put_super(struct super_block
*sb
)
1738 iput(UDF_SB_VAT(sb
));
1739 if (UDF_SB_NUMPARTS(sb
))
1741 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_TABLE
)
1742 iput(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_table
);
1743 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_TABLE
)
1744 iput(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_table
);
1745 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_BITMAP
)
1747 for (i
=0; i
<UDF_SB_BITMAP_NR_GROUPS(sb
,UDF_SB_PARTITION(sb
),s_uspace
); i
++)
1749 if (UDF_SB_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_uspace
,i
))
1750 udf_release_data(UDF_SB_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_uspace
,i
));
1752 kfree(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_bitmap
);
1754 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_BITMAP
)
1756 for (i
=0; i
<UDF_SB_BITMAP_NR_GROUPS(sb
,UDF_SB_PARTITION(sb
),s_fspace
); i
++)
1758 if (UDF_SB_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_fspace
,i
))
1759 udf_release_data(UDF_SB_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_fspace
,i
));
1761 kfree(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_bitmap
);
1763 if (UDF_SB_PARTTYPE(sb
, UDF_SB_PARTITION(sb
)) == UDF_SPARABLE_MAP15
)
1766 udf_release_data(UDF_SB_TYPESPAR(sb
, UDF_SB_PARTITION(sb
)).s_spar_map
[i
]);
1769 #if defined(CONFIG_NLS) || defined(CONFIG_NLS_MODULE)
1770 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
1771 unload_nls(UDF_SB(sb
)->s_nls_map
);
1773 if (!(sb
->s_flags
& MS_RDONLY
))
1775 udf_release_data(UDF_SB_LVIDBH(sb
));
1777 kfree(sb
->s_fs_info
);
1778 sb
->s_fs_info
= NULL
;
1785 * Return info about the filesystem.
1788 * Called by sys_statfs()
1791 * July 1, 1997 - Andrew E. Mileski
1792 * Written, tested, and released.
1795 udf_statfs(struct super_block
*sb
, struct kstatfs
*buf
)
1797 buf
->f_type
= UDF_SUPER_MAGIC
;
1798 buf
->f_bsize
= sb
->s_blocksize
;
1799 buf
->f_blocks
= UDF_SB_PARTLEN(sb
, UDF_SB_PARTITION(sb
));
1800 buf
->f_bfree
= udf_count_free(sb
);
1801 buf
->f_bavail
= buf
->f_bfree
;
1802 buf
->f_files
= (UDF_SB_LVIDBH(sb
) ?
1803 (le32_to_cpu(UDF_SB_LVIDIU(sb
)->numFiles
) +
1804 le32_to_cpu(UDF_SB_LVIDIU(sb
)->numDirs
)) : 0) + buf
->f_bfree
;
1805 buf
->f_ffree
= buf
->f_bfree
;
1806 /* __kernel_fsid_t f_fsid */
1807 buf
->f_namelen
= UDF_NAME_LEN
;
1812 static unsigned char udf_bitmap_lookup
[16] = {
1813 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
1817 udf_count_free_bitmap(struct super_block
*sb
, struct udf_bitmap
*bitmap
)
1819 struct buffer_head
*bh
= NULL
;
1820 unsigned int accum
= 0;
1822 int block
= 0, newblock
;
1828 struct spaceBitmapDesc
*bm
;
1832 loc
.logicalBlockNum
= bitmap
->s_extPosition
;
1833 loc
.partitionReferenceNum
= UDF_SB_PARTITION(sb
);
1834 bh
= udf_read_ptagged(sb
, loc
, 0, &ident
);
1838 printk(KERN_ERR
"udf: udf_count_free failed\n");
1841 else if (ident
!= TAG_IDENT_SBD
)
1843 udf_release_data(bh
);
1844 printk(KERN_ERR
"udf: udf_count_free failed\n");
1848 bm
= (struct spaceBitmapDesc
*)bh
->b_data
;
1849 bytes
= bm
->numOfBytes
;
1850 index
= sizeof(struct spaceBitmapDesc
); /* offset in first block only */
1851 ptr
= (uint8_t *)bh
->b_data
;
1855 while ((bytes
> 0) && (index
< sb
->s_blocksize
))
1858 accum
+= udf_bitmap_lookup
[ value
& 0x0f ];
1859 accum
+= udf_bitmap_lookup
[ value
>> 4 ];
1865 udf_release_data(bh
);
1866 newblock
= udf_get_lb_pblock(sb
, loc
, ++block
);
1867 bh
= udf_tread(sb
, newblock
);
1870 udf_debug("read failed\n");
1874 ptr
= (uint8_t *)bh
->b_data
;
1877 udf_release_data(bh
);
1886 udf_count_free_table(struct super_block
*sb
, struct inode
* table
)
1888 unsigned int accum
= 0;
1889 uint32_t extoffset
, elen
;
1892 struct buffer_head
*bh
= NULL
;
1896 bloc
= UDF_I_LOCATION(table
);
1897 extoffset
= sizeof(struct unallocSpaceEntry
);
1899 while ((etype
= udf_next_aext(table
, &bloc
, &extoffset
, &eloc
, &elen
, &bh
, 1)) != -1)
1901 accum
+= (elen
>> table
->i_sb
->s_blocksize_bits
);
1903 udf_release_data(bh
);
1911 udf_count_free(struct super_block
*sb
)
1913 unsigned int accum
= 0;
1915 if (UDF_SB_LVIDBH(sb
))
1917 if (le32_to_cpu(UDF_SB_LVID(sb
)->numOfPartitions
) > UDF_SB_PARTITION(sb
))
1919 accum
= le32_to_cpu(UDF_SB_LVID(sb
)->freeSpaceTable
[UDF_SB_PARTITION(sb
)]);
1921 if (accum
== 0xFFFFFFFF)
1929 if (UDF_SB_PARTFLAGS(sb
,UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_BITMAP
)
1931 accum
+= udf_count_free_bitmap(sb
,
1932 UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_bitmap
);
1934 if (UDF_SB_PARTFLAGS(sb
,UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_BITMAP
)
1936 accum
+= udf_count_free_bitmap(sb
,
1937 UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_bitmap
);
1942 if (UDF_SB_PARTFLAGS(sb
,UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_TABLE
)
1944 accum
+= udf_count_free_table(sb
,
1945 UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_table
);
1947 if (UDF_SB_PARTFLAGS(sb
,UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_TABLE
)
1949 accum
+= udf_count_free_table(sb
,
1950 UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_table
);