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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ named `ei_block`. This field, `ei_block`, serves different purposes depending
on the type of file:
- For a directory, it contains the list of files within that directory.
A directory can hold a maximum of 40,920 files, with filenames restricted
to a maximum of 255 characters to ensure they fit within a single block.
to a maximum of 254 characters to ensure they fit within a single block.
```
inode
+-----------------------+
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;
Comment thread
RoyWFHuang marked this conversation as resolved.
Comment thread
RoyWFHuang marked this conversation as resolved.
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
15 changes: 15 additions & 0 deletions hash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <linux/dcache.h>
#include <linux/types.h>
#include "simplefs.h"

uint32_t simplefs_hash(struct dentry *dentry)
{
const char *str = dentry->d_name.name;
Comment thread
jserv marked this conversation as resolved.
uint64_t h = 0xcbf29ce484222325ULL;
while (*str) {
h ^= (unsigned char) (*str++);
h *= 0x100000001b3ULL;
}
/* Fold high 32 bits into low 32 bits to mix the full 64-bit result */
return (uint32_t) (h ^ (h >> 32));
}
Comment thread
RoyWFHuang marked this conversation as resolved.
Loading
Loading