/* * This file implements the Directory Entry object and associated operations. */ #include #include #include static void direntry_delete(Object *); /* Directory Entry object type */ ObjectType dirEntryType = { .name = "DIRECTORY ENTRY", .size = sizeof(DirEntry), .delete = direntry_delete, }; /* Hash a file name */ static uint32_t name_hash(const char *name) { uint32_t digest = 5381; int c; while (c = *name++) digest = ((digest << 5) + digest) ^ c; return digest; } /* Destroy a Directory Entry */ static void direntry_delete(Object *obj) { DirEntry *entry = (void *) obj; if (entry->inode) put(entry->inode); } /* Find a Directory Entry by name in a list */ DirEntry * find_direntry(ObjectList *list, const char *name) { DirEntry *entry; uint32_t hash = name_hash(name); foreach (list, entry) { if (__builtin_expect(!(entry->hash), 0)) entry->hash = name_hash(entry->name); if (entry->hash != hash) continue; if (strcmp(entry->name, name)) continue; break; } return entry; }