This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Odd, is it not? mkdir 'e:\' cannot be undone by rmdir 'e:\' ...

On Fri, 30 Aug 2019 11:54:27, Houder  wrote:

> A trailing forward slash in "pathname" is stripped in path_conv::check,
> (look for: *--tail = '\0' )
> after "pathname" has been normalized in
> normalized_posix_path or normalized_win32_path (or both),
> before it is fed into conv_to_win32_path.
> Tests have shown that Eric's code snippet can be deleted w/o harm.
> Counter arguments?

Hi Corinna,

My last post in this issue.

As reported, Eric's code snippet in rmdir() ( has become
redundant, lines 317 - 325 can be removed.

My "rough" understanding of the code flow is as follows:

mkdir in
  fh = build_fh_name -- returns pointer to fhandler_base
  fh->mkdir(mode) -- handled by mkdir() in
        NtCreateFile(... FILE_ATTRIBUTE_DIRECTORY ...)

fhandler_base has a member of type path_conv, called pc, which
is a copy of the path_conv object, created by build_fh_name().

Having removed Eric's code snippet in - and for the sake
of completeness, I decided to inspect the values of

    pc.posix_path and pc.path (i.e. "pathname" in native format)

when I stopped the debugger in mkdir() (

If I specified e.g. '/foo/\/' as the directory to create, I saw
the following:

    pc.path = "E:\\Cygwin64\\foo"
    pc.posix_path = "/" <==== HUH?

As the directory "/foo" had been correctly created, I turned to
path_conv::check(), which is called when build_fhname() creates
the path_conv object (also called pc) -- see

Examining this (obsure) method in, I corrected the code
in 2 places:

      if (dev.isfs ())
          //if (strncmp (path, "\\\\.\\", 4)) <==== 1171
          if ( ! strncmp (path, "\\\\.\\", 4)) // <==== [1]
              if (!tail || tail == path)
                /* nothing */;
              else if (tail[-1] != '\\')
                *tail = '\0'; <==== Ah! (you should not do that!)
                  error = ENOENT;

[1] this code should be executed only if path == '\\.\' !!

The above snippet 'mutilated' "/foo" into "/\0oo"

      //else if (!need_directory || error) <==== 1155
      else if (!need_directory || error || (opt & PC_SYM_NOFOLLOW) )
        /* nothing to do */;
      else if (fileattr == INVALID_FILE_ATTRIBUTES)
        /* Reattach trailing dirsep in native path. */
        strcat (modifiable_path (), "\\"); // <==== [2]

[2] WHY? Why must the native name of a directory be terminated
by a backslash? (NtCreateFile() specifies that a directory must
be created -- see mkdir() in fhandler_disk_file.c).

Yes, the above correction is an awfull hack (it abuses the Posix
directive that _no_ directory shall be created through a symbolic

Without this hack, a directory specified as '/foo/' will result
    pc.path = "E:\\Cygwin64\foo\" <==== note additional \
    pc.posix_path = "/foo"

Without the corrections in path_conv::check() (and without Eric's
code snippet in, a directory will be correctly created.

However, pc.path and pc.posix_path will not always be "equal", i.e.
consistent w/ each other.


Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]