blob: 235cbe7ceb940ede1885003f208b3311fd23d32d [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
Ethan Yonkerb8e985c2016-08-31 13:42:11 -050022#ifdef __cplusplus
23extern "C" {
24#endif
25
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080026typedef struct MtdPartition MtdPartition;
27
28int mtd_scan_partitions(void);
29
30const MtdPartition *mtd_find_partition_by_name(const char *name);
31
32/* mount_point is like "/system"
33 * filesystem is like "yaffs2"
34 */
35int mtd_mount_partition(const MtdPartition *partition, const char *mount_point,
36 const char *filesystem, int read_only);
37
38/* get the partition and the minimum erase/write block size. NULL is ok.
39 */
40int mtd_partition_info(const MtdPartition *partition,
41 size_t *total_size, size_t *erase_size, size_t *write_size);
42
43/* read or write raw data from a partition, starting at the beginning.
44 * skips bad blocks as best we can.
45 */
46typedef struct MtdReadContext MtdReadContext;
47typedef struct MtdWriteContext MtdWriteContext;
48
49MtdReadContext *mtd_read_partition(const MtdPartition *);
50ssize_t mtd_read_data(MtdReadContext *, char *data, size_t data_len);
51void mtd_read_close(MtdReadContext *);
52
53MtdWriteContext *mtd_write_partition(const MtdPartition *);
54ssize_t mtd_write_data(MtdWriteContext *, const char *data, size_t data_len);
55off_t mtd_erase_blocks(MtdWriteContext *, int blocks); /* 0 ok, -1 for all */
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080056int mtd_write_close(MtdWriteContext *);
57
Dees_Troy51a0e822012-09-05 15:24:24 -040058struct MtdPartition {
59 int device_index;
60 unsigned int size;
61 unsigned int erase_size;
62 char *name;
63};
Doug Zongker28ce47c2011-10-28 10:33:05 -070064
Ethan Yonkerb8e985c2016-08-31 13:42:11 -050065#ifdef __cplusplus
66}
67#endif
68
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080069#endif // MTDUTILS_H_