Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Date: Wed, 30 Jun 2004 13:08:52 +0200
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: Prn lpt1 nul aux ...Win Xp
Message-ID: <20040630110852.GU19325@cygbert.vinschen.de>
Reply-To: cygwin@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
References: <156038A5123A7F43B4357AAEB498AF5776B291@ulm002.vs.dasa.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <156038A5123A7F43B4357AAEB498AF5776B291@ulm002.vs.dasa.de>
User-Agent: Mutt/1.4.2i

On Jun 30 11:46, Guettich, Ulrich, OPM2 wrote:
> Hi,
> 
> I have recognized that files named "aux", "lpt1", "nul", "prn" ... (old DOS
> devices) generated under Cygwin on a XP OS cannot be deleted anymore:
> 
> rm: cannot unlink `prn': Permission denied
> 
> Why? How to get rid of them?

It's a bug in 1.5.10 that these files can be created.  That will be fixed
in the next version.

In the meantime, build the below source with

  gcc ntdel.c -o ntdel -lntdll

Let's say, the directory in which you created "nul" is C:\your\dir, then
you should get rid of that file with

  ntdel c:/your/dir/nul

Corinna

==== SNIP ====
#include <stdio.h>
#include <ctype.h>
#include <windows.h>
#include <ntdef.h>
#include <ddk/ntifs.h>

int
main (int argc, char **argv)
{
  char apath[MAX_PATH + 32];
  char *c;
  WCHAR wpath[MAX_PATH + 32];
  UNICODE_STRING upath;
  OBJECT_ATTRIBUTES attr;
  NTSTATUS ret;

  if (argc < 2 || !isalpha (argv[1][0]) || argv[1][1] != ':')
    {
      fprintf (stderr, "usage: %s full-local-win32-path\n", argv[0]);
      return 1;
    }

  strcpy (apath, "\\??\\");
  strcat (apath, argv[1]);
  while (c = strchr (apath, '/'))
    *c = '\\';

  upath.Buffer = wpath;
  upath.MaximumLength = (MAX_PATH + 32) * sizeof (wchar_t);
  upath.Length = (MultiByteToWideChar (GetACP (), 0, apath, -1,
				       upath.Buffer, upath.MaximumLength) - 1)
		 * sizeof (WCHAR);

  InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE, NULL, NULL);

  ret = NtDeleteFile (&attr);

  if (!NT_SUCCESS (ret))
    {
      fprintf (stderr, "NtDeleteFile returned with Win32 err %lu\n",
	       RtlNtStatusToDosError (ret));
      return 1;
    }

  printf ("File successfully deleted\n");
  return 0;
}
==== SNAP ====

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Co-Project Leader          mailto:cygwin@cygwin.com
Red Hat, Inc.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

