fs: Enable bmap() function to properly return errors
By now, bmap() will either return the physical block number related to the requested file offset or 0 in case of error or the requested offset maps into a hole. This patch makes the needed changes to enable bmap() to proper return errors, using the return value as an error return, and now, a pointer must be passed to bmap() to be filled with the mapped physical block. It will change the behavior of bmap() on return: - negative value in case of error - zero on success or map fell into a hole In case of a hole, the *block will be zero too Since this is a prep patch, by now, the only error return is -EINVAL if ->bmap doesn't exist. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
committed by
Jaegeuk Kim
parent
c8203f86b6
commit
ae6e619e82
30
fs/inode.c
30
fs/inode.c
@@ -1576,25 +1576,31 @@ void iput(struct inode *inode)
|
||||
}
|
||||
EXPORT_SYMBOL(iput);
|
||||
|
||||
#ifdef CONFIG_BLOCK
|
||||
/**
|
||||
* bmap - find a block number in a file
|
||||
* @inode: inode of file
|
||||
* @block: block to find
|
||||
* @inode: inode owning the block number being requested
|
||||
* @block: pointer containing the block to find
|
||||
*
|
||||
* Returns the block number on the device holding the inode that
|
||||
* is the disk block number for the block of the file requested.
|
||||
* That is, asked for block 4 of inode 1 the function will return the
|
||||
* disk block relative to the disk start that holds that block of the
|
||||
* file.
|
||||
* Replaces the value in *block with the block number on the device holding
|
||||
* corresponding to the requested block number in the file.
|
||||
* That is, asked for block 4 of inode 1 the function will replace the
|
||||
* 4 in *block, with disk block relative to the disk start that holds that
|
||||
* block of the file.
|
||||
*
|
||||
* Returns -EINVAL in case of error, 0 otherwise. If mapping falls into a
|
||||
* hole, returns 0 and *block is also set to 0.
|
||||
*/
|
||||
sector_t bmap(struct inode *inode, sector_t block)
|
||||
int bmap(struct inode *inode, sector_t *block)
|
||||
{
|
||||
sector_t res = 0;
|
||||
if (inode->i_mapping->a_ops->bmap)
|
||||
res = inode->i_mapping->a_ops->bmap(inode->i_mapping, block);
|
||||
return res;
|
||||
if (!inode->i_mapping->a_ops->bmap)
|
||||
return -EINVAL;
|
||||
|
||||
*block = inode->i_mapping->a_ops->bmap(inode->i_mapping, *block);
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(bmap);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* With relative atime, only update atime if the previous atime is
|
||||
|
||||
Reference in New Issue
Block a user