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
37 * vol descs. 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 *,
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 *,
89 static void udf_load_pvoldesc(struct super_block *, struct buffer_head *);
90 static void udf_load_fileset(struct super_block *, struct buffer_head *,
92 static int udf_load_partdesc(struct super_block *, struct buffer_head *);
93 static void udf_open_lvid(struct super_block *);
94 static void udf_close_lvid(struct super_block *);
95 static unsigned int udf_count_free(struct super_block *);
96 static int udf_statfs(struct dentry *, struct kstatfs *);
98 struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi)
100 struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data;
101 __u32 number_of_partitions = le32_to_cpu(lvid->numOfPartitions);
102 __u32 offset = number_of_partitions * 2 * sizeof(uint32_t)/sizeof(uint8_t);
103 return (struct logicalVolIntegrityDescImpUse *)&(lvid->impUse[offset]);
106 /* UDF filesystem type */
107 static int udf_get_sb(struct file_system_type *fs_type,
108 int flags, const char *dev_name, void *data,
109 struct vfsmount *mnt)
111 return get_sb_bdev(fs_type, flags, dev_name, data, udf_fill_super, mnt);
114 static struct file_system_type udf_fstype = {
115 .owner = THIS_MODULE,
117 .get_sb = udf_get_sb,
118 .kill_sb = kill_block_super,
119 .fs_flags = FS_REQUIRES_DEV,
122 static struct kmem_cache *udf_inode_cachep;
124 static struct inode *udf_alloc_inode(struct super_block *sb)
126 struct udf_inode_info *ei;
127 ei = kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL);
132 ei->i_lenExtents = 0;
133 ei->i_next_alloc_block = 0;
134 ei->i_next_alloc_goal = 0;
137 return &ei->vfs_inode;
140 static void udf_destroy_inode(struct inode *inode)
142 kmem_cache_free(udf_inode_cachep, UDF_I(inode));
145 static void init_once(struct kmem_cache *cachep, void *foo)
147 struct udf_inode_info *ei = (struct udf_inode_info *)foo;
149 ei->i_ext.i_data = NULL;
150 inode_init_once(&ei->vfs_inode);
153 static int init_inodecache(void)
155 udf_inode_cachep = kmem_cache_create("udf_inode_cache",
156 sizeof(struct udf_inode_info),
157 0, (SLAB_RECLAIM_ACCOUNT |
160 if (!udf_inode_cachep)
165 static void destroy_inodecache(void)
167 kmem_cache_destroy(udf_inode_cachep);
170 /* Superblock operations */
171 static const struct super_operations udf_sb_ops = {
172 .alloc_inode = udf_alloc_inode,
173 .destroy_inode = udf_destroy_inode,
174 .write_inode = udf_write_inode,
175 .delete_inode = udf_delete_inode,
176 .clear_inode = udf_clear_inode,
177 .put_super = udf_put_super,
178 .write_super = udf_write_super,
179 .statfs = udf_statfs,
180 .remount_fs = udf_remount_fs,
185 unsigned int blocksize;
186 unsigned int session;
187 unsigned int lastblock;
190 unsigned short partition;
191 unsigned int fileset;
192 unsigned int rootdir;
197 struct nls_table *nls_map;
200 static int __init init_udf_fs(void)
204 err = init_inodecache();
207 err = register_filesystem(&udf_fstype);
214 destroy_inodecache();
220 static void __exit exit_udf_fs(void)
222 unregister_filesystem(&udf_fstype);
223 destroy_inodecache();
226 module_init(init_udf_fs)
227 module_exit(exit_udf_fs)
233 * Parse mount options.
236 * The following mount options are supported:
238 * gid= Set the default group.
239 * umask= Set the default umask.
240 * uid= Set the default user.
241 * bs= Set the block size.
242 * unhide Show otherwise hidden files.
243 * undelete Show deleted files in lists.
244 * adinicb Embed data in the inode (default)
245 * noadinicb Don't embed data in the inode
246 * shortad Use short ad's
247 * longad Use long ad's (default)
248 * nostrict Unset strict conformance
249 * iocharset= Set the NLS character set
251 * The remaining are for debugging and disaster recovery:
253 * novrs Skip volume sequence recognition
255 * The following expect a offset from 0.
257 * session= Set the CDROM session (default= last session)
258 * anchor= Override standard anchor location. (default= 256)
259 * volume= Override the VolumeDesc location. (unused)
260 * partition= Override the PartitionDesc location. (unused)
261 * lastblock= Set the last block of the filesystem/
263 * The following expect a offset from the partition root.
265 * fileset= Override the fileset block location. (unused)
266 * rootdir= Override the root directory location. (unused)
267 * WARNING: overriding the rootdir to a non-directory may
268 * yield highly unpredictable results.
271 * options Pointer to mount options string.
272 * uopts Pointer to mount options variable.
275 * <return> 1 Mount options parsed okay.
276 * <return> 0 Error parsing mount options.
279 * July 1, 1997 - Andrew E. Mileski
280 * Written, tested, and released.
284 Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete,
285 Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad,
286 Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock,
287 Opt_anchor, Opt_volume, Opt_partition, Opt_fileset,
288 Opt_rootdir, Opt_utf8, Opt_iocharset,
289 Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore
292 static match_table_t tokens = {
293 {Opt_novrs, "novrs"},
294 {Opt_nostrict, "nostrict"},
296 {Opt_unhide, "unhide"},
297 {Opt_undelete, "undelete"},
298 {Opt_noadinicb, "noadinicb"},
299 {Opt_adinicb, "adinicb"},
300 {Opt_shortad, "shortad"},
301 {Opt_longad, "longad"},
302 {Opt_uforget, "uid=forget"},
303 {Opt_uignore, "uid=ignore"},
304 {Opt_gforget, "gid=forget"},
305 {Opt_gignore, "gid=ignore"},
308 {Opt_umask, "umask=%o"},
309 {Opt_session, "session=%u"},
310 {Opt_lastblock, "lastblock=%u"},
311 {Opt_anchor, "anchor=%u"},
312 {Opt_volume, "volume=%u"},
313 {Opt_partition, "partition=%u"},
314 {Opt_fileset, "fileset=%u"},
315 {Opt_rootdir, "rootdir=%u"},
317 {Opt_iocharset, "iocharset=%s"},
321 static int udf_parse_options(char *options, struct udf_options *uopt)
327 uopt->blocksize = 2048;
328 uopt->partition = 0xFFFF;
329 uopt->session = 0xFFFFFFFF;
332 uopt->volume = 0xFFFFFFFF;
333 uopt->rootdir = 0xFFFFFFFF;
334 uopt->fileset = 0xFFFFFFFF;
335 uopt->nls_map = NULL;
340 while ((p = strsep(&options, ",")) != NULL) {
341 substring_t args[MAX_OPT_ARGS];
346 token = match_token(p, tokens, args);
351 if (match_int(&args[0], &option))
353 uopt->blocksize = option;
356 uopt->flags |= (1 << UDF_FLAG_UNHIDE);
359 uopt->flags |= (1 << UDF_FLAG_UNDELETE);
362 uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
365 uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
368 uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
371 uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
374 if (match_int(args, &option))
377 uopt->flags |= (1 << UDF_FLAG_GID_SET);
380 if (match_int(args, &option))
383 uopt->flags |= (1 << UDF_FLAG_UID_SET);
386 if (match_octal(args, &option))
388 uopt->umask = option;
391 uopt->flags &= ~(1 << UDF_FLAG_STRICT);
394 if (match_int(args, &option))
396 uopt->session = option;
399 if (match_int(args, &option))
401 uopt->lastblock = option;
404 if (match_int(args, &option))
406 uopt->anchor = option;
409 if (match_int(args, &option))
411 uopt->volume = option;
414 if (match_int(args, &option))
416 uopt->partition = option;
419 if (match_int(args, &option))
421 uopt->fileset = option;
424 if (match_int(args, &option))
426 uopt->rootdir = option;
429 uopt->flags |= (1 << UDF_FLAG_UTF8);
431 #ifdef CONFIG_UDF_NLS
433 uopt->nls_map = load_nls(args[0].from);
434 uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
438 uopt->flags |= (1 << UDF_FLAG_UID_IGNORE);
441 uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
444 uopt->flags |= (1 << UDF_FLAG_GID_IGNORE);
447 uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
450 printk(KERN_ERR "udf: bad mount option \"%s\" "
451 "or missing value\n", p);
458 void udf_write_super(struct super_block *sb)
462 if (!(sb->s_flags & MS_RDONLY))
469 static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
471 struct udf_options uopt;
472 struct udf_sb_info *sbi = UDF_SB(sb);
474 uopt.flags = sbi->s_flags;
475 uopt.uid = sbi->s_uid;
476 uopt.gid = sbi->s_gid;
477 uopt.umask = sbi->s_umask;
479 if (!udf_parse_options(options, &uopt))
482 sbi->s_flags = uopt.flags;
483 sbi->s_uid = uopt.uid;
484 sbi->s_gid = uopt.gid;
485 sbi->s_umask = uopt.umask;
487 if (sbi->s_lvid_bh) {
488 int write_rev = le16_to_cpu(udf_sb_lvidiu(sbi)->minUDFWriteRev);
489 if (write_rev > UDF_MAX_WRITE_VERSION)
493 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
495 if (*flags & MS_RDONLY)
507 * Set the block size to be used in all transfers.
510 * To allow room for a DMA transfer, it is best to guess big when unsure.
511 * This routine picks 2048 bytes as the blocksize when guessing. This
512 * should be adequate until devices with larger block sizes become common.
514 * Note that the Linux kernel can currently only deal with blocksizes of
515 * 512, 1024, 2048, 4096, and 8192 bytes.
518 * sb Pointer to _locked_ superblock.
521 * sb->s_blocksize Blocksize.
522 * sb->s_blocksize_bits log2 of blocksize.
523 * <return> 0 Blocksize is valid.
524 * <return> 1 Blocksize is invalid.
527 * July 1, 1997 - Andrew E. Mileski
528 * Written, tested, and released.
530 static int udf_set_blocksize(struct super_block *sb, int bsize)
532 if (!sb_min_blocksize(sb, bsize)) {
533 udf_debug("Bad block size (%d)\n", bsize);
534 printk(KERN_ERR "udf: bad block size (%d)\n", bsize);
538 return sb->s_blocksize;
541 static int udf_vrs(struct super_block *sb, int silent)
543 struct volStructDesc *vsd = NULL;
546 struct buffer_head *bh = NULL;
550 struct udf_sb_info *sbi;
552 /* Block size must be a multiple of 512 */
553 if (sb->s_blocksize & 511)
557 if (sb->s_blocksize < sizeof(struct volStructDesc))
558 sectorsize = sizeof(struct volStructDesc);
560 sectorsize = sb->s_blocksize;
562 sector += (sbi->s_session << sb->s_blocksize_bits);
564 udf_debug("Starting at sector %u (%ld byte sectors)\n",
565 (sector >> sb->s_blocksize_bits), sb->s_blocksize);
566 /* Process the sequence (if applicable) */
567 for (; !nsr02 && !nsr03; sector += sectorsize) {
569 bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
573 /* Look for ISO descriptors */
574 vsd = (struct volStructDesc *)(bh->b_data +
575 (sector & (sb->s_blocksize - 1)));
577 if (vsd->stdIdent[0] == 0) {
580 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001,
583 switch (vsd->structType) {
585 udf_debug("ISO9660 Boot Record found\n");
588 udf_debug("ISO9660 Primary Volume Descriptor "
592 udf_debug("ISO9660 Supplementary Volume "
593 "Descriptor found\n");
596 udf_debug("ISO9660 Volume Partition Descriptor "
600 udf_debug("ISO9660 Volume Descriptor Set "
601 "Terminator found\n");
604 udf_debug("ISO9660 VRS (%u) found\n",
608 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01,
611 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01,
615 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02,
618 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03,
628 else if (sector - (sbi->s_session << sb->s_blocksize_bits) == 32768)
638 * Find an anchor volume descriptor.
641 * sb Pointer to _locked_ superblock.
642 * lastblock Last block on media.
645 * <return> 1 if not found, 0 if ok
648 * July 1, 1997 - Andrew E. Mileski
649 * Written, tested, and released.
651 static void udf_find_anchor(struct super_block *sb)
654 struct buffer_head *bh = NULL;
658 struct udf_sb_info *sbi;
661 lastblock = sbi->s_last_block;
664 int varlastblock = udf_variable_to_fixed(lastblock);
665 int last[] = { lastblock, lastblock - 2,
666 lastblock - 150, lastblock - 152,
667 varlastblock, varlastblock - 2,
668 varlastblock - 150, varlastblock - 152 };
672 /* Search for an anchor volume descriptor pointer */
674 /* according to spec, anchor is in either:
678 * however, if the disc isn't closed, it could be 512 */
680 for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) {
681 ident = location = 0;
683 bh = sb_bread(sb, last[i]);
685 tag *t = (tag *)bh->b_data;
686 ident = le16_to_cpu(t->tagIdent);
687 location = le32_to_cpu(t->tagLocation);
692 if (ident == TAG_IDENT_AVDP) {
693 if (location == last[i] - sbi->s_session) {
694 lastblock = last[i] - sbi->s_session;
695 sbi->s_anchor[0] = lastblock;
696 sbi->s_anchor[1] = lastblock - 256;
697 } else if (location == udf_variable_to_fixed(last[i]) - sbi->s_session) {
698 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
699 lastblock = udf_variable_to_fixed(last[i]) - sbi->s_session;
700 sbi->s_anchor[0] = lastblock;
701 sbi->s_anchor[1] = lastblock - 256 - sbi->s_session;
703 udf_debug("Anchor found at block %d, location mismatch %d.\n",
706 } else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE) {
708 sbi->s_anchor[3] = 512;
710 ident = location = 0;
711 if (last[i] >= 256) {
712 bh = sb_bread(sb, last[i] - 256);
714 tag *t = (tag *)bh->b_data;
715 ident = le16_to_cpu(t->tagIdent);
716 location = le32_to_cpu(t->tagLocation);
721 if (ident == TAG_IDENT_AVDP &&
722 location == last[i] - 256 - sbi->s_session) {
724 sbi->s_anchor[1] = last[i] - 256;
726 ident = location = 0;
727 if (last[i] >= 312 + sbi->s_session) {
728 bh = sb_bread(sb, last[i] - 312 - sbi->s_session);
730 tag *t = (tag *)bh->b_data;
731 ident = le16_to_cpu(t->tagIdent);
732 location = le32_to_cpu(t->tagLocation);
737 if (ident == TAG_IDENT_AVDP &&
738 location == udf_variable_to_fixed(last[i]) - 256) {
739 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
740 lastblock = udf_variable_to_fixed(last[i]);
741 sbi->s_anchor[1] = lastblock - 256;
749 /* We haven't found the lastblock. check 312 */
750 bh = sb_bread(sb, 312 + sbi->s_session);
752 tag *t = (tag *)bh->b_data;
753 ident = le16_to_cpu(t->tagIdent);
754 location = le32_to_cpu(t->tagLocation);
757 if (ident == TAG_IDENT_AVDP && location == 256)
758 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
762 for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
763 if (sbi->s_anchor[i]) {
764 bh = udf_read_tagged(sb, sbi->s_anchor[i],
765 sbi->s_anchor[i], &ident);
767 sbi->s_anchor[i] = 0;
770 if ((ident != TAG_IDENT_AVDP) &&
771 (i || (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE)))
772 sbi->s_anchor[i] = 0;
777 sbi->s_last_block = lastblock;
780 static int udf_find_fileset(struct super_block *sb,
781 kernel_lb_addr *fileset,
782 kernel_lb_addr *root)
784 struct buffer_head *bh = NULL;
787 struct udf_sb_info *sbi;
789 if (fileset->logicalBlockNum != 0xFFFFFFFF ||
790 fileset->partitionReferenceNum != 0xFFFF) {
791 bh = udf_read_ptagged(sb, *fileset, 0, &ident);
795 } else if (ident != TAG_IDENT_FSD) {
804 /* Search backwards through the partitions */
805 kernel_lb_addr newfileset;
807 /* --> cvg: FIXME - is it reasonable? */
810 for (newfileset.partitionReferenceNum = sbi->s_partitions - 1;
811 (newfileset.partitionReferenceNum != 0xFFFF &&
812 fileset->logicalBlockNum == 0xFFFFFFFF &&
813 fileset->partitionReferenceNum == 0xFFFF);
814 newfileset.partitionReferenceNum--) {
815 lastblock = sbi->s_partmaps
816 [newfileset.partitionReferenceNum]
818 newfileset.logicalBlockNum = 0;
821 bh = udf_read_ptagged(sb, newfileset, 0,
824 newfileset.logicalBlockNum++;
831 struct spaceBitmapDesc *sp;
832 sp = (struct spaceBitmapDesc *)bh->b_data;
833 newfileset.logicalBlockNum += 1 +
834 ((le32_to_cpu(sp->numOfBytes) +
835 sizeof(struct spaceBitmapDesc) - 1)
836 >> sb->s_blocksize_bits);
841 *fileset = newfileset;
844 newfileset.logicalBlockNum++;
849 } while (newfileset.logicalBlockNum < lastblock &&
850 fileset->logicalBlockNum == 0xFFFFFFFF &&
851 fileset->partitionReferenceNum == 0xFFFF);
855 if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
856 fileset->partitionReferenceNum != 0xFFFF) && bh) {
857 udf_debug("Fileset at block=%d, partition=%d\n",
858 fileset->logicalBlockNum,
859 fileset->partitionReferenceNum);
861 sbi->s_partition = fileset->partitionReferenceNum;
862 udf_load_fileset(sb, bh, root);
869 static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
871 struct primaryVolDesc *pvoldesc;
877 pvoldesc = (struct primaryVolDesc *)bh->b_data;
879 if (udf_stamp_to_time(&recording, &recording_usec,
880 lets_to_cpu(pvoldesc->recordingDateAndTime))) {
882 ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
883 udf_debug("recording time %ld/%ld, %04u/%02u/%02u"
885 recording, recording_usec,
886 ts.year, ts.month, ts.day, ts.hour,
887 ts.minute, ts.typeAndTimezone);
888 UDF_SB(sb)->s_record_time.tv_sec = recording;
889 UDF_SB(sb)->s_record_time.tv_nsec = recording_usec * 1000;
892 if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) {
893 if (udf_CS0toUTF8(&outstr, &instr)) {
894 strncpy(UDF_SB(sb)->s_volume_ident, outstr.u_name,
895 outstr.u_len > 31 ? 31 : outstr.u_len);
896 udf_debug("volIdent[] = '%s'\n", UDF_SB(sb)->s_volume_ident);
900 if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) {
901 if (udf_CS0toUTF8(&outstr, &instr))
902 udf_debug("volSetIdent[] = '%s'\n", outstr.u_name);
906 static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
907 kernel_lb_addr *root)
909 struct fileSetDesc *fset;
911 fset = (struct fileSetDesc *)bh->b_data;
913 *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
915 UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum);
917 udf_debug("Rootdir at block=%d, partition=%d\n",
918 root->logicalBlockNum, root->partitionReferenceNum);
921 static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
923 struct partitionDesc *p;
925 struct udf_part_map *map;
926 struct udf_sb_info *sbi;
928 p = (struct partitionDesc *)bh->b_data;
931 for (i = 0; i < sbi->s_partitions; i++) {
932 map = &sbi->s_partmaps[i];
933 udf_debug("Searching map: (%d == %d)\n",
934 map->s_partition_num, le16_to_cpu(p->partitionNumber));
935 if (map->s_partition_num == le16_to_cpu(p->partitionNumber)) {
936 map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */
937 map->s_partition_root = le32_to_cpu(p->partitionStartingLocation);
938 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY)
939 map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
940 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_WRITE_ONCE)
941 map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
942 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_REWRITABLE)
943 map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
944 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_OVERWRITABLE)
945 map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
947 if (!strcmp(p->partitionContents.ident,
948 PD_PARTITION_CONTENTS_NSR02) ||
949 !strcmp(p->partitionContents.ident,
950 PD_PARTITION_CONTENTS_NSR03)) {
951 struct partitionHeaderDesc *phd;
953 phd = (struct partitionHeaderDesc *)(p->partitionContentsUse);
954 if (phd->unallocSpaceTable.extLength) {
955 kernel_lb_addr loc = {
956 .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition),
957 .partitionReferenceNum = i,
960 map->s_uspace.s_table =
962 if (!map->s_uspace.s_table) {
963 udf_debug("cannot load unallocSpaceTable (part %d)\n", i);
966 map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE;
967 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
968 i, map->s_uspace.s_table->i_ino);
970 if (phd->unallocSpaceBitmap.extLength) {
971 UDF_SB_ALLOC_BITMAP(sb, i, s_uspace);
972 if (map->s_uspace.s_bitmap != NULL) {
973 map->s_uspace.s_bitmap->s_extLength =
974 le32_to_cpu(phd->unallocSpaceBitmap.extLength);
975 map->s_uspace.s_bitmap->s_extPosition =
976 le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
977 map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
978 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
979 i, map->s_uspace.s_bitmap->s_extPosition);
982 if (phd->partitionIntegrityTable.extLength)
983 udf_debug("partitionIntegrityTable (part %d)\n", i);
984 if (phd->freedSpaceTable.extLength) {
985 kernel_lb_addr loc = {
986 .logicalBlockNum = le32_to_cpu(phd->freedSpaceTable.extPosition),
987 .partitionReferenceNum = i,
990 map->s_fspace.s_table =
992 if (!map->s_fspace.s_table) {
993 udf_debug("cannot load freedSpaceTable (part %d)\n", i);
996 map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE;
997 udf_debug("freedSpaceTable (part %d) @ %ld\n",
998 i, map->s_fspace.s_table->i_ino);
1000 if (phd->freedSpaceBitmap.extLength) {
1001 UDF_SB_ALLOC_BITMAP(sb, i, s_fspace);
1002 if (map->s_fspace.s_bitmap != NULL) {
1003 map->s_fspace.s_bitmap->s_extLength =
1004 le32_to_cpu(phd->freedSpaceBitmap.extLength);
1005 map->s_fspace.s_bitmap->s_extPosition =
1006 le32_to_cpu(phd->freedSpaceBitmap.extPosition);
1007 map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
1008 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
1009 i, map->s_fspace.s_bitmap->s_extPosition);
1016 if (i == sbi->s_partitions) {
1017 udf_debug("Partition (%d) not found in partition map\n",
1018 le16_to_cpu(p->partitionNumber));
1020 udf_debug("Partition (%d:%d type %x) starts at physical %d, "
1021 "block length %d\n",
1022 le16_to_cpu(p->partitionNumber), i,
1023 map->s_partition_type,
1024 map->s_partition_root,
1025 map->s_partition_len);
1030 static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
1031 kernel_lb_addr *fileset)
1033 struct logicalVolDesc *lvd;
1036 struct udf_sb_info *sbi = UDF_SB(sb);
1038 lvd = (struct logicalVolDesc *)bh->b_data;
1040 UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps));
1042 for (i = 0, offset = 0;
1043 i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength);
1044 i++, offset += ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength) {
1045 struct udf_part_map *map = &sbi->s_partmaps[i];
1046 type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType;
1048 struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]);
1049 map->s_partition_type = UDF_TYPE1_MAP15;
1050 map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum);
1051 map->s_partition_num = le16_to_cpu(gpm1->partitionNum);
1052 map->s_partition_func = NULL;
1053 } else if (type == 2) {
1054 struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]);
1055 if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL))) {
1056 if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0150) {
1057 map->s_partition_type = UDF_VIRTUAL_MAP15;
1058 map->s_partition_func = udf_get_pblock_virt15;
1059 } else if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0200) {
1060 map->s_partition_type = UDF_VIRTUAL_MAP20;
1061 map->s_partition_func = udf_get_pblock_virt20;
1063 } else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE))) {
1066 struct sparingTable *st;
1067 struct sparablePartitionMap *spm = (struct sparablePartitionMap *)&(lvd->partitionMaps[offset]);
1069 map->s_partition_type = UDF_SPARABLE_MAP15;
1070 map->s_type_specific.s_sparing.s_packet_len = le16_to_cpu(spm->packetLength);
1071 for (j = 0; j < spm->numSparingTables; j++) {
1072 loc = le32_to_cpu(spm->locSparingTable[j]);
1073 map->s_type_specific.s_sparing.s_spar_map[j] =
1074 udf_read_tagged(sb, loc, loc, &ident);
1075 if (map->s_type_specific.s_sparing.s_spar_map[j] != NULL) {
1076 st = (struct sparingTable *)map->s_type_specific.s_sparing.s_spar_map[j]->b_data;
1078 strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING))) {
1079 brelse(map->s_type_specific.s_sparing.s_spar_map[j]);
1080 map->s_type_specific.s_sparing.s_spar_map[j] = NULL;
1084 map->s_partition_func = udf_get_pblock_spar15;
1086 udf_debug("Unknown ident: %s\n",
1087 upm2->partIdent.ident);
1090 map->s_volumeseqnum = le16_to_cpu(upm2->volSeqNum);
1091 map->s_partition_num = le16_to_cpu(upm2->partitionNum);
1093 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1094 i, map->s_partition_num, type,
1095 map->s_volumeseqnum);
1099 long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]);
1101 *fileset = lelb_to_cpu(la->extLocation);
1102 udf_debug("FileSet found in LogicalVolDesc at block=%d, "
1103 "partition=%d\n", fileset->logicalBlockNum,
1104 fileset->partitionReferenceNum);
1106 if (lvd->integritySeqExt.extLength)
1107 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
1113 * udf_load_logicalvolint
1116 static void udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
1118 struct buffer_head *bh = NULL;
1120 struct udf_sb_info *sbi = UDF_SB(sb);
1121 struct logicalVolIntegrityDesc *lvid;
1123 while (loc.extLength > 0 &&
1124 (bh = udf_read_tagged(sb, loc.extLocation,
1125 loc.extLocation, &ident)) &&
1126 ident == TAG_IDENT_LVID) {
1127 sbi->s_lvid_bh = bh;
1128 lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
1130 if (lvid->nextIntegrityExt.extLength)
1131 udf_load_logicalvolint(sb,
1132 leea_to_cpu(lvid->nextIntegrityExt));
1134 if (sbi->s_lvid_bh != bh)
1136 loc.extLength -= sb->s_blocksize;
1139 if (sbi->s_lvid_bh != bh)
1144 * udf_process_sequence
1147 * Process a main/reserve volume descriptor sequence.
1150 * sb Pointer to _locked_ superblock.
1151 * block First block of first extent of the sequence.
1152 * lastblock Lastblock of first extent of the sequence.
1155 * July 1, 1997 - Andrew E. Mileski
1156 * Written, tested, and released.
1158 static int udf_process_sequence(struct super_block *sb, long block,
1159 long lastblock, kernel_lb_addr *fileset)
1161 struct buffer_head *bh = NULL;
1162 struct udf_vds_record vds[VDS_POS_LENGTH];
1163 struct generic_desc *gd;
1164 struct volDescPtr *vdp;
1169 long next_s = 0, next_e = 0;
1171 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
1173 /* Read the main descriptor sequence */
1174 for (; (!done && block <= lastblock); block++) {
1176 bh = udf_read_tagged(sb, block, block, &ident);
1180 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1181 gd = (struct generic_desc *)bh->b_data;
1182 vdsn = le32_to_cpu(gd->volDescSeqNum);
1184 case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
1185 if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) {
1186 vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn;
1187 vds[VDS_POS_PRIMARY_VOL_DESC].block = block;
1190 case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
1191 if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) {
1192 vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn;
1193 vds[VDS_POS_VOL_DESC_PTR].block = block;
1195 vdp = (struct volDescPtr *)bh->b_data;
1196 next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation);
1197 next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength);
1198 next_e = next_e >> sb->s_blocksize_bits;
1202 case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
1203 if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) {
1204 vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn;
1205 vds[VDS_POS_IMP_USE_VOL_DESC].block = block;
1208 case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
1209 if (!vds[VDS_POS_PARTITION_DESC].block)
1210 vds[VDS_POS_PARTITION_DESC].block = block;
1212 case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
1213 if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) {
1214 vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn;
1215 vds[VDS_POS_LOGICAL_VOL_DESC].block = block;
1218 case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
1219 if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) {
1220 vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn;
1221 vds[VDS_POS_UNALLOC_SPACE_DESC].block = block;
1224 case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
1225 vds[VDS_POS_TERMINATING_DESC].block = block;
1229 next_s = next_e = 0;
1237 for (i = 0; i < VDS_POS_LENGTH; i++) {
1239 bh = udf_read_tagged(sb, vds[i].block, vds[i].block,
1242 if (i == VDS_POS_PRIMARY_VOL_DESC) {
1243 udf_load_pvoldesc(sb, bh);
1244 } else if (i == VDS_POS_LOGICAL_VOL_DESC) {
1245 udf_load_logicalvol(sb, bh, fileset);
1246 } else if (i == VDS_POS_PARTITION_DESC) {
1247 struct buffer_head *bh2 = NULL;
1248 if (udf_load_partdesc(sb, bh)) {
1252 for (j = vds[i].block + 1;
1253 j < vds[VDS_POS_TERMINATING_DESC].block;
1255 bh2 = udf_read_tagged(sb, j, j, &ident);
1256 gd = (struct generic_desc *)bh2->b_data;
1257 if (ident == TAG_IDENT_PD)
1258 if (udf_load_partdesc(sb,
1277 static int udf_check_valid(struct super_block *sb, int novrs, int silent)
1282 udf_debug("Validity check skipped because of novrs option\n");
1285 /* Check that it is NSR02 compliant */
1286 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1288 block = udf_vrs(sb, silent);
1290 struct udf_sb_info *sbi = UDF_SB(sb);
1291 udf_debug("Failed to read byte 32768. Assuming open "
1292 "disc. Skipping validity check\n");
1293 if (!sbi->s_last_block)
1294 sbi->s_last_block = udf_get_last_block(sb);
1301 static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
1303 struct anchorVolDescPtr *anchor;
1305 struct buffer_head *bh;
1306 long main_s, main_e, reserve_s, reserve_e;
1308 struct udf_sb_info *sbi;
1314 for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
1315 if (sbi->s_anchor[i] &&
1316 (bh = udf_read_tagged(sb, sbi->s_anchor[i],
1317 sbi->s_anchor[i], &ident))) {
1318 anchor = (struct anchorVolDescPtr *)bh->b_data;
1320 /* Locate the main sequence */
1321 main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
1322 main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength);
1323 main_e = main_e >> sb->s_blocksize_bits;
1326 /* Locate the reserve sequence */
1327 reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation);
1328 reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
1329 reserve_e = reserve_e >> sb->s_blocksize_bits;
1330 reserve_e += reserve_s;
1334 /* Process the main & reserve sequences */
1335 /* responsible for finding the PartitionDesc(s) */
1336 if (!(udf_process_sequence(sb, main_s, main_e, fileset) &&
1337 udf_process_sequence(sb, reserve_s, reserve_e, fileset)))
1342 if (i == ARRAY_SIZE(sbi->s_anchor)) {
1343 udf_debug("No Anchor block found\n");
1346 udf_debug("Using anchor in block %d\n", sbi->s_anchor[i]);
1348 for (i = 0; i < sbi->s_partitions; i++) {
1349 kernel_lb_addr uninitialized_var(ino);
1350 struct udf_part_map *map = &sbi->s_partmaps[i];
1351 switch (map->s_partition_type) {
1352 case UDF_VIRTUAL_MAP15:
1353 case UDF_VIRTUAL_MAP20:
1354 if (!sbi->s_last_block) {
1355 sbi->s_last_block = udf_get_last_block(sb);
1356 udf_find_anchor(sb);
1359 if (!sbi->s_last_block) {
1360 udf_debug("Unable to determine Lastblock (For "
1361 "Virtual Partition)\n");
1365 for (j = 0; j < sbi->s_partitions; j++) {
1366 struct udf_part_map *map2 = &sbi->s_partmaps[j];
1368 map->s_volumeseqnum == map2->s_volumeseqnum &&
1369 map->s_partition_num == map2->s_partition_num) {
1370 ino.partitionReferenceNum = j;
1371 ino.logicalBlockNum = sbi->s_last_block - map2->s_partition_root;
1376 if (j == sbi->s_partitions)
1379 sbi->s_vat_inode = udf_iget(sb, ino);
1380 if (!sbi->s_vat_inode)
1383 if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
1384 map->s_type_specific.s_virtual.s_start_offset =
1385 udf_ext0_offset(sbi->s_vat_inode);
1386 map->s_type_specific.s_virtual.s_num_entries =
1387 (sbi->s_vat_inode->i_size - 36) >> 2;
1388 } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
1389 struct buffer_head *bh = NULL;
1392 pos = udf_block_map(sbi->s_vat_inode, 0);
1393 bh = sb_bread(sb, pos);
1396 map->s_type_specific.s_virtual.s_start_offset =
1397 le16_to_cpu(((struct virtualAllocationTable20 *)bh->b_data +
1398 udf_ext0_offset(sbi->s_vat_inode))->lengthHeader) +
1399 udf_ext0_offset(sbi->s_vat_inode);
1400 map->s_type_specific.s_virtual.s_num_entries = (sbi->s_vat_inode->i_size -
1401 map->s_type_specific.s_virtual.s_start_offset) >> 2;
1404 map->s_partition_root = udf_get_pblock(sb, 0, i, 0);
1405 map->s_partition_len =
1406 sbi->s_partmaps[ino.partitionReferenceNum].
1413 static void udf_open_lvid(struct super_block *sb)
1415 struct udf_sb_info *sbi = UDF_SB(sb);
1416 struct buffer_head *bh = sbi->s_lvid_bh;
1419 kernel_timestamp cpu_time;
1420 struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
1421 struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sbi);
1423 lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1424 lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1425 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1426 lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
1427 lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
1429 lvid->descTag.descCRC = cpu_to_le16(udf_crc((char *)lvid + sizeof(tag),
1430 le16_to_cpu(lvid->descTag.descCRCLength), 0));
1432 lvid->descTag.tagChecksum = 0;
1433 for (i = 0; i < 16; i++)
1435 lvid->descTag.tagChecksum +=
1436 ((uint8_t *) &(lvid->descTag))[i];
1438 mark_buffer_dirty(bh);
1442 static void udf_close_lvid(struct super_block *sb)
1444 kernel_timestamp cpu_time;
1446 struct udf_sb_info *sbi = UDF_SB(sb);
1447 struct buffer_head *bh = sbi->s_lvid_bh;
1448 struct logicalVolIntegrityDesc *lvid;
1453 lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
1455 if (lvid->integrityType == LVID_INTEGRITY_TYPE_OPEN) {
1456 struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sbi);
1457 lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1458 lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1459 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1460 lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
1461 if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
1462 lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
1463 if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
1464 lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
1465 if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
1466 lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
1467 lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
1469 lvid->descTag.descCRC =
1470 cpu_to_le16(udf_crc((char *)lvid + sizeof(tag),
1471 le16_to_cpu(lvid->descTag.descCRCLength), 0));
1473 lvid->descTag.tagChecksum = 0;
1474 for (i = 0; i < 16; i++)
1476 lvid->descTag.tagChecksum +=
1477 ((uint8_t *)&(lvid->descTag))[i];
1479 mark_buffer_dirty(bh);
1487 * Complete the specified super block.
1490 * sb Pointer to superblock to complete - never NULL.
1491 * sb->s_dev Device to read suberblock from.
1492 * options Pointer to mount options.
1493 * silent Silent flag.
1496 * July 1, 1997 - Andrew E. Mileski
1497 * Written, tested, and released.
1499 static int udf_fill_super(struct super_block *sb, void *options, int silent)
1502 struct inode *inode = NULL;
1503 struct udf_options uopt;
1504 kernel_lb_addr rootdir, fileset;
1505 struct udf_sb_info *sbi;
1507 uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
1512 sbi = kzalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
1516 sb->s_fs_info = sbi;
1518 mutex_init(&sbi->s_alloc_mutex);
1520 if (!udf_parse_options((char *)options, &uopt))
1523 if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
1524 uopt.flags & (1 << UDF_FLAG_NLS_MAP)) {
1525 udf_error(sb, "udf_read_super",
1526 "utf8 cannot be combined with iocharset\n");
1529 #ifdef CONFIG_UDF_NLS
1530 if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) {
1531 uopt.nls_map = load_nls_default();
1533 uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
1535 udf_debug("Using default NLS map\n");
1538 if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
1539 uopt.flags |= (1 << UDF_FLAG_UTF8);
1541 fileset.logicalBlockNum = 0xFFFFFFFF;
1542 fileset.partitionReferenceNum = 0xFFFF;
1544 sbi->s_flags = uopt.flags;
1545 sbi->s_uid = uopt.uid;
1546 sbi->s_gid = uopt.gid;
1547 sbi->s_umask = uopt.umask;
1548 sbi->s_nls_map = uopt.nls_map;
1550 /* Set the block size for all transfers */
1551 if (!udf_set_blocksize(sb, uopt.blocksize))
1554 if (uopt.session == 0xFFFFFFFF)
1555 sbi->s_session = udf_get_last_session(sb);
1557 sbi->s_session = uopt.session;
1559 udf_debug("Multi-session=%d\n", sbi->s_session);
1561 sbi->s_last_block = uopt.lastblock;
1562 sbi->s_anchor[0] = sbi->s_anchor[1] = 0;
1563 sbi->s_anchor[2] = uopt.anchor;
1564 sbi->s_anchor[3] = 256;
1566 if (udf_check_valid(sb, uopt.novrs, silent)) {
1567 /* read volume recognition sequences */
1568 printk(KERN_WARNING "UDF-fs: No VRS found\n");
1572 udf_find_anchor(sb);
1574 /* Fill in the rest of the superblock */
1575 sb->s_op = &udf_sb_ops;
1578 sb->s_magic = UDF_SUPER_MAGIC;
1579 sb->s_time_gran = 1000;
1581 if (udf_load_partition(sb, &fileset)) {
1582 printk(KERN_WARNING "UDF-fs: No partition found (1)\n");
1586 udf_debug("Lastblock=%d\n", sbi->s_last_block);
1588 if (sbi->s_lvid_bh) {
1589 struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sbi);
1590 uint16_t minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev);
1591 uint16_t minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev);
1592 /* uint16_t maxUDFWriteRev = le16_to_cpu(lvidiu->maxUDFWriteRev); */
1594 if (minUDFReadRev > UDF_MAX_READ_VERSION) {
1595 printk(KERN_ERR "UDF-fs: minUDFReadRev=%x (max is %x)\n",
1596 le16_to_cpu(lvidiu->minUDFReadRev),
1597 UDF_MAX_READ_VERSION);
1599 } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) {
1600 sb->s_flags |= MS_RDONLY;
1603 sbi->s_udfrev = minUDFWriteRev;
1605 if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
1606 UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
1607 if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
1608 UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
1611 if (!sbi->s_partitions) {
1612 printk(KERN_WARNING "UDF-fs: No partition found (2)\n");
1616 if (sbi->s_partmaps[sbi->s_partition].s_partition_flags & UDF_PART_FLAG_READ_ONLY) {
1617 printk(KERN_NOTICE "UDF-fs: Partition marked readonly; forcing readonly mount\n");
1618 sb->s_flags |= MS_RDONLY;
1621 if (udf_find_fileset(sb, &fileset, &rootdir)) {
1622 printk(KERN_WARNING "UDF-fs: No fileset found\n");
1627 kernel_timestamp ts;
1628 udf_time_to_stamp(&ts, sbi->s_record_time);
1629 udf_info("UDF %s (%s) Mounting volume '%s', "
1630 "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1631 UDFFS_VERSION, UDFFS_DATE,
1632 sbi->s_volume_ident, ts.year, ts.month, ts.day,
1633 ts.hour, ts.minute, ts.typeAndTimezone);
1635 if (!(sb->s_flags & MS_RDONLY))
1638 /* Assign the root inode */
1639 /* assign inodes by physical block number */
1640 /* perhaps it's not extensible enough, but for now ... */
1641 inode = udf_iget(sb, rootdir);
1643 printk(KERN_ERR "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);
1651 printk(KERN_ERR "UDF-fs: Couldn't allocate root dentry\n");
1655 sb->s_maxbytes = MAX_LFS_FILESIZE;
1659 if (sbi->s_vat_inode)
1660 iput(sbi->s_vat_inode);
1661 if (sbi->s_partitions) {
1662 struct udf_part_map *map = &sbi->s_partmaps[sbi->s_partition];
1663 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
1664 iput(map->s_uspace.s_table);
1665 if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
1666 iput(map->s_fspace.s_table);
1667 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
1668 UDF_SB_FREE_BITMAP(sb, sbi->s_partition, s_uspace);
1669 if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
1670 UDF_SB_FREE_BITMAP(sb, sbi->s_partition, s_fspace);
1671 if (map->s_partition_type == UDF_SPARABLE_MAP15)
1672 for (i = 0; i < 4; i++)
1673 brelse(map->s_type_specific.s_sparing.s_spar_map[i]);
1675 #ifdef CONFIG_UDF_NLS
1676 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1677 unload_nls(sbi->s_nls_map);
1679 if (!(sb->s_flags & MS_RDONLY))
1681 brelse(sbi->s_lvid_bh);
1683 kfree(sbi->s_partmaps);
1685 sb->s_fs_info = NULL;
1690 void udf_error(struct super_block *sb, const char *function,
1691 const char *fmt, ...)
1695 if (!(sb->s_flags & MS_RDONLY)) {
1699 va_start(args, fmt);
1700 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
1702 printk(KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
1703 sb->s_id, function, error_buf);
1706 void udf_warning(struct super_block *sb, const char *function,
1707 const char *fmt, ...)
1711 va_start(args, fmt);
1712 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
1714 printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
1715 sb->s_id, function, error_buf);
1722 * Prepare for destruction of the superblock.
1725 * Called before the filesystem is unmounted.
1728 * July 1, 1997 - Andrew E. Mileski
1729 * Written, tested, and released.
1731 static void udf_put_super(struct super_block *sb)
1734 struct udf_sb_info *sbi;
1737 if (sbi->s_vat_inode)
1738 iput(sbi->s_vat_inode);
1739 if (sbi->s_partitions) {
1740 struct udf_part_map *map = &sbi->s_partmaps[sbi->s_partition];
1741 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
1742 iput(map->s_uspace.s_table);
1743 if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
1744 iput(map->s_fspace.s_table);
1745 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
1746 UDF_SB_FREE_BITMAP(sb, sbi->s_partition, s_uspace);
1747 if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
1748 UDF_SB_FREE_BITMAP(sb, sbi->s_partition, s_fspace);
1749 if (map->s_partition_type == UDF_SPARABLE_MAP15)
1750 for (i = 0; i < 4; i++)
1751 brelse(map->s_type_specific.s_sparing.s_spar_map[i]);
1753 #ifdef CONFIG_UDF_NLS
1754 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1755 unload_nls(sbi->s_nls_map);
1757 if (!(sb->s_flags & MS_RDONLY))
1759 brelse(sbi->s_lvid_bh);
1760 kfree(sbi->s_partmaps);
1761 kfree(sb->s_fs_info);
1762 sb->s_fs_info = NULL;
1769 * Return info about the filesystem.
1772 * Called by sys_statfs()
1775 * July 1, 1997 - Andrew E. Mileski
1776 * Written, tested, and released.
1778 static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
1780 struct super_block *sb = dentry->d_sb;
1781 struct udf_sb_info *sbi = UDF_SB(sb);
1782 struct logicalVolIntegrityDescImpUse *lvidiu;
1784 if (sbi->s_lvid_bh != NULL)
1785 lvidiu = udf_sb_lvidiu(sbi);
1789 buf->f_type = UDF_SUPER_MAGIC;
1790 buf->f_bsize = sb->s_blocksize;
1791 buf->f_blocks = sbi->s_partmaps[sbi->s_partition].s_partition_len;
1792 buf->f_bfree = udf_count_free(sb);
1793 buf->f_bavail = buf->f_bfree;
1794 buf->f_files = (lvidiu != NULL ? (le32_to_cpu(lvidiu->numFiles) +
1795 le32_to_cpu(lvidiu->numDirs)) : 0)
1797 buf->f_ffree = buf->f_bfree;
1798 /* __kernel_fsid_t f_fsid */
1799 buf->f_namelen = UDF_NAME_LEN - 2;
1804 static unsigned char udf_bitmap_lookup[16] = {
1805 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
1808 static unsigned int udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
1810 struct buffer_head *bh = NULL;
1811 unsigned int accum = 0;
1813 int block = 0, newblock;
1819 struct spaceBitmapDesc *bm;
1823 loc.logicalBlockNum = bitmap->s_extPosition;
1824 loc.partitionReferenceNum = UDF_SB(sb)->s_partition;
1825 bh = udf_read_ptagged(sb, loc, 0, &ident);
1828 printk(KERN_ERR "udf: udf_count_free failed\n");
1830 } else if (ident != TAG_IDENT_SBD) {
1832 printk(KERN_ERR "udf: udf_count_free failed\n");
1836 bm = (struct spaceBitmapDesc *)bh->b_data;
1837 bytes = le32_to_cpu(bm->numOfBytes);
1838 index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
1839 ptr = (uint8_t *)bh->b_data;
1842 while ((bytes > 0) && (index < sb->s_blocksize)) {
1844 accum += udf_bitmap_lookup[value & 0x0f];
1845 accum += udf_bitmap_lookup[value >> 4];
1851 newblock = udf_get_lb_pblock(sb, loc, ++block);
1852 bh = udf_tread(sb, newblock);
1854 udf_debug("read failed\n");
1858 ptr = (uint8_t *)bh->b_data;
1869 static unsigned int udf_count_free_table(struct super_block *sb, struct inode *table)
1871 unsigned int accum = 0;
1873 kernel_lb_addr eloc;
1875 struct extent_position epos;
1879 epos.block = UDF_I_LOCATION(table);
1880 epos.offset = sizeof(struct unallocSpaceEntry);
1883 while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
1884 accum += (elen >> table->i_sb->s_blocksize_bits);
1893 static unsigned int udf_count_free(struct super_block *sb)
1895 unsigned int accum = 0;
1896 struct udf_sb_info *sbi;
1897 struct udf_part_map *map;
1900 if (sbi->s_lvid_bh) {
1901 struct logicalVolIntegrityDesc *lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data;
1902 if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) {
1903 accum = le32_to_cpu(lvid->freeSpaceTable[sbi->s_partition]);
1904 if (accum == 0xFFFFFFFF)
1912 map = &sbi->s_partmaps[sbi->s_partition];
1913 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
1914 accum += udf_count_free_bitmap(sb,
1915 map->s_uspace.s_bitmap);
1917 if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) {
1918 accum += udf_count_free_bitmap(sb,
1919 map->s_fspace.s_bitmap);
1924 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
1925 accum += udf_count_free_table(sb,
1926 map->s_uspace.s_table);
1928 if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) {
1929 accum += udf_count_free_table(sb,
1930 map->s_fspace.s_table);