2

I created a virtual file driver that takes input from a file. This input is saved internally (besides other things that happen) and written out on a reading file access.

Now when I write an empty string or datablock to this file, it seems the write handler is not called. It does not make sense on the first glance but on the second is does. Look at

echo -n "" > somefile

this clears the file's content. I need the same for a virtual file because I want to tell the driver "hey now there is no more data for you".

Do I have a chance to have the writehandler called with an empty information?

Sending a certain escape sequence is not an option because data is binary and I can't nominate a value to be treated as "empty".

Droidum
  • 440
  • 2
  • 9

1 Answers1

2

First, it might be bad taste to add binary pseudo-files in /proc/. Did you consider making them textual, like most pseudo-files in /proc/ are? The additional overhead of parsing some textual pseudo-file is most often negligible (and a sysadmin really likes to have textual pseudo-files in /proc/ that could be read without much harmful side-effects).

Then you might use the ftruncate(2) syscall (but I don't know if it works on /proc/ pseudofiles). You'll then use the truncate(1) command like:

truncate /proc/your_weird_pseudo_file

Perhaps that might not work (I have no idea if procfs filesystem supports that)

Alternatively (but this is ugly), provide another pseudo file to clear some state, so your user would do:

echo 1 > /proc/clear_your_weird_state
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Yes I am aware of the "taste". What I do is something to be used from applications that can put any data into. Other "files" in this directory give information in text format but I don't want to restrict the payload data in there. It is Android kernel, there is no truncate. – Droidum May 23 '16 at 11:18