Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * lowlevel.c |
| 3 | * |
| 4 | * PURPOSE |
| 5 | * Low Level Device Routines for the UDF filesystem |
| 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * COPYRIGHT |
| 8 | * This file is distributed under the terms of the GNU General Public |
| 9 | * License (GPL). Copies of the GPL can be obtained from: |
| 10 | * ftp://prep.ai.mit.edu/pub/gnu/GPL |
| 11 | * Each contributing author retains all rights to their own work. |
| 12 | * |
| 13 | * (C) 1999-2001 Ben Fennema |
| 14 | * |
| 15 | * HISTORY |
| 16 | * |
| 17 | * 03/26/99 blf Created. |
| 18 | */ |
| 19 | |
| 20 | #include "udfdecl.h" |
| 21 | |
| 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/cdrom.h> |
Fabian Frederick | e973606 | 2014-06-18 19:38:24 +0200 | [diff] [blame] | 24 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "udf_sb.h" |
| 27 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 28 | unsigned int udf_get_last_session(struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | { |
Christoph Hellwig | 8b075e5 | 2020-04-25 09:57:06 +0200 | [diff] [blame] | 30 | struct cdrom_device_info *cdi = disk_to_cdi(sb->s_bdev->bd_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | struct cdrom_multisession ms_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Christoph Hellwig | 8b075e5 | 2020-04-25 09:57:06 +0200 | [diff] [blame] | 33 | if (!cdi) { |
| 34 | udf_debug("CDROMMULTISESSION not supported.\n"); |
| 35 | return 0; |
| 36 | } |
| 37 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 38 | ms_info.addr_format = CDROM_LBA; |
Christoph Hellwig | 8b075e5 | 2020-04-25 09:57:06 +0200 | [diff] [blame] | 39 | if (cdrom_multisession(cdi, &ms_info) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | udf_debug("XA disk: %s, vol_desc_start=%d\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 41 | ms_info.xa_flag ? "yes" : "no", ms_info.addr.lba); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 42 | if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */ |
Christoph Hellwig | 8b075e5 | 2020-04-25 09:57:06 +0200 | [diff] [blame] | 43 | return ms_info.addr.lba; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | } |
Christoph Hellwig | 8b075e5 | 2020-04-25 09:57:06 +0200 | [diff] [blame] | 45 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 48 | unsigned long udf_get_last_block(struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | struct block_device *bdev = sb->s_bdev; |
Christoph Hellwig | 8b075e5 | 2020-04-25 09:57:06 +0200 | [diff] [blame] | 51 | struct cdrom_device_info *cdi = disk_to_cdi(bdev->bd_disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | unsigned long lblock = 0; |
| 53 | |
Jan Kara | 24a5d59 | 2009-06-18 12:33:16 +0200 | [diff] [blame] | 54 | /* |
Christoph Hellwig | 8b075e5 | 2020-04-25 09:57:06 +0200 | [diff] [blame] | 55 | * The cdrom layer call failed or returned obviously bogus value? |
Jan Kara | 24a5d59 | 2009-06-18 12:33:16 +0200 | [diff] [blame] | 56 | * Try using the device size... |
| 57 | */ |
Christoph Hellwig | 8b075e5 | 2020-04-25 09:57:06 +0200 | [diff] [blame] | 58 | if (!cdi || cdrom_get_last_written(cdi, &lblock) || lblock == 0) |
Fabian Frederick | 23bcda1 | 2017-01-06 21:54:41 +0100 | [diff] [blame] | 59 | lblock = i_size_read(bdev->bd_inode) >> sb->s_blocksize_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | if (lblock) |
| 62 | return lblock - 1; |
Christoph Hellwig | 8b075e5 | 2020-04-25 09:57:06 +0200 | [diff] [blame] | 63 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |