* syscalls.cc (stat_worker): Make stat return correct st_blocks for files with

size bigger than 2Gb and less than 4Gb
This commit is contained in:
Christopher Faylor 2000-07-26 17:48:49 +00:00
parent a246b47b67
commit f489e86b8f
2 changed files with 155 additions and 149 deletions

View File

@ -1,3 +1,8 @@
Wed Jul 26 14:32:38 2000 Egor Duda <deo@logos-m.ru>
* syscalls.cc (stat_worker): Make stat return correct st_blocks for
files with size bigger than 2Gb and less than 4Gb
Wed Jul 26 17:43:00 2000 Corinna Vinschen <corinna@vinschen.de> Wed Jul 26 17:43:00 2000 Corinna Vinschen <corinna@vinschen.de>
* security.cc (lookup_name): Search on local machine first if * security.cc (lookup_name): Search on local machine first if

View File

@ -689,36 +689,36 @@ chown_worker (const char *name, unsigned fmode, uid_t uid, gid_t gid)
DWORD attrib = 0; DWORD attrib = 0;
if (win32_path.file_attributes () & FILE_ATTRIBUTE_DIRECTORY) if (win32_path.file_attributes () & FILE_ATTRIBUTE_DIRECTORY)
attrib |= S_IFDIR; attrib |= S_IFDIR;
res = get_file_attribute (win32_path.has_acls (), res = get_file_attribute (win32_path.has_acls (),
win32_path.get_win32 (), win32_path.get_win32 (),
(int *) &attrib, (int *) &attrib,
&old_uid, &old_uid,
&old_gid); &old_gid);
if (!res) if (!res)
{ {
if (uid == (uid_t) -1) if (uid == (uid_t) -1)
uid = old_uid; uid = old_uid;
if (gid == (gid_t) -1) if (gid == (gid_t) -1)
gid = old_gid; gid = old_gid;
if (win32_path.file_attributes () & FILE_ATTRIBUTE_DIRECTORY) if (win32_path.file_attributes () & FILE_ATTRIBUTE_DIRECTORY)
attrib |= S_IFDIR; attrib |= S_IFDIR;
res = set_file_attribute (win32_path.has_acls (), res = set_file_attribute (win32_path.has_acls (),
win32_path.get_win32 (), win32_path.get_win32 (),
uid, gid, attrib, uid, gid, attrib,
myself->logsrv); myself->logsrv);
} }
if (res != 0 && get_errno () == ENOSYS) if (res != 0 && get_errno () == ENOSYS)
{ {
/* fake - if not supported, pretend we're like win95 /* fake - if not supported, pretend we're like win95
where it just works */ where it just works */
res = 0; res = 0;
} }
} }
done: done:
syscall_printf ("%d = %schown (%s,...)", syscall_printf ("%d = %schown (%s,...)",
res, (fmode & PC_SYM_IGNORE) ? "l" : "", name); res, (fmode & PC_SYM_IGNORE) ? "l" : "", name);
return res; return res;
} }
@ -757,7 +757,7 @@ fchown (int fd, uid_t uid, gid_t gid)
} }
syscall_printf ("fchown (%d,...): calling chown_worker (%s,FOLLOW,...)", syscall_printf ("fchown (%d,...): calling chown_worker (%s,FOLLOW,...)",
fd, path); fd, path);
return chown_worker (path, PC_SYM_FOLLOW, uid, gid); return chown_worker (path, PC_SYM_FOLLOW, uid, gid);
} }
@ -809,14 +809,14 @@ chmod (const char *path, mode_t mode)
gid_t gid; gid_t gid;
if (win32_path.file_attributes () & FILE_ATTRIBUTE_DIRECTORY) if (win32_path.file_attributes () & FILE_ATTRIBUTE_DIRECTORY)
mode |= S_IFDIR; mode |= S_IFDIR;
get_file_attribute (win32_path.has_acls (), get_file_attribute (win32_path.has_acls (),
win32_path.get_win32 (), win32_path.get_win32 (),
NULL, &uid, &gid); NULL, &uid, &gid);
if (win32_path.file_attributes () & FILE_ATTRIBUTE_DIRECTORY) if (win32_path.file_attributes () & FILE_ATTRIBUTE_DIRECTORY)
mode |= S_IFDIR; mode |= S_IFDIR;
if (! set_file_attribute (win32_path.has_acls (), if (! set_file_attribute (win32_path.has_acls (),
win32_path.get_win32 (), win32_path.get_win32 (),
uid, gid, uid, gid,
mode, myself->logsrv) mode, myself->logsrv)
&& allow_ntsec) && allow_ntsec)
@ -1030,8 +1030,8 @@ stat_worker (const char *caller, const char *name, struct stat *buf,
if ((atts == -1 || !(atts & FILE_ATTRIBUTE_DIRECTORY) || if ((atts == -1 || !(atts & FILE_ATTRIBUTE_DIRECTORY) ||
(os_being_run == winNT (os_being_run == winNT
&& dtype != DRIVE_NO_ROOT_DIR && dtype != DRIVE_NO_ROOT_DIR
&& dtype != DRIVE_UNKNOWN)) && dtype != DRIVE_UNKNOWN))
&& (oret = fh.open (real_path, O_RDONLY | O_BINARY | O_DIROPEN | && (oret = fh.open (real_path, O_RDONLY | O_BINARY | O_DIROPEN |
(nofollow ? O_NOSYMLINK : 0), 0))) (nofollow ? O_NOSYMLINK : 0), 0)))
{ {
@ -1039,58 +1039,59 @@ stat_worker (const char *caller, const char *name, struct stat *buf,
fh.close (); fh.close ();
/* The number of links to a directory includes the /* The number of links to a directory includes the
number of subdirectories in the directory, since all number of subdirectories in the directory, since all
those subdirectories point to it. those subdirectories point to it.
This is too slow on remote drives, so we do without it and This is too slow on remote drives, so we do without it and
set the number of links to 2. */ set the number of links to 2. */
/* Unfortunately the count of 2 confuses `find(1)' command. So /* Unfortunately the count of 2 confuses `find(1)' command. So
let's try it with `1' as link count. */ let's try it with `1' as link count. */
if (atts != -1 && (atts & FILE_ATTRIBUTE_DIRECTORY)) if (atts != -1 && (atts & FILE_ATTRIBUTE_DIRECTORY))
buf->st_nlink = buf->st_nlink =
(dtype == DRIVE_REMOTE ? 1 : num_entries (real_path.get_win32 ())); (dtype == DRIVE_REMOTE ? 1 : num_entries (real_path.get_win32 ()));
} }
else if (atts != -1 || (!oret && get_errno () != ENOENT else if (atts != -1 || (!oret && get_errno () != ENOENT
&& get_errno () != ENOSHARE)) && get_errno () != ENOSHARE))
{ {
/* Unfortunately, the above open may fail if the file exists, though. /* Unfortunately, the above open may fail if the file exists, though.
So we have to care for this case here, too. */ So we have to care for this case here, too. */
WIN32_FIND_DATA wfd; WIN32_FIND_DATA wfd;
HANDLE handle; HANDLE handle;
buf->st_nlink = 1; buf->st_nlink = 1;
if (atts != -1 if (atts != -1
&& (atts & FILE_ATTRIBUTE_DIRECTORY) && (atts & FILE_ATTRIBUTE_DIRECTORY)
&& dtype != DRIVE_REMOTE) && dtype != DRIVE_REMOTE)
buf->st_nlink = num_entries (real_path.get_win32 ()); buf->st_nlink = num_entries (real_path.get_win32 ());
buf->st_dev = FHDEVN(FH_DISK) << 8; buf->st_dev = FHDEVN(FH_DISK) << 8;
buf->st_ino = hash_path_name (0, real_path.get_win32 ()); buf->st_ino = hash_path_name (0, real_path.get_win32 ());
if (atts != -1 && (atts & FILE_ATTRIBUTE_DIRECTORY)) if (atts != -1 && (atts & FILE_ATTRIBUTE_DIRECTORY))
buf->st_mode = S_IFDIR; buf->st_mode = S_IFDIR;
else if (real_path.issymlink ()) else if (real_path.issymlink ())
buf->st_mode = S_IFLNK; buf->st_mode = S_IFLNK;
else if (real_path.issocket ()) else if (real_path.issocket ())
buf->st_mode = S_IFSOCK; buf->st_mode = S_IFSOCK;
else else
buf->st_mode = S_IFREG; buf->st_mode = S_IFREG;
if (!real_path.has_acls () if (!real_path.has_acls ()
|| get_file_attribute (real_path.has_acls (), real_path.get_win32 (), || get_file_attribute (real_path.has_acls (), real_path.get_win32 (),
&buf->st_mode, &buf->st_uid, &buf->st_gid)) &buf->st_mode, &buf->st_uid, &buf->st_gid))
{ {
buf->st_mode |= STD_RBITS | STD_XBITS; buf->st_mode |= STD_RBITS | STD_XBITS;
if ((atts & FILE_ATTRIBUTE_READONLY) == 0) if ((atts & FILE_ATTRIBUTE_READONLY) == 0)
buf->st_mode |= STD_WBITS; buf->st_mode |= STD_WBITS;
get_file_attribute (FALSE, real_path.get_win32 (), get_file_attribute (FALSE, real_path.get_win32 (),
NULL, &buf->st_uid, &buf->st_gid); NULL, &buf->st_uid, &buf->st_gid);
} }
if ((handle = FindFirstFile (real_path.get_win32(), &wfd)) if ((handle = FindFirstFile (real_path.get_win32(), &wfd))
!= INVALID_HANDLE_VALUE) != INVALID_HANDLE_VALUE)
{ {
buf->st_atime = to_time_t (&wfd.ftLastAccessTime); buf->st_atime = to_time_t (&wfd.ftLastAccessTime);
buf->st_mtime = to_time_t (&wfd.ftLastWriteTime); buf->st_mtime = to_time_t (&wfd.ftLastWriteTime);
buf->st_ctime = to_time_t (&wfd.ftCreationTime); buf->st_ctime = to_time_t (&wfd.ftCreationTime);
buf->st_size = wfd.nFileSizeLow; buf->st_size = wfd.nFileSizeLow;
buf->st_blksize = S_BLKSIZE; buf->st_blksize = S_BLKSIZE;
buf->st_blocks = (buf->st_size + S_BLKSIZE-1) / S_BLKSIZE; buf->st_blocks = ((unsigned long) buf->st_size +
FindClose (handle); S_BLKSIZE-1) / S_BLKSIZE;
} FindClose (handle);
}
res = 0; res = 0;
} }
@ -1139,47 +1140,47 @@ access (const char *fn, int flags)
if (flags & R_OK) if (flags & R_OK)
{ {
if (st.st_uid == myself->uid) if (st.st_uid == myself->uid)
{ {
if (!(st.st_mode & S_IRUSR)) if (!(st.st_mode & S_IRUSR))
goto done; goto done;
} }
else if (st.st_gid == myself->gid) else if (st.st_gid == myself->gid)
{ {
if (!(st.st_mode & S_IRGRP)) if (!(st.st_mode & S_IRGRP))
goto done; goto done;
} }
else if (!(st.st_mode & S_IROTH)) else if (!(st.st_mode & S_IROTH))
goto done; goto done;
} }
if (flags & W_OK) if (flags & W_OK)
{ {
if (st.st_uid == myself->uid) if (st.st_uid == myself->uid)
{ {
if (!(st.st_mode & S_IWUSR)) if (!(st.st_mode & S_IWUSR))
goto done; goto done;
} }
else if (st.st_gid == myself->gid) else if (st.st_gid == myself->gid)
{ {
if (!(st.st_mode & S_IWGRP)) if (!(st.st_mode & S_IWGRP))
goto done; goto done;
} }
else if (!(st.st_mode & S_IWOTH)) else if (!(st.st_mode & S_IWOTH))
goto done; goto done;
} }
if (flags & X_OK) if (flags & X_OK)
{ {
if (st.st_uid == myself->uid) if (st.st_uid == myself->uid)
{ {
if (!(st.st_mode & S_IXUSR)) if (!(st.st_mode & S_IXUSR))
goto done; goto done;
} }
else if (st.st_gid == myself->gid) else if (st.st_gid == myself->gid)
{ {
if (!(st.st_mode & S_IXGRP)) if (!(st.st_mode & S_IXGRP))
goto done; goto done;
} }
else if (!(st.st_mode & S_IXOTH)) else if (!(st.st_mode & S_IXOTH))
goto done; goto done;
} }
r = 0; r = 0;
done: done:
@ -1237,7 +1238,7 @@ _rename (const char *oldpath, const char *newpath)
res = -1; res = -1;
if (res == 0 || (GetLastError () != ERROR_ALREADY_EXISTS if (res == 0 || (GetLastError () != ERROR_ALREADY_EXISTS
&& GetLastError () != ERROR_FILE_EXISTS)) && GetLastError () != ERROR_FILE_EXISTS))
goto done; goto done;
if (os_being_run == winNT) if (os_being_run == winNT)
@ -1832,57 +1833,57 @@ seteuid (uid_t uid)
if (os_being_run == winNT) if (os_being_run == winNT)
{ {
if (uid != (uid_t) -1) if (uid != (uid_t) -1)
{ {
struct passwd *pw_new = getpwuid (uid); struct passwd *pw_new = getpwuid (uid);
if (!pw_new) if (!pw_new)
{ {
set_errno (EINVAL); set_errno (EINVAL);
return -1; return -1;
} }
if (uid != myself->uid) if (uid != myself->uid)
if (uid == myself->orig_uid) if (uid == myself->orig_uid)
{ {
debug_printf ("RevertToSelf() (uid == orig_uid, token=%d)", debug_printf ("RevertToSelf() (uid == orig_uid, token=%d)",
myself->token); myself->token);
RevertToSelf(); RevertToSelf();
if (myself->token != INVALID_HANDLE_VALUE) if (myself->token != INVALID_HANDLE_VALUE)
myself->impersonated = FALSE; myself->impersonated = FALSE;
} }
else if (!myself->impersonated) else if (!myself->impersonated)
{ {
debug_printf ("Impersonate(uid == %d)", uid); debug_printf ("Impersonate(uid == %d)", uid);
RevertToSelf(); RevertToSelf();
if (myself->token != INVALID_HANDLE_VALUE) if (myself->token != INVALID_HANDLE_VALUE)
if (!ImpersonateLoggedOnUser (myself->token)) if (!ImpersonateLoggedOnUser (myself->token))
system_printf ("Impersonate(%d) in set(e)uid failed: %E", system_printf ("Impersonate(%d) in set(e)uid failed: %E",
myself->token); myself->token);
else else
myself->impersonated = TRUE; myself->impersonated = TRUE;
} }
struct pinfo pi; struct pinfo pi;
pi.psid = (PSID) pi.sidbuf; pi.psid = (PSID) pi.sidbuf;
/* pi.token is used in internal_getlogin() to determine if /* pi.token is used in internal_getlogin() to determine if
impersonation is active. If so, the token is used for impersonation is active. If so, the token is used for
retrieving user's SID. */ retrieving user's SID. */
pi.token = myself->impersonated ? myself->token pi.token = myself->impersonated ? myself->token
: INVALID_HANDLE_VALUE; : INVALID_HANDLE_VALUE;
struct passwd *pw_cur = getpwnam (internal_getlogin (&pi)); struct passwd *pw_cur = getpwnam (internal_getlogin (&pi));
if (pw_cur != pw_new) if (pw_cur != pw_new)
{ {
debug_printf ("Diffs!!! token: %d, cur: %d, new: %d, orig: %d", debug_printf ("Diffs!!! token: %d, cur: %d, new: %d, orig: %d",
myself->token, pw_cur->pw_uid, myself->token, pw_cur->pw_uid,
pw_new->pw_uid, myself->orig_uid); pw_new->pw_uid, myself->orig_uid);
set_errno (EPERM); set_errno (EPERM);
return -1; return -1;
} }
myself->uid = uid; myself->uid = uid;
strcpy (myself->username, pi.username); strcpy (myself->username, pi.username);
strcpy (myself->logsrv, pi.logsrv); strcpy (myself->logsrv, pi.logsrv);
strcpy (myself->domain, pi.domain); strcpy (myself->domain, pi.domain);
memcpy (myself->sidbuf, pi.sidbuf, MAX_SID_LEN); memcpy (myself->sidbuf, pi.sidbuf, MAX_SID_LEN);
} }
} }
else else
set_errno (ENOSYS); set_errno (ENOSYS);
@ -1898,14 +1899,14 @@ setegid (gid_t gid)
if (os_being_run == winNT) if (os_being_run == winNT)
{ {
if (gid != (gid_t) -1) if (gid != (gid_t) -1)
{ {
if (!getgrgid (gid)) if (!getgrgid (gid))
{ {
set_errno (EINVAL); set_errno (EINVAL);
return -1; return -1;
} }
myself->gid = gid; myself->gid = gid;
} }
} }
else else
set_errno (ENOSYS); set_errno (ENOSYS);
@ -1920,7 +1921,7 @@ chroot (const char *newroot)
{ {
int ret = -1; int ret = -1;
path_conv path(newroot, PC_SYM_FOLLOW | PC_FULL); path_conv path(newroot, PC_SYM_FOLLOW | PC_FULL);
if (path.error) if (path.error)
goto done; goto done;
if (path.file_attributes () == (DWORD)-1) if (path.file_attributes () == (DWORD)-1)
@ -1934,7 +1935,7 @@ chroot (const char *newroot)
goto done; goto done;
} }
ret = cygwin_shared->mount.conv_to_posix_path (path.get_win32 (), ret = cygwin_shared->mount.conv_to_posix_path (path.get_win32 (),
myself->root, 0); myself->root, 0);
if (ret) if (ret)
{ {
set_errno (ret); set_errno (ret);
@ -1947,7 +1948,7 @@ chroot (const char *newroot)
done: done:
syscall_printf ("%d = chroot (%s)", ret ? get_errno () : 0, syscall_printf ("%d = chroot (%s)", ret ? get_errno () : 0,
newroot ? newroot : "NULL"); newroot ? newroot : "NULL");
return ret; return ret;
} }