blob: c57d45d50aecb3ff3bafd41cf7c9ad48f0f54db9 [file] [log] [blame]
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001/*
2 * Copyright (C) 2007 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#ifndef MTDUTILS_H_
18#define MTDUTILS_H_
19
20#include <sys/types.h> // for size_t, etc.
21
22typedef struct MtdPartition MtdPartition;
23
24int mtd_scan_partitions(void);
25
26const MtdPartition *mtd_find_partition_by_name(const char *name);
27
28/* mount_point is like "/system"
29 * filesystem is like "yaffs2"
30 */
31int mtd_mount_partition(const MtdPartition *partition, const char *mount_point,
32 const char *filesystem, int read_only);
33
34/* get the partition and the minimum erase/write block size. NULL is ok.
35 */
36int mtd_partition_info(const MtdPartition *partition,
37 size_t *total_size, size_t *erase_size, size_t *write_size);
38
39/* read or write raw data from a partition, starting at the beginning.
40 * skips bad blocks as best we can.
41 */
42typedef struct MtdReadContext MtdReadContext;
43typedef struct MtdWriteContext MtdWriteContext;
44
45MtdReadContext *mtd_read_partition(const MtdPartition *);
46ssize_t mtd_read_data(MtdReadContext *, char *data, size_t data_len);
47void mtd_read_close(MtdReadContext *);
Doug Zongkerd12560a2010-09-14 14:25:48 -070048void mtd_read_skip_to(const MtdReadContext *, size_t offset);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080049
50MtdWriteContext *mtd_write_partition(const MtdPartition *);
51ssize_t mtd_write_data(MtdWriteContext *, const char *data, size_t data_len);
52off_t mtd_erase_blocks(MtdWriteContext *, int blocks); /* 0 ok, -1 for all */
Doug Zongker4c5f9f32010-01-12 16:18:33 -080053off_t mtd_find_write_start(MtdWriteContext *ctx, off_t pos);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080054int mtd_write_close(MtdWriteContext *);
55
Dees_Troy51a0e822012-09-05 15:24:24 -040056struct MtdPartition {
57 int device_index;
58 unsigned int size;
59 unsigned int erase_size;
60 char *name;
61};
Doug Zongker28ce47c2011-10-28 10:33:05 -070062
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080063#endif // MTDUTILS_H_