Re: [PATCH] ntfs: add code to make FIBMAP ioctl work

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 16 Oct 2014, at 00:12, Andreas Dilger <adilger@xxxxxxxxx> wrote:
> On Oct 15, 2014, at 1:19 PM, Sergei Antonov <saproj@xxxxxxxxx> wrote:
>> Implement ntfs_bmap() function for the "bmap" address space operation.
>> Now user space programs can send FIBMAP ioctl to get files' placement on
>> NTFS the same way they can do it on a number of other linux filesystems.
>> 
>> The result is returned in FIGETBSZ units, which is equal to sector size
>> in ntfs driver. An error value zero is returned for resident, compressed,
>> encrypted files, and for holes in sparse files.
> 
> Any thoughts about implementing FIEMAP for NTFS?  This allows byte offset
> granularity, and reduces the number of system calls significantly.

Sure, would be nice to have it.  And I will get round to it one day but no customer has ever requested it so at least I haven't implemented it yet...

Best regards,

	Anton

> Cheers, Andreas
> 
>> Tested on drives with different sector sizes and different cluster sizes.
>> 
>> Cc: Anton Altaparmakov <aia21@xxxxxxxxxx>
>> Signed-off-by: Sergei Antonov <saproj@xxxxxxxxx>
>> ---
>> fs/ntfs/aops.c | 31 +++++++++++++++++++++++++++++++
>> 1 file changed, 31 insertions(+)
>> 
>> diff --git a/fs/ntfs/aops.c b/fs/ntfs/aops.c
>> index d267ea6..3972b6b 100644
>> --- a/fs/ntfs/aops.c
>> +++ b/fs/ntfs/aops.c
>> @@ -1538,6 +1538,36 @@ err_out:
>> 
>> #endif	/* NTFS_RW */
>> 
>> +static sector_t ntfs_bmap(struct address_space *mapping, sector_t block)
>> +{
>> +	struct inode *vi = mapping->host;
>> +	ntfs_inode *ni = NTFS_I(vi);
>> +	ntfs_volume *vol = ni->vol;
>> +	const unsigned clust2sect_bits = vol->cluster_size_bits -
>> +		vol->sector_size_bits;
>> +	const sector_t clust2sect_mask = (1 << clust2sect_bits) - 1;
>> +	LCN lcn;
>> +
>> +	BUG_ON(S_ISDIR(vi->i_mode));
>> +	ntfs_debug("Requested LCN for block %llu.", (unsigned long long)block);
>> +	if (!NInoNonResident(ni) || NInoCompressed(ni) || NInoEncrypted(ni))
>> +		return 0;
>> +
>> +	down_read(&ni->runlist.lock);
>> +	lcn = ntfs_attr_vcn_to_lcn_nolock(ni, block >> clust2sect_bits, false);
>> +	up_read(&ni->runlist.lock);
>> +
>> +	if (lcn < 0) {
>> +		if (lcn == LCN_HOLE)
>> +			ntfs_warning(vol->sb, "Cannot get LCN for a hole.");
>> +		else
>> +			ntfs_error(vol->sb, "Error getting LCN: %lld.", lcn);
>> +		return 0;
>> +	}
>> +
>> +	return (lcn << clust2sect_bits) + (block & clust2sect_mask);
>> +}
>> +
>> /**
>> * ntfs_aops - general address space operations for inodes and attributes
>> */
>> @@ -1546,6 +1576,7 @@ const struct address_space_operations ntfs_aops = {
>> #ifdef NTFS_RW
>> 	.writepage	= ntfs_writepage,	/* Write dirty page to disk. */
>> #endif /* NTFS_RW */
>> +	.bmap		= ntfs_bmap,		/* Map file offset to volume. */
>> 	.migratepage	= buffer_migrate_page,	/* Move a page cache page from
>> 						   one physical page to an
>> 						   other. */

-- 
Anton Altaparmakov <anton at tuxera.com> (replace at with @)
Senior Kernel Engineer, Tuxera Inc., http://www.tuxera.com/
Linux NTFS maintainer

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux