It's not quite duplicated code.  Factoring it out seems like it'll just end up awkward since each case is a bit different.  For example, the write code specifically disallows writing the BL partition and the writes set up more flags than the reads.