1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * Copyright (C) 2007 The Android Open Source Project 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * Licensed under the Apache License, Version 2.0 (the "License"); 5*4882a593Smuzhiyun * you may not use this file except in compliance with the License. 6*4882a593Smuzhiyun * You may obtain a copy of the License at 7*4882a593Smuzhiyun * 8*4882a593Smuzhiyun * http://www.apache.org/licenses/LICENSE-2.0 9*4882a593Smuzhiyun * 10*4882a593Smuzhiyun * Unless required by applicable law or agreed to in writing, software 11*4882a593Smuzhiyun * distributed under the License is distributed on an "AS IS" BASIS, 12*4882a593Smuzhiyun * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*4882a593Smuzhiyun * See the License for the specific language governing permissions and 14*4882a593Smuzhiyun * limitations under the License. 15*4882a593Smuzhiyun */ 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun #ifndef MTDUTILS_H_ 18*4882a593Smuzhiyun #define MTDUTILS_H_ 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun #include <sys/types.h> // for size_t, etc. 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun //typedef struct MtdPartition MtdPartition; 23*4882a593Smuzhiyun typedef struct { 24*4882a593Smuzhiyun int device_index; 25*4882a593Smuzhiyun unsigned int size; 26*4882a593Smuzhiyun unsigned int erase_size; 27*4882a593Smuzhiyun char *name; 28*4882a593Smuzhiyun } MtdPartition; 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun int mtd_scan_partitions(void); 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun const MtdPartition *mtd_find_partition_by_name(const char *name); 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun /* mount_point is like "/system" 36*4882a593Smuzhiyun * filesystem is like "yaffs2" 37*4882a593Smuzhiyun */ 38*4882a593Smuzhiyun int mtd_mount_partition(const MtdPartition *partition, const char *mount_point, 39*4882a593Smuzhiyun const char *filesystem, int read_only); 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun /* get the partition and the minimum erase/write block size. NULL is ok. 42*4882a593Smuzhiyun */ 43*4882a593Smuzhiyun int mtd_partition_info(const MtdPartition *partition, 44*4882a593Smuzhiyun size_t *total_size, size_t *erase_size, size_t *write_size); 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun /* read or write raw data from a partition, starting at the beginning. 47*4882a593Smuzhiyun * skips bad blocks as best we can. 48*4882a593Smuzhiyun */ 49*4882a593Smuzhiyun typedef struct MtdReadContext MtdReadContext; 50*4882a593Smuzhiyun typedef struct MtdWriteContext MtdWriteContext; 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun MtdReadContext *mtd_read_partition(const MtdPartition *); 53*4882a593Smuzhiyun ssize_t mtd_read_data(MtdReadContext *, char *data, size_t data_len); 54*4882a593Smuzhiyun void mtd_read_close(MtdReadContext *); 55*4882a593Smuzhiyun void mtd_read_skip_to(const MtdReadContext *, size_t offset); 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun MtdWriteContext *mtd_write_partition(const MtdPartition *); 58*4882a593Smuzhiyun ssize_t mtd_write_data(MtdWriteContext *, const char *data, size_t data_len); 59*4882a593Smuzhiyun off_t mtd_erase_blocks(MtdWriteContext *, int blocks); /* 0 ok, -1 for all */ 60*4882a593Smuzhiyun off_t mtd_find_write_start(MtdWriteContext *ctx, off_t pos); 61*4882a593Smuzhiyun int mtd_write_close(MtdWriteContext *); 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun int mtd_get_flash_info(size_t *total_size, size_t *block_size, size_t *page_size); 64*4882a593Smuzhiyun #endif // MTDUTILS_H_ 65