Domanda

This is a bit of a strange question. I'm writing a fuse module using the go-fuse library, and at the moment I have a "fake" file with a size of 6000 bytes, and which will output some unrelated data for all read requests. My read function looks like this:

func (f *MyFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Status) {
    log.Printf("Reading into buffer of len %d from %d\n",len(buf),off)
    FillBuffer(buf, uint64(off), f.secret)
    return fuse.ReadResultData(buf), fuse.OK
}

As you can see I'm outputting a log on every read containing the range of the read request. The weird thing is that when I cat the file I get the following:

2013/09/13 21:09:03 Reading into buffer of len 4096 from 0
2013/09/13 21:09:03 Reading into buffer of len 8192 from 0

So cat is apparently reading the first 4096 bytes of data, discarding it, then reading 8192 bytes, which encompasses all the data and so succeeds. I've tried with other programs too, including hexdump and vim, and they all do the same thing. Interestingly, if I do a head -c 3000 dir/fakefile it still does the two reads, even though the later one is completely unnecessary. Does anyone have any insights into why this might be happening?

È stato utile?

Soluzione

I suggest you strace your cat process to see for yourself. On my system, cat reads by 64K chunks, and does a final read() to make sure it read the whole file. That last read() is necessary to make the distinction between a reading a "chunk-sized file" and a bigger file. i.e. it makes sure there is nothing left to read, as the file size could have changed between the fstat() and the read() system calls.

Is your "fake file" size being returned correctly to FUSE by stat/fstat() system calls?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top