Theory of Magnetic Recording