1 /*
2  * Copyright (c) 2016 Intel Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Disk Access layer API
10  *
11  * This file contains APIs for disk access.
12  */
13 
14 #ifndef ZEPHYR_INCLUDE_STORAGE_DISK_ACCESS_H_
15 #define ZEPHYR_INCLUDE_STORAGE_DISK_ACCESS_H_
16 
17 /**
18  * @brief Storage APIs
19  * @defgroup storage_apis Storage APIs
20  * @ingroup os_services
21  * @{
22  * @}
23  */
24 
25 /**
26  * @brief Disk Access APIs
27  * @defgroup disk_access_interface Disk Access Interface
28  * @ingroup storage_apis
29  * @{
30  */
31 
32 #include <zephyr/drivers/disk.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /**
39  * @brief perform any initialization
40  *
41  * This call is made by the consumer before doing any IO calls so that the
42  * disk or the backing device can do any initialization.
43  *
44  * @param[in] pdrv          Disk name
45  *
46  * @return 0 on success, negative errno code on fail
47  */
48 int disk_access_init(const char *pdrv);
49 
50 /**
51  * @brief Get the status of disk
52  *
53  * This call is used to get the status of the disk
54  *
55  * @param[in] pdrv          Disk name
56  *
57  * @return DISK_STATUS_OK or other DISK_STATUS_*s
58  */
59 int disk_access_status(const char *pdrv);
60 
61 /**
62  * @brief read data from disk
63  *
64  * Function to read data from disk to a memory buffer.
65  *
66  * @param[in] pdrv          Disk name
67  * @param[in] data_buf      Pointer to the memory buffer to put data.
68  * @param[in] start_sector  Start disk sector to read from
69  * @param[in] num_sector    Number of disk sectors to read
70  *
71  * @return 0 on success, negative errno code on fail
72  */
73 int disk_access_read(const char *pdrv, uint8_t *data_buf,
74 		     uint32_t start_sector, uint32_t num_sector);
75 
76 /**
77  * @brief write data to disk
78  *
79  * Function write data from memory buffer to disk.
80  *
81  * @param[in] pdrv          Disk name
82  * @param[in] data_buf      Pointer to the memory buffer
83  * @param[in] start_sector  Start disk sector to write to
84  * @param[in] num_sector    Number of disk sectors to write
85  *
86  * @return 0 on success, negative errno code on fail
87  */
88 int disk_access_write(const char *pdrv, const uint8_t *data_buf,
89 		      uint32_t start_sector, uint32_t num_sector);
90 
91 /**
92  * @brief Get/Configure disk parameters
93  *
94  * Function to get disk parameters and make any special device requests.
95  *
96  * @param[in] pdrv          Disk name
97  * @param[in] cmd           DISK_IOCTL_* code describing the request
98  * @param[in] buff          Command data buffer
99  *
100  * @return 0 on success, negative errno code on fail
101  */
102 int disk_access_ioctl(const char *pdrv, uint8_t cmd, void *buff);
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 /**
109  * @}
110  */
111 
112 #endif /* ZEPHYR_INCLUDE_STORAGE_DISK_ACCESS_H_ */
113