Mail Archives: djgpp-workers/2003/01/20/09:23:19
Hello.
Eli Zaretskii wrote:
>
> > Date: Sun, 12 Jan 2003 16:01:53 +0000
> > From: "Richard Dawe" <rich AT phekda DOT freeserve DOT co DOT uk>
[snip]
> > Basically: The patch uses fd_props to obtain the file name used
> > to open a file. It fixes up the file name and then uses
> > that as the input to _invent_inode.
>
> Did you try to see what does this do with (a) handles open on devices,
> and (b) redirected handles?
Results for (a):
bash-2.04$ echo $CMD
./fstat.exe 0 /dev/null /dev/null con /dev/con c:/dev/con c:/dev/tty
bash-2.04$ $CMD
handle-0: -1 268435457 20644 1 42 0 1043068808 Mon Jan 20 13:20:08 2003
Everything checks out OK
handle-1: -1 268435457 20644 1 42 0 1043068808 Mon Jan 20 13:20:08 2003
Everything checks out OK
handle-2: -1 268435457 20644 1 42 0 1043068808 Mon Jan 20 13:20:08 2003
Everything checks out OK
handle-3: -1 268435458 20644 1 42 0 1043068808 Mon Jan 20 13:20:08 2003
Everything checks out OK
handle-4: -1 268435459 20644 1 42 0 1043068808 Mon Jan 20 13:20:08 2003
Everything checks out OK
/dev/null (7): -1 268435460 20644 1 42 0 1043068808 Mon Jan 20 13:20:08 2003
Times: 1043068808 312768000
Block size: 4096
Everything checks out OK
/dev/null (8): -1 268435460 20644 1 42 0 1043068808 Mon Jan 20 13:20:08 2003
Times: 1043068808 312768000
Block size: 4096
Everything checks out OK
con (9): -1 268435457 20644 1 42 0 1043068808 Mon Jan 20 13:20:08 2003
Times: 1043068808 312768000
Block size: 4096
Everything checks out OK
/dev/con (10): -1 268435457 20644 1 42 0 1043068808 Mon Jan 20 13:20:08 2003
Times: 1043068808 312768000
Block size: 4096
Everything checks out OK
c:/dev/con (11): -1 268435457 20644 1 42 0 1043068808 Mon Jan 20 13:20:08 2003
Times: 1043068808 312768000
Block size: 4096
Everything checks out OK
c:/dev/tty (12): -1 268435457 20644 1 42 0 1043068808 Mon Jan 20 13:20:08 2003
Times: 1043068808 312768000
Block size: 4096
Everything checks out OK
Test program for (b):
---Start fstat-redir.c---
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/stat.h>
void
fstat_it (const char *argv0, const int fd)
{
struct stat stat_buf;
if (fstat(fd, &stat_buf) < 0)
{
perror(argv0);
exit(EXIT_FAILURE);
}
/* Nicked from src/libc/posix/sys/stat/fstat.c */
fprintf(stderr, "%s (%d): %d %6u %o %d %d %ld %lu %s", argv0, fd,
stat_buf.st_dev,
(unsigned)stat_buf.st_ino,
stat_buf.st_mode,
stat_buf.st_nlink,
stat_buf.st_uid,
(long)stat_buf.st_size,
(unsigned long)stat_buf.st_mtime,
ctime(&stat_buf.st_mtime));
fprintf (stderr, "\t\t\tTimes: %lu %lu\n",
(unsigned long)stat_buf.st_atime,
(unsigned long)stat_buf.st_ctime);
fprintf(stderr, "\t\t\tBlock size: %d\n",
stat_buf.st_blksize);
_djstat_describe_lossage(stderr);
}
int
main (int argc, char *argv[])
{
fstat_it(argv[0], fileno(stdin));
fstat_it(argv[0], fileno(stdout));
puts("wibble");
return(EXIT_SUCCESS);
}
---End fstat-redir.c---
Results for (b):
bash-2.04$ rm -f foo foo2
bash-2.04$ echo blahblahblah > foo
bash-2.04$ ./fstat-redir <foo >foo2
c:/djgpp.204/rdawe-test/fstat/fstat-redir (0): 2 268435457 644 1 42 14
104307015
8 Mon Jan 20 13:42:38 2003
Times: 1043070158 1043070156
Block size: 16384
Failed to get starting cluster number; inode defaults to hashing
(if no other messages were printed, then this is either an empty
file on a local disk drive, or a file on a networked drive, or
you run under some kind of DOS clone)
SFT entry found, but is inconsistent with file size and time stamp
c:/djgpp.204/rdawe-test/fstat/fstat-redir (1): 2 268435458 644 1 42 0
1043070160
Mon Jan 20 13:42:40 2003
Times: 1043070160 1043070158
Block size: 16384
Failed to get starting cluster number; inode defaults to hashing
(if no other messages were printed, then this is either an empty
file on a local disk drive, or a file on a networked drive, or
you run under some kind of DOS clone)
SFT entry found, but is inconsistent with file size and time stamp
bash-2.04$ ./fstat-redir
c:/djgpp.204/rdawe-test/fstat/fstat-redir (0): -1 268435457 20644 1 42 0
1043070
165 Mon Jan 20 13:42:45 2003
Times: 1043070165 312768000
Block size: 16384
Everything checks out OK
c:/djgpp.204/rdawe-test/fstat/fstat-redir (1): -1 268435457 20644 1 42 0
1043070
165 Mon Jan 20 13:42:45 2003
Times: 1043070165 312768000
Block size: 16384
Everything checks out OK
wibble
> Also, if you run _fixpath on a file name in a place other than where
> the file is actually opened, the program might be in a different
> directory, so _fixpath will produce incorrect results. Therefore, I
> believe that if we want to use fd_props for this, we should run
> _fixpath on the file name when its info is recorded in fd_props.
> Then fstat should simply reuse the absolute name.
Well, it turns out that __set_fd_properties() runs the file name through
_truename(), before storing it. I think _truename() is sufficient - I don't
think we need to call _fixpath in fstat(). I think we can just use whatever
__get_fd_name() returns.
Bye, Rich =]
--
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]
- Raw text -