1 /* 2 This file is part of UFFS, the Ultra-low-cost Flash File System. 3 4 Copyright (C) 2005-2009 Ricky Zheng <[email protected]> 5 6 UFFS is free software; you can redistribute it and/or modify it under 7 the GNU Library General Public License as published by the Free Software 8 Foundation; either version 2 of the License, or (at your option) any 9 later version. 10 11 UFFS is distributed in the hope that it will be useful, but WITHOUT 12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 or GNU Library General Public License, as applicable, for more details. 15 16 You should have received a copy of the GNU General Public License 17 and GNU Library General Public License along with UFFS; if not, write 18 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 Boston, MA 02110-1301, USA. 20 21 As a special exception, if other files instantiate templates or use 22 macros or inline functions from this file, or you compile this file 23 and link it with other works to produce a work based on this file, 24 this file does not by itself cause the resulting work to be covered 25 by the GNU General Public License. However the source code for this 26 file must still be made available in accordance with section (3) of 27 the GNU General Public License v2. 28 29 This exception does not invalidate any other reasons why a work based 30 on this file might be covered by the GNU General Public License. 31 */ 32 33 /** 34 * \file uffs_fs.h 35 * \brief uffs basic file operations 36 * \author Ricky Zheng 37 */ 38 39 #ifndef _UFFS_FS_H_ 40 #define _UFFS_FS_H_ 41 42 #include "uffs/uffs_types.h" 43 #include "uffs/uffs.h" 44 #include "uffs/uffs_public.h" 45 #include "uffs/uffs_core.h" 46 47 #ifdef __cplusplus 48 extern "C"{ 49 #endif 50 51 /** file object */ 52 struct uffs_ObjectSt { 53 /******* objects manager ********/ 54 int dev_lock_count; 55 int dev_get_count; 56 57 /******** init level 0 ********/ 58 const char * name; //!< pointer to the start of name, for open or create 59 u32 name_len; //!< name length 60 u16 sum; //!< sum of name 61 uffs_Device *dev; //!< uffs device 62 u32 oflag; 63 u8 type; 64 u16 head_pages; //!< data pages on file head block 65 u16 parent; 66 67 /******* init level 1 ********/ 68 TreeNode *node; //!< file entry node in tree 69 u16 serial; 70 71 /******* output ******/ 72 int err; //!< error number 73 74 /******* current *******/ 75 u32 pos; //!< current position in file 76 77 /***** others *******/ 78 UBOOL attr_loaded; //!< attributes loaded ? 79 UBOOL open_succ; //!< U_TRUE or U_FALSE 80 81 }; 82 83 typedef struct uffs_ObjectSt uffs_Object; 84 85 86 87 #define uffs_GetObjectErr(obj) ((obj)->err) 88 #define uffs_ClearObjectErr(obj) do { (obj)->err = UENOERR; } while (0) 89 90 uffs_Pool * uffs_GetObjectPool(void); 91 92 URET uffs_InitObjectBuf(void); 93 URET uffs_ReleaseObjectBuf(void); 94 int uffs_PutAllObjectBuf(uffs_Device *dev); 95 uffs_Object * uffs_GetObject(void); 96 void uffs_PutObject(uffs_Object *obj); 97 int uffs_GetObjectIndex(uffs_Object *obj); 98 uffs_Object * uffs_GetObjectByIndex(int idx); 99 100 101 /** 102 * Re-initialize an object. 103 * should call this function if you want to re-use an object. 104 */ 105 URET uffs_ReInitObject(uffs_Object *obj); 106 107 URET uffs_ParseObject(uffs_Object *obj, const char *name); 108 109 URET uffs_CreateObjectEx(uffs_Object *obj, uffs_Device *dev, 110 int dir, const char *name, int name_len, int oflag); 111 URET uffs_OpenObjectEx(uffs_Object *obj, uffs_Device *dev, 112 int dir, const char *name, int name_len, int oflag); 113 114 URET uffs_OpenObject(uffs_Object *obj, const char *fullname, int oflag); 115 URET uffs_TruncateObject(uffs_Object *obj, u32 remain); 116 URET uffs_CreateObject(uffs_Object *obj, const char *fullname, int oflag); 117 118 URET uffs_CloseObject(uffs_Object *obj); 119 int uffs_WriteObject(uffs_Object *obj, const void *data, int len); 120 int uffs_ReadObject(uffs_Object *obj, void *data, int len); 121 long uffs_SeekObject(uffs_Object *obj, long offset, int origin); 122 int uffs_GetCurOffset(uffs_Object *obj); 123 int uffs_EndOfFile(uffs_Object *obj); 124 URET uffs_FlushObject(uffs_Object *obj); 125 126 URET uffs_RenameObject(const char *old_name, const char *new_name, int *err); 127 URET uffs_DeleteObject(const char * name, int *err); 128 129 int uffs_GetFreeObjectHandlers(void); 130 131 132 #ifdef __cplusplus 133 } 134 #endif 135 136 137 #endif 138 139