1 /*
2  * Copyright (c) 2025, sakumisu
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #ifndef USBD_MTP_H
7 #define USBD_MTP_H
8 
9 #include "usb_mtp.h"
10 #include <sys/stat.h>
11 #include <fcntl.h>
12 
13 /* gcc toolchain does not implement dirent.h, so we define our own MTP_DIR and mtp_dirent */
14 
15 typedef void MTP_DIR;
16 
17 struct mtp_statfs {
18     size_t f_bsize;  /* block size */
19     size_t f_blocks; /* total data blocks in file system */
20     size_t f_bfree;  /* free blocks in file system */
21 };
22 
23 struct mtp_dirent {
24     uint8_t d_type;                              /* The type of the file */
25     uint8_t d_namlen;                            /* The length of the not including the terminating null file name */
26     uint16_t d_reclen;                           /* length of this record */
27     char d_name[CONFIG_USBDEV_MTP_MAX_PATHNAME]; /* The null-terminated file name */
28 };
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 struct usbd_interface *usbd_mtp_init_intf(struct usbd_interface *intf,
35                                           const uint8_t out_ep,
36                                           const uint8_t in_ep,
37                                           const uint8_t int_ep);
38 
39 int usbd_mtp_notify_object_add(const char *path);
40 int usbd_mtp_notify_object_remove(const char *path);
41 
42 const char *usbd_mtp_fs_root_path(void);
43 const char *usbd_mtp_fs_description(void);
44 
45 int usbd_mtp_mkdir(const char *path);
46 int usbd_mtp_rmdir(const char *path);
47 MTP_DIR *usbd_mtp_opendir(const char *name);
48 int usbd_mtp_closedir(MTP_DIR *d);
49 struct mtp_dirent *usbd_mtp_readdir(MTP_DIR *d);
50 
51 int usbd_mtp_statfs(const char *path, struct mtp_statfs *buf);
52 int usbd_mtp_stat(const char *file, struct stat *buf);
53 
54 int usbd_mtp_open(const char *path, uint8_t mode);
55 int usbd_mtp_close(int fd);
56 int usbd_mtp_read(int fd, void *buf, size_t len);
57 int usbd_mtp_write(int fd, const void *buf, size_t len);
58 
59 int usbd_mtp_unlink(const char *path);
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 
65 #endif /* USBD_MTP_H */
66