static int test_overwrite_other(void) { uint32_t offset, size; /* Test that we can overwrite the other image */ if (system_get_image_copy() == SYSTEM_IMAGE_RW) { offset = CONFIG_RO_STORAGE_OFF; size = CONFIG_RO_SIZE; } else { offset = CONFIG_RW_STORAGE_OFF; size = CONFIG_RW_SIZE; } #ifdef EMU_BUILD mock_is_running_img = 0; #endif VERIFY_ERASE(offset, strlen(testdata)); VERIFY_ERASE(offset + size - strlen(testdata), strlen(testdata)); VERIFY_WRITE(offset, strlen(testdata), testdata); VERIFY_WRITE(offset + size - strlen(testdata), strlen(testdata), testdata); return EC_SUCCESS; }
static int callback_chown (const char *path, uid_t uid, gid_t gid) { path = ENSURE_RELPATH (path); VERIFY_WRITE(path); if (fchownat (basefd, path, uid, gid, 0) != 0) return -errno; return 0; }
static int callback_chmod (const char *path, mode_t mode) { path = ENSURE_RELPATH (path); VERIFY_WRITE(path); if (fchmodat (basefd, path, mode, 0) != 0) return -errno; return 0; }
static int callback_truncate (const char *path, off_t size) { glnx_fd_close int fd = -1; path = ENSURE_RELPATH (path); VERIFY_WRITE(path); fd = openat (basefd, path, O_WRONLY); if (fd == -1) return -errno; if (ftruncate (fd, size) == -1) return -errno; return 0; }