fallocate

fallocate的功能是為檔案預分配物理空間。

基本介紹

  • 中文名:fallocate
  • 功能:為檔案預分配物理空間
  • 頭檔案:#include <fcntl.h>
  • 返回值:成功返回0,失敗返回-1
函式參數,相關函式,函式功能,程式實例,相關版本,

函式參數

int fallocate(int fd, int mode, off_t offset, off_t len);

相關函式

posix_fadvise, posix_fallocate

函式功能

為檔案預分配物理空間。
頭檔案
#include <fcntl.h>
返回值
成功返回0,失敗返回-1。

程式實例

#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
int main(){
int fd1,ret;
int file_size=20971520; //20M
fd1=open("/tmp/1",O_CREAT | O_RDWR,0777);
ret = fallocate(fd1, 0, 0, file_size);
close(fd1);
return ret;
}
編譯:
gcc fallocate_test.c -o fallocate_test
運行:
./fallocate_test
查看:
ll -h 1
-rwxr-xr-x. 1 root root 20M Aug 10 13:28 1

相關版本

linux核心 2.6.23及其以上 && glibc2.10及其以上。

相關詞條

熱門詞條

聯絡我們