From 9318887cd520906cf387c8e87ddd3fc7e1a235b3 Mon Sep 17 00:00:00 2001 From: "cantab.net!aia21" Date: Wed, 17 Mar 2004 12:22:03 +0000 Subject: [PATCH] Add new API device.[hc]::ntfs_device_partition_start_sector_get() and make mkntfs use it. (Logical change 1.336) --- include/ntfs/device.h | 2 ++ libntfs/device.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/ntfs/device.h b/include/ntfs/device.h index 7db9b0e7..4acd2896 100644 --- a/include/ntfs/device.h +++ b/include/ntfs/device.h @@ -109,4 +109,6 @@ extern s64 ntfs_cluster_write(const ntfs_volume *vol, const s64 lcn, extern s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size); +extern s64 ntfs_device_partition_start_sector_get(struct ntfs_device *dev); + #endif /* defined _NTFS_DEVICE_H */ diff --git a/libntfs/device.c b/libntfs/device.c index dc451d03..d0450c58 100644 --- a/libntfs/device.c +++ b/libntfs/device.c @@ -33,6 +33,9 @@ #ifdef HAVE_LINUX_FD_H # include #endif +#ifdef HAVE_LINUX_HDREG_H +# include +#endif #include "types.h" #include "mst.h" @@ -40,10 +43,13 @@ #include "device.h" #if defined(linux) && defined(_IO) && !defined(BLKGETSIZE) -#define BLKGETSIZE _IO(0x12,96) /* Get device size in 512-byte blocks. */ +#define BLKGETSIZE _IO(0x12,96) /* Get device size in 512-byte blocks. */ #endif #if defined(linux) && defined(_IOR) && !defined(BLKGETSIZE64) -#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* Get device size in bytes. */ +#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* Get device size in bytes. */ +#endif +#if defined(linux) && !defined(HDIO_GETGEO) +#define HDIO_GETGEO 0x0301 /* Get device geometry. */ #endif /** @@ -506,3 +512,30 @@ s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size) return (low + 1LL) / block_size; } +/** + * ntfs_device_partition_start_sector_get - get starting sector of a partition + * @dev: open device + * + * On success, return the starting sector of the partition @dev in the parent + * block device of @dev. On error return -1 with errno set to the error code. + * + * The following error codes are defined: + * ENOTSUP System does not support HDIO_GETGEO ioctl + * ENOTTY @dev is a file or a device not supporting HDIO_GETGEO + */ +s64 ntfs_device_partition_start_sector_get(struct ntfs_device *dev) +{ +#ifdef HDIO_GETGEO + { struct hd_geometry geo; + + if (!dev->d_ops->ioctl(dev, HDIO_GETGEO, &geo)) { + Dprintf("HDIO_GETGEO start_sect = %lu (0x%lx)\n", + geo.start, geo.start); + return geo.start; + } + } +#else + errno = ENOTSUP; +#endif + return -1; +}