Linux学习笔记之---文件

来源:互联网 发布:思派网络 ceo 马旭广 编辑:程序博客网 时间:2024/05/16 00:36
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;
            };
0 0
原创粉丝点击