delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/11/18/12:42:43

From: dano AT aa DOT net (Dan Olson)
Subject: Re: B19 stat() under Win95 yields funky values for files on network drives
18 Nov 1998 12:42:43 -0800 :
Message-ID: <00d201be12bf$54c988e0$0f02000a.cygnus.gnu-win32@ole.aa.net>
Mime-Version: 1.0
To: "Dan Olson" <dano AT aa DOT net>, <gnu-win32 AT cygnus DOT com>

>>>>> From Dan Olson <dano AT aa DOT net>, Monday, November 02, 1998 9:35 PM
>>Anybody ran into this?  I'm finding that stat() in B19 returns weird
values
>>when it gets info about files on network drives.  The numbers in struct
stat
>>look kinda like garbage (i.e. I haven't figured out a pattern).  I'm only
>>working on Win95 machines so don't know if this occurs on NT.


I found the problem.  While scanning dejanews I found an article that says:

 "Depending on the underlying network components of the operating system and
  the type of server connected to, the GetFileInformationByHandle function
  may fail, return partial information, or full information for the given
  file. In general, you should not use GetFileInformationByHandle unless
your
  application is intended to be run on a limited set of operating system
  configurations."

It turns out that GetFileInformationByHandle returns partial information for
files served by Win95 shared drive :-(   But, it turns out that
GetFileSize() does work correctly.  Weird.  I don't  know enough about Win32
to suggest a fix for stat() to make it *reliable*.  Any Ideas?  Question:
are so few people sharing files from Win95 that it is not worth solving?

Anyway, here is a little test program that shows the behavoir of stat() and
GetFileInformationByHandle() getting bogus file size info, while
GetFileSize() works.  Drive F: is a shared from a Win95 machine.


#include <sys/types.h>
#include <sys/stat.h>
#include <windows.h>

static void size(const char *file)
{
  struct stat s;
  HANDLE f;
  BY_HANDLE_FILE_INFORMATION info;

  if (stat(file, &s) == -1) {
    perror("stat");
  }

  printf("stat(%s) st_size = %d\n", file, s.st_size);

  f = CreateFile(file, GENERIC_READ, 0, NULL,
                 OPEN_EXISTING, 0, NULL );

  if (f == NULL) {
    printf("f is null\n");
  }

  if (!GetFileInformationByHandle(f, &info)) {
    printf("Didn't work\n");
  }

  printf("GetFileInformationByHandle()\n"
         " nFileSizeLow = %d (0x%x), nFileSizeHigh = %d (0x%x)\n",
         info.nFileSizeLow, info.nFileSizeLow,
         info.nFileSizeHigh, info.nFileSizeHigh);

  printf("GetFileSize() = %d\n\n", GetFileSize((HANDLE)f, NULL));
}

int main()
{
  size("C:/AUTOEXEC.BAT");
  size("F:/AUTOEXEC.BAT");
  return 0;
}


bash$ ./stat
stat(C:/AUTOEXEC.BAT) st_size = 859
GetFileInformationByHandle()
nFileSizeLow = 859 (0x35b), nFileSizeHigh = 0 (0x0)
GetFileSize() = 859

stat(F:/AUTOEXEC.BAT) st_size = -1058025616
GetFileInformationByHandle()
nFileSizeLow = -1058017424 (0xc0efef70), nFileSizeHigh = 0 (0x0)
GetFileSize() = 1265

--
dano AT aa DOT net


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019