/* * Gets an IFSFileEntry from a certain directory, and copies it * into dest */ static int ifs_get_file_entry(int parent, char* dir, IFSFileEntry* dest) { bool has_sep = contains(dir, '/'); int32_t* directory = (int32_t*)(initrd + ifs_get_address(parent)); for(int i = 0; i < 256&& directory[i] != -1; i++) { int e = directory[i]; IFSFileEntry* entry = (IFSFileEntry*)(initrd + ifs_get_address(e)); if(has_sep && strncmp(dir, entry->file_name, strindx(dir, '/')) == 0) { return ifs_get_file_entry(entry->data_index, strrchr(dir, '/') + 1, dest); } else if (!has_sep) { if(strcmp(entry->file_name, dir) == 0) { memcpy(dest, entry, sizeof(IFSFileEntry)); return 1; } } } return 0; }
/* * Returns the index to a directory table */ static int ifs_get_directory(struct device *dev, int parent, char *dir) { if(dir[0] == 0 && parent == 0) return 0; bool has_sep = contains(dir, '/'); int32_t directory[256]; struct ifs_entry dentry; device_read(dev, &dentry, sizeof(struct ifs_entry), ifs_get_address(dev, parent)); int dtable = dentry.data_index; device_read(dev, directory, 1024, ifs_get_address(dev, dtable)); for (int i = 0; i < 256 && directory[i] != -1; i++) { int e = directory[i]; struct ifs_entry entry; device_read(dev, &entry, sizeof(struct ifs_entry), ifs_get_address(dev, e)); if (has_sep && strncmp(dir, entry.file_name, strindx(dir, '/')) == 0) { return ifs_get_directory(dev, e, strrchr(dir, '/') + 1); } else if (!has_sep) { if (strncmp(entry.file_name, dir, strlen(entry.file_name)) == 0) { return e; } } } return -1; }
/* * Returns the index to a directory table */ static int ifs_get_directory(int parent, char* dir) { bool has_sep = contains(dir, '/'); int32_t* directory = (int32_t*)(initrd + ifs_get_address(parent)); for(int i = 0; i < 256 && directory[i] != -1; i++) { int e = directory[i]; IFSFileEntry* entry = (IFSFileEntry*)(initrd + ifs_get_address(e)); if(has_sep && strncmp(dir, entry->file_name, strindx(dir, '/')) == 0) { return ifs_get_directory(entry->data_index, strrchr(dir, '/') + 1); } else if (!has_sep) { if(strncmp(entry->file_name, dir, strlen(entry->file_name)) == 0) { return e; } } } return -1; }