Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * lowlevel.c
0003  *
0004  * PURPOSE
0005  *  Low Level Device Routines for the UDF filesystem
0006  *
0007  * COPYRIGHT
0008  *  This file is distributed under the terms of the GNU General Public
0009  *  License (GPL). Copies of the GPL can be obtained from:
0010  *      ftp://prep.ai.mit.edu/pub/gnu/GPL
0011  *  Each contributing author retains all rights to their own work.
0012  *
0013  *  (C) 1999-2001 Ben Fennema
0014  *
0015  * HISTORY
0016  *
0017  *  03/26/99 blf  Created.
0018  */
0019 
0020 #include "udfdecl.h"
0021 
0022 #include <linux/blkdev.h>
0023 #include <linux/cdrom.h>
0024 #include <linux/uaccess.h>
0025 
0026 #include "udf_sb.h"
0027 
0028 unsigned int udf_get_last_session(struct super_block *sb)
0029 {
0030     struct cdrom_device_info *cdi = disk_to_cdi(sb->s_bdev->bd_disk);
0031     struct cdrom_multisession ms_info;
0032 
0033     if (!cdi) {
0034         udf_debug("CDROMMULTISESSION not supported.\n");
0035         return 0;
0036     }
0037 
0038     ms_info.addr_format = CDROM_LBA;
0039     if (cdrom_multisession(cdi, &ms_info) == 0) {
0040         udf_debug("XA disk: %s, vol_desc_start=%d\n",
0041               ms_info.xa_flag ? "yes" : "no", ms_info.addr.lba);
0042         if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */
0043             return ms_info.addr.lba;
0044     }
0045     return 0;
0046 }
0047 
0048 unsigned long udf_get_last_block(struct super_block *sb)
0049 {
0050     struct cdrom_device_info *cdi = disk_to_cdi(sb->s_bdev->bd_disk);
0051     unsigned long lblock = 0;
0052 
0053     /*
0054      * The cdrom layer call failed or returned obviously bogus value?
0055      * Try using the device size...
0056      */
0057     if (!cdi || cdrom_get_last_written(cdi, &lblock) || lblock == 0)
0058         lblock = sb_bdev_nr_blocks(sb);
0059 
0060     if (lblock)
0061         return lblock - 1;
0062     return 0;
0063 }