Linux Dirent 结构的成员

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12991334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:39:16  来源:igfitidea点击:

Members of Dirent structure

clinuxdirreaddirdirent.h

提问by Naruto

I have started working with dirent.h library and I came across a very useful member of "struct dirent" structer which struct dirent *p->d_name in my book. But unfortunatly it doesn't states any other members of this structure;

我已经开始使用 dirent.h 库,并且在我的书中遇到了“struct dirent”构造器的一个非常有用的成员,它 struct dirent *p->d_name。但不幸的是,它没有说明该结构的任何其他成员;

I was wondering what else are the members of this structure and what are they used for?

我想知道这个结构的其他成员还有什么用途?

Regards

问候

采纳答案by askmish

The structure, struct direntrefers to directory entry.

结构,struct dirent指目录项。

http://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html

http://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html

In linux it is defined as:

在linux中定义为:

struct dirent {
    ino_t          d_ino;       /* inode number */
    off_t          d_off;       /* offset to the next dirent */
    unsigned short d_reclen;    /* length of this record */
    unsigned char  d_type;      /* type of file; not supported
                                   by all file system types */
    char           d_name[256]; /* filename */
};

refer: man readdir

参考: man readdir

Or just look for "dirent.h" in the include directory.

或者只是在包含目录中查找“dirent.h”。

回答by MByD

There are only two members (from wikipedia):

只有两个成员(来自维基百科):

  • ino_t d_ino- file serial number
  • char d_name[]- name of entry (will not exceed a size of NAME_MAX)
  • ino_t d_ino- 文件序列号
  • char d_name[]- 条目名称(不会超过 NAME_MAX 的大小)

Take a look at the unix specas well.

也看看unix 规范

回答by Ravindra Bagale

in addition to above answer of @Binyamin Sharet:

除了@Binyamin Sharet的上述答案:

 off_t d_off - file offset
    unsigned short int d_reclen - length of the dirent record
    unsigned short int d_namlen - length of name
    unsigned int d_type - type of file