@@ -341,3 +341,43 @@ pub fn vmsplice(fd: RawFd, iov: &[IoVec<&[u8]>], flags: SpliceFFlags) -> Result<
341
341
Errno :: result ( ret) . map ( |r| r as usize )
342
342
}
343
343
344
+ #[ cfg( any( target_os = "linux" ) ) ]
345
+ libc_bitflags ! (
346
+ /// Mode argument flags for fallocate determining operation performed on a given range.
347
+ pub struct FallocateFlags : libc:: c_int {
348
+ /// File size is not changed.
349
+ ///
350
+ /// offset + len can be greater than file size.
351
+ FALLOC_FL_KEEP_SIZE ;
352
+ /// Deallocates space by creating a hole.
353
+ ///
354
+ /// Must be ORed with FALLOC_FL_KEEP_SIZE. Byte range starts at offset and continues for len bytes.
355
+ FALLOC_FL_PUNCH_HOLE ;
356
+ /// Removes byte range from a file without leaving a hole.
357
+ ///
358
+ /// Byte range to collapse starts at offset and continues for len bytes.
359
+ FALLOC_FL_COLLAPSE_RANGE ;
360
+ /// Zeroes space in specified byte range.
361
+ ///
362
+ /// Byte range starts at offset and continues for len bytes.
363
+ FALLOC_FL_ZERO_RANGE ;
364
+ /// Increases file space by inserting a hole within the file size.
365
+ ///
366
+ /// Does not overwrite existing data. Hole starts at offset and continues for len bytes.
367
+ FALLOC_FL_INSERT_RANGE ;
368
+ /// Shared file data extants are made private to the file.
369
+ ///
370
+ /// Gaurantees that a subsequent write will not fail due to lack of space.
371
+ FALLOC_FL_UNSHARE_RANGE ;
372
+ }
373
+ ) ;
374
+
375
+ /// Manipulates file space.
376
+ ///
377
+ /// Allows the caller to directly manipulate the allocated disk space for the
378
+ /// file referred to by fd.
379
+ #[ cfg( any( target_os = "linux" ) ) ]
380
+ pub fn fallocate ( fd : RawFd , mode : FallocateFlags , offset : libc:: off_t , len : libc:: off_t ) -> Result < c_int > {
381
+ let res = unsafe { libc:: fallocate ( fd, mode. bits ( ) , offset, len) } ;
382
+ Errno :: result ( res)
383
+ }
0 commit comments