vnop_strategy unexpectedly zero-extends files

On implementing vnop_mmap, vnop_strategy and other related VNOPs as suggested in https://developer.apple.com/forums/thread/756358 my vnop_strategy routine ends up zero-extending files.

I don't understand why my filesystem behaves as described above.

Perusing the source code of both the relevant parts of Darwin/XNU and SMBClient did not clarify things for me.

A nudge in the right direction would be greatly appreciated.

The technical details of the issue are given in the plain text file attached, as some text was found to be sensitive. Unsure what exactly it was.

Answered by DTS Engineer in 797407022

Looking at your specific example:

49152 / 16384 (16k) = 3

34288 / 16384 (16k) = ~2.09

Have you looked closely at exactly what inputs you received and what you then wrote back out? The simplest explanation here would be that your wrote back out the "full" pages you received from the kernel (which would have been zero filled) instead of only writing out the logical data of the file.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Accepted Answer

Looking at your specific example:

49152 / 16384 (16k) = 3

34288 / 16384 (16k) = ~2.09

Have you looked closely at exactly what inputs you received and what you then wrote back out? The simplest explanation here would be that your wrote back out the "full" pages you received from the kernel (which would have been zero filled) instead of only writing out the logical data of the file.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Passing the smaller value of buf_count and the difference between the file size and the current offset into the file, instead of passing the value returned by buf_count, into myfs_write function fixes the problem.

Thanks very much Kevin Elliott for the tip.

Happy to help!

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

vnop_strategy unexpectedly zero-extends files
 
 
Q