rouch acts strange after touching around

hi there

Strange title? Well yes...it is strange..."touch" is driving me nutts! Trying to set the access / modified date by a bash script. For a certain time everything works well with all files. After point x the code works only for some files, for others it doesn't. After looking for the cause, I saw that it is a permission issue..so I checked on which permission the access time is no longer editable.

For me, that doesn't make sense at all. I'm logged in as root and am owner of the file. I also don't know what cause that problem....after a reboot, everything works well again. Had anybody already the same problem? What could cause this strange behavior?

The command:

root@owned:/home/foobar# touch -t 201110101212 test

The output:
if it works:

root@owned:/home/foobar# stat -c "atime: %x  mtime: %y ctime: %z" test
atime: 2011-10-10 12:12:00.000000000 +0200 
mtime: 2011-10-10  12:12:00.000000000 +0200
ctime: 2011-07-13 14:34:04.383508864 +0200

else:

atime: 2011-07-13 14:30:21.398403162 +0200 
mtime: 2011-10-10 12:12:00.000000000 +0200
ctime: 2011-07-13 14:30:20.386398151 +0200

List of permissions where it work / doesn't work:

-r-------- 1 root root 5 2011-07-13 14:11 test //ATIME & MTIME
-rw------- 1 root root 5 2011-10-10 12:11 test //ATIME & MTIME
-rwx------ 1 root root 5 2011-10-10 12:12 test //ATIME & MTIME
  
----r----- 1 root root 5 2011-10-10 12:14 test //ATIME & MTIME
----rw---- 1 root root 5 2011-10-10 12:15 test //ATIME & MTIME
----rwx--- 1 root root 5 2011-10-10 12:16 test //ATIME & MTIME
  
-------r-- 1 root root 5 2011-07-13 14:23 test //MTIME
-------rw- 1 root root 5 2011-07-13 14:25 test //MTIME
-------rwx 1 root root 5 2011-07-13 14:25 test //MTIME
  
-r-----r-- 1 root root 5 2011-07-13 14:27 test //MTIME
-rw----rw- 1 root root 5 2011-07-13 14:28 test //MTIME
  
-rw-r----- 1 root root 5 2011-10-10 12:10 test //ATIME & MTIME
-rw-r--r-- 1 root root 5 2011-07-13 14:30 test //ATIME

The influence are the "other" rights. As soon as it is readable for "other", the modified time is no longer editable. Again, this happens only after....well...after point x....

OS/Kernel
Linux owned 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 i686 i686 i386 GNU/Linux

best,
/dev/blah

Does touch actually fail, or do the mtimes just not change?

It doesn't fail...except of, that it doesn't change the access time. In my list above, you see what is changed on which permission:

//ATIME & MTIME = Both changed
//MTIME = only mtime changed

atimes can be funny. Many systems don't bother keeping them at all (to reduce the number of useless disk writes) and some don't bother updating them if the time difference is too small.

Yes, but that's still no reason why it doesn't change it on certain permissions....also, it doesn't explain why it change atime & mtime till a certain event happens.

Example:

0) touch works on all permissions for atime & mtime
1) event x happens
2) touch changes only mtime for files with permission ??6
3) chmod file to ??0
4) touch works for atime & mtime
5) chmod file to ??6
6) touch works only for mtime again
....

this is strange...for me it looks like a bug...doesn't has to be on touch...but a certain event has to force this behaviour.