stdlib.h _MAX_PATH problem.

I am seeing truncated file path strings in a user mode application that uses
_MAX_PATH defined in stdlib.h to set the buffer sizes.

Microsoft documents the Path Field Limits here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_path_field_limits.asp

However, my preliminary investigation at the kernel mode level is showing
file paths that exceed this 260 character _MAX_PATH limit. Since I am a
kernel mode developer and not a user mode developer, I am not experienced in
these user mode limitations. Do I need to increase the size of my user mode
buffers or will that be opening a can of worms at the user level if I do?
Any suggestion are welcome. I suspect it is a DOS legacy limitation.

Best Regards,
Joe

Joe:

This should be simple, but it’s not. Almost everything in Windows uses a
MAXIMUM_FILENAME_LENGTH of 256 and MAX_PATH of 260.

However, per the Platform SDK:

“The Unicode versions of several functions permit a maximum path length of
32,767 characters, composed of components up to 255 characters in length. To
specify such a path, use the “\?" prefix. For example, “\?\D:<path>”.”

However, Visual Studio says:

“The maximum length for the full path including the file name and extension
cannot exceed 258 characters.”

However, the Windows 200 error message says:

“A component of a path name cannot exceed 255 (MAXNAMELEN) characters, or an
entire path name cannot exceed 1023 (MAXPATHLEN-1) characters.”

However, Visual Database says:

“As a general guideline, long path names greater than 160 characters might
cause problems.”

There are some suggestions that short (8.3) filenames can be used to keep
the path length to ~256 characters. This implies that an expanded filename
may exceed 256 characters.

In addition, many of the paths used in Filter Drivers include the device
name (”\Device\HarddiskVolume1"), which is in addition to the full
260-character path name.



Clearly, lots of things (like Explorer) break when the full path exceeds 256
characters. But being conservative, you should make sure that (1) the paths
you handle do not exceed these limits, and (2) you can handle at least as
much as the rest of the file system.

Note that these definitions are characters, not bytes. Also, they may or
may not include the null terminator, so the maximum path length is really
MAX_PATH-1 characters. Going beyond 512 for MAX_PATH inside a driver
sometimes causes __chkstk problems, so anything larger will require dynamic
allocation/deallocation.

Bottom line: be very careful.

HTH,
Ken

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Joe Stivaletta
Sent: Wednesday, November 17, 2004 12:06 PM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] stdlib.h _MAX_PATH problem.

I am seeing truncated file path strings in a user mode application that uses

_MAX_PATH defined in stdlib.h to set the buffer sizes.

Microsoft documents the Path Field Limits here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/ht
ml/_crt_path_field_limits.asp

However, my preliminary investigation at the kernel mode level is showing
file paths that exceed this 260 character _MAX_PATH limit. Since I am a
kernel mode developer and not a user mode developer, I am not experienced in

these user mode limitations. Do I need to increase the size of my user mode

buffers or will that be opening a can of worms at the user level if I do?
Any suggestion are welcome. I suspect it is a DOS legacy limitation.

Best Regards,
Joe


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@comcast.net
To unsubscribe send a blank email to xxxxx@lists.osr.com

Joe Stivaletta wrote:

I am seeing truncated file path strings in a user mode application that uses
_MAX_PATH defined in stdlib.h to set the buffer sizes.

Microsoft documents the Path Field Limits here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_path_field_limits.asp

Unicode APIs such as CreateFile can take a pathname of up to 32k if you
prefix then with ‘??’. ANSI and CRTL APIs are limited to _MAX_PATH.

Tony

Use \?\ style paths, they are not converted to native NT paths inside
kernel32 and so the limit is not applicable to them. This is documented
somewhere in MSDN.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Joe Stivaletta”
Newsgroups: ntfsd
To: “Windows File Systems Devs Interest List”
Sent: Wednesday, November 17, 2004 8:05 PM
Subject: [ntfsd] stdlib.h _MAX_PATH problem.

> I am seeing truncated file path strings in a user mode application that uses
> _MAX_PATH defined in stdlib.h to set the buffer sizes.
>
> Microsoft documents the Path Field Limits here:
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_path_field_limits.asp
>
> However, my preliminary investigation at the kernel mode level is showing
> file paths that exceed this 260 character _MAX_PATH limit. Since I am a
> kernel mode developer and not a user mode developer, I am not experienced in
> these user mode limitations. Do I need to increase the size of my user mode
> buffers or will that be opening a can of worms at the user level if I do?
> Any suggestion are welcome. I suspect it is a DOS legacy limitation.
>
> Best Regards,
> Joe
>
>
>
> —
> Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com