The crystal structure of the inorganic surface films formed on Mg and Li intercalation compounds and the electrode performance