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
;
774 pvoldesc
= (struct PrimaryVolDesc
*)bh
->b_data
;
776 if ( udf_stamp_to_time(&recording
, lets_to_cpu(pvoldesc
->recordingDateAndTime
)) )
779 ts
= lets_to_cpu(pvoldesc
->recordingDateAndTime
);
780 udf_debug("recording time %ld, %u/%u/%u %u:%u (%x)\n",
781 recording
, ts
.year
, ts
.month
, ts
.day
, ts
.hour
, ts
.minute
,
783 UDF_SB_RECORDTIME(sb
) = recording
;
786 if ( !udf_build_ustr(&instr
, pvoldesc
->volIdent
, 32) )
788 if (!udf_CS0toUTF8(&outstr
, &instr
))
790 udf_debug("volIdent[] = '%s'\n", outstr
.u_name
);
791 strncpy( UDF_SB_VOLIDENT(sb
), outstr
.u_name
, outstr
.u_len
);
795 if ( !udf_build_ustr(&instr
, pvoldesc
->volSetIdent
, 128) )
797 if (!udf_CS0toUTF8(&outstr
, &instr
))
798 udf_debug("volSetIdent[] = '%s'\n", outstr
.u_name
);
803 udf_load_fileset(struct super_block
*sb
, struct buffer_head
*bh
, lb_addr
*root
)
805 struct FileSetDesc
*fset
;
807 fset
= (struct FileSetDesc
*)bh
->b_data
;
809 *root
= lelb_to_cpu(fset
->rootDirectoryICB
.extLocation
);
811 UDF_SB_SERIALNUM(sb
) = le16_to_cpu(fset
->descTag
.tagSerialNum
);
813 udf_debug("Rootdir at block=%d, partition=%d\n",
814 root
->logicalBlockNum
, root
->partitionReferenceNum
);
818 udf_load_partdesc(struct super_block
*sb
, struct buffer_head
*bh
)
820 struct PartitionDesc
*p
;
823 p
=(struct PartitionDesc
*)bh
->b_data
;
825 for (i
=0; i
<UDF_SB_NUMPARTS(sb
); i
++)
827 udf_debug("Searching map: (%d == %d)\n",
828 UDF_SB_PARTMAPS(sb
)[i
].s_partition_num
, le16_to_cpu(p
->partitionNumber
));
829 if (UDF_SB_PARTMAPS(sb
)[i
].s_partition_num
== le16_to_cpu(p
->partitionNumber
))
831 UDF_SB_PARTLEN(sb
,i
) = le32_to_cpu(p
->partitionLength
); /* blocks */
832 UDF_SB_PARTROOT(sb
,i
) = le32_to_cpu(p
->partitionStartingLocation
) + UDF_SB_SESSION(sb
);
833 UDF_SB_PARTMAPS(sb
)[i
].s_uspace_bitmap
= 0xFFFFFFFF;
835 if (!strcmp(p
->partitionContents
.ident
, PARTITION_CONTENTS_NSR02
) ||
836 !strcmp(p
->partitionContents
.ident
, PARTITION_CONTENTS_NSR03
))
838 struct PartitionHeaderDesc
*phd
;
840 phd
= (struct PartitionHeaderDesc
*)(p
->partitionContentsUse
);
841 if (phd
->unallocatedSpaceTable
.extLength
)
842 udf_debug("unallocatedSpaceTable (part %d)\n", i
);
843 if (phd
->unallocatedSpaceBitmap
.extLength
)
845 UDF_SB_PARTMAPS(sb
)[i
].s_uspace_bitmap
=
846 le32_to_cpu(phd
->unallocatedSpaceBitmap
.extPosition
);
847 udf_debug("unallocatedSpaceBitmap (part %d) @ %d\n",
848 i
, UDF_SB_PARTMAPS(sb
)[i
].s_uspace_bitmap
);
850 if (phd
->partitionIntegrityTable
.extLength
)
851 udf_debug("partitionIntegrityTable (part %d)\n", i
);
852 if (phd
->freedSpaceTable
.extLength
)
853 udf_debug("freedSpaceTable (part %d)\n", i
);
854 if (phd
->freedSpaceBitmap
.extLength
)
855 udf_debug("freedSpaceBitmap (part %d\n", i
);
860 if (i
== UDF_SB_NUMPARTS(sb
))
862 udf_debug("Partition (%d) not found in partition map\n", le16_to_cpu(p
->partitionNumber
));
866 udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
867 le16_to_cpu(p
->partitionNumber
), i
, UDF_SB_PARTTYPE(sb
,i
),
868 UDF_SB_PARTROOT(sb
,i
), UDF_SB_PARTLEN(sb
,i
));
873 udf_load_logicalvol(struct super_block
*sb
, struct buffer_head
* bh
, lb_addr
*fileset
)
875 struct LogicalVolDesc
*lvd
;
879 lvd
= (struct LogicalVolDesc
*)bh
->b_data
;
881 UDF_SB_NUMPARTS(sb
) = le32_to_cpu(lvd
->numPartitionMaps
);
882 UDF_SB_ALLOC_PARTMAPS(sb
, UDF_SB_NUMPARTS(sb
));
885 i
<UDF_SB_NUMPARTS(sb
) && offset
<le32_to_cpu(lvd
->mapTableLength
);
886 i
++,offset
+=((struct GenericPartitionMap
*)&(lvd
->partitionMaps
[offset
]))->partitionMapLength
)
888 type
= ((struct GenericPartitionMap
*)&(lvd
->partitionMaps
[offset
]))->partitionMapType
;
889 udf_debug("Partition (%d) type %d\n", i
, type
);
892 struct GenericPartitionMap1
*gpm1
= (struct GenericPartitionMap1
*)&(lvd
->partitionMaps
[offset
]);
893 UDF_SB_PARTTYPE(sb
,i
) = UDF_TYPE1_MAP15
;
894 UDF_SB_PARTVSN(sb
,i
) = le16_to_cpu(gpm1
->volSeqNum
);
895 UDF_SB_PARTNUM(sb
,i
) = le16_to_cpu(gpm1
->partitionNum
);
899 struct UdfPartitionMap2
*upm2
= (struct UdfPartitionMap2
*)&(lvd
->partitionMaps
[offset
]);
900 if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_VIRTUAL
, strlen(UDF_ID_VIRTUAL
)))
902 if (le16_to_cpu(((Uint16
*)upm2
->partIdent
.identSuffix
)[0]) == 0x0150)
903 UDF_SB_PARTTYPE(sb
,i
) = UDF_VIRTUAL_MAP15
;
904 else if (le16_to_cpu(((Uint16
*)upm2
->partIdent
.identSuffix
)[0]) == 0x0200)
905 UDF_SB_PARTTYPE(sb
,i
) = UDF_VIRTUAL_MAP20
;
907 else if (!strncmp(upm2
->partIdent
.ident
, UDF_ID_SPARABLE
, strlen(UDF_ID_SPARABLE
)))
909 struct SparablePartitionMap
*spm
= (struct SparablePartitionMap
*)&(lvd
->partitionMaps
[offset
]);
910 UDF_SB_PARTTYPE(sb
,i
) = UDF_SPARABLE_MAP15
;
911 UDF_SB_TYPESPAR(sb
,i
).s_spar_plen
= le16_to_cpu(spm
->packetLength
);
912 UDF_SB_TYPESPAR(sb
,i
).s_spar_loc
= le32_to_cpu(spm
->locSparingTable
[0]);
916 udf_debug("Unknown ident: %s\n", upm2
->partIdent
.ident
);
919 UDF_SB_PARTVSN(sb
,i
) = le16_to_cpu(upm2
->volSeqNum
);
920 UDF_SB_PARTNUM(sb
,i
) = le16_to_cpu(upm2
->partitionNum
);
926 long_ad
*la
= (long_ad
*)&(lvd
->logicalVolContentsUse
[0]);
928 *fileset
= lelb_to_cpu(la
->extLocation
);
929 udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
930 fileset
->logicalBlockNum
,
931 fileset
->partitionReferenceNum
);
933 if (lvd
->integritySeqExt
.extLength
)
934 udf_load_logicalvolint(sb
, leea_to_cpu(lvd
->integritySeqExt
));
939 * udf_load_logicalvolint
943 udf_load_logicalvolint(struct super_block
*sb
, extent_ad loc
)
945 struct buffer_head
*bh
= NULL
;
948 while ((bh
= udf_read_tagged(sb
, loc
.extLocation
, loc
.extLocation
, &ident
)) &&
949 ident
== TID_LOGICAL_VOL_INTEGRITY_DESC
&& loc
.extLength
> 0)
951 UDF_SB_LVIDBH(sb
) = bh
;
953 if (UDF_SB_LVID(sb
)->nextIntegrityExt
.extLength
)
954 udf_load_logicalvolint(sb
, leea_to_cpu(UDF_SB_LVID(sb
)->nextIntegrityExt
));
956 if (UDF_SB_LVIDBH(sb
) != bh
)
957 udf_release_data(bh
);
958 loc
.extLength
-= sb
->s_blocksize
;
961 if (UDF_SB_LVIDBH(sb
) != bh
)
962 udf_release_data(bh
);
966 * udf_process_sequence
969 * Process a main/reserve volume descriptor sequence.
972 * sb Pointer to _locked_ superblock.
973 * block First block of first extent of the sequence.
974 * lastblock Lastblock of first extent of the sequence.
977 * July 1, 1997 - Andrew E. Mileski
978 * Written, tested, and released.
981 udf_process_sequence(struct super_block
*sb
, long block
, long lastblock
, lb_addr
*fileset
)
983 struct buffer_head
*bh
= NULL
;
984 struct udf_vds_record vds
[VDS_POS_LENGTH
];
985 struct GenericDesc
*gd
;
991 memset(vds
, 0, sizeof(struct udf_vds_record
) * VDS_POS_LENGTH
);
993 /* Read the main descriptor sequence */
994 for (;(!done
&& block
<= lastblock
); block
++)
997 bh
= udf_read_tagged(sb
, block
, block
, &ident
);
1001 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1002 gd
= (struct GenericDesc
*)bh
->b_data
;
1003 vdsn
= le32_to_cpu(gd
->volDescSeqNum
);
1006 case TID_PRIMARY_VOL_DESC
: /* ISO 13346 3/10.1 */
1007 if (vdsn
>= vds
[VDS_POS_PRIMARY_VOL_DESC
].volDescSeqNum
)
1009 vds
[VDS_POS_PRIMARY_VOL_DESC
].volDescSeqNum
= vdsn
;
1010 vds
[VDS_POS_PRIMARY_VOL_DESC
].block
= block
;
1013 case TID_VOL_DESC_PTR
: /* ISO 13346 3/10.3 */
1014 if (vdsn
>= vds
[VDS_POS_VOL_DESC_PTR
].volDescSeqNum
)
1016 vds
[VDS_POS_VOL_DESC_PTR
].volDescSeqNum
= vdsn
;
1017 vds
[VDS_POS_VOL_DESC_PTR
].block
= block
;
1020 case TID_IMP_USE_VOL_DESC
: /* ISO 13346 3/10.4 */
1021 if (vdsn
>= vds
[VDS_POS_IMP_USE_VOL_DESC
].volDescSeqNum
)
1023 vds
[VDS_POS_IMP_USE_VOL_DESC
].volDescSeqNum
= vdsn
;
1024 vds
[VDS_POS_IMP_USE_VOL_DESC
].block
= block
;
1027 case TID_PARTITION_DESC
: /* ISO 13346 3/10.5 */
1028 if (!vds
[VDS_POS_PARTITION_DESC
].block
)
1029 vds
[VDS_POS_PARTITION_DESC
].block
= block
;
1031 case TID_LOGICAL_VOL_DESC
: /* ISO 13346 3/10.6 */
1032 if (vdsn
>= vds
[VDS_POS_LOGICAL_VOL_DESC
].volDescSeqNum
)
1034 vds
[VDS_POS_LOGICAL_VOL_DESC
].volDescSeqNum
= vdsn
;
1035 vds
[VDS_POS_LOGICAL_VOL_DESC
].block
= block
;
1038 case TID_UNALLOC_SPACE_DESC
: /* ISO 13346 3/10.8 */
1039 if (vdsn
>= vds
[VDS_POS_UNALLOC_SPACE_DESC
].volDescSeqNum
)
1041 vds
[VDS_POS_UNALLOC_SPACE_DESC
].volDescSeqNum
= vdsn
;
1042 vds
[VDS_POS_UNALLOC_SPACE_DESC
].block
= block
;
1045 case TID_TERMINATING_DESC
: /* ISO 13346 3/10.9 */
1046 vds
[VDS_POS_TERMINATING_DESC
].block
= block
;
1050 udf_release_data(bh
);
1052 for (i
=0; i
<VDS_POS_LENGTH
; i
++)
1056 bh
= udf_read_tagged(sb
, vds
[i
].block
, vds
[i
].block
, &ident
);
1058 if (i
== VDS_POS_PRIMARY_VOL_DESC
)
1059 udf_load_pvoldesc(sb
, bh
);
1060 else if (i
== VDS_POS_LOGICAL_VOL_DESC
)
1061 udf_load_logicalvol(sb
, bh
, fileset
);
1062 else if (i
== VDS_POS_PARTITION_DESC
)
1064 struct buffer_head
*bh2
= NULL
;
1065 udf_load_partdesc(sb
, bh
);
1066 for (j
=vds
[i
].block
+1; j
<vds
[VDS_POS_TERMINATING_DESC
].block
; j
++)
1068 bh2
= udf_read_tagged(sb
, j
, j
, &ident
);
1069 gd
= (struct GenericDesc
*)bh2
->b_data
;
1070 if (ident
== TID_PARTITION_DESC
)
1071 udf_load_partdesc(sb
, bh2
);
1072 udf_release_data(bh2
);
1075 udf_release_data(bh
);
1086 udf_check_valid(struct super_block
*sb
, int novrs
, int silent
)
1092 udf_debug("Validity check skipped because of novrs option\n");
1095 /* Check that it is NSR02 compliant */
1096 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
1097 else if ((block
= udf_vrs(sb
, silent
)) == -1)
1099 udf_debug("Failed to read byte 32768. Assuming open disc. Skipping validity check\n");
1107 udf_load_partition(struct super_block
*sb
, lb_addr
*fileset
)
1109 struct AnchorVolDescPtr
*anchor
;
1111 struct buffer_head
*bh
;
1112 long main_s
, main_e
, reserve_s
, reserve_e
;
1118 for (i
=0; i
<sizeof(UDF_SB_ANCHOR(sb
))/sizeof(int); i
++)
1120 if (UDF_SB_ANCHOR(sb
)[i
] && (bh
= udf_read_tagged(sb
,
1121 UDF_SB_ANCHOR(sb
)[i
], UDF_SB_ANCHOR(sb
)[i
] - UDF_SB_SESSION(sb
), &ident
)))
1123 anchor
= (struct AnchorVolDescPtr
*)bh
->b_data
;
1125 /* Locate the main sequence */
1126 main_s
= le32_to_cpu( anchor
->mainVolDescSeqExt
.extLocation
);
1127 main_e
= le32_to_cpu( anchor
->mainVolDescSeqExt
.extLength
);
1128 main_e
= main_e
>> sb
->s_blocksize_bits
;
1131 /* Locate the reserve sequence */
1132 reserve_s
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLocation
);
1133 reserve_e
= le32_to_cpu(anchor
->reserveVolDescSeqExt
.extLength
);
1134 reserve_e
= reserve_e
>> sb
->s_blocksize_bits
;
1135 reserve_e
+= reserve_s
;
1137 udf_release_data(bh
);
1139 /* Process the main & reserve sequences */
1140 /* responsible for finding the PartitionDesc(s) */
1141 if (!(udf_process_sequence(sb
, main_s
, main_e
, fileset
) &&
1142 udf_process_sequence(sb
, reserve_s
, reserve_e
, fileset
)))
1149 if (i
== sizeof(UDF_SB_ANCHOR(sb
))/sizeof(int))
1151 udf_debug("No Anchor block found\n");
1155 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb
)[i
]);
1157 for (i
=0; i
<UDF_SB_NUMPARTS(sb
); i
++)
1159 switch UDF_SB_PARTTYPE(sb
, i
)
1161 case UDF_VIRTUAL_MAP15
:
1162 case UDF_VIRTUAL_MAP20
:
1166 if (!UDF_SB_LASTBLOCK(sb
))
1168 udf_debug("Unable to determine Lastblock (For Virtual Partition)\n");
1173 ino
.partitionReferenceNum
= i
+1;
1175 ino
.partitionReferenceNum
= i
-1;
1177 ino
.logicalBlockNum
= UDF_SB_LASTBLOCK(sb
) - UDF_SB_PARTROOT(sb
,ino
.partitionReferenceNum
);
1179 if (!(UDF_SB_VAT(sb
) = udf_iget(sb
, ino
)))
1182 if (UDF_SB_PARTTYPE(sb
,i
) == UDF_VIRTUAL_MAP15
)
1184 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
= UDF_I_EXT0OFFS(UDF_SB_VAT(sb
));
1185 UDF_SB_TYPEVIRT(sb
,i
).s_num_entries
= (UDF_SB_VAT(sb
)->i_size
- 36) / sizeof(Uint32
);
1187 else if (UDF_SB_PARTTYPE(sb
,i
) == UDF_VIRTUAL_MAP20
)
1189 struct buffer_head
*bh
= NULL
;
1192 pos
= udf_block_map(UDF_SB_VAT(sb
), 0);
1193 bh
= bread(sb
->s_dev
, pos
, sb
->s_blocksize
);
1194 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
=
1195 le16_to_cpu(((struct VirtualAllocationTable20
*)bh
->b_data
+ UDF_I_EXT0OFFS(UDF_SB_VAT(sb
)))->lengthHeader
) +
1196 UDF_I_EXT0OFFS(UDF_SB_VAT(sb
));
1197 UDF_SB_TYPEVIRT(sb
,i
).s_num_entries
= (UDF_SB_VAT(sb
)->i_size
-
1198 UDF_SB_TYPEVIRT(sb
,i
).s_start_offset
) / sizeof(Uint32
);
1199 udf_release_data(bh
);
1201 UDF_SB_PARTROOT(sb
,i
) = udf_get_pblock(sb
, 0, i
, 0);
1202 UDF_SB_PARTLEN(sb
,i
) = UDF_SB_PARTLEN(sb
,ino
.partitionReferenceNum
);
1203 UDF_SB_PARTMAPS(sb
)[i
].s_uspace_bitmap
= 0xFFFFFFFF;
1210 static void udf_open_lvid(struct super_block
*sb
)
1212 #ifdef CONFIG_UDF_RW
1213 if (UDF_SB_LVIDBH(sb
))
1218 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1219 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1220 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
, CURRENT_UTIME
))
1221 UDF_SB_LVID(sb
)->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1222 UDF_SB_LVID(sb
)->integrityType
= INTEGRITY_TYPE_OPEN
;
1224 UDF_SB_LVID(sb
)->descTag
.descCRC
=
1225 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb
) + sizeof(tag
),
1226 le16_to_cpu(UDF_SB_LVID(sb
)->descTag
.descCRCLength
), 0));
1228 UDF_SB_LVID(sb
)->descTag
.tagChecksum
= 0;
1229 for (i
=0; i
<16; i
++)
1231 UDF_SB_LVID(sb
)->descTag
.tagChecksum
+=
1232 ((Uint8
*)&(UDF_SB_LVID(sb
)->descTag
))[i
];
1234 mark_buffer_dirty(UDF_SB_LVIDBH(sb
), 1);
1239 static void udf_close_lvid(struct super_block
*sb
)
1241 #ifdef CONFIG_UDF_RW
1242 if (UDF_SB_LVIDBH(sb
) &&
1243 UDF_SB_LVID(sb
)->integrityType
== INTEGRITY_TYPE_OPEN
)
1248 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[0] = UDF_OS_CLASS_UNIX
;
1249 UDF_SB_LVIDIU(sb
)->impIdent
.identSuffix
[1] = UDF_OS_ID_LINUX
;
1250 if (udf_time_to_stamp(&cpu_time
, CURRENT_TIME
, CURRENT_UTIME
))
1251 UDF_SB_LVID(sb
)->recordingDateAndTime
= cpu_to_lets(cpu_time
);
1253 UDF_SB_LVID(sb
)->integrityType
= INTEGRITY_TYPE_CLOSE
;
1255 UDF_SB_LVID(sb
)->descTag
.descCRC
=
1256 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb
) + sizeof(tag
),
1257 le16_to_cpu(UDF_SB_LVID(sb
)->descTag
.descCRCLength
), 0));
1259 UDF_SB_LVID(sb
)->descTag
.tagChecksum
= 0;
1260 for (i
=0; i
<16; i
++)
1262 UDF_SB_LVID(sb
)->descTag
.tagChecksum
+=
1263 ((Uint8
*)&(UDF_SB_LVID(sb
)->descTag
))[i
];
1265 mark_buffer_dirty(UDF_SB_LVIDBH(sb
), 1);
1274 * Complete the specified super block.
1277 * sb Pointer to superblock to complete - never NULL.
1278 * sb->s_dev Device to read suberblock from.
1279 * options Pointer to mount options.
1280 * silent Silent flag.
1283 * July 1, 1997 - Andrew E. Mileski
1284 * Written, tested, and released.
1286 static struct super_block
*
1287 udf_read_super(struct super_block
*sb
, void *options
, int silent
)
1289 struct inode
*inode
=NULL
;
1290 struct udf_options uopt
;
1291 lb_addr rootdir
, fileset
;
1300 /* Lock the module in memory (if applicable) */
1305 UDF_SB_PARTMAPS(sb
) = NULL
;
1306 UDF_SB_LVIDBH(sb
) = NULL
;
1307 UDF_SB_VAT(sb
) = NULL
;
1309 if (!udf_parse_options((char *)options
, &uopt
))
1312 memset(UDF_SB_ANCHOR(sb
), 0x00, sizeof(UDF_SB_ANCHOR(sb
)));
1313 fileset
.logicalBlockNum
= 0xFFFFFFFF;
1314 fileset
.partitionReferenceNum
= 0xFFFF;
1315 UDF_SB_RECORDTIME(sb
)=0;
1316 UDF_SB_VOLIDENT(sb
)[0]=0;
1318 UDF_SB(sb
)->s_flags
= uopt
.flags
;
1319 UDF_SB(sb
)->s_uid
= uopt
.uid
;
1320 UDF_SB(sb
)->s_gid
= uopt
.gid
;
1321 UDF_SB(sb
)->s_umask
= uopt
.umask
;
1322 UDF_SB(sb
)->s_utf8
= uopt
.utf8
;
1324 /* Set the block size for all transfers */
1325 if (!udf_set_blocksize(sb
, uopt
.blocksize
))
1328 if ( uopt
.session
== 0xFFFFFFFF )
1329 UDF_SB_SESSION(sb
) = udf_get_last_session(sb
->s_dev
);
1331 UDF_SB_SESSION(sb
) = uopt
.session
;
1333 udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb
));
1335 if ( uopt
.lastblock
== 0xFFFFFFFF )
1336 UDF_SB_LASTBLOCK(sb
) = udf_get_last_block(sb
->s_dev
, &(UDF_SB(sb
)->s_flags
));
1338 UDF_SB_LASTBLOCK(sb
) = uopt
.lastblock
;
1340 UDF_SB_LASTBLOCK(sb
) = udf_find_anchor(sb
, uopt
.anchor
, UDF_SB_LASTBLOCK(sb
));
1342 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb
));
1344 if (udf_check_valid(sb
, uopt
.novrs
, silent
)) /* read volume recognition sequences */
1346 udf_debug("No VRS found\n");
1350 UDF_SB_CHARSET(sb
) = NULL
;
1355 char *p
= uopt
.iocharset
? uopt
.iocharset
: "iso8859-1";
1356 UDF_SB_CHARSET(sb
) = load_nls(p
);
1357 if (!UDF_SB_CHARSET(sb
))
1360 UDF_SB_CHARSET(sb
) = load_nls_default();
1364 /* Fill in the rest of the superblock */
1365 sb
->s_op
= &udf_sb_ops
;
1369 sb
->s_magic
= UDF_SUPER_MAGIC
;
1371 for (i
=0; i
<UDF_MAX_BLOCK_LOADED
; i
++)
1373 UDF_SB_BLOCK_BITMAP_NUMBER(sb
,i
) = 0;
1374 UDF_SB_BLOCK_BITMAP(sb
,i
) = NULL
;
1376 UDF_SB_LOADED_BLOCK_BITMAPS(sb
) = 0;
1378 if (udf_load_partition(sb
, &fileset
))
1380 udf_debug("No partition found (1)\n");
1384 if ( !UDF_SB_NUMPARTS(sb
) )
1386 udf_debug("No partition found (2)\n");
1390 if ( udf_find_fileset(sb
, &fileset
, &rootdir
) )
1392 udf_debug("No fileset found\n");
1399 udf_time_to_stamp(&ts
, UDF_SB_RECORDTIME(sb
), 0);
1400 udf_info("Mounting volume '%s', timestamp %u/%02u/%u %02u:%02u\n",
1401 UDF_SB_VOLIDENT(sb
), ts
.year
, ts
.month
, ts
.day
, ts
.hour
, ts
.minute
);
1403 if (!(sb
->s_flags
& MS_RDONLY
))
1407 /* Assign the root inode */
1408 /* assign inodes by physical block number */
1409 /* perhaps it's not extensible enough, but for now ... */
1410 inode
= udf_iget(sb
, rootdir
);
1413 udf_debug("Error in udf_iget, block=%d, partition=%d\n",
1414 rootdir
.logicalBlockNum
, rootdir
.partitionReferenceNum
);
1418 /* Allocate a dentry for the root inode */
1419 sb
->s_root
= d_alloc_root(inode
);
1423 udf_debug("Couldn't allocate root dentry\n");
1432 iput(UDF_SB_VAT(sb
));
1433 if (!(sb
->s_flags
& MS_RDONLY
))
1435 udf_release_data(UDF_SB_LVIDBH(sb
));
1442 void udf_error(struct super_block
*sb
, const char *function
,
1443 const char *fmt
, ...)
1447 if (!(sb
->s_flags
& MS_RDONLY
))
1452 va_start(args
, fmt
);
1453 vsprintf(error_buf
, fmt
, args
);
1455 printk (KERN_CRIT
"UDF-fs error (device %s): %s: %s\n",
1456 bdevname(sb
->s_dev
), function
, error_buf
);
1459 void udf_warning(struct super_block
*sb
, const char *function
,
1460 const char *fmt
, ...)
1464 va_start (args
, fmt
);
1465 vsprintf(error_buf
, fmt
, args
);
1467 printk(KERN_WARNING
"UDF-fs warning (device %s): %s: %s\n",
1468 bdevname(sb
->s_dev
), function
, error_buf
);
1475 * Prepare for destruction of the superblock.
1478 * Called before the filesystem is unmounted.
1481 * July 1, 1997 - Andrew E. Mileski
1482 * Written, tested, and released.
1485 udf_put_super(struct super_block
*sb
)
1490 iput(UDF_SB_VAT(sb
));
1491 if (!(sb
->s_flags
& MS_RDONLY
))
1493 udf_release_data(UDF_SB_LVIDBH(sb
));
1494 for (i
=0; i
<UDF_MAX_BLOCK_LOADED
; i
++)
1495 udf_release_data(UDF_SB_BLOCK_BITMAP(sb
, i
));
1505 * Return info about the filesystem.
1508 * Called by sys_statfs()
1511 * July 1, 1997 - Andrew E. Mileski
1512 * Written, tested, and released.
1515 udf_statfs(struct super_block
*sb
, struct statfs
*buf
, int bufsize
)
1521 size
= (bufsize
< sizeof(tmp
)) ? bufsize
: sizeof(tmp
);
1523 memset(&tmp
, 0, sizeof(tmp
));
1524 tmp
.f_type
= UDF_SUPER_MAGIC
;
1525 tmp
.f_bsize
= sb
->s_blocksize
;
1526 tmp
.f_blocks
= UDF_SB_PARTLEN(sb
, UDF_SB_PARTITION(sb
));
1527 tmp
.f_bfree
= udf_count_free(sb
);
1528 tmp
.f_bavail
= tmp
.f_bfree
;
1529 tmp
.f_files
= (UDF_SB_LVIDBH(sb
) ?
1530 (le32_to_cpu(UDF_SB_LVIDIU(sb
)->numFiles
) +
1531 le32_to_cpu(UDF_SB_LVIDIU(sb
)->numDirs
)) : 0) + tmp
.f_bfree
;
1532 tmp
.f_ffree
= tmp
.f_bfree
;
1533 /* __kernel_fsid_t f_fsid */
1534 tmp
.f_namelen
= UDF_NAME_LEN
;
1536 rc
= copy_to_user(buf
, &tmp
, size
) ? -EFAULT
: 0;
1540 static unsigned char udf_bitmap_lookup
[16] = {
1541 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
1545 udf_count_free(struct super_block
*sb
)
1547 struct buffer_head
*bh
= NULL
;
1548 unsigned int accum
=0;
1550 int block
=0, newblock
;
1557 if (UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace_bitmap
== 0xFFFFFFFF)
1559 if (UDF_SB_LVIDBH(sb
))
1561 if (le32_to_cpu(UDF_SB_LVID(sb
)->numOfPartitions
) > UDF_SB_PARTITION(sb
))
1562 accum
= le32_to_cpu(UDF_SB_LVID(sb
)->freeSpaceTable
[UDF_SB_PARTITION(sb
)]);
1564 if (accum
== 0xFFFFFFFF)
1574 struct SpaceBitmapDesc
*bm
;
1575 loc
.logicalBlockNum
= UDF_SB_PARTMAPS(sb
)[UDF_SB_PARTITION(sb
)].s_uspace_bitmap
;
1576 loc
.partitionReferenceNum
= UDF_SB_PARTITION(sb
);
1577 bh
= udf_read_ptagged(sb
, loc
, 0, &ident
);
1581 printk(KERN_ERR
"udf: udf_count_free failed\n");
1584 else if (ident
!= TID_SPACE_BITMAP_DESC
)
1586 udf_release_data(bh
);
1587 printk(KERN_ERR
"udf: udf_count_free failed\n");
1591 bm
= (struct SpaceBitmapDesc
*)bh
->b_data
;
1592 bytes
= bm
->numOfBytes
;
1593 index
= sizeof(struct SpaceBitmapDesc
); /* offset in first block only */
1594 ptr
= (Uint8
*)bh
->b_data
;
1598 while ((bytes
> 0) && (index
< sb
->s_blocksize
))
1601 accum
+= udf_bitmap_lookup
[ value
& 0x0f ];
1602 accum
+= udf_bitmap_lookup
[ value
>> 4 ];
1608 udf_release_data(bh
);
1609 newblock
= udf_get_lb_pblock(sb
, loc
, ++block
);
1610 bh
= udf_tread(sb
, newblock
, sb
->s_blocksize
);
1613 udf_debug("read failed\n");
1617 ptr
= (Uint8
*)bh
->b_data
;
1620 udf_release_data(bh
);