blob: f1094cdcd6cdea91957a4ca4697ad89dd90184bf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * lowlevel.c
3 *
4 * PURPOSE
5 * Low Level Device Routines for the UDF filesystem
6 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 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 Fredericke9736062014-06-18 19:38:24 +020024#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "udf_sb.h"
27
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -070028unsigned int udf_get_last_session(struct super_block *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
Christoph Hellwig8b075e52020-04-25 09:57:06 +020030 struct cdrom_device_info *cdi = disk_to_cdi(sb->s_bdev->bd_disk);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 struct cdrom_multisession ms_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Christoph Hellwig8b075e52020-04-25 09:57:06 +020033 if (!cdi) {
34 udf_debug("CDROMMULTISESSION not supported.\n");
35 return 0;
36 }
37
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -070038 ms_info.addr_format = CDROM_LBA;
Christoph Hellwig8b075e52020-04-25 09:57:06 +020039 if (cdrom_multisession(cdi, &ms_info) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 udf_debug("XA disk: %s, vol_desc_start=%d\n",
Joe Perchesa983f362011-10-10 01:08:07 -070041 ms_info.xa_flag ? "yes" : "no", ms_info.addr.lba);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070042 if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */
Christoph Hellwig8b075e52020-04-25 09:57:06 +020043 return ms_info.addr.lba;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 }
Christoph Hellwig8b075e52020-04-25 09:57:06 +020045 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -070048unsigned long udf_get_last_block(struct super_block *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50 struct block_device *bdev = sb->s_bdev;
Christoph Hellwig8b075e52020-04-25 09:57:06 +020051 struct cdrom_device_info *cdi = disk_to_cdi(bdev->bd_disk);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 unsigned long lblock = 0;
53
Jan Kara24a5d592009-06-18 12:33:16 +020054 /*
Christoph Hellwig8b075e52020-04-25 09:57:06 +020055 * The cdrom layer call failed or returned obviously bogus value?
Jan Kara24a5d592009-06-18 12:33:16 +020056 * Try using the device size...
57 */
Christoph Hellwig8b075e52020-04-25 09:57:06 +020058 if (!cdi || cdrom_get_last_written(cdi, &lblock) || lblock == 0)
Fabian Frederick23bcda12017-01-06 21:54:41 +010059 lblock = i_size_read(bdev->bd_inode) >> sb->s_blocksize_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 if (lblock)
62 return lblock - 1;
Christoph Hellwig8b075e52020-04-25 09:57:06 +020063 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}