1:sccess函數,用來判斷是否具有存取文件的權限
#include <unistd.h>
int access(const char *pathname,int mode)
access函數用於檢測是否可以讀,寫某一個文件或者測試某個文件是否存在,如果測試的文件是一個符號連接,access函數將測試這個符號連接引用的文件
mode有這集中組合:R_OK,W_OK,X_OK,F_OK
如果要查覈的權限都通過了檢查,則返回0,表示成功,只要有一個權限被進制則返回-1
2:chown函數和fchown函數:該變文件的所有者
#include <sys/types.h>
#include <unistd.h>
int chown(const char *path,uid_t owner,gid_t group)
int fchown(int fd,uid_t owner,gid_t group)
chaown和gchown函數用於修改文件的所有者和組,他們分別使用參數owner和group來指定,如果參數owner或group爲-1,則表示對應的所有者或是組不會有所改變root與文件所有者皆可改變文件組,但所有者必須是參數group組的成員,chown函數指定的使用參數path作爲文件的路徑,fchown函數使用參數fd指定文件文件描述符
當使用root權限來改變所有者或組時,如果該文件具有S_ISUID,S_ISGID權限,則會清除此權限,如果具有S_ISDID但是不具有 S_IXGRP權限,則該文件會被強制鎖定,文件模式會保留
陳功就返回零,或者就是-1————————————————————————uid——他代表新用戶的編號,gid代表組用戶的組編號
3:chmod函數和fchmod函數,改變.權限
#include <sys/types.h>
#inlcude <sys/stat.h>
int chmod(const char *path,mode_t mode)
int fchmod(int fildes,mode_t mode)
chmod和fchmod函數用於將文件的讀寫執行等權限改爲參數mode表示的值,chmod表示文件的參數使用的文件路徑path,fchmod表示文件的蠶食使用文件描述符
執行成功返回零,不成功就返回-1
4:unlink函數,刪除文件
#include <unistd,h>
int unlink(const char *pathname)
unlink函數用於刪除參數pathname指定的文件,如果該文件名爲最後連接點,但是其他進程打開了此文件,則在所有關於此文件描述符關閉後纔會刪除文件,如果參數pathname爲一副好連接,則此鏈接會被刪除
執行成功返回零,不成功就返回
5:utime和utimes函數:改變文件時間
#include <sys/types,h>
#inlcude <utime.h>
int utime)const char *filename ,strct utimbuf *buf)
struct utimbuf{
time_t actime;
time_t modtime
};
utime用來修改參數filename文件所屬的inode存取時間,如果buf爲NULL,則將文件的訪問和修改時間設置爲當前的時間
執行成功返回0,失敗返回-1
#include <sys/time.h>
int utimes (char *filename,struct timeval *tvp)
struct timeval{
long tv_sec;
long tv_usec;
}
函數返回值,如果參數buf爲null,則該文件的存取時間和更改時間全部會設爲目前時間,執行成功返回0,不成功返回-1
6:umask 函數,設置建立新文件時的權限掩碼
#include <sys/types.h>
#inlcude <sys/stat,h>
mode_t umask(mode_t mask)
umask會將系統umask值設置爲參數mask與0777與運算後的值,然後將先前的umask值返回,在使用open建立新文件時,新建立文件真正的權限並非起參數mode的值,而是相見算後的值,例如,在建立文件是指定文件權限爲0666,通常umask值默認爲022,則該文件的正直權限則是0666&~022 = 0644
7:link函數:建立文件連接
#include <unistd.h>
int link (const char * oldpath,const char * newpath)
link函數以參數newpath指定名稱,來建立到參數oldpath所指定的已存在文件一個新的連接,如果參數newpath指定的名稱爲一個已經在的文件,則不會建立連接,link函數所建立的硬連接不能跨越不突破那個文件系統
8:stat函數,fstat函數,lstat函數,獲取文件信息
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int stat(const char *path,struct stat *buf)
int fstat (int filedes,strct stat *buf)
int lstat(const char *path,sruct stat *buf)
struct stat{
dev_t st_dev;//文件所在設備標誌
ino_t st _ino;文件節點號
mode_t st_mode; 文件保護模式
nlink_t st_nlink硬連接個數
uid_t st_uid;文件用戶標誌
gid_t st_gid;文件用戶組標誌
dev_t st_rdev;文件所表示的特殊設備文件的設備標誌
off_t st_size;總大小以字節爲但爲
blksize_t st_blksize文件系統的快大小
blkcnt_t st_blocks分配給文件的快的數量,以512字節單元
time_t st_atime 最後訪問時間
time_t st_mtime最後修改時間
time_t st_ctime;最後狀態改變時間
}