/** * get object information * * \param[in] obj the object to be revealed * \param[out] info object information will be loaded to info * \param[out] err return error code if failed * * \return U_SUCC or U_FAIL * * \node the obj should be openned before call this function. */ URET uffs_GetObjectInfo(uffs_Object *obj, uffs_ObjectInfo *info, int *err) { uffs_Device *dev = obj->dev; URET ret = U_FAIL; uffs_DeviceLock(dev); if (obj && dev && info) { if (obj->parent == PARENT_OF_ROOT) { // this is ROOT. UFFS does not physically has root, just fake it ... memset(info, 0, sizeof(uffs_ObjectInfo)); info->serial = obj->serial; info->info.attr |= (FILE_ATTR_DIR | FILE_ATTR_WRITE); if (err) *err = UENOERR; ret = U_SUCC; } else ret = _LoadObjectInfo(dev, obj->node, info, obj->type, err); } else { if (err) *err = UEINVAL; } uffs_DeviceUnLock(dev); return ret; }
/** * get object information * * \param[in] obj the object to be revealed * \param[out] info object information will be loaded to info * \param[out] err return error code if failed * * \return U_SUCC or U_FAIL * * \node the obj should be openned before call this function. */ URET uffs_GetObjectInfo(uffs_Object *obj, uffs_ObjectInfo *info, int *err) { uffs_Device *dev = obj->dev; URET ret = U_FAIL; uffs_DeviceLock(dev); if (obj && dev && info) { ret = _LoadObjectInfo(dev, obj->node, info, obj->type, err); } else { if (err) *err = UEINVAL; } uffs_DeviceUnLock(dev); return ret; }
static URET do_FindObject(uffs_FindInfo *f, uffs_ObjectInfo *info, u16 x) { URET ret = U_SUCC; TreeNode *node; uffs_Device *dev = f->dev; if (f->step == 0) { //!< working on dirs while (x != EMPTY_NODE) { node = FROM_IDX(x, TPOOL(dev)); if (node->u.dir.parent == f->serial) { f->work = node; f->pos++; if (info) ret = _LoadObjectInfo(dev, node, info, UFFS_TYPE_DIR, NULL); goto ext; } x = node->hash_next; } f->hash++; //come to next hash entry for (; f->hash < DIR_NODE_ENTRY_LEN; f->hash++) { x = dev->tree.dir_entry[f->hash]; while (x != EMPTY_NODE) { node = FROM_IDX(x, TPOOL(dev)); if (node->u.dir.parent == f->serial) { f->work = node; f->pos++; if (info) ret = _LoadObjectInfo(dev, node, info, UFFS_TYPE_DIR, NULL); goto ext; } x = node->hash_next; } } //no subdirs, then lookup files .. f->step++; f->hash = 0; x = EMPTY_NODE; } if (f->step == 1) { while (x != EMPTY_NODE) { node = FROM_IDX(x, TPOOL(dev)); if (node->u.file.parent == f->serial) { f->work = node; f->pos++; if (info) ret = _LoadObjectInfo(dev, node, info, UFFS_TYPE_FILE, NULL); goto ext; } x = node->hash_next; } f->hash++; //come to next hash entry for (; f->hash < FILE_NODE_ENTRY_LEN; f->hash++) { x = dev->tree.file_entry[f->hash]; while (x != EMPTY_NODE) { node = FROM_IDX(x, TPOOL(dev)); if (node->u.file.parent == f->serial) { f->work = node; f->pos++; if (info) ret = _LoadObjectInfo(dev, node, info, UFFS_TYPE_FILE, NULL); goto ext; } x = node->hash_next; } } //no any files, stopped. f->step++; } ret = U_FAIL; ext: return ret; }