Extend API to pass dev_offset

Add option device offset.
pull/48/head
Konstantin Germanov 2022-06-28 06:44:09 -04:00
parent 875a1d4e90
commit d874c30200
4 changed files with 65 additions and 1 deletions

View File

@ -90,6 +90,8 @@ struct ntfs_device {
heads or -1. */
int d_sectors_per_track; /* Disk geometry: number of
sectors per track or -1. */
s64 dev_offset; /* Offset from the start of the device
where the ntfs filesystem begins.*/
};
struct stat;
@ -117,6 +119,9 @@ struct ntfs_device_operations {
extern struct ntfs_device *ntfs_device_alloc(const char *name, const long state,
struct ntfs_device_operations *dops, void *priv_data);
extern struct ntfs_device *ntfs_device_alloc_ext(const char *name, const long state,
struct ntfs_device_operations *dops, void *priv_data, s64 dev_offset);
extern int ntfs_device_free(struct ntfs_device *dev);
extern int ntfs_device_sync(struct ntfs_device *dev);

View File

@ -299,6 +299,7 @@ extern ntfs_volume *ntfs_device_mount(struct ntfs_device *dev,
ntfs_mount_flags flags);
extern ntfs_volume *ntfs_mount(const char *name, ntfs_mount_flags flags);
extern ntfs_volume *ntfs_mount_ext(const char *name, ntfs_mount_flags flags, const s64 dev_offset);
extern int ntfs_umount(ntfs_volume *vol, const BOOL force);
extern int ntfs_version_is_supported(ntfs_volume *vol);

View File

@ -114,6 +114,30 @@
struct ntfs_device *ntfs_device_alloc(const char *name, const long state,
struct ntfs_device_operations *dops, void *priv_data)
{
return ntfs_device_alloc_ext(name, state, dops, priv_data, 0);
}
/**
* ntfs_device_alloc_ext - allocate an ntfs device structure and pre-initialize it
* @name: name of the device (must be present)
* @state: initial device state (usually zero)
* @dops: ntfs device operations to use with the device (must be present)
* @priv_data: pointer to private data (optional)
* @dev_offset: offset from beginning of device where the ntfs filesystem begins
*
* Allocate an ntfs device structure and pre-initialize it with the user-
* specified device operations @dops, device state @state, device name @name,
* and optional private data @priv_data.
*
* Note, @name is copied and can hence be freed after this functions returns.
*
* On success return a pointer to the allocated ntfs device structure and on
* error return NULL with errno set to the error code returned by ntfs_malloc().
*/
struct ntfs_device *ntfs_device_alloc_ext(const char *name, const long state,
struct ntfs_device_operations *dops, void *priv_data, const s64 dev_offset)
{
struct ntfs_device *dev;
if (!name) {
@ -134,6 +158,7 @@ struct ntfs_device *ntfs_device_alloc(const char *name, const long state,
dev->d_private = priv_data;
dev->d_heads = -1;
dev->d_sectors_per_track = -1;
dev->dev_offset = dev_offset;
}
return dev;
}

View File

@ -1413,13 +1413,46 @@ int ntfs_set_ignore_case(ntfs_volume *vol)
*/
ntfs_volume *ntfs_mount(const char *name __attribute__((unused)),
ntfs_mount_flags flags __attribute__((unused)))
{
return ntfs_mount_ext(name, flags, 0);
}
/**
* ntfs_mount_ext - open ntfs volume with dev_offset
* @name: name of device/file to open
* @flags: optional mount flags
* @dev_offset: offset from beginning of device where the ntfs filesystem begins
*
* This function mounts an ntfs volume. @name should contain the name of the
* device/file to mount as the ntfs volume.
*
* @flags is an optional second parameter. The same flags are used as for
* the mount system call (man 2 mount). Currently only the following flags
* is implemented:
* NTFS_MNT_RDONLY - mount volume read-only
*
* The function opens the device or file @name and verifies that it contains a
* valid bootsector. Then, it allocates an ntfs_volume structure and initializes
* some of the values inside the structure from the information stored in the
* bootsector. It proceeds to load the necessary system files and completes
* setting up the structure.
*
* Return the allocated volume structure on success and NULL on error with
* errno set to the error code.
*
* Note, that a copy is made of @name, and hence it can be discarded as
* soon as the function returns.
*/
ntfs_volume *ntfs_mount_ext(const char *name __attribute__((unused)),
ntfs_mount_flags flags __attribute__((unused)), const s64 dev_offset)
{
#ifndef NO_NTFS_DEVICE_DEFAULT_IO_OPS
struct ntfs_device *dev;
ntfs_volume *vol;
/* Allocate an ntfs_device structure. */
dev = ntfs_device_alloc(name, 0, &ntfs_device_default_io_ops, NULL);
dev = ntfs_device_alloc_ext(name, 0, &ntfs_device_default_io_ops, NULL, dev_offset);
if (!dev)
return NULL;
/* Call ntfs_device_mount() to do the actual mount. */