将ext4文件系统的文件名大小限制扩展为1012个字符

Suf*_*ori 8 unix linux filesystems ext4

我从服务器中提取数据,其中一个文件夹名称超过256个字节,因此我的CentOS会抛出名称太长的错误.我在互联网上搜索过但无法找到任何方法在ext2/ext3/ext4文件系统下创建大小超过256字节的文件夹/文件名.

但是,One解决方案建议创建reiserfs文件系统ext4以处理名称较长的files \文件夹.这个解决方案可能会有效,但我在其中一本书中读到,如果需要,可以将文件名大小的限制从255字符扩展到1012字符.

The maximal file name size is 255 characters. This limit could be extended to `1012` if needed. 
Run Code Online (Sandbox Code Playgroud)

来源: 谷歌

但我找不到任何解释如何修改文件系统以扩展大小的网站1012

有人可以帮我吗?

osg*_*sgx 13

不知道在哪里找到1012(在http://e2fsprogs.sourceforge.net/ext2intro.html - 第二个扩展文件系统的设计和实现,ISBN 90-367-0385-9.1995中提到),但是在现代Linux中内核文件名固定为struct ext2_dir_entry_2最大 255 个字符(字节):

https://elixir.bootlin.com/linux/v4.10/source/fs/ext2/ext2.h#L600

/*
 * The new version of the directory entry.  Since EXT2 structures are
 * stored in intel byte order, and the name_len field could never be
 * bigger than 255 chars, it's safe to reclaim the extra byte for the
 * file_type field.
 */
struct ext2_dir_entry_2 {
    __le32  inode;          /* Inode number */
    __le16  rec_len;        /* Directory entry length */
    __u8    name_len;       /* Name length */
    __u8    file_type;
    char    name[];         /* File name, up to EXT2_NAME_LEN */
};
Run Code Online (Sandbox Code Playgroud)

struct ext2_dir_entry更长的文件名长度,但额外的字节name_len被重新定义为file_type.

      __le16    name_len;       /* Name length */
Run Code Online (Sandbox Code Playgroud)

因此,当前 ext2 的最大文件名长度为 255

https://elixir.bootlin.com/linux/v4.10/source/include/linux/ext2_fs.h#L22

#define EXT2_NAME_LEN 255
Run Code Online (Sandbox Code Playgroud)

https://elixir.bootlin.com/linux/v4.10/source/fs/ext2/namei.c#L62

if (dentry->d_name.len > EXT2_NAME_LEN)
    return ERR_PTR(-ENAMETOOLONG);
Run Code Online (Sandbox Code Playgroud)

ext3/ext4 相同:

https://elixir.bootlin.com/linux/v4.10/source/fs/ext4/ext4.h#L1892

/*
 * Structure of a directory entry
 */
#define EXT4_NAME_LEN 255
Run Code Online (Sandbox Code Playgroud)

https://elixir.bootlin.com/linux/v4.10/source/fs/ext4/namei.c

  * `len <= EXT4_NAME_LEN' is guaranteed by caller.
   if (namelen > EXT4_NAME_LEN)
        return NULL;
   if (dentry->d_name.len > EXT4_NAME_LEN)
       return ERR_PTR(-ENAMETOOLONG);
Run Code Online (Sandbox Code Playgroud)

Ondisk 格式也使用 8 位 file_name 进行描述(file_type 在旧文档中仅使用 3 位 - EXT2_FT_MAX,但现代驱动程序不会处理 255+ 文件名。ext4 具有额外的 0xde FT):

http://www.nongnu.org/ext2-doc/ext2.html#IFDIR-NAME-LEN “4.1.3. name_len - 8 位无符号值,指示名称中包含多少字节的字符数据。”

http://cs.smith.edu/~nhowe/262/oldlabs/ext2.html#direntry “file_type 字段指示条目所指的文件类型...文件名的最大长度为 EXT2_NAME_LEN,其中通常是 255。”

https://oss.oracle.com/projects/ocfs2/dist/documentation/disklayout.pdf#page=16“__u8 name_len”


Pat*_*zek 6

请参阅https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits,没有很多文件系统可以处理超过 255 字节的文件名。

虽然它可能不是对您问题的直接答复,但我认为您不应该尝试走这条路线(更改最大长度)。

您从哪个服务器检索文件?为什么在检索时不更改他们的名字?您确定整个路径名是相关的吗?如果提取前 250 个字符或后 250 个字符,是否足以毫无歧义地引用每个文件?

您有多种选择,具体取决于您的限制:

  • 要么生成“随机”名称(或顺序名称),然后将旧真名和新假名之间的映射存储在文本文件中
  • 或者将初始名称拆分为 250 个字符的路径元素(或类似的内容)并使用它们创建中间目录

您可以在https://serverfault.com/questions/264339/how-to-increase-filename-size-limit-on-ext3-on-ubuntu找到类似的讨论