/** Changes the directory to the given path @param fat_fs FS_Instance to find all the information from @param current_directory The location of the current directory @param path The name of the directory we want to change into @return Location of the new directory we are in **/ FS_CurrentDir change_dir(FS_Instance *fat_fs, FS_CurrentDir current_directory, char *path){ char *tokens = strtok(path, "/\\"); uint32_t directory = current_directory; while(NULL != tokens) { current_directory = directory; FS_EntryList *list = get_entries(fat_fs, (uint32_t)directory); uint8_t found = 0; while(NULL != list) { FS_Entry *entry = list->node; if((current_directory == directory) && (check_mask(entry->entry->DIR_Attr, ATTR_DIRECTORY))) { char *file_name = get_file_name(entry->entry); if(strcmp(tokens, file_name) == 0) { found = 1; directory = (entry->entry->DIR_FstClusHI << 8) + entry->entry->DIR_FstClusLO; } free(file_name); } FS_EntryList *curr = list; list = list->next; entry_list_cleanup(curr); } if(!found) { printf("Couldn't find directory.\n"); directory = current_directory; break; } tokens = strtok(NULL, "/\\"); } return directory; }
ssize_t um_consume_one_message(um_parser_t* um_parser, const uint8_t* buf, size_t nbuf, uint64_t* reqid_out, mc_msg_t** msg_out) { FBI_ASSERT(um_parser && buf && nbuf > 0 && reqid_out && msg_out); *msg_out = NULL; ssize_t consumed = entry_list_preparer_read(&um_parser->prep, (const char*)buf, nbuf); if (consumed <= 0) { goto error; } /* Because the rank of the unsigned integer is equal to the rank of the * signed integer, the signed integer is converted to the type of the * unsigned integer, and this assertion triggers on error. To get around * this, we do the cast ourselves. */ FBI_ASSERT(consumed <= (ssize_t)nbuf); if (entry_list_preparer_finished(&um_parser->prep)) { entry_list_t elist; if (entry_list_consume_preparer(&elist, &um_parser->prep) < 0) { goto error; } mc_msg_t base; mc_msg_init_not_refcounted(&base); _parse_info_t parse_info; if (_fill_base_msg(&elist, &base, &parse_info) != 0) { goto error; } *reqid_out = parse_info.reqid; *msg_out = _msg_create(&base, &elist, &parse_info); if (*msg_out == NULL) { dbg_error("msg_create failed"); goto error; } FBI_ASSERT((*msg_out)->op != mc_op_end); entry_list_cleanup(&elist); } else { FBI_ASSERT(consumed == nbuf); } return consumed; error: entry_list_preparer_reset_after_failure(&um_parser->prep); // Function that return an error must have not left any messages around FBI_ASSERT(*msg_out == NULL); return -1; }
void um_backing_msg_cleanup(um_backing_msg_t* bmsg) { entry_list_cleanup(&bmsg->elist); bmsg->elist.entries = bmsg->entries_array; bmsg->elist.entries_size = BMSG_ENTRIES_ARRAY_SIZE; if (bmsg->msg != NULL) { mc_msg_decref(bmsg->msg); bmsg->msg = NULL; } bmsg->inuse = 0; }