【问题标题】:os.pathconf() keys and their meaningos.pathconf() 键及其含义
【发布时间】:2016-04-12 04:45:03
【问题描述】:

documentation for os.pathconf()(或Python 2 相同)只是模糊地暗示了一组键,其含义在其他各个地方都指定了;

返回与命名文件相关的系统配置信息。 name 指定要检索的配置值;它可能是一个字符串,它是定义的系统值的名称;这些名称在许多标准(POSIX.1、Unix 95、Unix 98 等)中指定。一些平台还定义了其他名称。主机操作系统已知的名称在pathconf_names 字典中给出。

所以我可以获取并检查pathconf_names

>>> import os
>>> print os.pathconf_names
{'PC_MAX_INPUT': 3, 'PC_VDISABLE': 9, 'PC_SYNC_IO': 25,
'PC_NAME_MAX': 4, 'PC_MAX_CANON': 2, 'PC_PRIO_IO': 19,
'PC_CHOWN_RESTRICTED': 7, 'PC_ASYNC_IO': 17, 'PC_NO_TRUNC': 8,
'PC_FILESIZEBITS': 18, 'PC_LINK_MAX': 1, 'PC_PIPE_BUF': 6,
'PC_PATH_MAX': 5}

并猜测其中一些标签的含义。但是我该去哪里查找它们的精确语义呢?标签明确地特定于这个接口;搜索PC_LINK_MAX 会出现documentation for a similar interface in z/OS (原文如此!)1 和 Ruby 等的日语页面,但没有具体关于 Python 或“某些平台也定义其他名称”可能意味着什么。这篇 TutorialsPoint 文章是关于 Python 的:http://www.tutorialspoint.com/python/os_pathconf.htm 但它只是一个教程。

我在哪里可以找到有关此接口的有用文档,特别是关于 Python 在各种平台上可用的标签以及它们的值的含义?

(Python 文档说“可用性:Unix”,因此显然在一定程度上限制了可能的平台集。澄清“某些平台”的含义将是一个很好的奖励。)


  1. IBM 似乎比 Microsoft 更多地运行了一个链接腐烂机器人,它会在注意到任何人链接到的任何内容后立即移动它;所以 URL 现在不太可能再工作了。抱歉。

【问题讨论】:

标签: python unix constants


【解决方案1】:

来自pathconf manual (Linux)

  • _PC_LINK_MAX 返回文件的最大链接数。如果 fd 或 path 引用一个目录,则该值适用于整个 目录。对应的宏是_POSIX_LINK_MAX。

  • _PC_MAX_CANON 返回格式化输入行的最大长度,其中 fd 或 path 必须引用终端。对应的宏是 _POSIX_MAX_CANON。

  • _PC_MAX_INPUT 返回输入行的最大长度,其中 fd 或 path 必须引用终端。对应的宏是 _POSIX_MAX_INPUT。
  • _PC_NAME_MAX 返回允许进程创建的目录路径或 fd 中文件名的最大长度。相应的 宏是 _POSIX_NAME_MAX。
  • 当 path 或 fd 是当前工作目录时,_PC_PATH_MAX 返回相对路径名的最大长度。对应的宏 是 _POSIX_PATH_MAX。
  • _PC_PIPE_BUF 返回管道缓冲区的大小,其中 fd 必须引用管道或 FIFO,路径必须引用 FIFO。相应的 宏是 _POSIX_PIPE_BUF。
  • _PC_CHOWN_RESTRICTED 如果不能在此文件上使用 chown(2) 调用,则返回非零值。如果 fd 或 path 引用一个目录,那么这个 适用于该目录中的所有文件。对应的宏是 _POSIX_CHOWN_RESTRICTED。
  • 如果访问长于 _POSIX_NAME_MAX 的文件名产生错误,_PC_NO_TRUNC 将返回非零值。对应的宏是_POSIX_NO_TRUNC。
  • 如果可以禁用特殊字符处理,_PC_VDISABLE 返回非零值,其中 fd 或 path 必须引用终端。

来自pathconf manual (FreeBSD)

 _PC_LINK_MAX
     The maximum file link count.

 _PC_MAX_CANON
     The maximum number of bytes in terminal canonical input line.

 _PC_MAX_INPUT
     The minimum maximum number of bytes for which space is available
     in a terminal input queue.

 _PC_NAME_MAX
     The maximum number of bytes in a file name.

 _PC_PATH_MAX
     The maximum number of bytes in a pathname.

 _PC_PIPE_BUF
     The maximum number of bytes which will be written atomically to a
     pipe.

 _PC_CHOWN_RESTRICTED
     Return 1 if appropriate privilege is required for the chown(2)
     system call, otherwise 0.  IEEE Std 1003.1-2001 (``POSIX.1'')
     requires appropriate privilege in all cases, but this behavior
     was optional in prior editions of the standard.

 _PC_NO_TRUNC
     Return greater than zero if attempts to use pathname components
     longer than {NAME_MAX} will result in an [ENAMETOOLONG] error;
     otherwise, such components will be truncated to {NAME_MAX}.  IEEE
     Std 1003.1-2001 (``POSIX.1'') requires the error in all cases,
     but this behavior was optional in prior editions of the standard,
     and some non-POSIX-compliant file systems do not support this
     behavior.

 _PC_VDISABLE
     Returns the terminal character disabling value.

 _PC_ASYNC_IO
     Return 1 if asynchronous I/O is supported, otherwise 0.

 _PC_PRIO_IO
     Returns 1 if prioritised I/O is supported for this file, other-
     wise 0.

 _PC_SYNC_IO
     Returns 1 if synchronised I/O is supported for this file, other-
     wise 0.

 _PC_ALLOC_SIZE_MIN
     Minimum number of bytes of storage allocated for any portion of a
     file.

 _PC_FILESIZEBITS
     Number of bits needed to represent the maximum file size.

 _PC_REC_INCR_XFER_SIZE
     Recommended increment for file transfer sizes between
     _PC_REC_MIN_XFER_SIZE and _PC_REC_MAX_XFER_SIZE.

 _PC_REC_MAX_XFER_SIZE
     Maximum recommended file transfer size.

 _PC_REC_MIN_XFER_SIZE
     Minimum recommended file transfer size.

 _PC_REC_XFER_ALIGN
     Recommended file transfer buffer alignment.

 _PC_SYMLINK_MAX
     Maximum number of bytes in a symbolic link.

 _PC_ACL_EXTENDED
     Returns 1 if an Access Control List (ACL) can be set on the spec-
     ified file, otherwise 0.

 _PC_ACL_NFS4
     Returns 1 if an NFSv4 ACLs can be set on the specified file, oth-
     erwise 0.

 _PC_ACL_PATH_MAX
     Maximum number of ACL entries per file.

 _PC_CAP_PRESENT
     Returns 1 if a capability state can be set on the specified file,
     otherwise 0.

 _PC_INF_PRESENT
     Returns 1 if an information label can be set on the specified
     file, otherwise 0.

 _PC_MAC_PRESENT
     Returns 1 if a Mandatory Access Control (MAC) label can be set on
     the specified file, otherwise 0.

 _PC_MIN_HOLE_SIZE
     If a file system supports the reporting of holes (see lseek(2)),
     pathconf() and fpathconf() return a positive number that repre-
     sents the minimum hole size returned in bytes.  The offsets of
     holes returned will be aligned to this same value.  A special
     value of 1 is returned if the file system does not specify the
     minimum hole size but still reports holes.

【讨论】:

  • 请注意,在许多平台上,结果可能是谎言或无限的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
  • 2022-01-12
  • 2011-03-10
  • 2016-05-01
  • 2011-01-23
  • 1970-01-01
  • 2010-10-30
相关资源
最近更新 更多