1 /* 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 22 //typedef struct MtdPartition MtdPartition; 23 typedef struct { 24 int device_index; 25 unsigned int size; 26 unsigned int erase_size; 27 char *name; 28 } MtdPartition; 29 30 31 int mtd_scan_partitions(void); 32 33 const MtdPartition *mtd_find_partition_by_name(const char *name); 34 35 /* mount_point is like "/system" 36 * filesystem is like "yaffs2" 37 */ 38 int mtd_mount_partition(const MtdPartition *partition, const char *mount_point, 39 const char *filesystem, int read_only); 40 41 /* get the partition and the minimum erase/write block size. NULL is ok. 42 */ 43 int mtd_partition_info(const MtdPartition *partition, 44 size_t *total_size, size_t *erase_size, size_t *write_size); 45 46 /* read or write raw data from a partition, starting at the beginning. 47 * skips bad blocks as best we can. 48 */ 49 typedef struct MtdReadContext MtdReadContext; 50 typedef struct MtdWriteContext MtdWriteContext; 51 52 MtdReadContext *mtd_read_partition(const MtdPartition *); 53 ssize_t mtd_read_data(MtdReadContext *, char *data, size_t data_len); 54 void mtd_read_close(MtdReadContext *); 55 void mtd_read_skip_to(const MtdReadContext *, size_t offset); 56 57 MtdWriteContext *mtd_write_partition(const MtdPartition *); 58 ssize_t mtd_write_data(MtdWriteContext *, const char *data, size_t data_len); 59 off_t mtd_erase_blocks(MtdWriteContext *, int blocks); /* 0 ok, -1 for all */ 60 off_t mtd_find_write_start(MtdWriteContext *ctx, off_t pos); 61 int mtd_write_close(MtdWriteContext *); 62 63 int mtd_get_flash_info(size_t *total_size, size_t *block_size, size_t *page_size); 64 #endif // MTDUTILS_H_ 65