1/* 2 * Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#ifndef _VFS_FILES_H_ 32#define _VFS_FILES_H_ 33 34#include "dirent.h" 35#include "sys/stat.h" 36#include "unistd.h" 37#include "los_compiler.h" 38 39#ifdef __cplusplus 40#if __cplusplus 41extern "C" { 42#endif /* __cplusplus */ 43#endif /* __cplusplus */ 44 45#define FILE_STATUS_NOT_USED 0 46#define FILE_STATUS_INITING 1 47#define FILE_STATUS_READY 2 48#define FILE_STATUS_CLOSING 3 49 50struct FileOps; 51struct File; 52struct Dir; 53struct MountPoint; 54 55struct FileOps { 56 int (*open)(struct File *, const char *, int); 57 int (*close)(struct File *); 58 ssize_t (*read)(struct File *, char *, size_t); 59 ssize_t (*write)(struct File *, const char *, size_t); 60 off_t (*lseek)(struct File *, off_t, int); 61 int (*stat)(struct MountPoint *, const char *, struct stat *); 62 int (*truncate)(struct File *, off_t); 63 int (*unlink)(struct MountPoint *, const char *); 64 int (*rename)(struct MountPoint *, const char *, const char *); 65 int (*ioctl)(struct File *, int, unsigned long); 66 int (*sync)(struct File *); 67 int (*opendir)(struct Dir *, const char *); 68 int (*readdir)(struct Dir *, struct dirent *); 69 int (*closedir)(struct Dir *); 70 int (*mkdir)(struct MountPoint *, const char *); 71 int (*rmdir)(struct MountPoint *, const char *); 72}; 73 74struct File { 75 const struct FileOps *fFops; 76 UINT32 fFlags; 77 UINT32 fStatus; 78 off_t fOffset; 79 INT32 fOwner; 80 struct MountPoint *fMp; 81 void *fData; /* file system operations handle, fatfs FIL, etc. */ 82 const char *fullPath; 83}; 84 85struct Dir { 86 struct MountPoint *dMp; 87 struct dirent dDent; 88 off_t dOffset; 89 void *dData; 90}; 91 92int FileToFd(const struct File *file); 93struct File *FdToFile(int fd); 94struct File *VfsFileGet(void); 95struct File *VfsFileGetSpec(int fd); 96void VfsFilePut(struct File *file); 97 98#ifdef __cplusplus 99#if __cplusplus 100} 101#endif /* __cplusplus */ 102#endif /* __cplusplus */ 103 104#endif /* _VFS_FILES_H_ */ 105