<commit_before>#include <lib/memory.h>
#include <lib/string.h>
#include <kernel/log.h>
#include <kernel/modules.h>
#include <kernel/vfs.h>
#include <modules/nodefs/nodefs.h>

static char *filesystem_get_name(struct vfs_filesystem *self, unsigned int index)
{

    struct nodefs_filesystem *filesystem = (struct nodefs_filesystem *)self;

    if (index >= filesystem->count)
        return 0;

    return filesystem->nodes[index]->name;

}

static struct vfs_node *filesystem_find_node(struct vfs_filesystem *self, char *name)
{

    struct nodefs_filesystem *filesystem = (struct nodefs_filesystem *)self;

    unsigned int i;

    for (i = 0; i < filesystem->count; i++)
    {

        if (string_find(filesystem->nodes[i]->name, name))
            return filesystem->nodes[i];

    }

    return 0;

}

static unsigned int filesystem_walk(struct vfs_filesystem *self, unsigned int index)
{

    struct nodefs_filesystem *filesystem = (struct nodefs_filesystem *)self;

    if (index >= filesystem->count)
        return 0;

    return index + 1;

}

static void register_node(struct nodefs_driver *self, struct vfs_node *node)
{

    unsigned int i;

    for (i = 0; i < 128; i++)
    {

        if (!self->filesystem.nodes[i])
        {

            self->filesystem.nodes[i] = node;
            self->filesystem.count++;

            break;

        }

    }

}

static void unregister_node(struct nodefs_driver *self, struct vfs_node *node)
{

    unsigned int i;

    for (i = 0; i < 128; i++)
    {

        if (self->filesystem.nodes[i] == node)
        {

            self->filesystem.nodes[i] = 0;
            self->filesystem.count--;

            break;

        }

    }

}

void nodefs_filesystem_init(struct nodefs_filesystem *filesystem)
{

    vfs_filesystem_init(&filesystem->base, 0, 0, 0, 0, 0, filesystem_get_name, filesystem_find_node, filesystem_walk); 
    filesystem->count = 0;

    memory_clear(filesystem->nodes, sizeof (struct vfs_node *) * 128);

    vfs_register_filesystem(&filesystem->base);

}

void nodefs_driver_init(struct nodefs_driver *driver)<commit_msg>temporary fix to create unique ids for each node<commit_after>#include <lib/memory.h>
#include <lib/string.h>
#include <kernel/log.h>
#include <kernel/modules.h>
#include <kernel/vfs.h>
#include <modules/nodefs/nodefs.h>

static char *filesystem_get_name(struct vfs_filesystem *self, unsigned int index)
{

    index -= 100;

    struct nodefs_filesystem *filesystem = (struct nodefs_filesystem *)self;

    if (index >= filesystem->count)
        return 0;

    return filesystem->nodes[index]->name;

}

static struct vfs_node *filesystem_find_node(struct vfs_filesystem *self, char *name)
{

    struct nodefs_filesystem *filesystem = (struct nodefs_filesystem *)self;

    unsigned int i;

    for (i = 0; i < filesystem->count; i++)
    {

        if (string_find(filesystem->nodes[i]->name, name))
            return filesystem->nodes[i];

    }

    return 0;

}

static unsigned int filesystem_walk(struct vfs_filesystem *self, unsigned int index)
{

    index -= 100;

    struct nodefs_filesystem *filesystem = (struct nodefs_filesystem *)self;

    if (index >= filesystem->count)
        return 0;

    return index + 1 + 100;

}

static void register_node(struct nodefs_driver *self, struct vfs_node *node)
{

    unsigned int i;

    for (i = 0; i < 128; i++)
    {

        if (!self->filesystem.nodes[i])
        {

            self->filesystem.nodes[i] = node;
            self->filesystem.count++;

            break;

        }

    }

}

static void unregister_node(struct nodefs_driver *self, struct vfs_node *node)
{

    unsigned int i;

    for (i = 0; i < 128; i++)
    {

        if (self->filesystem.nodes[i] == node)
        {

            self->filesystem.nodes[i] = 0;
            self->filesystem.count--;

            break;

        }

    }

}

void nodefs_filesystem_init(struct nodefs_filesystem *filesystem)
{

    vfs_filesystem_init(&filesystem->base, 100, 0, 0, 0, 0, filesystem_get_name, filesystem_find_node, filesystem_walk); 
    filesystem->count = 0;

    memory_clear(filesystem->nodes, sizeof (struct vfs_node *) * 128);

    vfs_register_filesystem(&filesystem->base);

}

void nodefs_driver_init(struct nodefs_driver *driver)
{'fraction_non_alphanumeric': 0.12016865776528461, 'fraction_numerical': 0.013352073085031623, 'mean_word_length': 2.913840513290559, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5289335', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1372, 'n_words': 328}