8

I am trying to detect when Dropbox is busy updating a file in a user's Dropbox in Mac OS X. By running stat(1) or stat(2) on a file, I see that the user defined flags for file (st_flags) are normally 0x40, but while Dropbox is updating the file they change to 0x00 for a couple seconds.

Poking around my Desktop and other folders, I see that ~95% of files have flags value 0x00 but about 5% have value 0x40. So it may be not just a Dropbox implementation detail. I cannot discern any pattern for predicting which files have 0x40 flags. Does anyone know what these values mean? Who is the "user" that is defining them?

Jerry Krinock
  • 4,860
  • 33
  • 39

2 Answers2

11

Well even though Martin essentially answered this with a very educated guess, I'm entering this as an answer because it's too long to enter as a comment.

Here is the evidence…

• Indeed, 10.7 is when Auto Save and Versions was introduced, so that's why you don't see UF_TRACKED in stat.h in 10.6.

• I tried my experiment on a Mac running Mac OS X 10.7 and it behaves the same as in 10.8.

• There is a pattern: Document files created by some applications, which after examining a few appear to be those which have adopted Auto Save and Versions, are the ones which have the UF_TRACKED = 0x40.

• Another experiment. I renamed the revision daemon executable in Mac OS X,

/System/Library/PrivateFrameworks/GenerationalStorage.framework/Versions/A/Support/revisiond

then restarted the Mac, and monitored the UF_TRACKED state of a document file in Dropbox which had 0x40. I then changed the file on another Mac, so that Dropbox would push it to this Mac with the revision daemon disabled. Result: The UF_TRACKED state of the file changed from 0x40 to 0x00, but this time it did not change back to 0x40 after 2 seconds.

• It did change to 0x40 30 seconds later, after I restored the revision daemon to its original name, and it relaunched. (Apparently revisiond is started by launchd with a KeepAlive attribute.)

==================

So the evidence is overwhelming that Martin's guess is correct. It is Apple's revision daemon and not Dropbox which is setting UF_TRACKED to 0x40. The meaning of this bit is that its document revision is being tracked by Lion Auto Save and Versions.

Jerry Krinock
  • 4,860
  • 33
  • 39
8

The flags can be set with the chflags command line tool or the chflags() system call (see man 2 chflags). The values can be found in "/usr/include/sys/stat.h".

UF_TRACKED seems to be a bit special. It is documented in "sys/stat.h"

#define UF_TRACKED    0x00000040 /* file renames and deletes are tracked */

but not in the "chflags" man-page.

Unfortunately, I cannot tell you what "tracked" precisely means, but perhaps this helps already to find more information.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • 1
    Ah, the header file! So it looks like the "user" in this context is implied to be the unix file owner (as in owner, group, everyone). This UF_TRACKED is one of 8 flag bits that go beyond the other stat states, or restrict file may/should be modified. I wonder if these rules have any enforcement mechanism or if they are just advisory for programs which care to look at them. I'll have to do some experiments. – Jerry Krinock May 11 '13 at 15:52
  • 1
    @JerryKrinock: The flags a definitely more than advisory. For example, if you do "chflags uappend myfile" then "ls > myfile" (overwrite) fails, but "ls >> myfile" (append) works, so the flag "append only" is enforced by the file system. – Martin R May 11 '13 at 15:55
  • @JerryKrinock: The only other reference to `UF_TRACKED` that I could find is http://stackoverflow.com/questions/10607877/uf-tracked-file-flag-from-stat-h. I *assume* that this is connected with the "Auto Save and Versions" features of OS X, but that is only a guess. – Martin R May 11 '13 at 15:57
  • I think you are probably correct, Martin. I just looked at the file in Dropbox on a 10.6 Mac and its UF_TRACKED is 0x0. – Jerry Krinock May 12 '13 at 12:55
  • 1
    @JerryKrinock: OK, I'm glad that it helped. Btw: `` on a 10.6 Mac does not contain the UF_TRACKED definition, so this must be new with 10.7. – Martin R May 12 '13 at 12:59
  • 2
    Yes, you've nailed it, Martin.I tried it on a Mac running Mac OS X 10.7 and it behaves the same as Mac OS X 10.8. And there _is_ a pattern: Document files created by some applications, probably those which have adopted Auto Save and Versions, are the ones which have the UF_TRACKED = 0x40. – Jerry Krinock May 12 '13 at 20:09