5 * Super block routines for the OSTA-UDF(tm) filesystem.
8 * OSTA-UDF(tm) = Optical Storage Technology Association
9 * Universal Disk Format.
11 * This code is based on version 2.00 of the UDF specification,
12 * and revision 3 of the ECMA 167 standard [equivalent to ISO 13346].
13 * http://www.osta.org/
18 * This file is distributed under the terms of the GNU General Public
19 * License (GPL). Copies of the GPL can be obtained from:
20 * ftp://prep.ai.mit.edu/pub/gnu/GPL
21 * Each contributing author retains all rights to their own work.
23 * (C) 1998 Dave Boynton
24 * (C) 1998-2004 Ben Fennema
25 * (C) 2000 Stelias Computing Inc
29 * 09/24/98 dgb changed to allow compiling outside of kernel, and
30 * added some debugging.
31 * 10/01/98 dgb updated to allow (some) possibility of compiling w/2.0.34
32 * 10/16/98 attempting some multi-session support
33 * 10/17/98 added freespace count for "df"
34 * 11/11/98 gr added novrs option
35 * 11/26/98 dgb added fileset,anchor mount options
36 * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced vol descs
37 * rewrote option handling based on isofs
38 * 12/20/98 find the free space bitmap (if it exists)
43 #include <linux/blkdev.h>
44 #include <linux/slab.h>
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/parser.h>
48 #include <linux/stat.h>
49 #include <linux/cdrom.h>
50 #include <linux/nls.h>
51 #include <linux/smp_lock.h>
52 #include <linux/buffer_head.h>
53 #include <linux/vfs.h>
54 #include <linux/vmalloc.h>
55 #include <asm/byteorder.h>
57 #include <linux/udf_fs.h>
61 #include <linux/init.h>
62 #include <asm/uaccess.h>
64 #define VDS_POS_PRIMARY_VOL_DESC 0
65 #define VDS_POS_UNALLOC_SPACE_DESC 1
66 #define VDS_POS_LOGICAL_VOL_DESC 2
67 #define VDS_POS_PARTITION_DESC 3
68 #define VDS_POS_IMP_USE_VOL_DESC 4
69 #define VDS_POS_VOL_DESC_PTR 5
70 #define VDS_POS_TERMINATING_DESC 6
71 #define VDS_POS_LENGTH 7
73 static char error_buf
[1024];
75 /* These are the "meat" - everything else is stuffing */
76 static int udf_fill_super(struct super_block
*, void *, int);
77 static void udf_put_super(struct super_block
*);
78 static void udf_write_super(struct super_block
*);
79 static int udf_remount_fs(struct super_block
*, int *, char *);
80 static int udf_check_valid(struct super_block
*, int, int);
81 static int udf_vrs(struct super_block
*sb
, int silent
);
82 static int udf_load_partition(struct super_block
*, kernel_lb_addr
*);
83 static int udf_load_logicalvol(struct super_block
*, struct buffer_head
*, kernel_lb_addr
*);
84 static void udf_load_logicalvolint(struct super_block
*, kernel_extent_ad
);
85 static void udf_find_anchor(struct super_block
*);
86 static int udf_find_fileset(struct super_block
*, kernel_lb_addr
*, kernel_lb_addr
*);
87 static void udf_load_pvoldesc(struct super_block
*, struct buffer_head
*);
88 static void udf_load_fileset(struct super_block
*, struct buffer_head
*, kernel_lb_addr
*);
89 static void udf_load_partdesc(struct super_block
*, struct buffer_head
*);
90 static void udf_open_lvid(struct super_block
*);
91 static void udf_close_lvid(struct super_block
*);
92 static unsigned int udf_count_free(struct super_block
*);
93 static int udf_statfs(struct dentry
*, struct kstatfs
*);
95 /* UDF filesystem type */
96 static int udf_get_sb(struct file_system_type
*fs_type
,
97 int flags
, const char *dev_name
, void *data
, struct vfsmount
*mnt
)
99 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, udf_fill_super
, mnt
);
102 static struct file_system_type udf_fstype
= {
103 .owner
= THIS_MODULE
,
105 .get_sb
= udf_get_sb
,
106 .kill_sb
= kill_block_super
,
107 .fs_flags
= FS_REQUIRES_DEV
,
110 static struct kmem_cache
* udf_inode_cachep
;
112 static struct inode
*udf_alloc_inode(struct super_block
*sb
)
114 struct udf_inode_info
*ei
;
115 ei
= (struct udf_inode_info
*)kmem_cache_alloc(udf_inode_cachep
, GFP_KERNEL
);
120 ei
->i_lenExtents
= 0;
121 ei
->i_next_alloc_block
= 0;
122 ei
->i_next_alloc_goal
= 0;
125 return &ei
->vfs_inode
;
128 static void udf_destroy_inode(struct inode
*inode
)
130 kmem_cache_free(udf_inode_cachep
, UDF_I(inode
));
133 static void init_once(void * foo
, struct kmem_cache
* cachep
, unsigned long flags
)
135 struct udf_inode_info
*ei
= (struct udf_inode_info
*) foo
;
137 if (flags
& SLAB_CTOR_CONSTRUCTOR
) {
138 ei
->i_ext
.i_data
= NULL
;
139 inode_init_once(&ei
->vfs_inode
);
143 static int init_inodecache(void)
145 udf_inode_cachep
= kmem_cache_create("udf_inode_cache",
146 sizeof(struct udf_inode_info
),
147 0, (SLAB_RECLAIM_ACCOUNT
|
150 if (udf_inode_cachep
== NULL
)
155 static void destroy_inodecache(void)
157 kmem_cache_destroy(udf_inode_cachep
);
160 /* Superblock operations */
161 static const struct super_operations udf_sb_ops
= {
162 .alloc_inode
= udf_alloc_inode
,
163 .destroy_inode
= udf_destroy_inode
,
164 .write_inode
= udf_write_inode
,
165 .delete_inode
= udf_delete_inode
,
166 .clear_inode
= udf_clear_inode
,
167 .put_super
= udf_put_super
,
168 .write_super
= udf_write_super
,
169 .statfs
= udf_statfs
,
170 .remount_fs
= udf_remount_fs
,
176 unsigned int blocksize
;
177 unsigned int session
;
178 unsigned int lastblock
;
181 unsigned short partition
;
182 unsigned int fileset
;
183 unsigned int rootdir
;
188 struct nls_table
*nls_map
;
191 static int __init
init_udf_fs(void)
194 err
= init_inodecache();
197 err
= register_filesystem(&udf_fstype
);
202 destroy_inodecache();
207 static void __exit
exit_udf_fs(void)
209 unregister_filesystem(&udf_fstype
);
210 destroy_inodecache();
213 module_init(init_udf_fs
)
214 module_exit(exit_udf_fs
)
220 * Parse mount options.
223 * The following mount options are supported:
225 * gid= Set the default group.
226 * umask= Set the default umask.
227 * uid= Set the default user.
228 * bs= Set the block size.
229 * unhide Show otherwise hidden files.
230 * undelete Show deleted files in lists.
231 * adinicb Embed data in the inode (default)
232 * noadinicb Don't embed data in the inode
233 * shortad Use short ad's
234 * longad Use long ad's (default)
235 * nostrict Unset strict conformance
236 * iocharset= Set the NLS character set
238 * The remaining are for debugging and disaster recovery:
240 * novrs Skip volume sequence recognition
242 * The following expect a offset from 0.
244 * session= Set the CDROM session (default= last session)
245 * anchor= Override standard anchor location. (default= 256)
246 * volume= Override the VolumeDesc location. (unused)
247 * partition= Override the PartitionDesc location. (unused)
248 * lastblock= Set the last block of the filesystem/
250 * The following expect a offset from the partition root.
252 * fileset= Override the fileset block location. (unused)
253 * rootdir= Override the root directory location. (unused)
254 * WARNING: overriding the rootdir to a non-directory may
255 * yield highly unpredictable results.
258 * options Pointer to mount options string.
259 * uopts Pointer to mount options variable.
262 * <return> 1 Mount options parsed okay.
263 * <return> 0 Error parsing mount options.
266 * July 1, 1997 - Andrew E. Mileski
267 * Written, tested, and released.
271 Opt_novrs
, Opt_nostrict
, Opt_bs
, Opt_unhide
, Opt_undelete
,
272 Opt_noadinicb
, Opt_adinicb
, Opt_shortad
, Opt_longad
,
273 Opt_gid
, Opt_uid
, Opt_umask
, Opt_session
, Opt_lastblock
,
274 Opt_anchor
, Opt_volume
, Opt_partition
, Opt_fileset
,
275 Opt_rootdir
, Opt_utf8
, Opt_iocharset
,
276 Opt_err
, Opt_uforget
, Opt_uignore
, Opt_gforget
, Opt_gignore
279 static match_table_t tokens
= {
280 {Opt_novrs
, "novrs"},
281 {Opt_nostrict
, "nostrict"},
283 {Opt_unhide
, "unhide"},
284 {Opt_undelete
, "undelete"},
285 {Opt_noadinicb
, "noadinicb"},
286 {Opt_adinicb
, "adinicb"},
287 {Opt_shortad
, "shortad"},
288 {Opt_longad
, "longad"},
289 {Opt_uforget
, "uid=forget"},
290 {Opt_uignore
, "uid=ignore"},
291 {Opt_gforget
, "gid=forget"},
292 {Opt_gignore
, "gid=ignore"},
295 {Opt_umask
, "umask=%o"},
296 {Opt_session
, "session=%u"},
297 {Opt_lastblock
, "lastblock=%u"},
298 {Opt_anchor
, "anchor=%u"},
299 {Opt_volume
, "volume=%u"},
300 {Opt_partition
, "partition=%u"},
301 {Opt_fileset
, "fileset=%u"},
302 {Opt_rootdir
, "rootdir=%u"},
304 {Opt_iocharset
, "iocharset=%s"},
309 udf_parse_options(char *options
, struct udf_options
*uopt
)
315 uopt
->blocksize
= 2048;
316 uopt
->partition
= 0xFFFF;
317 uopt
->session
= 0xFFFFFFFF;
320 uopt
->volume
= 0xFFFFFFFF;
321 uopt
->rootdir
= 0xFFFFFFFF;
322 uopt
->fileset
= 0xFFFFFFFF;
323 uopt
->nls_map
= NULL
;
328 while ((p
= strsep(&options
, ",")) != NULL
)
330 substring_t args
[MAX_OPT_ARGS
];
335 token
= match_token(p
, tokens
, args
);
341 if (match_int(&args
[0], &option
))
343 uopt
->blocksize
= option
;
346 uopt
->flags
|= (1 << UDF_FLAG_UNHIDE
);
349 uopt
->flags
|= (1 << UDF_FLAG_UNDELETE
);
352 uopt
->flags
&= ~(1 << UDF_FLAG_USE_AD_IN_ICB
);
355 uopt
->flags
|= (1 << UDF_FLAG_USE_AD_IN_ICB
);
358 uopt
->flags
|= (1 << UDF_FLAG_USE_SHORT_AD
);
361 uopt
->flags
&= ~(1 << UDF_FLAG_USE_SHORT_AD
);
364 if (match_int(args
, &option
))
369 if (match_int(args
, &option
))
374 if (match_octal(args
, &option
))
376 uopt
->umask
= option
;
379 uopt
->flags
&= ~(1 << UDF_FLAG_STRICT
);
382 if (match_int(args
, &option
))
384 uopt
->session
= option
;
387 if (match_int(args
, &option
))
389 uopt
->lastblock
= option
;
392 if (match_int(args
, &option
))
394 uopt
->anchor
= option
;
397 if (match_int(args
, &option
))
399 uopt
->volume
= option
;
402 if (match_int(args
, &option
))
404 uopt
->partition
= option
;
407 if (match_int(args
, &option
))
409 uopt
->fileset
= option
;
412 if (match_int(args
, &option
))
414 uopt
->rootdir
= option
;
417 uopt
->flags
|= (1 << UDF_FLAG_UTF8
);
419 #ifdef CONFIG_UDF_NLS
421 uopt
->nls_map
= load_nls(args
[0].from
);
422 uopt
->flags
|= (1 << UDF_FLAG_NLS_MAP
);
426 uopt
->flags
|= (1 << UDF_FLAG_UID_IGNORE
);
429 uopt
->flags
|= (1 << UDF_FLAG_UID_FORGET
);
432 uopt
->flags
|= (1 << UDF_FLAG_GID_IGNORE
);
435 uopt
->flags
|= (1 << UDF_FLAG_GID_FORGET
);
438 printk(KERN_ERR
"udf: bad mount option \"%s\" "
439 "or missing value\n", p
);
447 udf_write_super(struct super_block
*sb
)
450 if (!(sb
->s_flags
& MS_RDONLY
))
457 udf_remount_fs(struct super_block
*sb
, int *flags
, char *options
)
459 struct udf_options uopt
;
461 uopt
.flags
= UDF_SB(sb
)->s_flags
;
462 uopt
.uid
= UDF_SB(sb
)->s_uid
;
463 uopt
.gid
= UDF_SB(sb
)->s_gid
;
464 uopt
.umask
= UDF_SB(sb
)->s_umask
;
466 if ( !udf_parse_options(options
, &uopt
) )
469 UDF_SB(sb
)->s_flags
= uopt
.flags
;
470 UDF_SB(sb
)->s_uid
= uopt
.uid
;
471 UDF_SB(sb
)->s_gid
= uopt
.gid
;
472 UDF_SB(sb
)->s_umask
= uopt
.umask
;
474 if (UDF_SB_LVIDBH(sb
)) {
475 int write_rev
= le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFWriteRev
);
476 if (write_rev
> UDF_MAX_WRITE_VERSION
)
480 if ((*flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
))
482 if (*flags
& MS_RDONLY
)
494 * Set the block size to be used in all transfers.
497 * To allow room for a DMA transfer, it is best to guess big when unsure.
498 * This routine picks 2048 bytes as the blocksize when guessing. This
499 * should be adequate until devices with larger block sizes become common.
501 * Note that the Linux kernel can currently only deal with blocksizes of
502 * 512, 1024, 2048, 4096, and 8192 bytes.
505 * sb Pointer to _locked_ superblock.
508 * sb->s_blocksize Blocksize.
509 * sb->s_blocksize_bits log2 of blocksize.
510 * <return> 0 Blocksize is valid.
511 * <return> 1 Blocksize is invalid.
514 * July 1, 1997 - Andrew E. Mileski
515 * Written, tested, and released.
518 udf_set_blocksize(struct super_block
*sb
, int bsize
)
520 if (!sb_min_blocksize(sb
, bsize
)) {
521 udf_debug("Bad block size (%d)\n", bsize
);
522 printk(KERN_ERR
"udf: bad block size (%d)\n", bsize
);
525 return sb
->s_blocksize
;
529 udf_vrs(struct super_block
*sb
, int silent
)
531 struct volStructDesc
*vsd
= NULL
;
534 struct buffer_head
*bh
= NULL
;
539 /* Block size must be a multiple of 512 */
540 if (sb
->s_blocksize
& 511)
543 if (sb
->s_blocksize
< sizeof(struct volStructDesc
))
544 sectorsize
= sizeof(struct volStructDesc
);
546 sectorsize
= sb
->s_blocksize
;
548 sector
+= (UDF_SB_SESSION(sb
) << sb
->s_blocksize_bits
);
550 udf_debug("Starting at sector %u (%ld byte sectors)\n",
551 (sector
>> sb
->s_blocksize_bits
), sb
->s_blocksize
);
552 /* Process the sequence (if applicable) */
553 for (;!nsr02
&& !nsr03
; sector
+= sectorsize
)
556 bh
= udf_tread(sb
, sector
>> sb
->s_blocksize_bits
);
560 /* Look for ISO descriptors */
561 vsd
= (struct volStructDesc
*)(bh
->b_data
+
562 (sector
& (sb
->s_blocksize
- 1)));
564 if (vsd
->stdIdent
[0] == 0)
569 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_CD001
, VSD_STD_ID_LEN
))
572 switch (vsd
->structType
)
575 udf_debug("ISO9660 Boot Record found\n");
578 udf_debug("ISO9660 Primary Volume Descriptor found\n");
581 udf_debug("ISO9660 Supplementary Volume Descriptor found\n");
584 udf_debug("ISO9660 Volume Partition Descriptor found\n");
587 udf_debug("ISO9660 Volume Descriptor Set Terminator found\n");
590 udf_debug("ISO9660 VRS (%u) found\n", vsd
->structType
);
594 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_BEA01
, VSD_STD_ID_LEN
))
597 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_TEA01
, VSD_STD_ID_LEN
))
602 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR02
, VSD_STD_ID_LEN
))
606 else if (!strncmp(vsd
->stdIdent
, VSD_STD_ID_NSR03
, VSD_STD_ID_LEN
))
617 else if (sector
- (UDF_SB_SESSION(sb
) << sb
->s_blocksize_bits
) == 32768)
627 * Find an anchor volume descriptor.
630 * sb Pointer to _locked_ superblock.
631 * lastblock Last block on media.
634 * <return> 1 if not found, 0 if ok
637 * July 1, 1997 - Andrew E. Mileski
638 * Written, tested, and released.
641 udf_find_anchor(struct super_block
*sb
)
643 int lastblock
= UDF_SB_LASTBLOCK(sb
);
644 struct buffer_head
*bh
= NULL
;
651 int varlastblock
= udf_variable_to_fixed(lastblock
);
652 int last
[] = { lastblock
, lastblock
- 2,
653 lastblock
- 150, lastblock
- 152,
654 varlastblock
, varlastblock
- 2,
655 varlastblock
- 150, varlastblock
- 152 };
659 /* Search for an anchor volume descriptor pointer */
661 /* according to spec, anchor is in either:
665 * however, if the disc isn't closed, it could be 512 */
667 for (i
= 0; !lastblock
&& i
< ARRAY_SIZE(last
); i
++) {
668 if (last
[i
] < 0 || !(bh
= sb_bread(sb
, last
[i
])))
670 ident
= location
= 0;
674 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
675 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
679 if (ident
== TAG_IDENT_AVDP
)
681 if (location
== last
[i
] - UDF_SB_SESSION(sb
))
683 lastblock
= UDF_SB_ANCHOR(sb
)[0] = last
[i
] - UDF_SB_SESSION(sb
);
684 UDF_SB_ANCHOR(sb
)[1] = last
[i
] - 256 - UDF_SB_SESSION(sb
);
686 else if (location
== udf_variable_to_fixed(last
[i
]) - UDF_SB_SESSION(sb
))
688 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
689 lastblock
= UDF_SB_ANCHOR(sb
)[0] = udf_variable_to_fixed(last
[i
]) - UDF_SB_SESSION(sb
);
690 UDF_SB_ANCHOR(sb
)[1] = lastblock
- 256 - UDF_SB_SESSION(sb
);
693 udf_debug("Anchor found at block %d, location mismatch %d.\n",
696 else if (ident
== TAG_IDENT_FE
|| ident
== TAG_IDENT_EFE
)
699 UDF_SB_ANCHOR(sb
)[3] = 512;
703 if (last
[i
] < 256 || !(bh
= sb_bread(sb
, last
[i
] - 256)))
705 ident
= location
= 0;
709 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
710 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
714 if (ident
== TAG_IDENT_AVDP
&&
715 location
== last
[i
] - 256 - UDF_SB_SESSION(sb
))
718 UDF_SB_ANCHOR(sb
)[1] = last
[i
] - 256;
722 if (last
[i
] < 312 + UDF_SB_SESSION(sb
) || !(bh
= sb_bread(sb
, last
[i
] - 312 - UDF_SB_SESSION(sb
))))
724 ident
= location
= 0;
728 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
729 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
733 if (ident
== TAG_IDENT_AVDP
&&
734 location
== udf_variable_to_fixed(last
[i
]) - 256)
736 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
737 lastblock
= udf_variable_to_fixed(last
[i
]);
738 UDF_SB_ANCHOR(sb
)[1] = lastblock
- 256;
747 /* We havn't found the lastblock. check 312 */
748 if ((bh
= sb_bread(sb
, 312 + UDF_SB_SESSION(sb
))))
750 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
751 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
754 if (ident
== TAG_IDENT_AVDP
&& location
== 256)
755 UDF_SET_FLAG(sb
, UDF_FLAG_VARCONV
);
759 for (i
= 0; i
< ARRAY_SIZE(UDF_SB_ANCHOR(sb
)); i
++) {
760 if (UDF_SB_ANCHOR(sb
)[i
])
762 if (!(bh
= udf_read_tagged(sb
,
763 UDF_SB_ANCHOR(sb
)[i
], UDF_SB_ANCHOR(sb
)[i
], &ident
)))
765 UDF_SB_ANCHOR(sb
)[i
] = 0;
770 if ((ident
!= TAG_IDENT_AVDP
) && (i
||
771 (ident
!= TAG_IDENT_FE
&& ident
!= TAG_IDENT_EFE
)))
773 UDF_SB_ANCHOR(sb
)[i
] = 0;
779 UDF_SB_LASTBLOCK(sb
) = lastblock
;
783 udf_find_fileset(struct super_block
*sb
, kernel_lb_addr
*fileset
, kernel_lb_addr
*root
)
785 struct buffer_head
*bh
= NULL
;
789 if (fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
790 fileset
->partitionReferenceNum
!= 0xFFFF)
792 bh
= udf_read_ptagged(sb
, *fileset
, 0, &ident
);
796 else if (ident
!= TAG_IDENT_FSD
)
804 if (!bh
) /* Search backwards through the partitions */
806 kernel_lb_addr newfileset
;
810 for (newfileset
.partitionReferenceNum
=UDF_SB_NUMPARTS(sb
)-1;
811 (newfileset
.partitionReferenceNum
!= 0xFFFF &&
812 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
813 fileset
->partitionReferenceNum
== 0xFFFF);
814 newfileset
.partitionReferenceNum
--)
816 lastblock
= UDF_SB_PARTLEN(sb
, newfileset
.partitionReferenceNum
);
817 newfileset
.logicalBlockNum
= 0;
821 bh
= udf_read_ptagged(sb
, newfileset
, 0, &ident
);
824 newfileset
.logicalBlockNum
++;
832 struct spaceBitmapDesc
*sp
;
833 sp
= (struct spaceBitmapDesc
*)bh
->b_data
;
834 newfileset
.logicalBlockNum
+= 1 +
835 ((le32_to_cpu(sp
->numOfBytes
) + sizeof(struct spaceBitmapDesc
) - 1)
836 >> sb
->s_blocksize_bits
);
842 *fileset
= newfileset
;
847 newfileset
.logicalBlockNum
++;
854 while (newfileset
.logicalBlockNum
< lastblock
&&
855 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
856 fileset
->partitionReferenceNum
== 0xFFFF);
860 if ((fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
861 fileset
->partitionReferenceNum
!= 0xFFFF) && bh
)
863 udf_debug("Fileset at block=%d, partition=%d\n",
864 fileset
->logicalBlockNum
, fileset
->partitionReferenceNum
);
866 UDF_SB_PARTITION(sb
) = fileset
->partitionReferenceNum
;
867 udf_load_fileset(sb
, bh
, root
);
875 udf_load_pvoldesc(struct super_block
*sb
, struct buffer_head
*bh
)
877 struct primaryVolDesc
*pvoldesc
;
883 pvoldesc
= (struct primaryVolDesc
*)bh
->b_data
;
885 if ( udf_stamp_to_time(&recording
, &recording_usec
,
886 lets_to_cpu(pvoldesc
->recordingDateAndTime
)) )
889 ts
= lets_to_cpu(pvoldesc
->recordingDateAndTime
);
890 udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n",
891 recording
, recording_usec
,
892 ts
.year
, ts
.month
, ts
.day
, ts
.hour
, ts
.minute
, ts
.typeAndTimezone
);
893 UDF_SB_RECORDTIME(sb
).tv_sec
= recording
;
894 UDF_SB_RECORDTIME(sb
).tv_nsec
= recording_usec
* 1000;
897 if ( !udf_build_ustr(&instr
, pvoldesc
->volIdent
, 32) )
899 if (udf_CS0toUTF8(&outstr
, &instr
))
901 strncpy( UDF_SB_VOLIDENT(sb
), outstr
.u_name
,
902 outstr
.u_len
> 31 ? 31 : outstr
.u_len
);
903 udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb
));
907 if ( !udf_build_ustr(&instr
, pvoldesc
->volSetIdent
, 128) )
909 if (udf_CS0toUTF8(&outstr
, &instr
))
910 udf_debug("volSetIdent[] = '%s'\n", outstr
.u_name
);
915 udf_load_fileset(struct super_block
*sb
, struct buffer_head
*bh
, kernel_lb_addr
*root
)
917 struct fileSetDesc
*fset
;
919 fset
= (struct fileSetDesc
*)bh
->b_data
;
921 *root
= lelb_to_cpu(fset
->rootDirectoryICB
.extLocation
);
923 UDF_SB_SERIALNUM(sb
) = le16_to_cpu(fset
->descTag
.tagSerialNum
);
925 udf_debug("Rootdir at block=%d, partition=%d\n",
926 root
->logicalBlockNum
, root
->partitionReferenceNum
);
930 udf_load_partdesc(struct super_block
*sb
, struct buffer_head
*bh
)
932 struct partitionDesc
*p
;
935 p
= (struct partitionDesc
*)bh
->b_data
;
937 for (i
=0; i
<UDF_SB_NUMPARTS(sb
); i
++)
939 udf_debug("Searching map: (%d == %d)\n",
940 UDF_SB_PARTMAPS(sb
)[i
].s_partition_num
, le16_to_cpu(p
->partitionNumber
));
941 if (UDF_SB_PARTMAPS(sb
)[i
].s_partition_num
== le16_to_cpu(p
->partitionNumber
))
943 UDF_SB_PARTLEN(sb
,i
) = le32_to_cpu(p
->partitionLength
); /* blocks */
944 UDF_SB_PARTROOT(sb
,i
) = le32_to_cpu(p
->partitionStartingLocation
);
945 if (le32_to_cpu(p
->accessType
) == PD_ACCESS_TYPE_READ_ONLY
)
946 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_READ_ONLY
;
947 if (le32_to_cpu(p
->accessType
) == PD_ACCESS_TYPE_WRITE_ONCE
)
948 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_WRITE_ONCE
;
949 if (le32_to_cpu(p
->accessType
) == PD_ACCESS_TYPE_REWRITABLE
)
950 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_REWRITABLE
;
951 if (le32_to_cpu(p
->accessType
) == PD_ACCESS_TYPE_OVERWRITABLE
)
952 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_OVERWRITABLE
;
954 if (!strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR02
) ||
955 !strcmp(p
->partitionContents
.ident
, PD_PARTITION_CONTENTS_NSR03
))
957 struct partitionHeaderDesc
*phd
;
959 phd
= (struct partitionHeaderDesc
*)(p
->partitionContentsUse
);
960 if (phd
->unallocSpaceTable
.extLength
)
962 kernel_lb_addr loc
= { le32_to_cpu(phd
->unallocSpaceTable
.extPosition
), i
};
964 UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_table
=
966 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_UNALLOC_TABLE
;
967 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
968 i
, UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_table
->i_ino
);
970 if (phd
->unallocSpaceBitmap
.extLength
)
972 UDF_SB_ALLOC_BITMAP(sb
, i
, s_uspace
);
973 if (UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_bitmap
!= NULL
)
975 UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_bitmap
->s_extLength
=
976 le32_to_cpu(phd
->unallocSpaceBitmap
.extLength
);
977 UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_bitmap
->s_extPosition
=
978 le32_to_cpu(phd
->unallocSpaceBitmap
.extPosition
);
979 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_UNALLOC_BITMAP
;
980 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
981 i
, UDF_SB_PARTMAPS(sb
)[i
].s_uspace
.s_bitmap
->s_extPosition
);
984 if (phd
->partitionIntegrityTable
.extLength
)
985 udf_debug("partitionIntegrityTable (part %d)\n", i
);
986 if (phd
->freedSpaceTable
.extLength
)
988 kernel_lb_addr loc
= { le32_to_cpu(phd
->freedSpaceTable
.extPosition
), i
};
990 UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_table
=
992 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_FREED_TABLE
;
993 udf_debug("freedSpaceTable (part %d) @ %ld\n",
994 i
, UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_table
->i_ino
);
996 if (phd
->freedSpaceBitmap
.extLength
)
998 UDF_SB_ALLOC_BITMAP(sb
, i
, s_fspace
);
999 if (UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_bitmap
!= NULL
)
1001 UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_bitmap
->s_extLength
=
1002 le32_to_cpu(phd
->freedSpaceBitmap
.extLength
);
1003 UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_bitmap
->s_extPosition
=
1004 le32_to_cpu(phd
->freedSpaceBitmap
.extPosition
);
1005 UDF_SB_PARTFLAGS(sb
,i
) |= UDF_PART_FLAG_FREED_BITMAP
;
1006 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
1007 i
, UDF_SB_PARTMAPS(sb
)[i
].s_fspace
.s_bitmap
->s_extPosition
);
1014 if (i
== UDF_SB_NUMPARTS(sb
))
1016 udf_debug("Partition (%d) not found in partition map\n", le16_to_cpu(p
->partitionNumber
));
1020 udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
1021 le16_to_cpu(p
->partitionNumber
), i
, UDF_SB_PARTTYPE(sb
,i
),
1022 UDF_SB_PARTROOT(sb
,i
), UDF_SB_PARTLEN(sb
,i
));
1027 udf_load_logicalvol(struct super_block
*sb
, struct buffer_head
* bh
, kernel_lb_addr
*fileset
)
1029 struct logicalVolDesc
*lvd
;
1033 lvd
= (struct logicalVolDesc
*)bh
->b_data
;
1035 UDF_SB_ALLOC_PARTMAPS(sb
, le32_to_cpu(lvd
->numPartitionMaps
));
1038 i
<UDF_SB_NUMPARTS(sb
) && offset
<le32_to_cpu(lvd
->mapTableLength
);
1039 i
++,offset
+=((struct genericPartitionMap
*)&(lvd
->partitionMaps
[offset
]))->partitionMapLength
)
1041 type
= ((struct genericPartitionMap
*)&(lvd
->partitionMaps
[offset
]))->partitionMapType
;
1044 struct genericPartitionMap1
*gpm1
= (struct genericPartitionMap1
*)&(lvd
->partitionMaps
[offset
]);
1045 UDF_SB_PARTTYPE(sb
,i
) = UDF_TYPE1_MAP15
;
1046 UDF_SB_PARTVSN(sb
,i
) = le16_to_cpu(gpm1
->volSeqNum
);
1047 UDF_SB_PARTNUM(sb
,i
) = le16_to_cpu(gpm1
->partitionNum
);
1048 UDF_SB_PARTFUNC(sb
,i
) = NULL
;
1052 struct udfPartitionMap2
*upm2
= (struct udfPartitionMap2
*)&(lvd
->partitionMaps
[offset
]);
1053 if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_VIRTUAL
, strlen(UDF_ID_VIRTUAL
)))
1055 if (le16_to_cpu(((__le16
*)upm2
->partIdent
.identSuffix
)[0]) == 0x0150)
1057 UDF_SB_PARTTYPE(sb
,i
) = UDF_VIRTUAL_MAP15
;
1058 UDF_SB_PARTFUNC(sb
,i
) = udf_get_pblock_virt15
;
1060 else if (le16_to_cpu(((__le16
*)upm2
->partIdent
.identSuffix
)[0]) == 0x0200)
1062 UDF_SB_PARTTYPE(sb
,i
) = UDF_VIRTUAL_MAP20
;
1063 UDF_SB_PARTFUNC(sb
,i
) = udf_get_pblock_virt20
;
1066 else if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_SPARABLE
, strlen(UDF_ID_SPARABLE
)))
1070 struct sparingTable
*st
;
1071 struct sparablePartitionMap
*spm
= (struct sparablePartitionMap
*)&(lvd
->partitionMaps
[offset
]);
1073 UDF_SB_PARTTYPE(sb
,i
) = UDF_SPARABLE_MAP15
;
1074 UDF_SB_TYPESPAR(sb
,i
).s_packet_len
= le16_to_cpu(spm
->packetLength
);
1075 for (j
=0; j
<spm
->numSparingTables
; j
++)
1077 loc
= le32_to_cpu(spm
->locSparingTable
[j
]);
1078 UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
] =
1079 udf_read_tagged(sb
, loc
, loc
, &ident
);
1080 if (UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
] != NULL
)
1082 st
= (struct sparingTable
*)UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
]->b_data
;
1084 strncmp(st
->sparingIdent
.ident
, UDF_ID_SPARING
, strlen(UDF_ID_SPARING
)))
1086 brelse(UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
]);
1087 UDF_SB_TYPESPAR(sb
,i
).s_spar_map
[j
] = NULL
;
1091 UDF_SB_PARTFUNC(sb
,i
) = udf_get_pblock_spar15
;
1095 udf_debug("Unknown ident: %s\n", upm2
->partIdent
.ident
);
1098 UDF_SB_PARTVSN(sb
,i
) = le16_to_cpu(upm2
->volSeqNum
);
1099 UDF_SB_PARTNUM(sb
,i
) = le16_to_cpu(upm2
->partitionNum
);
1101 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1102 i
, UDF_SB_PARTNUM(sb
,i
), type
, UDF_SB_PARTVSN(sb
,i
));
1107 long_ad
*la
= (long_ad
*)&(lvd
->logicalVolContentsUse
[0]);
1109 *fileset
= lelb_to_cpu(la
->extLocation
);
1110 udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
1111 fileset
->logicalBlockNum
,
1112 fileset
->partitionReferenceNum
);
1114 if (lvd
->integritySeqExt
.extLength
)
1115 udf_load_logicalvolint(sb
, leea_to_cpu(lvd
->integritySeqExt
));
1120 * udf_load_logicalvolint
1124 udf_load_logicalvolint(struct super_block
*sb
, kernel_extent_ad loc
)
1126 struct buffer_head
*bh
= NULL
;
1129 while (loc
.extLength
> 0 &&
1130 (bh
= udf_read_tagged(sb
, loc
.extLocation
,
1131 loc
.extLocation
, &ident
)) &&
1132 ident
== TAG_IDENT_LVID
)
1134 UDF_SB_LVIDBH(sb
) = bh
;
1136 if (UDF_SB_LVID(sb
)->nextIntegrityExt
.extLength
)
1137 udf_load_logicalvolint(sb
, leea_to_cpu(UDF_SB_LVID(sb
)->nextIntegrityExt
));
1139 if (UDF_SB_LVIDBH(sb
) != bh
)
1141 loc
.extLength
-= sb
->s_blocksize
;
1144 if (UDF_SB_LVIDBH(sb
) != bh
)
1149 * udf_process_sequence
1152 * Process a main/reserve volume descriptor sequence.
1155 * sb Pointer to _locked_ superblock.
1156 * block First block of first extent of the sequence.
1157 * lastblock Lastblock of first extent of the sequence.
1160 * July 1, 1997 - Andrew E. Mileski
1161 * Written, tested, and released.
1164 udf_process_sequence(struct super_block
*sb
, long block
, long lastblock
, kernel_lb_addr
*fileset
)
1166 struct buffer_head
*bh
= NULL
;
1167 struct udf_vds_record vds
[VDS_POS_LENGTH
];
1168 struct generic_desc
*gd
;
1169 struct volDescPtr
*vdp
;
1174 long next_s
= 0, next_e
= 0;
1176 memset(vds
, 0, sizeof(struct udf_vds_record
) * VDS_POS_LENGTH
);
1178 /* Read the main descriptor sequence */
1179 for (;(!done
&& block
<= lastblock
); block
++)
1182 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1186 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1187 gd
= (struct generic_desc
*)bh
->b_data
;
1188 vdsn
= le32_to_cpu(gd
->volDescSeqNum
);
1191 case TAG_IDENT_PVD
: /* ISO 13346 3/10.1 */
1192 if (vdsn
>= vds
[VDS_POS_PRIMARY_VOL_DESC
].volDescSeqNum
)
1194 vds
[VDS_POS_PRIMARY_VOL_DESC
].volDescSeqNum
= vdsn
;
1195 vds
[VDS_POS_PRIMARY_VOL_DESC
].block
= block
;
1198 case TAG_IDENT_VDP
: /* ISO 13346 3/10.3 */
1199 if (vdsn
>= vds
[VDS_POS_VOL_DESC_PTR
].volDescSeqNum
)
1201 vds
[VDS_POS_VOL_DESC_PTR
].volDescSeqNum
= vdsn
;
1202 vds
[VDS_POS_VOL_DESC_PTR
].block
= block
;
1204 vdp
= (struct volDescPtr
*)bh
->b_data
;
1205 next_s
= le32_to_cpu(vdp
->nextVolDescSeqExt
.extLocation
);
1206 next_e
= le32_to_cpu(vdp
->nextVolDescSeqExt
.extLength
);
1207 next_e
= next_e
>> sb
->s_blocksize_bits
;
1211 case TAG_IDENT_IUVD
: /* ISO 13346 3/10.4 */
1212 if (vdsn
>= vds
[VDS_POS_IMP_USE_VOL_DESC
].volDescSeqNum
)
1214 vds
[VDS_POS_IMP_USE_VOL_DESC
].volDescSeqNum
= vdsn
;
1215 vds
[VDS_POS_IMP_USE_VOL_DESC
].block
= block
;
1218 case TAG_IDENT_PD
: /* ISO 13346 3/10.5 */
1219 if (!vds
[VDS_POS_PARTITION_DESC
].block
)
1220 vds
[VDS_POS_PARTITION_DESC
].block
= block
;
1222 case TAG_IDENT_LVD
: /* ISO 13346 3/10.6 */
1223 if (vdsn
>= vds
[VDS_POS_LOGICAL_VOL_DESC
].volDescSeqNum
)
1225 vds
[VDS_POS_LOGICAL_VOL_DESC
].volDescSeqNum
= vdsn
;
1226 vds
[VDS_POS_LOGICAL_VOL_DESC
].block
= block
;
1229 case TAG_IDENT_USD
: /* ISO 13346 3/10.8 */
1230 if (vdsn
>= vds
[VDS_POS_UNALLOC_SPACE_DESC
].volDescSeqNum
)
1232 vds
[VDS_POS_UNALLOC_SPACE_DESC
].volDescSeqNum
= vdsn
;
1233 vds
[VDS_POS_UNALLOC_SPACE_DESC
].block
= block
;
1236 case TAG_IDENT_TD
: /* ISO 13346 3/10.9 */
1237 vds
[VDS_POS_TERMINATING_DESC
].block
= block
;
1242 next_s
= next_e
= 0;
1250 for (i
=0; i
<VDS_POS_LENGTH
; i
++)
1254 bh
= udf_read_tagged(sb
, vds
[i
].block
, vds
[i
].block
, &ident
);
1256 if (i
== VDS_POS_PRIMARY_VOL_DESC
)
1257 udf_load_pvoldesc(sb
, bh
);
1258 else if (i
== VDS_POS_LOGICAL_VOL_DESC
)
1259 udf_load_logicalvol(sb
, bh
, fileset
);
1260 else if (i
== VDS_POS_PARTITION_DESC
)
1262 struct buffer_head
*bh2
= NULL
;
1263 udf_load_partdesc(sb
, bh
);
1264 for (j
=vds
[i
].block
+1; j
<vds
[VDS_POS_TERMINATING_DESC
].block
; j
++)
1266 bh2
= udf_read_tagged(sb
, j
, j
, &ident
);
1267 gd
= (struct generic_desc
*)bh2
->b_data
;
1268 if (ident
== TAG_IDENT_PD
)
1269 udf_load_partdesc(sb
, bh2
);
1284 udf_check_valid(struct super_block
*sb
, int novrs
, int silent
)
1290 udf_debug("Validity check skipped because of novrs option\n");
1293 /* Check that it is NSR02 compliant */
1294 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1295 else if ((block
= udf_vrs(sb
, silent
)) == -1)
1297 udf_debug("Failed to read byte 32768. Assuming open disc. Skipping validity check\n");
1298 if (!UDF_SB_LASTBLOCK(sb
))
1299 UDF_SB_LASTBLOCK(sb
) = udf_get_last_block(sb
);
1307 udf_load_partition(struct super_block
*sb
, kernel_lb_addr
*fileset
)
1309 struct anchorVolDescPtr
*anchor
;
1311 struct buffer_head
*bh
;
1312 long main_s
, main_e
, reserve_s
, reserve_e
;
1318 for (i
= 0; i
< ARRAY_SIZE(UDF_SB_ANCHOR(sb
)); i
++) {
1319 if (UDF_SB_ANCHOR(sb
)[i
] && (bh
= udf_read_tagged(sb
,
1320 UDF_SB_ANCHOR(sb
)[i
], UDF_SB_ANCHOR(sb
)[i
], &ident
)))
1322 anchor
= (struct anchorVolDescPtr
*)bh
->b_data
;
1324 /* Locate the main sequence */
1325 main_s
= le32_to_cpu( anchor
->mainVolDescSeqExt
.extLocation
);
1326 main_e
= le32_to_cpu( anchor
->mainVolDescSeqExt
.extLength
);
1327 main_e
= main_e
>> sb
->s_blocksize_bits
;
1330 /* Locate the reserve sequence */
1331 reserve_s
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLocation
);
1332 reserve_e
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLength
);
1333 reserve_e
= reserve_e
>> sb
->s_blocksize_bits
;
1334 reserve_e
+= reserve_s
;
1338 /* Process the main & reserve sequences */
1339 /* responsible for finding the PartitionDesc(s) */
1340 if (!(udf_process_sequence(sb
, main_s
, main_e
, fileset
) &&
1341 udf_process_sequence(sb
, reserve_s
, reserve_e
, fileset
)))
1348 if (i
== ARRAY_SIZE(UDF_SB_ANCHOR(sb
))) {
1349 udf_debug("No Anchor block found\n");
1352 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb
)[i
]);
1354 for (i
=0; i
<UDF_SB_NUMPARTS(sb
); i
++)
1356 switch UDF_SB_PARTTYPE(sb
, i
)
1358 case UDF_VIRTUAL_MAP15
:
1359 case UDF_VIRTUAL_MAP20
:
1363 if (!UDF_SB_LASTBLOCK(sb
))
1365 UDF_SB_LASTBLOCK(sb
) = udf_get_last_block(sb
);
1366 udf_find_anchor(sb
);
1369 if (!UDF_SB_LASTBLOCK(sb
))
1371 udf_debug("Unable to determine Lastblock (For Virtual Partition)\n");
1375 for (j
=0; j
<UDF_SB_NUMPARTS(sb
); j
++)
1378 UDF_SB_PARTVSN(sb
,i
) == UDF_SB_PARTVSN(sb
,j
) &&
1379 UDF_SB_PARTNUM(sb
,i
) == UDF_SB_PARTNUM(sb
,j
))
1381 ino
.partitionReferenceNum
= j
;
1382 ino
.logicalBlockNum
= UDF_SB_LASTBLOCK(sb
) -
1383 UDF_SB_PARTROOT(sb
,j
);
1388 if (j
== UDF_SB_NUMPARTS(sb
))
1391 if (!(UDF_SB_VAT(sb
) = udf_iget(sb
, ino
)))
1394 if (UDF_SB_PARTTYPE(sb
,i
) == UDF_VIRTUAL_MAP15
)
1396 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
= udf_ext0_offset(UDF_SB_VAT(sb
));
1397 UDF_SB_TYPEVIRT(sb
,i
).s_num_entries
= (UDF_SB_VAT(sb
)->i_size
- 36) >> 2;
1399 else if (UDF_SB_PARTTYPE(sb
,i
) == UDF_VIRTUAL_MAP20
)
1401 struct buffer_head
*bh
= NULL
;
1404 pos
= udf_block_map(UDF_SB_VAT(sb
), 0);
1405 bh
= sb_bread(sb
, pos
);
1408 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
=
1409 le16_to_cpu(((struct virtualAllocationTable20
*)bh
->b_data
+ udf_ext0_offset(UDF_SB_VAT(sb
)))->lengthHeader
) +
1410 udf_ext0_offset(UDF_SB_VAT(sb
));
1411 UDF_SB_TYPEVIRT(sb
,i
).s_num_entries
= (UDF_SB_VAT(sb
)->i_size
-
1412 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
) >> 2;
1415 UDF_SB_PARTROOT(sb
,i
) = udf_get_pblock(sb
, 0, i
, 0);
1416 UDF_SB_PARTLEN(sb
,i
) = UDF_SB_PARTLEN(sb
,ino
.partitionReferenceNum
);
1423 static void udf_open_lvid(struct super_block
*sb
)
1425 if (UDF_SB_LVIDBH(sb
))
1428 kernel_timestamp cpu_time
;
1430 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1431 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1432 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
))
1433 UDF_SB_LVID(sb
)->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1434 UDF_SB_LVID(sb
)->integrityType
= LVID_INTEGRITY_TYPE_OPEN
;
1436 UDF_SB_LVID(sb
)->descTag
.descCRC
=
1437 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb
) + sizeof(tag
),
1438 le16_to_cpu(UDF_SB_LVID(sb
)->descTag
.descCRCLength
), 0));
1440 UDF_SB_LVID(sb
)->descTag
.tagChecksum
= 0;
1441 for (i
=0; i
<16; i
++)
1443 UDF_SB_LVID(sb
)->descTag
.tagChecksum
+=
1444 ((uint8_t *)&(UDF_SB_LVID(sb
)->descTag
))[i
];
1446 mark_buffer_dirty(UDF_SB_LVIDBH(sb
));
1450 static void udf_close_lvid(struct super_block
*sb
)
1452 if (UDF_SB_LVIDBH(sb
) &&
1453 UDF_SB_LVID(sb
)->integrityType
== LVID_INTEGRITY_TYPE_OPEN
)
1456 kernel_timestamp cpu_time
;
1458 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1459 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1460 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
))
1461 UDF_SB_LVID(sb
)->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1462 if (UDF_MAX_WRITE_VERSION
> le16_to_cpu(UDF_SB_LVIDIU(sb
)->maxUDFWriteRev
))
1463 UDF_SB_LVIDIU(sb
)->maxUDFWriteRev
= cpu_to_le16(UDF_MAX_WRITE_VERSION
);
1464 if (UDF_SB_UDFREV(sb
) > le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFReadRev
))
1465 UDF_SB_LVIDIU(sb
)->minUDFReadRev
= cpu_to_le16(UDF_SB_UDFREV(sb
));
1466 if (UDF_SB_UDFREV(sb
) > le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFWriteRev
))
1467 UDF_SB_LVIDIU(sb
)->minUDFWriteRev
= cpu_to_le16(UDF_SB_UDFREV(sb
));
1468 UDF_SB_LVID(sb
)->integrityType
= cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE
);
1470 UDF_SB_LVID(sb
)->descTag
.descCRC
=
1471 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb
) + sizeof(tag
),
1472 le16_to_cpu(UDF_SB_LVID(sb
)->descTag
.descCRCLength
), 0));
1474 UDF_SB_LVID(sb
)->descTag
.tagChecksum
= 0;
1475 for (i
=0; i
<16; i
++)
1477 UDF_SB_LVID(sb
)->descTag
.tagChecksum
+=
1478 ((uint8_t *)&(UDF_SB_LVID(sb
)->descTag
))[i
];
1480 mark_buffer_dirty(UDF_SB_LVIDBH(sb
));
1488 * Complete the specified super block.
1491 * sb Pointer to superblock to complete - never NULL.
1492 * sb->s_dev Device to read suberblock from.
1493 * options Pointer to mount options.
1494 * silent Silent flag.
1497 * July 1, 1997 - Andrew E. Mileski
1498 * Written, tested, and released.
1500 static int udf_fill_super(struct super_block
*sb
, void *options
, int silent
)
1503 struct inode
*inode
=NULL
;
1504 struct udf_options uopt
;
1505 kernel_lb_addr rootdir
, fileset
;
1506 struct udf_sb_info
*sbi
;
1508 uopt
.flags
= (1 << UDF_FLAG_USE_AD_IN_ICB
) | (1 << UDF_FLAG_STRICT
);
1513 sbi
= kmalloc(sizeof(struct udf_sb_info
), GFP_KERNEL
);
1516 sb
->s_fs_info
= sbi
;
1517 memset(UDF_SB(sb
), 0x00, sizeof(struct udf_sb_info
));
1519 mutex_init(&sbi
->s_alloc_mutex
);
1521 if (!udf_parse_options((char *)options
, &uopt
))
1524 if (uopt
.flags
& (1 << UDF_FLAG_UTF8
) &&
1525 uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
))
1527 udf_error(sb
, "udf_read_super",
1528 "utf8 cannot be combined with iocharset\n");
1531 #ifdef CONFIG_UDF_NLS
1532 if ((uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)) && !uopt
.nls_map
)
1534 uopt
.nls_map
= load_nls_default();
1536 uopt
.flags
&= ~(1 << UDF_FLAG_NLS_MAP
);
1538 udf_debug("Using default NLS map\n");
1541 if (!(uopt
.flags
& (1 << UDF_FLAG_NLS_MAP
)))
1542 uopt
.flags
|= (1 << UDF_FLAG_UTF8
);
1544 fileset
.logicalBlockNum
= 0xFFFFFFFF;
1545 fileset
.partitionReferenceNum
= 0xFFFF;
1547 UDF_SB(sb
)->s_flags
= uopt
.flags
;
1548 UDF_SB(sb
)->s_uid
= uopt
.uid
;
1549 UDF_SB(sb
)->s_gid
= uopt
.gid
;
1550 UDF_SB(sb
)->s_umask
= uopt
.umask
;
1551 UDF_SB(sb
)->s_nls_map
= uopt
.nls_map
;
1553 /* Set the block size for all transfers */
1554 if (!udf_set_blocksize(sb
, uopt
.blocksize
))
1557 if ( uopt
.session
== 0xFFFFFFFF )
1558 UDF_SB_SESSION(sb
) = udf_get_last_session(sb
);
1560 UDF_SB_SESSION(sb
) = uopt
.session
;
1562 udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb
));
1564 UDF_SB_LASTBLOCK(sb
) = uopt
.lastblock
;
1565 UDF_SB_ANCHOR(sb
)[0] = UDF_SB_ANCHOR(sb
)[1] = 0;
1566 UDF_SB_ANCHOR(sb
)[2] = uopt
.anchor
;
1567 UDF_SB_ANCHOR(sb
)[3] = 256;
1569 if (udf_check_valid(sb
, uopt
.novrs
, silent
)) /* read volume recognition sequences */
1571 printk("UDF-fs: No VRS found\n");
1575 udf_find_anchor(sb
);
1577 /* Fill in the rest of the superblock */
1578 sb
->s_op
= &udf_sb_ops
;
1581 sb
->s_magic
= UDF_SUPER_MAGIC
;
1582 sb
->s_time_gran
= 1000;
1584 if (udf_load_partition(sb
, &fileset
))
1586 printk("UDF-fs: No partition found (1)\n");
1590 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb
));
1592 if ( UDF_SB_LVIDBH(sb
) )
1594 uint16_t minUDFReadRev
= le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFReadRev
);
1595 uint16_t minUDFWriteRev
= le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFWriteRev
);
1596 /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */
1598 if (minUDFReadRev
> UDF_MAX_READ_VERSION
)
1600 printk("UDF-fs: minUDFReadRev=%x (max is %x)\n",
1601 le16_to_cpu(UDF_SB_LVIDIU(sb
)->minUDFReadRev
),
1602 UDF_MAX_READ_VERSION
);
1605 else if (minUDFWriteRev
> UDF_MAX_WRITE_VERSION
)
1607 sb
->s_flags
|= MS_RDONLY
;
1610 UDF_SB_UDFREV(sb
) = minUDFWriteRev
;
1612 if (minUDFReadRev
>= UDF_VERS_USE_EXTENDED_FE
)
1613 UDF_SET_FLAG(sb
, UDF_FLAG_USE_EXTENDED_FE
);
1614 if (minUDFReadRev
>= UDF_VERS_USE_STREAMS
)
1615 UDF_SET_FLAG(sb
, UDF_FLAG_USE_STREAMS
);
1618 if ( !UDF_SB_NUMPARTS(sb
) )
1620 printk("UDF-fs: No partition found (2)\n");
1624 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_READ_ONLY
) {
1625 printk("UDF-fs: Partition marked readonly; forcing readonly mount\n");
1626 sb
->s_flags
|= MS_RDONLY
;
1629 if ( udf_find_fileset(sb
, &fileset
, &rootdir
) )
1631 printk("UDF-fs: No fileset found\n");
1637 kernel_timestamp ts
;
1638 udf_time_to_stamp(&ts
, UDF_SB_RECORDTIME(sb
));
1639 udf_info("UDF %s (%s) Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1640 UDFFS_VERSION
, UDFFS_DATE
,
1641 UDF_SB_VOLIDENT(sb
), ts
.year
, ts
.month
, ts
.day
, ts
.hour
, ts
.minute
,
1642 ts
.typeAndTimezone
);
1644 if (!(sb
->s_flags
& MS_RDONLY
))
1647 /* Assign the root inode */
1648 /* assign inodes by physical block number */
1649 /* perhaps it's not extensible enough, but for now ... */
1650 inode
= udf_iget(sb
, rootdir
);
1653 printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n",
1654 rootdir
.logicalBlockNum
, rootdir
.partitionReferenceNum
);
1658 /* Allocate a dentry for the root inode */
1659 sb
->s_root
= d_alloc_root(inode
);
1662 printk("UDF-fs: Couldn't allocate root dentry\n");
1666 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
1671 iput(UDF_SB_VAT(sb
));
1672 if (UDF_SB_NUMPARTS(sb
))
1674 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_TABLE
)
1675 iput(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_table
);
1676 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_TABLE
)
1677 iput(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_table
);
1678 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_BITMAP
)
1679 UDF_SB_FREE_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_uspace
);
1680 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_BITMAP
)
1681 UDF_SB_FREE_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_fspace
);
1682 if (UDF_SB_PARTTYPE(sb
, UDF_SB_PARTITION(sb
)) == UDF_SPARABLE_MAP15
)
1685 brelse(UDF_SB_TYPESPAR(sb
, UDF_SB_PARTITION(sb
)).s_spar_map
[i
]);
1688 #ifdef CONFIG_UDF_NLS
1689 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
1690 unload_nls(UDF_SB(sb
)->s_nls_map
);
1692 if (!(sb
->s_flags
& MS_RDONLY
))
1694 brelse(UDF_SB_LVIDBH(sb
));
1697 sb
->s_fs_info
= NULL
;
1701 void udf_error(struct super_block
*sb
, const char *function
,
1702 const char *fmt
, ...)
1706 if (!(sb
->s_flags
& MS_RDONLY
))
1711 va_start(args
, fmt
);
1712 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
1714 printk (KERN_CRIT
"UDF-fs error (device %s): %s: %s\n",
1715 sb
->s_id
, function
, error_buf
);
1718 void udf_warning(struct super_block
*sb
, const char *function
,
1719 const char *fmt
, ...)
1723 va_start (args
, fmt
);
1724 vsnprintf(error_buf
, sizeof(error_buf
), fmt
, args
);
1726 printk(KERN_WARNING
"UDF-fs warning (device %s): %s: %s\n",
1727 sb
->s_id
, function
, error_buf
);
1734 * Prepare for destruction of the superblock.
1737 * Called before the filesystem is unmounted.
1740 * July 1, 1997 - Andrew E. Mileski
1741 * Written, tested, and released.
1744 udf_put_super(struct super_block
*sb
)
1749 iput(UDF_SB_VAT(sb
));
1750 if (UDF_SB_NUMPARTS(sb
))
1752 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_TABLE
)
1753 iput(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_table
);
1754 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_TABLE
)
1755 iput(UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_table
);
1756 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_BITMAP
)
1757 UDF_SB_FREE_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_uspace
);
1758 if (UDF_SB_PARTFLAGS(sb
, UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_BITMAP
)
1759 UDF_SB_FREE_BITMAP(sb
,UDF_SB_PARTITION(sb
),s_fspace
);
1760 if (UDF_SB_PARTTYPE(sb
, UDF_SB_PARTITION(sb
)) == UDF_SPARABLE_MAP15
)
1763 brelse(UDF_SB_TYPESPAR(sb
, UDF_SB_PARTITION(sb
)).s_spar_map
[i
]);
1766 #ifdef CONFIG_UDF_NLS
1767 if (UDF_QUERY_FLAG(sb
, UDF_FLAG_NLS_MAP
))
1768 unload_nls(UDF_SB(sb
)->s_nls_map
);
1770 if (!(sb
->s_flags
& MS_RDONLY
))
1772 brelse(UDF_SB_LVIDBH(sb
));
1774 kfree(sb
->s_fs_info
);
1775 sb
->s_fs_info
= NULL
;
1782 * Return info about the filesystem.
1785 * Called by sys_statfs()
1788 * July 1, 1997 - Andrew E. Mileski
1789 * Written, tested, and released.
1792 udf_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
1794 struct super_block
*sb
= dentry
->d_sb
;
1796 buf
->f_type
= UDF_SUPER_MAGIC
;
1797 buf
->f_bsize
= sb
->s_blocksize
;
1798 buf
->f_blocks
= UDF_SB_PARTLEN(sb
, UDF_SB_PARTITION(sb
));
1799 buf
->f_bfree
= udf_count_free(sb
);
1800 buf
->f_bavail
= buf
->f_bfree
;
1801 buf
->f_files
= (UDF_SB_LVIDBH(sb
) ?
1802 (le32_to_cpu(UDF_SB_LVIDIU(sb
)->numFiles
) +
1803 le32_to_cpu(UDF_SB_LVIDIU(sb
)->numDirs
)) : 0) + buf
->f_bfree
;
1804 buf
->f_ffree
= buf
->f_bfree
;
1805 /* __kernel_fsid_t f_fsid */
1806 buf
->f_namelen
= UDF_NAME_LEN
-2;
1811 static unsigned char udf_bitmap_lookup
[16] = {
1812 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
1816 udf_count_free_bitmap(struct super_block
*sb
, struct udf_bitmap
*bitmap
)
1818 struct buffer_head
*bh
= NULL
;
1819 unsigned int accum
= 0;
1821 int block
= 0, newblock
;
1827 struct spaceBitmapDesc
*bm
;
1831 loc
.logicalBlockNum
= bitmap
->s_extPosition
;
1832 loc
.partitionReferenceNum
= UDF_SB_PARTITION(sb
);
1833 bh
= udf_read_ptagged(sb
, loc
, 0, &ident
);
1837 printk(KERN_ERR
"udf: udf_count_free failed\n");
1840 else if (ident
!= TAG_IDENT_SBD
)
1843 printk(KERN_ERR
"udf: udf_count_free failed\n");
1847 bm
= (struct spaceBitmapDesc
*)bh
->b_data
;
1848 bytes
= le32_to_cpu(bm
->numOfBytes
);
1849 index
= sizeof(struct spaceBitmapDesc
); /* offset in first block only */
1850 ptr
= (uint8_t *)bh
->b_data
;
1854 while ((bytes
> 0) && (index
< sb
->s_blocksize
))
1857 accum
+= udf_bitmap_lookup
[ value
& 0x0f ];
1858 accum
+= udf_bitmap_lookup
[ value
>> 4 ];
1865 newblock
= udf_get_lb_pblock(sb
, loc
, ++block
);
1866 bh
= udf_tread(sb
, newblock
);
1869 udf_debug("read failed\n");
1873 ptr
= (uint8_t *)bh
->b_data
;
1885 udf_count_free_table(struct super_block
*sb
, struct inode
* table
)
1887 unsigned int accum
= 0;
1889 kernel_lb_addr eloc
;
1891 struct extent_position epos
;
1895 epos
.block
= UDF_I_LOCATION(table
);
1896 epos
.offset
= sizeof(struct unallocSpaceEntry
);
1899 while ((etype
= udf_next_aext(table
, &epos
, &eloc
, &elen
, 1)) != -1)
1900 accum
+= (elen
>> table
->i_sb
->s_blocksize_bits
);
1909 udf_count_free(struct super_block
*sb
)
1911 unsigned int accum
= 0;
1913 if (UDF_SB_LVIDBH(sb
))
1915 if (le32_to_cpu(UDF_SB_LVID(sb
)->numOfPartitions
) > UDF_SB_PARTITION(sb
))
1917 accum
= le32_to_cpu(UDF_SB_LVID(sb
)->freeSpaceTable
[UDF_SB_PARTITION(sb
)]);
1919 if (accum
== 0xFFFFFFFF)
1927 if (UDF_SB_PARTFLAGS(sb
,UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_BITMAP
)
1929 accum
+= udf_count_free_bitmap(sb
,
1930 UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_bitmap
);
1932 if (UDF_SB_PARTFLAGS(sb
,UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_BITMAP
)
1934 accum
+= udf_count_free_bitmap(sb
,
1935 UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_bitmap
);
1940 if (UDF_SB_PARTFLAGS(sb
,UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_UNALLOC_TABLE
)
1942 accum
+= udf_count_free_table(sb
,
1943 UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace
.s_table
);
1945 if (UDF_SB_PARTFLAGS(sb
,UDF_SB_PARTITION(sb
)) & UDF_PART_FLAG_FREED_TABLE
)
1947 accum
+= udf_count_free_table(sb
,
1948 UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_fspace
.s_table
);