-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
system/core: move libsparse into system/core
This moves an exact copy of libsparse from system/extras/ext4_utils/libsparse to system/core/libsparse in preparation for linking tools in system/core against it. Change-Id: If664e4fcfd6612844ac745589beb1517e7f9fe58
- Loading branch information
1 parent
2177c79
commit 28fa5bc
Showing
15 changed files
with
2,320 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Copyright 2010 The Android Open Source Project | ||
|
||
LOCAL_PATH:= $(call my-dir) | ||
|
||
libsparse_src_files := \ | ||
backed_block.c \ | ||
output_file.c \ | ||
sparse.c \ | ||
sparse_crc32.c | ||
|
||
include $(CLEAR_VARS) | ||
|
||
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include | ||
LOCAL_SRC_FILES := $(libsparse_src_files) | ||
LOCAL_MODULE := libsparse | ||
LOCAL_MODULE_TAGS := optional | ||
LOCAL_STATIC_LIBRARIES := libz | ||
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include external/zlib | ||
|
||
include $(BUILD_HOST_STATIC_LIBRARY) | ||
|
||
include $(CLEAR_VARS) | ||
|
||
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include | ||
LOCAL_SRC_FILES := $(libsparse_src_files) | ||
LOCAL_MODULE := libsparse | ||
LOCAL_MODULE_TAGS := optional | ||
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include external/zlib | ||
LOCAL_SHARED_LIBRARIES := libz | ||
|
||
include $(BUILD_SHARED_LIBRARY) | ||
|
||
include $(CLEAR_VARS) | ||
|
||
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include | ||
LOCAL_SRC_FILES := $(libsparse_src_files) | ||
LOCAL_MODULE := libsparse | ||
LOCAL_MODULE_TAGS := optional | ||
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include external/zlib | ||
LOCAL_STATIC_LIBRARIES := libz | ||
|
||
include $(BUILD_STATIC_LIBRARY) | ||
|
||
include $(CLEAR_VARS) | ||
|
||
LOCAL_SRC_FILES := simg2img.c \ | ||
sparse_crc32.c | ||
LOCAL_MODULE := simg2img | ||
LOCAL_MODULE_TAGS := debug | ||
|
||
include $(BUILD_HOST_EXECUTABLE) | ||
|
||
include $(CLEAR_VARS) | ||
|
||
LOCAL_SRC_FILES := simg2img.c \ | ||
sparse_crc32.c | ||
LOCAL_MODULE := simg2img | ||
LOCAL_MODULE_TAGS := optional | ||
|
||
include $(BUILD_EXECUTABLE) | ||
|
||
include $(CLEAR_VARS) | ||
|
||
LOCAL_SRC_FILES := img2simg.c | ||
LOCAL_MODULE := img2simg | ||
LOCAL_MODULE_TAGS := debug | ||
|
||
include $(BUILD_HOST_EXECUTABLE) | ||
|
||
include $(CLEAR_VARS) | ||
|
||
LOCAL_SRC_FILES := img2simg.c | ||
LOCAL_MODULE := img2simg | ||
LOCAL_MODULE_TAGS := optional | ||
|
||
include $(BUILD_EXECUTABLE) | ||
|
||
include $(CLEAR_VARS) | ||
|
||
LOCAL_MODULE := simg_dump.py | ||
LOCAL_MODULE_TAGS := debug | ||
LOCAL_SRC_FILES := simg_dump.py | ||
LOCAL_MODULE_CLASS := EXECUTABLES | ||
LOCAL_IS_HOST_MODULE := true | ||
|
||
include $(BUILD_PREBUILT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/* | ||
* Copyright (C) 2010 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "backed_block.h" | ||
#include "sparse_defs.h" | ||
|
||
struct data_block { | ||
u32 block; | ||
u32 len; | ||
void *data; | ||
const char *filename; | ||
int64_t offset; | ||
struct data_block *next; | ||
u32 fill_val; | ||
u8 fill; | ||
u8 pad1; | ||
u16 pad2; | ||
}; | ||
|
||
static struct data_block *data_blocks = NULL; | ||
static struct data_block *last_used = NULL; | ||
|
||
static void queue_db(struct data_block *new_db) | ||
{ | ||
struct data_block *db; | ||
|
||
if (data_blocks == NULL) { | ||
data_blocks = new_db; | ||
return; | ||
} | ||
|
||
if (data_blocks->block > new_db->block) { | ||
new_db->next = data_blocks; | ||
data_blocks = new_db; | ||
return; | ||
} | ||
|
||
/* Optimization: blocks are mostly queued in sequence, so save the | ||
pointer to the last db that was added, and start searching from | ||
there if the next block number is higher */ | ||
if (last_used && new_db->block > last_used->block) | ||
db = last_used; | ||
else | ||
db = data_blocks; | ||
last_used = new_db; | ||
|
||
for (; db->next && db->next->block < new_db->block; db = db->next) | ||
; | ||
|
||
if (db->next == NULL) { | ||
db->next = new_db; | ||
} else { | ||
new_db->next = db->next; | ||
db->next = new_db; | ||
} | ||
} | ||
|
||
/* Queues a fill block of memory to be written to the specified data blocks */ | ||
void queue_fill_block(unsigned int fill_val, unsigned int len, unsigned int block) | ||
{ | ||
struct data_block *db = malloc(sizeof(struct data_block)); | ||
if (db == NULL) { | ||
error_errno("malloc"); | ||
return; | ||
} | ||
|
||
db->block = block; | ||
db->len = len; | ||
db->fill = 1; | ||
db->fill_val = fill_val; | ||
db->data = NULL; | ||
db->filename = NULL; | ||
db->next = NULL; | ||
|
||
queue_db(db); | ||
} | ||
|
||
/* Queues a block of memory to be written to the specified data blocks */ | ||
void queue_data_block(void *data, unsigned int len, unsigned int block) | ||
{ | ||
struct data_block *db = malloc(sizeof(struct data_block)); | ||
if (db == NULL) { | ||
error_errno("malloc"); | ||
return; | ||
} | ||
|
||
db->block = block; | ||
db->len = len; | ||
db->data = data; | ||
db->filename = NULL; | ||
db->fill = 0; | ||
db->next = NULL; | ||
|
||
queue_db(db); | ||
} | ||
|
||
/* Queues a chunk of a file on disk to be written to the specified data blocks */ | ||
void queue_data_file(const char *filename, int64_t offset, unsigned int len, | ||
unsigned int block) | ||
{ | ||
struct data_block *db = malloc(sizeof(struct data_block)); | ||
if (db == NULL) { | ||
error_errno("malloc"); | ||
return; | ||
} | ||
|
||
db->block = block; | ||
db->len = len; | ||
db->filename = strdup(filename); | ||
db->offset = offset; | ||
db->data = NULL; | ||
db->fill = 0; | ||
db->next = NULL; | ||
|
||
queue_db(db); | ||
} | ||
|
||
/* Iterates over the queued data blocks, calling data_func for each contiguous | ||
data block, and file_func for each contiguous file block */ | ||
void for_each_data_block(data_block_callback_t data_func, | ||
data_block_file_callback_t file_func, | ||
data_block_fill_callback_t fill_func, void *priv, unsigned int block_size) | ||
{ | ||
struct data_block *db; | ||
u32 last_block = 0; | ||
|
||
for (db = data_blocks; db; db = db->next) { | ||
if (db->block < last_block) | ||
error("data blocks out of order: %u < %u", db->block, last_block); | ||
last_block = db->block + DIV_ROUND_UP(db->len, block_size) - 1; | ||
|
||
if (db->filename) | ||
file_func(priv, (u64)db->block * block_size, db->filename, db->offset, db->len); | ||
else if (db->fill) | ||
fill_func(priv, (u64)db->block * block_size, db->fill_val, db->len); | ||
else | ||
data_func(priv, (u64)db->block * block_size, db->data, db->len); | ||
} | ||
} | ||
|
||
/* Frees the memory used by the linked list of data blocks */ | ||
void free_data_blocks() | ||
{ | ||
if (!data_blocks) return; | ||
struct data_block *db = data_blocks; | ||
while (db) { | ||
struct data_block *next = db->next; | ||
free((void*)db->filename); | ||
|
||
// There used to be a free() of db->data here, but it | ||
// made the function crash since queue_data_block() is | ||
// sometimes passed pointers it can't take ownership of | ||
// (like a pointer into the middle of an allocated | ||
// block). It's not clear what the queue_data_block | ||
// contract is supposed to be, but we'd rather leak | ||
// memory than crash. | ||
|
||
free(db); | ||
db = next; | ||
} | ||
data_blocks = NULL; | ||
last_used = NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2010 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef _BACKED_BLOCK_H_ | ||
#define _BACKED_BLOCK_H_ | ||
|
||
#include <sparse/sparse.h> | ||
|
||
typedef void (*data_block_callback_t)(void *priv, int64_t off, void *data, int len); | ||
typedef void (*data_block_fill_callback_t)(void *priv, int64_t off, unsigned int fill_val, int len); | ||
typedef void (*data_block_file_callback_t)(void *priv, int64_t off, | ||
const char *file, int64_t offset, | ||
int len); | ||
|
||
void for_each_data_block(data_block_callback_t data_func, | ||
data_block_file_callback_t file_func, | ||
data_block_fill_callback_t fill_func, void *priv, unsigned int); | ||
|
||
void queue_data_block(void *data, unsigned int len, unsigned int block); | ||
void queue_fill_block(unsigned int fill_val, unsigned int len, unsigned int block); | ||
void queue_data_file(const char *filename, int64_t offset, unsigned int len, | ||
unsigned int block); | ||
|
||
void free_data_blocks(); | ||
|
||
#endif |
Oops, something went wrong.