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@hootie.lvld.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-1999 Ben Fennema
33 * 09/24/98 dgb changed to allow compiling outside of kernel, and
34 * added some debugging.
35 * 10/01/98 dgb updated to allow (some) possibility of compiling w/2.0.34
36 * 10/16/98 attempting some multi-session support
37 * 10/17/98 added freespace count for "df"
38 * 11/11/98 gr added novrs option
39 * 11/26/98 dgb added fileset,anchor mount options
40 * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced vol descs
41 * rewrote option handling based on isofs
42 * 12/20/98 find the free space bitmap (if it exists)
45 #ifndef LINUX_VERSION_CODE
46 #include <linux/version.h>
51 #include <linux/blkdev.h>
52 #include <linux/malloc.h>
53 #include <linux/kernel.h>
54 #include <linux/locks.h>
55 #include <linux/module.h>
56 #include <linux/stat.h>
57 #include <linux/cdrom.h>
58 #include <linux/nls.h>
59 #include <asm/byteorder.h>
61 #include <linux/udf_fs.h>
65 #include <linux/init.h>
66 #include <asm/uaccess.h>
68 static char error_buf
[1024];
70 /* These are the "meat" - everything else is stuffing */
71 static struct super_block
*udf_read_super(struct super_block
*, void *, int);
72 static void udf_put_super(struct super_block
*);
73 static int udf_remount_fs(struct super_block
*, int *, char *);
74 static int udf_check_valid(struct super_block
*, int, int);
75 static int udf_vrs(struct super_block
*sb
, int silent
);
76 static int udf_load_partition(struct super_block
*, lb_addr
*);
77 static int udf_load_logicalvol(struct super_block
*, struct buffer_head
*, lb_addr
*);
78 static void udf_load_logicalvolint(struct super_block
*, extent_ad
);
79 static int udf_find_anchor(struct super_block
*, int, int);
80 static int udf_find_fileset(struct super_block
*, lb_addr
*, lb_addr
*);
81 static void udf_load_pvoldesc(struct super_block
*, struct buffer_head
*);
82 static void udf_load_fileset(struct super_block
*, struct buffer_head
*, lb_addr
*);
83 static void udf_load_partdesc(struct super_block
*, struct buffer_head
*);
84 static void udf_open_lvid(struct super_block
*);
85 static void udf_close_lvid(struct super_block
*);
86 static unsigned int udf_count_free(struct super_block
*);
88 /* version specific functions */
89 static int udf_statfs(struct super_block
*, struct statfs
*, int);
91 /* UDF filesystem type */
92 static struct file_system_type udf_fstype
= {
94 FS_REQUIRES_DEV
, /* fs_flags */
95 udf_read_super
, /* read_super */
99 /* Superblock operations */
100 static struct super_operations udf_sb_ops
=
102 udf_read_inode
, /* read_inode */
104 udf_write_inode
, /* write_inode */
106 NULL
, /* write_inode */
108 udf_put_inode
, /* put_inode */
110 udf_delete_inode
, /* delete_inode */
112 NULL
, /* delete_inode */
114 NULL
, /* notify_change */
115 udf_put_super
, /* put_super */
116 NULL
, /* write_super */
117 udf_statfs
, /* statfs */
118 udf_remount_fs
, /* remount_fs */
119 NULL
, /* clear_inode */
120 NULL
, /* umount_begin */
127 unsigned int blocksize
;
128 unsigned int session
;
129 unsigned int lastblock
;
132 unsigned short partition
;
133 unsigned int fileset
;
134 unsigned int rootdir
;
148 * Unregister the UDF filesystem type.
151 * Clean-up before the module is unloaded.
152 * This routine only applies when compiled as a module.
155 * July 1, 1997 - Andrew E. Mileski
156 * Written, tested, and released.
161 printk(KERN_NOTICE
"udf: unregistering filesystem\n");
162 return unregister_filesystem(&udf_fstype
);
166 * init_module / init_udf_fs
169 * Register the UDF filesystem type.
172 * July 1, 1997 - Andrew E. Mileski
173 * Written, tested, and released.
175 int init_module(void)
176 #else /* if !defined(MODULE) */
177 int __init
init_udf_fs(void)
180 printk(KERN_NOTICE
"udf: registering filesystem\n");
182 struct super_block sb
;
185 size
= sizeof(struct super_block
) +
186 (long)&sb
.u
- (long)&sb
;
187 if ( size
< sizeof(struct udf_sb_info
) )
189 printk(KERN_ERR
"udf: Danger! Kernel was compiled without enough room for udf_sb_info\n");
190 printk(KERN_ERR
"udf: Kernel has room for %u bytes, udf needs %u\n",
191 size
, sizeof(struct udf_sb_info
));
195 return register_filesystem(&udf_fstype
);
202 * Parse mount options.
205 * The following mount options are supported:
207 * gid= Set the default group.
208 * umask= Set the default umask.
209 * uid= Set the default user.
210 * unhide Show otherwise hidden files.
211 * undelete Show deleted files in lists.
212 * strict Set strict conformance (unused)
216 * The remaining are for debugging and disaster recovery:
218 * bs= Set the block size. (may not work unless 2048)
219 * novrs Skip volume sequence recognition
221 * The following expect a offset from 0.
223 * session= Set the CDROM session (default= last session)
224 * anchor= Override standard anchor location. (default= 256)
225 * volume= Override the VolumeDesc location. (unused)
226 * partition= Override the PartitionDesc location. (unused)
227 * lastblock= Set the last block of the filesystem/
229 * The following expect a offset from the partition root.
231 * fileset= Override the fileset block location. (unused)
232 * rootdir= Override the root directory location. (unused)
233 * WARNING: overriding the rootdir to a non-directory may
234 * yield highly unpredictable results.
237 * options Pointer to mount options string.
238 * uopts Pointer to mount options variable.
241 * <return> 0 Mount options parsed okay.
242 * <return> -1 Error parsing mount options.
245 * July 1, 1997 - Andrew E. Mileski
246 * Written, tested, and released.
250 udf_parse_options(char *options
, struct udf_options
*uopt
)
255 uopt
->blocksize
= 2048;
256 uopt
->partition
= 0xFFFF;
257 uopt
->session
= 0xFFFFFFFF;
258 uopt
->lastblock
= 0xFFFFFFFF;
259 uopt
->anchor
= 0xFFFFFFFF;
260 uopt
->volume
= 0xFFFFFFFF;
261 uopt
->rootdir
= 0xFFFFFFFF;
262 uopt
->fileset
= 0xFFFFFFFF;
263 uopt
->iocharset
= NULL
;
268 for (opt
= strtok(options
, ","); opt
; opt
= strtok(NULL
, ","))
270 /* Make "opt=val" into two strings */
271 val
= strchr(opt
, '=');
274 if (!strcmp(opt
, "novrs") && !val
)
276 else if (!strcmp(opt
, "utf8") && !val
)
278 else if (!strcmp(opt
, "bs") && val
)
279 uopt
->blocksize
= simple_strtoul(val
, NULL
, 0);
280 else if (!strcmp(opt
, "unhide") && !val
)
281 uopt
->flags
|= UDF_FLAG_UNHIDE
;
282 else if (!strcmp(opt
, "undelete") && !val
)
283 uopt
->flags
|= UDF_FLAG_UNDELETE
;
284 else if (!strcmp(opt
, "gid") && val
)
285 uopt
->gid
= simple_strtoul(val
, NULL
, 0);
286 else if (!strcmp(opt
, "umask") && val
)
287 uopt
->umask
= simple_strtoul(val
, NULL
, 0);
288 else if (!strcmp(opt
, "strict") && !val
)
289 uopt
->flags
|= UDF_FLAG_STRICT
;
290 else if (!strcmp(opt
, "uid") && val
)
291 uopt
->uid
= simple_strtoul(val
, NULL
, 0);
292 else if (!strcmp(opt
, "session") && val
)
293 uopt
->session
= simple_strtoul(val
, NULL
, 0);
294 else if (!strcmp(opt
, "lastblock") && val
)
295 uopt
->lastblock
= simple_strtoul(val
, NULL
, 0);
296 else if (!strcmp(opt
, "anchor") && val
)
297 uopt
->anchor
= simple_strtoul(val
, NULL
, 0);
298 else if (!strcmp(opt
, "volume") && val
)
299 uopt
->volume
= simple_strtoul(val
, NULL
, 0);
300 else if (!strcmp(opt
, "partition") && val
)
301 uopt
->partition
= simple_strtoul(val
, NULL
, 0);
302 else if (!strcmp(opt
, "fileset") && val
)
303 uopt
->fileset
= simple_strtoul(val
, NULL
, 0);
304 else if (!strcmp(opt
, "rootdir") && val
)
305 uopt
->rootdir
= simple_strtoul(val
, NULL
, 0);
306 else if (!strcmp(opt
, "iocharset") && val
)
308 uopt
->iocharset
= val
;
309 while (*val
&& *val
!= ',')
311 if (val
== uopt
->iocharset
)
317 printk(KERN_ERR
"udf: bad mount option \"%s=%s\"\n",
323 printk(KERN_ERR
"udf: bad mount option \"%s\"\n",
332 udf_remount_fs(struct super_block
*sb
, int *flags
, char *options
)
334 struct udf_options uopt
;
336 uopt
.flags
= UDF_SB(sb
)->s_flags
;
337 uopt
.uid
= UDF_SB(sb
)->s_uid
;
338 uopt
.gid
= UDF_SB(sb
)->s_gid
;
339 uopt
.umask
= UDF_SB(sb
)->s_umask
;
340 uopt
.utf8
= UDF_SB(sb
)->s_utf8
;
342 if ( !udf_parse_options(options
, &uopt
) )
345 UDF_SB(sb
)->s_flags
= uopt
.flags
;
346 UDF_SB(sb
)->s_uid
= uopt
.uid
;
347 UDF_SB(sb
)->s_gid
= uopt
.gid
;
348 UDF_SB(sb
)->s_umask
= uopt
.umask
;
349 UDF_SB(sb
)->s_utf8
= uopt
.utf8
;
351 if ((*flags
& MS_RDONLY
) == (sb
->s_flags
& MS_RDONLY
))
353 if (*flags
& MS_RDONLY
)
365 * Set the block size to be used in all transfers.
368 * To allow room for a DMA transfer, it is best to guess big when unsure.
369 * This routine picks 2048 bytes as the blocksize when guessing. This
370 * should be adequate until devices with larger block sizes become common.
372 * Note that the Linux kernel can currently only deal with blocksizes of
373 * 512, 1024, 2048, 4096, and 8192 bytes.
376 * sb Pointer to _locked_ superblock.
379 * sb->s_blocksize Blocksize.
380 * sb->s_blocksize_bits log2 of blocksize.
381 * <return> 0 Blocksize is valid.
382 * <return> 1 Blocksize is invalid.
385 * July 1, 1997 - Andrew E. Mileski
386 * Written, tested, and released.
389 udf_set_blocksize(struct super_block
*sb
, int bsize
)
391 /* Use specified block size if specified */
392 sb
->s_blocksize
= get_hardblocksize(sb
->s_dev
);
393 sb
->s_blocksize
= sb
->s_blocksize
? sb
->s_blocksize
: 2048;
394 if (bsize
> sb
->s_blocksize
)
395 sb
->s_blocksize
= bsize
;
397 /* Block size must be an even multiple of 512 */
398 switch (sb
->s_blocksize
) {
399 case 512: sb
->s_blocksize_bits
= 9; break;
400 case 1024: sb
->s_blocksize_bits
= 10; break;
401 case 2048: sb
->s_blocksize_bits
= 11; break;
402 case 4096: sb
->s_blocksize_bits
= 12; break;
403 case 8192: sb
->s_blocksize_bits
= 13; break;
406 udf_debug("Bad block size (%ld)\n", sb
->s_blocksize
);
407 printk(KERN_ERR
"udf: bad block size (%ld)\n", sb
->s_blocksize
);
412 /* Set the block size */
413 set_blocksize(sb
->s_dev
, sb
->s_blocksize
);
414 return sb
->s_blocksize
;
418 udf_vrs(struct super_block
*sb
, int silent
)
420 struct VolStructDesc
*vsd
= NULL
;
422 struct buffer_head
*bh
= NULL
;
427 /* Block size must be a multiple of 512 */
428 if (sb
->s_blocksize
& 511)
431 sector
+= (UDF_SB_SESSION(sb
) << sb
->s_blocksize_bits
);
433 udf_debug("Starting at sector %u (%ld byte sectors)\n",
434 (sector
>> sb
->s_blocksize_bits
), sb
->s_blocksize
);
435 /* Process the sequence (if applicable) */
436 for (;!nsr02
&& !nsr03
; sector
+= 2048)
439 bh
= udf_tread(sb
, sector
>> sb
->s_blocksize_bits
, 2048);
443 /* Look for ISO descriptors */
444 vsd
= (struct VolStructDesc
*)(bh
->b_data
+
445 (sector
& (sb
->s_blocksize
- 1)));
447 if (vsd
->stdIdent
[0] == 0)
449 udf_release_data(bh
);
452 else if (!strncmp(vsd
->stdIdent
, STD_ID_CD001
, STD_ID_LEN
))
455 switch (vsd
->structType
)
458 udf_debug("ISO9660 Boot Record found\n");
461 udf_debug("ISO9660 Primary Volume Descriptor found\n");
464 udf_debug("ISO9660 Supplementary Volume Descriptor found\n");
467 udf_debug("ISO9660 Volume Partition Descriptor found\n");
470 udf_debug("ISO9660 Volume Descriptor Set Terminator found\n");
473 udf_debug("ISO9660 VRS (%u) found\n", vsd
->structType
);
477 else if (!strncmp(vsd
->stdIdent
, STD_ID_BEA01
, STD_ID_LEN
))
480 else if (!strncmp(vsd
->stdIdent
, STD_ID_TEA01
, STD_ID_LEN
))
482 udf_release_data(bh
);
485 else if (!strncmp(vsd
->stdIdent
, STD_ID_NSR02
, STD_ID_LEN
))
489 else if (!strncmp(vsd
->stdIdent
, STD_ID_NSR03
, STD_ID_LEN
))
493 udf_release_data(bh
);
500 else if (sector
- (UDF_SB_SESSION(sb
) << sb
->s_blocksize_bits
) == 32768)
510 * Find an anchor volume descriptor.
513 * sb Pointer to _locked_ superblock.
514 * lastblock Last block on media.
517 * <return> 1 if not found, 0 if ok
520 * July 1, 1997 - Andrew E. Mileski
521 * Written, tested, and released.
524 udf_find_anchor(struct super_block
*sb
, int useranchor
, int lastblock
)
526 int varlastblock
= udf_variable_to_fixed(lastblock
);
527 int last
[] = { lastblock
, lastblock
- 2,
528 lastblock
- 150, lastblock
- 152,
529 varlastblock
, varlastblock
- 2,
530 varlastblock
- 150, varlastblock
- 152 };
531 struct buffer_head
*bh
= NULL
;
536 UDF_SB_ANCHOR(sb
)[0] = 0;
537 UDF_SB_ANCHOR(sb
)[1] = 0;
538 UDF_SB_ANCHOR(sb
)[2] = 0;
539 UDF_SB_ANCHOR(sb
)[3] = 256 + UDF_SB_SESSION(sb
);
543 /* Search for an anchor volume descriptor pointer */
545 /* according to spec, anchor is in either:
549 * however, if the disc isn't closed, it could be 512 */
551 for (i
=0; (!lastblock
&& i
<sizeof(last
)/sizeof(int)); i
++)
553 if (!(bh
= bread(sb
->s_dev
, last
[i
], sb
->s_blocksize
)))
555 ident
= location
= 0;
559 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
560 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
561 udf_release_data(bh
);
564 if (ident
== TID_ANCHOR_VOL_DESC_PTR
)
566 if (location
== last
[i
] - UDF_SB_SESSION(sb
))
568 lastblock
= UDF_SB_ANCHOR(sb
)[0] = last
[i
];
569 UDF_SB_ANCHOR(sb
)[1] = last
[i
] - 256;
571 else if (location
== udf_variable_to_fixed(last
[i
]) - UDF_SB_SESSION(sb
))
573 UDF_SB(sb
)->s_flags
|= UDF_FLAG_VARCONV
;
574 lastblock
= UDF_SB_ANCHOR(sb
)[0] = udf_variable_to_fixed(last
[i
]);
575 UDF_SB_ANCHOR(sb
)[1] = lastblock
- 256;
578 udf_debug("Anchor found at block %d, location mismatch %d.\n",
581 else if (ident
== TID_FILE_ENTRY
|| ident
== TID_EXTENDED_FILE_ENTRY
)
584 UDF_SB_ANCHOR(sb
)[2] = 512 + UDF_SB_SESSION(sb
);
588 if (!(bh
= bread(sb
->s_dev
, last
[i
] - 256, sb
->s_blocksize
)))
590 ident
= location
= 0;
594 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
595 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
596 udf_release_data(bh
);
599 if (ident
== TID_ANCHOR_VOL_DESC_PTR
&&
600 location
== last
[i
] - 256 - UDF_SB_SESSION(sb
))
603 UDF_SB_ANCHOR(sb
)[1] = last
[i
] - 256;
607 if (!(bh
= bread(sb
->s_dev
, last
[i
] - 312 - UDF_SB_SESSION(sb
),
610 ident
= location
= 0;
614 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
615 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
616 udf_release_data(bh
);
619 if (ident
== TID_ANCHOR_VOL_DESC_PTR
&&
620 location
== udf_variable_to_fixed(last
[i
]) - 256)
622 UDF_SB(sb
)->s_flags
|= UDF_FLAG_VARCONV
;
623 lastblock
= udf_variable_to_fixed(last
[i
]);
624 UDF_SB_ANCHOR(sb
)[1] = lastblock
- 256;
632 /* We havn't found the lastblock. check 312 */
633 if ((bh
= bread(sb
->s_dev
, 312 + UDF_SB_SESSION(sb
), sb
->s_blocksize
)))
635 ident
= le16_to_cpu(((tag
*)bh
->b_data
)->tagIdent
);
636 location
= le32_to_cpu(((tag
*)bh
->b_data
)->tagLocation
);
637 udf_release_data(bh
);
639 if (ident
== TID_ANCHOR_VOL_DESC_PTR
&& location
== 256)
640 UDF_SB(sb
)->s_flags
|= UDF_FLAG_VARCONV
;
644 for (i
=0; i
<sizeof(UDF_SB_ANCHOR(sb
))/sizeof(int); i
++)
646 if (UDF_SB_ANCHOR(sb
)[i
])
648 if (!(bh
= udf_read_tagged(sb
,
649 UDF_SB_ANCHOR(sb
)[i
], UDF_SB_ANCHOR(sb
)[i
], &ident
)))
651 UDF_SB_ANCHOR(sb
)[i
] = 0;
655 udf_release_data(bh
);
656 if ((ident
!= TID_ANCHOR_VOL_DESC_PTR
) && (i
||
657 (ident
!= TID_FILE_ENTRY
&& ident
!= TID_EXTENDED_FILE_ENTRY
)))
659 UDF_SB_ANCHOR(sb
)[i
] = 0;
663 else if (useranchor
!= 0xFFFFFFFF)
665 UDF_SB_ANCHOR(sb
)[i
] = useranchor
;
666 useranchor
= 0xFFFFFFFF;
675 udf_find_fileset(struct super_block
*sb
, lb_addr
*fileset
, lb_addr
*root
)
677 struct buffer_head
*bh
= NULL
;
681 if (fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
682 fileset
->partitionReferenceNum
!= 0xFFFF)
684 bh
= udf_read_ptagged(sb
, *fileset
, 0, &ident
);
688 else if (ident
!= TID_FILE_SET_DESC
)
690 udf_release_data(bh
);
696 if (!bh
) /* Search backwards through the partitions */
702 for (newfileset
.partitionReferenceNum
=UDF_SB_NUMPARTS(sb
)-1;
703 (newfileset
.partitionReferenceNum
!= 0xFFFF &&
704 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
705 fileset
->partitionReferenceNum
== 0xFFFF);
706 newfileset
.partitionReferenceNum
--)
708 lastblock
= UDF_SB_PARTLEN(sb
, newfileset
.partitionReferenceNum
);
709 newfileset
.logicalBlockNum
= 0;
713 bh
= udf_read_ptagged(sb
, newfileset
, 0, &ident
);
716 newfileset
.logicalBlockNum
++;
722 case TID_SPACE_BITMAP_DESC
:
724 struct SpaceBitmapDesc
*sp
;
725 sp
= (struct SpaceBitmapDesc
*)bh
->b_data
;
726 newfileset
.logicalBlockNum
+= 1 +
727 ((le32_to_cpu(sp
->numOfBytes
) + sizeof(struct SpaceBitmapDesc
) - 1)
728 >> sb
->s_blocksize_bits
);
729 udf_release_data(bh
);
732 case TID_FILE_SET_DESC
:
734 *fileset
= newfileset
;
739 newfileset
.logicalBlockNum
++;
740 udf_release_data(bh
);
746 while (newfileset
.logicalBlockNum
< lastblock
&&
747 fileset
->logicalBlockNum
== 0xFFFFFFFF &&
748 fileset
->partitionReferenceNum
== 0xFFFF);
752 if ((fileset
->logicalBlockNum
!= 0xFFFFFFFF ||
753 fileset
->partitionReferenceNum
!= 0xFFFF) && bh
)
755 udf_debug("Fileset at block=%d, partition=%d\n",
756 fileset
->logicalBlockNum
, fileset
->partitionReferenceNum
);
758 UDF_SB_PARTITION(sb
) = fileset
->partitionReferenceNum
;
759 udf_load_fileset(sb
, bh
, root
);
760 udf_release_data(bh
);
767 udf_load_pvoldesc(struct super_block
*sb
, struct buffer_head
*bh
)
769 struct PrimaryVolDesc
*pvoldesc
;
775 pvoldesc
= (struct PrimaryVolDesc
*)bh
->b_data
;
777 if ( udf_stamp_to_time(&recording
, &recording_usec
,
778 lets_to_cpu(pvoldesc
->recordingDateAndTime
)) )
781 ts
= lets_to_cpu(pvoldesc
->recordingDateAndTime
);
782 udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n",
783 recording
, recording_usec
,
784 ts
.year
, ts
.month
, ts
.day
, ts
.hour
, ts
.minute
, ts
.typeAndTimezone
);
785 UDF_SB_RECORDTIME(sb
) = recording
;
788 if ( !udf_build_ustr(&instr
, pvoldesc
->volIdent
, 32) )
790 if (!udf_CS0toUTF8(&outstr
, &instr
))
792 udf_debug("volIdent[] = '%s'\n", outstr
.u_name
);
793 strncpy( UDF_SB_VOLIDENT(sb
), outstr
.u_name
, outstr
.u_len
);
797 if ( !udf_build_ustr(&instr
, pvoldesc
->volSetIdent
, 128) )
799 if (!udf_CS0toUTF8(&outstr
, &instr
))
800 udf_debug("volSetIdent[] = '%s'\n", outstr
.u_name
);
805 udf_load_fileset(struct super_block
*sb
, struct buffer_head
*bh
, lb_addr
*root
)
807 struct FileSetDesc
*fset
;
809 fset
= (struct FileSetDesc
*)bh
->b_data
;
811 *root
= lelb_to_cpu(fset
->rootDirectoryICB
.extLocation
);
813 UDF_SB_SERIALNUM(sb
) = le16_to_cpu(fset
->descTag
.tagSerialNum
);
815 udf_debug("Rootdir at block=%d, partition=%d\n",
816 root
->logicalBlockNum
, root
->partitionReferenceNum
);
820 udf_load_partdesc(struct super_block
*sb
, struct buffer_head
*bh
)
822 struct PartitionDesc
*p
;
825 p
=(struct PartitionDesc
*)bh
->b_data
;
827 for (i
=0; i
<UDF_SB_NUMPARTS(sb
); i
++)
829 udf_debug("Searching map: (%d == %d)\n",
830 UDF_SB_PARTMAPS(sb
)[i
].s_partition_num
, le16_to_cpu(p
->partitionNumber
));
831 if (UDF_SB_PARTMAPS(sb
)[i
].s_partition_num
== le16_to_cpu(p
->partitionNumber
))
833 UDF_SB_PARTLEN(sb
,i
) = le32_to_cpu(p
->partitionLength
); /* blocks */
834 UDF_SB_PARTROOT(sb
,i
) = le32_to_cpu(p
->partitionStartingLocation
) + UDF_SB_SESSION(sb
);
835 UDF_SB_PARTMAPS(sb
)[i
].s_uspace_bitmap
= 0xFFFFFFFF;
837 if (!strcmp(p
->partitionContents
.ident
, PARTITION_CONTENTS_NSR02
) ||
838 !strcmp(p
->partitionContents
.ident
, PARTITION_CONTENTS_NSR03
))
840 struct PartitionHeaderDesc
*phd
;
842 phd
= (struct PartitionHeaderDesc
*)(p
->partitionContentsUse
);
843 if (phd
->unallocatedSpaceTable
.extLength
)
844 udf_debug("unallocatedSpaceTable (part %d)\n", i
);
845 if (phd
->unallocatedSpaceBitmap
.extLength
)
847 UDF_SB_PARTMAPS(sb
)[i
].s_uspace_bitmap
=
848 le32_to_cpu(phd
->unallocatedSpaceBitmap
.extPosition
);
849 udf_debug("unallocatedSpaceBitmap (part %d) @ %d\n",
850 i
, UDF_SB_PARTMAPS(sb
)[i
].s_uspace_bitmap
);
852 if (phd
->partitionIntegrityTable
.extLength
)
853 udf_debug("partitionIntegrityTable (part %d)\n", i
);
854 if (phd
->freedSpaceTable
.extLength
)
855 udf_debug("freedSpaceTable (part %d)\n", i
);
856 if (phd
->freedSpaceBitmap
.extLength
)
857 udf_debug("freedSpaceBitmap (part %d\n", i
);
862 if (i
== UDF_SB_NUMPARTS(sb
))
864 udf_debug("Partition (%d) not found in partition map\n", le16_to_cpu(p
->partitionNumber
));
868 udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
869 le16_to_cpu(p
->partitionNumber
), i
, UDF_SB_PARTTYPE(sb
,i
),
870 UDF_SB_PARTROOT(sb
,i
), UDF_SB_PARTLEN(sb
,i
));
875 udf_load_logicalvol(struct super_block
*sb
, struct buffer_head
* bh
, lb_addr
*fileset
)
877 struct LogicalVolDesc
*lvd
;
881 lvd
= (struct LogicalVolDesc
*)bh
->b_data
;
883 UDF_SB_NUMPARTS(sb
) = le32_to_cpu(lvd
->numPartitionMaps
);
884 UDF_SB_ALLOC_PARTMAPS(sb
, UDF_SB_NUMPARTS(sb
));
887 i
<UDF_SB_NUMPARTS(sb
) && offset
<le32_to_cpu(lvd
->mapTableLength
);
888 i
++,offset
+=((struct GenericPartitionMap
*)&(lvd
->partitionMaps
[offset
]))->partitionMapLength
)
890 type
= ((struct GenericPartitionMap
*)&(lvd
->partitionMaps
[offset
]))->partitionMapType
;
891 udf_debug("Partition (%d) type %d\n", i
, type
);
894 struct GenericPartitionMap1
*gpm1
= (struct GenericPartitionMap1
*)&(lvd
->partitionMaps
[offset
]);
895 UDF_SB_PARTTYPE(sb
,i
) = UDF_TYPE1_MAP15
;
896 UDF_SB_PARTVSN(sb
,i
) = le16_to_cpu(gpm1
->volSeqNum
);
897 UDF_SB_PARTNUM(sb
,i
) = le16_to_cpu(gpm1
->partitionNum
);
901 struct UdfPartitionMap2
*upm2
= (struct UdfPartitionMap2
*)&(lvd
->partitionMaps
[offset
]);
902 if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_VIRTUAL
, strlen(UDF_ID_VIRTUAL
)))
904 if (le16_to_cpu(((Uint16
*)upm2
->partIdent
.identSuffix
)[0]) == 0x0150)
905 UDF_SB_PARTTYPE(sb
,i
) = UDF_VIRTUAL_MAP15
;
906 else if (le16_to_cpu(((Uint16
*)upm2
->partIdent
.identSuffix
)[0]) == 0x0200)
907 UDF_SB_PARTTYPE(sb
,i
) = UDF_VIRTUAL_MAP20
;
909 else if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_SPARABLE
, strlen(UDF_ID_SPARABLE
)))
911 struct SparablePartitionMap
*spm
= (struct SparablePartitionMap
*)&(lvd
->partitionMaps
[offset
]);
912 UDF_SB_PARTTYPE(sb
,i
) = UDF_SPARABLE_MAP15
;
913 UDF_SB_TYPESPAR(sb
,i
).s_spar_plen
= le16_to_cpu(spm
->packetLength
);
914 UDF_SB_TYPESPAR(sb
,i
).s_spar_loc
= le32_to_cpu(spm
->locSparingTable
[0]);
918 udf_debug("Unknown ident: %s\n", upm2
->partIdent
.ident
);
921 UDF_SB_PARTVSN(sb
,i
) = le16_to_cpu(upm2
->volSeqNum
);
922 UDF_SB_PARTNUM(sb
,i
) = le16_to_cpu(upm2
->partitionNum
);
928 long_ad
*la
= (long_ad
*)&(lvd
->logicalVolContentsUse
[0]);
930 *fileset
= lelb_to_cpu(la
->extLocation
);
931 udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
932 fileset
->logicalBlockNum
,
933 fileset
->partitionReferenceNum
);
935 if (lvd
->integritySeqExt
.extLength
)
936 udf_load_logicalvolint(sb
, leea_to_cpu(lvd
->integritySeqExt
));
941 * udf_load_logicalvolint
945 udf_load_logicalvolint(struct super_block
*sb
, extent_ad loc
)
947 struct buffer_head
*bh
= NULL
;
950 while ((bh
= udf_read_tagged(sb
, loc
.extLocation
, loc
.extLocation
, &ident
)) &&
951 ident
== TID_LOGICAL_VOL_INTEGRITY_DESC
&& loc
.extLength
> 0)
953 UDF_SB_LVIDBH(sb
) = bh
;
955 if (UDF_SB_LVID(sb
)->nextIntegrityExt
.extLength
)
956 udf_load_logicalvolint(sb
, leea_to_cpu(UDF_SB_LVID(sb
)->nextIntegrityExt
));
958 if (UDF_SB_LVIDBH(sb
) != bh
)
959 udf_release_data(bh
);
960 loc
.extLength
-= sb
->s_blocksize
;
963 if (UDF_SB_LVIDBH(sb
) != bh
)
964 udf_release_data(bh
);
968 * udf_process_sequence
971 * Process a main/reserve volume descriptor sequence.
974 * sb Pointer to _locked_ superblock.
975 * block First block of first extent of the sequence.
976 * lastblock Lastblock of first extent of the sequence.
979 * July 1, 1997 - Andrew E. Mileski
980 * Written, tested, and released.
983 udf_process_sequence(struct super_block
*sb
, long block
, long lastblock
, lb_addr
*fileset
)
985 struct buffer_head
*bh
= NULL
;
986 struct udf_vds_record vds
[VDS_POS_LENGTH
];
987 struct GenericDesc
*gd
;
993 memset(vds
, 0, sizeof(struct udf_vds_record
) * VDS_POS_LENGTH
);
995 /* Read the main descriptor sequence */
996 for (;(!done
&& block
<= lastblock
); block
++)
999 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1003 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1004 gd
= (struct GenericDesc
*)bh
->b_data
;
1005 vdsn
= le32_to_cpu(gd
->volDescSeqNum
);
1008 case TID_PRIMARY_VOL_DESC
: /* ISO 13346 3/10.1 */
1009 if (vdsn
>= vds
[VDS_POS_PRIMARY_VOL_DESC
].volDescSeqNum
)
1011 vds
[VDS_POS_PRIMARY_VOL_DESC
].volDescSeqNum
= vdsn
;
1012 vds
[VDS_POS_PRIMARY_VOL_DESC
].block
= block
;
1015 case TID_VOL_DESC_PTR
: /* ISO 13346 3/10.3 */
1016 if (vdsn
>= vds
[VDS_POS_VOL_DESC_PTR
].volDescSeqNum
)
1018 vds
[VDS_POS_VOL_DESC_PTR
].volDescSeqNum
= vdsn
;
1019 vds
[VDS_POS_VOL_DESC_PTR
].block
= block
;
1022 case TID_IMP_USE_VOL_DESC
: /* ISO 13346 3/10.4 */
1023 if (vdsn
>= vds
[VDS_POS_IMP_USE_VOL_DESC
].volDescSeqNum
)
1025 vds
[VDS_POS_IMP_USE_VOL_DESC
].volDescSeqNum
= vdsn
;
1026 vds
[VDS_POS_IMP_USE_VOL_DESC
].block
= block
;
1029 case TID_PARTITION_DESC
: /* ISO 13346 3/10.5 */
1030 if (!vds
[VDS_POS_PARTITION_DESC
].block
)
1031 vds
[VDS_POS_PARTITION_DESC
].block
= block
;
1033 case TID_LOGICAL_VOL_DESC
: /* ISO 13346 3/10.6 */
1034 if (vdsn
>= vds
[VDS_POS_LOGICAL_VOL_DESC
].volDescSeqNum
)
1036 vds
[VDS_POS_LOGICAL_VOL_DESC
].volDescSeqNum
= vdsn
;
1037 vds
[VDS_POS_LOGICAL_VOL_DESC
].block
= block
;
1040 case TID_UNALLOC_SPACE_DESC
: /* ISO 13346 3/10.8 */
1041 if (vdsn
>= vds
[VDS_POS_UNALLOC_SPACE_DESC
].volDescSeqNum
)
1043 vds
[VDS_POS_UNALLOC_SPACE_DESC
].volDescSeqNum
= vdsn
;
1044 vds
[VDS_POS_UNALLOC_SPACE_DESC
].block
= block
;
1047 case TID_TERMINATING_DESC
: /* ISO 13346 3/10.9 */
1048 vds
[VDS_POS_TERMINATING_DESC
].block
= block
;
1052 udf_release_data(bh
);
1054 for (i
=0; i
<VDS_POS_LENGTH
; i
++)
1058 bh
= udf_read_tagged(sb
, vds
[i
].block
, vds
[i
].block
, &ident
);
1060 if (i
== VDS_POS_PRIMARY_VOL_DESC
)
1061 udf_load_pvoldesc(sb
, bh
);
1062 else if (i
== VDS_POS_LOGICAL_VOL_DESC
)
1063 udf_load_logicalvol(sb
, bh
, fileset
);
1064 else if (i
== VDS_POS_PARTITION_DESC
)
1066 struct buffer_head
*bh2
= NULL
;
1067 udf_load_partdesc(sb
, bh
);
1068 for (j
=vds
[i
].block
+1; j
<vds
[VDS_POS_TERMINATING_DESC
].block
; j
++)
1070 bh2
= udf_read_tagged(sb
, j
, j
, &ident
);
1071 gd
= (struct GenericDesc
*)bh2
->b_data
;
1072 if (ident
== TID_PARTITION_DESC
)
1073 udf_load_partdesc(sb
, bh2
);
1074 udf_release_data(bh2
);
1077 udf_release_data(bh
);
1088 udf_check_valid(struct super_block
*sb
, int novrs
, int silent
)
1094 udf_debug("Validity check skipped because of novrs option\n");
1097 /* Check that it is NSR02 compliant */
1098 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1099 else if ((block
= udf_vrs(sb
, silent
)) == -1)
1101 udf_debug("Failed to read byte 32768. Assuming open disc. Skipping validity check\n");
1109 udf_load_partition(struct super_block
*sb
, lb_addr
*fileset
)
1111 struct AnchorVolDescPtr
*anchor
;
1113 struct buffer_head
*bh
;
1114 long main_s
, main_e
, reserve_s
, reserve_e
;
1120 for (i
=0; i
<sizeof(UDF_SB_ANCHOR(sb
))/sizeof(int); i
++)
1122 if (UDF_SB_ANCHOR(sb
)[i
] && (bh
= udf_read_tagged(sb
,
1123 UDF_SB_ANCHOR(sb
)[i
], UDF_SB_ANCHOR(sb
)[i
] - UDF_SB_SESSION(sb
), &ident
)))
1125 anchor
= (struct AnchorVolDescPtr
*)bh
->b_data
;
1127 /* Locate the main sequence */
1128 main_s
= le32_to_cpu( anchor
->mainVolDescSeqExt
.extLocation
);
1129 main_e
= le32_to_cpu( anchor
->mainVolDescSeqExt
.extLength
);
1130 main_e
= main_e
>> sb
->s_blocksize_bits
;
1133 /* Locate the reserve sequence */
1134 reserve_s
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLocation
);
1135 reserve_e
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLength
);
1136 reserve_e
= reserve_e
>> sb
->s_blocksize_bits
;
1137 reserve_e
+= reserve_s
;
1139 udf_release_data(bh
);
1141 /* Process the main & reserve sequences */
1142 /* responsible for finding the PartitionDesc(s) */
1143 if (!(udf_process_sequence(sb
, main_s
, main_e
, fileset
) &&
1144 udf_process_sequence(sb
, reserve_s
, reserve_e
, fileset
)))
1151 if (i
== sizeof(UDF_SB_ANCHOR(sb
))/sizeof(int))
1153 udf_debug("No Anchor block found\n");
1157 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb
)[i
]);
1159 for (i
=0; i
<UDF_SB_NUMPARTS(sb
); i
++)
1161 switch UDF_SB_PARTTYPE(sb
, i
)
1163 case UDF_VIRTUAL_MAP15
:
1164 case UDF_VIRTUAL_MAP20
:
1168 if (!UDF_SB_LASTBLOCK(sb
))
1170 udf_debug("Unable to determine Lastblock (For Virtual Partition)\n");
1175 ino
.partitionReferenceNum
= i
+1;
1177 ino
.partitionReferenceNum
= i
-1;
1179 ino
.logicalBlockNum
= UDF_SB_LASTBLOCK(sb
) - UDF_SB_PARTROOT(sb
,ino
.partitionReferenceNum
);
1181 if (!(UDF_SB_VAT(sb
) = udf_iget(sb
, ino
)))
1184 if (UDF_SB_PARTTYPE(sb
,i
) == UDF_VIRTUAL_MAP15
)
1186 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
= UDF_I_EXT0OFFS(UDF_SB_VAT(sb
));
1187 UDF_SB_TYPEVIRT(sb
,i
).s_num_entries
= (UDF_SB_VAT(sb
)->i_size
- 36) / sizeof(Uint32
);
1189 else if (UDF_SB_PARTTYPE(sb
,i
) == UDF_VIRTUAL_MAP20
)
1191 struct buffer_head
*bh
= NULL
;
1194 pos
= udf_block_map(UDF_SB_VAT(sb
), 0);
1195 bh
= bread(sb
->s_dev
, pos
, sb
->s_blocksize
);
1196 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
=
1197 le16_to_cpu(((struct VirtualAllocationTable20
*)bh
->b_data
+ UDF_I_EXT0OFFS(UDF_SB_VAT(sb
)))->lengthHeader
) +
1198 UDF_I_EXT0OFFS(UDF_SB_VAT(sb
));
1199 UDF_SB_TYPEVIRT(sb
,i
).s_num_entries
= (UDF_SB_VAT(sb
)->i_size
-
1200 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
) / sizeof(Uint32
);
1201 udf_release_data(bh
);
1203 UDF_SB_PARTROOT(sb
,i
) = udf_get_pblock(sb
, 0, i
, 0);
1204 UDF_SB_PARTLEN(sb
,i
) = UDF_SB_PARTLEN(sb
,ino
.partitionReferenceNum
);
1205 UDF_SB_PARTMAPS(sb
)[i
].s_uspace_bitmap
= 0xFFFFFFFF;
1212 static void udf_open_lvid(struct super_block
*sb
)
1214 #ifdef CONFIG_UDF_RW
1215 if (UDF_SB_LVIDBH(sb
))
1220 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1221 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1222 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
, CURRENT_UTIME
))
1223 UDF_SB_LVID(sb
)->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1224 UDF_SB_LVID(sb
)->integrityType
= INTEGRITY_TYPE_OPEN
;
1226 UDF_SB_LVID(sb
)->descTag
.descCRC
=
1227 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb
) + sizeof(tag
),
1228 le16_to_cpu(UDF_SB_LVID(sb
)->descTag
.descCRCLength
), 0));
1230 UDF_SB_LVID(sb
)->descTag
.tagChecksum
= 0;
1231 for (i
=0; i
<16; i
++)
1233 UDF_SB_LVID(sb
)->descTag
.tagChecksum
+=
1234 ((Uint8
*)&(UDF_SB_LVID(sb
)->descTag
))[i
];
1236 mark_buffer_dirty(UDF_SB_LVIDBH(sb
), 1);
1241 static void udf_close_lvid(struct super_block
*sb
)
1243 #ifdef CONFIG_UDF_RW
1244 if (UDF_SB_LVIDBH(sb
) &&
1245 UDF_SB_LVID(sb
)->integrityType
== INTEGRITY_TYPE_OPEN
)
1250 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1251 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1252 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
, CURRENT_UTIME
))
1253 UDF_SB_LVID(sb
)->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1255 UDF_SB_LVID(sb
)->integrityType
= INTEGRITY_TYPE_CLOSE
;
1257 UDF_SB_LVID(sb
)->descTag
.descCRC
=
1258 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb
) + sizeof(tag
),
1259 le16_to_cpu(UDF_SB_LVID(sb
)->descTag
.descCRCLength
), 0));
1261 UDF_SB_LVID(sb
)->descTag
.tagChecksum
= 0;
1262 for (i
=0; i
<16; i
++)
1264 UDF_SB_LVID(sb
)->descTag
.tagChecksum
+=
1265 ((Uint8
*)&(UDF_SB_LVID(sb
)->descTag
))[i
];
1267 mark_buffer_dirty(UDF_SB_LVIDBH(sb
), 1);
1276 * Complete the specified super block.
1279 * sb Pointer to superblock to complete - never NULL.
1280 * sb->s_dev Device to read suberblock from.
1281 * options Pointer to mount options.
1282 * silent Silent flag.
1285 * July 1, 1997 - Andrew E. Mileski
1286 * Written, tested, and released.
1288 static struct super_block
*
1289 udf_read_super(struct super_block
*sb
, void *options
, int silent
)
1291 struct inode
*inode
=NULL
;
1292 struct udf_options uopt
;
1293 lb_addr rootdir
, fileset
;
1302 /* Lock the module in memory (if applicable) */
1307 UDF_SB_PARTMAPS(sb
) = NULL
;
1308 UDF_SB_LVIDBH(sb
) = NULL
;
1309 UDF_SB_VAT(sb
) = NULL
;
1311 if (!udf_parse_options((char *)options
, &uopt
))
1314 memset(UDF_SB_ANCHOR(sb
), 0x00, sizeof(UDF_SB_ANCHOR(sb
)));
1315 fileset
.logicalBlockNum
= 0xFFFFFFFF;
1316 fileset
.partitionReferenceNum
= 0xFFFF;
1317 UDF_SB_RECORDTIME(sb
)=0;
1318 UDF_SB_VOLIDENT(sb
)[0]=0;
1320 UDF_SB(sb
)->s_flags
= uopt
.flags
;
1321 UDF_SB(sb
)->s_uid
= uopt
.uid
;
1322 UDF_SB(sb
)->s_gid
= uopt
.gid
;
1323 UDF_SB(sb
)->s_umask
= uopt
.umask
;
1324 UDF_SB(sb
)->s_utf8
= uopt
.utf8
;
1326 /* Set the block size for all transfers */
1327 if (!udf_set_blocksize(sb
, uopt
.blocksize
))
1330 if ( uopt
.session
== 0xFFFFFFFF )
1331 UDF_SB_SESSION(sb
) = udf_get_last_session(sb
->s_dev
);
1333 UDF_SB_SESSION(sb
) = uopt
.session
;
1335 udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb
));
1337 if ( uopt
.lastblock
== 0xFFFFFFFF )
1338 UDF_SB_LASTBLOCK(sb
) = udf_get_last_block(sb
->s_dev
, &(UDF_SB(sb
)->s_flags
));
1340 UDF_SB_LASTBLOCK(sb
) = uopt
.lastblock
;
1342 UDF_SB_LASTBLOCK(sb
) = udf_find_anchor(sb
, uopt
.anchor
, UDF_SB_LASTBLOCK(sb
));
1344 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb
));
1346 if (udf_check_valid(sb
, uopt
.novrs
, silent
)) /* read volume recognition sequences */
1348 udf_debug("No VRS found\n");
1352 UDF_SB_CHARSET(sb
) = NULL
;
1357 char *p
= uopt
.iocharset
? uopt
.iocharset
: "iso8859-1";
1358 UDF_SB_CHARSET(sb
) = load_nls(p
);
1359 if (!UDF_SB_CHARSET(sb
))
1362 UDF_SB_CHARSET(sb
) = load_nls_default();
1366 /* Fill in the rest of the superblock */
1367 sb
->s_op
= &udf_sb_ops
;
1371 sb
->s_magic
= UDF_SUPER_MAGIC
;
1373 for (i
=0; i
<UDF_MAX_BLOCK_LOADED
; i
++)
1375 UDF_SB_BLOCK_BITMAP_NUMBER(sb
,i
) = 0;
1376 UDF_SB_BLOCK_BITMAP(sb
,i
) = NULL
;
1378 UDF_SB_LOADED_BLOCK_BITMAPS(sb
) = 0;
1380 if (udf_load_partition(sb
, &fileset
))
1382 udf_debug("No partition found (1)\n");
1386 if ( !UDF_SB_NUMPARTS(sb
) )
1388 udf_debug("No partition found (2)\n");
1392 if ( udf_find_fileset(sb
, &fileset
, &rootdir
) )
1394 udf_debug("No fileset found\n");
1401 udf_time_to_stamp(&ts
, UDF_SB_RECORDTIME(sb
), 0);
1402 udf_info("Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1403 UDF_SB_VOLIDENT(sb
), ts
.year
, ts
.month
, ts
.day
, ts
.hour
, ts
.minute
,
1404 ts
.typeAndTimezone
);
1406 if (!(sb
->s_flags
& MS_RDONLY
))
1410 /* Assign the root inode */
1411 /* assign inodes by physical block number */
1412 /* perhaps it's not extensible enough, but for now ... */
1413 inode
= udf_iget(sb
, rootdir
);
1416 udf_debug("Error in udf_iget, block=%d, partition=%d\n",
1417 rootdir
.logicalBlockNum
, rootdir
.partitionReferenceNum
);
1421 /* Allocate a dentry for the root inode */
1422 sb
->s_root
= d_alloc_root(inode
);
1426 udf_debug("Couldn't allocate root dentry\n");
1435 iput(UDF_SB_VAT(sb
));
1436 if (!(sb
->s_flags
& MS_RDONLY
))
1438 udf_release_data(UDF_SB_LVIDBH(sb
));
1445 void udf_error(struct super_block
*sb
, const char *function
,
1446 const char *fmt
, ...)
1450 if (!(sb
->s_flags
& MS_RDONLY
))
1455 va_start(args
, fmt
);
1456 vsprintf(error_buf
, fmt
, args
);
1458 printk (KERN_CRIT
"UDF-fs error (device %s): %s: %s\n",
1459 bdevname(sb
->s_dev
), function
, error_buf
);
1462 void udf_warning(struct super_block
*sb
, const char *function
,
1463 const char *fmt
, ...)
1467 va_start (args
, fmt
);
1468 vsprintf(error_buf
, fmt
, args
);
1470 printk(KERN_WARNING
"UDF-fs warning (device %s): %s: %s\n",
1471 bdevname(sb
->s_dev
), function
, error_buf
);
1478 * Prepare for destruction of the superblock.
1481 * Called before the filesystem is unmounted.
1484 * July 1, 1997 - Andrew E. Mileski
1485 * Written, tested, and released.
1488 udf_put_super(struct super_block
*sb
)
1493 iput(UDF_SB_VAT(sb
));
1494 if (!(sb
->s_flags
& MS_RDONLY
))
1496 udf_release_data(UDF_SB_LVIDBH(sb
));
1497 for (i
=0; i
<UDF_MAX_BLOCK_LOADED
; i
++)
1498 udf_release_data(UDF_SB_BLOCK_BITMAP(sb
, i
));
1508 * Return info about the filesystem.
1511 * Called by sys_statfs()
1514 * July 1, 1997 - Andrew E. Mileski
1515 * Written, tested, and released.
1518 udf_statfs(struct super_block
*sb
, struct statfs
*buf
, int bufsize
)
1524 size
= (bufsize
< sizeof(tmp
)) ? bufsize
: sizeof(tmp
);
1526 memset(&tmp
, 0, sizeof(tmp
));
1527 tmp
.f_type
= UDF_SUPER_MAGIC
;
1528 tmp
.f_bsize
= sb
->s_blocksize
;
1529 tmp
.f_blocks
= UDF_SB_PARTLEN(sb
, UDF_SB_PARTITION(sb
));
1530 tmp
.f_bfree
= udf_count_free(sb
);
1531 tmp
.f_bavail
= tmp
.f_bfree
;
1532 tmp
.f_files
= (UDF_SB_LVIDBH(sb
) ?
1533 (le32_to_cpu(UDF_SB_LVIDIU(sb
)->numFiles
) +
1534 le32_to_cpu(UDF_SB_LVIDIU(sb
)->numDirs
)) : 0) + tmp
.f_bfree
;
1535 tmp
.f_ffree
= tmp
.f_bfree
;
1536 /* __kernel_fsid_t f_fsid */
1537 tmp
.f_namelen
= UDF_NAME_LEN
;
1539 rc
= copy_to_user(buf
, &tmp
, size
) ? -EFAULT
: 0;
1543 static unsigned char udf_bitmap_lookup
[16] = {
1544 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
1548 udf_count_free(struct super_block
*sb
)
1550 struct buffer_head
*bh
= NULL
;
1551 unsigned int accum
=0;
1553 int block
=0, newblock
;
1560 if (UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace_bitmap
== 0xFFFFFFFF)
1562 if (UDF_SB_LVIDBH(sb
))
1564 if (le32_to_cpu(UDF_SB_LVID(sb
)->numOfPartitions
) > UDF_SB_PARTITION(sb
))
1565 accum
= le32_to_cpu(UDF_SB_LVID(sb
)->freeSpaceTable
[UDF_SB_PARTITION(sb
)]);
1567 if (accum
== 0xFFFFFFFF)
1577 struct SpaceBitmapDesc
*bm
;
1578 loc
.logicalBlockNum
= UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace_bitmap
;
1579 loc
.partitionReferenceNum
= UDF_SB_PARTITION(sb
);
1580 bh
= udf_read_ptagged(sb
, loc
, 0, &ident
);
1584 printk(KERN_ERR
"udf: udf_count_free failed\n");
1587 else if (ident
!= TID_SPACE_BITMAP_DESC
)
1589 udf_release_data(bh
);
1590 printk(KERN_ERR
"udf: udf_count_free failed\n");
1594 bm
= (struct SpaceBitmapDesc
*)bh
->b_data
;
1595 bytes
= bm
->numOfBytes
;
1596 index
= sizeof(struct SpaceBitmapDesc
); /* offset in first block only */
1597 ptr
= (Uint8
*)bh
->b_data
;
1601 while ((bytes
> 0) && (index
< sb
->s_blocksize
))
1604 accum
+= udf_bitmap_lookup
[ value
& 0x0f ];
1605 accum
+= udf_bitmap_lookup
[ value
>> 4 ];
1611 udf_release_data(bh
);
1612 newblock
= udf_get_lb_pblock(sb
, loc
, ++block
);
1613 bh
= udf_tread(sb
, newblock
, sb
->s_blocksize
);
1616 udf_debug("read failed\n");
1620 ptr
= (Uint8
*)bh
->b_data
;
1623 udf_release_data(bh
);