• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <string.h>
20 #include <errno.h>
21 
22 #include "adb.h"
23 #include "adb_io.h"
24 #include "fuse_adb_provider.h"
25 #include "fuse_sideload.h"
26 
read_block_adb(void * data,uint32_t block,uint8_t * buffer,uint32_t fetch_size)27 int read_block_adb(void* data, uint32_t block, uint8_t* buffer, uint32_t fetch_size) {
28     adb_data* ad = reinterpret_cast<adb_data*>(data);
29 
30     if (!WriteFdFmt(ad->sfd, "%08u", block)) {
31         fprintf(stderr, "failed to write to adb host: %s\n", strerror(errno));
32         return -EIO;
33     }
34 
35     if (!ReadFdExactly(ad->sfd, buffer, fetch_size)) {
36         fprintf(stderr, "failed to read from adb host: %s\n", strerror(errno));
37         return -EIO;
38     }
39 
40     return 0;
41 }
42 
close_adb(void * data)43 static void close_adb(void* data) {
44     adb_data* ad = reinterpret_cast<adb_data*>(data);
45     WriteFdExactly(ad->sfd, "DONEDONE");
46 }
47 
run_adb_fuse(int sfd,uint64_t file_size,uint32_t block_size)48 int run_adb_fuse(int sfd, uint64_t file_size, uint32_t block_size) {
49     adb_data ad;
50     ad.sfd = sfd;
51     ad.file_size = file_size;
52     ad.block_size = block_size;
53 
54     provider_vtab vtab;
55     vtab.read_block = read_block_adb;
56     vtab.close = close_adb;
57 
58     return run_fuse_sideload(&vtab, &ad, file_size, block_size);
59 }
60