From 623ac3db4f99bfdbab5b72fd09374a26f7793526 Mon Sep 17 00:00:00 2001 From: cgf Date: Sun, 2 Jun 2002 03:13:22 +0000 Subject: [PATCH] * fhandler.cc (fhandler_base::fstat): Move dev and ino calculation into caller. * syscalls.cc (stat_worker): Calculate dev and ino calculation here, if zero. * fhandler_proc.cc (fhandler_proc::fhandler_proc): Minor reorg for debugging. * fhandler_process.cc (fhandler_process::exists): Return 0 on nonexistence. (fhandler_process::fstat): Simplify pid logic. * fhandler_tape.cc (fhandler_dev_tape::fstat): Minor reformatting. --- winsup/cygwin/ChangeLog | 13 +++++++++++++ winsup/cygwin/fhandler.cc | 2 -- winsup/cygwin/fhandler_proc.cc | 3 ++- winsup/cygwin/fhandler_process.cc | 19 ++++++------------- winsup/cygwin/fhandler_tape.cc | 6 ++---- winsup/cygwin/syscalls.cc | 22 ++++++++++++++-------- 6 files changed, 37 insertions(+), 28 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 9e1f51325b..e5ed794c8c 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,18 @@ 2002-06-01 Christopher Faylor + * fhandler.cc (fhandler_base::fstat): Move dev and ino calculation into + caller. + * syscalls.cc (stat_worker): Calculate dev and ino calculation here, if + zero. + * fhandler_proc.cc (fhandler_proc::fhandler_proc): Minor reorg for + debugging. + * fhandler_process.cc (fhandler_process::exists): Return 0 on + nonexistence. + (fhandler_process::fstat): Simplify pid logic. + * fhandler_tape.cc (fhandler_dev_tape::fstat): Minor reformatting. + +2002-06-01 Christopher Faylor + * path.cc (chdir): Don't allow cd'ing to a non-directory virtual path. 2002-05-31 Christopher Faylor diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 00a8e0b0bc..2e2d0d0764 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -839,8 +839,6 @@ fhandler_base::fstat (struct __stat64 *buf, path_conv *) buf->st_mode |= get_device () == FH_FLOPPY ? S_IFBLK : S_IFCHR; buf->st_nlink = 1; buf->st_blksize = S_BLKSIZE; - buf->st_dev = buf->st_rdev = FHDEVN (get_device ()) << 8 | (get_unit () & 0xff); - buf->st_ino = get_namehash (); buf->st_atime = buf->st_mtime = buf->st_ctime = time (NULL) - 1; return 0; } diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc index 27a8220968..aa2324ef5d 100644 --- a/winsup/cygwin/fhandler_proc.cc +++ b/winsup/cygwin/fhandler_proc.cc @@ -161,8 +161,9 @@ fhandler_proc::fhandler_proc (DWORD devtype): int fhandler_proc::fstat (struct __stat64 *buf, path_conv *pc) { - debug_printf ("fstat (%s)", get_name ()); const char *path = get_name (); + debug_printf ("fstat (%s)", path); + path += proc_len; (void) fhandler_base::fstat (buf, pc); diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc index 3858a21161..35f1c7bb43 100644 --- a/winsup/cygwin/fhandler_process.cc +++ b/winsup/cygwin/fhandler_process.cc @@ -87,7 +87,7 @@ fhandler_process::exists () for (int i = 0; process_listing[i]; i++) if (pathmatch (path + 1, process_listing[i])) return -1; - return 1; + return 0; } fhandler_process::fhandler_process (): @@ -104,20 +104,13 @@ fhandler_process::fstat (struct __stat64 *buf, path_conv *pc) path += proc_len + 1; int pid = atoi (path); winpids pids; - _pinfo *p; - for (unsigned i = 0; i < pids.npids; i++) + pinfo p (pid); + if (!p) { - p = pids[i]; - - if (!proc_exists (p)) - continue; - - if (p->pid == pid) - goto found; + set_errno(ENOENT); + return -1; } - set_errno(ENOENT); - return -1; -found: + buf->st_mode &= ~_IFMT & NO_W; switch (file_type) diff --git a/winsup/cygwin/fhandler_tape.cc b/winsup/cygwin/fhandler_tape.cc index 6b9bd1f4db..a7a3bbe914 100644 --- a/winsup/cygwin/fhandler_tape.cc +++ b/winsup/cygwin/fhandler_tape.cc @@ -155,10 +155,8 @@ fhandler_dev_tape::fstat (struct __stat64 *buf, path_conv *pc) { struct mtget get; - if (! ioctl (MTIOCGET, &get)) - { - buf->st_blocks = get.mt_capacity / buf->st_blksize; - } + if (!ioctl (MTIOCGET, &get)) + buf->st_blocks = get.mt_capacity / buf->st_blksize; } return ret; diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 969389f312..a936a21fd1 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1073,18 +1073,17 @@ stat_worker (const char *name, struct __stat64 *buf, int nofollow, path_conv real_path; fhandler_base *fh = NULL; - if (!pc) - pc = &real_path; - - MALLOC_CHECK; if (check_null_invalid_struct_errno (buf)) goto done; + if (!pc) + pc = &real_path; + fh = cygheap->fdtab.build_fhandler_from_name (-1, name, NULL, *pc, - (nofollow ? - PC_SYM_NOFOLLOW - : PC_SYM_FOLLOW) + (nofollow ? PC_SYM_NOFOLLOW + : PC_SYM_FOLLOW) | PC_FULL, stat_suffixes); + if (pc->error) { debug_printf ("got %d error from build_fhandler_from_name", pc->error); @@ -1094,8 +1093,15 @@ stat_worker (const char *name, struct __stat64 *buf, int nofollow, { debug_printf ("(%s, %p, %d, %p), file_attributes %d", name, buf, nofollow, pc, (DWORD) real_path); - memset (buf, 0, sizeof (struct __stat64)); + memset (buf, 0, sizeof (*buf)); res = fh->fstat (buf, pc); + if (!res) + { + if (!buf->st_ino) + buf->st_ino = hash_path_name (0, fh->get_win32_name ()); + if (!buf->st_dev) + buf->st_dev = FHDEVN (fh->get_device ()) << 8 | (fh->get_unit () & 0xff); + } } done: -- 2.11.0