You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jeff Trawick <tr...@bellsouth.net> on 2000/03/20 03:10:48 UTC

[PATCH] let ap_open() work on Win9x

FILE_SHARE_DELETE is NT/Win2K only...

follow-on issues...

. define ap_get_oslevel() in a header file 
  (lib/apr/include/apr_general.h?)

. perhaps change ap_get_oslevel() so you can ask does this have NT 
  functionality or not?  Win32's GetVersionEx() lets us ask the right 
  question without getting into the details of which release; we
  don't want to end up with various code that has to be changed when
  Microsoft updates Win2K or Win98

Index: lib/apr/file_io/win32/open.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/lib/apr/file_io/win32/open.c,v
retrieving revision 1.22
diff -u -r1.22 open.c
--- open.c	2000/03/15 16:53:30	1.22
+++ open.c	2000/03/20 02:03:18
@@ -81,6 +81,8 @@
     DWORD oflags = 0;
     DWORD createflags = 0;
     DWORD attributes = 0;
+	DWORD sharemode = FILE_SHARE_READ | FILE_SHARE_WRITE;
+    ap_oslevel_e level;
 
     (*dafile) = (struct file_t *)ap_palloc(cont, sizeof(struct file_t));
 
@@ -106,7 +108,11 @@
 
     (*dafile)->demonfname = canonical_filename((*dafile)->cntxt, fname);
     (*dafile)->lowerdemonfname = strlwr((*dafile)->demonfname);
-    
+ 
+	if (ap_get_oslevel(cont, &level) == APR_SUCCESS && level == APR_WIN_NT) {
+		sharemode |= FILE_SHARE_DELETE;
+	}
+
     if (flag & APR_CREATE) {
         if (flag & APR_EXCL) {
             /* only create new if file does not already exist */
@@ -147,7 +153,7 @@
         attributes |= FILE_FLAG_DELETE_ON_CLOSE;
     }
 
-    (*dafile)->filehand = CreateFile(fname, oflags, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+    (*dafile)->filehand = CreateFile(fname, oflags, sharemode,
                                      NULL, createflags, attributes, 0);
 
     if ((*dafile)->filehand == INVALID_HANDLE_VALUE) {

-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Re: [PATCH] let ap_open() work on Win9x

Posted by Ben Laurie <be...@algroup.co.uk>.
Greg Stein wrote:
> And one other comment: there is *no* reason to use bitfields here. This
> structure (in all likelihood) exists only on the stack. There is no reason
> to conserve space -- it isn't like we are allocating a million of these
> things on the heap. Each flag should be a separate "int" (drop the
> unsigned, too!).

Curious to know why?

Cheers,

Ben.

--
SECURE HOSTING AT THE BUNKER: http://www.thebunker.net/hosting.htm

http://www.apache-ssl.org/ben.html

Coming to ApacheCon Europe? http://ApacheCon.Com/

Re: [PATCH] let ap_open() work on Win9x

Posted by Greg Stein <gs...@lyra.org>.
On Mon, 20 Mar 2000 rbb@apache.org wrote:
> > Another thought I had on how to handle the differences between
> > various flavors of Windows (or AIX or whatever) in one executable
> > is to have an os-specific function that filled in a vector of stuff
> > like
> > 
> >   struct os_capabilities {
> >     unsigned int hasFeature1 : 1; 
> >     unsigned int hasFeature2 : 1;
> >     ...
> >   };
> 
> I still don't see how this helps.  On platforms like windows, where things
> are done based on version, we already have a method of retrieving the
> version of the OS.  I guess I see the performance penalties of having to
> fill out this structure as far outweighing any potential benefit this
> might get us.

And one other comment: there is *no* reason to use bitfields here. This
structure (in all likelihood) exists only on the stack. There is no reason
to conserve space -- it isn't like we are allocating a million of these
things on the heap. Each flag should be a separate "int" (drop the
unsigned, too!).

I don't have any comments on the need itself... Ryan can address that. I
just wanted to add my comment that bitfields are bogus.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/


Re: [PATCH] let ap_open() work on Win9x

Posted by rb...@apache.org.
> Another thought I had on how to handle the differences between
> various flavors of Windows (or AIX or whatever) in one executable
> is to have an os-specific function that filled in a vector of stuff
> like
> 
>   struct os_capabilities {
>     unsigned int hasFeature1 : 1; 
>     unsigned int hasFeature2 : 1;
>     ...
>   };

I still don't see how this helps.  On platforms like windows, where things
are done based on version, we already have a method of retrieving the
version of the OS.  I guess I see the performance penalties of having to
fill out this structure as far outweighing any potential benefit this
might get us.

> 
> This is definitely internal-to-apr stuff and is probably 
> only needed on Win32 for the forseeable future.  The code
> that wants to open a file only needs to know whether or not
> a certain feature is available.  

This should be done by ap_get_oslevel.  Having another function adds
complexity that is unecessary.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------



Re: [PATCH] let ap_open() work on Win9x

Posted by Jeff Trawick <tr...@bellsouth.net>.
I agree on the internal-vs.-external issue.

Another thought I had on how to handle the differences between
various flavors of Windows (or AIX or whatever) in one executable
is to have an os-specific function that filled in a vector of stuff
like

  struct os_capabilities {
    unsigned int hasFeature1 : 1; 
    unsigned int hasFeature2 : 1;
    ...
  };

This is definitely internal-to-apr stuff and is probably 
only needed on Win32 for the forseeable future.  The code
that wants to open a file only needs to know whether or not
a certain feature is available.  It doesn't need to figure
out for itself when that feature is available.  A common
piece of code can look at the windows version (and perhaps
in bizarre cases at what service pack is applied) to figure
that out.

-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Re: [PATCH] let ap_open() work on Win9x

Posted by Jeff Trawick <tr...@bellsouth.net>.
> > . perhaps change ap_get_oslevel() so you can ask does this have NT 
> >   functionality or not?  Win32's GetVersionEx() lets us ask the right 
> >   question without getting into the details of which release; we
> >   don't want to end up with various code that has to be changed when
> >   Microsoft updates Win2K or Win98
> 
> I don't understand what you want to do to ap_get_oslevel.  Perhaps if you
> could explain the new prototype and the what it allows us to do.
> 
> Ryan

I misread the code.  Sorry!  The current structure *does* tell us
whether or not we have the NT capabilities.  I thought originally that
it would need to change to return yet another value (APR_WIN_2K?) for 
Win2K and that callers would have to change their logic.

  level set by ap_get_oslevel()        platform      version
  -----------------------------        --------      -------
  APR_WIN_NT                           NT            don't know (NT or WIN2K)
  APR_WIN_95                           toy Windows   Win95
  APR_WIN_98                           toy Windows   Win98

Have fun...
-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Re: [PATCH] let ap_open() work on Win9x

Posted by rb...@apache.org.
> follow-on issues...
> 
> . define ap_get_oslevel() in a header file 
>   (lib/apr/include/apr_general.h?)

My impression, is that this hasn't been decided yet.  I am still waiting
for a good reason to expose this to external programs.  I really believe
this should be an internal APR function.  If you externalize this, you are
basically telling people code like the following is good.

ap_get_os_level(c, &level);
if (level == APR_WIN_NT) {
    ...
} else if (level == APR_WIN98) {
    ...
}

This is checking for functionality based on platform and version of that
platform.  I consider this a bad idea.  We are forced to do this on
Windows, because this is how Windows does things.  But, this is the exact
coding style that APR was supposed to help us get away from.  I find it
much cleaner to do:

if (ap_function != APR_ENOTIMPL) { /*platform doesn't support this func*/
  ...
} else if (ap_other_func != APR_ENOTIMPLE) {
  ...
}

This is choosing run-time options based on what the platform can do, not
which platform it is.  IMHO, this almost always creates more portable,
more easily understandably code.

I am -1 on this change, until somebody convinces me this is a good idea.




> . perhaps change ap_get_oslevel() so you can ask does this have NT 
>   functionality or not?  Win32's GetVersionEx() lets us ask the right 
>   question without getting into the details of which release; we
>   don't want to end up with various code that has to be changed when
>   Microsoft updates Win2K or Win98

I don't understand what you want to do to ap_get_oslevel.  Perhaps if you
could explain the new prototype and the what it allows us to do.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------




Re: [PATCH] let ap_open() work on Win9x

Posted by Bill Stoddard <st...@raleigh.ibm.com>.
> I believe Ryan or Bill pointed out we need a global flag on this.  No
excuse
> to add the function call overhead for a boolean flag.
I suggested a global, Ryan brought to my attention the existance of
ap_get_oslevel(). I have no objections to calling ap_get_oslevel(). The
function call overhead is minimal.

Bill


RE: [PATCH] let ap_open() work on Win9x

Posted by "William A. Rowe, Jr." <wr...@lnd.com>.
Let me clarify - the global flag is internal to modules linked into
aprlib.dll - because we cannot maintain the binary compatibility of data
linkages from build to build, it needs to be exported as a function, if at
all.  But since _EVERY_ messy NT/95 detail is addressed in aprlib, this
isn't a problem (we trust).

> -----Original Message-----
> From: William A. Rowe, Jr. [mailto:wrowe@lnd.com]
> Sent: Sunday, March 19, 2000 9:02 PM
> To: new-httpd@apache.org; trawickj@bellsouth.net
> Subject: RE: [PATCH] let ap_open() work on Win9x
>
>
> I believe Ryan or Bill pointed out we need a global flag on
> this.  No excuse
> to add the function call overhead for a boolean flag.  It
> ought to be set on
> startup through the win32 flavor of process initialization.
>
> Bill
>
> > -----Original Message-----
> > From: Jeff Trawick [mailto:trawickj@bellsouth.net]
> > Sent: Sunday, March 19, 2000 8:11 PM
> > To: new-httpd@apache.org
> > Subject: [PATCH] let ap_open() work on Win9x
> >
> >
> > FILE_SHARE_DELETE is NT/Win2K only...
> >
> > follow-on issues...
> >
> > . define ap_get_oslevel() in a header file
> >   (lib/apr/include/apr_general.h?)
> >
> > . perhaps change ap_get_oslevel() so you can ask does this have NT
> >   functionality or not?  Win32's GetVersionEx() lets us ask
> the right
> >   question without getting into the details of which release; we
> >   don't want to end up with various code that has to be changed when
> >   Microsoft updates Win2K or Win98
> >
> > Index: lib/apr/file_io/win32/open.c
> > ===================================================================
> > RCS file: /cvs/apache/apache-2.0/src/lib/apr/file_io/win32/open.c,v
> > retrieving revision 1.22
> > diff -u -r1.22 open.c
> > --- open.c	2000/03/15 16:53:30	1.22
> > +++ open.c	2000/03/20 02:03:18
> > @@ -81,6 +81,8 @@
> >      DWORD oflags = 0;
> >      DWORD createflags = 0;
> >      DWORD attributes = 0;
> > +	DWORD sharemode = FILE_SHARE_READ | FILE_SHARE_WRITE;
> > +    ap_oslevel_e level;
> >
> >      (*dafile) = (struct file_t *)ap_palloc(cont,
> > sizeof(struct file_t));
> >
> > @@ -106,7 +108,11 @@
> >
> >      (*dafile)->demonfname =
> > canonical_filename((*dafile)->cntxt, fname);
> >      (*dafile)->lowerdemonfname = strlwr((*dafile)->demonfname);
> > -
> > +
> > +	if (ap_get_oslevel(cont, &level) == APR_SUCCESS &&
> > level == APR_WIN_NT) {
> > +		sharemode |= FILE_SHARE_DELETE;
> > +	}
> > +
> >      if (flag & APR_CREATE) {
> >          if (flag & APR_EXCL) {
> >              /* only create new if file does not already exist */
> > @@ -147,7 +153,7 @@
> >          attributes |= FILE_FLAG_DELETE_ON_CLOSE;
> >      }
> >
> > -    (*dafile)->filehand = CreateFile(fname, oflags,
> > FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
> > +    (*dafile)->filehand = CreateFile(fname, oflags, sharemode,
> >                                       NULL, createflags,
> > attributes, 0);
> >
> >      if ((*dafile)->filehand == INVALID_HANDLE_VALUE) {
> >
> > --
> > Jeff Trawick | trawick@ibm.net | PGP public key at web site:
> >      http://www.geocities.com/SiliconValley/Park/9289/
> >           Born in Roswell... married an alien...
> >
>


RE: [PATCH] let ap_open() work on Win9x

Posted by "William A. Rowe, Jr." <wr...@lnd.com>.
I believe Ryan or Bill pointed out we need a global flag on this.  No excuse
to add the function call overhead for a boolean flag.  It ought to be set on
startup through the win32 flavor of process initialization.

Bill

> -----Original Message-----
> From: Jeff Trawick [mailto:trawickj@bellsouth.net]
> Sent: Sunday, March 19, 2000 8:11 PM
> To: new-httpd@apache.org
> Subject: [PATCH] let ap_open() work on Win9x
>
>
> FILE_SHARE_DELETE is NT/Win2K only...
>
> follow-on issues...
>
> . define ap_get_oslevel() in a header file
>   (lib/apr/include/apr_general.h?)
>
> . perhaps change ap_get_oslevel() so you can ask does this have NT
>   functionality or not?  Win32's GetVersionEx() lets us ask the right
>   question without getting into the details of which release; we
>   don't want to end up with various code that has to be changed when
>   Microsoft updates Win2K or Win98
>
> Index: lib/apr/file_io/win32/open.c
> ===================================================================
> RCS file: /cvs/apache/apache-2.0/src/lib/apr/file_io/win32/open.c,v
> retrieving revision 1.22
> diff -u -r1.22 open.c
> --- open.c	2000/03/15 16:53:30	1.22
> +++ open.c	2000/03/20 02:03:18
> @@ -81,6 +81,8 @@
>      DWORD oflags = 0;
>      DWORD createflags = 0;
>      DWORD attributes = 0;
> +	DWORD sharemode = FILE_SHARE_READ | FILE_SHARE_WRITE;
> +    ap_oslevel_e level;
>
>      (*dafile) = (struct file_t *)ap_palloc(cont,
> sizeof(struct file_t));
>
> @@ -106,7 +108,11 @@
>
>      (*dafile)->demonfname =
> canonical_filename((*dafile)->cntxt, fname);
>      (*dafile)->lowerdemonfname = strlwr((*dafile)->demonfname);
> -
> +
> +	if (ap_get_oslevel(cont, &level) == APR_SUCCESS &&
> level == APR_WIN_NT) {
> +		sharemode |= FILE_SHARE_DELETE;
> +	}
> +
>      if (flag & APR_CREATE) {
>          if (flag & APR_EXCL) {
>              /* only create new if file does not already exist */
> @@ -147,7 +153,7 @@
>          attributes |= FILE_FLAG_DELETE_ON_CLOSE;
>      }
>
> -    (*dafile)->filehand = CreateFile(fname, oflags,
> FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
> +    (*dafile)->filehand = CreateFile(fname, oflags, sharemode,
>                                       NULL, createflags,
> attributes, 0);
>
>      if ((*dafile)->filehand == INVALID_HANDLE_VALUE) {
>
> --
> Jeff Trawick | trawick@ibm.net | PGP public key at web site:
>      http://www.geocities.com/SiliconValley/Park/9289/
>           Born in Roswell... married an alien...
>