Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/fhandler_disk_file.cc')
-rw-r--r--winsup/cygwin/fhandler_disk_file.cc505
1 files changed, 239 insertions, 266 deletions
diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index 1ce4893d2..f8a7afca1 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -1,6 +1,6 @@
/* fhandler_disk_file.cc
- Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc.
+ Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
This file is part of Cygwin.
@@ -9,7 +9,6 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include "winsup.h"
-#include <sys/fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
@@ -24,14 +23,14 @@ details. */
#include "dtable.h"
#include "cygheap.h"
#include "shared_info.h"
-#include "sigproc.h"
#include "pinfo.h"
#include <assert.h>
+#include <ctype.h>
#define _COMPILING_NEWLIB
#include <dirent.h>
-static int
+static int __stdcall
num_entries (const char *win32_name)
{
WIN32_FIND_DATA buf;
@@ -60,27 +59,126 @@ num_entries (const char *win32_name)
return count;
}
-int
-fhandler_disk_file::fstat (struct stat *buf, path_conv *pc)
+int __stdcall
+fhandler_disk_file::fstat_by_handle (struct __stat64 *buf, path_conv *pc)
+{
+ int res = 0;
+ BY_HANDLE_FILE_INFORMATION local;
+
+ /* NT 3.51 seems to have a bug when attempting to get vol serial
+ numbers. This loop gets around this. */
+ for (int i = 0; i < 2; i++)
+ {
+ if (!(res = GetFileInformationByHandle (get_handle (), &local)))
+ break;
+ if (local.dwVolumeSerialNumber && (long) local.dwVolumeSerialNumber != -1)
+ break;
+ }
+ debug_printf ("%d = GetFileInformationByHandle (%s, %d)",
+ res, get_win32_name (), get_handle ());
+ if (res == 0)
+ /* GetFileInformationByHandle will fail if it's given stdin/out/err
+ or a pipe*/
+ {
+ memset (&local, 0, sizeof (local));
+ local.nFileSizeLow = GetFileSize (get_handle (), &local.nFileSizeHigh);
+ }
+
+ return fstat_helper (buf, pc,
+ local.ftCreationTime,
+ local.ftLastAccessTime,
+ local.ftLastWriteTime,
+ local.nFileSizeHigh,
+ local.nFileSizeLow,
+ local.nFileIndexHigh,
+ local.nFileIndexLow,
+ local.nNumberOfLinks);
+}
+
+int __stdcall
+fhandler_disk_file::fstat_by_name (struct __stat64 *buf, path_conv *pc)
+{
+ int res;
+ HANDLE handle;
+ WIN32_FIND_DATA local;
+
+ if (!pc->exists ())
+ {
+ debug_printf ("already determined that pc does not exist");
+ set_errno (ENOENT);
+ res = -1;
+ }
+ else
+ {
+ char drivebuf[5];
+ char *name;
+ if ((*pc)[3] != '\0' || !isalpha ((*pc)[0]) || (*pc)[1] != ':' || (*pc)[2] != '\\')
+ name = *pc;
+ else
+ {
+ /* FIXME: Does this work on empty disks? */
+ drivebuf[0] = (*pc)[0];
+ drivebuf[1] = (*pc)[1];
+ drivebuf[2] = (*pc)[2];
+ drivebuf[3] = '*';
+ drivebuf[4] = '\0';
+ name = drivebuf;
+ }
+
+ if ((handle = FindFirstFile (name, &local)) == INVALID_HANDLE_VALUE)
+ {
+ debug_printf ("FindFirstFile failed for '%s', %E", name);
+ __seterrno ();
+ res = -1;
+ }
+ else
+ {
+ FindClose (handle);
+ res = fstat_helper (buf, pc,
+ local.ftCreationTime,
+ local.ftLastAccessTime,
+ local.ftLastWriteTime,
+ local.nFileSizeHigh,
+ local.nFileSizeLow);
+ }
+ }
+ return res;
+}
+
+int __stdcall
+fhandler_disk_file::fstat (struct __stat64 *buf, path_conv *pc)
{
int res = -1;
int oret;
- uid_t uid;
- gid_t gid;
+ __uid32_t uid;
+ __gid32_t gid;
int open_flags = O_RDONLY | O_BINARY | O_DIROPEN;
+ bool query_open_already;
- if (!pc)
- return fstat_helper (buf);
-
- if ((oret = open (pc, open_flags, 0)))
- /* ok */;
+ if (get_io_handle ())
+ {
+ if (get_nohandle ())
+ return fstat_by_name (buf, pc);
+ else
+ return fstat_by_handle (buf, pc);
+ }
+ /* If we don't care if the file is executable or we already know if it is,
+ then just do a "query open" as it is apparently much faster. */
+ if (pc->exec_state () != dont_know_if_executable)
+ set_query_open (query_open_already = true);
else
+ query_open_already = false;
+
+ if (query_open_already && strncasematch (pc->volname (), "FAT", 3)
+ && !strpbrk (get_win32_name (), "?*|<>"))
+ oret = 0;
+ else if (!(oret = open (pc, open_flags, 0)))
{
int ntsec_atts = 0;
/* If we couldn't open the file, try a "query open" with no permissions.
This will allow us to determine *some* things about the file, at least. */
- set_query_open (TRUE);
- if ((oret = open (pc, open_flags, 0)))
+ set_query_open (true);
+ if (!query_open_already && (oret = open (pc, open_flags, 0)))
/* ok */;
else if (allow_ntsec && pc->has_acls () && get_errno () == EACCES
&& !get_file_attribute (TRUE, get_win32_name (), &ntsec_atts, &uid, &gid)
@@ -96,149 +194,54 @@ fhandler_disk_file::fstat (struct stat *buf, path_conv *pc)
set_file_attribute (TRUE, get_win32_name (), ntsec_atts);
}
}
- if (oret)
- {
- res = fstat_helper (buf);
- /* The number of links to a directory includes the
- number of subdirectories in the directory, since all
- those subdirectories point to it.
- This is too slow on remote drives, so we do without it and
- set the number of links to 2. */
- /* Unfortunately the count of 2 confuses `find (1)' command. So
- let's try it with `1' as link count. */
- if (pc->isdir ())
- buf->st_nlink = (pc->isremote ()
- ? 1 : num_entries (pc->get_win32 ()));
+
+ if (!oret || get_nohandle ())
+ res = fstat_by_name (buf, pc);
+ else
+ {
+ res = fstat_by_handle (buf, pc);
close ();
}
- else if (pc->exists ())
- {
- /* Unfortunately, the above open may fail if the file exists, though.
- So we have to care for this case here, too. */
- WIN32_FIND_DATA wfd;
- HANDLE handle;
- buf->st_nlink = 1;
- if (pc->isdir () && pc->isremote ())
- buf->st_nlink = num_entries (pc->get_win32 ());
- buf->st_dev = FHDEVN (FH_DISK) << 8;
- buf->st_ino = hash_path_name (0, pc->get_win32 ());
- if (pc->isdir ())
- buf->st_mode = S_IFDIR;
- else if (pc->issymlink ())
- buf->st_mode = S_IFLNK;
- else if (pc->issocket ())
- buf->st_mode = S_IFSOCK;
- else
- buf->st_mode = S_IFREG;
- if (!pc->has_acls ()
- || get_file_attribute (TRUE, pc->get_win32 (),
- &buf->st_mode,
- &buf->st_uid, &buf->st_gid))
- {
- buf->st_mode |= STD_RBITS | STD_XBITS;
- if (!(pc->has_attribute (FILE_ATTRIBUTE_READONLY)))
- buf->st_mode |= STD_WBITS;
- if (pc->issymlink ())
- buf->st_mode |= S_IRWXU | S_IRWXG | S_IRWXO;
- get_file_attribute (FALSE, pc->get_win32 (),
- NULL, &buf->st_uid, &buf->st_gid);
- }
- if ((handle = FindFirstFile (pc->get_win32 (), &wfd))
- != INVALID_HANDLE_VALUE)
- {
- /* This is for FAT filesystems, which don't support atime/ctime */
- if (wfd.ftLastAccessTime.dwLowDateTime == 0
- && wfd.ftLastAccessTime.dwHighDateTime == 0)
- wfd.ftLastAccessTime = wfd.ftLastWriteTime;
- if (wfd.ftCreationTime.dwLowDateTime == 0
- && wfd.ftCreationTime.dwHighDateTime == 0)
- wfd.ftCreationTime = wfd.ftLastWriteTime;
-
- buf->st_atime = to_time_t (&wfd.ftLastAccessTime);
- buf->st_mtime = to_time_t (&wfd.ftLastWriteTime);
- buf->st_ctime = to_time_t (&wfd.ftCreationTime);
- buf->st_size = wfd.nFileSizeLow;
- buf->st_blksize = S_BLKSIZE;
- buf->st_blocks = ((unsigned long) buf->st_size +
- S_BLKSIZE-1) / S_BLKSIZE;
- FindClose (handle);
- }
- res = 0;
- }
return res;
}
-int
-fhandler_disk_file::fstat_helper (struct stat *buf)
+int __stdcall
+fhandler_disk_file::fstat_helper (struct __stat64 *buf, path_conv *pc,
+ FILETIME ftCreationTime,
+ FILETIME ftLastAccessTime,
+ FILETIME ftLastWriteTime,
+ DWORD nFileSizeHigh,
+ DWORD nFileSizeLow,
+ DWORD nFileIndexHigh,
+ DWORD nFileIndexLow,
+ DWORD nNumberOfLinks)
{
- int res = 0; // avoid a compiler warning
- BY_HANDLE_FILE_INFORMATION local;
- save_errno saved_errno;
-
- /* NT 3.51 seems to have a bug when attempting to get vol serial
- numbers. This loop gets around this. */
- for (int i = 0; i < 2; i++)
- {
- if (!(res = GetFileInformationByHandle (get_handle (), &local)))
- break;
- if (local.dwVolumeSerialNumber && (long) local.dwVolumeSerialNumber != -1)
- break;
- }
- debug_printf ("%d = GetFileInformationByHandle (%s, %d)",
- res, get_win32_name (), get_handle ());
- if (res == 0)
- {
- /* GetFileInformationByHandle will fail if it's given stdin/out/err
- or a pipe*/
- DWORD lsize, hsize;
-
- if (GetFileType (get_handle ()) != FILE_TYPE_DISK)
- buf->st_mode = S_IFCHR;
-
- lsize = GetFileSize (get_handle (), &hsize);
- if (lsize == 0xffffffff && GetLastError () != NO_ERROR)
- buf->st_mode = S_IFCHR;
- else
- buf->st_size = lsize;
- /* We expect these to fail! */
- buf->st_mode |= STD_RBITS | STD_WBITS;
- buf->st_blksize = S_BLKSIZE;
- buf->st_ino = get_namehash ();
- syscall_printf ("0 = fstat (, %p)", buf);
- return 0;
- }
-
- if (!get_win32_name ())
- {
- saved_errno.set (ENOENT);
- return -1;
- }
-
/* This is for FAT filesystems, which don't support atime/ctime */
- if (local.ftLastAccessTime.dwLowDateTime == 0
- && local.ftLastAccessTime.dwHighDateTime == 0)
- local.ftLastAccessTime = local.ftLastWriteTime;
- if (local.ftCreationTime.dwLowDateTime == 0
- && local.ftCreationTime.dwHighDateTime == 0)
- local.ftCreationTime = local.ftLastWriteTime;
-
- buf->st_atime = to_time_t (&local.ftLastAccessTime);
- buf->st_mtime = to_time_t (&local.ftLastWriteTime);
- buf->st_ctime = to_time_t (&local.ftCreationTime);
- buf->st_nlink = local.nNumberOfLinks;
- buf->st_dev = local.dwVolumeSerialNumber;
- buf->st_size = local.nFileSizeLow;
-
- /* Allocate some place to determine the root directory. Need to allocate
- enough so that rootdir can add a trailing slash if path starts with \\. */
- char root[strlen (get_win32_name ()) + 3];
- strcpy (root, get_win32_name ());
+ if (ftLastAccessTime.dwLowDateTime == 0
+ && ftLastAccessTime.dwHighDateTime == 0)
+ ftLastAccessTime = ftLastWriteTime;
+ if (ftCreationTime.dwLowDateTime == 0
+ && ftCreationTime.dwHighDateTime == 0)
+ ftCreationTime = ftLastWriteTime;
+
+ to_timestruc_t (&ftLastAccessTime, &buf->st_atim);
+ to_timestruc_t (&ftLastWriteTime, &buf->st_mtim);
+ to_timestruc_t (&ftCreationTime, &buf->st_ctim);
+ buf->st_dev = pc->volser ();
+ buf->st_size = ((__off64_t)nFileSizeHigh << 32) + nFileSizeLow;
+ /* Unfortunately the count of 2 confuses `find (1)' command. So
+ let's try it with `1' as link count. */
+ if (pc->isdir () && !pc->isremote () && nNumberOfLinks == 1)
+ buf->st_nlink = num_entries (pc->get_win32 ());
+ else
+ buf->st_nlink = nNumberOfLinks;
/* Assume that if a drive has ACL support it MAY have valid "inodes".
It definitely does not have valid inodes if it does not have ACL
support. */
- switch (has_acls () ? GetDriveType (rootdir (root)) : DRIVE_UNKNOWN)
+ switch (pc->has_acls () && (nFileIndexHigh || nFileIndexLow)
+ ? pc->drive_type () : DRIVE_UNKNOWN)
{
case DRIVE_FIXED:
case DRIVE_REMOVABLE:
@@ -246,7 +249,7 @@ fhandler_disk_file::fstat_helper (struct stat *buf)
case DRIVE_RAMDISK:
/* Although the documentation indicates otherwise, it seems like
"inodes" on these devices are persistent, at least across reboots. */
- buf->st_ino = local.nFileIndexHigh | local.nFileIndexLow;
+ buf->st_ino = nFileIndexHigh | nFileIndexLow;
break;
default:
/* Either the nFileIndex* fields are unreliable or unavailable. Use the
@@ -256,23 +259,25 @@ fhandler_disk_file::fstat_helper (struct stat *buf)
}
buf->st_blksize = S_BLKSIZE;
- buf->st_blocks = ((unsigned long) buf->st_size + S_BLKSIZE-1) / S_BLKSIZE;
+ buf->st_blocks = (buf->st_size + S_BLKSIZE - 1) / S_BLKSIZE;
buf->st_mode = 0;
/* Using a side effect: get_file_attibutes checks for
directory. This is used, to set S_ISVTX, if needed. */
- if (local.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ if (pc->isdir ())
buf->st_mode = S_IFDIR;
- else if (get_symlink_p ())
+ else if (pc->issymlink ())
buf->st_mode = S_IFLNK;
- else if (get_socket_p ())
+ else if (pc->issocket ())
buf->st_mode = S_IFSOCK;
- if (get_file_attribute (has_acls (), get_win32_name (), &buf->st_mode,
- &buf->st_uid, &buf->st_gid) == 0)
+
+ __uid32_t uid;
+ __gid32_t gid;
+ if (get_file_attribute (pc->has_acls (), get_win32_name (), &buf->st_mode,
+ &uid, &gid) == 0)
{
/* If read-only attribute is set, modify ntsec return value */
- if ((local.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
- && !get_symlink_p ())
+ if (pc->has_attribute (FILE_ATTRIBUTE_READONLY) && !get_symlink_p ())
buf->st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
if (!(buf->st_mode & S_IFMT))
@@ -282,7 +287,7 @@ fhandler_disk_file::fstat_helper (struct stat *buf)
{
buf->st_mode |= STD_RBITS;
- if (!(local.dwFileAttributes & FILE_ATTRIBUTE_READONLY))
+ if (!pc->has_attribute (FILE_ATTRIBUTE_READONLY))
buf->st_mode |= STD_WBITS;
/* | S_IWGRP | S_IWOTH; we don't give write to group etc */
@@ -290,51 +295,52 @@ fhandler_disk_file::fstat_helper (struct stat *buf)
buf->st_mode |= S_IFDIR | STD_XBITS;
else if (buf->st_mode & S_IFMT)
/* nothing */;
- else if (get_socket_p ())
+ else if (pc->issocket ())
buf->st_mode |= S_IFSOCK;
else
- switch (GetFileType (get_handle ()))
- {
- case FILE_TYPE_CHAR:
- case FILE_TYPE_UNKNOWN:
- buf->st_mode |= S_IFCHR;
- break;
- case FILE_TYPE_DISK:
- buf->st_mode |= S_IFREG;
- if (!dont_care_if_execable () && !get_execable_p ())
- {
- DWORD cur, done;
- char magic[3];
-
- /* First retrieve current position, set to beginning
- of file if not already there. */
- cur = SetFilePointer (get_handle(), 0, NULL, FILE_CURRENT);
- if (cur != INVALID_SET_FILE_POINTER &&
- (!cur ||
- SetFilePointer (get_handle(), 0, NULL, FILE_BEGIN)
- != INVALID_SET_FILE_POINTER))
- {
- /* FIXME should we use /etc/magic ? */
- magic[0] = magic[1] = magic[2] = '\0';
- if (ReadFile (get_handle (), magic, 3, &done, NULL) &&
- has_exec_chars (magic, done))
- set_execable_p ();
- SetFilePointer (get_handle(), cur, NULL, FILE_BEGIN);
- }
- }
- if (get_execable_p ())
- buf->st_mode |= STD_XBITS;
- break;
- case FILE_TYPE_PIPE:
- buf->st_mode |= S_IFSOCK;
- break;
- }
- }
-
- syscall_printf ("0 = fstat (, %p) st_atime=%x st_size=%d, st_mode=%p, st_ino=%d, sizeof=%d",
- buf, buf->st_atime, buf->st_size, buf->st_mode,
- (int) buf->st_ino, sizeof (*buf));
+ {
+ buf->st_mode |= S_IFREG;
+ if (pc->exec_state () == dont_know_if_executable)
+ {
+ DWORD cur, done;
+ char magic[3];
+
+ /* First retrieve current position, set to beginning
+ of file if not already there. */
+ cur = SetFilePointer (get_handle (), 0, NULL, FILE_CURRENT);
+ if (cur != INVALID_SET_FILE_POINTER &&
+ (!cur ||
+ SetFilePointer (get_handle (), 0, NULL, FILE_BEGIN)
+ != INVALID_SET_FILE_POINTER))
+ {
+ /* FIXME should we use /etc/magic ? */
+ magic[0] = magic[1] = magic[2] = '\0';
+ if (ReadFile (get_handle (), magic, 3, &done, NULL) &&
+ has_exec_chars (magic, done))
+ {
+ set_execable_p ();
+ pc->set_exec ();
+ }
+ SetFilePointer (get_handle (), cur, NULL, FILE_BEGIN);
+ }
+ }
+ if (pc->exec_state () == is_executable)
+ buf->st_mode |= STD_XBITS;
+ }
+ }
+
+ buf->st_uid = uid;
+ buf->st_gid = gid;
+ /* The number of links to a directory includes the
+ number of subdirectories in the directory, since all
+ those subdirectories point to it.
+ This is too slow on remote drives, so we do without it and
+ set the number of links to 2. */
+
+ syscall_printf ("0 = fstat (, %p) st_atime=%x st_size=%D, st_mode=%p, st_ino=%d, sizeof=%d",
+ buf, buf->st_atime, buf->st_size, buf->st_mode,
+ (int) buf->st_ino, sizeof (*buf));
return 0;
}
@@ -358,20 +364,10 @@ fhandler_disk_file::open (path_conv *real_path, int flags, mode_t mode)
return 0;
}
- if (real_path->isbinary ())
- {
- set_r_binary (1);
- set_w_binary (1);
- }
-
set_has_acls (real_path->has_acls ());
set_isremote (real_path->isremote ());
- if (real_path->isdir ())
- flags |= O_DIROPEN;
-
- int res = this->fhandler_base::open (real_path, flags, mode);
-
+ int res = this->fhandler_base::open (real_path, flags | O_DIROPEN, mode);
if (!res)
goto out;
@@ -381,8 +377,7 @@ fhandler_disk_file::open (path_conv *real_path, int flags, mode_t mode)
The only known file system to date is the SUN NFS Solstice Client 3.1
which returns a valid handle when trying to open a file in a nonexistent
directory. */
- if (real_path->has_buggy_open ()
- && GetFileAttributes (win32_path_name) == (DWORD) -1)
+ if (real_path->has_buggy_open () && !real_path->exists ())
{
debug_printf ("Buggy open detected.");
close ();
@@ -390,9 +385,6 @@ fhandler_disk_file::open (path_conv *real_path, int flags, mode_t mode)
return 0;
}
- if (flags & O_APPEND)
- SetFilePointer (get_handle(), 0, 0, FILE_END);
-
set_symlink_p (real_path->issymlink ());
set_execable_p (real_path->exec_state ());
set_socket_p (real_path->issocket ());
@@ -429,10 +421,10 @@ fhandler_disk_file::close ()
int
fhandler_disk_file::lock (int cmd, struct flock *fl)
{
- int win32_start;
+ __off64_t win32_start;
int win32_len;
DWORD win32_upper;
- DWORD startpos;
+ __off64_t startpos;
/*
* We don't do getlck calls yet.
@@ -455,18 +447,19 @@ fhandler_disk_file::lock (int cmd, struct flock *fl)
startpos = 0;
break;
case SEEK_CUR:
- if ((off_t) (startpos = lseek (0, SEEK_CUR)) == (off_t)-1)
+ if ((startpos = lseek (0, SEEK_CUR)) == ILLEGAL_SEEK)
return -1;
break;
case SEEK_END:
{
BY_HANDLE_FILE_INFORMATION finfo;
- if (GetFileInformationByHandle (get_handle(), &finfo) == 0)
+ if (GetFileInformationByHandle (get_handle (), &finfo) == 0)
{
__seterrno ();
return -1;
}
- startpos = finfo.nFileSizeLow; /* Nowhere to keep high word */
+ startpos = ((__off64_t)finfo.nFileSizeHigh << 32)
+ + finfo.nFileSizeLow;
break;
}
default:
@@ -676,37 +669,6 @@ fhandler_disk_file::readdir (DIR *dir)
}
}
- /* Compute d_ino by combining filename hash with the directory hash
- (which was stored in dir->__d_dirhash when opendir was called). */
- if (buf.cFileName[0] == '.')
- {
- if (buf.cFileName[1] == '\0')
- dir->__d_dirent->d_ino = dir->__d_dirhash;
- else if (buf.cFileName[1] != '.' || buf.cFileName[2] != '\0')
- goto hashit;
- else
- {
- char *p, up[strlen (dir->__d_dirname) + 1];
- strcpy (up, dir->__d_dirname);
- if (!(p = strrchr (up, '\\')))
- goto hashit;
- *p = '\0';
- if (!(p = strrchr (up, '\\')))
- dir->__d_dirent->d_ino = hash_path_name (0, ".");
- else
- {
- *p = '\0';
- dir->__d_dirent->d_ino = hash_path_name (0, up);
- }
- }
- }
- else
- {
- hashit:
- ino_t dino = hash_path_name (dir->__d_dirhash, "\\");
- dir->__d_dirent->d_ino = hash_path_name (dino, buf.cFileName);
- }
-
dir->__d_position++;
res = dir->__d_dirent;
syscall_printf ("%p = readdir (%p) (%s)",
@@ -714,14 +676,14 @@ fhandler_disk_file::readdir (DIR *dir)
return res;
}
-off_t
+__off64_t
fhandler_disk_file::telldir (DIR *dir)
{
return dir->__d_position;
}
void
-fhandler_disk_file::seekdir (DIR *dir, off_t loc)
+fhandler_disk_file::seekdir (DIR *dir, __off64_t loc)
{
rewinddir (dir);
while (loc > dir->__d_position)
@@ -764,14 +726,18 @@ void
fhandler_cygdrive::set_drives ()
{
const int len = 1 + 26 * DRVSZ;
- win32_path_name = (char *) crealloc (win32_path_name, len);
-
- ndrives = GetLogicalDriveStrings (len, win32_path_name) / DRVSZ;
- pdrive = win32_path_name;
+ char *p = (char *) crealloc ((void *) win32_path_name,
+ sizeof (".") + sizeof ("..") + len);
+
+ win32_path_name = pdrive = p;
+ strcpy (p, ".");
+ strcpy (p + sizeof ("."), "..");
+ p += sizeof (".") + sizeof ("..");
+ ndrives = GetLogicalDriveStrings (len, p) / DRVSZ;
}
int
-fhandler_cygdrive::fstat (struct stat *buf, path_conv *pc)
+fhandler_cygdrive::fstat (struct __stat64 *buf, path_conv *pc)
{
if (!iscygdrive_root ())
return fhandler_disk_file::fstat (buf, pc);
@@ -804,33 +770,40 @@ fhandler_cygdrive::readdir (DIR *dir)
set_errno (ENMFILE);
return NULL;
}
- if (GetFileAttributes (pdrive) == (DWORD) -1)
+ else if (dir->__d_position > 1
+ && GetFileAttributes (pdrive) == INVALID_FILE_ATTRIBUTES)
{
- pdrive += DRVSZ;
+ pdrive = strchr (pdrive, '\0') + 1;
return readdir (dir);
}
- *dir->__d_dirent->d_name = cyg_tolower (*pdrive);
- dir->__d_dirent->d_name[1] = '\0';
+ else if (*pdrive == '.')
+ strcpy (dir->__d_dirent->d_name, pdrive);
+ else
+ {
+ *dir->__d_dirent->d_name = cyg_tolower (*pdrive);
+ dir->__d_dirent->d_name[1] = '\0';
+ }
dir->__d_position++;
- pdrive += DRVSZ;
+ pdrive = strchr (pdrive, '\0') + 1;
syscall_printf ("%p = readdir (%p) (%s)", &dir->__d_dirent, dir,
- dir->__d_dirent->d_name);
+ dir->__d_dirent->d_name);
return dir->__d_dirent;
}
-off_t
+__off64_t
fhandler_cygdrive::telldir (DIR *dir)
{
return fhandler_disk_file::telldir (dir);
}
void
-fhandler_cygdrive::seekdir (DIR *dir, off_t loc)
+fhandler_cygdrive::seekdir (DIR *dir, __off64_t loc)
{
if (!iscygdrive_root ())
return fhandler_disk_file::seekdir (dir, loc);
- for (pdrive = win32_path_name, dir->__d_position = -1; *pdrive; pdrive += DRVSZ)
+ for (pdrive = win32_path_name, dir->__d_position = -1; *pdrive;
+ pdrive = strchr (pdrive, '\0') + 1)
if (++dir->__d_position >= loc)
break;