/*
 * wnix, a Unix-like operating system for WebAssembly applications.
 * Copyright (C) 2025  Xavier Del Campo Romero
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#include <ramfs.h>
#include <fs/fs.h>
#include <state.h>
#include <sys/stat.h>

static enum state done(void *const args)
{
    return STATE_OK;
}

int ramfs_stat(const struct fs_stat *const s, const struct ramfs *const rfs,
    const union inode_result *const inode, struct fs_ret *const r)
{
    const struct inode *const i = inode->memi;

    *s->sb = (const struct stat)
    {
        .st_atim = i->atim,
        .st_ctim = i->ctim,
        .st_mtim = i->mtim,
        .st_size = i->size,
        .st_blksize = 1,
        .st_ino = i->ino,
        .st_uid = i->uid,
        .st_gid = i->gid,
        .st_mode = i->mode
    };

    *r = (const struct fs_ret)
    {
        .f = done
    };

    return 0;
}
