mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-27 00:51:35 +00:00
block: Change direct_access calling convention
In order to support accesses to larger chunks of memory, pass in a 'size' parameter (counted in bytes), and return the amount available at that address. Add a new helper function, bdev_direct_access(), to handle common functionality including partition handling, checking the length requested is positive, checking for the sector being page-aligned, and checking the length of the request does not pass the end of the partition. Signed-off-by: Matthew Wilcox <matthew.r.wilcox@intel.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Boaz Harrosh <boaz@plexistor.com> Signed-off-by: Jens Axboe <axboe@fb.com>
This commit is contained in:
parent
c761d96b07
commit
dd22f551ac
7 changed files with 86 additions and 58 deletions
|
@ -429,6 +429,46 @@ int bdev_write_page(struct block_device *bdev, sector_t sector,
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(bdev_write_page);
|
||||
|
||||
/**
|
||||
* bdev_direct_access() - Get the address for directly-accessibly memory
|
||||
* @bdev: The device containing the memory
|
||||
* @sector: The offset within the device
|
||||
* @addr: Where to put the address of the memory
|
||||
* @pfn: The Page Frame Number for the memory
|
||||
* @size: The number of bytes requested
|
||||
*
|
||||
* If a block device is made up of directly addressable memory, this function
|
||||
* will tell the caller the PFN and the address of the memory. The address
|
||||
* may be directly dereferenced within the kernel without the need to call
|
||||
* ioremap(), kmap() or similar. The PFN is suitable for inserting into
|
||||
* page tables.
|
||||
*
|
||||
* Return: negative errno if an error occurs, otherwise the number of bytes
|
||||
* accessible at this address.
|
||||
*/
|
||||
long bdev_direct_access(struct block_device *bdev, sector_t sector,
|
||||
void **addr, unsigned long *pfn, long size)
|
||||
{
|
||||
long avail;
|
||||
const struct block_device_operations *ops = bdev->bd_disk->fops;
|
||||
|
||||
if (size < 0)
|
||||
return size;
|
||||
if (!ops->direct_access)
|
||||
return -EOPNOTSUPP;
|
||||
if ((sector + DIV_ROUND_UP(size, 512)) >
|
||||
part_nr_sects_read(bdev->bd_part))
|
||||
return -ERANGE;
|
||||
sector += get_start_sect(bdev);
|
||||
if (sector % (PAGE_SIZE / 512))
|
||||
return -EINVAL;
|
||||
avail = ops->direct_access(bdev, sector, addr, pfn, size);
|
||||
if (!avail)
|
||||
return -ERANGE;
|
||||
return min(avail, size);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(bdev_direct_access);
|
||||
|
||||
/*
|
||||
* pseudo-fs
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue