From: Sergei Antonov <saproj@gmail.com>
To: linux-fsdevel@vger.kernel.org
Cc: Anton Altaparmakov <aia21@cantab.net>, Sergei Antonov <saproj@gmail.com>
Subject: [PATCH] ntfs: add code to make FIBMAP ioctl work
Date: Wed, 15 Oct 2014 21:19:27 +0200 [thread overview]
Message-ID: <1413400767-2788-1-git-send-email-saproj@gmail.com> (raw)
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.
Tested on drives with different sector sizes and different cluster sizes.
Cc: Anton Altaparmakov <aia21@cantab.net>
Signed-off-by: Sergei Antonov <saproj@gmail.com>
---
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. */
--
2.1.2
next reply other threads:[~2014-10-15 19:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-15 19:19 Sergei Antonov [this message]
2014-10-15 23:12 ` [PATCH] ntfs: add code to make FIBMAP ioctl work Andreas Dilger
2014-10-16 11:37 ` Sergei Antonov
2014-10-16 13:23 ` Anton Altaparmakov
2014-10-16 13:20 ` Anton Altaparmakov
2014-10-16 15:07 ` Sergei Antonov
2014-10-16 15:36 ` Anton Altaparmakov
2014-10-16 20:03 ` Sergei Antonov
2014-10-16 20:43 ` Anton Altaparmakov
2014-10-16 21:55 ` Anton Altaparmakov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1413400767-2788-1-git-send-email-saproj@gmail.com \
--to=saproj@gmail.com \
--cc=aia21@cantab.net \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).