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 super_block *, struct kstatfs *);
96 /* UDF filesystem type */
97 static struct super_block *udf_get_sb(struct file_system_type *fs_type,
98 int flags, const char *dev_name, void *data)
100 return get_sb_bdev(fs_type, flags, dev_name, data, udf_fill_super);
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,
145 if (udf_inode_cachep == NULL)
150 static void destroy_inodecache(void)
152 if (kmem_cache_destroy(udf_inode_cachep))
153 printk(KERN_INFO "udf_inode_cache: not all structures were freed\n");
156 /* Superblock operations */
157 static struct super_operations udf_sb_ops = {
158 .alloc_inode = udf_alloc_inode,
159 .destroy_inode = udf_destroy_inode,
160 .write_inode = udf_write_inode,
161 .delete_inode = udf_delete_inode,
162 .clear_inode = udf_clear_inode,
163 .put_super = udf_put_super,
164 .write_super = udf_write_super,
165 .statfs = udf_statfs,
166 .remount_fs = udf_remount_fs,
172 unsigned int blocksize;
173 unsigned int session;
174 unsigned int lastblock;
177 unsigned short partition;
178 unsigned int fileset;
179 unsigned int rootdir;
184 struct nls_table *nls_map;
187 static int __init init_udf_fs(void)
190 err = init_inodecache();
193 err = register_filesystem(&udf_fstype);
198 destroy_inodecache();
203 static void __exit exit_udf_fs(void)
205 unregister_filesystem(&udf_fstype);
206 destroy_inodecache();
209 module_init(init_udf_fs)
210 module_exit(exit_udf_fs)
216 * Parse mount options.
219 * The following mount options are supported:
221 * gid= Set the default group.
222 * umask= Set the default umask.
223 * uid= Set the default user.
224 * bs= Set the block size.
225 * unhide Show otherwise hidden files.
226 * undelete Show deleted files in lists.
227 * adinicb Embed data in the inode (default)
228 * noadinicb Don't embed data in the inode
229 * shortad Use short ad's
230 * longad Use long ad's (default)
231 * nostrict Unset strict conformance
232 * iocharset= Set the NLS character set
234 * The remaining are for debugging and disaster recovery:
236 * novrs Skip volume sequence recognition
238 * The following expect a offset from 0.
240 * session= Set the CDROM session (default= last session)
241 * anchor= Override standard anchor location. (default= 256)
242 * volume= Override the VolumeDesc location. (unused)
243 * partition= Override the PartitionDesc location. (unused)
244 * lastblock= Set the last block of the filesystem/
246 * The following expect a offset from the partition root.
248 * fileset= Override the fileset block location. (unused)
249 * rootdir= Override the root directory location. (unused)
250 * WARNING: overriding the rootdir to a non-directory may
251 * yield highly unpredictable results.
254 * options Pointer to mount options string.
255 * uopts Pointer to mount options variable.
258 * <return> 1 Mount options parsed okay.
259 * <return> 0 Error parsing mount options.
262 * July 1, 1997 - Andrew E. Mileski
263 * Written, tested, and released.
267 Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete,
268 Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad,
269 Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock,
270 Opt_anchor, Opt_volume, Opt_partition, Opt_fileset,
271 Opt_rootdir, Opt_utf8, Opt_iocharset,
275 static match_table_t tokens = {
276 {Opt_novrs, "novrs"},
277 {Opt_nostrict, "nostrict"},
279 {Opt_unhide, "unhide"},
280 {Opt_undelete, "undelete"},
281 {Opt_noadinicb, "noadinicb"},
282 {Opt_adinicb, "adinicb"},
283 {Opt_shortad, "shortad"},
284 {Opt_longad, "longad"},
287 {Opt_umask, "umask=%o"},
288 {Opt_session, "session=%u"},
289 {Opt_lastblock, "lastblock=%u"},
290 {Opt_anchor, "anchor=%u"},
291 {Opt_volume, "volume=%u"},
292 {Opt_partition, "partition=%u"},
293 {Opt_fileset, "fileset=%u"},
294 {Opt_rootdir, "rootdir=%u"},
296 {Opt_iocharset, "iocharset=%s"},
301 udf_parse_options(char *options, struct udf_options *uopt)
307 uopt->blocksize = 2048;
308 uopt->partition = 0xFFFF;
309 uopt->session = 0xFFFFFFFF;
312 uopt->volume = 0xFFFFFFFF;
313 uopt->rootdir = 0xFFFFFFFF;
314 uopt->fileset = 0xFFFFFFFF;
315 uopt->nls_map = NULL;
320 while ((p = strsep(&options, ",")) != NULL)
322 substring_t args[MAX_OPT_ARGS];
327 token = match_token(p, tokens, args);
333 if (match_int(&args[0], &option))
335 uopt->blocksize = option;
338 uopt->flags |= (1 << UDF_FLAG_UNHIDE);
341 uopt->flags |= (1 << UDF_FLAG_UNDELETE);
344 uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
347 uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
350 uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
353 uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
356 if (match_int(args, &option))
361 if (match_int(args, &option))
366 if (match_octal(args, &option))
368 uopt->umask = option;
371 uopt->flags &= ~(1 << UDF_FLAG_STRICT);
374 if (match_int(args, &option))
376 uopt->session = option;
379 if (match_int(args, &option))
381 uopt->lastblock = option;
384 if (match_int(args, &option))
386 uopt->anchor = option;
389 if (match_int(args, &option))
391 uopt->volume = option;
394 if (match_int(args, &option))
396 uopt->partition = option;
399 if (match_int(args, &option))
401 uopt->fileset = option;
404 if (match_int(args, &option))
406 uopt->rootdir = option;
409 uopt->flags |= (1 << UDF_FLAG_UTF8);
411 #ifdef CONFIG_UDF_NLS
413 uopt->nls_map = load_nls(args[0].from);
414 uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
418 printk(KERN_ERR "udf: bad mount option \"%s\" "
419 "or missing value\n", p);
427 udf_write_super(struct super_block *sb)
430 if (!(sb->s_flags & MS_RDONLY))
437 udf_remount_fs(struct super_block *sb, int *flags, char *options)
439 struct udf_options uopt;
441 uopt.flags = UDF_SB(sb)->s_flags ;
442 uopt.uid = UDF_SB(sb)->s_uid ;
443 uopt.gid = UDF_SB(sb)->s_gid ;
444 uopt.umask = UDF_SB(sb)->s_umask ;
446 if ( !udf_parse_options(options, &uopt) )
449 UDF_SB(sb)->s_flags = uopt.flags;
450 UDF_SB(sb)->s_uid = uopt.uid;
451 UDF_SB(sb)->s_gid = uopt.gid;
452 UDF_SB(sb)->s_umask = uopt.umask;
454 if (UDF_SB_LVIDBH(sb)) {
455 int write_rev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
456 if (write_rev > UDF_MAX_WRITE_VERSION)
460 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
462 if (*flags & MS_RDONLY)
474 * Set the block size to be used in all transfers.
477 * To allow room for a DMA transfer, it is best to guess big when unsure.
478 * This routine picks 2048 bytes as the blocksize when guessing. This
479 * should be adequate until devices with larger block sizes become common.
481 * Note that the Linux kernel can currently only deal with blocksizes of
482 * 512, 1024, 2048, 4096, and 8192 bytes.
485 * sb Pointer to _locked_ superblock.
488 * sb->s_blocksize Blocksize.
489 * sb->s_blocksize_bits log2 of blocksize.
490 * <return> 0 Blocksize is valid.
491 * <return> 1 Blocksize is invalid.
494 * July 1, 1997 - Andrew E. Mileski
495 * Written, tested, and released.
498 udf_set_blocksize(struct super_block *sb, int bsize)
500 if (!sb_min_blocksize(sb, bsize)) {
501 udf_debug("Bad block size (%d)\n", bsize);
502 printk(KERN_ERR "udf: bad block size (%d)\n", bsize);
505 return sb->s_blocksize;
509 udf_vrs(struct super_block *sb, int silent)
511 struct volStructDesc *vsd = NULL;
514 struct buffer_head *bh = NULL;
519 /* Block size must be a multiple of 512 */
520 if (sb->s_blocksize & 511)
523 if (sb->s_blocksize < sizeof(struct volStructDesc))
524 sectorsize = sizeof(struct volStructDesc);
526 sectorsize = sb->s_blocksize;
528 sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits);
530 udf_debug("Starting at sector %u (%ld byte sectors)\n",
531 (sector >> sb->s_blocksize_bits), sb->s_blocksize);
532 /* Process the sequence (if applicable) */
533 for (;!nsr02 && !nsr03; sector += sectorsize)
536 bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
540 /* Look for ISO descriptors */
541 vsd = (struct volStructDesc *)(bh->b_data +
542 (sector & (sb->s_blocksize - 1)));
544 if (vsd->stdIdent[0] == 0)
546 udf_release_data(bh);
549 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN))
552 switch (vsd->structType)
555 udf_debug("ISO9660 Boot Record found\n");
558 udf_debug("ISO9660 Primary Volume Descriptor found\n");
561 udf_debug("ISO9660 Supplementary Volume Descriptor found\n");
564 udf_debug("ISO9660 Volume Partition Descriptor found\n");
567 udf_debug("ISO9660 Volume Descriptor Set Terminator found\n");
570 udf_debug("ISO9660 VRS (%u) found\n", vsd->structType);
574 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN))
577 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01, VSD_STD_ID_LEN))
579 udf_release_data(bh);
582 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN))
586 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN))
590 udf_release_data(bh);
597 else if (sector - (UDF_SB_SESSION(sb) << sb->s_blocksize_bits) == 32768)
607 * Find an anchor volume descriptor.
610 * sb Pointer to _locked_ superblock.
611 * lastblock Last block on media.
614 * <return> 1 if not found, 0 if ok
617 * July 1, 1997 - Andrew E. Mileski
618 * Written, tested, and released.
621 udf_find_anchor(struct super_block *sb)
623 int lastblock = UDF_SB_LASTBLOCK(sb);
624 struct buffer_head *bh = NULL;
631 int varlastblock = udf_variable_to_fixed(lastblock);
632 int last[] = { lastblock, lastblock - 2,
633 lastblock - 150, lastblock - 152,
634 varlastblock, varlastblock - 2,
635 varlastblock - 150, varlastblock - 152 };
639 /* Search for an anchor volume descriptor pointer */
641 /* according to spec, anchor is in either:
645 * however, if the disc isn't closed, it could be 512 */
647 for (i=0; (!lastblock && i<sizeof(last)/sizeof(int)); i++)
649 if (last[i] < 0 || !(bh = sb_bread(sb, last[i])))
651 ident = location = 0;
655 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
656 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
657 udf_release_data(bh);
660 if (ident == TAG_IDENT_AVDP)
662 if (location == last[i] - UDF_SB_SESSION(sb))
664 lastblock = UDF_SB_ANCHOR(sb)[0] = last[i] - UDF_SB_SESSION(sb);
665 UDF_SB_ANCHOR(sb)[1] = last[i] - 256 - UDF_SB_SESSION(sb);
667 else if (location == udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb))
669 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
670 lastblock = UDF_SB_ANCHOR(sb)[0] = udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb);
671 UDF_SB_ANCHOR(sb)[1] = lastblock - 256 - UDF_SB_SESSION(sb);
674 udf_debug("Anchor found at block %d, location mismatch %d.\n",
677 else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE)
680 UDF_SB_ANCHOR(sb)[3] = 512;
684 if (last[i] < 256 || !(bh = sb_bread(sb, last[i] - 256)))
686 ident = location = 0;
690 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
691 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
692 udf_release_data(bh);
695 if (ident == TAG_IDENT_AVDP &&
696 location == last[i] - 256 - UDF_SB_SESSION(sb))
699 UDF_SB_ANCHOR(sb)[1] = last[i] - 256;
703 if (last[i] < 312 + UDF_SB_SESSION(sb) || !(bh = sb_bread(sb, last[i] - 312 - UDF_SB_SESSION(sb))))
705 ident = location = 0;
709 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
710 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
711 udf_release_data(bh);
714 if (ident == TAG_IDENT_AVDP &&
715 location == udf_variable_to_fixed(last[i]) - 256)
717 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
718 lastblock = udf_variable_to_fixed(last[i]);
719 UDF_SB_ANCHOR(sb)[1] = lastblock - 256;
728 /* We havn't found the lastblock. check 312 */
729 if ((bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb))))
731 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
732 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
733 udf_release_data(bh);
735 if (ident == TAG_IDENT_AVDP && location == 256)
736 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
740 for (i=0; i<sizeof(UDF_SB_ANCHOR(sb))/sizeof(int); i++)
742 if (UDF_SB_ANCHOR(sb)[i])
744 if (!(bh = udf_read_tagged(sb,
745 UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident)))
747 UDF_SB_ANCHOR(sb)[i] = 0;
751 udf_release_data(bh);
752 if ((ident != TAG_IDENT_AVDP) && (i ||
753 (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE)))
755 UDF_SB_ANCHOR(sb)[i] = 0;
761 UDF_SB_LASTBLOCK(sb) = lastblock;
765 udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, kernel_lb_addr *root)
767 struct buffer_head *bh = NULL;
771 if (fileset->logicalBlockNum != 0xFFFFFFFF ||
772 fileset->partitionReferenceNum != 0xFFFF)
774 bh = udf_read_ptagged(sb, *fileset, 0, &ident);
778 else if (ident != TAG_IDENT_FSD)
780 udf_release_data(bh);
786 if (!bh) /* Search backwards through the partitions */
788 kernel_lb_addr newfileset;
792 for (newfileset.partitionReferenceNum=UDF_SB_NUMPARTS(sb)-1;
793 (newfileset.partitionReferenceNum != 0xFFFF &&
794 fileset->logicalBlockNum == 0xFFFFFFFF &&
795 fileset->partitionReferenceNum == 0xFFFF);
796 newfileset.partitionReferenceNum--)
798 lastblock = UDF_SB_PARTLEN(sb, newfileset.partitionReferenceNum);
799 newfileset.logicalBlockNum = 0;
803 bh = udf_read_ptagged(sb, newfileset, 0, &ident);
806 newfileset.logicalBlockNum ++;
814 struct spaceBitmapDesc *sp;
815 sp = (struct spaceBitmapDesc *)bh->b_data;
816 newfileset.logicalBlockNum += 1 +
817 ((le32_to_cpu(sp->numOfBytes) + sizeof(struct spaceBitmapDesc) - 1)
818 >> sb->s_blocksize_bits);
819 udf_release_data(bh);
824 *fileset = newfileset;
829 newfileset.logicalBlockNum ++;
830 udf_release_data(bh);
836 while (newfileset.logicalBlockNum < lastblock &&
837 fileset->logicalBlockNum == 0xFFFFFFFF &&
838 fileset->partitionReferenceNum == 0xFFFF);
842 if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
843 fileset->partitionReferenceNum != 0xFFFF) && bh)
845 udf_debug("Fileset at block=%d, partition=%d\n",
846 fileset->logicalBlockNum, fileset->partitionReferenceNum);
848 UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum;
849 udf_load_fileset(sb, bh, root);
850 udf_release_data(bh);
857 udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
859 struct primaryVolDesc *pvoldesc;
865 pvoldesc = (struct primaryVolDesc *)bh->b_data;
867 if ( udf_stamp_to_time(&recording, &recording_usec,
868 lets_to_cpu(pvoldesc->recordingDateAndTime)) )
871 ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
872 udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n",
873 recording, recording_usec,
874 ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.typeAndTimezone);
875 UDF_SB_RECORDTIME(sb).tv_sec = recording;
876 UDF_SB_RECORDTIME(sb).tv_nsec = recording_usec * 1000;
879 if ( !udf_build_ustr(&instr, pvoldesc->volIdent, 32) )
881 if (udf_CS0toUTF8(&outstr, &instr))
883 strncpy( UDF_SB_VOLIDENT(sb), outstr.u_name,
884 outstr.u_len > 31 ? 31 : outstr.u_len);
885 udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb));
889 if ( !udf_build_ustr(&instr, pvoldesc->volSetIdent, 128) )
891 if (udf_CS0toUTF8(&outstr, &instr))
892 udf_debug("volSetIdent[] = '%s'\n", outstr.u_name);
897 udf_load_fileset(struct super_block *sb, struct buffer_head *bh, kernel_lb_addr *root)
899 struct fileSetDesc *fset;
901 fset = (struct fileSetDesc *)bh->b_data;
903 *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
905 UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum);
907 udf_debug("Rootdir at block=%d, partition=%d\n",
908 root->logicalBlockNum, root->partitionReferenceNum);
912 udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
914 struct partitionDesc *p;
917 p = (struct partitionDesc *)bh->b_data;
919 for (i=0; i<UDF_SB_NUMPARTS(sb); i++)
921 udf_debug("Searching map: (%d == %d)\n",
922 UDF_SB_PARTMAPS(sb)[i].s_partition_num, le16_to_cpu(p->partitionNumber));
923 if (UDF_SB_PARTMAPS(sb)[i].s_partition_num == le16_to_cpu(p->partitionNumber))
925 UDF_SB_PARTLEN(sb,i) = le32_to_cpu(p->partitionLength); /* blocks */
926 UDF_SB_PARTROOT(sb,i) = le32_to_cpu(p->partitionStartingLocation);
927 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY)
928 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_READ_ONLY;
929 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_WRITE_ONCE)
930 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_WRITE_ONCE;
931 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_REWRITABLE)
932 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_REWRITABLE;
933 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_OVERWRITABLE)
934 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_OVERWRITABLE;
936 if (!strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) ||
937 !strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03))
939 struct partitionHeaderDesc *phd;
941 phd = (struct partitionHeaderDesc *)(p->partitionContentsUse);
942 if (phd->unallocSpaceTable.extLength)
944 kernel_lb_addr loc = { le32_to_cpu(phd->unallocSpaceTable.extPosition), i };
946 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table =
948 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_TABLE;
949 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
950 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table->i_ino);
952 if (phd->unallocSpaceBitmap.extLength)
954 UDF_SB_ALLOC_BITMAP(sb, i, s_uspace);
955 if (UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap != NULL)
957 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extLength =
958 le32_to_cpu(phd->unallocSpaceBitmap.extLength);
959 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition =
960 le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
961 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_BITMAP;
962 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
963 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition);
966 if (phd->partitionIntegrityTable.extLength)
967 udf_debug("partitionIntegrityTable (part %d)\n", i);
968 if (phd->freedSpaceTable.extLength)
970 kernel_lb_addr loc = { le32_to_cpu(phd->freedSpaceTable.extPosition), i };
972 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table =
974 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_TABLE;
975 udf_debug("freedSpaceTable (part %d) @ %ld\n",
976 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table->i_ino);
978 if (phd->freedSpaceBitmap.extLength)
980 UDF_SB_ALLOC_BITMAP(sb, i, s_fspace);
981 if (UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap != NULL)
983 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extLength =
984 le32_to_cpu(phd->freedSpaceBitmap.extLength);
985 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition =
986 le32_to_cpu(phd->freedSpaceBitmap.extPosition);
987 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_BITMAP;
988 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
989 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition);
996 if (i == UDF_SB_NUMPARTS(sb))
998 udf_debug("Partition (%d) not found in partition map\n", le16_to_cpu(p->partitionNumber));
1002 udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
1003 le16_to_cpu(p->partitionNumber), i, UDF_SB_PARTTYPE(sb,i),
1004 UDF_SB_PARTROOT(sb,i), UDF_SB_PARTLEN(sb,i));
1009 udf_load_logicalvol(struct super_block *sb, struct buffer_head * bh, kernel_lb_addr *fileset)
1011 struct logicalVolDesc *lvd;
1015 lvd = (struct logicalVolDesc *)bh->b_data;
1017 UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps));
1020 i<UDF_SB_NUMPARTS(sb) && offset<le32_to_cpu(lvd->mapTableLength);
1021 i++,offset+=((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength)
1023 type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType;
1026 struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]);
1027 UDF_SB_PARTTYPE(sb,i) = UDF_TYPE1_MAP15;
1028 UDF_SB_PARTVSN(sb,i) = le16_to_cpu(gpm1->volSeqNum);
1029 UDF_SB_PARTNUM(sb,i) = le16_to_cpu(gpm1->partitionNum);
1030 UDF_SB_PARTFUNC(sb,i) = NULL;
1034 struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]);
1035 if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL)))
1037 if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0150)
1039 UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP15;
1040 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt15;
1042 else if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0200)
1044 UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP20;
1045 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt20;
1048 else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE)))
1052 struct sparingTable *st;
1053 struct sparablePartitionMap *spm = (struct sparablePartitionMap *)&(lvd->partitionMaps[offset]);
1055 UDF_SB_PARTTYPE(sb,i) = UDF_SPARABLE_MAP15;
1056 UDF_SB_TYPESPAR(sb,i).s_packet_len = le16_to_cpu(spm->packetLength);
1057 for (j=0; j<spm->numSparingTables; j++)
1059 loc = le32_to_cpu(spm->locSparingTable[j]);
1060 UDF_SB_TYPESPAR(sb,i).s_spar_map[j] =
1061 udf_read_tagged(sb, loc, loc, &ident);
1062 if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL)
1064 st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,i).s_spar_map[j]->b_data;
1066 strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING)))
1068 udf_release_data(UDF_SB_TYPESPAR(sb,i).s_spar_map[j]);
1069 UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = NULL;
1073 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_spar15;
1077 udf_debug("Unknown ident: %s\n", upm2->partIdent.ident);
1080 UDF_SB_PARTVSN(sb,i) = le16_to_cpu(upm2->volSeqNum);
1081 UDF_SB_PARTNUM(sb,i) = le16_to_cpu(upm2->partitionNum);
1083 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1084 i, UDF_SB_PARTNUM(sb,i), type, UDF_SB_PARTVSN(sb,i));
1089 long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]);
1091 *fileset = lelb_to_cpu(la->extLocation);
1092 udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
1093 fileset->logicalBlockNum,
1094 fileset->partitionReferenceNum);
1096 if (lvd->integritySeqExt.extLength)
1097 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
1102 * udf_load_logicalvolint
1106 udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
1108 struct buffer_head *bh = NULL;
1111 while (loc.extLength > 0 &&
1112 (bh = udf_read_tagged(sb, loc.extLocation,
1113 loc.extLocation, &ident)) &&
1114 ident == TAG_IDENT_LVID)
1116 UDF_SB_LVIDBH(sb) = bh;
1118 if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength)
1119 udf_load_logicalvolint(sb, leea_to_cpu(UDF_SB_LVID(sb)->nextIntegrityExt));
1121 if (UDF_SB_LVIDBH(sb) != bh)
1122 udf_release_data(bh);
1123 loc.extLength -= sb->s_blocksize;
1126 if (UDF_SB_LVIDBH(sb) != bh)
1127 udf_release_data(bh);
1131 * udf_process_sequence
1134 * Process a main/reserve volume descriptor sequence.
1137 * sb Pointer to _locked_ superblock.
1138 * block First block of first extent of the sequence.
1139 * lastblock Lastblock of first extent of the sequence.
1142 * July 1, 1997 - Andrew E. Mileski
1143 * Written, tested, and released.
1146 udf_process_sequence(struct super_block *sb, long block, long lastblock, kernel_lb_addr *fileset)
1148 struct buffer_head *bh = NULL;
1149 struct udf_vds_record vds[VDS_POS_LENGTH];
1150 struct generic_desc *gd;
1151 struct volDescPtr *vdp;
1156 long next_s = 0, next_e = 0;
1158 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
1160 /* Read the main descriptor sequence */
1161 for (;(!done && block <= lastblock); block++)
1164 bh = udf_read_tagged(sb, block, block, &ident);
1168 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1169 gd = (struct generic_desc *)bh->b_data;
1170 vdsn = le32_to_cpu(gd->volDescSeqNum);
1173 case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
1174 if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum)
1176 vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn;
1177 vds[VDS_POS_PRIMARY_VOL_DESC].block = block;
1180 case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
1181 if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum)
1183 vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn;
1184 vds[VDS_POS_VOL_DESC_PTR].block = block;
1186 vdp = (struct volDescPtr *)bh->b_data;
1187 next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation);
1188 next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength);
1189 next_e = next_e >> sb->s_blocksize_bits;
1193 case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
1194 if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum)
1196 vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn;
1197 vds[VDS_POS_IMP_USE_VOL_DESC].block = block;
1200 case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
1201 if (!vds[VDS_POS_PARTITION_DESC].block)
1202 vds[VDS_POS_PARTITION_DESC].block = block;
1204 case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
1205 if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum)
1207 vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn;
1208 vds[VDS_POS_LOGICAL_VOL_DESC].block = block;
1211 case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
1212 if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum)
1214 vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn;
1215 vds[VDS_POS_UNALLOC_SPACE_DESC].block = block;
1218 case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
1219 vds[VDS_POS_TERMINATING_DESC].block = block;
1224 next_s = next_e = 0;
1230 udf_release_data(bh);
1232 for (i=0; i<VDS_POS_LENGTH; i++)
1236 bh = udf_read_tagged(sb, vds[i].block, vds[i].block, &ident);
1238 if (i == VDS_POS_PRIMARY_VOL_DESC)
1239 udf_load_pvoldesc(sb, bh);
1240 else if (i == VDS_POS_LOGICAL_VOL_DESC)
1241 udf_load_logicalvol(sb, bh, fileset);
1242 else if (i == VDS_POS_PARTITION_DESC)
1244 struct buffer_head *bh2 = NULL;
1245 udf_load_partdesc(sb, bh);
1246 for (j=vds[i].block+1; j<vds[VDS_POS_TERMINATING_DESC].block; j++)
1248 bh2 = udf_read_tagged(sb, j, j, &ident);
1249 gd = (struct generic_desc *)bh2->b_data;
1250 if (ident == TAG_IDENT_PD)
1251 udf_load_partdesc(sb, bh2);
1252 udf_release_data(bh2);
1255 udf_release_data(bh);
1266 udf_check_valid(struct super_block *sb, int novrs, int silent)
1272 udf_debug("Validity check skipped because of novrs option\n");
1275 /* Check that it is NSR02 compliant */
1276 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1277 else if ((block = udf_vrs(sb, silent)) == -1)
1279 udf_debug("Failed to read byte 32768. Assuming open disc. Skipping validity check\n");
1280 if (!UDF_SB_LASTBLOCK(sb))
1281 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
1289 udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1291 struct anchorVolDescPtr *anchor;
1293 struct buffer_head *bh;
1294 long main_s, main_e, reserve_s, reserve_e;
1300 for (i=0; i<sizeof(UDF_SB_ANCHOR(sb))/sizeof(int); i++)
1302 if (UDF_SB_ANCHOR(sb)[i] && (bh = udf_read_tagged(sb,
1303 UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident)))
1305 anchor = (struct anchorVolDescPtr *)bh->b_data;
1307 /* Locate the main sequence */
1308 main_s = le32_to_cpu( anchor->mainVolDescSeqExt.extLocation );
1309 main_e = le32_to_cpu( anchor->mainVolDescSeqExt.extLength );
1310 main_e = main_e >> sb->s_blocksize_bits;
1313 /* Locate the reserve sequence */
1314 reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation);
1315 reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
1316 reserve_e = reserve_e >> sb->s_blocksize_bits;
1317 reserve_e += reserve_s;
1319 udf_release_data(bh);
1321 /* Process the main & reserve sequences */
1322 /* responsible for finding the PartitionDesc(s) */
1323 if (!(udf_process_sequence(sb, main_s, main_e, fileset) &&
1324 udf_process_sequence(sb, reserve_s, reserve_e, fileset)))
1331 if (i == sizeof(UDF_SB_ANCHOR(sb))/sizeof(int))
1333 udf_debug("No Anchor block found\n");
1337 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]);
1339 for (i=0; i<UDF_SB_NUMPARTS(sb); i++)
1341 switch UDF_SB_PARTTYPE(sb, i)
1343 case UDF_VIRTUAL_MAP15:
1344 case UDF_VIRTUAL_MAP20:
1348 if (!UDF_SB_LASTBLOCK(sb))
1350 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
1351 udf_find_anchor(sb);
1354 if (!UDF_SB_LASTBLOCK(sb))
1356 udf_debug("Unable to determine Lastblock (For Virtual Partition)\n");
1360 for (j=0; j<UDF_SB_NUMPARTS(sb); j++)
1363 UDF_SB_PARTVSN(sb,i) == UDF_SB_PARTVSN(sb,j) &&
1364 UDF_SB_PARTNUM(sb,i) == UDF_SB_PARTNUM(sb,j))
1366 ino.partitionReferenceNum = j;
1367 ino.logicalBlockNum = UDF_SB_LASTBLOCK(sb) -
1368 UDF_SB_PARTROOT(sb,j);
1373 if (j == UDF_SB_NUMPARTS(sb))
1376 if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino)))
1379 if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP15)
1381 UDF_SB_TYPEVIRT(sb,i).s_start_offset = udf_ext0_offset(UDF_SB_VAT(sb));
1382 UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size - 36) >> 2;
1384 else if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP20)
1386 struct buffer_head *bh = NULL;
1389 pos = udf_block_map(UDF_SB_VAT(sb), 0);
1390 bh = sb_bread(sb, pos);
1391 UDF_SB_TYPEVIRT(sb,i).s_start_offset =
1392 le16_to_cpu(((struct virtualAllocationTable20 *)bh->b_data + udf_ext0_offset(UDF_SB_VAT(sb)))->lengthHeader) +
1393 udf_ext0_offset(UDF_SB_VAT(sb));
1394 UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size -
1395 UDF_SB_TYPEVIRT(sb,i).s_start_offset) >> 2;
1396 udf_release_data(bh);
1398 UDF_SB_PARTROOT(sb,i) = udf_get_pblock(sb, 0, i, 0);
1399 UDF_SB_PARTLEN(sb,i) = UDF_SB_PARTLEN(sb,ino.partitionReferenceNum);
1406 static void udf_open_lvid(struct super_block *sb)
1408 if (UDF_SB_LVIDBH(sb))
1411 kernel_timestamp cpu_time;
1413 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1414 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1415 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1416 UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time);
1417 UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN;
1419 UDF_SB_LVID(sb)->descTag.descCRC =
1420 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1421 le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0));
1423 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
1424 for (i=0; i<16; i++)
1426 UDF_SB_LVID(sb)->descTag.tagChecksum +=
1427 ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i];
1429 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
1433 static void udf_close_lvid(struct super_block *sb)
1435 if (UDF_SB_LVIDBH(sb) &&
1436 UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN)
1439 kernel_timestamp cpu_time;
1441 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1442 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1443 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1444 UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time);
1445 if (UDF_MAX_WRITE_VERSION > le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev))
1446 UDF_SB_LVIDIU(sb)->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
1447 if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev))
1448 UDF_SB_LVIDIU(sb)->minUDFReadRev = cpu_to_le16(UDF_SB_UDFREV(sb));
1449 if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev))
1450 UDF_SB_LVIDIU(sb)->minUDFWriteRev = cpu_to_le16(UDF_SB_UDFREV(sb));
1451 UDF_SB_LVID(sb)->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
1453 UDF_SB_LVID(sb)->descTag.descCRC =
1454 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1455 le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0));
1457 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
1458 for (i=0; i<16; i++)
1460 UDF_SB_LVID(sb)->descTag.tagChecksum +=
1461 ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i];
1463 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
1471 * Complete the specified super block.
1474 * sb Pointer to superblock to complete - never NULL.
1475 * sb->s_dev Device to read suberblock from.
1476 * options Pointer to mount options.
1477 * silent Silent flag.
1480 * July 1, 1997 - Andrew E. Mileski
1481 * Written, tested, and released.
1483 static int udf_fill_super(struct super_block *sb, void *options, int silent)
1486 struct inode *inode=NULL;
1487 struct udf_options uopt;
1488 kernel_lb_addr rootdir, fileset;
1489 struct udf_sb_info *sbi;
1491 uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
1496 sbi = kmalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
1499 sb->s_fs_info = sbi;
1500 memset(UDF_SB(sb), 0x00, sizeof(struct udf_sb_info));
1502 init_MUTEX(&sbi->s_alloc_sem);
1504 if (!udf_parse_options((char *)options, &uopt))
1507 if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
1508 uopt.flags & (1 << UDF_FLAG_NLS_MAP))
1510 udf_error(sb, "udf_read_super",
1511 "utf8 cannot be combined with iocharset\n");
1514 #ifdef CONFIG_UDF_NLS
1515 if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map)
1517 uopt.nls_map = load_nls_default();
1519 uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
1521 udf_debug("Using default NLS map\n");
1524 if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
1525 uopt.flags |= (1 << UDF_FLAG_UTF8);
1527 fileset.logicalBlockNum = 0xFFFFFFFF;
1528 fileset.partitionReferenceNum = 0xFFFF;
1530 UDF_SB(sb)->s_flags = uopt.flags;
1531 UDF_SB(sb)->s_uid = uopt.uid;
1532 UDF_SB(sb)->s_gid = uopt.gid;
1533 UDF_SB(sb)->s_umask = uopt.umask;
1534 UDF_SB(sb)->s_nls_map = uopt.nls_map;
1536 /* Set the block size for all transfers */
1537 if (!udf_set_blocksize(sb, uopt.blocksize))
1540 if ( uopt.session == 0xFFFFFFFF )
1541 UDF_SB_SESSION(sb) = udf_get_last_session(sb);
1543 UDF_SB_SESSION(sb) = uopt.session;
1545 udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb));
1547 UDF_SB_LASTBLOCK(sb) = uopt.lastblock;
1548 UDF_SB_ANCHOR(sb)[0] = UDF_SB_ANCHOR(sb)[1] = 0;
1549 UDF_SB_ANCHOR(sb)[2] = uopt.anchor;
1550 UDF_SB_ANCHOR(sb)[3] = 256;
1552 if (udf_check_valid(sb, uopt.novrs, silent)) /* read volume recognition sequences */
1554 printk("UDF-fs: No VRS found\n");
1558 udf_find_anchor(sb);
1560 /* Fill in the rest of the superblock */
1561 sb->s_op = &udf_sb_ops;
1564 sb->s_magic = UDF_SUPER_MAGIC;
1565 sb->s_time_gran = 1000;
1567 if (udf_load_partition(sb, &fileset))
1569 printk("UDF-fs: No partition found (1)\n");
1573 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb));
1575 if ( UDF_SB_LVIDBH(sb) )
1577 uint16_t minUDFReadRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev);
1578 uint16_t minUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
1579 /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */
1581 if (minUDFReadRev > UDF_MAX_READ_VERSION)
1583 printk("UDF-fs: minUDFReadRev=%x (max is %x)\n",
1584 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev),
1585 UDF_MAX_READ_VERSION);
1588 else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
1590 sb->s_flags |= MS_RDONLY;
1593 UDF_SB_UDFREV(sb) = minUDFWriteRev;
1595 if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
1596 UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
1597 if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
1598 UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
1601 if ( !UDF_SB_NUMPARTS(sb) )
1603 printk("UDF-fs: No partition found (2)\n");
1607 if ( udf_find_fileset(sb, &fileset, &rootdir) )
1609 printk("UDF-fs: No fileset found\n");
1615 kernel_timestamp ts;
1616 udf_time_to_stamp(&ts, UDF_SB_RECORDTIME(sb));
1617 udf_info("UDF %s (%s) Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1618 UDFFS_VERSION, UDFFS_DATE,
1619 UDF_SB_VOLIDENT(sb), ts.year, ts.month, ts.day, ts.hour, ts.minute,
1620 ts.typeAndTimezone);
1622 if (!(sb->s_flags & MS_RDONLY))
1625 /* Assign the root inode */
1626 /* assign inodes by physical block number */
1627 /* perhaps it's not extensible enough, but for now ... */
1628 inode = udf_iget(sb, rootdir);
1631 printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n",
1632 rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
1636 /* Allocate a dentry for the root inode */
1637 sb->s_root = d_alloc_root(inode);
1640 printk("UDF-fs: Couldn't allocate root dentry\n");
1644 sb->s_maxbytes = MAX_LFS_FILESIZE;
1649 iput(UDF_SB_VAT(sb));
1650 if (UDF_SB_NUMPARTS(sb))
1652 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
1653 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1654 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
1655 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
1656 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
1657 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace);
1658 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
1659 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace);
1660 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15)
1663 udf_release_data(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
1666 #ifdef CONFIG_UDF_NLS
1667 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1668 unload_nls(UDF_SB(sb)->s_nls_map);
1670 if (!(sb->s_flags & MS_RDONLY))
1672 udf_release_data(UDF_SB_LVIDBH(sb));
1675 sb->s_fs_info = NULL;
1679 void udf_error(struct super_block *sb, const char *function,
1680 const char *fmt, ...)
1684 if (!(sb->s_flags & MS_RDONLY))
1689 va_start(args, fmt);
1690 vsprintf(error_buf, fmt, args);
1692 printk (KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
1693 sb->s_id, function, error_buf);
1696 void udf_warning(struct super_block *sb, const char *function,
1697 const char *fmt, ...)
1701 va_start (args, fmt);
1702 vsprintf(error_buf, fmt, args);
1704 printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
1705 sb->s_id, function, error_buf);
1712 * Prepare for destruction of the superblock.
1715 * Called before the filesystem is unmounted.
1718 * July 1, 1997 - Andrew E. Mileski
1719 * Written, tested, and released.
1722 udf_put_super(struct super_block *sb)
1727 iput(UDF_SB_VAT(sb));
1728 if (UDF_SB_NUMPARTS(sb))
1730 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
1731 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1732 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
1733 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
1734 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
1735 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace);
1736 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
1737 UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace);
1738 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15)
1741 udf_release_data(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
1744 #ifdef CONFIG_UDF_NLS
1745 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1746 unload_nls(UDF_SB(sb)->s_nls_map);
1748 if (!(sb->s_flags & MS_RDONLY))
1750 udf_release_data(UDF_SB_LVIDBH(sb));
1752 kfree(sb->s_fs_info);
1753 sb->s_fs_info = NULL;
1760 * Return info about the filesystem.
1763 * Called by sys_statfs()
1766 * July 1, 1997 - Andrew E. Mileski
1767 * Written, tested, and released.
1770 udf_statfs(struct super_block *sb, struct kstatfs *buf)
1772 buf->f_type = UDF_SUPER_MAGIC;
1773 buf->f_bsize = sb->s_blocksize;
1774 buf->f_blocks = UDF_SB_PARTLEN(sb, UDF_SB_PARTITION(sb));
1775 buf->f_bfree = udf_count_free(sb);
1776 buf->f_bavail = buf->f_bfree;
1777 buf->f_files = (UDF_SB_LVIDBH(sb) ?
1778 (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) +
1779 le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) + buf->f_bfree;
1780 buf->f_ffree = buf->f_bfree;
1781 /* __kernel_fsid_t f_fsid */
1782 buf->f_namelen = UDF_NAME_LEN-2;
1787 static unsigned char udf_bitmap_lookup[16] = {
1788 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
1792 udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
1794 struct buffer_head *bh = NULL;
1795 unsigned int accum = 0;
1797 int block = 0, newblock;
1803 struct spaceBitmapDesc *bm;
1807 loc.logicalBlockNum = bitmap->s_extPosition;
1808 loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
1809 bh = udf_read_ptagged(sb, loc, 0, &ident);
1813 printk(KERN_ERR "udf: udf_count_free failed\n");
1816 else if (ident != TAG_IDENT_SBD)
1818 udf_release_data(bh);
1819 printk(KERN_ERR "udf: udf_count_free failed\n");
1823 bm = (struct spaceBitmapDesc *)bh->b_data;
1824 bytes = le32_to_cpu(bm->numOfBytes);
1825 index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
1826 ptr = (uint8_t *)bh->b_data;
1830 while ((bytes > 0) && (index < sb->s_blocksize))
1833 accum += udf_bitmap_lookup[ value & 0x0f ];
1834 accum += udf_bitmap_lookup[ value >> 4 ];
1840 udf_release_data(bh);
1841 newblock = udf_get_lb_pblock(sb, loc, ++block);
1842 bh = udf_tread(sb, newblock);
1845 udf_debug("read failed\n");
1849 ptr = (uint8_t *)bh->b_data;
1852 udf_release_data(bh);
1861 udf_count_free_table(struct super_block *sb, struct inode * table)
1863 unsigned int accum = 0;
1864 uint32_t extoffset, elen;
1865 kernel_lb_addr bloc, eloc;
1867 struct buffer_head *bh = NULL;
1871 bloc = UDF_I_LOCATION(table);
1872 extoffset = sizeof(struct unallocSpaceEntry);
1874 while ((etype = udf_next_aext(table, &bloc, &extoffset, &eloc, &elen, &bh, 1)) != -1)
1876 accum += (elen >> table->i_sb->s_blocksize_bits);
1878 udf_release_data(bh);
1886 udf_count_free(struct super_block *sb)
1888 unsigned int accum = 0;
1890 if (UDF_SB_LVIDBH(sb))
1892 if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) > UDF_SB_PARTITION(sb))
1894 accum = le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]);
1896 if (accum == 0xFFFFFFFF)
1904 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
1906 accum += udf_count_free_bitmap(sb,
1907 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_bitmap);
1909 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
1911 accum += udf_count_free_bitmap(sb,
1912 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_bitmap);
1917 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
1919 accum += udf_count_free_table(sb,
1920 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1922 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
1924 accum += udf_count_free_table(sb,
1925 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);