36
36
37
37
extern crate libc;
38
38
39
+ #[ cfg( feature = "direct_io" ) ]
40
+ use bindings:: LOOP_SET_DIRECT_IO ;
39
41
use bindings:: {
40
- loop_info64, LOOP_CLR_FD , LOOP_CTL_GET_FREE , LOOP_SET_CAPACITY , LOOP_SET_DIRECT_IO ,
41
- LOOP_SET_FD , LOOP_SET_STATUS64 , LO_FLAGS_AUTOCLEAR , LO_FLAGS_READ_ONLY ,
42
+ loop_info64, LOOP_CLR_FD , LOOP_CTL_GET_FREE , LOOP_SET_CAPACITY , LOOP_SET_FD , LOOP_SET_STATUS64 ,
43
+ LO_FLAGS_AUTOCLEAR , LO_FLAGS_READ_ONLY ,
42
44
} ;
43
45
use libc:: { c_int, ioctl} ;
44
46
use std:: {
@@ -160,6 +162,7 @@ impl LoopDevice {
160
162
AttachOptions {
161
163
device : self ,
162
164
info : Default :: default ( ) ,
165
+ #[ cfg( feature = "direct_io" ) ]
163
166
direct_io : false ,
164
167
}
165
168
}
@@ -343,6 +346,7 @@ impl LoopDevice {
343
346
}
344
347
345
348
// Enable or disable direct I/O for the backing file.
349
+ #[ cfg( feature = "direct_io" ) ]
346
350
pub fn set_direct_io ( & self , direct_io : bool ) -> io:: Result < ( ) > {
347
351
ioctl_to_error ( unsafe {
348
352
ioctl (
@@ -386,6 +390,7 @@ impl LoopDevice {
386
390
pub struct AttachOptions < ' d > {
387
391
device : & ' d LoopDevice ,
388
392
info : loop_info64 ,
393
+ #[ cfg( feature = "direct_io" ) ]
389
394
direct_io : bool ,
390
395
}
391
396
@@ -423,6 +428,7 @@ impl AttachOptions<'_> {
423
428
}
424
429
425
430
// Enable or disable direct I/O for the backing file.
431
+ #[ cfg( feature = "direct_io" ) ]
426
432
pub fn set_direct_io ( mut self , direct_io : bool ) -> Self {
427
433
self . direct_io = direct_io;
428
434
self
@@ -442,6 +448,7 @@ impl AttachOptions<'_> {
442
448
/// Attach the loop device to a file with the set options.
443
449
pub fn attach ( self , backing_file : impl AsRef < Path > ) -> io:: Result < ( ) > {
444
450
self . device . attach_with_loop_info ( backing_file, self . info ) ?;
451
+ #[ cfg( feature = "direct_io" ) ]
445
452
if self . direct_io {
446
453
self . device . set_direct_io ( self . direct_io ) ?;
447
454
}
@@ -452,6 +459,7 @@ impl AttachOptions<'_> {
452
459
pub fn attach_fd ( self , backing_file_fd : impl AsRawFd ) -> io:: Result < ( ) > {
453
460
self . device
454
461
. attach_fd_with_loop_info ( backing_file_fd, self . info ) ?;
462
+ #[ cfg( feature = "direct_io" ) ]
455
463
if self . direct_io {
456
464
self . device . set_direct_io ( self . direct_io ) ?;
457
465
}
0 commit comments