檔案系統 stat函式

2021-07-23 12:17:13 字數 2034 閱讀 2353

stat函式主要用於獲取檔案的inode資訊。

stat命令其實就是呼叫的stat函式。

1)chmod 777 stat_1.txtstat之後發現ctime變了。改變了檔案的許可權,檔案許可權儲存在inode裡面。

2)vim stat_1.txt什麼都不做,看一下退出。stat後發現atime變了。

3)echo "123456" >>stat_1.txt追加到stat_1.txt後發現mtime,ctime變了。檔案內容變了mtime改變,檔案大小變了ctime改變,檔案大小儲存在inode裡面。

#include 

#include

#include

int stat(const

char *path, struct stat *buf);

int fstat(int fd, struct stat *buf);

int lstat(const

char *path, struct stat *buf);

fstat函式獲得已在描述符上開啟的檔案的有關資訊。

lstat函式類似於stat,但是當命名的檔案是乙個符號連線時, lstat返回該符號連線的有關資訊,而不是由該符號連線引用的檔案的資訊。

函式說明: 通過path獲取檔案資訊,並儲存在buf所指的結構體stat中。

返回值: 執行成功則返回0,失敗返回-1,錯誤**存於errno。

stat結構體:

dev_t st_dev; /* 檔案的裝置編號 */

ino_t st_ino; /* inode number */

mode_t st_mode; /* 檔案的型別和訪問許可權 */

nlink_t st_nlink; /* number

of hard links */

uid_t st_uid; /* user id of owner */

gid_t st_gid; /* group id of owner */

dev_t st_rdev; /* device id (if special file) */

off_t st_size; /* 檔案位元組數 */

blksize_t st_blksize; /* blocksize for filesystem i/o */

blkcnt_t st_blocks; /* number

of512b blocks allocated */

time_t st_atime; /* time

oflast access */

time_t st_mtime; /* time

oflast modification */

time_t st_ctime; /* time

oflast status change */

};1)輸出檔案的大小。

Linux 檔案系統之stat函式

1 stat主要函式 include include include int stat const char path,struct stat buf 在linux中,可以利用stat 函式來獲取乙個檔案的狀態 這個函式執行成功返回0,失敗返回 1 取得的檔案狀態存放在buf指標指向的struct ...

LINUX檔案系統中的stat結構

stat結構的成員在不同的unix中會有所變化.但一般都包含以下所示的內容 st mode 檔案許可權和檔案型別資訊。st ino 與該檔案關聯的inode st dev 儲存檔案的裝置 st uid 檔案屬主的uid號 st gid 檔案屬主的gid號 st atime 檔案上次被訪問的時間 st...

PHP file 檔案系統函式

file 把整個檔案讀入乙個陣列中 php4 php5 php7 支援支援 支援5.0.0 增加了引數 context5.0.0 在php 5.0.0之前,flags引數僅包含include path並已啟用14.3.0 file 開始是二進位制安全的file string filename int...