Fix several long-standing bugs in HDFS implementation