@@ -5,13 +5,15 @@ use std::ffi::OsString;
5
5
use std:: os:: raw;
6
6
use std:: os:: unix:: ffi:: OsStringExt ;
7
7
use std:: os:: unix:: io:: RawFd ;
8
- use crate :: sys:: stat:: Mode ;
9
- use crate :: { NixPath , Result } ;
10
8
11
9
#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
12
10
use std:: ptr; // For splice and copy_file_range
13
- #[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
14
- use crate :: sys:: uio:: IoVec ; // For vmsplice
11
+ #[ cfg( feature = "fs" ) ]
12
+ use crate :: {
13
+ NixPath ,
14
+ Result ,
15
+ sys:: stat:: Mode
16
+ } ;
15
17
16
18
#[ cfg( any(
17
19
target_os = "linux" ,
@@ -22,10 +24,13 @@ use crate::sys::uio::IoVec; // For vmsplice
22
24
target_env = "uclibc" ,
23
25
target_os = "freebsd"
24
26
) ) ]
25
- pub use self :: posix_fadvise:: * ;
27
+ #[ cfg( feature = "fs" ) ]
28
+ pub use self :: posix_fadvise:: { PosixFadviseAdvice , posix_fadvise} ;
26
29
27
30
#[ cfg( not( target_os = "redox" ) ) ]
31
+ #[ cfg( any( feature = "fs" , feature = "process" ) ) ]
28
32
libc_bitflags ! {
33
+ #[ cfg_attr( docsrs, doc( cfg( any( feature = "fs" , feature = "process" ) ) ) ) ]
29
34
pub struct AtFlags : c_int {
30
35
AT_REMOVEDIR ;
31
36
AT_SYMLINK_FOLLOW ;
@@ -39,8 +44,10 @@ libc_bitflags! {
39
44
}
40
45
}
41
46
47
+ #[ cfg( any( feature = "fs" , feature = "term" ) ) ]
42
48
libc_bitflags ! (
43
49
/// Configuration options for opened files.
50
+ #[ cfg_attr( docsrs, doc( cfg( any( feature = "fs" , feature = "term" ) ) ) ) ]
44
51
pub struct OFlag : c_int {
45
52
/// Mask for the access mode of the file.
46
53
O_ACCMODE ;
@@ -165,6 +172,9 @@ libc_bitflags!(
165
172
}
166
173
) ;
167
174
175
+ feature ! {
176
+ #![ feature = "fs" ]
177
+
168
178
// The conversion is not identical on all operating systems.
169
179
#[ allow( clippy:: useless_conversion) ]
170
180
pub fn open<P : ?Sized + NixPath >( path: & P , oflag: OFlag , mode: Mode ) -> Result <RawFd > {
@@ -209,19 +219,24 @@ pub fn renameat<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(
209
219
} ) ??;
210
220
Errno :: result( res) . map( drop)
211
221
}
222
+ }
212
223
213
224
#[ cfg( all(
214
225
target_os = "linux" ,
215
226
target_env = "gnu" ,
216
227
) ) ]
228
+ #[ cfg( feature = "fs" ) ]
217
229
libc_bitflags ! {
230
+ #[ cfg_attr( docsrs, doc( cfg( feature = "fs" ) ) ) ]
218
231
pub struct RenameFlags : u32 {
219
232
RENAME_EXCHANGE ;
220
233
RENAME_NOREPLACE ;
221
234
RENAME_WHITEOUT ;
222
235
}
223
236
}
224
237
238
+ feature ! {
239
+ #![ feature = "fs" ]
225
240
#[ cfg( all(
226
241
target_os = "linux" ,
227
242
target_env = "gnu" ,
@@ -348,6 +363,7 @@ pub(crate) fn at_rawfd(fd: Option<RawFd>) -> raw::c_int {
348
363
Some ( fd) => fd,
349
364
}
350
365
}
366
+ }
351
367
352
368
#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
353
369
libc_bitflags ! (
@@ -364,14 +380,19 @@ libc_bitflags!(
364
380
}
365
381
) ;
366
382
383
+ #[ cfg( feature = "fs" ) ]
367
384
libc_bitflags ! (
368
385
/// Additional configuration flags for `fcntl`'s `F_SETFD`.
386
+ #[ cfg_attr( docsrs, doc( cfg( feature = "fs" ) ) ) ]
369
387
pub struct FdFlag : c_int {
370
388
/// The file descriptor will automatically be closed during a successful `execve(2)`.
371
389
FD_CLOEXEC ;
372
390
}
373
391
) ;
374
392
393
+ feature ! {
394
+ #![ feature = "fs" ]
395
+
375
396
#[ cfg( not( target_os = "redox" ) ) ]
376
397
#[ derive( Debug , Eq , Hash , PartialEq ) ]
377
398
#[ non_exhaustive]
@@ -455,6 +476,7 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
455
476
Errno :: result( res)
456
477
}
457
478
479
+ // TODO: convert to libc_enum
458
480
#[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
459
481
#[ non_exhaustive]
460
482
pub enum FlockArg {
@@ -483,10 +505,13 @@ pub fn flock(fd: RawFd, arg: FlockArg) -> Result<()> {
483
505
484
506
Errno :: result( res) . map( drop)
485
507
}
508
+ }
486
509
487
510
#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
511
+ #[ cfg( feature = "zerocopy" ) ]
488
512
libc_bitflags ! {
489
513
/// Additional flags to `splice` and friends.
514
+ #[ cfg_attr( docsrs, doc( cfg( feature = "zerocopy" ) ) ) ]
490
515
pub struct SpliceFFlags : c_uint {
491
516
/// Request that pages be moved instead of copied.
492
517
///
@@ -505,6 +530,9 @@ libc_bitflags! {
505
530
}
506
531
}
507
532
533
+ feature ! {
534
+ #![ feature = "zerocopy" ]
535
+
508
536
/// Copy a range of data from one file to another
509
537
///
510
538
/// The `copy_file_range` system call performs an in-kernel copy between
@@ -577,7 +605,12 @@ pub fn tee(fd_in: RawFd, fd_out: RawFd, len: usize, flags: SpliceFFlags) -> Resu
577
605
}
578
606
579
607
#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
580
- pub fn vmsplice ( fd : RawFd , iov : & [ IoVec < & [ u8 ] > ] , flags : SpliceFFlags ) -> Result < usize > {
608
+ pub fn vmsplice(
609
+ fd: RawFd ,
610
+ iov: & [ crate :: sys:: uio:: IoVec <& [ u8 ] >] ,
611
+ flags: SpliceFFlags
612
+ ) -> Result <usize >
613
+ {
581
614
let ret = unsafe {
582
615
libc:: vmsplice(
583
616
fd,
@@ -588,10 +621,13 @@ pub fn vmsplice(fd: RawFd, iov: &[IoVec<&[u8]>], flags: SpliceFFlags) -> Result<
588
621
} ;
589
622
Errno :: result( ret) . map( |r| r as usize )
590
623
}
624
+ }
591
625
592
626
#[ cfg( any( target_os = "linux" ) ) ]
627
+ #[ cfg( feature = "fs" ) ]
593
628
libc_bitflags ! (
594
629
/// Mode argument flags for fallocate determining operation performed on a given range.
630
+ #[ cfg_attr( docsrs, doc( cfg( feature = "fs" ) ) ) ]
595
631
pub struct FallocateFlags : c_int {
596
632
/// File size is not changed.
597
633
///
@@ -620,11 +656,15 @@ libc_bitflags!(
620
656
}
621
657
) ;
622
658
659
+ feature ! {
660
+ #![ feature = "fs" ]
661
+
623
662
/// Manipulates file space.
624
663
///
625
664
/// Allows the caller to directly manipulate the allocated disk space for the
626
665
/// file referred to by fd.
627
666
#[ cfg( any( target_os = "linux" ) ) ]
667
+ #[ cfg( feature = "fs" ) ]
628
668
pub fn fallocate(
629
669
fd: RawFd ,
630
670
mode: FallocateFlags ,
@@ -635,6 +675,7 @@ pub fn fallocate(
635
675
Errno :: result( res) . map( drop)
636
676
}
637
677
678
+
638
679
#[ cfg( any(
639
680
target_os = "linux" ,
640
681
target_os = "android" ,
@@ -649,9 +690,11 @@ mod posix_fadvise {
649
690
use std:: os:: unix:: io:: RawFd ;
650
691
use crate :: Result ;
651
692
693
+ #[ cfg( feature = "fs" ) ]
652
694
libc_enum! {
653
695
#[ repr( i32 ) ]
654
696
#[ non_exhaustive]
697
+ #[ cfg_attr( docsrs, doc( cfg( feature = "fs" ) ) ) ]
655
698
pub enum PosixFadviseAdvice {
656
699
POSIX_FADV_NORMAL ,
657
700
POSIX_FADV_SEQUENTIAL ,
@@ -662,6 +705,8 @@ mod posix_fadvise {
662
705
}
663
706
}
664
707
708
+ feature!{
709
+ #![ feature = "fs" ]
665
710
pub fn posix_fadvise(
666
711
fd: RawFd ,
667
712
offset: libc:: off_t,
@@ -676,6 +721,7 @@ mod posix_fadvise {
676
721
Err ( Errno :: from_i32( res) )
677
722
}
678
723
}
724
+ }
679
725
}
680
726
681
727
#[ cfg( any(
@@ -694,3 +740,4 @@ pub fn posix_fallocate(fd: RawFd, offset: libc::off_t, len: libc::off_t) -> Resu
694
740
Ok ( errno) => Err ( Errno :: from_i32( errno) ) ,
695
741
}
696
742
}
743
+ }
0 commit comments