| rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (c) International Business Machines Corp., 2006 | 
|  | 3 | * Copyright (C) 2009 Nokia Corporation | 
|  | 4 | * | 
|  | 5 | * This program is free software; you can redistribute it and/or modify | 
|  | 6 | * it under the terms of the GNU General Public License as published by | 
|  | 7 | * the Free Software Foundation; either version 2 of the License, or | 
|  | 8 | * (at your option) any later version. | 
|  | 9 | * | 
|  | 10 | * This program is distributed in the hope that it will be useful, | 
|  | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | 
|  | 13 | * the GNU General Public License for more details. | 
|  | 14 | * | 
|  | 15 | * You should have received a copy of the GNU General Public License | 
|  | 16 | * along with this program; if not, write to the Free Software | 
|  | 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 
|  | 18 | * | 
|  | 19 | * Author: Artem Bityutskiy | 
|  | 20 | * | 
|  | 21 | * MTD library. | 
|  | 22 | */ | 
|  | 23 |  | 
|  | 24 | #ifndef __LIBMTD_INT_H__ | 
|  | 25 | #define __LIBMTD_INT_H__ | 
|  | 26 |  | 
|  | 27 | #ifdef __cplusplus | 
|  | 28 | extern "C" { | 
|  | 29 | #endif | 
|  | 30 |  | 
|  | 31 | #define PROGRAM_NAME "libmtd" | 
|  | 32 |  | 
|  | 33 | #define SYSFS_MTD        "class/mtd" | 
|  | 34 | #define MTD_NAME_PATT    "mtd%d" | 
|  | 35 | #define MTD_DEV          "dev" | 
|  | 36 | #define MTD_NAME         "name" | 
|  | 37 | #define MTD_TYPE         "type" | 
|  | 38 | #define MTD_EB_SIZE      "erasesize" | 
|  | 39 | #define MTD_SIZE         "size" | 
|  | 40 | #define MTD_MIN_IO_SIZE  "writesize" | 
|  | 41 | #define MTD_SUBPAGE_SIZE "subpagesize" | 
|  | 42 | #define MTD_OOB_SIZE     "oobsize" | 
|  | 43 | #define MTD_REGION_CNT   "numeraseregions" | 
|  | 44 | #define MTD_FLAGS        "flags" | 
|  | 45 |  | 
|  | 46 | #define OFFS64_IOCTLS_UNKNOWN       0 | 
|  | 47 | #define OFFS64_IOCTLS_NOT_SUPPORTED 1 | 
|  | 48 | #define OFFS64_IOCTLS_SUPPORTED     2 | 
|  | 49 |  | 
|  | 50 | /** | 
|  | 51 | * libmtd - MTD library description data structure. | 
|  | 52 | * @sysfs_mtd: MTD directory in sysfs | 
|  | 53 | * @mtd: MTD device sysfs directory pattern | 
|  | 54 | * @mtd_dev: MTD device major/minor numbers file pattern | 
|  | 55 | * @mtd_name: MTD device name file pattern | 
|  | 56 | * @mtd_type: MTD device type file pattern | 
|  | 57 | * @mtd_eb_size: MTD device eraseblock size file pattern | 
|  | 58 | * @mtd_size: MTD device size file pattern | 
|  | 59 | * @mtd_min_io_size: minimum I/O unit size file pattern | 
|  | 60 | * @mtd_subpage_size: sub-page size file pattern | 
|  | 61 | * @mtd_oob_size: MTD device OOB size file pattern | 
|  | 62 | * @mtd_region_cnt: count of additional erase regions file pattern | 
|  | 63 | * @mtd_flags: MTD device flags file pattern | 
|  | 64 | * @sysfs_supported: non-zero if sysfs is supported by MTD | 
|  | 65 | * @offs64_ioctls: %OFFS64_IOCTLS_SUPPORTED if 64-bit %MEMERASE64, | 
|  | 66 | *                 %MEMREADOOB64, %MEMWRITEOOB64 MTD device ioctls are | 
|  | 67 | *                 supported, %OFFS64_IOCTLS_NOT_SUPPORTED if not, and | 
|  | 68 | *                 %OFFS64_IOCTLS_UNKNOWN if it is not known yet; | 
|  | 69 | * | 
|  | 70 | *  Note, we cannot find out whether 64-bit ioctls are supported by MTD when we | 
|  | 71 | *  are initializing the library, because this requires an MTD device node. | 
|  | 72 | *  Indeed, we have to actually call the ioctl and check for %ENOTTY to find | 
|  | 73 | *  out whether it is supported or not. | 
|  | 74 | * | 
|  | 75 | *  Thus, we leave %offs64_ioctls uninitialized in 'libmtd_open()', and | 
|  | 76 | *  initialize it later, when corresponding libmtd function is used, and when | 
|  | 77 | *  we actually have a device node and can invoke an ioctl command on it. | 
|  | 78 | */ | 
|  | 79 | struct libmtd | 
|  | 80 | { | 
|  | 81 | char *sysfs_mtd; | 
|  | 82 | char *mtd; | 
|  | 83 | char *mtd_dev; | 
|  | 84 | char *mtd_name; | 
|  | 85 | char *mtd_type; | 
|  | 86 | char *mtd_eb_size; | 
|  | 87 | char *mtd_size; | 
|  | 88 | char *mtd_min_io_size; | 
|  | 89 | char *mtd_subpage_size; | 
|  | 90 | char *mtd_oob_size; | 
|  | 91 | char *mtd_region_cnt; | 
|  | 92 | char *mtd_flags; | 
|  | 93 | unsigned int sysfs_supported:1; | 
|  | 94 | unsigned int offs64_ioctls:2; | 
|  | 95 | }; | 
|  | 96 |  | 
|  | 97 | int legacy_libmtd_open(void); | 
|  | 98 | int legacy_dev_present(int mtd_num); | 
|  | 99 | int legacy_mtd_get_info(struct mtd_info *info); | 
|  | 100 | int legacy_get_dev_info(const char *node, struct mtd_dev_info *mtd); | 
|  | 101 | int legacy_get_dev_info1(int dev_num, struct mtd_dev_info *mtd); | 
|  | 102 |  | 
|  | 103 | #ifdef __cplusplus | 
|  | 104 | } | 
|  | 105 | #endif | 
|  | 106 |  | 
|  | 107 | #endif /* !__LIBMTD_INT_H__ */ |