5 * Super block routines for the OSTA-UDF(tm) filesystem.
8 * OSTA-UDF(tm) = Optical Storage Technology Association
9 * Universal Disk Format.
11 * This code is based on version 2.00 of the UDF specification,
12 * and revision 3 of the ECMA 167 standard [equivalent to ISO 13346].
13 * http://www.osta.org/
18 * E-mail regarding any portion of the Linux UDF file system should be
19 * directed to the development team mailing list (run by majordomo):
20 * linux_udf@hpesjro.fc.hp.com
23 * This file is distributed under the terms of the GNU General Public
24 * License (GPL). Copies of the GPL can be obtained from:
25 * ftp://prep.ai.mit.edu/pub/gnu/GPL
26 * Each contributing author retains all rights to their own work.
28 * (C) 1998 Dave Boynton
29 * (C) 1998-2001 Ben Fennema
30 * (C) 2000 Stelias Computing Inc
34 * 09/24/98 dgb changed to allow compiling outside of kernel, and
35 * added some debugging.
36 * 10/01/98 dgb updated to allow (some) possibility of compiling w/2.0.34
37 * 10/16/98 attempting some multi-session support
38 * 10/17/98 added freespace count for "df"
39 * 11/11/98 gr added novrs option
40 * 11/26/98 dgb added fileset,anchor mount options
41 * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced vol descs
42 * rewrote option handling based on isofs
43 * 12/20/98 find the free space bitmap (if it exists)
48 #include <linux/config.h>
49 #include <linux/version.h>
50 #include <linux/blkdev.h>
51 #include <linux/slab.h>
52 #include <linux/kernel.h>
53 #include <linux/locks.h>
54 #include <linux/module.h>
55 #include <linux/stat.h>
56 #include <linux/cdrom.h>
57 #include <linux/nls.h>
58 #include <asm/byteorder.h>
60 #include <linux/udf_fs.h>
64 #include <linux/init.h>
65 #include <asm/uaccess.h>
67 #define VDS_POS_PRIMARY_VOL_DESC 0
68 #define VDS_POS_UNALLOC_SPACE_DESC 1
69 #define VDS_POS_LOGICAL_VOL_DESC 2
70 #define VDS_POS_PARTITION_DESC 3
71 #define VDS_POS_IMP_USE_VOL_DESC 4
72 #define VDS_POS_VOL_DESC_PTR 5
73 #define VDS_POS_TERMINATING_DESC 6
74 #define VDS_POS_LENGTH 7
76 static char error_buf[1024];
78 /* These are the "meat" - everything else is stuffing */
79 static struct super_block *udf_read_super(struct super_block *, void *, int);
80 static void udf_put_super(struct super_block *);
81 static void udf_write_super(struct super_block *);
82 static int udf_remount_fs(struct super_block *, int *, char *);
83 static int udf_check_valid(struct super_block *, int, int);
84 static int udf_vrs(struct super_block *sb, int silent);
85 static int udf_load_partition(struct super_block *, lb_addr *);
86 static int udf_load_logicalvol(struct super_block *, struct buffer_head *, lb_addr *);
87 static void udf_load_logicalvolint(struct super_block *, extent_ad);
88 static void udf_find_anchor(struct super_block *);
89 static int udf_find_fileset(struct super_block *, lb_addr *, lb_addr *);
90 static void udf_load_pvoldesc(struct super_block *, struct buffer_head *);
91 static void udf_load_fileset(struct super_block *, struct buffer_head *, lb_addr *);
92 static void 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 super_block *, struct statfs *);
98 /* UDF filesystem type */
99 static DECLARE_FSTYPE_DEV(udf_fstype, "udf", udf_read_super);
101 /* Superblock operations */
102 static struct super_operations udf_sb_ops = {
103 read_inode: udf_read_inode,
104 write_inode: udf_write_inode,
105 put_inode: udf_put_inode,
106 delete_inode: udf_delete_inode,
107 put_super: udf_put_super,
108 write_super: udf_write_super,
110 remount_fs: udf_remount_fs,
116 unsigned int blocksize;
117 unsigned int session;
118 unsigned int lastblock;
121 unsigned short partition;
122 unsigned int fileset;
123 unsigned int rootdir;
128 struct nls_table *nls_map;
131 static int __init init_udf_fs(void)
133 printk(KERN_NOTICE "udf: registering filesystem\n");
134 return register_filesystem(&udf_fstype);
137 static void __exit exit_udf_fs(void)
139 printk(KERN_NOTICE "udf: unregistering filesystem\n");
140 unregister_filesystem(&udf_fstype);
145 module_init(init_udf_fs)
146 module_exit(exit_udf_fs)
152 * Parse mount options.
155 * The following mount options are supported:
157 * gid= Set the default group.
158 * umask= Set the default umask.
159 * uid= Set the default user.
160 * bs= Set the block size.
161 * unhide Show otherwise hidden files.
162 * undelete Show deleted files in lists.
163 * adinicb Embed data in the inode (default)
164 * noadinicb Don't embed data in the inode
165 * shortad Use short ad's
166 * longad Use long ad's (default)
167 * nostrict Unset strict conformance
168 * iocharset= Set the NLS character set
170 * The remaining are for debugging and disaster recovery:
172 * novrs Skip volume sequence recognition
174 * The following expect a offset from 0.
176 * session= Set the CDROM session (default= last session)
177 * anchor= Override standard anchor location. (default= 256)
178 * volume= Override the VolumeDesc location. (unused)
179 * partition= Override the PartitionDesc location. (unused)
180 * lastblock= Set the last block of the filesystem/
182 * The following expect a offset from the partition root.
184 * fileset= Override the fileset block location. (unused)
185 * rootdir= Override the root directory location. (unused)
186 * WARNING: overriding the rootdir to a non-directory may
187 * yield highly unpredictable results.
190 * options Pointer to mount options string.
191 * uopts Pointer to mount options variable.
194 * <return> 0 Mount options parsed okay.
195 * <return> -1 Error parsing mount options.
198 * July 1, 1997 - Andrew E. Mileski
199 * Written, tested, and released.
203 udf_parse_options(char *options, struct udf_options *uopt)
208 uopt->blocksize = 2048;
209 uopt->partition = 0xFFFF;
210 uopt->session = 0xFFFFFFFF;
213 uopt->volume = 0xFFFFFFFF;
214 uopt->rootdir = 0xFFFFFFFF;
215 uopt->fileset = 0xFFFFFFFF;
216 uopt->nls_map = NULL;
221 for (opt = strtok(options, ","); opt; opt = strtok(NULL, ","))
223 /* Make "opt=val" into two strings */
224 val = strchr(opt, '=');
227 if (!strcmp(opt, "novrs") && !val)
229 else if (!strcmp(opt, "bs") && val)
230 uopt->blocksize = simple_strtoul(val, NULL, 0);
231 else if (!strcmp(opt, "unhide") && !val)
232 uopt->flags |= (1 << UDF_FLAG_UNHIDE);
233 else if (!strcmp(opt, "undelete") && !val)
234 uopt->flags |= (1 << UDF_FLAG_UNDELETE);
235 else if (!strcmp(opt, "noadinicb") && !val)
236 uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
237 else if (!strcmp(opt, "adinicb") && !val)
238 uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
239 else if (!strcmp(opt, "shortad") && !val)
240 uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
241 else if (!strcmp(opt, "longad") && !val)
242 uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
243 else if (!strcmp(opt, "gid") && val)
244 uopt->gid = simple_strtoul(val, NULL, 0);
245 else if (!strcmp(opt, "umask") && val)
246 uopt->umask = simple_strtoul(val, NULL, 0);
247 else if (!strcmp(opt, "nostrict") && !val)
248 uopt->flags &= ~(1 << UDF_FLAG_STRICT);
249 else if (!strcmp(opt, "uid") && val)
250 uopt->uid = simple_strtoul(val, NULL, 0);
251 else if (!strcmp(opt, "session") && val)
252 uopt->session = simple_strtoul(val, NULL, 0);
253 else if (!strcmp(opt, "lastblock") && val)
254 uopt->lastblock = simple_strtoul(val, NULL, 0);
255 else if (!strcmp(opt, "anchor") && val)
256 uopt->anchor = simple_strtoul(val, NULL, 0);
257 else if (!strcmp(opt, "volume") && val)
258 uopt->volume = simple_strtoul(val, NULL, 0);
259 else if (!strcmp(opt, "partition") && val)
260 uopt->partition = simple_strtoul(val, NULL, 0);
261 else if (!strcmp(opt, "fileset") && val)
262 uopt->fileset = simple_strtoul(val, NULL, 0);
263 else if (!strcmp(opt, "rootdir") && val)
264 uopt->rootdir = simple_strtoul(val, NULL, 0);
266 else if (!strcmp(opt, "iocharset") && val)
268 uopt->nls_map = load_nls(val);
269 uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
272 else if (!strcmp(opt, "utf8") && !val)
273 uopt->flags |= (1 << UDF_FLAG_UTF8);
276 printk(KERN_ERR "udf: bad mount option \"%s=%s\"\n",
282 printk(KERN_ERR "udf: bad mount option \"%s\"\n",
291 udf_write_super(struct super_block *sb)
293 if (!(sb->s_flags & MS_RDONLY))
299 udf_remount_fs(struct super_block *sb, int *flags, char *options)
301 struct udf_options uopt;
303 uopt.flags = UDF_SB(sb)->s_flags ;
304 uopt.uid = UDF_SB(sb)->s_uid ;
305 uopt.gid = UDF_SB(sb)->s_gid ;
306 uopt.umask = UDF_SB(sb)->s_umask ;
308 if ( !udf_parse_options(options, &uopt) )
311 UDF_SB(sb)->s_flags = uopt.flags;
312 UDF_SB(sb)->s_uid = uopt.uid;
313 UDF_SB(sb)->s_gid = uopt.gid;
314 UDF_SB(sb)->s_umask = uopt.umask;
320 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
322 if (*flags & MS_RDONLY)
334 * Set the block size to be used in all transfers.
337 * To allow room for a DMA transfer, it is best to guess big when unsure.
338 * This routine picks 2048 bytes as the blocksize when guessing. This
339 * should be adequate until devices with larger block sizes become common.
341 * Note that the Linux kernel can currently only deal with blocksizes of
342 * 512, 1024, 2048, 4096, and 8192 bytes.
345 * sb Pointer to _locked_ superblock.
348 * sb->s_blocksize Blocksize.
349 * sb->s_blocksize_bits log2 of blocksize.
350 * <return> 0 Blocksize is valid.
351 * <return> 1 Blocksize is invalid.
354 * July 1, 1997 - Andrew E. Mileski
355 * Written, tested, and released.
358 udf_set_blocksize(struct super_block *sb, int bsize)
360 /* Use specified block size if specified */
362 sb->s_blocksize = bsize;
363 if (get_hardsect_size(sb->s_dev) > sb->s_blocksize)
364 sb->s_blocksize = get_hardsect_size(sb->s_dev);
366 /* Block size must be an even multiple of 512 */
367 switch (sb->s_blocksize)
369 case 512: sb->s_blocksize_bits = 9; break;
370 case 1024: sb->s_blocksize_bits = 10; break;
371 case 2048: sb->s_blocksize_bits = 11; break;
372 case 4096: sb->s_blocksize_bits = 12; break;
373 case 8192: sb->s_blocksize_bits = 13; break;
376 udf_debug("Bad block size (%ld)\n", sb->s_blocksize);
377 printk(KERN_ERR "udf: bad block size (%ld)\n", sb->s_blocksize);
382 /* Set the block size */
383 set_blocksize(sb->s_dev, sb->s_blocksize);
384 return sb->s_blocksize;
388 udf_vrs(struct super_block *sb, int silent)
390 struct volStructDesc *vsd = NULL;
393 struct buffer_head *bh = NULL;
398 /* Block size must be a multiple of 512 */
399 if (sb->s_blocksize & 511)
402 if (sb->s_blocksize < sizeof(struct volStructDesc))
403 sectorsize = sizeof(struct volStructDesc);
405 sectorsize = sb->s_blocksize;
407 sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits);
409 udf_debug("Starting at sector %u (%ld byte sectors)\n",
410 (sector >> sb->s_blocksize_bits), sb->s_blocksize);
411 /* Process the sequence (if applicable) */
412 for (;!nsr02 && !nsr03; sector += sectorsize)
415 bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
419 /* Look for ISO descriptors */
420 vsd = (struct volStructDesc *)(bh->b_data +
421 (sector & (sb->s_blocksize - 1)));
423 if (vsd->stdIdent[0] == 0)
425 udf_release_data(bh);
428 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN))
431 switch (vsd->structType)
434 udf_debug("ISO9660 Boot Record found\n");
437 udf_debug("ISO9660 Primary Volume Descriptor found\n");
440 udf_debug("ISO9660 Supplementary Volume Descriptor found\n");
443 udf_debug("ISO9660 Volume Partition Descriptor found\n");
446 udf_debug("ISO9660 Volume Descriptor Set Terminator found\n");
449 udf_debug("ISO9660 VRS (%u) found\n", vsd->structType);
453 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN))
456 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01, VSD_STD_ID_LEN))
458 udf_release_data(bh);
461 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN))
465 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN))
469 udf_release_data(bh);
476 else if (sector - (UDF_SB_SESSION(sb) << sb->s_blocksize_bits) == 32768)
486 * Find an anchor volume descriptor.
489 * sb Pointer to _locked_ superblock.
490 * lastblock Last block on media.
493 * <return> 1 if not found, 0 if ok
496 * July 1, 1997 - Andrew E. Mileski
497 * Written, tested, and released.
500 udf_find_anchor(struct super_block *sb)
502 int lastblock = UDF_SB_LASTBLOCK(sb);
503 struct buffer_head *bh = NULL;
510 int varlastblock = udf_variable_to_fixed(lastblock);
511 int last[] = { lastblock, lastblock - 2,
512 lastblock - 150, lastblock - 152,
513 varlastblock, varlastblock - 2,
514 varlastblock - 150, varlastblock - 152 };
518 /* Search for an anchor volume descriptor pointer */
520 /* according to spec, anchor is in either:
524 * however, if the disc isn't closed, it could be 512 */
526 for (i=0; (!lastblock && i<sizeof(last)/sizeof(int)); i++)
528 if (last[i] < 0 || !(bh = sb_bread(sb, last[i])))
530 ident = location = 0;
534 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
535 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
536 udf_release_data(bh);
539 if (ident == TAG_IDENT_AVDP)
541 if (location == last[i] - UDF_SB_SESSION(sb))
543 lastblock = UDF_SB_ANCHOR(sb)[0] = last[i];
544 UDF_SB_ANCHOR(sb)[1] = last[i] - 256;
546 else if (location == udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb))
548 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
549 lastblock = UDF_SB_ANCHOR(sb)[0] = udf_variable_to_fixed(last[i]);
550 UDF_SB_ANCHOR(sb)[1] = lastblock - 256;
553 udf_debug("Anchor found at block %d, location mismatch %d.\n",
556 else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE)
559 UDF_SB_ANCHOR(sb)[3] = 512 + UDF_SB_SESSION(sb);
563 if (last[i] < 256 || !(bh = sb_bread(sb, last[i] - 256)))
565 ident = location = 0;
569 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
570 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
571 udf_release_data(bh);
574 if (ident == TAG_IDENT_AVDP &&
575 location == last[i] - 256 - UDF_SB_SESSION(sb))
578 UDF_SB_ANCHOR(sb)[1] = last[i] - 256;
582 if (last[i] < 312 + UDF_SB_SESSION(sb) || !(bh = sb_bread(sb, last[i] - 312 - UDF_SB_SESSION(sb))))
584 ident = location = 0;
588 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
589 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
590 udf_release_data(bh);
593 if (ident == TAG_IDENT_AVDP &&
594 location == udf_variable_to_fixed(last[i]) - 256)
596 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
597 lastblock = udf_variable_to_fixed(last[i]);
598 UDF_SB_ANCHOR(sb)[1] = lastblock - 256;
607 /* We havn't found the lastblock. check 312 */
608 if ((bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb))))
610 ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
611 location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
612 udf_release_data(bh);
614 if (ident == TAG_IDENT_AVDP && location == 256)
615 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
619 for (i=0; i<sizeof(UDF_SB_ANCHOR(sb))/sizeof(int); i++)
621 if (UDF_SB_ANCHOR(sb)[i])
623 if (!(bh = udf_read_tagged(sb,
624 UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident)))
626 UDF_SB_ANCHOR(sb)[i] = 0;
630 udf_release_data(bh);
631 if ((ident != TAG_IDENT_AVDP) && (i ||
632 (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE)))
634 UDF_SB_ANCHOR(sb)[i] = 0;
640 UDF_SB_LASTBLOCK(sb) = lastblock;
644 udf_find_fileset(struct super_block *sb, lb_addr *fileset, lb_addr *root)
646 struct buffer_head *bh = NULL;
650 if (fileset->logicalBlockNum != 0xFFFFFFFF ||
651 fileset->partitionReferenceNum != 0xFFFF)
653 bh = udf_read_ptagged(sb, *fileset, 0, &ident);
657 else if (ident != TAG_IDENT_FSD)
659 udf_release_data(bh);
665 if (!bh) /* Search backwards through the partitions */
671 for (newfileset.partitionReferenceNum=UDF_SB_NUMPARTS(sb)-1;
672 (newfileset.partitionReferenceNum != 0xFFFF &&
673 fileset->logicalBlockNum == 0xFFFFFFFF &&
674 fileset->partitionReferenceNum == 0xFFFF);
675 newfileset.partitionReferenceNum--)
677 lastblock = UDF_SB_PARTLEN(sb, newfileset.partitionReferenceNum);
678 newfileset.logicalBlockNum = 0;
682 bh = udf_read_ptagged(sb, newfileset, 0, &ident);
685 newfileset.logicalBlockNum ++;
693 struct spaceBitmapDesc *sp;
694 sp = (struct spaceBitmapDesc *)bh->b_data;
695 newfileset.logicalBlockNum += 1 +
696 ((le32_to_cpu(sp->numOfBytes) + sizeof(struct spaceBitmapDesc) - 1)
697 >> sb->s_blocksize_bits);
698 udf_release_data(bh);
703 *fileset = newfileset;
708 newfileset.logicalBlockNum ++;
709 udf_release_data(bh);
715 while (newfileset.logicalBlockNum < lastblock &&
716 fileset->logicalBlockNum == 0xFFFFFFFF &&
717 fileset->partitionReferenceNum == 0xFFFF);
721 if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
722 fileset->partitionReferenceNum != 0xFFFF) && bh)
724 udf_debug("Fileset at block=%d, partition=%d\n",
725 fileset->logicalBlockNum, fileset->partitionReferenceNum);
727 UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum;
728 udf_load_fileset(sb, bh, root);
729 udf_release_data(bh);
736 udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
738 struct primaryVolDesc *pvoldesc;
744 pvoldesc = (struct primaryVolDesc *)bh->b_data;
746 if ( udf_stamp_to_time(&recording, &recording_usec,
747 lets_to_cpu(pvoldesc->recordingDateAndTime)) )
750 ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
751 udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n",
752 recording, recording_usec,
753 ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.typeAndTimezone);
754 UDF_SB_RECORDTIME(sb) = recording;
757 if ( !udf_build_ustr(&instr, pvoldesc->volIdent, 32) )
759 if (udf_CS0toUTF8(&outstr, &instr))
761 strncpy( UDF_SB_VOLIDENT(sb), outstr.u_name,
762 outstr.u_len > 31 ? 31 : outstr.u_len);
763 udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb));
767 if ( !udf_build_ustr(&instr, pvoldesc->volSetIdent, 128) )
769 if (udf_CS0toUTF8(&outstr, &instr))
770 udf_debug("volSetIdent[] = '%s'\n", outstr.u_name);
775 udf_load_fileset(struct super_block *sb, struct buffer_head *bh, lb_addr *root)
777 struct fileSetDesc *fset;
779 fset = (struct fileSetDesc *)bh->b_data;
781 *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
783 UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum);
785 udf_debug("Rootdir at block=%d, partition=%d\n",
786 root->logicalBlockNum, root->partitionReferenceNum);
790 udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
792 struct partitionDesc *p;
795 p = (struct partitionDesc *)bh->b_data;
797 for (i=0; i<UDF_SB_NUMPARTS(sb); i++)
799 udf_debug("Searching map: (%d == %d)\n",
800 UDF_SB_PARTMAPS(sb)[i].s_partition_num, le16_to_cpu(p->partitionNumber));
801 if (UDF_SB_PARTMAPS(sb)[i].s_partition_num == le16_to_cpu(p->partitionNumber))
803 UDF_SB_PARTLEN(sb,i) = le32_to_cpu(p->partitionLength); /* blocks */
804 UDF_SB_PARTROOT(sb,i) = le32_to_cpu(p->partitionStartingLocation) + UDF_SB_SESSION(sb);
805 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY)
806 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_READ_ONLY;
807 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_WRITE_ONCE)
808 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_WRITE_ONCE;
809 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_REWRITABLE)
810 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_REWRITABLE;
811 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_OVERWRITABLE)
812 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_OVERWRITABLE;
814 if (!strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) ||
815 !strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03))
817 struct partitionHeaderDesc *phd;
819 phd = (struct partitionHeaderDesc *)(p->partitionContentsUse);
820 if (phd->unallocSpaceTable.extLength)
822 lb_addr loc = { le32_to_cpu(phd->unallocSpaceTable.extPosition), i };
824 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table =
826 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_TABLE;
827 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
828 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table->i_ino);
830 if (phd->unallocSpaceBitmap.extLength)
832 UDF_SB_ALLOC_BITMAP(sb, i, s_uspace);
833 if (UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap != NULL)
835 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extLength =
836 le32_to_cpu(phd->unallocSpaceBitmap.extLength);
837 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition =
838 le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
839 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_BITMAP;
840 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
841 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition);
844 if (phd->partitionIntegrityTable.extLength)
845 udf_debug("partitionIntegrityTable (part %d)\n", i);
846 if (phd->freedSpaceTable.extLength)
848 lb_addr loc = { le32_to_cpu(phd->freedSpaceTable.extPosition), i };
850 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table =
852 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_TABLE;
853 udf_debug("freedSpaceTable (part %d) @ %ld\n",
854 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table->i_ino);
856 if (phd->freedSpaceBitmap.extLength)
858 UDF_SB_ALLOC_BITMAP(sb, i, s_fspace);
859 if (UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap != NULL)
861 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extLength =
862 le32_to_cpu(phd->freedSpaceBitmap.extLength);
863 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition =
864 le32_to_cpu(phd->freedSpaceBitmap.extPosition);
865 UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_BITMAP;
866 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
867 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition);
874 if (i == UDF_SB_NUMPARTS(sb))
876 udf_debug("Partition (%d) not found in partition map\n", le16_to_cpu(p->partitionNumber));
880 udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
881 le16_to_cpu(p->partitionNumber), i, UDF_SB_PARTTYPE(sb,i),
882 UDF_SB_PARTROOT(sb,i), UDF_SB_PARTLEN(sb,i));
887 udf_load_logicalvol(struct super_block *sb, struct buffer_head * bh, lb_addr *fileset)
889 struct logicalVolDesc *lvd;
893 lvd = (struct logicalVolDesc *)bh->b_data;
895 UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps));
898 i<UDF_SB_NUMPARTS(sb) && offset<le32_to_cpu(lvd->mapTableLength);
899 i++,offset+=((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength)
901 type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType;
904 struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]);
905 UDF_SB_PARTTYPE(sb,i) = UDF_TYPE1_MAP15;
906 UDF_SB_PARTVSN(sb,i) = le16_to_cpu(gpm1->volSeqNum);
907 UDF_SB_PARTNUM(sb,i) = le16_to_cpu(gpm1->partitionNum);
908 UDF_SB_PARTFUNC(sb,i) = NULL;
912 struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]);
913 if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL)))
915 if (le16_to_cpu(((uint16_t *)upm2->partIdent.identSuffix)[0]) == 0x0150)
917 UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP15;
918 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt15;
920 else if (le16_to_cpu(((uint16_t *)upm2->partIdent.identSuffix)[0]) == 0x0200)
922 UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP20;
923 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt20;
926 else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE)))
930 struct sparingTable *st;
931 struct sparablePartitionMap *spm = (struct sparablePartitionMap *)&(lvd->partitionMaps[offset]);
933 UDF_SB_PARTTYPE(sb,i) = UDF_SPARABLE_MAP15;
934 UDF_SB_TYPESPAR(sb,i).s_packet_len = le16_to_cpu(spm->packetLength);
935 for (j=0; j<spm->numSparingTables; j++)
937 loc = le32_to_cpu(spm->locSparingTable[j]);
938 UDF_SB_TYPESPAR(sb,i).s_spar_map[j] =
939 udf_read_tagged(sb, loc, loc, &ident);
940 if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL)
942 st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,i).s_spar_map[j]->b_data;
944 strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING)))
946 udf_release_data(UDF_SB_TYPESPAR(sb,i).s_spar_map[j]);
947 UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = NULL;
951 UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_spar15;
955 udf_debug("Unknown ident: %s\n", upm2->partIdent.ident);
958 UDF_SB_PARTVSN(sb,i) = le16_to_cpu(upm2->volSeqNum);
959 UDF_SB_PARTNUM(sb,i) = le16_to_cpu(upm2->partitionNum);
961 udf_debug("Partition (%d:%d) type %d on volume %d\n",
962 i, UDF_SB_PARTNUM(sb,i), type, UDF_SB_PARTVSN(sb,i));
967 long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]);
969 *fileset = lelb_to_cpu(la->extLocation);
970 udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
971 fileset->logicalBlockNum,
972 fileset->partitionReferenceNum);
974 if (lvd->integritySeqExt.extLength)
975 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
980 * udf_load_logicalvolint
984 udf_load_logicalvolint(struct super_block *sb, extent_ad loc)
986 struct buffer_head *bh = NULL;
989 while (loc.extLength > 0 &&
990 (bh = udf_read_tagged(sb, loc.extLocation,
991 loc.extLocation, &ident)) &&
992 ident == TAG_IDENT_LVID)
994 UDF_SB_LVIDBH(sb) = bh;
996 if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength)
997 udf_load_logicalvolint(sb, leea_to_cpu(UDF_SB_LVID(sb)->nextIntegrityExt));
999 if (UDF_SB_LVIDBH(sb) != bh)
1000 udf_release_data(bh);
1001 loc.extLength -= sb->s_blocksize;
1004 if (UDF_SB_LVIDBH(sb) != bh)
1005 udf_release_data(bh);
1009 * udf_process_sequence
1012 * Process a main/reserve volume descriptor sequence.
1015 * sb Pointer to _locked_ superblock.
1016 * block First block of first extent of the sequence.
1017 * lastblock Lastblock of first extent of the sequence.
1020 * July 1, 1997 - Andrew E. Mileski
1021 * Written, tested, and released.
1024 udf_process_sequence(struct super_block *sb, long block, long lastblock, lb_addr *fileset)
1026 struct buffer_head *bh = NULL;
1027 struct udf_vds_record vds[VDS_POS_LENGTH];
1028 struct generic_desc *gd;
1029 struct volDescPtr *vdp;
1034 long next_s = 0, next_e = 0;
1036 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
1038 /* Read the main descriptor sequence */
1039 for (;(!done && block <= lastblock); block++)
1042 bh = udf_read_tagged(sb, block, block, &ident);
1046 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1047 gd = (struct generic_desc *)bh->b_data;
1048 vdsn = le32_to_cpu(gd->volDescSeqNum);
1051 case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
1052 if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum)
1054 vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn;
1055 vds[VDS_POS_PRIMARY_VOL_DESC].block = block;
1058 case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
1059 if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum)
1061 vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn;
1062 vds[VDS_POS_VOL_DESC_PTR].block = block;
1064 vdp = (struct volDescPtr *)bh->b_data;
1065 next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation);
1066 next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength);
1067 next_e = next_e >> sb->s_blocksize_bits;
1071 case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
1072 if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum)
1074 vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn;
1075 vds[VDS_POS_IMP_USE_VOL_DESC].block = block;
1078 case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
1079 if (!vds[VDS_POS_PARTITION_DESC].block)
1080 vds[VDS_POS_PARTITION_DESC].block = block;
1082 case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
1083 if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum)
1085 vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn;
1086 vds[VDS_POS_LOGICAL_VOL_DESC].block = block;
1089 case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
1090 if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum)
1092 vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn;
1093 vds[VDS_POS_UNALLOC_SPACE_DESC].block = block;
1096 case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
1097 vds[VDS_POS_TERMINATING_DESC].block = block;
1102 next_s = next_e = 0;
1108 udf_release_data(bh);
1110 for (i=0; i<VDS_POS_LENGTH; i++)
1114 bh = udf_read_tagged(sb, vds[i].block, vds[i].block, &ident);
1116 if (i == VDS_POS_PRIMARY_VOL_DESC)
1117 udf_load_pvoldesc(sb, bh);
1118 else if (i == VDS_POS_LOGICAL_VOL_DESC)
1119 udf_load_logicalvol(sb, bh, fileset);
1120 else if (i == VDS_POS_PARTITION_DESC)
1122 struct buffer_head *bh2 = NULL;
1123 udf_load_partdesc(sb, bh);
1124 for (j=vds[i].block+1; j<vds[VDS_POS_TERMINATING_DESC].block; j++)
1126 bh2 = udf_read_tagged(sb, j, j, &ident);
1127 gd = (struct generic_desc *)bh2->b_data;
1128 if (ident == TAG_IDENT_PD)
1129 udf_load_partdesc(sb, bh2);
1130 udf_release_data(bh2);
1133 udf_release_data(bh);
1144 udf_check_valid(struct super_block *sb, int novrs, int silent)
1150 udf_debug("Validity check skipped because of novrs option\n");
1153 /* Check that it is NSR02 compliant */
1154 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1155 else if ((block = udf_vrs(sb, silent)) == -1)
1157 udf_debug("Failed to read byte 32768. Assuming open disc. Skipping validity check\n");
1158 if (!UDF_SB_LASTBLOCK(sb))
1159 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
1167 udf_load_partition(struct super_block *sb, lb_addr *fileset)
1169 struct anchorVolDescPtr *anchor;
1171 struct buffer_head *bh;
1172 long main_s, main_e, reserve_s, reserve_e;
1178 for (i=0; i<sizeof(UDF_SB_ANCHOR(sb))/sizeof(int); i++)
1180 if (UDF_SB_ANCHOR(sb)[i] && (bh = udf_read_tagged(sb,
1181 UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident)))
1183 anchor = (struct anchorVolDescPtr *)bh->b_data;
1185 /* Locate the main sequence */
1186 main_s = le32_to_cpu( anchor->mainVolDescSeqExt.extLocation );
1187 main_e = le32_to_cpu( anchor->mainVolDescSeqExt.extLength );
1188 main_e = main_e >> sb->s_blocksize_bits;
1191 /* Locate the reserve sequence */
1192 reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation);
1193 reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
1194 reserve_e = reserve_e >> sb->s_blocksize_bits;
1195 reserve_e += reserve_s;
1197 udf_release_data(bh);
1199 /* Process the main & reserve sequences */
1200 /* responsible for finding the PartitionDesc(s) */
1201 if (!(udf_process_sequence(sb, main_s, main_e, fileset) &&
1202 udf_process_sequence(sb, reserve_s, reserve_e, fileset)))
1209 if (i == sizeof(UDF_SB_ANCHOR(sb))/sizeof(int))
1211 udf_debug("No Anchor block found\n");
1215 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]);
1217 for (i=0; i<UDF_SB_NUMPARTS(sb); i++)
1219 switch UDF_SB_PARTTYPE(sb, i)
1221 case UDF_VIRTUAL_MAP15:
1222 case UDF_VIRTUAL_MAP20:
1226 if (!UDF_SB_LASTBLOCK(sb))
1228 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
1229 udf_find_anchor(sb);
1232 if (!UDF_SB_LASTBLOCK(sb))
1234 udf_debug("Unable to determine Lastblock (For Virtual Partition)\n");
1238 for (j=0; j<UDF_SB_NUMPARTS(sb); j++)
1241 UDF_SB_PARTVSN(sb,i) == UDF_SB_PARTVSN(sb,j) &&
1242 UDF_SB_PARTNUM(sb,i) == UDF_SB_PARTNUM(sb,j))
1244 ino.partitionReferenceNum = j;
1245 ino.logicalBlockNum = UDF_SB_LASTBLOCK(sb) -
1246 UDF_SB_PARTROOT(sb,j);
1251 if (j == UDF_SB_NUMPARTS(sb))
1254 if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino)))
1257 if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP15)
1259 UDF_SB_TYPEVIRT(sb,i).s_start_offset = udf_ext0_offset(UDF_SB_VAT(sb));
1260 UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size - 36) >> 2;
1262 else if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP20)
1264 struct buffer_head *bh = NULL;
1267 pos = udf_block_map(UDF_SB_VAT(sb), 0);
1268 bh = sb_bread(sb, pos);
1269 UDF_SB_TYPEVIRT(sb,i).s_start_offset =
1270 le16_to_cpu(((struct virtualAllocationTable20 *)bh->b_data + udf_ext0_offset(UDF_SB_VAT(sb)))->lengthHeader) +
1271 udf_ext0_offset(UDF_SB_VAT(sb));
1272 UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size -
1273 UDF_SB_TYPEVIRT(sb,i).s_start_offset) >> 2;
1274 udf_release_data(bh);
1276 UDF_SB_PARTROOT(sb,i) = udf_get_pblock(sb, 0, i, 0);
1277 UDF_SB_PARTLEN(sb,i) = UDF_SB_PARTLEN(sb,ino.partitionReferenceNum);
1284 static void udf_open_lvid(struct super_block *sb)
1286 if (UDF_SB_LVIDBH(sb))
1291 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1292 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1293 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME, CURRENT_UTIME))
1294 UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time);
1295 UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN;
1297 UDF_SB_LVID(sb)->descTag.descCRC =
1298 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1299 le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0));
1301 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
1302 for (i=0; i<16; i++)
1304 UDF_SB_LVID(sb)->descTag.tagChecksum +=
1305 ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i];
1307 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
1311 static void udf_close_lvid(struct super_block *sb)
1313 if (UDF_SB_LVIDBH(sb) &&
1314 UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN)
1319 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1320 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1321 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME, CURRENT_UTIME))
1322 UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time);
1323 if (UDF_MAX_WRITE_VERSION > le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev))
1324 UDF_SB_LVIDIU(sb)->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
1325 if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev))
1326 UDF_SB_LVIDIU(sb)->minUDFReadRev = cpu_to_le16(UDF_SB_UDFREV(sb));
1327 if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev))
1328 UDF_SB_LVIDIU(sb)->minUDFWriteRev = cpu_to_le16(UDF_SB_UDFREV(sb));
1329 UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_CLOSE;
1331 UDF_SB_LVID(sb)->descTag.descCRC =
1332 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1333 le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0));
1335 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
1336 for (i=0; i<16; i++)
1338 UDF_SB_LVID(sb)->descTag.tagChecksum +=
1339 ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i];
1341 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
1349 * Complete the specified super block.
1352 * sb Pointer to superblock to complete - never NULL.
1353 * sb->s_dev Device to read suberblock from.
1354 * options Pointer to mount options.
1355 * silent Silent flag.
1358 * July 1, 1997 - Andrew E. Mileski
1359 * Written, tested, and released.
1361 static struct super_block *
1362 udf_read_super(struct super_block *sb, void *options, int silent)
1365 struct inode *inode=NULL;
1366 struct udf_options uopt;
1367 lb_addr rootdir, fileset;
1369 uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
1374 memset(UDF_SB(sb), 0x00, sizeof(struct udf_sb_info));
1377 sb->s_flags |= MS_RDONLY;
1380 if (!udf_parse_options((char *)options, &uopt))
1383 if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
1384 uopt.flags & (1 << UDF_FLAG_NLS_MAP))
1386 udf_error(sb, "udf_read_super",
1387 "utf8 cannot be combined with iocharset\n");
1391 if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map)
1393 uopt.nls_map = load_nls_default();
1395 uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
1397 udf_debug("Using default NLS map\n");
1400 if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
1401 uopt.flags |= (1 << UDF_FLAG_UTF8);
1403 fileset.logicalBlockNum = 0xFFFFFFFF;
1404 fileset.partitionReferenceNum = 0xFFFF;
1406 UDF_SB(sb)->s_flags = uopt.flags;
1407 UDF_SB(sb)->s_uid = uopt.uid;
1408 UDF_SB(sb)->s_gid = uopt.gid;
1409 UDF_SB(sb)->s_umask = uopt.umask;
1410 UDF_SB(sb)->s_nls_map = uopt.nls_map;
1412 /* Set the block size for all transfers */
1413 if (!udf_set_blocksize(sb, uopt.blocksize))
1416 if ( uopt.session == 0xFFFFFFFF )
1417 UDF_SB_SESSION(sb) = udf_get_last_session(sb);
1419 UDF_SB_SESSION(sb) = uopt.session;
1421 udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb));
1423 UDF_SB_LASTBLOCK(sb) = uopt.lastblock;
1424 UDF_SB_ANCHOR(sb)[0] = UDF_SB_ANCHOR(sb)[1] = 0;
1425 UDF_SB_ANCHOR(sb)[2] = uopt.anchor;
1426 UDF_SB_ANCHOR(sb)[3] = UDF_SB_SESSION(sb) + 256;
1428 if (udf_check_valid(sb, uopt.novrs, silent)) /* read volume recognition sequences */
1430 printk("UDF-fs: No VRS found\n");
1434 udf_find_anchor(sb);
1436 /* Fill in the rest of the superblock */
1437 sb->s_op = &udf_sb_ops;
1440 sb->s_magic = UDF_SUPER_MAGIC;
1442 if (udf_load_partition(sb, &fileset))
1444 printk("UDF-fs: No partition found (1)\n");
1448 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb));
1450 if ( UDF_SB_LVIDBH(sb) )
1452 uint16_t minUDFReadRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev);
1453 uint16_t minUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
1454 /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */
1456 if (minUDFReadRev > UDF_MAX_READ_VERSION)
1458 printk("UDF-fs: minUDFReadRev=%x (max is %x)\n",
1459 UDF_SB_LVIDIU(sb)->minUDFReadRev, UDF_MAX_READ_VERSION);
1462 else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
1464 sb->s_flags |= MS_RDONLY;
1467 UDF_SB_UDFREV(sb) = minUDFWriteRev;
1469 if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
1470 UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
1471 if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
1472 UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
1475 if ( !UDF_SB_NUMPARTS(sb) )
1477 printk("UDF-fs: No partition found (2)\n");
1481 if ( udf_find_fileset(sb, &fileset, &rootdir) )
1483 printk("UDF-fs: No fileset found\n");
1490 udf_time_to_stamp(&ts, UDF_SB_RECORDTIME(sb), 0);
1491 udf_info("UDF %s-%s (%s) Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1492 UDFFS_VERSION, UDFFS_RW ? "rw" : "ro", UDFFS_DATE,
1493 UDF_SB_VOLIDENT(sb), ts.year, ts.month, ts.day, ts.hour, ts.minute,
1494 ts.typeAndTimezone);
1496 if (!(sb->s_flags & MS_RDONLY))
1499 /* Assign the root inode */
1500 /* assign inodes by physical block number */
1501 /* perhaps it's not extensible enough, but for now ... */
1502 inode = udf_iget(sb, rootdir);
1505 printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n",
1506 rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
1510 /* Allocate a dentry for the root inode */
1511 sb->s_root = d_alloc_root(inode);
1514 printk("UDF-fs: Couldn't allocate root dentry\n");
1518 sb->s_maxbytes = 1<<30;
1523 iput(UDF_SB_VAT(sb));
1524 if (UDF_SB_NUMPARTS(sb))
1526 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
1527 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1528 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
1529 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
1530 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
1532 for (i=0; i<UDF_SB_BITMAP_NR_GROUPS(sb,UDF_SB_PARTITION(sb),s_uspace); i++)
1534 if (UDF_SB_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace,i))
1535 udf_release_data(UDF_SB_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace,i));
1537 kfree(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_bitmap);
1539 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
1541 for (i=0; i<UDF_SB_BITMAP_NR_GROUPS(sb,UDF_SB_PARTITION(sb),s_fspace); i++)
1543 if (UDF_SB_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace,i))
1544 udf_release_data(UDF_SB_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace,i));
1546 kfree(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_bitmap);
1548 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15)
1551 udf_release_data(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
1555 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1556 unload_nls(UDF_SB(sb)->s_nls_map);
1558 if (!(sb->s_flags & MS_RDONLY))
1560 udf_release_data(UDF_SB_LVIDBH(sb));
1565 void udf_error(struct super_block *sb, const char *function,
1566 const char *fmt, ...)
1570 if (!(sb->s_flags & MS_RDONLY))
1575 va_start(args, fmt);
1576 vsprintf(error_buf, fmt, args);
1578 printk (KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
1579 bdevname(sb->s_dev), function, error_buf);
1582 void udf_warning(struct super_block *sb, const char *function,
1583 const char *fmt, ...)
1587 va_start (args, fmt);
1588 vsprintf(error_buf, fmt, args);
1590 printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
1591 bdevname(sb->s_dev), function, error_buf);
1598 * Prepare for destruction of the superblock.
1601 * Called before the filesystem is unmounted.
1604 * July 1, 1997 - Andrew E. Mileski
1605 * Written, tested, and released.
1608 udf_put_super(struct super_block *sb)
1613 iput(UDF_SB_VAT(sb));
1614 if (UDF_SB_NUMPARTS(sb))
1616 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
1617 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1618 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
1619 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
1620 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
1622 for (i=0; i<UDF_SB_BITMAP_NR_GROUPS(sb,UDF_SB_PARTITION(sb),s_uspace); i++)
1624 if (UDF_SB_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace,i))
1625 udf_release_data(UDF_SB_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace,i));
1627 kfree(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_bitmap);
1629 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
1631 for (i=0; i<UDF_SB_BITMAP_NR_GROUPS(sb,UDF_SB_PARTITION(sb),s_fspace); i++)
1633 if (UDF_SB_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace,i))
1634 udf_release_data(UDF_SB_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace,i));
1636 kfree(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_bitmap);
1638 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15)
1641 udf_release_data(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
1645 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1646 unload_nls(UDF_SB(sb)->s_nls_map);
1648 if (!(sb->s_flags & MS_RDONLY))
1650 udf_release_data(UDF_SB_LVIDBH(sb));
1658 * Return info about the filesystem.
1661 * Called by sys_statfs()
1664 * July 1, 1997 - Andrew E. Mileski
1665 * Written, tested, and released.
1668 udf_statfs(struct super_block *sb, struct statfs *buf)
1670 buf->f_type = UDF_SUPER_MAGIC;
1671 buf->f_bsize = sb->s_blocksize;
1672 buf->f_blocks = UDF_SB_PARTLEN(sb, UDF_SB_PARTITION(sb));
1673 buf->f_bfree = udf_count_free(sb);
1674 buf->f_bavail = buf->f_bfree;
1675 buf->f_files = (UDF_SB_LVIDBH(sb) ?
1676 (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) +
1677 le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) + buf->f_bfree;
1678 buf->f_ffree = buf->f_bfree;
1679 /* __kernel_fsid_t f_fsid */
1680 buf->f_namelen = UDF_NAME_LEN;
1685 static unsigned char udf_bitmap_lookup[16] = {
1686 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
1690 udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
1692 struct buffer_head *bh = NULL;
1693 unsigned int accum = 0;
1695 int block = 0, newblock;
1701 struct spaceBitmapDesc *bm;
1703 loc.logicalBlockNum = bitmap->s_extPosition;
1704 loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
1705 bh = udf_read_ptagged(sb, loc, 0, &ident);
1709 printk(KERN_ERR "udf: udf_count_free failed\n");
1712 else if (ident != TAG_IDENT_SBD)
1714 udf_release_data(bh);
1715 printk(KERN_ERR "udf: udf_count_free failed\n");
1719 bm = (struct spaceBitmapDesc *)bh->b_data;
1720 bytes = bm->numOfBytes;
1721 index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
1722 ptr = (uint8_t *)bh->b_data;
1726 while ((bytes > 0) && (index < sb->s_blocksize))
1729 accum += udf_bitmap_lookup[ value & 0x0f ];
1730 accum += udf_bitmap_lookup[ value >> 4 ];
1736 udf_release_data(bh);
1737 newblock = udf_get_lb_pblock(sb, loc, ++block);
1738 bh = udf_tread(sb, newblock);
1741 udf_debug("read failed\n");
1745 ptr = (uint8_t *)bh->b_data;
1748 udf_release_data(bh);
1753 udf_count_free_table(struct super_block *sb, struct inode * table)
1755 unsigned int accum = 0;
1756 uint32_t extoffset, elen;
1759 struct buffer_head *bh = NULL;
1761 bloc = UDF_I_LOCATION(table);
1762 extoffset = sizeof(struct unallocSpaceEntry);
1764 while ((etype = udf_next_aext(table, &bloc, &extoffset, &eloc, &elen, &bh, 1)) != -1)
1766 accum += (elen >> table->i_sb->s_blocksize_bits);
1768 udf_release_data(bh);
1773 udf_count_free(struct super_block *sb)
1775 unsigned int accum = 0;
1777 if (UDF_SB_LVIDBH(sb))
1779 if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) > UDF_SB_PARTITION(sb))
1781 accum = le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]);
1783 if (accum == 0xFFFFFFFF)
1791 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
1793 accum += udf_count_free_bitmap(sb,
1794 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_bitmap);
1796 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
1798 accum += udf_count_free_bitmap(sb,
1799 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_bitmap);
1804 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
1806 accum += udf_count_free_table(sb,
1807 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1809 if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
1811 accum += udf_count_free_table(sb,
1812 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);