1

I need to store an integer on the filesystem. I have a file (.txt, .log) that represents a simple priority queue. The integer helps with implementing priority the queue. I increment the integer and it needs to be persisted, so that multiple processes can read/write to it.

I could store that integer in a separate file than the file that represents the queue, but I was thinking it would be convenient and maybe slightly more performant to store the integer in the same file as metadata.

Is there a way to store a fairly unbounded (32 bit?) integer as file metadata that would be safe for read/write for a very indefinite amount of time?

BIBD
  • 15,107
  • 25
  • 85
  • 137
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • 1
    And the reason you can't store it in the file that contains the queue is ... ? – Jim Mischel Dec 29 '16 at 20:30
  • Because it's possible that this data could accidentally get written to the same portion of the file that represents the queue. I could reserve some bytes in the text file for the integer, but I'd rather just put it somewhere else. Does it not seem any more difficult to put it in the metadata than reserve bytes for the integer in the file itelf? ;) I doubt it. – Alexander Mills Dec 29 '16 at 20:31
  • 1
    You could use [NTFS alternate data streams](https://support.microsoft.com/en-us/kb/105763) on Windows. To my knowledge there's no cross-platform solution. Do note, however, that many tools don't understand them (see http://stackoverflow.com/questions/1809725/ntfs-alternate-data-streams). – Jim Mischel Dec 29 '16 at 20:43
  • thanks for the info - mostly looking for a unix solution for this, probably won't do cross-platform development in this case – Alexander Mills Dec 29 '16 at 22:42
  • 1
    Perhaps https://en.wikipedia.org/wiki/Extended_file_attributes#Linux is useful to you. – Jim Mischel Dec 30 '16 at 04:42
  • 1
    Take a look at this: http://unix.stackexchange.com/questions/307963/add-a-new-custom-metadata-tag – aparente001 Jan 11 '17 at 15:22
  • Since metadata availability depends on the filesystem type, you'd have to specify the type(s). – Armali Feb 01 '19 at 09:04

0 Answers0