Commit 46689499 authored by Mike Hibler's avatar Mike Hibler

Hot on the heels of the last change...

Add a new interface to the library to enable us to use the whole-disk
device rather than having to (figure out and) use a specific slice device.
parent 448221ad
......@@ -23,15 +23,23 @@ diff -ru ntfsprogs-1.7.1/include/debug.h ntfsprogs-1.7.1-utah/include/debug.h
#ifdef HAVE_STDIO_H
diff -ru ntfsprogs-1.7.1/include/disk_io.h ntfsprogs-1.7.1-utah/include/disk_io.h
--- ntfsprogs-1.7.1/include/disk_io.h Thu Feb 6 08:24:56 2003
+++ ntfsprogs-1.7.1-utah/include/disk_io.h Wed Mar 31 16:37:25 2004
@@ -22,6 +22,7 @@
+++ ntfsprogs-1.7.1-utah/include/disk_io.h Wed Apr 7 09:40:14 2004
@@ -22,10 +22,13 @@
#ifndef _NTFS_DISK_IO_H
#define _NTFS_DISK_IO_H
+#include <sys/param.h> /*Included for FreeBSD*/
#include "volume.h"
extern s64 ntfs_pread(const int fd, const s64 pos, s64 count, const void *b);
-extern s64 ntfs_pread(const int fd, const s64 pos, s64 count, const void *b);
-extern s64 ntfs_pwrite(const int fd, const s64 pos, s64 count, const void *b);
+extern void ntfs_setiobase(const int fd, const s64 base);
+
+extern s64 ntfs_pread(const int fd, s64 pos, s64 count, const void *b);
+extern s64 ntfs_pwrite(const int fd, s64 pos, s64 count, const void *b);
extern s64 ntfs_mst_pread(const int fd, const s64 pos, s64 count,
const u32 bksize, const void *b);
diff -ru ntfsprogs-1.7.1/include/endians.h ntfsprogs-1.7.1-utah/include/endians.h
--- ntfsprogs-1.7.1/include/endians.h Thu Feb 6 08:24:56 2003
+++ ntfsprogs-1.7.1-utah/include/endians.h Wed Mar 31 16:37:25 2004
......@@ -235,7 +243,7 @@ diff -ru ntfsprogs-1.7.1/include/types.h ntfsprogs-1.7.1-utah/include/types.h
typedef uint16_t u16;
diff -ru ntfsprogs-1.7.1/include/volume.h ntfsprogs-1.7.1-utah/include/volume.h
--- ntfsprogs-1.7.1/include/volume.h Thu Feb 6 08:24:56 2003
+++ ntfsprogs-1.7.1-utah/include/volume.h Wed Mar 31 16:37:25 2004
+++ ntfsprogs-1.7.1-utah/include/volume.h Tue Apr 6 18:18:08 2004
@@ -22,6 +22,7 @@
#ifndef _NTFS_VOLUME_H
#define _NTFS_VOLUME_H
......@@ -244,6 +252,14 @@ diff -ru ntfsprogs-1.7.1/include/volume.h ntfsprogs-1.7.1-utah/include/volume.h
#include "config.h"
#include <sys/mount.h>
@@ -156,6 +157,7 @@
extern ntfs_volume *ntfs_volume_startup(const char *name, unsigned long rwflag);
extern ntfs_volume *ntfs_mount(const char *name, unsigned long rwflag);
+extern ntfs_volume *ntfs_mount_with_offset(const char *name, unsigned long rwflag, const s64 doffset);
extern int ntfs_umount(ntfs_volume *vol, const BOOL force);
diff -ru ntfsprogs-1.7.1/libntfs/attrib.c ntfsprogs-1.7.1-utah/libntfs/attrib.c
--- ntfsprogs-1.7.1/libntfs/attrib.c Thu Feb 13 03:25:30 2003
+++ ntfsprogs-1.7.1-utah/libntfs/attrib.c Wed Mar 31 16:37:25 2004
......@@ -333,7 +349,7 @@ diff -ru ntfsprogs-1.7.1/libntfs/dir.c ntfsprogs-1.7.1-utah/libntfs/dir.c
index_end = (u8*)&ir->index + le32_to_cpu(ir->index.index_length);
diff -ru ntfsprogs-1.7.1/libntfs/disk_io.c ntfsprogs-1.7.1-utah/libntfs/disk_io.c
--- ntfsprogs-1.7.1/libntfs/disk_io.c Thu Feb 6 08:24:56 2003
+++ ntfsprogs-1.7.1-utah/libntfs/disk_io.c Wed Mar 31 16:37:25 2004
+++ ntfsprogs-1.7.1-utah/libntfs/disk_io.c Wed Apr 7 09:36:30 2004
@@ -26,6 +26,7 @@
#include <string.h>
#include <errno.h>
......@@ -342,9 +358,28 @@ diff -ru ntfsprogs-1.7.1/libntfs/disk_io.c ntfsprogs-1.7.1-utah/libntfs/disk_io.
#ifdef HAVE_LINUX_FD_H
# include <sys/ioctl.h>
# include <linux/fd.h>
@@ -61,7 +62,8 @@
@@ -40,6 +41,15 @@
# define BLKGETSIZE _IO(0x12,96) /* Get device size in 512byte blocks. */
#endif
+static int iofd = -1;
+static s64 iobase = 0LL;
+
+void ntfs_setiobase(const int fd, const s64 base)
+{
+ iofd = fd;
+ iobase = base;
+}
+
/**
* ntfs_pread - positioned read from disk
* @fd: file descriptor to read from
@@ -59,9 +69,10 @@
* to the return code of either lseek, read, or set to EINVAL in case of
* invalid arguments.
*/
s64 ntfs_pread(const int fd, const s64 pos, s64 count, const void *b)
-s64 ntfs_pread(const int fd, const s64 pos, s64 count, const void *b)
+s64 ntfs_pread(const int fd, s64 pos, s64 count, const void *b)
{
- s64 br, total;
+ s64 br, total, amount_wanted; /*Modified line: amount_wanted added FreeBSD*/
......@@ -352,7 +387,19 @@ diff -ru ntfsprogs-1.7.1/libntfs/disk_io.c ntfsprogs-1.7.1-utah/libntfs/disk_io.
Dprintf("%s(): Entering for pos 0x%Lx, count 0x%Lx.\n", __FUNCTION__,
pos, count);
@@ -78,7 +80,19 @@
@@ -71,6 +82,11 @@
}
if (!count)
return 0;
+
+ /* Account for static offset. */
+ if (fd == iofd)
+ pos += iobase;
+
/* Locate to position. */
if (lseek(fd, pos, SEEK_SET) == (off_t)-1) {
Dprintf("ntfs_pread: lseek to 0x%Lx returned error: %s\n", pos,
@@ -78,7 +94,19 @@
return -1;
}
/* Read the data. */
......@@ -373,6 +420,50 @@ diff -ru ntfsprogs-1.7.1/libntfs/disk_io.c ntfsprogs-1.7.1-utah/libntfs/disk_io.
br = read(fd, (char*)b + total, count);
/* If everything ok, continue. */
if (br > 0)
@@ -112,7 +140,7 @@
* appropriately to the return code of either lseek, write, or set
* to EINVAL in case of invalid arguments.
*/
-s64 ntfs_pwrite(const int fd, const s64 pos, s64 count, const void *b)
+s64 ntfs_pwrite(const int fd, s64 pos, s64 count, const void *b)
{
s64 written, total;
@@ -124,6 +152,11 @@
}
if (!count)
return 0;
+
+ /* Account for static offset. */
+ if (fd == iofd)
+ pos += iobase;
+
/* Locate to position. */
if (lseek(fd, pos, SEEK_SET) == (off_t)-1) {
Dprintf("ntfs_pwrite: lseek to 0x%Lx returned error: %s\n",
@@ -353,6 +386,10 @@
{
char ch;
+ /* Account for static offset. */
+ if (f == iofd)
+ ofs += iobase;
+
if (lseek(f, ofs, SEEK_SET) >= 0 && read(f, &ch, 1) == 1)
return 0;
return -1;
@@ -371,6 +408,11 @@
s64 ntfs_device_size_get(int f, int block_size)
{
s64 high, low;
+
+ /* Account for static offset. */
+ if (f == iofd)
+ Dprintf("WARNING: cannot correctly determine device size\n");
+
#ifdef BLKGETSIZE
long size;
diff -ru ntfsprogs-1.7.1/libntfs/lcnalloc.c ntfsprogs-1.7.1-utah/libntfs/lcnalloc.c
--- ntfsprogs-1.7.1/libntfs/lcnalloc.c Thu Feb 6 08:24:56 2003
+++ ntfsprogs-1.7.1-utah/libntfs/lcnalloc.c Wed Mar 31 16:37:25 2004
......@@ -428,7 +519,7 @@ diff -ru ntfsprogs-1.7.1/libntfs/unistr.c ntfsprogs-1.7.1-utah/libntfs/unistr.c
* IMPORTANT
diff -ru ntfsprogs-1.7.1/libntfs/volume.c ntfsprogs-1.7.1-utah/libntfs/volume.c
--- ntfsprogs-1.7.1/libntfs/volume.c Thu Feb 6 08:24:56 2003
+++ ntfsprogs-1.7.1-utah/libntfs/volume.c Wed Mar 31 16:37:25 2004
+++ ntfsprogs-1.7.1-utah/libntfs/volume.c Wed Apr 7 10:39:20 2004
@@ -27,6 +27,7 @@
#include <sys/stat.h>
#include <limits.h>
......@@ -437,12 +528,75 @@ diff -ru ntfsprogs-1.7.1/libntfs/volume.c ntfsprogs-1.7.1-utah/libntfs/volume.c
#include "volume.h"
#include "attrib.h"
#include "mft.h"
@@ -70,7 +71,7 @@
@@ -70,7 +71,8 @@
if (v->mftmirr_ni)
ntfs_inode_close(v->mftmirr_ni);
if (v->fd) {
- fdatasync(v->fd);
+/* fdatasync(v->fd); Removed for FreeBSD*/
+ ntfs_setiobase(-1, 0LL);
close(v->fd);
}
if (v->dev_name)
@@ -361,6 +363,9 @@
return -1;
}
+/* Internal */
+static ntfs_volume *ntfs_volume_startup_internal(const char *name, unsigned long rwflag, const s64 doffset);
+
/**
* ntfs_volume_startup - allocate and setup an ntfs volume
* @name: name of device/file to open
@@ -375,6 +380,11 @@
*/
ntfs_volume *ntfs_volume_startup(const char *name, unsigned long rwflag)
{
+ return ntfs_volume_startup_internal(name, rwflag, 0LL);
+}
+
+static ntfs_volume *ntfs_volume_startup_internal(const char *name, unsigned long rwflag, const s64 doffset)
+{
LCN mft_zone_size, mft_lcn;
s64 br;
const char *OK = "OK";
@@ -389,6 +399,8 @@
#endif
/* Allocate the volume structure. */
+
+
vol = __ntfs_volume_allocate();
if (!vol)
return NULL;
@@ -406,6 +418,9 @@
Dperror("Error opening partition file");
goto error_exit;
}
+ /* XXX set the disk offset if there is one. */
+ if (doffset)
+ ntfs_setiobase(vol->fd, doffset);
/* Now read the bootsector. */
br = ntfs_pread(vol->fd, 0, sizeof(NTFS_BOOT_SECTOR), bs);
if (br != sizeof(NTFS_BOOT_SECTOR)) {
@@ -563,6 +578,11 @@
*/
ntfs_volume *ntfs_mount(const char *name, unsigned long rwflag)
{
+ return ntfs_mount_with_offset(name, rwflag, 0LL);
+}
+
+ntfs_volume *ntfs_mount_with_offset(const char *name, unsigned long rwflag, const s64 doffset)
+{
s64 l;
const char *OK = "OK";
const char *FAILED = "FAILED";
@@ -582,7 +602,7 @@
return NULL;
}
- vol = ntfs_volume_startup(name, rwflag);
+ vol = ntfs_volume_startup_internal(name, rwflag, doffset);
if (!vol) {
Dperror("Failed to startup volume");
return NULL;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment