1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef MTD_USER_H
10 #define MTD_USER_H
11 
12 #include <sys/ioctl.h>
13 
14 enum MtdFileMode {
15     MTD_FILE_MODE_NORMAL,
16     MTD_FILE_MODE_RAW,
17     MTD_FILE_MODE_OOB,
18     MTD_FILE_MODE_MAX,
19 };
20 
21 struct MtdInfo {
22     uint8_t type;
23     uint32_t size;        /* Total size of the MTD */
24     uint32_t erasesize;
25     uint32_t writesize;
26     uint32_t oobsize;     /* Amount of OOB data per block (e.g. 16) */
27     uint64_t padding;     /* Old obsolete field; do not use */
28 };
29 
30 struct EraseInfo {
31     uint32_t start;
32     uint32_t length;
33 };
34 
35 struct EraseInfo64 {
36     uint64_t start;
37     uint64_t length;
38 };
39 
40 struct MtdOobBuf {
41     uint32_t start;
42     uint32_t length;
43     unsigned char *ptr;
44 };
45 
46 #define MTD_IOC_GETINFO          _IOR('M', 1, struct MtdInfo)
47 #define MTD_IOC_ERASE            _IOW('M', 2, struct EraseInfo)
48 #define MTD_IOC_WRITEOOB         _IOWR('M', 3, struct MtdOobBuf)
49 #define MTD_IOC_READOOB          _IOWR('M', 4, struct MtdOobBuf)
50 #define MTD_IOC_GETBADBLOCK      _IOW('M', 11, loff_t)
51 #define MTD_IOC_SETBADBLOCK      _IOW('M', 12, loff_t)
52 #define MTD_IOC_SETFILEMODE      _IO('M', 19)
53 #define MTD_IOC_ERASE64          _IOW('M', 20, struct EraseInfo64)
54 
55 #endif /* MTD_USER_H */
56