libmtd_int.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #ifndef __LIBMTD_INT_H__
  24. #define __LIBMTD_INT_H__
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. #define PROGRAM_NAME "libmtd"
  29. #ifndef SYSFS_ROOT
  30. #define SYSFS_ROOT "/sys"
  31. #endif
  32. #define SYSFS_MTD "class/mtd"
  33. #define MTD_NAME_PATT "mtd%d"
  34. #define MTD_DEV "dev"
  35. #define MTD_NAME "name"
  36. #define MTD_TYPE "type"
  37. #define MTD_EB_SIZE "erasesize"
  38. #define MTD_SIZE "size"
  39. #define MTD_MIN_IO_SIZE "writesize"
  40. #define MTD_SUBPAGE_SIZE "subpagesize"
  41. #define MTD_OOB_SIZE "oobsize"
  42. #define MTD_OOBAVAIL "oobavail"
  43. #define MTD_REGION_CNT "numeraseregions"
  44. #define MTD_FLAGS "flags"
  45. #define OFFS64_IOCTLS_UNKNOWN 0
  46. #define OFFS64_IOCTLS_NOT_SUPPORTED 1
  47. #define OFFS64_IOCTLS_SUPPORTED 2
  48. /**
  49. * libmtd - MTD library description data structure.
  50. * @sysfs_mtd: MTD directory in sysfs
  51. * @mtd: MTD device sysfs directory pattern
  52. * @mtd_dev: MTD device major/minor numbers file pattern
  53. * @mtd_name: MTD device name file pattern
  54. * @mtd_type: MTD device type file pattern
  55. * @mtd_eb_size: MTD device eraseblock size file pattern
  56. * @mtd_size: MTD device size file pattern
  57. * @mtd_min_io_size: minimum I/O unit size file pattern
  58. * @mtd_subpage_size: sub-page size file pattern
  59. * @mtd_oob_size: MTD device OOB size file pattern
  60. * @mtd_oobavail: MTD device free OOB size file pattern
  61. * @mtd_region_cnt: count of additional erase regions file pattern
  62. * @mtd_flags: MTD device flags file pattern
  63. * @sysfs_supported: non-zero if sysfs is supported by MTD
  64. * @offs64_ioctls: %OFFS64_IOCTLS_SUPPORTED if 64-bit %MEMERASE64,
  65. * %MEMREADOOB64, %MEMWRITEOOB64 MTD device ioctls are
  66. * supported, %OFFS64_IOCTLS_NOT_SUPPORTED if not, and
  67. * %OFFS64_IOCTLS_UNKNOWN if it is not known yet;
  68. *
  69. * Note, we cannot find out whether 64-bit ioctls are supported by MTD when we
  70. * are initializing the library, because this requires an MTD device node.
  71. * Indeed, we have to actually call the ioctl and check for %ENOTTY to find
  72. * out whether it is supported or not.
  73. *
  74. * Thus, we leave %offs64_ioctls uninitialized in 'libmtd_open()', and
  75. * initialize it later, when corresponding libmtd function is used, and when
  76. * we actually have a device node and can invoke an ioctl command on it.
  77. */
  78. struct libmtd
  79. {
  80. char *sysfs_mtd;
  81. char *mtd;
  82. char *mtd_dev;
  83. char *mtd_name;
  84. char *mtd_type;
  85. char *mtd_eb_size;
  86. char *mtd_size;
  87. char *mtd_min_io_size;
  88. char *mtd_subpage_size;
  89. char *mtd_oob_size;
  90. char *mtd_oobavail;
  91. char *mtd_region_cnt;
  92. char *mtd_flags;
  93. unsigned int sysfs_supported:1;
  94. unsigned int offs64_ioctls:2;
  95. };
  96. int legacy_procfs_is_supported(void);
  97. int legacy_dev_present(int mtd_num);
  98. int legacy_mtd_get_info(struct mtd_info *info);
  99. int legacy_get_dev_info(const char *node, struct mtd_dev_info *mtd);
  100. int legacy_get_dev_info1(int dev_num, struct mtd_dev_info *mtd);
  101. int legacy_get_mtd_oobavail(const char *node);
  102. int legacy_get_mtd_oobavail1(int mtd_num);
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106. #endif /* !__LIBMTD_INT_H__ */