summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes2016-02-13 14:48:23 -0600
committerElliott Hughes2016-02-13 14:48:23 -0600
commit8dccdbf3f80cafcc0e1c3fc55bf03b1b8c5c2b1c (patch)
tree839e3a9edd371bbb98c1c311c311213848db7286 /libdiskconfig
parent1697f4ee71a9e123432c09c068615d9f5a49780b (diff)
downloadplatform-system-core-8dccdbf3f80cafcc0e1c3fc55bf03b1b8c5c2b1c.tar.gz
platform-system-core-8dccdbf3f80cafcc0e1c3fc55bf03b1b8c5c2b1c.tar.xz
platform-system-core-8dccdbf3f80cafcc0e1c3fc55bf03b1b8c5c2b1c.zip
Move libdiskconfig headers into libdiskconfig.
Change-Id: I5d8e29687dca39a2a134d92f311528479b4ea102
Diffstat (limited to 'libdiskconfig')
-rw-r--r--libdiskconfig/Android.mk4
-rw-r--r--libdiskconfig/include/diskconfig/diskconfig.h130
2 files changed, 134 insertions, 0 deletions
diff --git a/libdiskconfig/Android.mk b/libdiskconfig/Android.mk
index 624e38522..a49ce5825 100644
--- a/libdiskconfig/Android.mk
+++ b/libdiskconfig/Android.mk
@@ -13,6 +13,8 @@ LOCAL_MODULE := libdiskconfig
13LOCAL_MODULE_TAGS := optional 13LOCAL_MODULE_TAGS := optional
14LOCAL_SYSTEM_SHARED_LIBRARIES := libcutils liblog libc 14LOCAL_SYSTEM_SHARED_LIBRARIES := libcutils liblog libc
15LOCAL_CFLAGS := -Werror 15LOCAL_CFLAGS := -Werror
16LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
17LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
16include $(BUILD_SHARED_LIBRARY) 18include $(BUILD_SHARED_LIBRARY)
17 19
18ifeq ($(HOST_OS),linux) 20ifeq ($(HOST_OS),linux)
@@ -21,5 +23,7 @@ LOCAL_SRC_FILES := $(commonSources)
21LOCAL_MODULE := libdiskconfig_host 23LOCAL_MODULE := libdiskconfig_host
22LOCAL_MODULE_TAGS := optional 24LOCAL_MODULE_TAGS := optional
23LOCAL_CFLAGS := -O2 -g -W -Wall -Werror -D_LARGEFILE64_SOURCE 25LOCAL_CFLAGS := -O2 -g -W -Wall -Werror -D_LARGEFILE64_SOURCE
26LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
27LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
24include $(BUILD_HOST_STATIC_LIBRARY) 28include $(BUILD_HOST_STATIC_LIBRARY)
25endif # HOST_OS == linux 29endif # HOST_OS == linux
diff --git a/libdiskconfig/include/diskconfig/diskconfig.h b/libdiskconfig/include/diskconfig/diskconfig.h
new file mode 100644
index 000000000..d45b99e24
--- /dev/null
+++ b/libdiskconfig/include/diskconfig/diskconfig.h
@@ -0,0 +1,130 @@
1/* system/core/include/diskconfig/diskconfig.h
2 *
3 * Copyright 2008, The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef __LIBS_DISKCONFIG_H
19#define __LIBS_DISKCONFIG_H
20
21#include <stdint.h>
22#include <sys/types.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#define MAX_NAME_LEN 512
29#define MAX_NUM_PARTS 16
30
31/* known partition schemes */
32#define PART_SCHEME_MBR 0x1
33#define PART_SCHEME_GPT 0x2
34
35/* PC Bios partition status */
36#define PC_PART_ACTIVE 0x80
37#define PC_PART_NORMAL 0x0
38
39/* Known (rather, used by us) partition types */
40#define PC_PART_TYPE_LINUX 0x83
41#define PC_PART_TYPE_EXTENDED 0x05
42#define PC_PART_TYPE_FAT32 0x0c
43
44#define PC_NUM_BOOT_RECORD_PARTS 4
45
46#define PC_EBR_LOGICAL_PART 0
47#define PC_EBR_NEXT_PTR_PART 1
48
49#define PC_BIOS_BOOT_SIG 0xAA55
50
51#define PC_MBR_DISK_OFFSET 0
52#define PC_MBR_SIZE 512
53
54#define PART_ACTIVE_FLAG 0x1
55
56struct chs {
57 uint8_t head;
58 uint8_t sector;
59 uint8_t cylinder;
60} __attribute__((__packed__));
61
62/* 16 byte pc partition descriptor that sits in MBR and EPBR.
63 * Note: multi-byte entities have little-endian layout on disk */
64struct pc_partition {
65 uint8_t status; /* byte 0 */
66 struct chs start; /* bytes 1-3 */
67 uint8_t type; /* byte 4 */
68 struct chs end; /* bytes 5-7 */
69 uint32_t start_lba; /* bytes 8-11 */
70 uint32_t len_lba; /* bytes 12-15 */
71} __attribute__((__packed__));
72
73struct pc_boot_record {
74 uint8_t code[440]; /* bytes 0-439 */
75 uint32_t disk_sig; /* bytes 440-443 */
76 uint16_t pad; /* bytes 444-445 */
77 struct pc_partition ptable[PC_NUM_BOOT_RECORD_PARTS]; /* bytes 446-509 */
78 uint16_t mbr_sig; /* bytes 510-511 */
79} __attribute__((__packed__));
80
81struct part_info {
82 char *name;
83 uint8_t flags;
84 uint8_t type;
85 uint32_t len_kb; /* in 1K-bytes */
86 uint32_t start_lba; /* the LBA where this partition begins */
87};
88
89struct disk_info {
90 char *device;
91 uint8_t scheme;
92 int sect_size; /* expected sector size in bytes. MUST BE POWER OF 2 */
93 uint32_t skip_lba; /* in sectors (1 unit of LBA) */
94 uint32_t num_lba; /* the size of the disk in LBA units */
95 struct part_info *part_lst;
96 int num_parts;
97};
98
99struct write_list {
100 struct write_list *next;
101 loff_t offset;
102 uint32_t len;
103 uint8_t data[0];
104};
105
106
107struct write_list *alloc_wl(uint32_t data_len);
108void free_wl(struct write_list *item);
109struct write_list *wlist_add(struct write_list **lst, struct write_list *item);
110void wlist_free(struct write_list *lst);
111int wlist_commit(int fd, struct write_list *lst, int test);
112
113struct disk_info *load_diskconfig(const char *fn, char *path_override);
114int dump_disk_config(struct disk_info *dinfo);
115int apply_disk_config(struct disk_info *dinfo, int test);
116char *find_part_device(struct disk_info *dinfo, const char *name);
117int process_disk_config(struct disk_info *dinfo);
118struct part_info *find_part(struct disk_info *dinfo, const char *name);
119
120int write_raw_image(const char *dst, const char *src, loff_t offset, int test);
121
122/* For MBR partition schemes */
123struct write_list *config_mbr(struct disk_info *dinfo);
124char *find_mbr_part(struct disk_info *dinfo, const char *name);
125
126#ifdef __cplusplus
127}
128#endif
129
130#endif /* __LIBS_DISKCONFIG_H */