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/config.h>
44 #include <linux/blkdev.h>
45 #include <linux/slab.h>
46 #include <linux/kernel.h>
47 #include <linux/module.h>
48 #include <linux/parser.h>
49 #include <linux/stat.h>
50 #include <linux/cdrom.h>
51 #include <linux/nls.h>
52 #include <linux/smp_lock.h>
53 #include <linux/buffer_head.h>
54 #include <linux/vfs.h>
55 #include <linux/vmalloc.h>
56 #include <asm/byteorder.h>
58 #include <linux/udf_fs.h>
62 #include <linux/init.h>
63 #include <asm/uaccess.h>
65 #define VDS_POS_PRIMARY_VOL_DESC 0
66 #define VDS_POS_UNALLOC_SPACE_DESC 1
67 #define VDS_POS_LOGICAL_VOL_DESC 2
68 #define VDS_POS_PARTITION_DESC 3
69 #define VDS_POS_IMP_USE_VOL_DESC 4
70 #define VDS_POS_VOL_DESC_PTR 5
71 #define VDS_POS_TERMINATING_DESC 6
72 #define VDS_POS_LENGTH 7
74 static char error_buf[1024];
76 /* These are the "meat" - everything else is stuffing */
77 static int udf_fill_super(struct super_block *, void *, int);
78 static void udf_put_super(struct super_block *);
79 static void udf_write_super(struct super_block *);
80 static int udf_remount_fs(struct super_block *, int *, char *);
81 static int udf_check_valid(struct super_block *, int, int);
82 static int udf_vrs(struct super_block *sb, int silent);
83 static int udf_load_partition(struct super_block *, kernel_lb_addr *);
84 static int udf_load_logicalvol(struct super_block *, struct buffer_head *, kernel_lb_addr *);
85 static void udf_load_logicalvolint(struct super_block *, kernel_extent_ad);
86 static void udf_find_anchor(struct super_block *);
87 static int udf_find_fileset(struct super_block *, kernel_lb_addr *, kernel_lb_addr *);
88 static void udf_load_pvoldesc(struct super_block *, struct buffer_head *);
89 static void udf_load_fileset(struct super_block *, struct buffer_head *, kernel_lb_addr *);
90 static void udf_load_partdesc(struct super_block *, struct buffer_head *);
91 static void udf_open_lvid(struct super_block *);
92 static void udf_close_lvid(struct super_block *);
93 static unsigned int udf_count_free(struct super_block *);
94 static int udf_statfs(struct dentry *, struct kstatfs *);
96 /* UDF filesystem type */
97 static int udf_get_sb(struct file_system_type *fs_type,
98 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
100 return get_sb_bdev(fs_type, flags, dev_name, data, udf_fill_super, mnt);
103 static struct file_system_type udf_fstype = {
104 .owner = THIS_MODULE,
106 .get_sb = udf_get_sb,
107 .kill_sb = kill_block_super,
108 .fs_flags = FS_REQUIRES_DEV,
111 static kmem_cache_t * udf_inode_cachep;
113 static struct inode *udf_alloc_inode(struct super_block *sb)
115 struct udf_inode_info *ei;
116 ei = (struct udf_inode_info *)kmem_cache_alloc(udf_inode_cachep, SLAB_KERNEL);
119 return &ei->vfs_inode;
122 static void udf_destroy_inode(struct inode *inode)
124 kmem_cache_free(udf_inode_cachep, UDF_I(inode));
127 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
129 struct udf_inode_info *ei = (struct udf_inode_info *) foo;
131 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
132 SLAB_CTOR_CONSTRUCTOR)
134 ei->i_ext.i_data = NULL;
135 inode_init_once(&ei->vfs_inode);
139 static int init_inodecache(void)
141 udf_inode_cachep = kmem_cache_create("udf_inode_cache",
142 sizeof(struct udf_inode_info),
143 0, (SLAB_RECLAIM_ACCOUNT|
146 if (udf_inode_cachep == NULL)
151 static void destroy_inodecache(void)
153 if (kmem_cache_destroy(udf_inode_cachep))
154 printk(KERN_INFO "udf_inode_cache: not all structures were freed\n");
157 /* Superblock operations */
158 static struct super_operations udf_sb_ops = {
159 .alloc_inode = udf_alloc_inode,
160 .destroy_inode = udf_destroy_inode,
161 .write_inode = udf_write_inode,
162 .delete_inode = udf_delete_inode,
163 .clear_inode = udf_clear_inode,
164 .put_super = udf_put_super,
165 .write_super = udf_write_super,
166 .statfs = udf_statfs,
167 .remount_fs = udf_remount_fs,
173 unsigned int blocksize;
174 unsigned int session;
175 unsigned int lastblock;
178 unsigned short partition;
179 unsigned int fileset;
180 unsigned int rootdir;
185 struct nls_table *nls_map;
188 static int __init init_udf_fs(void)
191 err = init_inodecache();
194 err = register_filesystem(&udf_fstype);
199 destroy_inodecache();
204 static void __exit exit_udf_fs(void)
206 unregister_filesystem(&udf_fstype);
207 destroy_inodecache();
210 module_init(init_udf_fs)
211 module_exit(exit_udf_fs)
217 * Parse mount options.
220 * The following mount options are supported:
222 * gid= Set the default group.
223 * umask= Set the default umask.
224 * uid= Set the default user.
225 * bs= Set the block size.
226 * unhide Show otherwise hidden files.
227 * undelete Show deleted files in lists.
228 * adinicb Embed data in the inode (default)
229 * noadinicb Don't embed data in the inode
230 * shortad Use short ad's
231 * longad Use long ad's (default)
232 * nostrict Unset strict conformance
233 * iocharset= Set the NLS character set
235 * The remaining are for debugging and disaster recovery:
237 * novrs Skip volume sequence recognition
239 * The following expect a offset from 0.
241 * session= Set the CDROM session (default= last session)
242 * anchor= Override standard anchor location. (default= 256)
243 * volume= Override the VolumeDesc location. (unused)
244 * partition= Override the PartitionDesc location. (unused)
245 * lastblock= Set the last block of the filesystem/
247 * The following expect a offset from the partition root.
249 * fileset= Override the fileset block location. (unused)
250 * rootdir= Override the root directory location. (unused)
251 * WARNING: overriding the rootdir to a non-directory may
252 * yield highly unpredictable results.
255 * options Pointer to mount options string.
256 * uopts Pointer to mount options variable.
259 * <return> 1 Mount options parsed okay.
260 * <return> 0 Error parsing mount options.
263 * July 1, 1997 - Andrew E. Mileski
264 * Written, tested, and released.
268 Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete,
269 Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad,
270 Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock,
271 Opt_anchor, Opt_volume, Opt_partition, Opt_fileset,
272 Opt_rootdir, Opt_utf8, Opt_iocharset,
273 Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore
276 static match_table_t tokens = {
277 {Opt_novrs, "novrs"},
278 {Opt_nostrict, "nostrict"},
280 {Opt_unhide, "unhide"},
281 {Opt_undelete, "undelete"},
282 {Opt_noadinicb, "noadinicb"},
283 {Opt_adinicb, "adinicb"},
284 {Opt_shortad, "shortad"},
285 {Opt_longad, "longad"},
286 {Opt_uforget, "uid=forget"},
287 {Opt_uignore, "uid=ignore"},
288 {Opt_gforget, "gid=forget"},
289 {Opt_gignore, "gid=ignore"},
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 uopt->flags |= (1 << UDF_FLAG_UID_IGNORE);
426 uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
429 uopt->flags |= (1 << UDF_FLAG_GID_IGNORE);
432 uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
435 printk(KERN_ERR "udf: bad mount option \"%s\" "
436 "or missing value\n", p);
444 udf_write_super(struct super_block *sb)
447 if (!(sb->s_flags & MS_RDONLY))
454 udf_remount_fs(struct super_block *sb, int *flags, char *options)
456 struct udf_options uopt;
458 uopt.flags = UDF_SB(sb)->s_flags ;
459 uopt.uid = UDF_SB(sb)->s_uid ;
460 uopt.gid = UDF_SB(sb)->s_gid ;
461 uopt.umask = UDF_SB(sb)->s_umask ;
463 if ( !udf_parse_options(options, &uopt) )
466 UDF_SB(sb)->s_flags = uopt.flags;
467 UDF_SB(sb)->s_uid = uopt.uid;
468 UDF_SB(sb)->s_gid = uopt.gid;
469 UDF_SB(sb)->s_umask = uopt.umask;
471 if (UDF_SB_LVIDBH(sb)) {
472 int write_rev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
473 if (write_rev > UDF_MAX_WRITE_VERSION)
477 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
479 if (*flags & MS_RDONLY)
491 * Set the block size to be used in all transfers.
494 * To allow room for a DMA transfer, it is best to guess big when unsure.
495 * This routine picks 2048 bytes as the blocksize when guessing. This
496 * should be adequate until devices with larger block sizes become common.
498 * Note that the Linux kernel can currently only deal with blocksizes of
499 * 512, 1024, 2048, 4096, and 8192 bytes.
502 * sb Pointer to _locked_ superblock.
505 * sb->s_blocksize Blocksize.
506 * sb->s_blocksize_bits log2 of blocksize.
507 * <return> 0 Blocksize is valid.
508 * <return> 1 Blocksize is invalid.
511 * July 1, 1997 - Andrew E. Mileski
512 * Written, tested, and released.
515 udf_set_blocksize(struct super_block *sb, int bsize)
517 if (!sb_min_blocksize(sb, bsize)) {
518 udf_debug("Bad block size (%d)\n", bsize);
519 printk(KERN_ERR "udf: bad block size (%d)\n", bsize);
522 return sb->s_blocksize;
526 udf_vrs(struct super_block *sb, int silent)
528 struct volStructDesc *vsd = NULL;
531 struct buffer_head *bh = NULL;
536 /* Block size must be a multiple of 512 */
537 if (sb->s_blocksize & 511)
540 if (sb->s_blocksize < sizeof(struct volStructDesc))
541 sectorsize = sizeof(struct volStructDesc);
543 sectorsize = sb->s_blocksize;
545 sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits);
547 udf_debug("Starting at sector %u (%ld byte sectors)\n",
548 (sector >> sb->s_blocksize_bits), sb->s_blocksize);
549 /* Process the sequence (if applicable) */
550 for (;!nsr02 && !nsr03; sector += sectorsize)
553 bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
557 /* Look for ISO descriptors */
558 vsd = (struct volStructDesc *)(bh->b_data +
559 (sector & (sb->s_blocksize - 1)));
561 if (vsd->stdIdent[0] == 0)
563 udf_release_data(bh);
566 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN))
569 switch (vsd->structType)
572 udf_debug("ISO9660 Boot Record found\n");
575 udf_debug("ISO9660 Primary Volume Descriptor found\n");
578 udf_debug("ISO9660 Supplementary Volume Descriptor found\n");
581 udf_debug("ISO9660 Volume Partition Descriptor found\n");
584 udf_debug("ISO9660 Volume Descriptor Set Terminator found\n");
587 udf_debug("ISO9660 VRS (%u) found\n", vsd->structType);
591 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN))
594 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01, VSD_STD_ID_LEN))
596 udf_release_data(bh);
599 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN))
603 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN))
607 udf_release_data(bh);
614 else if (sector - (UDF_SB_SESSION(sb) << sb->s_blocksize_bits) == 32768)
624 * Find an anchor volume descriptor.
627 * sb Pointer to _locked_ superblock.
628 * lastblock Last block on media.
631 * <return> 1 if not found, 0 if ok
634 * July 1, 1997 - Andrew E. Mileski
635 * Written, tested, and released.
638 udf_find_anchor(struct super_block *sb)
640 int lastblock = UDF_SB_LASTBLOCK(sb);
641 struct buffer_head *bh = NULL;
648 int varlastblock = udf_variable_to_fixed(lastblock);
649 int last[] = { lastblock, lastblock - 2,
650 lastblock - 150, lastblock - 152,
651 varlastblock, varlastblock - 2,
652 varlastblock - 150, varlastblock - 152 };
656 /* Search for an anchor volume descriptor pointer */
658 /* according to spec, anchor is in either:
662 * however, if the disc isn't closed, it could be 512 */
664 for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) {
665 if (last[i] < 0 || !(bh = sb_bread(sb, last[i])))
667 ident = location = 0;
671 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
672 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
673 udf_release_data(bh);
676 if (ident == TAG_IDENT_AVDP)
678 if (location == last[i] - UDF_SB_SESSION(sb))
680 lastblock = UDF_SB_ANCHOR(sb)[0] = last[i] - UDF_SB_SESSION(sb);
681 UDF_SB_ANCHOR(sb)[1] = last[i] - 256 - UDF_SB_SESSION(sb);
683 else if (location == udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb))
685 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
686 lastblock = UDF_SB_ANCHOR(sb)[0] = udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb);
687 UDF_SB_ANCHOR(sb)[1] = lastblock - 256 - UDF_SB_SESSION(sb);
690 udf_debug("Anchor found at block %d, location mismatch %d.\n",
693 else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE)
696 UDF_SB_ANCHOR(sb)[3] = 512;
700 if (last[i] < 256 || !(bh = sb_bread(sb, last[i] - 256)))
702 ident = location = 0;
706 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
707 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
708 udf_release_data(bh);
711 if (ident == TAG_IDENT_AVDP &&
712 location == last[i] - 256 - UDF_SB_SESSION(sb))
715 UDF_SB_ANCHOR(sb)[1] = last[i] - 256;
719 if (last[i] < 312 + UDF_SB_SESSION(sb) || !(bh = sb_bread(sb, last[i] - 312 - UDF_SB_SESSION(sb))))
721 ident = location = 0;
725 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
726 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
727 udf_release_data(bh);
730 if (ident == TAG_IDENT_AVDP &&
731 location == udf_variable_to_fixed(last[i]) - 256)
733 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
734 lastblock = udf_variable_to_fixed(last[i]);
735 UDF_SB_ANCHOR(sb)[1] = lastblock - 256;
744 /* We havn't found the lastblock. check 312 */
745 if ((bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb))))
747 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
748 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
749 udf_release_data(bh);
751 if (ident == TAG_IDENT_AVDP && location == 256)
752 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
756 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
757 if (UDF_SB_ANCHOR(sb)[i])
759 if (!(bh = udf_read_tagged(sb,
760 UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident)))
762 UDF_SB_ANCHOR(sb)[i] = 0;
766 udf_release_data(bh);
767 if ((ident != TAG_IDENT_AVDP) && (i ||
768 (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE)))
770 UDF_SB_ANCHOR(sb)[i] = 0;
776 UDF_SB_LASTBLOCK(sb) = lastblock;
780 udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, kernel_lb_addr *root)
782 struct buffer_head *bh = NULL;
786 if (fileset->logicalBlockNum != 0xFFFFFFFF ||
787 fileset->partitionReferenceNum != 0xFFFF)
789 bh = udf_read_ptagged(sb, *fileset, 0, &ident);
793 else if (ident != TAG_IDENT_FSD)
795 udf_release_data(bh);
801 if (!bh) /* Search backwards through the partitions */
803 kernel_lb_addr newfileset;
807 for (newfileset.partitionReferenceNum=UDF_SB_NUMPARTS(sb)-1;
808 (newfileset.partitionReferenceNum != 0xFFFF &&
809 fileset->logicalBlockNum == 0xFFFFFFFF &&
810 fileset->partitionReferenceNum == 0xFFFF);
811 newfileset.partitionReferenceNum--)
813 lastblock = UDF_SB_PARTLEN(sb, newfileset.partitionReferenceNum);
814 newfileset.logicalBlockNum = 0;
818 bh = udf_read_ptagged(sb, newfileset, 0, &ident);
821 newfileset.logicalBlockNum ++;
829 struct spaceBitmapDesc *sp;
830 sp = (struct spaceBitmapDesc *)bh->b_data;
831 newfileset.logicalBlockNum += 1 +
832 ((le32_to_cpu(sp->numOfBytes) + sizeof(struct spaceBitmapDesc) - 1)
833 >> sb->s_blocksize_bits);
834 udf_release_data(bh);
839 *fileset = newfileset;
844 newfileset.logicalBlockNum ++;
845 udf_release_data(bh);
851 while (newfileset.logicalBlockNum < lastblock &&
852 fileset->logicalBlockNum == 0xFFFFFFFF &&
853 fileset->partitionReferenceNum == 0xFFFF);
857 if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
858 fileset->partitionReferenceNum != 0xFFFF) && bh)
860 udf_debug("Fileset at block=%d, partition=%d\n",
861 fileset->logicalBlockNum, fileset->partitionReferenceNum);
863 UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum;
864 udf_load_fileset(sb, bh, root);
865 udf_release_data(bh);
872 udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
874 struct primaryVolDesc *pvoldesc;
880 pvoldesc = (struct primaryVolDesc *)bh->b_data;
882 if ( udf_stamp_to_time(&recording, &recording_usec,
883 lets_to_cpu(pvoldesc->recordingDateAndTime)) )
886 ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
887 udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n",
888 recording, recording_usec,
889 ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.typeAndTimezone);
890 UDF_SB_RECORDTIME(sb).tv_sec = recording;
891 UDF_SB_RECORDTIME(sb).tv_nsec = recording_usec * 1000;
894 if ( !udf_build_ustr(&instr, pvoldesc->volIdent, 32) )
896 if (udf_CS0toUTF8(&outstr, &instr))
898 strncpy( UDF_SB_VOLIDENT(sb), outstr.u_name,
899 outstr.u_len > 31 ? 31 : outstr.u_len);
900 udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb));
904 if ( !udf_build_ustr(&instr, pvoldesc->volSetIdent, 128) )
906 if (udf_CS0toUTF8(&outstr, &instr))
907 udf_debug("volSetIdent[] = '%s'\n", outstr.u_name);
912 udf_load_fileset(struct super_block *sb, struct buffer_head *bh, kernel_lb_addr *root)
914 struct fileSetDesc *fset;
916 fset = (struct fileSetDesc *)bh->b_data;
918 *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
920 UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum);
922 udf_debug("Rootdir at block=%d, partition=%d\n",
923 root->logicalBlockNum, root->partitionReferenceNum);
927 udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
929 struct partitionDesc *p;
932 p = (struct partitionDesc *)bh->b_data;
934 for (i=0; i<UDF_SB_NUMPARTS(sb); i++)
936 udf_debug("Searching map: (%d == %d)\n",
937 UDF_SB_PARTMAPS(sb)[i].s_partition_num, le16_to_cpu(p->partitionNumber));
938 if (UDF_SB_PARTMAPS(sb)[i].s_partition_num == le16_to_cpu(p->partitionNumber))
940 UDF_SB_PARTLEN(sb,i) = le32_to_cpu(p->partitionLength); /* blocks */
941 UDF_SB_PARTROOT(sb,i) = le32_to_cpu(p->partitionStartingLocation);
942 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY)
943 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_READ_ONLY;
944 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_WRITE_ONCE)
945 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_WRITE_ONCE;
946 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_REWRITABLE)
947 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_REWRITABLE;
948 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_OVERWRITABLE)
949 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_OVERWRITABLE;
951 if (!strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) ||
952 !strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03))
954 struct partitionHeaderDesc *phd;
956 phd = (struct partitionHeaderDesc *)(p->partitionContentsUse);
957 if (phd->unallocSpaceTable.extLength)
959 kernel_lb_addr loc = { le32_to_cpu(phd->unallocSpaceTable.extPosition), i };
961 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table =
963 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_TABLE;
964 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
965 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table->i_ino);
967 if (phd->unallocSpaceBitmap.extLength)
969 UDF_SB_ALLOC_BITMAP(sb, i, s_uspace);
970 if (UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap != NULL)
972 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extLength =
973 le32_to_cpu(phd->unallocSpaceBitmap.extLength);
974 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition =
975 le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
976 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_BITMAP;
977 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
978 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition);
981 if (phd->partitionIntegrityTable.extLength)
982 udf_debug("partitionIntegrityTable (part %d)\n", i);
983 if (phd->freedSpaceTable.extLength)
985 kernel_lb_addr loc = { le32_to_cpu(phd->freedSpaceTable.extPosition), i };
987 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table =
989 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_TABLE;
990 udf_debug("freedSpaceTable (part %d) @ %ld\n",
991 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table->i_ino);
993 if (phd->freedSpaceBitmap.extLength)
995 UDF_SB_ALLOC_BITMAP(sb, i, s_fspace);
996 if (UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap != NULL)
998 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extLength =
999 le32_to_cpu(phd->freedSpaceBitmap.extLength);
1000 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition =
1001 le32_to_cpu(phd->freedSpaceBitmap.extPosition);
1002 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_BITMAP;
1003 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
1004 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition);
1011 if (i == UDF_SB_NUMPARTS(sb))
1013 udf_debug("Partition (%d) not found in partition map\n", le16_to_cpu(p->partitionNumber));
1017 udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
1018 le16_to_cpu(p->partitionNumber), i, UDF_SB_PARTTYPE(sb,i),
1019 UDF_SB_PARTROOT(sb,i), UDF_SB_PARTLEN(sb,i));
1024 udf_load_logicalvol(struct super_block *sb, struct buffer_head * bh, kernel_lb_addr *fileset)
1026 struct logicalVolDesc *lvd;
1030 lvd = (struct logicalVolDesc *)bh->b_data;
1032 UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps));
1035 i<UDF_SB_NUMPARTS(sb) && offset<le32_to_cpu(lvd->mapTableLength);
1036 i++,offset+=((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength)
1038 type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType;
1041 struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]);
1042 UDF_SB_PARTTYPE(sb,i) = UDF_TYPE1_MAP15;
1043 UDF_SB_PARTVSN(sb,i) = le16_to_cpu(gpm1->volSeqNum);
1044 UDF_SB_PARTNUM(sb,i) = le16_to_cpu(gpm1->partitionNum);
1045 UDF_SB_PARTFUNC(sb,i) = NULL;
1049 struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]);
1050 if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL)))
1052 if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0150)
1054 UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP15;
1055 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt15;
1057 else if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0200)
1059 UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP20;
1060 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt20;
1063 else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE)))
1067 struct sparingTable *st;
1068 struct sparablePartitionMap *spm = (struct sparablePartitionMap *)&(lvd->partitionMaps[offset]);
1070 UDF_SB_PARTTYPE(sb,i) = UDF_SPARABLE_MAP15;
1071 UDF_SB_TYPESPAR(sb,i).s_packet_len = le16_to_cpu(spm->packetLength);
1072 for (j=0; j<spm->numSparingTables; j++)
1074 loc = le32_to_cpu(spm->locSparingTable[j]);
1075 UDF_SB_TYPESPAR(sb,i).s_spar_map[j] =
1076 udf_read_tagged(sb, loc, loc, &ident);
1077 if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL)
1079 st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,i).s_spar_map[j]->b_data;
1081 strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING)))
1083 udf_release_data(UDF_SB_TYPESPAR(sb,i).s_spar_map[j]);
1084 UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = NULL;
1088 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_spar15;
1092 udf_debug("Unknown ident: %s\n", upm2->partIdent.ident);
1095 UDF_SB_PARTVSN(sb,i) = le16_to_cpu(upm2->volSeqNum);
1096 UDF_SB_PARTNUM(sb,i) = le16_to_cpu(upm2->partitionNum);
1098 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1099 i, UDF_SB_PARTNUM(sb,i), type, UDF_SB_PARTVSN(sb,i));
1104 long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]);
1106 *fileset = lelb_to_cpu(la->extLocation);
1107 udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
1108 fileset->logicalBlockNum,
1109 fileset->partitionReferenceNum);
1111 if (lvd->integritySeqExt.extLength)
1112 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
1117 * udf_load_logicalvolint
1121 udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
1123 struct buffer_head *bh = NULL;
1126 while (loc.extLength > 0 &&
1127 (bh = udf_read_tagged(sb, loc.extLocation,
1128 loc.extLocation, &ident)) &&
1129 ident == TAG_IDENT_LVID)
1131 UDF_SB_LVIDBH(sb) = bh;
1133 if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength)
1134 udf_load_logicalvolint(sb, leea_to_cpu(UDF_SB_LVID(sb)->nextIntegrityExt));
1136 if (UDF_SB_LVIDBH(sb) != bh)
1137 udf_release_data(bh);
1138 loc.extLength -= sb->s_blocksize;
1141 if (UDF_SB_LVIDBH(sb) != bh)
1142 udf_release_data(bh);
1146 * udf_process_sequence
1149 * Process a main/reserve volume descriptor sequence.
1152 * sb Pointer to _locked_ superblock.
1153 * block First block of first extent of the sequence.
1154 * lastblock Lastblock of first extent of the sequence.
1157 * July 1, 1997 - Andrew E. Mileski
1158 * Written, tested, and released.
1161 udf_process_sequence(struct super_block *sb, long block, long lastblock, kernel_lb_addr *fileset)
1163 struct buffer_head *bh = NULL;
1164 struct udf_vds_record vds[VDS_POS_LENGTH];
1165 struct generic_desc *gd;
1166 struct volDescPtr *vdp;
1171 long next_s = 0, next_e = 0;
1173 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
1175 /* Read the main descriptor sequence */
1176 for (;(!done && block <= lastblock); block++)
1179 bh = udf_read_tagged(sb, block, block, &ident);
1183 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1184 gd = (struct generic_desc *)bh->b_data;
1185 vdsn = le32_to_cpu(gd->volDescSeqNum);
1188 case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
1189 if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum)
1191 vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn;
1192 vds[VDS_POS_PRIMARY_VOL_DESC].block = block;
1195 case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
1196 if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum)
1198 vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn;
1199 vds[VDS_POS_VOL_DESC_PTR].block = block;
1201 vdp = (struct volDescPtr *)bh->b_data;
1202 next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation);
1203 next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength);
1204 next_e = next_e >> sb->s_blocksize_bits;
1208 case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
1209 if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum)
1211 vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn;
1212 vds[VDS_POS_IMP_USE_VOL_DESC].block = block;
1215 case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
1216 if (!vds[VDS_POS_PARTITION_DESC].block)
1217 vds[VDS_POS_PARTITION_DESC].block = block;
1219 case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
1220 if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum)
1222 vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn;
1223 vds[VDS_POS_LOGICAL_VOL_DESC].block = block;
1226 case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
1227 if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum)
1229 vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn;
1230 vds[VDS_POS_UNALLOC_SPACE_DESC].block = block;
1233 case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
1234 vds[VDS_POS_TERMINATING_DESC].block = block;
1239 next_s = next_e = 0;
1245 udf_release_data(bh);
1247 for (i=0; i<VDS_POS_LENGTH; i++)
1251 bh = udf_read_tagged(sb, vds[i].block, vds[i].block, &ident);
1253 if (i == VDS_POS_PRIMARY_VOL_DESC)
1254 udf_load_pvoldesc(sb, bh);
1255 else if (i == VDS_POS_LOGICAL_VOL_DESC)
1256 udf_load_logicalvol(sb, bh, fileset);
1257 else if (i == VDS_POS_PARTITION_DESC)
1259 struct buffer_head *bh2 = NULL;
1260 udf_load_partdesc(sb, bh);
1261 for (j=vds[i].block+1; j<vds[VDS_POS_TERMINATING_DESC].block; j++)
1263 bh2 = udf_read_tagged(sb, j, j, &ident);
1264 gd = (struct generic_desc *)bh2->b_data;
1265 if (ident == TAG_IDENT_PD)
1266 udf_load_partdesc(sb, bh2);
1267 udf_release_data(bh2);
1270 udf_release_data(bh);
1281 udf_check_valid(struct super_block *sb, int novrs, int silent)
1287 udf_debug("Validity check skipped because of novrs option\n");
1290 /* Check that it is NSR02 compliant */
1291 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1292 else if ((block = udf_vrs(sb, silent)) == -1)
1294 udf_debug("Failed to read byte 32768. Assuming open disc. Skipping validity check\n");
1295 if (!UDF_SB_LASTBLOCK(sb))
1296 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
1304 udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1306 struct anchorVolDescPtr *anchor;
1308 struct buffer_head *bh;
1309 long main_s, main_e, reserve_s, reserve_e;
1315 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
1316 if (UDF_SB_ANCHOR(sb)[i] && (bh = udf_read_tagged(sb,
1317 UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident)))
1319 anchor = (struct anchorVolDescPtr *)bh->b_data;
1321 /* Locate the main sequence */
1322 main_s = le32_to_cpu( anchor->mainVolDescSeqExt.extLocation );
1323 main_e = le32_to_cpu( anchor->mainVolDescSeqExt.extLength );
1324 main_e = main_e >> sb->s_blocksize_bits;
1327 /* Locate the reserve sequence */
1328 reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation);
1329 reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
1330 reserve_e = reserve_e >> sb->s_blocksize_bits;
1331 reserve_e += reserve_s;
1333 udf_release_data(bh);
1335 /* Process the main & reserve sequences */
1336 /* responsible for finding the PartitionDesc(s) */
1337 if (!(udf_process_sequence(sb, main_s, main_e, fileset) &&
1338 udf_process_sequence(sb, reserve_s, reserve_e, fileset)))
1345 if (i == ARRAY_SIZE(UDF_SB_ANCHOR(sb))) {
1346 udf_debug("No Anchor block found\n");
1349 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]);
1351 for (i=0; i<UDF_SB_NUMPARTS(sb); i++)
1353 switch UDF_SB_PARTTYPE(sb, i)
1355 case UDF_VIRTUAL_MAP15:
1356 case UDF_VIRTUAL_MAP20:
1360 if (!UDF_SB_LASTBLOCK(sb))
1362 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
1363 udf_find_anchor(sb);
1366 if (!UDF_SB_LASTBLOCK(sb))
1368 udf_debug("Unable to determine Lastblock (For Virtual Partition)\n");
1372 for (j=0; j<UDF_SB_NUMPARTS(sb); j++)
1375 UDF_SB_PARTVSN(sb,i) == UDF_SB_PARTVSN(sb,j) &&
1376 UDF_SB_PARTNUM(sb,i) == UDF_SB_PARTNUM(sb,j))
1378 ino.partitionReferenceNum = j;
1379 ino.logicalBlockNum = UDF_SB_LASTBLOCK(sb) -
1380 UDF_SB_PARTROOT(sb,j);
1385 if (j == UDF_SB_NUMPARTS(sb))
1388 if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino)))
1391 if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP15)
1393 UDF_SB_TYPEVIRT(sb,i).s_start_offset = udf_ext0_offset(UDF_SB_VAT(sb));
1394 UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size - 36) >> 2;
1396 else if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP20)
1398 struct buffer_head *bh = NULL;
1401 pos = udf_block_map(UDF_SB_VAT(sb), 0);
1402 bh = sb_bread(sb, pos);
1403 UDF_SB_TYPEVIRT(sb,i).s_start_offset =
1404 le16_to_cpu(((struct virtualAllocationTable20 *)bh->b_data + udf_ext0_offset(UDF_SB_VAT(sb)))->lengthHeader) +
1405 udf_ext0_offset(UDF_SB_VAT(sb));
1406 UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size -
1407 UDF_SB_TYPEVIRT(sb,i).s_start_offset) >> 2;
1408 udf_release_data(bh);
1410 UDF_SB_PARTROOT(sb,i) = udf_get_pblock(sb, 0, i, 0);
1411 UDF_SB_PARTLEN(sb,i) = UDF_SB_PARTLEN(sb,ino.partitionReferenceNum);
1418 static void udf_open_lvid(struct super_block *sb)
1420 if (UDF_SB_LVIDBH(sb))
1423 kernel_timestamp cpu_time;
1425 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1426 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1427 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1428 UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time);
1429 UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN;
1431 UDF_SB_LVID(sb)->descTag.descCRC =
1432 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1433 le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0));
1435 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
1436 for (i=0; i<16; i++)
1438 UDF_SB_LVID(sb)->descTag.tagChecksum +=
1439 ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i];
1441 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
1445 static void udf_close_lvid(struct super_block *sb)
1447 if (UDF_SB_LVIDBH(sb) &&
1448 UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN)
1451 kernel_timestamp cpu_time;
1453 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1454 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1455 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1456 UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time);
1457 if (UDF_MAX_WRITE_VERSION > le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev))
1458 UDF_SB_LVIDIU(sb)->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
1459 if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev))
1460 UDF_SB_LVIDIU(sb)->minUDFReadRev = cpu_to_le16(UDF_SB_UDFREV(sb));
1461 if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev))
1462 UDF_SB_LVIDIU(sb)->minUDFWriteRev = cpu_to_le16(UDF_SB_UDFREV(sb));
1463 UDF_SB_LVID(sb)->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
1465 UDF_SB_LVID(sb)->descTag.descCRC =
1466 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1467 le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0));
1469 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
1470 for (i=0; i<16; i++)
1472 UDF_SB_LVID(sb)->descTag.tagChecksum +=
1473 ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i];
1475 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
1483 * Complete the specified super block.
1486 * sb Pointer to superblock to complete - never NULL.
1487 * sb->s_dev Device to read suberblock from.
1488 * options Pointer to mount options.
1489 * silent Silent flag.
1492 * July 1, 1997 - Andrew E. Mileski
1493 * Written, tested, and released.
1495 static int udf_fill_super(struct super_block *sb, void *options, int silent)
1498 struct inode *inode=NULL;
1499 struct udf_options uopt;
1500 kernel_lb_addr rootdir, fileset;
1501 struct udf_sb_info *sbi;
1503 uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
1508 sbi = kmalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
1511 sb->s_fs_info = sbi;
1512 memset(UDF_SB(sb), 0x00, sizeof(struct udf_sb_info));
1514 mutex_init(&sbi->s_alloc_mutex);
1516 if (!udf_parse_options((char *)options, &uopt))
1519 if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
1520 uopt.flags & (1 << UDF_FLAG_NLS_MAP))
1522 udf_error(sb, "udf_read_super",
1523 "utf8 cannot be combined with iocharset\n");
1526 #ifdef CONFIG_UDF_NLS
1527 if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map)
1529 uopt.nls_map = load_nls_default();
1531 uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
1533 udf_debug("Using default NLS map\n");
1536 if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
1537 uopt.flags |= (1 << UDF_FLAG_UTF8);
1539 fileset.logicalBlockNum = 0xFFFFFFFF;
1540 fileset.partitionReferenceNum = 0xFFFF;
1542 UDF_SB(sb)->s_flags = uopt.flags;
1543 UDF_SB(sb)->s_uid = uopt.uid;
1544 UDF_SB(sb)->s_gid = uopt.gid;
1545 UDF_SB(sb)->s_umask = uopt.umask;
1546 UDF_SB(sb)->s_nls_map = uopt.nls_map;
1548 /* Set the block size for all transfers */
1549 if (!udf_set_blocksize(sb, uopt.blocksize))
1552 if ( uopt.session == 0xFFFFFFFF )
1553 UDF_SB_SESSION(sb) = udf_get_last_session(sb);
1555 UDF_SB_SESSION(sb) = uopt.session;
1557 udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb));
1559 UDF_SB_LASTBLOCK(sb) = uopt.lastblock;
1560 UDF_SB_ANCHOR(sb)[0] = UDF_SB_ANCHOR(sb)[1] = 0;
1561 UDF_SB_ANCHOR(sb)[2] = uopt.anchor;
1562 UDF_SB_ANCHOR(sb)[3] = 256;
1564 if (udf_check_valid(sb, uopt.novrs, silent)) /* read volume recognition sequences */
1566 printk("UDF-fs: No VRS found\n");
1570 udf_find_anchor(sb);
1572 /* Fill in the rest of the superblock */
1573 sb->s_op = &udf_sb_ops;
1576 sb->s_magic = UDF_SUPER_MAGIC;
1577 sb->s_time_gran = 1000;
1579 if (udf_load_partition(sb, &fileset))
1581 printk("UDF-fs: No partition found (1)\n");
1585 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb));
1587 if ( UDF_SB_LVIDBH(sb) )
1589 uint16_t minUDFReadRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev);
1590 uint16_t minUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
1591 /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */
1593 if (minUDFReadRev > UDF_MAX_READ_VERSION)
1595 printk("UDF-fs: minUDFReadRev=%x (max is %x)\n",
1596 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev),
1597 UDF_MAX_READ_VERSION);
1600 else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
1602 sb->s_flags |= MS_RDONLY;
1605 UDF_SB_UDFREV(sb) = minUDFWriteRev;
1607 if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
1608 UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
1609 if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
1610 UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
1613 if ( !UDF_SB_NUMPARTS(sb) )
1615 printk("UDF-fs: No partition found (2)\n");
1619 if ( udf_find_fileset(sb, &fileset, &rootdir) )
1621 printk("UDF-fs: No fileset found\n");
1627 kernel_timestamp ts;
1628 udf_time_to_stamp(&ts, UDF_SB_RECORDTIME(sb));
1629 udf_info("UDF %s (%s) Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1630 UDFFS_VERSION, UDFFS_DATE,
1631 UDF_SB_VOLIDENT(sb), ts.year, ts.month, ts.day, ts.hour, ts.minute,
1632 ts.typeAndTimezone);
1634 if (!(sb->s_flags & MS_RDONLY))
1637 /* Assign the root inode */
1638 /* assign inodes by physical block number */
1639 /* perhaps it's not extensible enough, but for now ... */
1640 inode = udf_iget(sb, rootdir);
1643 printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n",
1644 rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
1648 /* Allocate a dentry for the root inode */
1649 sb->s_root = d_alloc_root(inode);
1652 printk("UDF-fs: Couldn't allocate root dentry\n");
1656 sb->s_maxbytes = MAX_LFS_FILESIZE;
1661 iput(UDF_SB_VAT(sb));
1662 if (UDF_SB_NUMPARTS(sb))
1664 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
1665 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1666 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
1667 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
1668 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
1669 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace);
1670 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
1671 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace);
1672 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15)
1675 udf_release_data(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
1678 #ifdef CONFIG_UDF_NLS
1679 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1680 unload_nls(UDF_SB(sb)->s_nls_map);
1682 if (!(sb->s_flags & MS_RDONLY))
1684 udf_release_data(UDF_SB_LVIDBH(sb));
1687 sb->s_fs_info = NULL;
1691 void udf_error(struct super_block *sb, const char *function,
1692 const char *fmt, ...)
1696 if (!(sb->s_flags & MS_RDONLY))
1701 va_start(args, fmt);
1702 vsprintf(error_buf, fmt, args);
1704 printk (KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
1705 sb->s_id, function, error_buf);
1708 void udf_warning(struct super_block *sb, const char *function,
1709 const char *fmt, ...)
1713 va_start (args, fmt);
1714 vsprintf(error_buf, fmt, args);
1716 printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
1717 sb->s_id, function, error_buf);
1724 * Prepare for destruction of the superblock.
1727 * Called before the filesystem is unmounted.
1730 * July 1, 1997 - Andrew E. Mileski
1731 * Written, tested, and released.
1734 udf_put_super(struct super_block *sb)
1739 iput(UDF_SB_VAT(sb));
1740 if (UDF_SB_NUMPARTS(sb))
1742 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
1743 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1744 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
1745 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
1746 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
1747 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace);
1748 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
1749 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace);
1750 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15)
1753 udf_release_data(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
1756 #ifdef CONFIG_UDF_NLS
1757 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1758 unload_nls(UDF_SB(sb)->s_nls_map);
1760 if (!(sb->s_flags & MS_RDONLY))
1762 udf_release_data(UDF_SB_LVIDBH(sb));
1764 kfree(sb->s_fs_info);
1765 sb->s_fs_info = NULL;
1772 * Return info about the filesystem.
1775 * Called by sys_statfs()
1778 * July 1, 1997 - Andrew E. Mileski
1779 * Written, tested, and released.
1782 udf_statfs(struct dentry *dentry, struct kstatfs *buf)
1784 struct super_block *sb = dentry->d_sb;
1786 buf->f_type = UDF_SUPER_MAGIC;
1787 buf->f_bsize = sb->s_blocksize;
1788 buf->f_blocks = UDF_SB_PARTLEN(sb, UDF_SB_PARTITION(sb));
1789 buf->f_bfree = udf_count_free(sb);
1790 buf->f_bavail = buf->f_bfree;
1791 buf->f_files = (UDF_SB_LVIDBH(sb) ?
1792 (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) +
1793 le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) + buf->f_bfree;
1794 buf->f_ffree = buf->f_bfree;
1795 /* __kernel_fsid_t f_fsid */
1796 buf->f_namelen = UDF_NAME_LEN-2;
1801 static unsigned char udf_bitmap_lookup[16] = {
1802 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
1806 udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
1808 struct buffer_head *bh = NULL;
1809 unsigned int accum = 0;
1811 int block = 0, newblock;
1817 struct spaceBitmapDesc *bm;
1821 loc.logicalBlockNum = bitmap->s_extPosition;
1822 loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
1823 bh = udf_read_ptagged(sb, loc, 0, &ident);
1827 printk(KERN_ERR "udf: udf_count_free failed\n");
1830 else if (ident != TAG_IDENT_SBD)
1832 udf_release_data(bh);
1833 printk(KERN_ERR "udf: udf_count_free failed\n");
1837 bm = (struct spaceBitmapDesc *)bh->b_data;
1838 bytes = le32_to_cpu(bm->numOfBytes);
1839 index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
1840 ptr = (uint8_t *)bh->b_data;
1844 while ((bytes > 0) && (index < sb->s_blocksize))
1847 accum += udf_bitmap_lookup[ value & 0x0f ];
1848 accum += udf_bitmap_lookup[ value >> 4 ];
1854 udf_release_data(bh);
1855 newblock = udf_get_lb_pblock(sb, loc, ++block);
1856 bh = udf_tread(sb, newblock);
1859 udf_debug("read failed\n");
1863 ptr = (uint8_t *)bh->b_data;
1866 udf_release_data(bh);
1875 udf_count_free_table(struct super_block *sb, struct inode * table)
1877 unsigned int accum = 0;
1878 uint32_t extoffset, elen;
1879 kernel_lb_addr bloc, eloc;
1881 struct buffer_head *bh = NULL;
1885 bloc = UDF_I_LOCATION(table);
1886 extoffset = sizeof(struct unallocSpaceEntry);
1888 while ((etype = udf_next_aext(table, &bloc, &extoffset, &eloc, &elen, &bh, 1)) != -1)
1890 accum += (elen >> table->i_sb->s_blocksize_bits);
1892 udf_release_data(bh);
1900 udf_count_free(struct super_block *sb)
1902 unsigned int accum = 0;
1904 if (UDF_SB_LVIDBH(sb))
1906 if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) > UDF_SB_PARTITION(sb))
1908 accum = le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]);
1910 if (accum == 0xFFFFFFFF)
1918 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
1920 accum += udf_count_free_bitmap(sb,
1921 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_bitmap);
1923 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
1925 accum += udf_count_free_bitmap(sb,
1926 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_bitmap);
1931 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
1933 accum += udf_count_free_table(sb,
1934 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1936 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
1938 accum += udf_count_free_table(sb,
1939 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);