summaryrefslogtreecommitdiffstats
path: root/sysutils/fusefs-ntfs/files/patch-libntfs-3g__unix_io.c
blob: b3e4c3dad80aeac1b5e3acadb63c8c218d47acdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
--- libntfs-3g/unix_io.c.orig	2010-03-06 13:12:25.000000000 -0300
+++ libntfs-3g/unix_io.c	2010-10-04 15:17:18.000000000 -0300
@@ -54,6 +54,22 @@
 #include <linux/fd.h>
 #endif
 
+/*
+ * The following build definitions are available:
+ * USE_ALIGNED_IO	- All I/O is done by blocks.
+ * USE_UBLIO		- Use the ublio user space cache library.
+ * USE_LOCK		- Lock the device/file when mounted.
+ */
+
+#ifdef __FreeBSD__
+#include <sys/disk.h>
+#define USE_ALIGNED_IO	1
+#endif
+
+#if USE_UBLIO
+#include <sys/uio.h>
+#endif
+
 #include "types.h"
 #include "mst.h"
 #include "debug.h"
@@ -61,13 +77,90 @@
 #include "logging.h"
 #include "misc.h"
 
-#define DEV_FD(dev)	(*(int *)dev->d_private)
+#if USE_UBLIO
+#define UBLIO_USE_API		1
+#include "ublio.h"
+#define UBLIO_DEFAULT_ENABLE	1
+#define UBLIO_DEFAULT_BLOCKSIZE	262144
+#define UBLIO_DEFAULT_ITEMS	64
+#define UBLIO_DEFAULT_GRACE	32
+#define UBLIO_DEFAULT_SYNC_IO	0
+#endif
+
+#if USE_ALIGNED_IO
+#define RAW_IO_ALIGNED(dev, offset, count)			\
+	(DEV_HANDLE(dev)->block_size == 0 ||			\
+	 ((offset) % DEV_HANDLE(dev)->block_size == 0 &&	\
+	  (count) % DEV_HANDLE(dev)->block_size == 0))
+#define RAW_IO_ALIGN(dev, offset)				\
+	((offset) / DEV_HANDLE(dev)->block_size * DEV_HANDLE(dev)->block_size)
+#define RAW_IO_MAX_SIZE (128 * 1024 * 1024)
+#endif
+
+struct unix_filehandle {
+	int fd;
+#if USE_ALIGNED_IO
+	s64 pos;
+	s32 block_size;
+	s64 media_size;
+#endif
+#if USE_UBLIO
+	ublio_filehandle_t ublio_fh;
+#endif
+};
+
+#define DEV_HANDLE(dev)	((struct unix_filehandle *)dev->d_private)
+#define DEV_FD(dev)	(DEV_HANDLE(dev)->fd)
 
 /* Define to nothing if not present on this system. */
 #ifndef O_EXCL
 #	define O_EXCL 0
 #endif
 
+#if USE_ALIGNED_IO
+/**
+ * Get block_size and media_size
+ */
+static int
+raw_io_get_size(struct ntfs_device *dev)
+{
+	int bs;
+	off_t ms;
+	struct stat sb;
+
+	if (fstat(DEV_FD(dev), &sb) < 0) {
+		ntfs_log_perror("Failed to stat '%s'", dev->d_name);
+		return -1;
+	}
+
+	if (S_ISREG(sb.st_mode)) {
+		DEV_HANDLE(dev)->media_size = sb.st_size;
+		ntfs_log_trace("%s: regular file (media_size %lld)\n",
+		    dev->d_name, DEV_HANDLE(dev)->media_size);
+		if (getenv("FORCE_ALIGNED_IO"))
+			DEV_HANDLE(dev)->block_size = 512;
+		return 0;
+	}
+
+	if (ioctl(DEV_FD(dev), DIOCGSECTORSIZE, &bs) < 0) {
+		ntfs_log_perror("Failed to ioctl(DIOCGSECTORSIZE) '%s'",
+		    dev->d_name);
+		return -1;
+	}
+	DEV_HANDLE(dev)->block_size = bs;
+	ntfs_log_trace("%s: block size %d\n", dev->d_name, bs);
+
+	if (ioctl(DEV_FD(dev), DIOCGMEDIASIZE, &ms) < 0) {
+		ntfs_log_perror("Failed to ioctl(DIOCGMEDIASIZE) '%s'",
+		    dev->d_name);
+		return -1;
+	}
+	DEV_HANDLE(dev)->media_size = ms;
+	ntfs_log_trace("%s: media size %lld\n", dev->d_name, ms);
+	return 0;
+}
+#endif
+
 /**
  * fsync replacement which makes every effort to try to get the data down to
  * disk, using different means for different operating systems. Specifically,
@@ -113,9 +206,21 @@
  */
 static int ntfs_device_unix_io_open(struct ntfs_device *dev, int flags)
 {
+#if USE_ALIGNED_IO
+	size_t sectsize;
+#endif
+#if USE_LOCK
 	struct flock flk;
+#endif
 	struct stat sbuf;
-	int err;
+	struct unix_filehandle *ufh;
+	int err = 0;
+	int is_special = 0;
+#if USE_UBLIO
+	struct ublio_param up;
+	int use_ublio = 0;
+	char *xenv, *xgarbage;
+#endif
 
 	if (NDevOpen(dev)) {
 		errno = EBUSY;
@@ -125,20 +230,28 @@
 		ntfs_log_perror("Failed to access '%s'", dev->d_name);
 		return -1;
 	}
-	if (S_ISBLK(sbuf.st_mode))
-		NDevSetBlock(dev);
+	if (S_ISBLK(sbuf.st_mode) || S_ISCHR(sbuf.st_mode))
+		is_special = 1;
 	
-	dev->d_private = ntfs_malloc(sizeof(int));
-	if (!dev->d_private)
+	ufh = ntfs_malloc(sizeof(*ufh));
+	if (!ufh)
 		return -1;
+	dev->d_private = ufh;
+#if USE_ALIGNED_IO
+	ufh->fd = -1;
+	ufh->pos = 0;
+	ufh->block_size = 0;
+	ufh->media_size = 0;
+#endif
+
 	/*
 	 * Open file for exclusive access if mounting r/w.
 	 * Fuseblk takes care about block devices.
 	 */ 
-	if (!NDevBlock(dev) && (flags & O_RDWR) == O_RDWR)
+	if (!is_special && (flags & O_RDWR) == O_RDWR)
 		flags |= O_EXCL;
-	*(int*)dev->d_private = open(dev->d_name, flags);
-	if (*(int*)dev->d_private == -1) {
+	ufh->fd = open(dev->d_name, flags);
+	if (ufh->fd == -1) {
 		err = errno;
 		goto err_out;
 	}
@@ -146,6 +259,37 @@
 	if ((flags & O_RDWR) != O_RDWR)
 		NDevSetReadOnly(dev);
 	
+#if USE_UBLIO
+	ufh->ublio_fh = NULL;
+	if ((xenv = getenv("NTFS_USE_UBLIO")) &&
+	    (xenv[0] == '0' || xenv[0] == '1') && xenv[1] == '\0')
+		use_ublio = (xenv[0] == '1');
+	else
+		use_ublio = UBLIO_DEFAULT_ENABLE;
+	if ((xenv = getenv("UBLIO_BLOCKSIZE")))
+		up.up_blocksize = strtoul(xenv, &xgarbage, 10);
+	if (!xenv || *xgarbage != '\0')
+		up.up_blocksize = UBLIO_DEFAULT_BLOCKSIZE;
+	if ((xenv = getenv("UBLIO_ITEMS")))
+		up.up_items = strtoul(xenv, &xgarbage, 10);
+	if (!xenv || *xgarbage != '\0')
+		up.up_items = UBLIO_DEFAULT_ITEMS;
+	if ((xenv = getenv("UBLIO_GRACE")))
+		up.up_grace = strtoul(xenv, &xgarbage, 10);
+	if (!xenv || *xgarbage != '\0')
+		up.up_grace = UBLIO_DEFAULT_GRACE;
+	if ((xenv = getenv("UBLIO_SYNC_IO")) &&
+	    (xenv[0] == '0' || xenv[0] == '1') && xenv[1] == '\0')
+		up.up_sync_io = (xenv[0] == '1');
+	else
+		up.up_sync_io = UBLIO_DEFAULT_SYNC_IO;
+	up.up_priv	= &ufh->fd;
+	up.up_pread	= NULL;
+	up.up_preadv	= NULL;
+	up.up_pwrite	= NULL;
+	up.up_pwritev	= NULL;
+#endif
+#if USE_LOCK
 	memset(&flk, 0, sizeof(flk));
 	if (NDevReadOnly(dev))
 		flk.l_type = F_RDLCK;
@@ -153,7 +297,21 @@
 		flk.l_type = F_WRLCK;
 	flk.l_whence = SEEK_SET;
 	flk.l_start = flk.l_len = 0LL;
-	if (fcntl(DEV_FD(dev), F_SETLK, &flk)) {
+#endif
+#if USE_ALIGNED_IO
+	if (raw_io_get_size(dev) < 0) {
+		err = errno;
+		close(DEV_FD(dev));
+		goto err_out;
+	}
+	if (S_ISBLK(sbuf.st_mode) || S_ISCHR(sbuf.st_mode))
+		NDevSetBlock(dev);
+#else
+	if (S_ISBLK(sbuf.st_mode))
+		NDevSetBlock(dev);
+#endif /* USE_ALIGNED_IO */
+#if USE_LOCK
+	if (!NDevBlock(dev) && fcntl(DEV_FD(dev), F_SETLK, &flk)) {
 		err = errno;
 		ntfs_log_perror("Failed to %s lock '%s'", NDevReadOnly(dev) ? 
 				"read" : "write", dev->d_name);
@@ -161,7 +319,16 @@
 			ntfs_log_perror("Failed to close '%s'", dev->d_name);
 		goto err_out;
 	}
-	
+#endif
+#if USE_UBLIO
+	if (use_ublio) {
+		ufh->ublio_fh = ublio_open(&up);
+		if (!ufh->ublio_fh) {
+			close(DEV_FD(dev));
+			goto err_out;
+		}
+	}
+#endif
 	NDevSetOpen(dev);
 	return 0;
 err_out:
@@ -181,7 +348,10 @@
  */
 static int ntfs_device_unix_io_close(struct ntfs_device *dev)
 {
+	/* XXX no error if fysnc, fcntl (ublio_close) fails? */
+#if USE_LOCK
 	struct flock flk;
+#endif
 
 	if (!NDevOpen(dev)) {
 		errno = EBADF;
@@ -194,12 +364,18 @@
 			return -1;
 		}
 
+#if USE_LOCK
 	memset(&flk, 0, sizeof(flk));
 	flk.l_type = F_UNLCK;
 	flk.l_whence = SEEK_SET;
 	flk.l_start = flk.l_len = 0LL;
-	if (fcntl(DEV_FD(dev), F_SETLK, &flk))
+	if (!NDevBlock(dev) && fcntl(DEV_FD(dev), F_SETLK, &flk))
 		ntfs_log_perror("Could not unlock %s", dev->d_name);
+#endif
+#if USE_UBLIO
+	if (DEV_HANDLE(dev)->ublio_fh)
+		ublio_close(DEV_HANDLE(dev)->ublio_fh);
+#endif
 	if (close(DEV_FD(dev))) {
 		ntfs_log_perror("Failed to close device %s", dev->d_name);
 		return -1;
@@ -223,9 +399,234 @@
 static s64 ntfs_device_unix_io_seek(struct ntfs_device *dev, s64 offset,
 		int whence)
 {
+#if USE_ALIGNED_IO
+	s64 abs_pos;
+
+	ntfs_log_trace("seek offset = 0x%llx, whence = %d.\n", offset, whence);
+	switch (whence) {
+	case SEEK_SET:
+		abs_pos = offset;
+		break;
+
+	case SEEK_CUR:
+		abs_pos = DEV_HANDLE(dev)->pos + offset;
+		break;
+
+	case SEEK_END:
+		abs_pos = DEV_HANDLE(dev)->media_size + offset;
+		break;
+
+	default:
+		ntfs_log_trace("Wrong mode %d.\n", whence);
+		errno = EINVAL;
+		return -1;
+	}
+
+	if (abs_pos < 0 || abs_pos > DEV_HANDLE(dev)->media_size) {
+		ntfs_log_trace("Seeking outsize seekable area.\n");
+		errno = EINVAL;
+		return -1;
+	}
+	DEV_HANDLE(dev)->pos = abs_pos;
+	return abs_pos;
+#else
 	return lseek(DEV_FD(dev), offset, whence);
+#endif
 }
 
+#if USE_ALIGNED_IO
+
+#if USE_UBLIO
+#define pread_wrap(fd, buf, count, off)					\
+	(DEV_HANDLE(fd)->ublio_fh ?					\
+	ublio_pread(DEV_HANDLE(fd)->ublio_fh, buf, count, off) :	\
+	pread(DEV_FD(fd), buf, count, off))
+#define pwrite_wrap(fd, buf, count, off)				\
+	(DEV_HANDLE(fd)->ublio_fh ?					\
+	ublio_pwrite(DEV_HANDLE(fd)->ublio_fh, buf, count, off) :	\
+	pwrite(DEV_FD(fd), buf, count, off))
+#else
+#define pread_wrap(fd, buf, count, off)		\
+	pread(DEV_FD(fd), buf, count, off)
+#define pwrite_wrap(fd, buf, count, off)	\
+	pwrite(DEV_FD(fd), buf, count, off)
+#endif
+
+/**
+ * aligned_pread - Perform an aligned positioned read from the device
+ */
+static s64 aligned_pread(struct ntfs_device *dev, void *buf, s64 count, s64 offset)
+{
+	s64 start, start_aligned;
+	s64 end, end_aligned;
+	size_t count_aligned;
+	char *buf_aligned;
+	ssize_t nr;
+
+	/* short-circuit for regular files */
+	start = offset;
+	if (count > RAW_IO_MAX_SIZE)
+		count = RAW_IO_MAX_SIZE;
+	if (RAW_IO_ALIGNED(dev, start, count))
+		return pread_wrap(dev, buf, count, start);
+
+	/*
+	 * +- start_aligned                 +- end_aligned
+	 * |                                |
+	 * |     +- start           +- end  |
+	 * v     v                  v       v
+	 * |----------|----------|----------|
+	 *       ^                  ^
+	 *       +----- count ------+
+	 * ^                                ^
+	 * +-------- count_aligned ---------+
+	 */
+	start_aligned = RAW_IO_ALIGN(dev, start);
+	end = start + count;
+	end_aligned = RAW_IO_ALIGN(dev, end) +
+	    (RAW_IO_ALIGNED(dev, end, 0) ? 0 : DEV_HANDLE(dev)->block_size);
+	count_aligned = end_aligned - start_aligned;
+	ntfs_log_trace(
+	    "%s: count = 0x%llx/0x%x, start = 0x%llx/0x%llx, end = 0x%llx/0x%llx\n",
+	    dev->d_name, count, count_aligned,
+	    start, start_aligned, end, end_aligned);
+
+	/* allocate buffer */
+	buf_aligned = ntfs_malloc(count_aligned);
+	if (buf_aligned == NULL) {
+		ntfs_log_trace("ntfs_malloc(%d) failed\n", count_aligned);
+		return -1;
+	}
+
+	/* read aligned data */
+	nr = pread_wrap(dev, buf_aligned, count_aligned, start_aligned);
+	if (nr == 0)
+		return 0;
+	if (nr < 0 || nr < start - start_aligned) {
+		free(buf_aligned);
+		return -1;
+	}
+
+	/* copy out */
+	memcpy(buf, buf_aligned + (start - start_aligned), count);
+	free(buf_aligned);
+
+	nr -= start - start_aligned;
+	if (nr > count)
+		nr = count;
+	return nr;
+}
+
+/**
+ * aligned_pwrite - Perform an aligned positioned write from the device
+ */
+static s64 aligned_pwrite(struct ntfs_device *dev, void *buf, s64 count, s64 offset)
+{
+	s64 start, start_aligned;
+	s64 end, end_aligned;
+	size_t count_aligned;
+	char *buf_aligned;
+	ssize_t nw;
+
+	if (NDevReadOnly(dev)) {
+		errno = EROFS;
+		return -1;
+	}
+	NDevSetDirty(dev);
+
+	/* short-circuit for regular files */
+	start = offset;
+	if (count > RAW_IO_MAX_SIZE)
+		count = RAW_IO_MAX_SIZE;
+	if (RAW_IO_ALIGNED(dev, start, count))
+		return pwrite_wrap(dev, buf, count, start);
+
+	/*
+	 * +- start_aligned                 +- end_aligned
+	 * |                                |
+	 * |     +- start           +- end  |
+	 * v     v                  v       v
+	 * |----------|----------|----------|
+	 *       ^                  ^
+	 *       +----- count ------+
+	 * ^                                ^
+	 * +-------- count_aligned ---------+
+	 */
+	start_aligned = RAW_IO_ALIGN(dev, start);
+	end = start + count;
+	end_aligned = RAW_IO_ALIGN(dev, end) +
+	    (RAW_IO_ALIGNED(dev, end, 0) ? 0 : DEV_HANDLE(dev)->block_size);
+	count_aligned = end_aligned - start_aligned;
+	ntfs_log_trace(
+	    "%s: count = 0x%llx/0x%x, start = 0x%llx/0x%llx, end = 0x%llx/0x%llx\n",
+	    dev->d_name, count, count_aligned,
+	    start, start_aligned, end, end_aligned);
+
+	/* allocate buffer */
+	buf_aligned = ntfs_malloc(count_aligned);
+	if (buf_aligned == NULL) {
+		ntfs_log_trace("ntfs_malloc(%d) failed\n", count_aligned);
+		return -1;
+	}
+
+	/* read aligned lead-in */
+	if (pread_wrap(dev, buf_aligned, DEV_HANDLE(dev)->block_size, start_aligned) != DEV_HANDLE(dev)->block_size) {
+		ntfs_log_trace("read lead-in failed\n");
+		free(buf_aligned);
+		return -1;
+	}
+
+	/* read aligned lead-out */
+	if (end != end_aligned && count_aligned > DEV_HANDLE(dev)->block_size) {
+		if (pread_wrap(dev, buf_aligned + count_aligned - DEV_HANDLE(dev)->block_size, DEV_HANDLE(dev)->block_size, end_aligned - DEV_HANDLE(dev)->block_size) != DEV_HANDLE(dev)->block_size) {
+			ntfs_log_trace("read lead-out failed\n");
+			free(buf_aligned);
+			return -1;
+		}
+	}
+
+	/* copy data to write */
+	memcpy(buf_aligned + (start - start_aligned), buf, count);
+
+	/* write aligned data */
+	nw = pwrite_wrap(dev, buf_aligned, count_aligned, start_aligned);
+	free(buf_aligned);
+	if (nw < 0 || nw < start - start_aligned)
+		return -1;
+
+	nw -= start - start_aligned;
+	if (nw > count)
+		nw = count;
+	return nw;
+}
+
+/**
+ * aligned_read - Perform an aligned read from the device
+ */
+static s64 aligned_read(struct ntfs_device *dev, void *buf, s64 count)
+{
+	s64 nr = aligned_pread(dev, buf, count, DEV_HANDLE(dev)->pos);
+	if (nr > 0)
+		DEV_HANDLE(dev)->pos += nr;
+	return nr;
+}
+
+/**
+ * aligned_write - Perform an aligned read from the device
+ */
+static s64 aligned_write(struct ntfs_device *dev, void *buf, s64 count)
+{
+	s64 nw = aligned_pwrite(dev, buf, count, DEV_HANDLE(dev)->pos);
+	if (nw > 0)
+		DEV_HANDLE(dev)->pos += nw;
+	return nw;
+}
+
+#undef ublio_pwrite
+#undef ublio_pread
+
+#endif
+
 /**
  * ntfs_device_unix_io_read - Read from the device, from the current location
  * @dev:
@@ -239,6 +640,29 @@
 static s64 ntfs_device_unix_io_read(struct ntfs_device *dev, void *buf,
 		s64 count)
 {
+#if USE_ALIGNED_IO
+	return aligned_read(dev, buf, count);
+#elif USE_UBLIO
+	if (DEV_HANDLE(dev)->ublio_fh) {
+		off_t offset;
+		ssize_t res;
+
+		offset = lseek(DEV_FD(dev), 0, SEEK_CUR);
+		if (offset == -1)
+			return -1;
+
+		res = ublio_pread(DEV_HANDLE(dev)->ublio_fh, buf, count,
+		    offset);
+		if (res == -1)
+			return -1;
+
+		if (lseek(DEV_FD(dev), res, SEEK_CUR) == -1)
+			return -1;
+
+		return res;
+	}
+#endif
+
 	return read(DEV_FD(dev), buf, count);
 }
 
@@ -260,6 +684,28 @@
 		return -1;
 	}
 	NDevSetDirty(dev);
+#if USE_ALIGNED_IO
+	return aligned_write(dev, buf, count);
+#elif USE_UBLIO
+	if (DEV_HANDLE(dev)->ublio_fh)
+		off_t offset;
+		ssize_t res;
+
+		offset = lseek(DEV_FD(dev), 0, SEEK_CUR);
+		if (offset == -1)
+			return -1;
+
+		res = ublio_pwrite(DEV_HANDLE(dev)->ublio_fh, (void *)buf,
+		    count, offset);
+		if (res == -1)
+			return -1;
+
+		if (lseek(DEV_FD(dev), res, SEEK_CUR) == -1)
+			return -1;
+
+		return res;
+	}
+#endif
 	return write(DEV_FD(dev), buf, count);
 }
 
@@ -277,6 +723,13 @@
 static s64 ntfs_device_unix_io_pread(struct ntfs_device *dev, void *buf,
 		s64 count, s64 offset)
 {
+#if USE_ALIGNED_IO
+	return aligned_pread(dev, buf, count, offset);
+#elif USE_UBLIO
+	if (DEV_HANDLE(dev)->ublio_fh)
+		return ublio_pread(DEV_HANDLE(dev)->ublio_fh, buf, count,
+		    offset);
+#endif
 	return pread(DEV_FD(dev), buf, count, offset);
 }
 
@@ -299,6 +752,13 @@
 		return -1;
 	}
 	NDevSetDirty(dev);
+#if USE_ALIGNED_IO
+	return aligned_pwrite(dev, buf, count, offset);
+#elif USE_UBLIO
+	if (DEV_HANDLE(dev)->ublio_fh)
+		return ublio_pwrite(DEV_HANDLE(dev)->ublio_fh, (void *)buf,
+		    count, offset);
+#endif
 	return pwrite(DEV_FD(dev), buf, count, offset);
 }
 
@@ -315,7 +775,14 @@
 	int res = 0;
 	
 	if (!NDevReadOnly(dev)) {
+#if USE_UBLIO
+		if (DEV_HANDLE(dev)->ublio_fh)
+			res = ublio_fsync(DEV_HANDLE(dev)->ublio_fh);
+		if (!DEV_HANDLE(dev)->ublio_fh || !res)
+			res = ntfs_fsync(DEV_FD(dev));
+#else
 		res = ntfs_fsync(DEV_FD(dev));
+#endif
 		if (res)
 			ntfs_log_perror("Failed to sync device %s", dev->d_name);
 		else
OpenPOWER on IntegriCloud