B19 stat() under Win95 yields funky values for files on network drives

Dan Olson dano@aa.net
Wed Nov 18 03:45:00 GMT 1998


>>>>> From Dan Olson <dano@aa.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@aa.net
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


More information about the Cygwin mailing list

AltStyle によって変換されたページ (->オリジナル) /