blob: 4f7d7af013d34ba3764748a2827f1c880185d212 [file] [log] [blame]
Jooyung Han74573482021-06-08 17:10:21 +09001// Copyright 2021, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Payload metadata from /dev/block/by-name/metadata
16
17use log::info;
18use microdroid_metadata::metadata::Metadata;
19use protobuf::Message;
20use std::fs::File;
21use std::io;
22use std::io::Read;
23
24const METADATA_PATH: &str = "/dev/block/by-name/metadata";
25
26/// loads payload metadata from /dev/block/by-name/metadata
27pub fn load() -> io::Result<Metadata> {
28 info!("loading payload metadata...");
29
30 let mut f = File::open(METADATA_PATH)?;
31 // metadata partition is
32 // 4 bytes : size(N) in big endian
33 // N bytes : message for Metadata
34 let mut buf = [0u8; 4];
35 f.read_exact(&mut buf)?;
36 let size = i32::from_be_bytes(buf);
37
38 Ok(Metadata::parse_from_reader(&mut f.take(size as u64))?)
39}