Linux学习笔记之---文件
2015-03-10 19:39
204 查看
1:文件系统结构
1.1: 获取文件属性函数:
#include <sys/types.h>
#include <sys/stat.h>
int stat (const char *path, struct stat *buf);
int fstat (int fildes, struct stat *buf);
int lstat (const char *path, struct stat *buf);
成功返回0,否则返回-1;其中stat结构体如下:
struct stat
{
'''''''''''''''''
dev_t st_dev; /*文件常驻设备ID*/
ino_t st_ino; /*i节点编号*/
mode_t st_mode; /*文件类型与权限*/
nlink_t st_nlink; /*文件连接数*/
uid_t st_uid; /*文件属主ID*/
gid_t st_gid; /*文件属组ID*/
dev_t st_rdev; /*特别文件设备号*/
off_t st_size; /*文件长度*/
time_t st_atime; /*文件最近访问时间*/
time_t st_mtime; /*文件最近修改时间*/
time_t st_ctime; /*文件状态最近改变时间*/
'''''''''''''''''
};
1.2: 文件类型:
参数 判断宏 UNIX标识
普通文件 S_ISREG(_M) -
块文件 S_ISBLK(_M) b
字符文件 S_ISCHR(_M) c
目录文件 S_ISDIR(_M) d
管道或FIFO S_ISFIFO(_M) p
符号链接 S_ISLNK(_M) l
套接字文件 S_ISSOCK(_M)
举例说明:if (S_ISREG(st_mode)) 是普通文件;······
1.3: 文件权限
S_IRWXU 属主读写执行
S_IRUSR 属主读
S_IWUSR 属主写
S_IXUSR 属主执行
S_IRWXG 属组读写执行
S_IRGRP 属组读
S_IWGRP 属组写
S_IXGRP 属组执行
S_IRWXO 其他用户读写执行
S_IROTH 其他用户读
S_IWOTH 其他用户写
S_IXOTH 其他用户执行
举例:if (st_mode & S_IXUSR)属主执行权限
1.4: i节点区(inode区)
struct dinode
{
ushort di_mode;
short di_nlink;
ushort di_uid;
ushort di_gid;
off_t di_size;
char di_addr[NADDR_BYTES];
char di_gen;
time_t di_atime;
time_t di_mtime;
time_t di_ctime;
};
1.1: 获取文件属性函数:
#include <sys/types.h>
#include <sys/stat.h>
int stat (const char *path, struct stat *buf);
int fstat (int fildes, struct stat *buf);
int lstat (const char *path, struct stat *buf);
成功返回0,否则返回-1;其中stat结构体如下:
struct stat
{
'''''''''''''''''
dev_t st_dev; /*文件常驻设备ID*/
ino_t st_ino; /*i节点编号*/
mode_t st_mode; /*文件类型与权限*/
nlink_t st_nlink; /*文件连接数*/
uid_t st_uid; /*文件属主ID*/
gid_t st_gid; /*文件属组ID*/
dev_t st_rdev; /*特别文件设备号*/
off_t st_size; /*文件长度*/
time_t st_atime; /*文件最近访问时间*/
time_t st_mtime; /*文件最近修改时间*/
time_t st_ctime; /*文件状态最近改变时间*/
'''''''''''''''''
};
1.2: 文件类型:
参数 判断宏 UNIX标识
普通文件 S_ISREG(_M) -
块文件 S_ISBLK(_M) b
字符文件 S_ISCHR(_M) c
目录文件 S_ISDIR(_M) d
管道或FIFO S_ISFIFO(_M) p
符号链接 S_ISLNK(_M) l
套接字文件 S_ISSOCK(_M)
举例说明:if (S_ISREG(st_mode)) 是普通文件;······
1.3: 文件权限
S_IRWXU 属主读写执行
S_IRUSR 属主读
S_IWUSR 属主写
S_IXUSR 属主执行
S_IRWXG 属组读写执行
S_IRGRP 属组读
S_IWGRP 属组写
S_IXGRP 属组执行
S_IRWXO 其他用户读写执行
S_IROTH 其他用户读
S_IWOTH 其他用户写
S_IXOTH 其他用户执行
举例:if (st_mode & S_IXUSR)属主执行权限
1.4: i节点区(inode区)
struct dinode
{
ushort di_mode;
short di_nlink;
ushort di_uid;
ushort di_gid;
off_t di_size;
char di_addr[NADDR_BYTES];
char di_gen;
time_t di_atime;
time_t di_mtime;
time_t di_ctime;
};
相关文章推荐
- Linux 文件管理学习笔记(5-27)
- Linux学习笔记--ln连接文件
- linux & C++Primer 学习笔记--fstream 非常好用的文件操作流
- LINUX学习笔记2——文件编程
- 【学习笔记】Linux平台的文件,目录及操作
- Linux学习笔记8--文件的所有权和访问权
- linux学习笔记-读《Linux编程技术详解》(4-2)-文件和目录
- 【学习笔记】Linux平台的文件I/O操作
- linux学习笔记-读《Linux编程技术详解》(6-1)-设备文件
- linux学习笔记之(二)---文件与文件夹操作
- Linux学习笔记之目录和文件权限
- Linux程序设计-学习笔记-第三章文件操作
- Makefile学习笔记1:Linux平台Makefile文件的编写基础篇(zz)
- 【学习笔记】Linux平台的文件,目录及操作
- linux学习笔记(一 文件权限控制)
- 查看文件命令cat,more,less,tail,tac,nl,od---linux学习笔记
- linux系统管理学习笔记之六---linux文件系统
- linux系统管理学习笔记之八---linux文件与目录的管理及权限
- 我的Linux学习笔记1(文件操作常用命令)
- 【学习笔记】Linux平台的文件I/O操作