Forum: PC-Programmierung cygwin: stat access modify change


von Daniel -. (root)


Lesenswert?

Hallo,

ich habe gerade ein Experiment gemacht
hier ist das Bash Skript
1
#!/usr/bin/bash
2
3
[ -e data ] && echo "datei existiert bereits" && exit 1
4
touch data
5
stat data | tail -3
6
echo
7
#postcondition: alle zeiten gleich =: X
8
9
sleep 10
10
chmod 755 data
11
stat data | tail -3
12
echo
13
#postcondition: change hat einen 10 sec alteren wert (X+10)
14
15
sleep 10
16
echo "1 2 3" >> data
17
stat data | tail -3
18
echo
19
#postcondition: modify hat einen 20 sec alteren wert (X+20)
20
21
sleep 10
22
cat data
23
stat data | tail -3
24
#postcondition: access hat einen 30 sec alteren wert (X+30)


und hier die Ergebnisse
1
$ ./sk.sh
2
Access: 2010-11-27 21:10:31.108964300 +0100
3
Modify: 2010-11-27 21:10:31.108964300 +0100
4
Change: 2010-11-27 21:10:31.106945200 +0100
5
6
Access: 2010-11-27 21:10:31.108964300 +0100
7
Modify: 2010-11-27 21:10:31.108964300 +0100
8
Change: 2010-11-27 21:10:41.371950400 +0100
9
10
Access: 2010-11-27 21:10:31.108964300 +0100
11
Modify: 2010-11-27 21:10:51.550955400 +0100
12
Change: 2010-11-27 21:10:51.550955400 +0100
13
14
1 2 3
15
Access: 2010-11-27 21:10:31.108964300 +0100
16
Modify: 2010-11-27 21:10:51.550955400 +0100
17
Change: 2010-11-27 21:10:51.550955400 +0100

Meine Erwartungen sind im Skript als "postconditions"
festgehalten.
chmod ändert erwartungsgemäss "change time", die als letzte
der 3-Zeilen erscheint.
Ein append ist eigentlich ein write und damit ein modify ..
würde ich erwarten. Seltsamerweise ändert sich "change time" nochmal.
Und zuletzt lese ich die Datei einfach mit cat. Allerdings
ändert sich, wie man sehen kann, dabei gar nichts.

Ich habe das unter Cygwin getestet. Deswegen meine Frage ..
verstehe ich die Semantik von access/modify/change falsch?
Werden beim "echo >>" syscalls getätigt die change time ändern?
Oder liegt es schlicht an cygwin (da nicht ext3 Dateisystem)
Vielleicht kann jemand unter Linux das Skript testen.

Grüsse

von AS (Gast)


Lesenswert?

Daniel -------- schrieb:
> Ein append ist eigentlich ein write und damit ein modify ..
> würde ich erwarten. Seltsamerweise ändert sich "change time" nochmal.

Das ist nicht seltsam, das ist normal.

von Daniel -. (root)


Lesenswert?

ich habe mich nach diesen Infos gerichtet

There are 3 kind of "timestamps":

* Access - the last time the file was read
* Modify - the last time the file was modified (content has been 
modified)
* Change - the last time meta data of the file was changed (e.g.
permissions)

http://unix.stackexchange.com/questions/2802/what-is-the-difference-between-modify-and-change-in-stat-command-context

von Daniel -. (root)


Lesenswert?

hier nochmal etwas genauer
1
st_atime is the access time, updated on read(2) calls (and probably also 
2
when open(2) opens a file for reading) -- it is NOT updated when files are 
3
read via mmap(2). (Which is why I assume open(2) will mark the access time.)
4
5
st_mtime is the data modification time, either via write(2) or truncate(2) 
6
or open(2) for writing. (Again, it is NOT updated when files are written 
7
via mmap(2).)
8
9
st_ctime is the metadata modification time: when any of the other data in 
10
the struct stat gets modified.

Quelle: 
http://stackoverflow.com/questions/3385203/regarding-access-time-unix

demnach müsste doch "access time" beim "cat data" aktualisiert werden.

von AS (Gast)


Lesenswert?

Dann gurgle ich mal für Dich ;-)

<< Note that ctime has nothing to do with file creation time. It is 
updated any time file content changes (together with mtime), and also by 
changes in metadata such as file permissions, file ownership, and 
creation and deletion of hard links. In some implementations, ctime is 
affected by renaming a file (both original Unix and modern Linux tend to 
do this).
Unlike atime and mtime, ctime cannot be set with utime() (as used e.g. 
by touch); the only way to set it to an arbitrary value is by changing 
the system clock. >>

Quelle: <<http://en.wikipedia.org/wiki/Stat_(Unix)%20


Abgesehen davon ^^^, hat Deine Datei nach

  echo "1 2 3" >> data

eine andere Größe, also andere "Metadaten".
Alleine das wäre schon eine Änderung von ctime wert...

von AS (Gast)


Lesenswert?

Hatte ich übersehen:

Daniel -------- schrieb:
> demnach müsste doch "access time" beim "cat data" aktualisiert werden.

Nur auf POSIX konformen Systemen
(steht aber bestimmt auch in dem Link da oben ^^^)

von Daniel -. (root)


Lesenswert?

Du meinst im Abschnitt "Criticism of atime"?
Scheinbar verzichtet Cygwin aus diesem Grund auf Updates von atime.
Ok. Danke für die wiki Seite.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.