system/corennnnn
Revisión | c472b6a362f3a2dfc3d65a035ff1bc59951a9ef2 (tree) |
---|---|
Tiempo | 2016-11-09 00:27:22 |
Autor | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
Merge branch 'android-ia' into nougat-x86
@@ -51,7 +51,48 @@ ADB_MUTEX_DEFINE(local_transports_lock); | ||
51 | 51 | * trying to connect twice to a given local transport. |
52 | 52 | */ |
53 | 53 | static atransport* local_transports[ ADB_LOCAL_TRANSPORT_MAX ]; |
54 | -#endif /* ADB_HOST */ | |
54 | +#else /* !ADB_HOST */ | |
55 | + | |
56 | +#define WAKE_LOCK_NAME "adb-socket-connection" | |
57 | +#define WAKE_LOCK_ACQUIRE "/sys/power/wake_lock" | |
58 | +#define WAKE_LOCK_RELEASE "/sys/power/wake_unlock" | |
59 | + | |
60 | +static int sysfs_write(const char *node, const char *message) | |
61 | +{ | |
62 | + int fd; | |
63 | + ssize_t to_write; | |
64 | + int ret = 0; | |
65 | + | |
66 | + fd = adb_open(node, O_RDWR); | |
67 | + if (!fd) { | |
68 | + D("open '%s' failed: %s", node, strerror(errno)); | |
69 | + return -1; | |
70 | + } | |
71 | + | |
72 | + to_write = strlen(message); | |
73 | + if (adb_write(fd, message, to_write) != to_write) { | |
74 | + D("write '%s' failed: %s", node, strerror(errno)); | |
75 | + ret = -1; | |
76 | + } | |
77 | + adb_close(fd); | |
78 | + return ret; | |
79 | +} | |
80 | + | |
81 | +static void get_wakelock(void) | |
82 | +{ | |
83 | + if (sysfs_write(WAKE_LOCK_ACQUIRE, WAKE_LOCK_NAME)) { | |
84 | + D("couldn't reserve wakelock for socket connection"); | |
85 | + } | |
86 | +} | |
87 | + | |
88 | +static void release_wakelock(void) | |
89 | +{ | |
90 | + if (sysfs_write(WAKE_LOCK_RELEASE, WAKE_LOCK_NAME)) { | |
91 | + D("couldn't release wakelock for socket connection"); | |
92 | + } | |
93 | +} | |
94 | + | |
95 | +#endif /* !ADB_HOST */ | |
55 | 96 | |
56 | 97 | static int remote_read(apacket *p, atransport *t) |
57 | 98 | { |
@@ -170,6 +211,9 @@ static void server_socket_thread(void* arg) { | ||
170 | 211 | fd = adb_socket_accept(serverfd, addrp, &alen); |
171 | 212 | if(fd >= 0) { |
172 | 213 | D("server: new connection on fd %d", fd); |
214 | +#if !ADB_HOST | |
215 | + get_wakelock(); | |
216 | +#endif | |
173 | 217 | close_on_exec(fd); |
174 | 218 | disable_tcp_nagle(fd); |
175 | 219 | register_socket_transport(fd, "host", port, 1); |
@@ -339,6 +383,9 @@ static void remote_kick(atransport *t) | ||
339 | 383 | |
340 | 384 | static void remote_close(atransport *t) |
341 | 385 | { |
386 | +#if !ADB_HOST | |
387 | + release_wakelock(); | |
388 | +#endif | |
342 | 389 | int fd = t->sfd; |
343 | 390 | if (fd != -1) { |
344 | 391 | t->sfd = -1; |
@@ -21,6 +21,11 @@ | ||
21 | 21 | #include <stdint.h> |
22 | 22 | #include <sys/types.h> |
23 | 23 | |
24 | +#ifdef __APPLE__ | |
25 | +typedef int64_t loff_t; | |
26 | +#define lseek64 lseek | |
27 | +#endif | |
28 | + | |
24 | 29 | #ifdef __cplusplus |
25 | 30 | extern "C" { |
26 | 31 | #endif |
@@ -981,8 +981,8 @@ void device_init() { | ||
981 | 981 | sehandle = selinux_android_file_context_handle(); |
982 | 982 | selinux_status_open(true); |
983 | 983 | |
984 | - /* is 256K enough? udev uses 16MB! */ | |
985 | - device_fd = uevent_open_socket(256*1024, true); | |
984 | + /* is 8MB enough? udev uses 16MB! */ | |
985 | + device_fd = uevent_open_socket(8 * 1024 * 1024, true); | |
986 | 986 | if (device_fd == -1) { |
987 | 987 | return; |
988 | 988 | } |
@@ -15,11 +15,9 @@ LOCAL_SYSTEM_SHARED_LIBRARIES := libcutils liblog libc | ||
15 | 15 | LOCAL_CFLAGS := -Werror |
16 | 16 | include $(BUILD_SHARED_LIBRARY) |
17 | 17 | |
18 | -ifeq ($(HOST_OS),linux) | |
19 | 18 | include $(CLEAR_VARS) |
20 | 19 | LOCAL_SRC_FILES := $(commonSources) |
21 | 20 | LOCAL_MODULE := libdiskconfig_host |
22 | 21 | LOCAL_MODULE_TAGS := optional |
23 | -LOCAL_CFLAGS := -O2 -g -W -Wall -Werror -D_LARGEFILE64_SOURCE | |
22 | +LOCAL_CFLAGS := -O2 -g -W -Wall -Werror -D_LARGEFILE64_SOURCE -DHOST_BUILD | |
24 | 23 | include $(BUILD_HOST_STATIC_LIBRARY) |
25 | -endif # HOST_OS == linux |
@@ -260,11 +260,11 @@ config_mbr(struct disk_info *dinfo) | ||
260 | 260 | } |
261 | 261 | |
262 | 262 | /* if extended, need 1 lba for ebr */ |
263 | - if ((cur_lba + extended) >= dinfo->num_lba) | |
263 | + if (dinfo->num_lba && (cur_lba + extended) >= dinfo->num_lba) | |
264 | 264 | goto nospace; |
265 | 265 | else if (pinfo->len_kb != (uint32_t)-1) { |
266 | 266 | uint32_t sz_lba = (pinfo->len_kb / dinfo->sect_size) * 1024; |
267 | - if ((cur_lba + sz_lba + extended) > dinfo->num_lba) | |
267 | + if (dinfo->num_lba && (cur_lba + sz_lba + extended) > dinfo->num_lba) | |
268 | 268 | goto nospace; |
269 | 269 | } |
270 | 270 |
@@ -27,7 +27,9 @@ | ||
27 | 27 | #include <sys/ioctl.h> |
28 | 28 | #include <sys/stat.h> |
29 | 29 | |
30 | +#ifndef HOST_BUILD | |
30 | 31 | #include <linux/fs.h> |
32 | +#endif | |
31 | 33 | |
32 | 34 | #include <cutils/config_utils.h> |
33 | 35 | #include <log/log.h> |
@@ -76,7 +78,7 @@ parse_len(const char *str, uint64_t *plen) | ||
76 | 78 | } |
77 | 79 | } else { |
78 | 80 | /* convert len to kilobytes */ |
79 | - if (multiple > 1024) | |
81 | + if (multiple >= 1024) | |
80 | 82 | multiple >>= 10; |
81 | 83 | *plen *= multiple; |
82 | 84 |
@@ -236,6 +238,7 @@ fail: | ||
236 | 238 | return NULL; |
237 | 239 | } |
238 | 240 | |
241 | +#ifndef HOST_BUILD | |
239 | 242 | static int |
240 | 243 | sync_ptable(int fd) |
241 | 244 | { |
@@ -256,6 +259,13 @@ sync_ptable(int fd) | ||
256 | 259 | |
257 | 260 | return 0; |
258 | 261 | } |
262 | +#else | |
263 | +static int sync_ptable(int fd) | |
264 | +{ | |
265 | + (void)fd; | |
266 | + return 0; | |
267 | +} | |
268 | +#endif | |
259 | 269 | |
260 | 270 | /* This function verifies that the disk info provided is valid, and if so, |
261 | 271 | * returns an open file descriptor. |
@@ -272,7 +282,6 @@ static int | ||
272 | 282 | validate(struct disk_info *dinfo) |
273 | 283 | { |
274 | 284 | int fd; |
275 | - int sect_sz; | |
276 | 285 | uint64_t disk_size; |
277 | 286 | uint64_t total_size; |
278 | 287 | int cnt; |
@@ -298,6 +307,12 @@ validate(struct disk_info *dinfo) | ||
298 | 307 | /* Verify that we can operate on the device that was requested. |
299 | 308 | * We presently only support block devices and regular file images. */ |
300 | 309 | if (S_ISBLK(stat.st_mode)) { |
310 | +#ifdef HOST_BUILD | |
311 | + ALOGE("Block device manipulation on host forbidden"); | |
312 | + goto fail; | |
313 | +#else | |
314 | + int sect_sz; | |
315 | + | |
301 | 316 | /* get the sector size and make sure we agree */ |
302 | 317 | if (ioctl(fd, BLKSSZGET, §_sz) < 0) { |
303 | 318 | ALOGE("Cannot get sector size (errno=%d)", errno); |
@@ -319,6 +334,7 @@ validate(struct disk_info *dinfo) | ||
319 | 334 | dinfo->num_lba = (uint32_t)(disk_size / (uint64_t)dinfo->sect_size); |
320 | 335 | } else |
321 | 336 | disk_size = (uint64_t)dinfo->num_lba * (uint64_t)dinfo->sect_size; |
337 | +#endif | |
322 | 338 | } else if (S_ISREG(stat.st_mode)) { |
323 | 339 | ALOGI("Requesting operation on a regular file, not block device."); |
324 | 340 | if (!dinfo->sect_size) { |
@@ -36,6 +36,7 @@ write_raw_image(const char *dst, const char *src, loff_t offset, int test) | ||
36 | 36 | int dst_fd = -1; |
37 | 37 | int src_fd = -1; |
38 | 38 | uint8_t buffer[2048]; |
39 | + ssize_t buf_offset; | |
39 | 40 | ssize_t nr_bytes; |
40 | 41 | ssize_t tmp; |
41 | 42 | int done = 0; |
@@ -80,8 +81,9 @@ write_raw_image(const char *dst, const char *src, loff_t offset, int test) | ||
80 | 81 | if (test) |
81 | 82 | nr_bytes = 0; |
82 | 83 | |
84 | + buf_offset = 0; | |
83 | 85 | while (nr_bytes > 0) { |
84 | - if ((tmp = write(dst_fd, buffer, nr_bytes)) < 0) { | |
86 | + if ((tmp = write(dst_fd, &buffer[buf_offset], nr_bytes)) < 0) { | |
85 | 87 | /* XXX: Should we not even bother with EINTR? */ |
86 | 88 | if (errno == EINTR) |
87 | 89 | continue; |
@@ -91,6 +93,7 @@ write_raw_image(const char *dst, const char *src, loff_t offset, int test) | ||
91 | 93 | if (!tmp) |
92 | 94 | continue; |
93 | 95 | nr_bytes -= tmp; |
96 | + buf_offset += tmp; | |
94 | 97 | } |
95 | 98 | } |
96 | 99 |
@@ -249,7 +249,7 @@ int newfs_msdos_main(int argc, char *argv[]) | ||
249 | 249 | char buf[MAXPATHLEN]; |
250 | 250 | struct stat sb; |
251 | 251 | struct timeval tv; |
252 | - struct bpb bpb; | |
252 | + struct bpb bpb, tempbpb; | |
253 | 253 | struct tm *tm; |
254 | 254 | struct bs *bs; |
255 | 255 | struct bsbpb *bsbpb; |
@@ -553,6 +553,7 @@ int newfs_msdos_main(int argc, char *argv[]) | ||
553 | 553 | set_spf = !bpb.bspf; |
554 | 554 | set_spc = !bpb.spc; |
555 | 555 | tempx = x; |
556 | + memset(&tempbpb, 0, sizeof(bpb)); | |
556 | 557 | /* |
557 | 558 | * Attempt to align if opt_A is set. This is done by increasing the number |
558 | 559 | * of reserved blocks. This can cause other factors to change, which can in |
@@ -600,10 +601,14 @@ int newfs_msdos_main(int argc, char *argv[]) | ||
600 | 601 | alignment = (bpb.res + bpb.bspf * bpb.nft) % bpb.spc; |
601 | 602 | extra_res += bpb.spc - alignment; |
602 | 603 | } |
603 | - attempts++; | |
604 | + if (++attempts == 1) | |
605 | + memcpy(&tempbpb, &bpb, sizeof(bpb)); | |
604 | 606 | } while(opt_A && alignment != 0 && attempts < 2); |
605 | - if (alignment != 0) | |
607 | + if (alignment != 0) { | |
606 | 608 | warnx("warning: Alignment failed."); |
609 | + /* return to data from first iteration */ | |
610 | + memcpy(&bpb, &tempbpb, sizeof(bpb)); | |
611 | + } | |
607 | 612 | |
608 | 613 | cls = (bpb.bsec - x1) / bpb.spc; |
609 | 614 | x = (u_int64_t)bpb.bspf * bpb.bps * NPB / (fat / BPN) - RESFTE; |