<commit_before>#include <fs/dentry.h>
#include <fs/fs.h>
#include <fs/inode.h>
#include <fs/path.h>
#include <fs/stat.h>
#include <kernel.h>
#include <mm/heap.h>
#include <string.h>
#include <tm/process.h>

struct inode* fs_root = NULL;

char* dirname(char* path)
{
    char* p;
    if (path == NULL || *path == '\0')
        return "/";
    p = path + strlen(path) - 1;
    while (*p == '/') {
        if (p == path)
            return path;
        *p-- = '\0';
    }
    while (p >= path && *p != '/')
        p--;
    return p < path ? "/" : p == path ? "/" : (*p = '\0', path);
}

static char* basename(const char* name)
{
    const char* base = name;

    while (*name) {
        if (*name++ == '/') {
            base = name;
        }
    }
    return (char*)base;
}

static inline struct inode* path_resolve_mountpoint(struct inode* original)
{
    if (original->i_mp) {
        return original->i_mp->mp_inode;
    } else {
        return original;
    }
}

static struct dentry* __path_resolve_dentry(struct inode* start,
                                            const char* path, int flags)
{
    if (!start || !path)
        return NULL;
    struct inode* inode = start;
    struct dentry* dentry = NULL;
    char* str = (char*)path;
    char* name;
    while (inode && (name = strtok_r(str, "/", &str))) {
        dentry = dentry_lookup(inode, name);
        if (!dentry)
            return NULL;
        inode = inode_resolve_dentry(dentry);
        inode = path_resolve_mountpoint(inode);
    }
    return dentry;
}

static struct inode* __path_resolve(struct inode* start, const char* path,
                                    int flags, struct dentry** dentry)
{
    struct dentry* fdentry = __path_resolve_dentry(start, path, flags);
    if (!fdentry)
        return NULL;
    struct inode* inode = inode_resolve_dentry(fdentry);
    if (dentry)
        *dentry = fdentry;
    return inode;
}

static struct inode* __path_resolve_create(struct inode* start,
                                           const char* path, int flags,
                                           mode_t mode, struct dentry** dentry)
{
    if (!start || !path)
        return NULL;
    char* dirpath = dirname(path);
    char* filename = basename(path);
    struct inode* dir = path_resolve(dirpath, 0, mode, NULL);<commit_msg>__path_resolve_create: Use __path_resolve instead of path_resolve<commit_after>#include <fs/dentry.h>
#include <fs/fs.h>
#include <fs/inode.h>
#include <fs/path.h>
#include <fs/stat.h>
#include <kernel.h>
#include <mm/heap.h>
#include <string.h>
#include <tm/process.h>

struct inode* fs_root = NULL;

char* dirname(char* path)
{
    char* p;
    if (path == NULL || *path == '\0')
        return "/";
    p = path + strlen(path) - 1;
    while (*p == '/') {
        if (p == path)
            return path;
        *p-- = '\0';
    }
    while (p >= path && *p != '/')
        p--;
    return p < path ? "/" : p == path ? "/" : (*p = '\0', path);
}

static char* basename(const char* name)
{
    const char* base = name;

    while (*name) {
        if (*name++ == '/') {
            base = name;
        }
    }
    return (char*)base;
}

static inline struct inode* path_resolve_mountpoint(struct inode* original)
{
    if (original->i_mp) {
        return original->i_mp->mp_inode;
    } else {
        return original;
    }
}

static struct dentry* __path_resolve_dentry(struct inode* start,
                                            const char* path, int flags)
{
    if (!start || !path)
        return NULL;
    struct inode* inode = start;
    struct dentry* dentry = NULL;
    char* str = (char*)path;
    char* name;
    while (inode && (name = strtok_r(str, "/", &str))) {
        dentry = dentry_lookup(inode, name);
        if (!dentry)
            return NULL;
        inode = inode_resolve_dentry(dentry);
        inode = path_resolve_mountpoint(inode);
    }
    return dentry;
}

static struct inode* __path_resolve(struct inode* start, const char* path,
                                    int flags, struct dentry** dentry)
{
    struct dentry* fdentry = __path_resolve_dentry(start, path, flags);
    if (!fdentry)
        return NULL;
    struct inode* inode = inode_resolve_dentry(fdentry);
    if (dentry)
        *dentry = fdentry;
    return inode;
}

static struct inode* __path_resolve_create(struct inode* start,
                                           const char* path, int flags,
                                           mode_t mode, struct dentry** dentry)
{
    if (!start || !path)
        return NULL;
    char* dirpath = dirname(path);
    char* filename = basename(path);
    struct inode* dir = __path_resolve(start, dirpath, 0, NULL);
{'fraction_non_alphanumeric': 0.1392136025504782, 'fraction_numerical': 0.0021253985122210413, 'mean_word_length': 2.0479274611398965, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2420184', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1487, 'n_words': 414}