Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ntfs_device_size_get for file #45

Open
wants to merge 3 commits into
base: edge
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions libntfs-3g/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ static int ntfs_device_offset_valid(struct ntfs_device *dev, s64 ofs)
s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size)
{
s64 high, low;
struct stat sbuf;

if (!dev || block_size <= 0 || (block_size - 1) & block_size) {
errno = EINVAL;
Expand Down Expand Up @@ -596,6 +597,18 @@ s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size)
}
}
#endif
/*
* We couldn't figure it out by using a specialized ioctl,
* so do lstat on device.
*/
if (dev->d_ops->stat(dev, &sbuf) == 0 && S_ISREG(sbuf.st_mode) && sbuf.st_size > 512) {
ntfs_log_debug("STAT nr bytes = %llu (0x%llx)\n",
(unsigned long long)sbuf.st_size,
(unsigned long long)sbuf.st_size);

return sbuf.st_size / block_size;
}

/*
* We couldn't figure it out by using a specialized ioctl,
* so do binary search to find the size of the device.
Expand Down