long uffs_space_total(const char *mount_point) { uffs_Device *dev = NULL; long ret = -1L; dev = uffs_GetDeviceFromMountPoint(mount_point); if (dev) { uffs_GlobalFsLockLock(); ret = (long) uffs_GetDeviceTotal(dev); uffs_GlobalFsLockUnlock(); } return ret; }
int uffs_closedir(uffs_DIR *dirp) { CHK_DIR_LOCK(dirp, -1); uffs_FindObjectClose(&dirp->f); if (dirp->obj) { uffs_CloseObject(dirp->obj); uffs_PutObject(dirp->obj); } PutDirEntry(dirp); uffs_GlobalFsLockUnlock(); return 0; }
int uffs_format(const char *mount_point) { uffs_Device *dev = NULL; URET ret = U_FAIL; dev = uffs_GetDeviceFromMountPoint(mount_point); if (dev) { uffs_GlobalFsLockLock(); ret = uffs_FormatDevice(dev, U_TRUE); uffs_GlobalFsLockUnlock(); } return ret == U_SUCC ? 0 : -1; }
int uffs_flush(int fd) { int ret; uffs_Object *obj; CHK_OBJ_LOCK(fd, obj, -1); uffs_ClearObjectErr(obj); ret = (uffs_FlushObject(obj) == U_SUCC) ? 0 : -1; uffs_set_error(-uffs_GetObjectErr(obj)); uffs_GlobalFsLockUnlock(); return ret; }
long uffs_tell(int fd) { long ret; uffs_Object *obj; CHK_OBJ_LOCK(fd, obj, -1); uffs_ClearObjectErr(obj); ret = (long) uffs_GetCurOffset(obj); uffs_set_error(-uffs_GetObjectErr(obj)); uffs_GlobalFsLockUnlock(); return ret; }
int uffs_eof(int fd) { int ret; uffs_Object *obj; CHK_OBJ_LOCK(fd, obj, -1); uffs_ClearObjectErr(obj); ret = uffs_EndOfFile(obj); uffs_set_error(-uffs_GetObjectErr(obj)); uffs_GlobalFsLockUnlock(); return ret; }
long uffs_seek(int fd, long offset, int origin) { int ret; uffs_Object *obj; CHK_OBJ_LOCK(fd, obj, -1); uffs_ClearObjectErr(obj); ret = uffs_SeekObject(obj, offset, origin); uffs_set_error(-uffs_GetObjectErr(obj)); uffs_GlobalFsLockUnlock(); return ret; }
int uffs_write(int fd, const void *data, int len) { int ret; uffs_Object *obj; CHK_OBJ_LOCK(fd, obj, -1); uffs_ClearObjectErr(obj); ret = uffs_WriteObject(obj, data, len); uffs_set_error(-uffs_GetObjectErr(obj)); uffs_GlobalFsLockUnlock(); return ret; }
long uffs_space_used(const char *mount_point) { uffs_Device *dev = NULL; long ret = -1L; uffs_GlobalFsLockLock(); dev = uffs_GetDeviceFromMountPoint(mount_point); if (dev) { ret = (long) uffs_GetDeviceUsed(dev); uffs_PutDevice(dev); } uffs_GlobalFsLockUnlock(); return ret; }
uffs_DIR * uffs_opendir(const char *path) { int err = 0; uffs_DIR *ret = NULL; uffs_DIR *dirp; uffs_GlobalFsLockLock(); dirp = GetDirEntry(); if (dirp) { dirp->obj = uffs_GetObject(); if (dirp->obj) { if (uffs_OpenObject(dirp->obj, path, UO_RDONLY | UO_DIR) == U_SUCC) { if (uffs_FindObjectOpen(&dirp->f, dirp->obj) == U_SUCC) { ret = dirp; goto ext; } else { uffs_CloseObject(dirp->obj); } } else { err = uffs_GetObjectErr(dirp->obj); } uffs_PutObject(dirp->obj); dirp->obj = NULL; } else { err = UEMFILE; } PutDirEntry(dirp); } else { err = UEMFILE; } ext: uffs_set_error(-err); uffs_GlobalFsLockUnlock(); return ret; }
struct uffs_dirent * uffs_readdir(uffs_DIR *dirp) { struct uffs_dirent *ent = NULL; CHK_DIR_LOCK(dirp, NULL); if (uffs_FindObjectNext(&dirp->info, &dirp->f) == U_SUCC) { ent = &dirp->dirent; ent->d_ino = dirp->info.serial; ent->d_namelen = dirp->info.info.name_len < (sizeof(ent->d_name) - 1) ? dirp->info.info.name_len : (sizeof(ent->d_name) - 1); memcpy(ent->d_name, dirp->info.info.name, ent->d_namelen); ent->d_name[ent->d_namelen] = '\0'; ent->d_off = dirp->f.pos; ent->d_reclen = sizeof(struct uffs_dirent); ent->d_type = dirp->info.info.attr; } uffs_GlobalFsLockUnlock(); return ent; }
int uffs_close(int fd) { int ret = 0; uffs_Object *obj; CHK_OBJ_LOCK(fd, obj, -1); uffs_ClearObjectErr(obj); if (uffs_CloseObject(obj) == U_FAIL) { uffs_set_error(-uffs_GetObjectErr(obj)); ret = -1; } else { uffs_PutObject(obj); ret = 0; } uffs_GlobalFsLockUnlock(); return ret; }
int uffs_stat(const char *name, struct uffs_stat *buf) { uffs_Object *obj; int ret = 0; int err = 0; URET result; uffs_GlobalFsLockLock(); obj = uffs_GetObject(); if (obj) { if (*name && name[strlen(name) - 1] == '/') { result = uffs_OpenObject(obj, name, UO_RDONLY | UO_DIR); } else { if ((result = uffs_OpenObject(obj, name, UO_RDONLY)) != U_SUCC) // try file result = uffs_OpenObject(obj, name, UO_RDONLY | UO_DIR); // then try dir } if (result == U_SUCC) { ret = do_stat(obj, buf); uffs_CloseObject(obj); } else { err = uffs_GetObjectErr(obj); ret = -1; } uffs_PutObject(obj); } else { err = UENOMEM; ret = -1; } uffs_set_error(-err); uffs_GlobalFsLockUnlock(); return ret; }
URET uffs_FormatDevice(uffs_Device *dev, UBOOL force) { u16 i, slot; URET ret = U_SUCC; if (dev == NULL) return U_FAIL; if (dev->ops == NULL) return U_FAIL; uffs_GlobalFsLockLock(); ret = uffs_BufFlushAll(dev); if (dev->ref_count > 1 && !force) { uffs_Perror(UFFS_MSG_NORMAL, "can't format when dev->ref_count = %d", dev->ref_count); ret = U_FAIL; } if (ret == U_SUCC && force) { uffs_DirEntryBufPutAll(dev); uffs_PutAllObjectBuf(dev); uffs_FdSignatureIncrease(); } if (ret == U_SUCC && uffs_BufIsAllFree(dev) == U_FALSE && !force) { uffs_Perror(UFFS_MSG_NORMAL, "some page still in used!"); ret = U_FAIL; } if (!force) { for (slot = 0; ret == U_SUCC && slot < dev->cfg.dirty_groups; slot++) { if (dev->buf.dirtyGroup[slot].count > 0) { uffs_Perror(UFFS_MSG_SERIOUS, "there still have dirty pages!"); ret = U_FAIL; } } } if (ret == U_SUCC) uffs_BufSetAllEmpty(dev); if (ret == U_SUCC && uffs_BlockInfoIsAllFree(dev) == U_FALSE && !force) { uffs_Perror(UFFS_MSG_NORMAL, "there still have block info cache ? fail to format"); ret = U_FAIL; } if (ret == U_SUCC) uffs_BlockInfoExpireAll(dev); for (i = dev->par.start; ret == U_SUCC && i <= dev->par.end; i++) { if (uffs_FlashIsBadBlock(dev, i) == U_FALSE) { uffs_FlashEraseBlock(dev, i); if (HAVE_BADBLOCK(dev)) uffs_BadBlockProcess(dev, NULL); } else { #ifdef CONFIG_ENABLE_BAD_BLOCK_VERIFY _ForceFormatAndCheckBlock(dev, i); #endif } } if (ret == U_SUCC && uffs_TreeRelease(dev) == U_FAIL) { ret = U_FAIL; } if (ret == U_SUCC && uffs_TreeInit(dev) == U_FAIL) { ret = U_FAIL; } if (ret == U_SUCC && uffs_BuildTree(dev) == U_FAIL) { ret = U_FAIL; } uffs_GlobalFsLockUnlock(); return ret; }