您的位置:首页 > 运维架构 > Linux

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;

            };
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: