chmod
#include <sys/stat.h>
int chmod (const char* filename, int mode);
filename是文件名
mode文件权限,八进制数
返回值:成功 返回0,失败返回-1。
chown
#include <unistd.h>
int chown(const char *path, uid_t owner, gid_t group);
path是文件路径
owner是用户ID,无符号整型。可以通过/etc/passwd访问用户ID
group是组ID, 无符号整型。可以通过/etc/group访问组ID
返回值:成功返回0,失败返回-1
truncate
#include <unistd.h>
#include <types.h>
int truncate(const char *path, off_t length);
path是文件名,length是文件的最终大小,off_t 是long int。
如果length比之前大,则扩展,反之则截断。
umask
#include <sys/stat.h>
mode_t umask(mode_t cmask);
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001
stat
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int stat(const char *path, struct stat *buf);
int fstat(int fd, struct stat *buf);
int lstat(const char *path, struct stat *buf);
struct stat {
unsigned long st_dev; /* Device. */
unsigned long st_ino; /* File serial number. */
unsigned int st_mode; /* File mode. */
unsigned int st_nlink; /* Link count. */
unsigned int st_uid; /* User ID of the file's owner. */
unsigned int st_gid; /* Group ID of the file's group. */
unsigned long st_rdev; /* Device number, if device. */
unsigned long __pad1;
long st_size; /* Size of file, in bytes. */
int st_blksize; /* Optimal block size for I/O. */
int __pad2;
long st_blocks; /* Number 512-byte blocks allocated. */
int st_atime; /* Time of last access. */
unsigned int st_atime_nsec;
int st_mtime; /* Time of last modification. */
unsigned int st_mtime_nsec;
int st_ctime; /* Time of last status change. */
unsigned int st_ctime_nsec;
unsigned int __unused4;
unsigned int __unused5;
}
stat主要用于获取文件的inode信息。
fstat用于获取已在描述符上打开的文件的有关信息。
lstat类似于stat,但是当命名的文件是一个符号链接时,lstat返回该符号链接的有关信息,而不是由该符号链接引用的文件信息。