Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
obj-m += simplefs.o
simplefs-objs := fs.o super.o inode.o file.o dir.o extent.o
simplefs-objs := fs.o super.o inode.o file.o dir.o extent.o hash.o

KDIR ?= /lib/modules/$(shell uname -r)/build

Expand Down
8 changes: 5 additions & 3 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ static int simplefs_iterate(struct file *dir, struct dir_context *ctx)
for (; remained_nr_files && ei < SIMPLEFS_MAX_EXTENTS; ei++) {
if (eblock->extents[ei].ee_start == 0)
continue;

int ei_nr = eblock->extents[ei].nr_files;
/* Iterate over blocks in one extent */
for (bi = 0; bi < eblock->extents[ei].ee_len && remained_nr_files;
for (bi = 0;
bi < eblock->extents[ei].ee_len && remained_nr_files && ei_nr;
bi++) {
bh2 = sb_bread(sb, eblock->extents[ei].ee_start + bi);
if (!bh2) {
Expand All @@ -80,12 +81,13 @@ static int simplefs_iterate(struct file *dir, struct dir_context *ctx)
continue;
}

for (fi = 0; fi < SIMPLEFS_FILES_PER_BLOCK;) {
for (fi = 0; fi < SIMPLEFS_FILES_PER_BLOCK && dblock->nr_files;) {
if (dblock->files[fi].inode != 0) {
if (offset) {
offset--;
} else {
remained_nr_files--;
ei_nr--;
if (!dir_emit(ctx, dblock->files[fi].filename,
SIMPLEFS_FILENAME_LEN,
dblock->files[fi].inode, DT_UNKNOWN)) {
Expand Down
16 changes: 16 additions & 0 deletions hash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <linux/stringhash.h>
#include <linux/types.h>
#include "simplefs.h"

uint32_t simplefs_hash(struct dentry *dentry)
{
/* FIX: Use a deterministic hash like FNV-1a or djb2.*/
/* Use fnv1a_64 algorithm */
Comment on lines +7 to +8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confusing comment. The code DOES use FNV-1a. Remove "FIX:" or clarify intent.

const char *str = dentry->d_name.name;
uint64_t h = 0xcbf29ce484222325ULL;
while (*str) {
h ^= (unsigned char) (*str++);
h *= 0x100000001b3ULL;
}
return h;
}
Loading