5 * Super block routines for the OSTA-UDF(tm) filesystem.
8 * OSTA-UDF(tm) = Optical Storage Technology Association
9 * Universal Disk Format.
11 * This code is based on version 2.00 of the UDF specification,
12 * and revision 3 of the ECMA 167 standard [equivalent to ISO 13346].
13 * http://www.osta.org/
18 * This file is distributed under the terms of the GNU General Public
19 * License (GPL). Copies of the GPL can be obtained from:
20 * ftp://prep.ai.mit.edu/pub/gnu/GPL
21 * Each contributing author retains all rights to their own work.
23 * (C) 1998 Dave Boynton
24 * (C) 1998-2004 Ben Fennema
25 * (C) 2000 Stelias Computing Inc
29 * 09/24/98 dgb changed to allow compiling outside of kernel, and
30 * added some debugging.
31 * 10/01/98 dgb updated to allow (some) possibility of compiling w/2.0.34
32 * 10/16/98 attempting some multi-session support
33 * 10/17/98 added freespace count for "df"
34 * 11/11/98 gr added novrs option
35 * 11/26/98 dgb added fileset,anchor mount options
36 * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced vol descs
37 * rewrote option handling based on isofs
38 * 12/20/98 find the free space bitmap (if it exists)
43 #include <linux/blkdev.h>
44 #include <linux/slab.h>
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/parser.h>
48 #include <linux/stat.h>
49 #include <linux/cdrom.h>
50 #include <linux/nls.h>
51 #include <linux/smp_lock.h>
52 #include <linux/buffer_head.h>
53 #include <linux/vfs.h>
54 #include <linux/vmalloc.h>
55 #include <asm/byteorder.h>
57 #include <linux/udf_fs.h>
61 #include <linux/init.h>
62 #include <asm/uaccess.h>
64 #define VDS_POS_PRIMARY_VOL_DESC 0
65 #define VDS_POS_UNALLOC_SPACE_DESC 1
66 #define VDS_POS_LOGICAL_VOL_DESC 2
67 #define VDS_POS_PARTITION_DESC 3
68 #define VDS_POS_IMP_USE_VOL_DESC 4
69 #define VDS_POS_VOL_DESC_PTR 5
70 #define VDS_POS_TERMINATING_DESC 6
71 #define VDS_POS_LENGTH 7
73 static char error_buf[1024];
75 /* These are the "meat" - everything else is stuffing */
76 static int udf_fill_super(struct super_block *, void *, int);
77 static void udf_put_super(struct super_block *);
78 static void udf_write_super(struct super_block *);
79 static int udf_remount_fs(struct super_block *, int *, char *);
80 static int udf_check_valid(struct super_block *, int, int);
81 static int udf_vrs(struct super_block *sb, int silent);
82 static int udf_load_partition(struct super_block *, kernel_lb_addr *);
83 static int udf_load_logicalvol(struct super_block *, struct buffer_head *,
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 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 dentry *, struct kstatfs *);
98 /* UDF filesystem type */
99 static int udf_get_sb(struct file_system_type *fs_type,
100 int flags, const char *dev_name, void *data,
101 struct vfsmount *mnt)
103 return get_sb_bdev(fs_type, flags, dev_name, data, udf_fill_super, mnt);
106 static struct file_system_type udf_fstype = {
107 .owner = THIS_MODULE,
109 .get_sb = udf_get_sb,
110 .kill_sb = kill_block_super,
111 .fs_flags = FS_REQUIRES_DEV,
114 static struct kmem_cache *udf_inode_cachep;
116 static struct inode *udf_alloc_inode(struct super_block *sb)
118 struct udf_inode_info *ei;
119 ei = (struct udf_inode_info *)kmem_cache_alloc(udf_inode_cachep,
125 ei->i_lenExtents = 0;
126 ei->i_next_alloc_block = 0;
127 ei->i_next_alloc_goal = 0;
130 return &ei->vfs_inode;
133 static void udf_destroy_inode(struct inode *inode)
135 kmem_cache_free(udf_inode_cachep, UDF_I(inode));
138 static void init_once(void *foo, struct kmem_cache *cachep, unsigned long flags)
140 struct udf_inode_info *ei = (struct udf_inode_info *)foo;
142 ei->i_ext.i_data = NULL;
143 inode_init_once(&ei->vfs_inode);
146 static int init_inodecache(void)
148 udf_inode_cachep = kmem_cache_create("udf_inode_cache",
149 sizeof(struct udf_inode_info),
150 0, (SLAB_RECLAIM_ACCOUNT |
153 if (udf_inode_cachep == NULL)
158 static void destroy_inodecache(void)
160 kmem_cache_destroy(udf_inode_cachep);
163 /* Superblock operations */
164 static const struct super_operations udf_sb_ops = {
165 .alloc_inode = udf_alloc_inode,
166 .destroy_inode = udf_destroy_inode,
167 .write_inode = udf_write_inode,
168 .delete_inode = udf_delete_inode,
169 .clear_inode = udf_clear_inode,
170 .put_super = udf_put_super,
171 .write_super = udf_write_super,
172 .statfs = udf_statfs,
173 .remount_fs = udf_remount_fs,
178 unsigned int blocksize;
179 unsigned int session;
180 unsigned int lastblock;
183 unsigned short partition;
184 unsigned int fileset;
185 unsigned int rootdir;
190 struct nls_table *nls_map;
193 static int __init init_udf_fs(void)
196 err = init_inodecache();
199 err = register_filesystem(&udf_fstype);
204 destroy_inodecache();
209 static void __exit exit_udf_fs(void)
211 unregister_filesystem(&udf_fstype);
212 destroy_inodecache();
215 module_init(init_udf_fs)
216 module_exit(exit_udf_fs)
222 * Parse mount options.
225 * The following mount options are supported:
227 * gid= Set the default group.
228 * umask= Set the default umask.
229 * uid= Set the default user.
230 * bs= Set the block size.
231 * unhide Show otherwise hidden files.
232 * undelete Show deleted files in lists.
233 * adinicb Embed data in the inode (default)
234 * noadinicb Don't embed data in the inode
235 * shortad Use short ad's
236 * longad Use long ad's (default)
237 * nostrict Unset strict conformance
238 * iocharset= Set the NLS character set
240 * The remaining are for debugging and disaster recovery:
242 * novrs Skip volume sequence recognition
244 * The following expect a offset from 0.
246 * session= Set the CDROM session (default= last session)
247 * anchor= Override standard anchor location. (default= 256)
248 * volume= Override the VolumeDesc location. (unused)
249 * partition= Override the PartitionDesc location. (unused)
250 * lastblock= Set the last block of the filesystem/
252 * The following expect a offset from the partition root.
254 * fileset= Override the fileset block location. (unused)
255 * rootdir= Override the root directory location. (unused)
256 * WARNING: overriding the rootdir to a non-directory may
257 * yield highly unpredictable results.
260 * options Pointer to mount options string.
261 * uopts Pointer to mount options variable.
264 * <return> 1 Mount options parsed okay.
265 * <return> 0 Error parsing mount options.
268 * July 1, 1997 - Andrew E. Mileski
269 * Written, tested, and released.
272 Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete,
273 Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad,
274 Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock,
275 Opt_anchor, Opt_volume, Opt_partition, Opt_fileset,
276 Opt_rootdir, Opt_utf8, Opt_iocharset,
277 Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore
280 static match_table_t tokens = {
281 {Opt_novrs, "novrs"},
282 {Opt_nostrict, "nostrict"},
284 {Opt_unhide, "unhide"},
285 {Opt_undelete, "undelete"},
286 {Opt_noadinicb, "noadinicb"},
287 {Opt_adinicb, "adinicb"},
288 {Opt_shortad, "shortad"},
289 {Opt_longad, "longad"},
290 {Opt_uforget, "uid=forget"},
291 {Opt_uignore, "uid=ignore"},
292 {Opt_gforget, "gid=forget"},
293 {Opt_gignore, "gid=ignore"},
296 {Opt_umask, "umask=%o"},
297 {Opt_session, "session=%u"},
298 {Opt_lastblock, "lastblock=%u"},
299 {Opt_anchor, "anchor=%u"},
300 {Opt_volume, "volume=%u"},
301 {Opt_partition, "partition=%u"},
302 {Opt_fileset, "fileset=%u"},
303 {Opt_rootdir, "rootdir=%u"},
305 {Opt_iocharset, "iocharset=%s"},
309 static int udf_parse_options(char *options, struct udf_options *uopt)
315 uopt->blocksize = 2048;
316 uopt->partition = 0xFFFF;
317 uopt->session = 0xFFFFFFFF;
320 uopt->volume = 0xFFFFFFFF;
321 uopt->rootdir = 0xFFFFFFFF;
322 uopt->fileset = 0xFFFFFFFF;
323 uopt->nls_map = NULL;
328 while ((p = strsep(&options, ",")) != NULL) {
329 substring_t args[MAX_OPT_ARGS];
334 token = match_token(p, tokens, args);
339 if (match_int(&args[0], &option))
341 uopt->blocksize = option;
344 uopt->flags |= (1 << UDF_FLAG_UNHIDE);
347 uopt->flags |= (1 << UDF_FLAG_UNDELETE);
350 uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
353 uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
356 uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
359 uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
362 if (match_int(args, &option))
367 if (match_int(args, &option))
372 if (match_octal(args, &option))
374 uopt->umask = option;
377 uopt->flags &= ~(1 << UDF_FLAG_STRICT);
380 if (match_int(args, &option))
382 uopt->session = option;
385 if (match_int(args, &option))
387 uopt->lastblock = option;
390 if (match_int(args, &option))
392 uopt->anchor = option;
395 if (match_int(args, &option))
397 uopt->volume = option;
400 if (match_int(args, &option))
402 uopt->partition = option;
405 if (match_int(args, &option))
407 uopt->fileset = option;
410 if (match_int(args, &option))
412 uopt->rootdir = option;
415 uopt->flags |= (1 << UDF_FLAG_UTF8);
417 #ifdef CONFIG_UDF_NLS
419 uopt->nls_map = load_nls(args[0].from);
420 uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
424 uopt->flags |= (1 << UDF_FLAG_UID_IGNORE);
427 uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
430 uopt->flags |= (1 << UDF_FLAG_GID_IGNORE);
433 uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
436 printk(KERN_ERR "udf: bad mount option \"%s\" "
437 "or missing value\n", p);
444 void udf_write_super(struct super_block *sb)
447 if (!(sb->s_flags & MS_RDONLY))
453 static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
455 struct udf_options uopt;
457 uopt.flags = UDF_SB(sb)->s_flags;
458 uopt.uid = UDF_SB(sb)->s_uid;
459 uopt.gid = UDF_SB(sb)->s_gid;
460 uopt.umask = UDF_SB(sb)->s_umask;
462 if (!udf_parse_options(options, &uopt))
465 UDF_SB(sb)->s_flags = uopt.flags;
466 UDF_SB(sb)->s_uid = uopt.uid;
467 UDF_SB(sb)->s_gid = uopt.gid;
468 UDF_SB(sb)->s_umask = uopt.umask;
470 if (UDF_SB_LVIDBH(sb)) {
471 int write_rev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
472 if (write_rev > UDF_MAX_WRITE_VERSION)
476 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
478 if (*flags & MS_RDONLY)
490 * Set the block size to be used in all transfers.
493 * To allow room for a DMA transfer, it is best to guess big when unsure.
494 * This routine picks 2048 bytes as the blocksize when guessing. This
495 * should be adequate until devices with larger block sizes become common.
497 * Note that the Linux kernel can currently only deal with blocksizes of
498 * 512, 1024, 2048, 4096, and 8192 bytes.
501 * sb Pointer to _locked_ superblock.
504 * sb->s_blocksize Blocksize.
505 * sb->s_blocksize_bits log2 of blocksize.
506 * <return> 0 Blocksize is valid.
507 * <return> 1 Blocksize is invalid.
510 * July 1, 1997 - Andrew E. Mileski
511 * Written, tested, and released.
513 static int udf_set_blocksize(struct super_block *sb, int bsize)
515 if (!sb_min_blocksize(sb, bsize)) {
516 udf_debug("Bad block size (%d)\n", bsize);
517 printk(KERN_ERR "udf: bad block size (%d)\n", bsize);
520 return sb->s_blocksize;
523 static int udf_vrs(struct super_block *sb, int silent)
525 struct volStructDesc *vsd = NULL;
528 struct buffer_head *bh = NULL;
533 /* Block size must be a multiple of 512 */
534 if (sb->s_blocksize & 511)
537 if (sb->s_blocksize < sizeof(struct volStructDesc))
538 sectorsize = sizeof(struct volStructDesc);
540 sectorsize = sb->s_blocksize;
542 sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits);
544 udf_debug("Starting at sector %u (%ld byte sectors)\n",
545 (sector >> sb->s_blocksize_bits), sb->s_blocksize);
546 /* Process the sequence (if applicable) */
547 for (; !nsr02 && !nsr03; sector += sectorsize) {
549 bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
553 /* Look for ISO descriptors */
554 vsd = (struct volStructDesc *)(bh->b_data +
556 (sb->s_blocksize - 1)));
558 if (vsd->stdIdent[0] == 0) {
563 (vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN)) {
565 switch (vsd->structType) {
567 udf_debug("ISO9660 Boot Record found\n");
571 ("ISO9660 Primary Volume Descriptor found\n");
575 ("ISO9660 Supplementary Volume Descriptor found\n");
579 ("ISO9660 Volume Partition Descriptor found\n");
583 ("ISO9660 Volume Descriptor Set Terminator found\n");
586 udf_debug("ISO9660 VRS (%u) found\n",
592 (vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN)) {
595 (vsd->stdIdent, VSD_STD_ID_TEA01, VSD_STD_ID_LEN)) {
600 (vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN)) {
604 (vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN)) {
614 else if (sector - (UDF_SB_SESSION(sb) << sb->s_blocksize_bits) == 32768)
624 * Find an anchor volume descriptor.
627 * sb Pointer to _locked_ superblock.
628 * lastblock Last block on media.
631 * <return> 1 if not found, 0 if ok
634 * July 1, 1997 - Andrew E. Mileski
635 * Written, tested, and released.
637 static void udf_find_anchor(struct super_block *sb)
639 int lastblock = UDF_SB_LASTBLOCK(sb);
640 struct buffer_head *bh = NULL;
646 int varlastblock = udf_variable_to_fixed(lastblock);
647 int last[] = { lastblock, lastblock - 2,
648 lastblock - 150, lastblock - 152,
649 varlastblock, varlastblock - 2,
650 varlastblock - 150, varlastblock - 152
655 /* Search for an anchor volume descriptor pointer */
657 /* according to spec, anchor is in either:
661 * however, if the disc isn't closed, it could be 512 */
663 for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) {
664 if (last[i] < 0 || !(bh = sb_bread(sb, last[i]))) {
665 ident = location = 0;
668 le16_to_cpu(((tag *) bh->b_data)->tagIdent);
670 le32_to_cpu(((tag *) bh->b_data)->
675 if (ident == TAG_IDENT_AVDP) {
676 if (location == last[i] - UDF_SB_SESSION(sb)) {
677 lastblock = UDF_SB_ANCHOR(sb)[0] =
678 last[i] - UDF_SB_SESSION(sb);
679 UDF_SB_ANCHOR(sb)[1] =
680 last[i] - 256 - UDF_SB_SESSION(sb);
681 } else if (location ==
682 udf_variable_to_fixed(last[i]) -
683 UDF_SB_SESSION(sb)) {
684 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
685 lastblock = UDF_SB_ANCHOR(sb)[0] =
686 udf_variable_to_fixed(last[i]) -
688 UDF_SB_ANCHOR(sb)[1] =
693 ("Anchor found at block %d, location mismatch %d.\n",
695 } else if (ident == TAG_IDENT_FE
696 || ident == TAG_IDENT_EFE) {
698 UDF_SB_ANCHOR(sb)[3] = 512;
701 || !(bh = sb_bread(sb, last[i] - 256))) {
702 ident = location = 0;
705 le16_to_cpu(((tag *) bh->b_data)->
708 le32_to_cpu(((tag *) bh->b_data)->
713 if (ident == TAG_IDENT_AVDP &&
715 last[i] - 256 - UDF_SB_SESSION(sb)) {
717 UDF_SB_ANCHOR(sb)[1] = last[i] - 256;
719 if (last[i] < 312 + UDF_SB_SESSION(sb)
723 UDF_SB_SESSION(sb))))
725 ident = location = 0;
728 le16_to_cpu(((tag *) bh->
732 le32_to_cpu(((tag *) bh->
738 if (ident == TAG_IDENT_AVDP &&
740 udf_variable_to_fixed(last[i]) -
745 udf_variable_to_fixed(last
747 UDF_SB_ANCHOR(sb)[1] =
756 /* We havn't found the lastblock. check 312 */
757 if ((bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb)))) {
758 ident = le16_to_cpu(((tag *) bh->b_data)->tagIdent);
760 le32_to_cpu(((tag *) bh->b_data)->tagLocation);
763 if (ident == TAG_IDENT_AVDP && location == 256)
764 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
768 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
769 if (UDF_SB_ANCHOR(sb)[i]) {
770 if (!(bh = udf_read_tagged(sb,
771 UDF_SB_ANCHOR(sb)[i],
772 UDF_SB_ANCHOR(sb)[i],
774 UDF_SB_ANCHOR(sb)[i] = 0;
777 if ((ident != TAG_IDENT_AVDP) && (i ||
783 UDF_SB_ANCHOR(sb)[i] = 0;
789 UDF_SB_LASTBLOCK(sb) = lastblock;
793 udf_find_fileset(struct super_block *sb, kernel_lb_addr * fileset,
794 kernel_lb_addr * root)
796 struct buffer_head *bh = NULL;
800 if (fileset->logicalBlockNum != 0xFFFFFFFF ||
801 fileset->partitionReferenceNum != 0xFFFF) {
802 bh = udf_read_ptagged(sb, *fileset, 0, &ident);
806 else if (ident != TAG_IDENT_FSD) {
813 if (!bh) { /* Search backwards through the partitions */
814 kernel_lb_addr newfileset;
818 for (newfileset.partitionReferenceNum = UDF_SB_NUMPARTS(sb) - 1;
819 (newfileset.partitionReferenceNum != 0xFFFF &&
820 fileset->logicalBlockNum == 0xFFFFFFFF &&
821 fileset->partitionReferenceNum == 0xFFFF);
822 newfileset.partitionReferenceNum--) {
825 newfileset.partitionReferenceNum);
826 newfileset.logicalBlockNum = 0;
829 bh = udf_read_ptagged(sb, newfileset, 0,
832 newfileset.logicalBlockNum++;
839 struct spaceBitmapDesc *sp;
840 sp = (struct spaceBitmapDesc *)
842 newfileset.logicalBlockNum +=
849 >> sb->s_blocksize_bits);
855 *fileset = newfileset;
860 newfileset.logicalBlockNum++;
867 while (newfileset.logicalBlockNum < lastblock &&
868 fileset->logicalBlockNum == 0xFFFFFFFF &&
869 fileset->partitionReferenceNum == 0xFFFF);
873 if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
874 fileset->partitionReferenceNum != 0xFFFF) && bh) {
875 udf_debug("Fileset at block=%d, partition=%d\n",
876 fileset->logicalBlockNum,
877 fileset->partitionReferenceNum);
879 UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum;
880 udf_load_fileset(sb, bh, root);
887 static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
889 struct primaryVolDesc *pvoldesc;
895 pvoldesc = (struct primaryVolDesc *)bh->b_data;
897 if (udf_stamp_to_time(&recording, &recording_usec,
898 lets_to_cpu(pvoldesc->recordingDateAndTime))) {
900 ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
902 ("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n",
903 recording, recording_usec, ts.year, ts.month, ts.day,
904 ts.hour, ts.minute, ts.typeAndTimezone);
905 UDF_SB_RECORDTIME(sb).tv_sec = recording;
906 UDF_SB_RECORDTIME(sb).tv_nsec = recording_usec * 1000;
909 if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) {
910 if (udf_CS0toUTF8(&outstr, &instr)) {
911 strncpy(UDF_SB_VOLIDENT(sb), outstr.u_name,
912 outstr.u_len > 31 ? 31 : outstr.u_len);
913 udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb));
917 if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) {
918 if (udf_CS0toUTF8(&outstr, &instr))
919 udf_debug("volSetIdent[] = '%s'\n", outstr.u_name);
924 udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
925 kernel_lb_addr * root)
927 struct fileSetDesc *fset;
929 fset = (struct fileSetDesc *)bh->b_data;
931 *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
933 UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum);
935 udf_debug("Rootdir at block=%d, partition=%d\n",
936 root->logicalBlockNum, root->partitionReferenceNum);
939 static void udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
941 struct partitionDesc *p;
944 p = (struct partitionDesc *)bh->b_data;
946 for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
947 udf_debug("Searching map: (%d == %d)\n",
948 UDF_SB_PARTMAPS(sb)[i].s_partition_num,
949 le16_to_cpu(p->partitionNumber));
950 if (UDF_SB_PARTMAPS(sb)[i].s_partition_num ==
951 le16_to_cpu(p->partitionNumber)) {
952 UDF_SB_PARTLEN(sb, i) = le32_to_cpu(p->partitionLength); /* blocks */
953 UDF_SB_PARTROOT(sb, i) =
954 le32_to_cpu(p->partitionStartingLocation);
955 if (le32_to_cpu(p->accessType) ==
956 PD_ACCESS_TYPE_READ_ONLY)
957 UDF_SB_PARTFLAGS(sb, i) |=
958 UDF_PART_FLAG_READ_ONLY;
959 if (le32_to_cpu(p->accessType) ==
960 PD_ACCESS_TYPE_WRITE_ONCE)
961 UDF_SB_PARTFLAGS(sb, i) |=
962 UDF_PART_FLAG_WRITE_ONCE;
963 if (le32_to_cpu(p->accessType) ==
964 PD_ACCESS_TYPE_REWRITABLE)
965 UDF_SB_PARTFLAGS(sb, i) |=
966 UDF_PART_FLAG_REWRITABLE;
967 if (le32_to_cpu(p->accessType) ==
968 PD_ACCESS_TYPE_OVERWRITABLE)
969 UDF_SB_PARTFLAGS(sb, i) |=
970 UDF_PART_FLAG_OVERWRITABLE;
973 (p->partitionContents.ident,
974 PD_PARTITION_CONTENTS_NSR02)
975 || !strcmp(p->partitionContents.ident,
976 PD_PARTITION_CONTENTS_NSR03)) {
977 struct partitionHeaderDesc *phd;
980 (struct partitionHeaderDesc *)(p->
981 partitionContentsUse);
982 if (phd->unallocSpaceTable.extLength) {
988 UDF_SB_PARTMAPS(sb)[i].s_uspace.
989 s_table = udf_iget(sb, loc);
990 UDF_SB_PARTFLAGS(sb, i) |=
991 UDF_PART_FLAG_UNALLOC_TABLE;
993 ("unallocSpaceTable (part %d) @ %ld\n",
995 UDF_SB_PARTMAPS(sb)[i].s_uspace.
998 if (phd->unallocSpaceBitmap.extLength) {
999 UDF_SB_ALLOC_BITMAP(sb, i, s_uspace);
1000 if (UDF_SB_PARTMAPS(sb)[i].s_uspace.
1002 UDF_SB_PARTMAPS(sb)[i].s_uspace.
1003 s_bitmap->s_extLength =
1007 UDF_SB_PARTMAPS(sb)[i].s_uspace.
1008 s_bitmap->s_extPosition =
1012 UDF_SB_PARTFLAGS(sb, i) |=
1013 UDF_PART_FLAG_UNALLOC_BITMAP;
1015 ("unallocSpaceBitmap (part %d) @ %d\n",
1017 UDF_SB_PARTMAPS(sb)[i].
1022 if (phd->partitionIntegrityTable.extLength)
1024 ("partitionIntegrityTable (part %d)\n",
1026 if (phd->freedSpaceTable.extLength) {
1027 kernel_lb_addr loc =
1028 { le32_to_cpu(phd->freedSpaceTable.
1031 UDF_SB_PARTMAPS(sb)[i].s_fspace.
1032 s_table = udf_iget(sb, loc);
1033 UDF_SB_PARTFLAGS(sb, i) |=
1034 UDF_PART_FLAG_FREED_TABLE;
1036 ("freedSpaceTable (part %d) @ %ld\n",
1038 UDF_SB_PARTMAPS(sb)[i].s_fspace.
1041 if (phd->freedSpaceBitmap.extLength) {
1042 UDF_SB_ALLOC_BITMAP(sb, i, s_fspace);
1043 if (UDF_SB_PARTMAPS(sb)[i].s_fspace.
1045 UDF_SB_PARTMAPS(sb)[i].s_fspace.
1046 s_bitmap->s_extLength =
1050 UDF_SB_PARTMAPS(sb)[i].s_fspace.
1051 s_bitmap->s_extPosition =
1055 UDF_SB_PARTFLAGS(sb, i) |=
1056 UDF_PART_FLAG_FREED_BITMAP;
1058 ("freedSpaceBitmap (part %d) @ %d\n",
1060 UDF_SB_PARTMAPS(sb)[i].
1069 if (i == UDF_SB_NUMPARTS(sb)) {
1070 udf_debug("Partition (%d) not found in partition map\n",
1071 le16_to_cpu(p->partitionNumber));
1074 ("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
1075 le16_to_cpu(p->partitionNumber), i, UDF_SB_PARTTYPE(sb, i),
1076 UDF_SB_PARTROOT(sb, i), UDF_SB_PARTLEN(sb, i));
1081 udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
1082 kernel_lb_addr * fileset)
1084 struct logicalVolDesc *lvd;
1088 lvd = (struct logicalVolDesc *)bh->b_data;
1090 UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps));
1092 for (i = 0, offset = 0;
1093 i < UDF_SB_NUMPARTS(sb)
1094 && offset < le32_to_cpu(lvd->mapTableLength);
1096 ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->
1097 partitionMapLength) {
1099 ((struct genericPartitionMap *)
1100 &(lvd->partitionMaps[offset]))->partitionMapType;
1102 struct genericPartitionMap1 *gpm1 =
1103 (struct genericPartitionMap1 *)&(lvd->
1106 UDF_SB_PARTTYPE(sb, i) = UDF_TYPE1_MAP15;
1107 UDF_SB_PARTVSN(sb, i) = le16_to_cpu(gpm1->volSeqNum);
1108 UDF_SB_PARTNUM(sb, i) = le16_to_cpu(gpm1->partitionNum);
1109 UDF_SB_PARTFUNC(sb, i) = NULL;
1110 } else if (type == 2) {
1111 struct udfPartitionMap2 *upm2 =
1112 (struct udfPartitionMap2 *)&(lvd->
1113 partitionMaps[offset]);
1115 (upm2->partIdent.ident, UDF_ID_VIRTUAL,
1116 strlen(UDF_ID_VIRTUAL))) {
1118 (((__le16 *) upm2->partIdent.
1119 identSuffix)[0]) == 0x0150) {
1120 UDF_SB_PARTTYPE(sb, i) =
1122 UDF_SB_PARTFUNC(sb, i) =
1123 udf_get_pblock_virt15;
1126 (((__le16 *) upm2->partIdent.
1127 identSuffix)[0]) == 0x0200) {
1128 UDF_SB_PARTTYPE(sb, i) =
1130 UDF_SB_PARTFUNC(sb, i) =
1131 udf_get_pblock_virt20;
1135 (upm2->partIdent.ident, UDF_ID_SPARABLE,
1136 strlen(UDF_ID_SPARABLE))) {
1139 struct sparingTable *st;
1140 struct sparablePartitionMap *spm =
1141 (struct sparablePartitionMap *)&(lvd->
1145 UDF_SB_PARTTYPE(sb, i) = UDF_SPARABLE_MAP15;
1146 UDF_SB_TYPESPAR(sb, i).s_packet_len =
1147 le16_to_cpu(spm->packetLength);
1148 for (j = 0; j < spm->numSparingTables; j++) {
1151 locSparingTable[j]);
1152 UDF_SB_TYPESPAR(sb, i).s_spar_map[j] =
1153 udf_read_tagged(sb, loc, loc,
1155 if (UDF_SB_TYPESPAR(sb, i).
1156 s_spar_map[j] != NULL) {
1157 st = (struct sparingTable *)
1160 s_spar_map[j]->b_data;
1162 || strncmp(st->sparingIdent.
1168 brelse(UDF_SB_TYPESPAR
1179 UDF_SB_PARTFUNC(sb, i) = udf_get_pblock_spar15;
1181 udf_debug("Unknown ident: %s\n",
1182 upm2->partIdent.ident);
1185 UDF_SB_PARTVSN(sb, i) = le16_to_cpu(upm2->volSeqNum);
1186 UDF_SB_PARTNUM(sb, i) = le16_to_cpu(upm2->partitionNum);
1188 udf_debug("Partition (%d:%d) type %d on volume %d\n",
1189 i, UDF_SB_PARTNUM(sb, i), type, UDF_SB_PARTVSN(sb,
1194 long_ad *la = (long_ad *) & (lvd->logicalVolContentsUse[0]);
1196 *fileset = lelb_to_cpu(la->extLocation);
1198 ("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
1199 fileset->logicalBlockNum, fileset->partitionReferenceNum);
1201 if (lvd->integritySeqExt.extLength)
1202 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
1207 * udf_load_logicalvolint
1210 static void udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
1212 struct buffer_head *bh = NULL;
1215 while (loc.extLength > 0 &&
1216 (bh = udf_read_tagged(sb, loc.extLocation,
1217 loc.extLocation, &ident)) &&
1218 ident == TAG_IDENT_LVID) {
1219 UDF_SB_LVIDBH(sb) = bh;
1221 if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength)
1222 udf_load_logicalvolint(sb,
1223 leea_to_cpu(UDF_SB_LVID(sb)->
1226 if (UDF_SB_LVIDBH(sb) != bh)
1228 loc.extLength -= sb->s_blocksize;
1231 if (UDF_SB_LVIDBH(sb) != bh)
1236 * udf_process_sequence
1239 * Process a main/reserve volume descriptor sequence.
1242 * sb Pointer to _locked_ superblock.
1243 * block First block of first extent of the sequence.
1244 * lastblock Lastblock of first extent of the sequence.
1247 * July 1, 1997 - Andrew E. Mileski
1248 * Written, tested, and released.
1251 udf_process_sequence(struct super_block *sb, long block, long lastblock,
1252 kernel_lb_addr * fileset)
1254 struct buffer_head *bh = NULL;
1255 struct udf_vds_record vds[VDS_POS_LENGTH];
1256 struct generic_desc *gd;
1257 struct volDescPtr *vdp;
1262 long next_s = 0, next_e = 0;
1264 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
1266 /* Read the main descriptor sequence */
1267 for (; (!done && block <= lastblock); block++) {
1269 bh = udf_read_tagged(sb, block, block, &ident);
1273 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1274 gd = (struct generic_desc *)bh->b_data;
1275 vdsn = le32_to_cpu(gd->volDescSeqNum);
1277 case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
1278 if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) {
1279 vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum =
1281 vds[VDS_POS_PRIMARY_VOL_DESC].block = block;
1284 case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
1285 if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) {
1286 vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn;
1287 vds[VDS_POS_VOL_DESC_PTR].block = block;
1289 vdp = (struct volDescPtr *)bh->b_data;
1291 le32_to_cpu(vdp->nextVolDescSeqExt.
1294 le32_to_cpu(vdp->nextVolDescSeqExt.
1296 next_e = next_e >> sb->s_blocksize_bits;
1300 case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
1301 if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) {
1302 vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum =
1304 vds[VDS_POS_IMP_USE_VOL_DESC].block = block;
1307 case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
1308 if (!vds[VDS_POS_PARTITION_DESC].block)
1309 vds[VDS_POS_PARTITION_DESC].block = block;
1311 case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
1312 if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) {
1313 vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum =
1315 vds[VDS_POS_LOGICAL_VOL_DESC].block = block;
1318 case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
1320 vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) {
1321 vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum =
1323 vds[VDS_POS_UNALLOC_SPACE_DESC].block = block;
1326 case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
1327 vds[VDS_POS_TERMINATING_DESC].block = block;
1331 next_s = next_e = 0;
1338 for (i = 0; i < VDS_POS_LENGTH; i++) {
1340 bh = udf_read_tagged(sb, vds[i].block, vds[i].block,
1343 if (i == VDS_POS_PRIMARY_VOL_DESC)
1344 udf_load_pvoldesc(sb, bh);
1345 else if (i == VDS_POS_LOGICAL_VOL_DESC)
1346 udf_load_logicalvol(sb, bh, fileset);
1347 else if (i == VDS_POS_PARTITION_DESC) {
1348 struct buffer_head *bh2 = NULL;
1349 udf_load_partdesc(sb, bh);
1350 for (j = vds[i].block + 1;
1351 j < vds[VDS_POS_TERMINATING_DESC].block;
1353 bh2 = udf_read_tagged(sb, j, j, &ident);
1354 gd = (struct generic_desc *)bh2->b_data;
1355 if (ident == TAG_IDENT_PD)
1356 udf_load_partdesc(sb, bh2);
1370 static int udf_check_valid(struct super_block *sb, int novrs, int silent)
1375 udf_debug("Validity check skipped because of novrs option\n");
1378 /* Check that it is NSR02 compliant */
1379 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1380 else if ((block = udf_vrs(sb, silent)) == -1) {
1382 ("Failed to read byte 32768. Assuming open disc. Skipping validity check\n");
1383 if (!UDF_SB_LASTBLOCK(sb))
1384 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
1390 static int udf_load_partition(struct super_block *sb, kernel_lb_addr * fileset)
1392 struct anchorVolDescPtr *anchor;
1394 struct buffer_head *bh;
1395 long main_s, main_e, reserve_s, reserve_e;
1401 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
1402 if (UDF_SB_ANCHOR(sb)[i] && (bh = udf_read_tagged(sb,
1408 anchor = (struct anchorVolDescPtr *)bh->b_data;
1410 /* Locate the main sequence */
1412 le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
1414 le32_to_cpu(anchor->mainVolDescSeqExt.extLength);
1415 main_e = main_e >> sb->s_blocksize_bits;
1418 /* Locate the reserve sequence */
1420 le32_to_cpu(anchor->reserveVolDescSeqExt.
1423 le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
1424 reserve_e = reserve_e >> sb->s_blocksize_bits;
1425 reserve_e += reserve_s;
1429 /* Process the main & reserve sequences */
1430 /* responsible for finding the PartitionDesc(s) */
1432 (udf_process_sequence(sb, main_s, main_e, fileset)
1433 && udf_process_sequence(sb, reserve_s, reserve_e,
1440 if (i == ARRAY_SIZE(UDF_SB_ANCHOR(sb))) {
1441 udf_debug("No Anchor block found\n");
1444 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]);
1446 for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
1447 switch (UDF_SB_PARTTYPE(sb, i)) {
1448 case UDF_VIRTUAL_MAP15:
1449 case UDF_VIRTUAL_MAP20:
1451 kernel_lb_addr uninitialized_var(ino);
1453 if (!UDF_SB_LASTBLOCK(sb)) {
1454 UDF_SB_LASTBLOCK(sb) =
1455 udf_get_last_block(sb);
1456 udf_find_anchor(sb);
1459 if (!UDF_SB_LASTBLOCK(sb)) {
1461 ("Unable to determine Lastblock (For Virtual Partition)\n");
1465 for (j = 0; j < UDF_SB_NUMPARTS(sb); j++) {
1469 UDF_SB_PARTVSN(sb, j)
1470 && UDF_SB_PARTNUM(sb,
1472 UDF_SB_PARTNUM(sb, j)) {
1473 ino.partitionReferenceNum = j;
1474 ino.logicalBlockNum =
1475 UDF_SB_LASTBLOCK(sb) -
1476 UDF_SB_PARTROOT(sb, j);
1481 if (j == UDF_SB_NUMPARTS(sb))
1484 if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino)))
1487 if (UDF_SB_PARTTYPE(sb, i) == UDF_VIRTUAL_MAP15) {
1488 UDF_SB_TYPEVIRT(sb, i).s_start_offset =
1489 udf_ext0_offset(UDF_SB_VAT(sb));
1490 UDF_SB_TYPEVIRT(sb, i).s_num_entries =
1491 (UDF_SB_VAT(sb)->i_size - 36) >> 2;
1492 } else if (UDF_SB_PARTTYPE(sb, i) ==
1493 UDF_VIRTUAL_MAP20) {
1494 struct buffer_head *bh = NULL;
1497 pos = udf_block_map(UDF_SB_VAT(sb), 0);
1498 bh = sb_bread(sb, pos);
1501 UDF_SB_TYPEVIRT(sb, i).s_start_offset =
1502 le16_to_cpu(((struct
1503 virtualAllocationTable20
1508 udf_ext0_offset(UDF_SB_VAT(sb));
1509 UDF_SB_TYPEVIRT(sb, i).s_num_entries =
1510 (UDF_SB_VAT(sb)->i_size -
1513 s_start_offset) >> 2;
1516 UDF_SB_PARTROOT(sb, i) =
1517 udf_get_pblock(sb, 0, i, 0);
1518 UDF_SB_PARTLEN(sb, i) =
1520 ino.partitionReferenceNum);
1527 static void udf_open_lvid(struct super_block *sb)
1529 if (UDF_SB_LVIDBH(sb)) {
1531 kernel_timestamp cpu_time;
1533 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1534 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1535 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1536 UDF_SB_LVID(sb)->recordingDateAndTime =
1537 cpu_to_lets(cpu_time);
1538 UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN;
1540 UDF_SB_LVID(sb)->descTag.descCRC =
1541 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1542 le16_to_cpu(UDF_SB_LVID(sb)->descTag.
1543 descCRCLength), 0));
1545 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
1546 for (i = 0; i < 16; i++)
1548 UDF_SB_LVID(sb)->descTag.tagChecksum +=
1550 (UDF_SB_LVID(sb)->descTag))[i];
1552 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
1556 static void udf_close_lvid(struct super_block *sb)
1558 if (UDF_SB_LVIDBH(sb) &&
1559 UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN) {
1561 kernel_timestamp cpu_time;
1563 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1564 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1565 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
1566 UDF_SB_LVID(sb)->recordingDateAndTime =
1567 cpu_to_lets(cpu_time);
1568 if (UDF_MAX_WRITE_VERSION >
1569 le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev))
1570 UDF_SB_LVIDIU(sb)->maxUDFWriteRev =
1571 cpu_to_le16(UDF_MAX_WRITE_VERSION);
1572 if (UDF_SB_UDFREV(sb) >
1573 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev))
1574 UDF_SB_LVIDIU(sb)->minUDFReadRev =
1575 cpu_to_le16(UDF_SB_UDFREV(sb));
1576 if (UDF_SB_UDFREV(sb) >
1577 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev))
1578 UDF_SB_LVIDIU(sb)->minUDFWriteRev =
1579 cpu_to_le16(UDF_SB_UDFREV(sb));
1580 UDF_SB_LVID(sb)->integrityType =
1581 cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
1583 UDF_SB_LVID(sb)->descTag.descCRC =
1584 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1585 le16_to_cpu(UDF_SB_LVID(sb)->descTag.
1586 descCRCLength), 0));
1588 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
1589 for (i = 0; i < 16; i++)
1591 UDF_SB_LVID(sb)->descTag.tagChecksum +=
1593 (UDF_SB_LVID(sb)->descTag))[i];
1595 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
1603 * Complete the specified super block.
1606 * sb Pointer to superblock to complete - never NULL.
1607 * sb->s_dev Device to read suberblock from.
1608 * options Pointer to mount options.
1609 * silent Silent flag.
1612 * July 1, 1997 - Andrew E. Mileski
1613 * Written, tested, and released.
1615 static int udf_fill_super(struct super_block *sb, void *options, int silent)
1618 struct inode *inode = NULL;
1619 struct udf_options uopt;
1620 kernel_lb_addr rootdir, fileset;
1621 struct udf_sb_info *sbi;
1623 uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
1628 sbi = kmalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
1631 sb->s_fs_info = sbi;
1632 memset(UDF_SB(sb), 0x00, sizeof(struct udf_sb_info));
1634 mutex_init(&sbi->s_alloc_mutex);
1636 if (!udf_parse_options((char *)options, &uopt))
1639 if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
1640 uopt.flags & (1 << UDF_FLAG_NLS_MAP)) {
1641 udf_error(sb, "udf_read_super",
1642 "utf8 cannot be combined with iocharset\n");
1645 #ifdef CONFIG_UDF_NLS
1646 if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) {
1647 uopt.nls_map = load_nls_default();
1649 uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
1651 udf_debug("Using default NLS map\n");
1654 if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
1655 uopt.flags |= (1 << UDF_FLAG_UTF8);
1657 fileset.logicalBlockNum = 0xFFFFFFFF;
1658 fileset.partitionReferenceNum = 0xFFFF;
1660 UDF_SB(sb)->s_flags = uopt.flags;
1661 UDF_SB(sb)->s_uid = uopt.uid;
1662 UDF_SB(sb)->s_gid = uopt.gid;
1663 UDF_SB(sb)->s_umask = uopt.umask;
1664 UDF_SB(sb)->s_nls_map = uopt.nls_map;
1666 /* Set the block size for all transfers */
1667 if (!udf_set_blocksize(sb, uopt.blocksize))
1670 if (uopt.session == 0xFFFFFFFF)
1671 UDF_SB_SESSION(sb) = udf_get_last_session(sb);
1673 UDF_SB_SESSION(sb) = uopt.session;
1675 udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb));
1677 UDF_SB_LASTBLOCK(sb) = uopt.lastblock;
1678 UDF_SB_ANCHOR(sb)[0] = UDF_SB_ANCHOR(sb)[1] = 0;
1679 UDF_SB_ANCHOR(sb)[2] = uopt.anchor;
1680 UDF_SB_ANCHOR(sb)[3] = 256;
1682 if (udf_check_valid(sb, uopt.novrs, silent)) { /* read volume recognition sequences */
1683 printk("UDF-fs: No VRS found\n");
1687 udf_find_anchor(sb);
1689 /* Fill in the rest of the superblock */
1690 sb->s_op = &udf_sb_ops;
1693 sb->s_magic = UDF_SUPER_MAGIC;
1694 sb->s_time_gran = 1000;
1696 if (udf_load_partition(sb, &fileset)) {
1697 printk("UDF-fs: No partition found (1)\n");
1701 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb));
1703 if (UDF_SB_LVIDBH(sb)) {
1704 uint16_t minUDFReadRev =
1705 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev);
1706 uint16_t minUDFWriteRev =
1707 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
1708 /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */
1710 if (minUDFReadRev > UDF_MAX_READ_VERSION) {
1711 printk("UDF-fs: minUDFReadRev=%x (max is %x)\n",
1712 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev),
1713 UDF_MAX_READ_VERSION);
1715 } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) {
1716 sb->s_flags |= MS_RDONLY;
1719 UDF_SB_UDFREV(sb) = minUDFWriteRev;
1721 if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
1722 UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
1723 if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
1724 UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
1727 if (!UDF_SB_NUMPARTS(sb)) {
1728 printk("UDF-fs: No partition found (2)\n");
1732 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1733 UDF_PART_FLAG_READ_ONLY) {
1735 ("UDF-fs: Partition marked readonly; forcing readonly mount\n");
1736 sb->s_flags |= MS_RDONLY;
1739 if (udf_find_fileset(sb, &fileset, &rootdir)) {
1740 printk("UDF-fs: No fileset found\n");
1745 kernel_timestamp ts;
1746 udf_time_to_stamp(&ts, UDF_SB_RECORDTIME(sb));
1748 ("UDF %s (%s) Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1749 UDFFS_VERSION, UDFFS_DATE, UDF_SB_VOLIDENT(sb), ts.year,
1750 ts.month, ts.day, ts.hour, ts.minute, ts.typeAndTimezone);
1752 if (!(sb->s_flags & MS_RDONLY))
1755 /* Assign the root inode */
1756 /* assign inodes by physical block number */
1757 /* perhaps it's not extensible enough, but for now ... */
1758 inode = udf_iget(sb, rootdir);
1760 printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n",
1761 rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
1765 /* Allocate a dentry for the root inode */
1766 sb->s_root = d_alloc_root(inode);
1768 printk("UDF-fs: Couldn't allocate root dentry\n");
1772 sb->s_maxbytes = MAX_LFS_FILESIZE;
1777 iput(UDF_SB_VAT(sb));
1778 if (UDF_SB_NUMPARTS(sb)) {
1779 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1780 UDF_PART_FLAG_UNALLOC_TABLE)
1781 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.
1783 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1784 UDF_PART_FLAG_FREED_TABLE)
1785 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.
1787 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1788 UDF_PART_FLAG_UNALLOC_BITMAP)
1789 UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_uspace);
1790 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1791 UDF_PART_FLAG_FREED_BITMAP)
1792 UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_fspace);
1793 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) ==
1794 UDF_SPARABLE_MAP15) {
1795 for (i = 0; i < 4; i++)
1796 brelse(UDF_SB_TYPESPAR
1798 UDF_SB_PARTITION(sb)).s_spar_map[i]);
1801 #ifdef CONFIG_UDF_NLS
1802 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1803 unload_nls(UDF_SB(sb)->s_nls_map);
1805 if (!(sb->s_flags & MS_RDONLY))
1807 brelse(UDF_SB_LVIDBH(sb));
1810 sb->s_fs_info = NULL;
1814 void udf_error(struct super_block *sb, const char *function,
1815 const char *fmt, ...)
1819 if (!(sb->s_flags & MS_RDONLY)) {
1823 va_start(args, fmt);
1824 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
1826 printk(KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
1827 sb->s_id, function, error_buf);
1830 void udf_warning(struct super_block *sb, const char *function,
1831 const char *fmt, ...)
1835 va_start(args, fmt);
1836 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
1838 printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
1839 sb->s_id, function, error_buf);
1846 * Prepare for destruction of the superblock.
1849 * Called before the filesystem is unmounted.
1852 * July 1, 1997 - Andrew E. Mileski
1853 * Written, tested, and released.
1855 static void udf_put_super(struct super_block *sb)
1860 iput(UDF_SB_VAT(sb));
1861 if (UDF_SB_NUMPARTS(sb)) {
1862 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1863 UDF_PART_FLAG_UNALLOC_TABLE)
1864 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.
1866 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1867 UDF_PART_FLAG_FREED_TABLE)
1868 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.
1870 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1871 UDF_PART_FLAG_UNALLOC_BITMAP)
1872 UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_uspace);
1873 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
1874 UDF_PART_FLAG_FREED_BITMAP)
1875 UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_fspace);
1876 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) ==
1877 UDF_SPARABLE_MAP15) {
1878 for (i = 0; i < 4; i++)
1879 brelse(UDF_SB_TYPESPAR
1881 UDF_SB_PARTITION(sb)).s_spar_map[i]);
1884 #ifdef CONFIG_UDF_NLS
1885 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1886 unload_nls(UDF_SB(sb)->s_nls_map);
1888 if (!(sb->s_flags & MS_RDONLY))
1890 brelse(UDF_SB_LVIDBH(sb));
1892 kfree(sb->s_fs_info);
1893 sb->s_fs_info = NULL;
1900 * Return info about the filesystem.
1903 * Called by sys_statfs()
1906 * July 1, 1997 - Andrew E. Mileski
1907 * Written, tested, and released.
1909 static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
1911 struct super_block *sb = dentry->d_sb;
1913 buf->f_type = UDF_SUPER_MAGIC;
1914 buf->f_bsize = sb->s_blocksize;
1915 buf->f_blocks = UDF_SB_PARTLEN(sb, UDF_SB_PARTITION(sb));
1916 buf->f_bfree = udf_count_free(sb);
1917 buf->f_bavail = buf->f_bfree;
1918 buf->f_files = (UDF_SB_LVIDBH(sb) ?
1919 (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) +
1920 le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) +
1922 buf->f_ffree = buf->f_bfree;
1923 /* __kernel_fsid_t f_fsid */
1924 buf->f_namelen = UDF_NAME_LEN - 2;
1929 static unsigned char udf_bitmap_lookup[16] = {
1930 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
1934 udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
1936 struct buffer_head *bh = NULL;
1937 unsigned int accum = 0;
1939 int block = 0, newblock;
1945 struct spaceBitmapDesc *bm;
1949 loc.logicalBlockNum = bitmap->s_extPosition;
1950 loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
1951 bh = udf_read_ptagged(sb, loc, 0, &ident);
1954 printk(KERN_ERR "udf: udf_count_free failed\n");
1956 } else if (ident != TAG_IDENT_SBD) {
1958 printk(KERN_ERR "udf: udf_count_free failed\n");
1962 bm = (struct spaceBitmapDesc *)bh->b_data;
1963 bytes = le32_to_cpu(bm->numOfBytes);
1964 index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
1965 ptr = (uint8_t *) bh->b_data;
1968 while ((bytes > 0) && (index < sb->s_blocksize)) {
1970 accum += udf_bitmap_lookup[value & 0x0f];
1971 accum += udf_bitmap_lookup[value >> 4];
1977 newblock = udf_get_lb_pblock(sb, loc, ++block);
1978 bh = udf_tread(sb, newblock);
1980 udf_debug("read failed\n");
1984 ptr = (uint8_t *) bh->b_data;
1996 udf_count_free_table(struct super_block *sb, struct inode *table)
1998 unsigned int accum = 0;
2000 kernel_lb_addr eloc;
2002 struct extent_position epos;
2006 epos.block = UDF_I_LOCATION(table);
2007 epos.offset = sizeof(struct unallocSpaceEntry);
2010 while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
2011 accum += (elen >> table->i_sb->s_blocksize_bits);
2019 static unsigned int udf_count_free(struct super_block *sb)
2021 unsigned int accum = 0;
2023 if (UDF_SB_LVIDBH(sb)) {
2024 if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) >
2025 UDF_SB_PARTITION(sb)) {
2027 le32_to_cpu(UDF_SB_LVID(sb)->
2028 freeSpaceTable[UDF_SB_PARTITION(sb)]);
2030 if (accum == 0xFFFFFFFF)
2038 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
2039 UDF_PART_FLAG_UNALLOC_BITMAP) {
2041 udf_count_free_bitmap(sb,
2042 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION
2046 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
2047 UDF_PART_FLAG_FREED_BITMAP) {
2049 udf_count_free_bitmap(sb,
2050 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION
2057 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
2058 UDF_PART_FLAG_UNALLOC_TABLE) {
2060 udf_count_free_table(sb,
2061 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION
2065 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) &
2066 UDF_PART_FLAG_FREED_TABLE) {
2068 udf_count_free_table(sb,
2069 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION