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-2004 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 <linux/vmalloc.h>
61 #include <asm/byteorder.h>
63 #include <linux/udf_fs.h>
67 #include <linux/init.h>
68 #include <asm/uaccess.h>
70 #define VDS_POS_PRIMARY_VOL_DESC 0
71 #define VDS_POS_UNALLOC_SPACE_DESC 1
72 #define VDS_POS_LOGICAL_VOL_DESC 2
73 #define VDS_POS_PARTITION_DESC 3
74 #define VDS_POS_IMP_USE_VOL_DESC 4
75 #define VDS_POS_VOL_DESC_PTR 5
76 #define VDS_POS_TERMINATING_DESC 6
77 #define VDS_POS_LENGTH 7
79 static char error_buf
[1024];
81 /* These are the "meat" - everything else is stuffing */
82 static int udf_fill_super(struct super_block
*, void *, int);
83 static void udf_put_super(struct super_block
*);
84 static void udf_write_super(struct super_block
*);
85 static int udf_remount_fs(struct super_block
*, int *, char *);
86 static int udf_check_valid(struct super_block
*, int, int);
87 static int udf_vrs(struct super_block
*sb
, int silent
);
88 static int udf_load_partition(struct super_block
*, kernel_lb_addr
*);
89 static int udf_load_logicalvol(struct super_block
*, struct buffer_head
*, kernel_lb_addr
*);
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
*, kernel_lb_addr
*);
93 static void udf_load_pvoldesc(struct super_block
*, struct buffer_head
*);
94 static void udf_load_fileset(struct super_block
*, struct buffer_head
*, kernel_lb_addr
*);
95 static void udf_load_partdesc(struct super_block
*, struct buffer_head
*);
96 static void udf_open_lvid(struct super_block
*);
97 static void udf_close_lvid(struct super_block
*);
98 static unsigned int udf_count_free(struct super_block
*);
99 static int udf_statfs(struct super_block
*, struct kstatfs
*);
101 /* UDF filesystem type */
102 static struct super_block
*udf_get_sb(struct file_system_type
*fs_type
,
103 int flags
, const char *dev_name
, void *data
)
105 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, udf_fill_super
);
108 static struct file_system_type udf_fstype
= {
109 .owner
= THIS_MODULE
,
111 .get_sb
= udf_get_sb
,
112 .kill_sb
= kill_block_super
,
113 .fs_flags
= FS_REQUIRES_DEV
,
116 static kmem_cache_t
* udf_inode_cachep
;
118 static struct inode
*udf_alloc_inode(struct super_block
*sb
)
120 struct udf_inode_info
*ei
;
121 ei
= (struct udf_inode_info
*)kmem_cache_alloc(udf_inode_cachep
, SLAB_KERNEL
);
124 return &ei
->vfs_inode
;
127 static void udf_destroy_inode(struct inode
*inode
)
129 kmem_cache_free(udf_inode_cachep
, UDF_I(inode
));
132 static void init_once(void * foo
, kmem_cache_t
* cachep
, unsigned long flags
)
134 struct udf_inode_info
*ei
= (struct udf_inode_info
*) foo
;
136 if ((flags
& (SLAB_CTOR_VERIFY
|SLAB_CTOR_CONSTRUCTOR
)) ==
137 SLAB_CTOR_CONSTRUCTOR
)
139 ei
->i_ext
.i_data
= NULL
;
140 inode_init_once(&ei
->vfs_inode
);
144 static int init_inodecache(void)
146 udf_inode_cachep
= kmem_cache_create("udf_inode_cache",
147 sizeof(struct udf_inode_info
),
148 0, SLAB_RECLAIM_ACCOUNT
,
150 if (udf_inode_cachep
== NULL
)
155 static void destroy_inodecache(void)
157 if (kmem_cache_destroy(udf_inode_cachep
))
158 printk(KERN_INFO
"udf_inode_cache: not all structures were freed\n");
161 /* Superblock operations */
162 static struct super_operations udf_sb_ops
= {
163 .alloc_inode
= udf_alloc_inode
,
164 .destroy_inode
= udf_destroy_inode
,
165 .write_inode
= udf_write_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 err
= init_inodecache();
198 err
= register_filesystem(&udf_fstype
);
203 destroy_inodecache();
208 static void __exit
exit_udf_fs(void)
210 unregister_filesystem(&udf_fstype
);
211 destroy_inodecache();
214 module_init(init_udf_fs
)
215 module_exit(exit_udf_fs
)
221 * Parse mount options.
224 * The following mount options are supported:
226 * gid= Set the default group.
227 * umask= Set the default umask.
228 * uid= Set the default user.
229 * bs= Set the block size.
230 * unhide Show otherwise hidden files.
231 * undelete Show deleted files in lists.
232 * adinicb Embed data in the inode (default)
233 * noadinicb Don't embed data in the inode
234 * shortad Use short ad's
235 * longad Use long ad's (default)
236 * nostrict Unset strict conformance
237 * iocharset= Set the NLS character set
239 * The remaining are for debugging and disaster recovery:
241 * novrs Skip volume sequence recognition
243 * The following expect a offset from 0.
245 * session= Set the CDROM session (default= last session)
246 * anchor= Override standard anchor location. (default= 256)
247 * volume= Override the VolumeDesc location. (unused)
248 * partition= Override the PartitionDesc location. (unused)
249 * lastblock= Set the last block of the filesystem/
251 * The following expect a offset from the partition root.
253 * fileset= Override the fileset block location. (unused)
254 * rootdir= Override the root directory location. (unused)
255 * WARNING: overriding the rootdir to a non-directory may
256 * yield highly unpredictable results.
259 * options Pointer to mount options string.
260 * uopts Pointer to mount options variable.
263 * <return> 1 Mount options parsed okay.
264 * <return> 0 Error parsing mount options.
267 * July 1, 1997 - Andrew E. Mileski
268 * Written, tested, and released.
272 Opt_novrs
, Opt_nostrict
, Opt_bs
, Opt_unhide
, Opt_undelete
,
273 Opt_noadinicb
, Opt_adinicb
, Opt_shortad
, Opt_longad
,
274 Opt_gid
, Opt_uid
, Opt_umask
, Opt_session
, Opt_lastblock
,
275 Opt_anchor
, Opt_volume
, Opt_partition
, Opt_fileset
,
276 Opt_rootdir
, Opt_utf8
, Opt_iocharset
,
280 static match_table_t tokens
= {
281 {Opt_novrs
, "novrs"},
282 {Opt_nostrict
, "nostrict"},
284 {Opt_unhide
, "unhide"},
285 {Opt_undelete
, "undelete"},
286 {Opt_noadinicb
, "noadinicb"},
287 {Opt_adinicb
, "adinicb"},
288 {Opt_shortad
, "shortad"},
289 {Opt_longad
, "longad"},
292 {Opt_umask
, "umask=%o"},
293 {Opt_session
, "session=%u"},
294 {Opt_lastblock
, "lastblock=%u"},
295 {Opt_anchor
, "anchor=%u"},
296 {Opt_volume
, "volume=%u"},
297 {Opt_partition
, "partition=%u"},
298 {Opt_fileset
, "fileset=%u"},
299 {Opt_rootdir
, "rootdir=%u"},
301 {Opt_iocharset
, "iocharset=%s"},
306 udf_parse_options(char *options
, struct udf_options
*uopt
)
312 uopt
->blocksize
= 2048;
313 uopt
->partition
= 0xFFFF;
314 uopt
->session
= 0xFFFFFFFF;
317 uopt
->volume
= 0xFFFFFFFF;
318 uopt
->rootdir
= 0xFFFFFFFF;
319 uopt
->fileset
= 0xFFFFFFFF;
320 uopt
->nls_map
= NULL
;
325 while ((p
= strsep(&options
, ",")) != NULL
)
327 substring_t args
[MAX_OPT_ARGS
];
332 token
= match_token(p
, tokens
, args
);
338 if (match_int(&args
[0], &option
))
340 uopt
->blocksize
= option
;
343 uopt
->flags
|= (1 << UDF_FLAG_UNHIDE
);
346 uopt
->flags
|= (1 << UDF_FLAG_UNDELETE
);
349 uopt
->flags
&= ~(1 << UDF_FLAG_USE_AD_IN_ICB
);
352 uopt
->flags
|= (1 << UDF_FLAG_USE_AD_IN_ICB
);
355 uopt
->flags
|= (1 << UDF_FLAG_USE_SHORT_AD
);
358 uopt
->flags
&= ~(1 << UDF_FLAG_USE_SHORT_AD
);
361 if (match_int(args
, &option
))
366 if (match_int(args
, &option
))
371 if (match_octal(args
, &option
))
373 uopt
->umask
= option
;
376 uopt
->flags
&= ~(1 << UDF_FLAG_STRICT
);
379 if (match_int(args
, &option
))
381 uopt
->session
= option
;
384 if (match_int(args
, &option
))
386 uopt
->lastblock
= option
;
389 if (match_int(args
, &option
))
391 uopt
->anchor
= option
;
394 if (match_int(args
, &option
))
396 uopt
->volume
= option
;
399 if (match_int(args
, &option
))
401 uopt
->partition
= option
;
404 if (match_int(args
, &option
))
406 uopt
->fileset
= option
;
409 if (match_int(args
, &option
))
411 uopt
->rootdir
= option
;
414 uopt
->flags
|= (1 << UDF_FLAG_UTF8
);
416 #ifdef CONFIG_UDF_NLS
418 uopt
->nls_map
= load_nls(args
[0].from
);
419 uopt
->flags
|= (1 << UDF_FLAG_NLS_MAP
);
423 printk(KERN_ERR
"udf: bad mount option \"%s\" "
424 "or missing value\n", p
);
432 udf_write_super(struct super_block
*sb
)
435 if (!(sb
->s_flags
& MS_RDONLY
))
442 udf_remount_fs(struct super_block
*sb
, int *flags
, char *options
)
444 struct udf_options uopt
;
446 uopt
.flags
= UDF_SB(sb
)->s_flags
;
447 uopt
.uid
= UDF_SB(sb
)->s_uid
;
448 uopt
.gid
= UDF_SB(sb
)->s_gid
;
449 uopt
.umask
= UDF_SB(sb
)->s_umask
;
451 if ( !udf_parse_options(options
, &uopt
) )
454 UDF_SB(sb
)->s_flags
= uopt
.flags
;
455 UDF_SB(sb
)->s_uid
= uopt
.uid
;
456 UDF_SB(sb
)->s_gid
= uopt
.gid
;
457 UDF_SB(sb
)->s_umask
= uopt
.umask
;
459 if (UDF_SB_LVIDBH(sb
)) {
460 int write_rev
= le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFWriteRev
);
461 if (write_rev
> UDF_MAX_WRITE_VERSION
)
465 if ((*flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
))
467 if (*flags
& MS_RDONLY
)
479 * Set the block size to be used in all transfers.
482 * To allow room for a DMA transfer, it is best to guess big when unsure.
483 * This routine picks 2048 bytes as the blocksize when guessing. This
484 * should be adequate until devices with larger block sizes become common.
486 * Note that the Linux kernel can currently only deal with blocksizes of
487 * 512, 1024, 2048, 4096, and 8192 bytes.
490 * sb Pointer to _locked_ superblock.
493 * sb->s_blocksize Blocksize.
494 * sb->s_blocksize_bits log2 of blocksize.
495 * <return> 0 Blocksize is valid.
496 * <return> 1 Blocksize is invalid.
499 * July 1, 1997 - Andrew E. Mileski
500 * Written, tested, and released.
503 udf_set_blocksize(struct super_block
*sb
, int bsize
)
505 if (!sb_min_blocksize(sb
, bsize
)) {
506 udf_debug("Bad block size (%d)\n", bsize
);
507 printk(KERN_ERR
"udf: bad block size (%d)\n", bsize
);
510 return sb
->s_blocksize
;
514 udf_vrs(struct super_block
*sb
, int silent
)
516 struct volStructDesc
*vsd
= NULL
;
519 struct buffer_head
*bh
= NULL
;
524 /* Block size must be a multiple of 512 */
525 if (sb
->s_blocksize
& 511)
528 if (sb
->s_blocksize
< sizeof(struct volStructDesc
))
529 sectorsize
= sizeof(struct volStructDesc
);
531 sectorsize
= sb
->s_blocksize
;
533 sector
+= (UDF_SB_SESSION(sb
) << sb
->s_blocksize_bits
);
535 udf_debug("Starting at sector %u (%ld byte sectors)\n",
536 (sector
>> sb
->s_blocksize_bits
), sb
->s_blocksize
);
537 /* Process the sequence (if applicable) */
538 for (;!nsr02
&& !nsr03
; sector
+= sectorsize
)
541 bh
= udf_tread(sb
, sector
>> sb
->s_blocksize_bits
);
545 /* Look for ISO descriptors */
546 vsd
= (struct volStructDesc
*)(bh
->b_data
+
547 (sector
& (sb
->s_blocksize
- 1)));
549 if (vsd
->stdIdent
[0] == 0)
551 udf_release_data(bh
);
554 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_CD001
, VSD_STD_ID_LEN
))
557 switch (vsd
->structType
)
560 udf_debug("ISO9660 Boot Record found\n");
563 udf_debug("ISO9660 Primary Volume Descriptor found\n");
566 udf_debug("ISO9660 Supplementary Volume Descriptor found\n");
569 udf_debug("ISO9660 Volume Partition Descriptor found\n");
572 udf_debug("ISO9660 Volume Descriptor Set Terminator found\n");
575 udf_debug("ISO9660 VRS (%u) found\n", vsd
->structType
);
579 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_BEA01
, VSD_STD_ID_LEN
))
582 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_TEA01
, VSD_STD_ID_LEN
))
584 udf_release_data(bh
);
587 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR02
, VSD_STD_ID_LEN
))
591 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR03
, VSD_STD_ID_LEN
))
595 udf_release_data(bh
);
602 else if (sector
- (UDF_SB_SESSION(sb
) << sb
->s_blocksize_bits
) == 32768)
612 * Find an anchor volume descriptor.
615 * sb Pointer to _locked_ superblock.
616 * lastblock Last block on media.
619 * <return> 1 if not found, 0 if ok
622 * July 1, 1997 - Andrew E. Mileski
623 * Written, tested, and released.
626 udf_find_anchor(struct super_block
*sb
)
628 int lastblock
= UDF_SB_LASTBLOCK(sb
);
629 struct buffer_head
*bh
= NULL
;
636 int varlastblock
= udf_variable_to_fixed(lastblock
);
637 int last
[] = { lastblock
, lastblock
- 2,
638 lastblock
- 150, lastblock
- 152,
639 varlastblock
, varlastblock
- 2,
640 varlastblock
- 150, varlastblock
- 152 };
644 /* Search for an anchor volume descriptor pointer */
646 /* according to spec, anchor is in either:
650 * however, if the disc isn't closed, it could be 512 */
652 for (i
=0; (!lastblock
&& i
<sizeof(last
)/sizeof(int)); i
++)
654 if (last
[i
] < 0 || !(bh
= sb_bread(sb
, last
[i
])))
656 ident
= location
= 0;
660 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
661 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
662 udf_release_data(bh
);
665 if (ident
== TAG_IDENT_AVDP
)
667 if (location
== last
[i
] - UDF_SB_SESSION(sb
))
669 lastblock
= UDF_SB_ANCHOR(sb
)[0] = last
[i
] - UDF_SB_SESSION(sb
);
670 UDF_SB_ANCHOR(sb
)[1] = last
[i
] - 256 - UDF_SB_SESSION(sb
);
672 else if (location
== udf_variable_to_fixed(last
[i
]) - UDF_SB_SESSION(sb
))
674 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
675 lastblock
= UDF_SB_ANCHOR(sb
)[0] = udf_variable_to_fixed(last
[i
]) - UDF_SB_SESSION(sb
);
676 UDF_SB_ANCHOR(sb
)[1] = lastblock
- 256 - UDF_SB_SESSION(sb
);
679 udf_debug("Anchor found at block %d, location mismatch %d.\n",
682 else if (ident
== TAG_IDENT_FE
|| ident
== TAG_IDENT_EFE
)
685 UDF_SB_ANCHOR(sb
)[3] = 512;
689 if (last
[i
] < 256 || !(bh
= sb_bread(sb
, last
[i
] - 256)))
691 ident
= location
= 0;
695 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
696 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
697 udf_release_data(bh
);
700 if (ident
== TAG_IDENT_AVDP
&&
701 location
== last
[i
] - 256 - UDF_SB_SESSION(sb
))
704 UDF_SB_ANCHOR(sb
)[1] = last
[i
] - 256;
708 if (last
[i
] < 312 + UDF_SB_SESSION(sb
) || !(bh
= sb_bread(sb
, last
[i
] - 312 - UDF_SB_SESSION(sb
))))
710 ident
= location
= 0;
714 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
715 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
716 udf_release_data(bh
);
719 if (ident
== TAG_IDENT_AVDP
&&
720 location
== udf_variable_to_fixed(last
[i
]) - 256)
722 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
723 lastblock
= udf_variable_to_fixed(last
[i
]);
724 UDF_SB_ANCHOR(sb
)[1] = lastblock
- 256;
733 /* We havn't found the lastblock. check 312 */
734 if ((bh
= sb_bread(sb
, 312 + UDF_SB_SESSION(sb
))))
736 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
737 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
738 udf_release_data(bh
);
740 if (ident
== TAG_IDENT_AVDP
&& location
== 256)
741 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
745 for (i
=0; i
<sizeof(UDF_SB_ANCHOR(sb
))/sizeof(int); i
++)
747 if (UDF_SB_ANCHOR(sb
)[i
])
749 if (!(bh
= udf_read_tagged(sb
,
750 UDF_SB_ANCHOR(sb
)[i
], UDF_SB_ANCHOR(sb
)[i
], &ident
)))
752 UDF_SB_ANCHOR(sb
)[i
] = 0;
756 udf_release_data(bh
);
757 if ((ident
!= TAG_IDENT_AVDP
) && (i
||
758 (ident
!= TAG_IDENT_FE
&& ident
!= TAG_IDENT_EFE
)))
760 UDF_SB_ANCHOR(sb
)[i
] = 0;
766 UDF_SB_LASTBLOCK(sb
) = lastblock
;
770 udf_find_fileset(struct super_block
*sb
, kernel_lb_addr
*fileset
, kernel_lb_addr
*root
)
772 struct buffer_head
*bh
= NULL
;
776 if (fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
777 fileset
->partitionReferenceNum
!= 0xFFFF)
779 bh
= udf_read_ptagged(sb
, *fileset
, 0, &ident
);
783 else if (ident
!= TAG_IDENT_FSD
)
785 udf_release_data(bh
);
791 if (!bh
) /* Search backwards through the partitions */
793 kernel_lb_addr newfileset
;
797 for (newfileset
.partitionReferenceNum
=UDF_SB_NUMPARTS(sb
)-1;
798 (newfileset
.partitionReferenceNum
!= 0xFFFF &&
799 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
800 fileset
->partitionReferenceNum
== 0xFFFF);
801 newfileset
.partitionReferenceNum
--)
803 lastblock
= UDF_SB_PARTLEN(sb
, newfileset
.partitionReferenceNum
);
804 newfileset
.logicalBlockNum
= 0;
808 bh
= udf_read_ptagged(sb
, newfileset
, 0, &ident
);
811 newfileset
.logicalBlockNum
++;
819 struct spaceBitmapDesc
*sp
;
820 sp
= (struct spaceBitmapDesc
*)bh
->b_data
;
821 newfileset
.logicalBlockNum
+= 1 +
822 ((le32_to_cpu(sp
->numOfBytes
) + sizeof(struct spaceBitmapDesc
) - 1)
823 >> sb
->s_blocksize_bits
);
824 udf_release_data(bh
);
829 *fileset
= newfileset
;
834 newfileset
.logicalBlockNum
++;
835 udf_release_data(bh
);
841 while (newfileset
.logicalBlockNum
< lastblock
&&
842 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
843 fileset
->partitionReferenceNum
== 0xFFFF);
847 if ((fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
848 fileset
->partitionReferenceNum
!= 0xFFFF) && bh
)
850 udf_debug("Fileset at block=%d, partition=%d\n",
851 fileset
->logicalBlockNum
, fileset
->partitionReferenceNum
);
853 UDF_SB_PARTITION(sb
) = fileset
->partitionReferenceNum
;
854 udf_load_fileset(sb
, bh
, root
);
855 udf_release_data(bh
);
862 udf_load_pvoldesc(struct super_block
*sb
, struct buffer_head
*bh
)
864 struct primaryVolDesc
*pvoldesc
;
870 pvoldesc
= (struct primaryVolDesc
*)bh
->b_data
;
872 if ( udf_stamp_to_time(&recording
, &recording_usec
,
873 lets_to_cpu(pvoldesc
->recordingDateAndTime
)) )
876 ts
= lets_to_cpu(pvoldesc
->recordingDateAndTime
);
877 udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n",
878 recording
, recording_usec
,
879 ts
.year
, ts
.month
, ts
.day
, ts
.hour
, ts
.minute
, ts
.typeAndTimezone
);
880 UDF_SB_RECORDTIME(sb
).tv_sec
= recording
;
881 UDF_SB_RECORDTIME(sb
).tv_nsec
= recording_usec
* 1000;
884 if ( !udf_build_ustr(&instr
, pvoldesc
->volIdent
, 32) )
886 if (udf_CS0toUTF8(&outstr
, &instr
))
888 strncpy( UDF_SB_VOLIDENT(sb
), outstr
.u_name
,
889 outstr
.u_len
> 31 ? 31 : outstr
.u_len
);
890 udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb
));
894 if ( !udf_build_ustr(&instr
, pvoldesc
->volSetIdent
, 128) )
896 if (udf_CS0toUTF8(&outstr
, &instr
))
897 udf_debug("volSetIdent[] = '%s'\n", outstr
.u_name
);
902 udf_load_fileset(struct super_block
*sb
, struct buffer_head
*bh
, kernel_lb_addr
*root
)
904 struct fileSetDesc
*fset
;
906 fset
= (struct fileSetDesc
*)bh
->b_data
;
908 *root
= lelb_to_cpu(fset
->rootDirectoryICB
.extLocation
);
910 UDF_SB_SERIALNUM(sb
) = le16_to_cpu(fset
->descTag
.tagSerialNum
);
912 udf_debug("Rootdir at block=%d, partition=%d\n",
913 root
->logicalBlockNum
, root
->partitionReferenceNum
);
917 udf_load_partdesc(struct super_block
*sb
, struct buffer_head
*bh
)
919 struct partitionDesc
*p
;
922 p
= (struct partitionDesc
*)bh
->b_data
;
924 for (i
=0; i
<UDF_SB_NUMPARTS(sb
); i
++)
926 udf_debug("Searching map: (%d == %d)\n",
927 UDF_SB_PARTMAPS(sb
)[i
].s_partition_num
, le16_to_cpu(p
->partitionNumber
));
928 if (UDF_SB_PARTMAPS(sb
)[i
].s_partition_num
== le16_to_cpu(p
->partitionNumber
))
930 UDF_SB_PARTLEN(sb
,i
) = le32_to_cpu(p
->partitionLength
); /* blocks */
931 UDF_SB_PARTROOT(sb
,i
) = le32_to_cpu(p
->partitionStartingLocation
);
932 if (le32_to_cpu(p
->accessType
) == PD_ACCESS_TYPE_READ_ONLY
)
933 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_READ_ONLY
;
934 if (le32_to_cpu(p
->accessType
) == PD_ACCESS_TYPE_WRITE_ONCE
)
935 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_WRITE_ONCE
;
936 if (le32_to_cpu(p
->accessType
) == PD_ACCESS_TYPE_REWRITABLE
)
937 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_REWRITABLE
;
938 if (le32_to_cpu(p
->accessType
) == PD_ACCESS_TYPE_OVERWRITABLE
)
939 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_OVERWRITABLE
;
941 if (!strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR02
) ||
942 !strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR03
))
944 struct partitionHeaderDesc
*phd
;
946 phd
= (struct partitionHeaderDesc
*)(p
->partitionContentsUse
);
947 if (phd
->unallocSpaceTable
.extLength
)
949 kernel_lb_addr loc
= { le32_to_cpu(phd
->unallocSpaceTable
.extPosition
), i
};
951 UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_table
=
953 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_UNALLOC_TABLE
;
954 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
955 i
, UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_table
->i_ino
);
957 if (phd
->unallocSpaceBitmap
.extLength
)
959 UDF_SB_ALLOC_BITMAP(sb
, i
, s_uspace
);
960 if (UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_bitmap
!= NULL
)
962 UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_bitmap
->s_extLength
=
963 le32_to_cpu(phd
->unallocSpaceBitmap
.extLength
);
964 UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_bitmap
->s_extPosition
=
965 le32_to_cpu(phd
->unallocSpaceBitmap
.extPosition
);
966 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_UNALLOC_BITMAP
;
967 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
968 i
, UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_bitmap
->s_extPosition
);
971 if (phd
->partitionIntegrityTable
.extLength
)
972 udf_debug("partitionIntegrityTable (part %d)\n", i
);
973 if (phd
->freedSpaceTable
.extLength
)
975 kernel_lb_addr loc
= { le32_to_cpu(phd
->freedSpaceTable
.extPosition
), i
};
977 UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_table
=
979 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_FREED_TABLE
;
980 udf_debug("freedSpaceTable (part %d) @ %ld\n",
981 i
, UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_table
->i_ino
);
983 if (phd
->freedSpaceBitmap
.extLength
)
985 UDF_SB_ALLOC_BITMAP(sb
, i
, s_fspace
);
986 if (UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_bitmap
!= NULL
)
988 UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_bitmap
->s_extLength
=
989 le32_to_cpu(phd
->freedSpaceBitmap
.extLength
);
990 UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_bitmap
->s_extPosition
=
991 le32_to_cpu(phd
->freedSpaceBitmap
.extPosition
);
992 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_FREED_BITMAP
;
993 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
994 i
, UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_bitmap
->s_extPosition
);
1001 if (i
== UDF_SB_NUMPARTS(sb
))
1003 udf_debug("Partition (%d) not found in partition map\n", le16_to_cpu(p
->partitionNumber
));
1007 udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
1008 le16_to_cpu(p
->partitionNumber
), i
, UDF_SB_PARTTYPE(sb
,i
),
1009 UDF_SB_PARTROOT(sb
,i
), UDF_SB_PARTLEN(sb
,i
));
1014 udf_load_logicalvol(struct super_block
*sb
, struct buffer_head
* bh
, kernel_lb_addr
*fileset
)
1016 struct logicalVolDesc
*lvd
;
1020 lvd
= (struct logicalVolDesc
*)bh
->b_data
;
1022 UDF_SB_ALLOC_PARTMAPS(sb
, le32_to_cpu(lvd
->numPartitionMaps
));
1025 i
<UDF_SB_NUMPARTS(sb
) && offset
<le32_to_cpu(lvd
->mapTableLength
);
1026 i
++,offset
+=((struct genericPartitionMap
*)&(lvd
->partitionMaps
[offset
]))->partitionMapLength
)
1028 type
= ((struct genericPartitionMap
*)&(lvd
->partitionMaps
[offset
]))->partitionMapType
;
1031 struct genericPartitionMap1
*gpm1
= (struct genericPartitionMap1
*)&(lvd
->partitionMaps
[offset
]);
1032 UDF_SB_PARTTYPE(sb
,i
) = UDF_TYPE1_MAP15
;
1033 UDF_SB_PARTVSN(sb
,i
) = le16_to_cpu(gpm1
->volSeqNum
);
1034 UDF_SB_PARTNUM(sb
,i
) = le16_to_cpu(gpm1
->partitionNum
);
1035 UDF_SB_PARTFUNC(sb
,i
) = NULL
;
1039 struct udfPartitionMap2
*upm2
= (struct udfPartitionMap2
*)&(lvd
->partitionMaps
[offset
]);
1040 if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_VIRTUAL
, strlen(UDF_ID_VIRTUAL
)))
1042 if (le16_to_cpu(((__le16
*)upm2
->partIdent
.identSuffix
)[0]) == 0x0150)
1044 UDF_SB_PARTTYPE(sb
,i
) = UDF_VIRTUAL_MAP15
;
1045 UDF_SB_PARTFUNC(sb
,i
) = udf_get_pblock_virt15
;
1047 else if (le16_to_cpu(((__le16
*)upm2
->partIdent
.identSuffix
)[0]) == 0x0200)
1049 UDF_SB_PARTTYPE(sb
,i
) = UDF_VIRTUAL_MAP20
;
1050 UDF_SB_PARTFUNC(sb
,i
) = udf_get_pblock_virt20
;
1053 else if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_SPARABLE
, strlen(UDF_ID_SPARABLE
)))
1057 struct sparingTable
*st
;
1058 struct sparablePartitionMap
*spm
= (struct sparablePartitionMap
*)&(lvd
->partitionMaps
[offset
]);
1060 UDF_SB_PARTTYPE(sb
,i
) = UDF_SPARABLE_MAP15
;
1061 UDF_SB_TYPESPAR(sb
,i
).s_packet_len
= le16_to_cpu(spm
->packetLength
);
1062 for (j
=0; j
<spm
->numSparingTables
; j
++)
1064 loc
= le32_to_cpu(spm
->locSparingTable
[j
]);
1065 UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
] =
1066 udf_read_tagged(sb
, loc
, loc
, &ident
);
1067 if (UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
] != NULL
)
1069 st
= (struct sparingTable
*)UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
]->b_data
;
1071 strncmp(st
->sparingIdent
.ident
, UDF_ID_SPARING
, strlen(UDF_ID_SPARING
)))
1073 udf_release_data(UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
]);
1074 UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
] = NULL
;
1078 UDF_SB_PARTFUNC(sb
,i
) = udf_get_pblock_spar15
;
1082 udf_debug("Unknown ident: %s\n", upm2
->partIdent
.ident
);
1085 UDF_SB_PARTVSN(sb
,i
) = le16_to_cpu(upm2
->volSeqNum
);
1086 UDF_SB_PARTNUM(sb
,i
) = le16_to_cpu(upm2
->partitionNum
);
1088 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1089 i
, UDF_SB_PARTNUM(sb
,i
), type
, UDF_SB_PARTVSN(sb
,i
));
1094 long_ad
*la
= (long_ad
*)&(lvd
->logicalVolContentsUse
[0]);
1096 *fileset
= lelb_to_cpu(la
->extLocation
);
1097 udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
1098 fileset
->logicalBlockNum
,
1099 fileset
->partitionReferenceNum
);
1101 if (lvd
->integritySeqExt
.extLength
)
1102 udf_load_logicalvolint(sb
, leea_to_cpu(lvd
->integritySeqExt
));
1107 * udf_load_logicalvolint
1111 udf_load_logicalvolint(struct super_block
*sb
, kernel_extent_ad loc
)
1113 struct buffer_head
*bh
= NULL
;
1116 while (loc
.extLength
> 0 &&
1117 (bh
= udf_read_tagged(sb
, loc
.extLocation
,
1118 loc
.extLocation
, &ident
)) &&
1119 ident
== TAG_IDENT_LVID
)
1121 UDF_SB_LVIDBH(sb
) = bh
;
1123 if (UDF_SB_LVID(sb
)->nextIntegrityExt
.extLength
)
1124 udf_load_logicalvolint(sb
, leea_to_cpu(UDF_SB_LVID(sb
)->nextIntegrityExt
));
1126 if (UDF_SB_LVIDBH(sb
) != bh
)
1127 udf_release_data(bh
);
1128 loc
.extLength
-= sb
->s_blocksize
;
1131 if (UDF_SB_LVIDBH(sb
) != bh
)
1132 udf_release_data(bh
);
1136 * udf_process_sequence
1139 * Process a main/reserve volume descriptor sequence.
1142 * sb Pointer to _locked_ superblock.
1143 * block First block of first extent of the sequence.
1144 * lastblock Lastblock of first extent of the sequence.
1147 * July 1, 1997 - Andrew E. Mileski
1148 * Written, tested, and released.
1151 udf_process_sequence(struct super_block
*sb
, long block
, long lastblock
, kernel_lb_addr
*fileset
)
1153 struct buffer_head
*bh
= NULL
;
1154 struct udf_vds_record vds
[VDS_POS_LENGTH
];
1155 struct generic_desc
*gd
;
1156 struct volDescPtr
*vdp
;
1161 long next_s
= 0, next_e
= 0;
1163 memset(vds
, 0, sizeof(struct udf_vds_record
) * VDS_POS_LENGTH
);
1165 /* Read the main descriptor sequence */
1166 for (;(!done
&& block
<= lastblock
); block
++)
1169 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1173 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1174 gd
= (struct generic_desc
*)bh
->b_data
;
1175 vdsn
= le32_to_cpu(gd
->volDescSeqNum
);
1178 case TAG_IDENT_PVD
: /* ISO 13346 3/10.1 */
1179 if (vdsn
>= vds
[VDS_POS_PRIMARY_VOL_DESC
].volDescSeqNum
)
1181 vds
[VDS_POS_PRIMARY_VOL_DESC
].volDescSeqNum
= vdsn
;
1182 vds
[VDS_POS_PRIMARY_VOL_DESC
].block
= block
;
1185 case TAG_IDENT_VDP
: /* ISO 13346 3/10.3 */
1186 if (vdsn
>= vds
[VDS_POS_VOL_DESC_PTR
].volDescSeqNum
)
1188 vds
[VDS_POS_VOL_DESC_PTR
].volDescSeqNum
= vdsn
;
1189 vds
[VDS_POS_VOL_DESC_PTR
].block
= block
;
1191 vdp
= (struct volDescPtr
*)bh
->b_data
;
1192 next_s
= le32_to_cpu(vdp
->nextVolDescSeqExt
.extLocation
);
1193 next_e
= le32_to_cpu(vdp
->nextVolDescSeqExt
.extLength
);
1194 next_e
= next_e
>> sb
->s_blocksize_bits
;
1198 case TAG_IDENT_IUVD
: /* ISO 13346 3/10.4 */
1199 if (vdsn
>= vds
[VDS_POS_IMP_USE_VOL_DESC
].volDescSeqNum
)
1201 vds
[VDS_POS_IMP_USE_VOL_DESC
].volDescSeqNum
= vdsn
;
1202 vds
[VDS_POS_IMP_USE_VOL_DESC
].block
= block
;
1205 case TAG_IDENT_PD
: /* ISO 13346 3/10.5 */
1206 if (!vds
[VDS_POS_PARTITION_DESC
].block
)
1207 vds
[VDS_POS_PARTITION_DESC
].block
= block
;
1209 case TAG_IDENT_LVD
: /* ISO 13346 3/10.6 */
1210 if (vdsn
>= vds
[VDS_POS_LOGICAL_VOL_DESC
].volDescSeqNum
)
1212 vds
[VDS_POS_LOGICAL_VOL_DESC
].volDescSeqNum
= vdsn
;
1213 vds
[VDS_POS_LOGICAL_VOL_DESC
].block
= block
;
1216 case TAG_IDENT_USD
: /* ISO 13346 3/10.8 */
1217 if (vdsn
>= vds
[VDS_POS_UNALLOC_SPACE_DESC
].volDescSeqNum
)
1219 vds
[VDS_POS_UNALLOC_SPACE_DESC
].volDescSeqNum
= vdsn
;
1220 vds
[VDS_POS_UNALLOC_SPACE_DESC
].block
= block
;
1223 case TAG_IDENT_TD
: /* ISO 13346 3/10.9 */
1224 vds
[VDS_POS_TERMINATING_DESC
].block
= block
;
1229 next_s
= next_e
= 0;
1235 udf_release_data(bh
);
1237 for (i
=0; i
<VDS_POS_LENGTH
; i
++)
1241 bh
= udf_read_tagged(sb
, vds
[i
].block
, vds
[i
].block
, &ident
);
1243 if (i
== VDS_POS_PRIMARY_VOL_DESC
)
1244 udf_load_pvoldesc(sb
, bh
);
1245 else if (i
== VDS_POS_LOGICAL_VOL_DESC
)
1246 udf_load_logicalvol(sb
, bh
, fileset
);
1247 else if (i
== VDS_POS_PARTITION_DESC
)
1249 struct buffer_head
*bh2
= NULL
;
1250 udf_load_partdesc(sb
, bh
);
1251 for (j
=vds
[i
].block
+1; j
<vds
[VDS_POS_TERMINATING_DESC
].block
; j
++)
1253 bh2
= udf_read_tagged(sb
, j
, j
, &ident
);
1254 gd
= (struct generic_desc
*)bh2
->b_data
;
1255 if (ident
== TAG_IDENT_PD
)
1256 udf_load_partdesc(sb
, bh2
);
1257 udf_release_data(bh2
);
1260 udf_release_data(bh
);
1271 udf_check_valid(struct super_block
*sb
, int novrs
, int silent
)
1277 udf_debug("Validity check skipped because of novrs option\n");
1280 /* Check that it is NSR02 compliant */
1281 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1282 else if ((block
= udf_vrs(sb
, silent
)) == -1)
1284 udf_debug("Failed to read byte 32768. Assuming open disc. Skipping validity check\n");
1285 if (!UDF_SB_LASTBLOCK(sb
))
1286 UDF_SB_LASTBLOCK(sb
) = udf_get_last_block(sb
);
1294 udf_load_partition(struct super_block
*sb
, kernel_lb_addr
*fileset
)
1296 struct anchorVolDescPtr
*anchor
;
1298 struct buffer_head
*bh
;
1299 long main_s
, main_e
, reserve_s
, reserve_e
;
1305 for (i
=0; i
<sizeof(UDF_SB_ANCHOR(sb
))/sizeof(int); i
++)
1307 if (UDF_SB_ANCHOR(sb
)[i
] && (bh
= udf_read_tagged(sb
,
1308 UDF_SB_ANCHOR(sb
)[i
], UDF_SB_ANCHOR(sb
)[i
], &ident
)))
1310 anchor
= (struct anchorVolDescPtr
*)bh
->b_data
;
1312 /* Locate the main sequence */
1313 main_s
= le32_to_cpu( anchor
->mainVolDescSeqExt
.extLocation
);
1314 main_e
= le32_to_cpu( anchor
->mainVolDescSeqExt
.extLength
);
1315 main_e
= main_e
>> sb
->s_blocksize_bits
;
1318 /* Locate the reserve sequence */
1319 reserve_s
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLocation
);
1320 reserve_e
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLength
);
1321 reserve_e
= reserve_e
>> sb
->s_blocksize_bits
;
1322 reserve_e
+= reserve_s
;
1324 udf_release_data(bh
);
1326 /* Process the main & reserve sequences */
1327 /* responsible for finding the PartitionDesc(s) */
1328 if (!(udf_process_sequence(sb
, main_s
, main_e
, fileset
) &&
1329 udf_process_sequence(sb
, reserve_s
, reserve_e
, fileset
)))
1336 if (i
== sizeof(UDF_SB_ANCHOR(sb
))/sizeof(int))
1338 udf_debug("No Anchor block found\n");
1342 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb
)[i
]);
1344 for (i
=0; i
<UDF_SB_NUMPARTS(sb
); i
++)
1346 switch UDF_SB_PARTTYPE(sb
, i
)
1348 case UDF_VIRTUAL_MAP15
:
1349 case UDF_VIRTUAL_MAP20
:
1353 if (!UDF_SB_LASTBLOCK(sb
))
1355 UDF_SB_LASTBLOCK(sb
) = udf_get_last_block(sb
);
1356 udf_find_anchor(sb
);
1359 if (!UDF_SB_LASTBLOCK(sb
))
1361 udf_debug("Unable to determine Lastblock (For Virtual Partition)\n");
1365 for (j
=0; j
<UDF_SB_NUMPARTS(sb
); j
++)
1368 UDF_SB_PARTVSN(sb
,i
) == UDF_SB_PARTVSN(sb
,j
) &&
1369 UDF_SB_PARTNUM(sb
,i
) == UDF_SB_PARTNUM(sb
,j
))
1371 ino
.partitionReferenceNum
= j
;
1372 ino
.logicalBlockNum
= UDF_SB_LASTBLOCK(sb
) -
1373 UDF_SB_PARTROOT(sb
,j
);
1378 if (j
== UDF_SB_NUMPARTS(sb
))
1381 if (!(UDF_SB_VAT(sb
) = udf_iget(sb
, ino
)))
1384 if (UDF_SB_PARTTYPE(sb
,i
) == UDF_VIRTUAL_MAP15
)
1386 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
= udf_ext0_offset(UDF_SB_VAT(sb
));
1387 UDF_SB_TYPEVIRT(sb
,i
).s_num_entries
= (UDF_SB_VAT(sb
)->i_size
- 36) >> 2;
1389 else if (UDF_SB_PARTTYPE(sb
,i
) == UDF_VIRTUAL_MAP20
)
1391 struct buffer_head
*bh
= NULL
;
1394 pos
= udf_block_map(UDF_SB_VAT(sb
), 0);
1395 bh
= sb_bread(sb
, pos
);
1396 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
=
1397 le16_to_cpu(((struct virtualAllocationTable20
*)bh
->b_data
+ udf_ext0_offset(UDF_SB_VAT(sb
)))->lengthHeader
) +
1398 udf_ext0_offset(UDF_SB_VAT(sb
));
1399 UDF_SB_TYPEVIRT(sb
,i
).s_num_entries
= (UDF_SB_VAT(sb
)->i_size
-
1400 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
) >> 2;
1401 udf_release_data(bh
);
1403 UDF_SB_PARTROOT(sb
,i
) = udf_get_pblock(sb
, 0, i
, 0);
1404 UDF_SB_PARTLEN(sb
,i
) = UDF_SB_PARTLEN(sb
,ino
.partitionReferenceNum
);
1411 static void udf_open_lvid(struct super_block
*sb
)
1413 if (UDF_SB_LVIDBH(sb
))
1416 kernel_timestamp cpu_time
;
1418 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1419 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1420 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
))
1421 UDF_SB_LVID(sb
)->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1422 UDF_SB_LVID(sb
)->integrityType
= LVID_INTEGRITY_TYPE_OPEN
;
1424 UDF_SB_LVID(sb
)->descTag
.descCRC
=
1425 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb
) + sizeof(tag
),
1426 le16_to_cpu(UDF_SB_LVID(sb
)->descTag
.descCRCLength
), 0));
1428 UDF_SB_LVID(sb
)->descTag
.tagChecksum
= 0;
1429 for (i
=0; i
<16; i
++)
1431 UDF_SB_LVID(sb
)->descTag
.tagChecksum
+=
1432 ((uint8_t *)&(UDF_SB_LVID(sb
)->descTag
))[i
];
1434 mark_buffer_dirty(UDF_SB_LVIDBH(sb
));
1438 static void udf_close_lvid(struct super_block
*sb
)
1440 if (UDF_SB_LVIDBH(sb
) &&
1441 UDF_SB_LVID(sb
)->integrityType
== LVID_INTEGRITY_TYPE_OPEN
)
1444 kernel_timestamp cpu_time
;
1446 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1447 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1448 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
))
1449 UDF_SB_LVID(sb
)->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1450 if (UDF_MAX_WRITE_VERSION
> le16_to_cpu(UDF_SB_LVIDIU(sb
)->maxUDFWriteRev
))
1451 UDF_SB_LVIDIU(sb
)->maxUDFWriteRev
= cpu_to_le16(UDF_MAX_WRITE_VERSION
);
1452 if (UDF_SB_UDFREV(sb
) > le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFReadRev
))
1453 UDF_SB_LVIDIU(sb
)->minUDFReadRev
= cpu_to_le16(UDF_SB_UDFREV(sb
));
1454 if (UDF_SB_UDFREV(sb
) > le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFWriteRev
))
1455 UDF_SB_LVIDIU(sb
)->minUDFWriteRev
= cpu_to_le16(UDF_SB_UDFREV(sb
));
1456 UDF_SB_LVID(sb
)->integrityType
= cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE
);
1458 UDF_SB_LVID(sb
)->descTag
.descCRC
=
1459 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb
) + sizeof(tag
),
1460 le16_to_cpu(UDF_SB_LVID(sb
)->descTag
.descCRCLength
), 0));
1462 UDF_SB_LVID(sb
)->descTag
.tagChecksum
= 0;
1463 for (i
=0; i
<16; i
++)
1465 UDF_SB_LVID(sb
)->descTag
.tagChecksum
+=
1466 ((uint8_t *)&(UDF_SB_LVID(sb
)->descTag
))[i
];
1468 mark_buffer_dirty(UDF_SB_LVIDBH(sb
));
1476 * Complete the specified super block.
1479 * sb Pointer to superblock to complete - never NULL.
1480 * sb->s_dev Device to read suberblock from.
1481 * options Pointer to mount options.
1482 * silent Silent flag.
1485 * July 1, 1997 - Andrew E. Mileski
1486 * Written, tested, and released.
1488 static int udf_fill_super(struct super_block
*sb
, void *options
, int silent
)
1491 struct inode
*inode
=NULL
;
1492 struct udf_options uopt
;
1493 kernel_lb_addr rootdir
, fileset
;
1494 struct udf_sb_info
*sbi
;
1496 uopt
.flags
= (1 << UDF_FLAG_USE_AD_IN_ICB
) | (1 << UDF_FLAG_STRICT
);
1501 sbi
= kmalloc(sizeof(struct udf_sb_info
), GFP_KERNEL
);
1504 sb
->s_fs_info
= sbi
;
1505 memset(UDF_SB(sb
), 0x00, sizeof(struct udf_sb_info
));
1507 init_MUTEX(&sbi
->s_alloc_sem
);
1509 if (!udf_parse_options((char *)options
, &uopt
))
1512 if (uopt
.flags
& (1 << UDF_FLAG_UTF8
) &&
1513 uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
))
1515 udf_error(sb
, "udf_read_super",
1516 "utf8 cannot be combined with iocharset\n");
1519 #ifdef CONFIG_UDF_NLS
1520 if ((uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) && !uopt
.nls_map
)
1522 uopt
.nls_map
= load_nls_default();
1524 uopt
.flags
&= ~(1 << UDF_FLAG_NLS_MAP
);
1526 udf_debug("Using default NLS map\n");
1529 if (!(uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)))
1530 uopt
.flags
|= (1 << UDF_FLAG_UTF8
);
1532 fileset
.logicalBlockNum
= 0xFFFFFFFF;
1533 fileset
.partitionReferenceNum
= 0xFFFF;
1535 UDF_SB(sb
)->s_flags
= uopt
.flags
;
1536 UDF_SB(sb
)->s_uid
= uopt
.uid
;
1537 UDF_SB(sb
)->s_gid
= uopt
.gid
;
1538 UDF_SB(sb
)->s_umask
= uopt
.umask
;
1539 UDF_SB(sb
)->s_nls_map
= uopt
.nls_map
;
1541 /* Set the block size for all transfers */
1542 if (!udf_set_blocksize(sb
, uopt
.blocksize
))
1545 if ( uopt
.session
== 0xFFFFFFFF )
1546 UDF_SB_SESSION(sb
) = udf_get_last_session(sb
);
1548 UDF_SB_SESSION(sb
) = uopt
.session
;
1550 udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb
));
1552 UDF_SB_LASTBLOCK(sb
) = uopt
.lastblock
;
1553 UDF_SB_ANCHOR(sb
)[0] = UDF_SB_ANCHOR(sb
)[1] = 0;
1554 UDF_SB_ANCHOR(sb
)[2] = uopt
.anchor
;
1555 UDF_SB_ANCHOR(sb
)[3] = 256;
1557 if (udf_check_valid(sb
, uopt
.novrs
, silent
)) /* read volume recognition sequences */
1559 printk("UDF-fs: No VRS found\n");
1563 udf_find_anchor(sb
);
1565 /* Fill in the rest of the superblock */
1566 sb
->s_op
= &udf_sb_ops
;
1569 sb
->s_magic
= UDF_SUPER_MAGIC
;
1570 sb
->s_time_gran
= 1000;
1572 if (udf_load_partition(sb
, &fileset
))
1574 printk("UDF-fs: No partition found (1)\n");
1578 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb
));
1580 if ( UDF_SB_LVIDBH(sb
) )
1582 uint16_t minUDFReadRev
= le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFReadRev
);
1583 uint16_t minUDFWriteRev
= le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFWriteRev
);
1584 /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */
1586 if (minUDFReadRev
> UDF_MAX_READ_VERSION
)
1588 printk("UDF-fs: minUDFReadRev=%x (max is %x)\n",
1589 le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFReadRev
),
1590 UDF_MAX_READ_VERSION
);
1593 else if (minUDFWriteRev
> UDF_MAX_WRITE_VERSION
)
1595 sb
->s_flags
|= MS_RDONLY
;
1598 UDF_SB_UDFREV(sb
) = minUDFWriteRev
;
1600 if (minUDFReadRev
>= UDF_VERS_USE_EXTENDED_FE
)
1601 UDF_SET_FLAG(sb
, UDF_FLAG_USE_EXTENDED_FE
);
1602 if (minUDFReadRev
>= UDF_VERS_USE_STREAMS
)
1603 UDF_SET_FLAG(sb
, UDF_FLAG_USE_STREAMS
);
1606 if ( !UDF_SB_NUMPARTS(sb
) )
1608 printk("UDF-fs: No partition found (2)\n");
1612 if ( udf_find_fileset(sb
, &fileset
, &rootdir
) )
1614 printk("UDF-fs: No fileset found\n");
1620 kernel_timestamp ts
;
1621 udf_time_to_stamp(&ts
, UDF_SB_RECORDTIME(sb
));
1622 udf_info("UDF %s (%s) Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1623 UDFFS_VERSION
, UDFFS_DATE
,
1624 UDF_SB_VOLIDENT(sb
), ts
.year
, ts
.month
, ts
.day
, ts
.hour
, ts
.minute
,
1625 ts
.typeAndTimezone
);
1627 if (!(sb
->s_flags
& MS_RDONLY
))
1630 /* Assign the root inode */
1631 /* assign inodes by physical block number */
1632 /* perhaps it's not extensible enough, but for now ... */
1633 inode
= udf_iget(sb
, rootdir
);
1636 printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n",
1637 rootdir
.logicalBlockNum
, rootdir
.partitionReferenceNum
);
1641 /* Allocate a dentry for the root inode */
1642 sb
->s_root
= d_alloc_root(inode
);
1645 printk("UDF-fs: Couldn't allocate root dentry\n");
1649 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
1654 iput(UDF_SB_VAT(sb
));
1655 if (UDF_SB_NUMPARTS(sb
))
1657 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_TABLE
)
1658 iput(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_table
);
1659 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_TABLE
)
1660 iput(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_table
);
1661 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_BITMAP
)
1662 UDF_SB_FREE_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_uspace
);
1663 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_BITMAP
)
1664 UDF_SB_FREE_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_fspace
);
1665 if (UDF_SB_PARTTYPE(sb
, UDF_SB_PARTITION(sb
)) == UDF_SPARABLE_MAP15
)
1668 udf_release_data(UDF_SB_TYPESPAR(sb
, UDF_SB_PARTITION(sb
)).s_spar_map
[i
]);
1671 #ifdef CONFIG_UDF_NLS
1672 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
1673 unload_nls(UDF_SB(sb
)->s_nls_map
);
1675 if (!(sb
->s_flags
& MS_RDONLY
))
1677 udf_release_data(UDF_SB_LVIDBH(sb
));
1680 sb
->s_fs_info
= NULL
;
1684 void udf_error(struct super_block
*sb
, const char *function
,
1685 const char *fmt
, ...)
1689 if (!(sb
->s_flags
& MS_RDONLY
))
1694 va_start(args
, fmt
);
1695 vsprintf(error_buf
, fmt
, args
);
1697 printk (KERN_CRIT
"UDF-fs error (device %s): %s: %s\n",
1698 sb
->s_id
, function
, error_buf
);
1701 void udf_warning(struct super_block
*sb
, const char *function
,
1702 const char *fmt
, ...)
1706 va_start (args
, fmt
);
1707 vsprintf(error_buf
, fmt
, args
);
1709 printk(KERN_WARNING
"UDF-fs warning (device %s): %s: %s\n",
1710 sb
->s_id
, function
, error_buf
);
1717 * Prepare for destruction of the superblock.
1720 * Called before the filesystem is unmounted.
1723 * July 1, 1997 - Andrew E. Mileski
1724 * Written, tested, and released.
1727 udf_put_super(struct super_block
*sb
)
1732 iput(UDF_SB_VAT(sb
));
1733 if (UDF_SB_NUMPARTS(sb
))
1735 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_TABLE
)
1736 iput(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_table
);
1737 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_TABLE
)
1738 iput(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_table
);
1739 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_BITMAP
)
1740 UDF_SB_FREE_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_uspace
);
1741 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_BITMAP
)
1742 UDF_SB_FREE_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_fspace
);
1743 if (UDF_SB_PARTTYPE(sb
, UDF_SB_PARTITION(sb
)) == UDF_SPARABLE_MAP15
)
1746 udf_release_data(UDF_SB_TYPESPAR(sb
, UDF_SB_PARTITION(sb
)).s_spar_map
[i
]);
1749 #ifdef CONFIG_UDF_NLS
1750 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
1751 unload_nls(UDF_SB(sb
)->s_nls_map
);
1753 if (!(sb
->s_flags
& MS_RDONLY
))
1755 udf_release_data(UDF_SB_LVIDBH(sb
));
1757 kfree(sb
->s_fs_info
);
1758 sb
->s_fs_info
= NULL
;
1765 * Return info about the filesystem.
1768 * Called by sys_statfs()
1771 * July 1, 1997 - Andrew E. Mileski
1772 * Written, tested, and released.
1775 udf_statfs(struct super_block
*sb
, struct kstatfs
*buf
)
1777 buf
->f_type
= UDF_SUPER_MAGIC
;
1778 buf
->f_bsize
= sb
->s_blocksize
;
1779 buf
->f_blocks
= UDF_SB_PARTLEN(sb
, UDF_SB_PARTITION(sb
));
1780 buf
->f_bfree
= udf_count_free(sb
);
1781 buf
->f_bavail
= buf
->f_bfree
;
1782 buf
->f_files
= (UDF_SB_LVIDBH(sb
) ?
1783 (le32_to_cpu(UDF_SB_LVIDIU(sb
)->numFiles
) +
1784 le32_to_cpu(UDF_SB_LVIDIU(sb
)->numDirs
)) : 0) + buf
->f_bfree
;
1785 buf
->f_ffree
= buf
->f_bfree
;
1786 /* __kernel_fsid_t f_fsid */
1787 buf
->f_namelen
= UDF_NAME_LEN
-2;
1792 static unsigned char udf_bitmap_lookup
[16] = {
1793 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
1797 udf_count_free_bitmap(struct super_block
*sb
, struct udf_bitmap
*bitmap
)
1799 struct buffer_head
*bh
= NULL
;
1800 unsigned int accum
= 0;
1802 int block
= 0, newblock
;
1808 struct spaceBitmapDesc
*bm
;
1812 loc
.logicalBlockNum
= bitmap
->s_extPosition
;
1813 loc
.partitionReferenceNum
= UDF_SB_PARTITION(sb
);
1814 bh
= udf_read_ptagged(sb
, loc
, 0, &ident
);
1818 printk(KERN_ERR
"udf: udf_count_free failed\n");
1821 else if (ident
!= TAG_IDENT_SBD
)
1823 udf_release_data(bh
);
1824 printk(KERN_ERR
"udf: udf_count_free failed\n");
1828 bm
= (struct spaceBitmapDesc
*)bh
->b_data
;
1829 bytes
= le32_to_cpu(bm
->numOfBytes
);
1830 index
= sizeof(struct spaceBitmapDesc
); /* offset in first block only */
1831 ptr
= (uint8_t *)bh
->b_data
;
1835 while ((bytes
> 0) && (index
< sb
->s_blocksize
))
1838 accum
+= udf_bitmap_lookup
[ value
& 0x0f ];
1839 accum
+= udf_bitmap_lookup
[ value
>> 4 ];
1845 udf_release_data(bh
);
1846 newblock
= udf_get_lb_pblock(sb
, loc
, ++block
);
1847 bh
= udf_tread(sb
, newblock
);
1850 udf_debug("read failed\n");
1854 ptr
= (uint8_t *)bh
->b_data
;
1857 udf_release_data(bh
);
1866 udf_count_free_table(struct super_block
*sb
, struct inode
* table
)
1868 unsigned int accum
= 0;
1869 uint32_t extoffset
, elen
;
1870 kernel_lb_addr bloc
, eloc
;
1872 struct buffer_head
*bh
= NULL
;
1876 bloc
= UDF_I_LOCATION(table
);
1877 extoffset
= sizeof(struct unallocSpaceEntry
);
1879 while ((etype
= udf_next_aext(table
, &bloc
, &extoffset
, &eloc
, &elen
, &bh
, 1)) != -1)
1881 accum
+= (elen
>> table
->i_sb
->s_blocksize_bits
);
1883 udf_release_data(bh
);
1891 udf_count_free(struct super_block
*sb
)
1893 unsigned int accum
= 0;
1895 if (UDF_SB_LVIDBH(sb
))
1897 if (le32_to_cpu(UDF_SB_LVID(sb
)->numOfPartitions
) > UDF_SB_PARTITION(sb
))
1899 accum
= le32_to_cpu(UDF_SB_LVID(sb
)->freeSpaceTable
[UDF_SB_PARTITION(sb
)]);
1901 if (accum
== 0xFFFFFFFF)
1909 if (UDF_SB_PARTFLAGS(sb
,UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_BITMAP
)
1911 accum
+= udf_count_free_bitmap(sb
,
1912 UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_bitmap
);
1914 if (UDF_SB_PARTFLAGS(sb
,UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_BITMAP
)
1916 accum
+= udf_count_free_bitmap(sb
,
1917 UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_bitmap
);
1922 if (UDF_SB_PARTFLAGS(sb
,UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_TABLE
)
1924 accum
+= udf_count_free_table(sb
,
1925 UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_table
);
1927 if (UDF_SB_PARTFLAGS(sb
,UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_TABLE
)
1929 accum
+= udf_count_free_table(sb
,
1930 UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_table
);