blob: 47719b07ae6860e2ec205bab1ecaa3a6748868ac [file] [log] [blame]
Doug Zongker18a78e02014-07-10 07:31:46 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Tao Bao91a7aa42017-05-01 15:57:38 -070017#include "fuse_adb_provider.h"
18
Doug Zongker18a78e02014-07-10 07:31:46 -070019#include <errno.h>
Tao Bao91a7aa42017-05-01 15:57:38 -070020#include <stdio.h>
Tao Bao91a7aa42017-05-01 15:57:38 -070021#include <string.h>
22
Doug Zongker18a78e02014-07-10 07:31:46 -070023#include "adb.h"
Dan Albert432584f2015-02-24 22:48:25 -080024#include "adb_io.h"
Doug Zongker18a78e02014-07-10 07:31:46 -070025
xunchangea2912f2019-03-17 16:45:12 -070026bool FuseAdbDataProvider::ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch_size,
27 uint32_t start_block) const {
28 if (!WriteFdFmt(fd_, "%08u", start_block)) {
Tao Bao91a7aa42017-05-01 15:57:38 -070029 fprintf(stderr, "failed to write to adb host: %s\n", strerror(errno));
xunchangea2912f2019-03-17 16:45:12 -070030 return false;
Tao Bao91a7aa42017-05-01 15:57:38 -070031 }
Doug Zongker18a78e02014-07-10 07:31:46 -070032
xunchangea2912f2019-03-17 16:45:12 -070033 if (!ReadFdExactly(fd_, buffer, fetch_size)) {
Tao Bao91a7aa42017-05-01 15:57:38 -070034 fprintf(stderr, "failed to read from adb host: %s\n", strerror(errno));
xunchangea2912f2019-03-17 16:45:12 -070035 return false;
Tao Bao91a7aa42017-05-01 15:57:38 -070036 }
Doug Zongker18a78e02014-07-10 07:31:46 -070037
xunchangea2912f2019-03-17 16:45:12 -070038 return true;
Doug Zongker18a78e02014-07-10 07:31:46 -070039}