Add fstat and tests. Fix position bug in read/write.