Windows内核中最大可能的文件名长度 [英] Maximum Possible File Name Length in Windows Kernel

查看:162
本文介绍了Windows内核中最大可能的文件名长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Windows内核允许的 longest 可能的名称长度是什么?

I was wondering, what is the longest possible name length allowed by the Windows kernel?

例如:我知道内核使用UNICODE_STRING结构来保存所有对象路径,并且由于宽字符字符串的字节长度存储在USHORT内部,因此最大路径长度为2 ^ 15 -1个字符.文件名(而不是路径)是否有类似的 hard 限制? (我不在乎NTFS或FAT32是否施加了特定限制;假设没有其他文件系统或外壳程序限制,我正在理论上在内核中寻找最长的允许名称.)

E.g.: I know the kernel uses UNICODE_STRING structures to hold all object paths, and since the byte length of a wide-character string is stored inside a USHORT, that allows for a maximum path length of 2^15 - 1 characters. Is there a similar, hard restriction on a file name (rather than path)? (I don't care if NTFS or FAT32 imposes a particular restriction; I'm looking for the longest possible theoretically allowed name in the kernel, assuming no additional file system or shell restrictions.)

(对于那些想知道为什么这样重要的人,请考虑通常情况下,遍历目录是通过FindFirstFile/FindNextFile调用来实现的,每个文件一个调用.给定名为NtQueryDirectoryFile的函数,这是基础系统调用,并且每次调用返回多个文件名,实际上可以利用路径上的最大长度限制来制作一个非常快的目录遍历器,该遍历器仅使用堆栈作为缓冲区.现在,我正在尝试扩展该概念,并且我需要知道文件名的最大大小.)

( For those wondering why this even matters, consider that normally, traversing a directory is achieved by FindFirstFile/FindNextFile calls, one call per file. Given the function named NtQueryDirectoryFile, which is the underlying system call and which returns multiple file names per call, it's actually possible to take advantage of this maximum-length restriction on the path to make an extremely-fast directory traverser that uses solely the stack as a buffer. Now I'm trying to extend that concept, and I need to know the maximum size of a file name.)

推荐答案

啊,我发现

Ah, I found this page myself that guarantees that file names can't be longer than 255 characters:

  • 路径名的长度不得超过32,760个字符.
    ...
  • 每个路径名组件的长度不得超过255个字符.
  • A pathname MUST be no more than 32,760 characters in length.
    ...
  • Each pathname component MUST be no more than 255 characters in length.

这让我感到奇怪:

如果有人知道这是为什么,请发表/评论!我很好奇:)

If anyone knows why this is, please post/comment! I'm rather curious. :)

这篇关于Windows内核中最大可能的文件名长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆