You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by st...@hyperreal.org on 2000/02/01 01:15:14 UTC

cvs commit: apache-2.0/src/lib/apr/file_io/win32 filestat.c

stoddard    00/01/31 16:15:13

  Modified:    src/lib/apr/file_io/win32 filestat.c
  Log:
  Reimplement ap_stat using native Windows calls. This is good for a 10% performance
  boost serving a 500 byte static file.
  
  Revision  Changes    Path
  1.6       +66 -7     apache-2.0/src/lib/apr/file_io/win32/filestat.c
  
  Index: filestat.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/filestat.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- filestat.c	2000/01/17 23:34:38	1.5
  +++ filestat.c	2000/02/01 00:15:11	1.6
  @@ -58,15 +58,12 @@
   #include "apr_file_io.h"
   #include "apr_general.h"
   #include "apr_errno.h"
  +#include "apr_time.h"
   #include <sys/stat.h>
   
  -#define S_ISLNK(m) (0)
  -#ifndef S_ISREG
  -#define S_ISREG(m)      (((m)&(S_IFMT)) == (S_IFREG))
  -#endif
  -#ifndef S_ISDIR
  -#define S_ISDIR(m) (((m) & S_IFDIR) == S_IFDIR)
  -#endif
  +#define S_ISLNK(m)  (0)
  +#define S_ISREG(m)  (((m) & (S_IFMT))  == S_IFREG)
  +#define S_ISDIR(m)  (((m) & (S_IFDIR)) == S_IFDIR)
   
   static ap_filetype_e filetype_from_mode(int mode)
   {
  @@ -81,6 +78,27 @@
   
       return type;
   }
  +BOOLEAN is_exe(const char* fname, ap_context_t *cont) {
  +    const char* exename;
  +    const char* ext;
  +    exename = strrchr(fname, '/');
  +    if (!exename) {
  +        exename = strrchr(fname, '\\');
  +    }
  +    if (!exename) {
  +        exename = fname;
  +    }
  +    else {
  +        exename++;
  +    }
  +    ext = strrchr(exename, '.');
  +
  +    if (ext && (!strcasecmp(ext,".exe") || !strcasecmp(ext,".com") || 
  +                !strcasecmp(ext,".bat") || !strcasecmp(ext,".cmd"))) {
  +        return TRUE;
  +    }
  +    return FALSE;
  +}
   
   ap_status_t ap_getfileinfo(ap_finfo_t *finfo, struct file_t *thefile)
   {
  @@ -110,6 +128,46 @@
   }
   ap_status_t ap_stat(ap_finfo_t *finfo, const char *fname, ap_context_t *cont)
   {
  +    WIN32_FILE_ATTRIBUTE_DATA FileInformation;
  +
  +    memset(finfo,'\0', sizeof(*finfo));
  +
  +    if (!GetFileAttributesEx(fname, GetFileExInfoStandard, &FileInformation)) {
  +        return GetLastError();
  +    }
  +    /* Filetype - Directory or file? */
  +    if (FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  +        finfo->protection |= S_IFDIR;
  +        finfo->filetype = APR_DIR;
  +    }
  +    else {
  +        finfo->protection |= S_IFREG;
  +        finfo->filetype = APR_REG;
  +    }
  +    /* Read, write execute for owner */
  +    if (FileInformation.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
  +        finfo->protection |= S_IREAD;
  +    }
  +    else {
  +        finfo->protection |= S_IREAD;
  +        finfo->protection |= S_IWRITE;
  +    }
  +    /* Is this an executable? Guess based on the file extension. */
  +    if (is_exe(fname, cont)) {
  +        finfo->protection |= S_IEXEC;
  +    }
  +    /* File times */
  +    FileTimeToAprTime(&finfo->atime, &FileInformation.ftLastAccessTime);
  +    FileTimeToAprTime(&finfo->ctime, &FileInformation.ftCreationTime);
  +    FileTimeToAprTime(&finfo->mtime, &FileInformation.ftLastWriteTime);
  +
  +    /* File size 
  +     * Note: This cannot handle files greater than can be held by an int */
  +    finfo->size = FileInformation.nFileSizeLow;
  +
  +    return APR_SUCCESS;
  +#if 0
  +    /* ap_stat implemented using stat() */
       struct stat info;
       int rv = stat(fname, &info);
       if (rv == 0) {
  @@ -127,5 +185,6 @@
       else {
           return errno;
       }
  +#endif
   }
   
  
  
  

Re: cvs commit: apache-2.0/src/lib/apr/file_io/win32 filestat.c

Posted by rb...@apache.org.
> > I'm not sure, but doesn't windows treat *.pif files in a similar way as
> > *.bat? And what about *.lnk
> 
> I don't know. And I'm not sure it matters for Apache purposes.

You're not writing Apache code per say.  You're writing APR code.  This
may not matter now, when nobody else is using APR, but at least add a
comment because if and when APR takes off this is a bug that will need to
be fixed.  If it isn't added by the time I get back to Raleigh and have
access to a machine with both the code and a modem, I'll add it myself.

Ryan


Come to the first official Apache Software Foundation
Conference!!!   <http://ApacheCon.Com/>

_______________________________________________________________________________
Ryan Bloom                        	rbb@ntrnet.net
2121 Stonehenge Dr. Apt #3
Raleigh, NC 27615		Ryan Bloom -- thinker, adventurer, artist,
				     writer, but mostly, friend.
-------------------------------------------------------------------------------


Re: cvs commit: apache-2.0/src/lib/apr/file_io/win32 filestat.c

Posted by Bill Stoddard <st...@raleigh.ibm.com>.
Subject: Re: cvs commit: apache-2.0/src/lib/apr/file_io/win32 filestat.c


> On Tue, Feb 01, 2000 at 12:15:14AM -0000, stoddard@hyperreal.org wrote:
> >   +    if (ext && (!strcasecmp(ext,".exe") || !strcasecmp(ext,".com") ||
> >   +                !strcasecmp(ext,".bat") || !strcasecmp(ext,".cmd")))
{
> >   +        return TRUE;
>
> I'm not sure, but doesn't windows treat *.pif files in a similar way as
> *.bat? And what about *.lnk

I don't know. And I'm not sure it matters for Apache purposes.

Bill


RE: cvs commit: apache-2.0/src/lib/apr/file_io/win32 filestat.c

Posted by "William A. Rowe, Jr." <wr...@lnd.com>.
> On Behalf Of Martin Kraemer > Sent: Monday, January 31, 2000 6:32 PM
> 
> On Tue, Feb 01, 2000 at 12:15:14AM -0000, 
> stoddard@hyperreal.org wrote:
> >   +    if (ext && (!strcasecmp(ext,".exe") || 
> !strcasecmp(ext,".com") ||
> >   +                !strcasecmp(ext,".bat") || 
> !strcasecmp(ext,".cmd"))) {
> >   +        return TRUE;
> 
> I'm not sure, but doesn't windows treat *.pif files in a 
> similar way as
> *.bat? And what about *.lnk?
> I dislike windows, so bear with me if this is a stupid question.

Not stupid - and you are correct about .pif (although all four
have differences within the API in execution) - and .lnk files 
are relative pointers to any other file (executable or not).  

The only answer to .lnk would be to resolve the redirection 
immediately upon request and treat it as a Location: redirect, 
but then again if that redirected path is outside the 
<Directory> space... well what then?  A similar question occurs
for .pif.  If not carefully handled... then the user downloading
innocent.pif or innocent.lnk ---> C:\WINNT\SYSTEM32\FORMAT.COM ???

PIF exists to support old 286 code that wasn't built to execute
in Win32 (using XMS or EMS memory mapping schemes, etc).  Do we
want to expose the kernal to that sort of nightmare?

Re: cvs commit: apache-2.0/src/lib/apr/file_io/win32 filestat.c

Posted by Martin Kraemer <Ma...@mch.sni.de>.
On Tue, Feb 01, 2000 at 12:15:14AM -0000, stoddard@hyperreal.org wrote:
>   +    if (ext && (!strcasecmp(ext,".exe") || !strcasecmp(ext,".com") ||
>   +                !strcasecmp(ext,".bat") || !strcasecmp(ext,".cmd"))) {
>   +        return TRUE;

I'm not sure, but doesn't windows treat *.pif files in a similar way as
*.bat? And what about *.lnk?
I dislike windows, so bear with me if this is a stupid question.

    Martin
-- 
  <Ma...@MchP.Siemens.De>      |       Fujitsu Siemens
       <ma...@apache.org>              |   81730  Munich,  Germany
((See you at ApacheCon 2000 in Orlanda, Florida, March 8-10, 2000!))
		   <URL:http://ApacheCon.Com/>