fs: move code out of buffer.c