2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* lowlevel.c
|
|
|
|
*
|
|
|
|
* PURPOSE
|
|
|
|
* Low Level Device Routines for the UDF filesystem
|
|
|
|
*
|
|
|
|
* COPYRIGHT
|
|
|
|
* This file is distributed under the terms of the GNU General Public
|
|
|
|
* License (GPL). Copies of the GPL can be obtained from:
|
|
|
|
* ftp://prep.ai.mit.edu/pub/gnu/GPL
|
|
|
|
* Each contributing author retains all rights to their own work.
|
|
|
|
*
|
|
|
|
* (C) 1999-2001 Ben Fennema
|
|
|
|
*
|
|
|
|
* HISTORY
|
|
|
|
*
|
|
|
|
* 03/26/99 blf Created.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "udfdecl.h"
|
|
|
|
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/cdrom.h>
|
2014-06-18 17:38:24 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "udf_sb.h"
|
|
|
|
|
2007-07-19 08:47:43 +00:00
|
|
|
unsigned int udf_get_last_session(struct super_block *sb)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2020-04-25 07:57:06 +00:00
|
|
|
struct cdrom_device_info *cdi = disk_to_cdi(sb->s_bdev->bd_disk);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct cdrom_multisession ms_info;
|
|
|
|
|
2020-04-25 07:57:06 +00:00
|
|
|
if (!cdi) {
|
|
|
|
udf_debug("CDROMMULTISESSION not supported.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2020-04-25 07:57:06 +00:00
|
|
|
ms_info.addr_format = CDROM_LBA;
|
|
|
|
if (cdrom_multisession(cdi, &ms_info) == 0) {
|
2005-04-16 22:20:36 +00:00
|
|
|
udf_debug("XA disk: %s, vol_desc_start=%d\n",
|
2011-10-10 08:08:07 +00:00
|
|
|
ms_info.xa_flag ? "yes" : "no", ms_info.addr.lba);
|
2007-07-21 11:37:18 +00:00
|
|
|
if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */
|
2020-04-25 07:57:06 +00:00
|
|
|
return ms_info.addr.lba;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2020-04-25 07:57:06 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2023-01-18 12:55:31 +00:00
|
|
|
udf_pblk_t udf_get_last_block(struct super_block *sb)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2021-10-18 10:11:30 +00:00
|
|
|
struct cdrom_device_info *cdi = disk_to_cdi(sb->s_bdev->bd_disk);
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long lblock = 0;
|
|
|
|
|
2009-06-18 10:33:16 +00:00
|
|
|
/*
|
2020-04-25 07:57:06 +00:00
|
|
|
* The cdrom layer call failed or returned obviously bogus value?
|
2009-06-18 10:33:16 +00:00
|
|
|
* Try using the device size...
|
|
|
|
*/
|
2023-01-18 12:55:31 +00:00
|
|
|
if (!cdi || cdrom_get_last_written(cdi, &lblock) || lblock == 0) {
|
|
|
|
if (sb_bdev_nr_blocks(sb) > ~(udf_pblk_t)0)
|
|
|
|
return 0;
|
2021-10-18 10:11:30 +00:00
|
|
|
lblock = sb_bdev_nr_blocks(sb);
|
2023-01-18 12:55:31 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (lblock)
|
|
|
|
return lblock - 1;
|
2020-04-25 07:57:06 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|