Google Ryhmät ei enää tue uusia Usenet-postauksia tai ‐tilauksia. Aiempi sisältö on edelleen nähtävissä.

open regular file = lstat + open + fcntl + ioctl ?

61 katselukertaa
Siirry ensimmäiseen lukemattomaan viestiin

xavier.d...@gmail.com

lukematon,
21.1.2018 klo 14.59.1321.1.2018
vastaanottaja
Hello,

Looking at what happens when opening a regular file in Tcl to read it. I discovered that a lot of syscall are made in addition to the 'open' call.

I am running on Linux, and tracing the "/path/to/file" file opening on Tcl 8.6.6 gives:

lstat("/path", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/path/to", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/path/to/file", O_RDONLY) = 3
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
ioctl(3, TCGETS, 0x7fff5efc0740) = -1 ENOTTY (Inappropriate ioctl for device)

I am working on a Tcl software where hundreds of files in a directory tree need to be read [1]. I would like to optimize this process so I wonder how the total number of syscalls can be reduced.

Is there a way to open a file for read only that will only produce a 'open' call to the system?

Regards,
Xavier

[1] http://modules.sourceforge.net/

Brad Lanam

lukematon,
21.1.2018 klo 16.02.5921.1.2018
vastaanottaja
If you want to reduce the number of calls to lstat(),
which is checking for symlinks and path permissions,
first change your working directory to the directory containing the files.

cd /path/to
set fh [open file1 r]

I don't think you will be able to reduce the number of system calls
much more than that.


briang

lukematon,
21.1.2018 klo 17.50.3321.1.2018
vastaanottaja
If you are counting sys calls, you should be writing in C. You could write your own extension open command.

Eliminating those sys calls will reduce error detection and thus reliability.

-Brian

xavier.d...@gmail.com

lukematon,
23.1.2018 klo 0.01.4223.1.2018
vastaanottaja
Thanks for these hints. I was thinking also to handle that with an extension written in C. But for the sake of the maintainability I would prefer that some enhancement would be done at the Tcl source code directly.

Especially I do not understand what are the benefit for:
* the "lstat" cascading: if there is a permission issue, "open" will tell it
* analysing the content of a directory, each file opening within the directory will redo the same "lstat" starting from filesystem root, maybe it can only be done once
* the "ioctl" call: it does not seem appropriate on a regular file

Regards,
Xavier

briang

lukematon,
23.1.2018 klo 1.06.3623.1.2018
vastaanottaja
At any time a virtual file system can be mounted at any point along the path. For each open the path must be checked just in case it changed. The lstat is actually the last check.

-Brian

Rich

lukematon,
23.1.2018 klo 6.31.2023.1.2018
vastaanottaja
xavier.d...@gmail.com wrote:
> * the "ioctl" call: it does not seem appropriate on a regular file

The tty devices are just "regular files" from the perspective of an
open() call. The ioctl is to see if the file, that was just opened, is
a tty device or not.

The reason is to likely do something different when the file /is/ a tty
device.
0 uutta viestiä