/* Copyright (c) 2019-2024 Griefer@Work                                       *
 *                                                                            *
 * This software is provided 'as-is', without any express or implied          *
 * warranty. In no event will the authors be held liable for any damages      *
 * arising from the use of this software.                                     *
 *                                                                            *
 * Permission is granted to anyone to use this software for any purpose,      *
 * including commercial applications, and to alter it and redistribute it     *
 * freely, subject to the following restrictions:                             *
 *                                                                            *
 * 1. The origin of this software must not be misrepresented; you must not    *
 *    claim that you wrote the original software. If you use this software    *
 *    in a product, an acknowledgement (see the following) in the product     *
 *    documentation is required:                                              *
 *    Portions Copyright (c) 2019-2024 Griefer@Work                           *
 * 2. Altered source versions must be plainly marked as such, and must not be *
 *    misrepresented as being the original software.                          *
 * 3. This notice may not be removed or altered from any source distribution. *
 */
#ifndef ROOTENT
#define ROOTENT(name, type, perm, fnode_ops_ptr, hash)
#endif /* !ROOTENT */
#ifndef MKDIR_BEGIN
#define MKDIR_BEGIN(ops_symbol_name)
#endif /* !MKDIR_BEGIN */
#ifndef MKDIR_ENT
#define MKDIR_ENT(name, type, perm, fnode_ops_ptr, hash)
#endif /* !MKDIR_ENT */
#ifndef MKDIR_END
#define MKDIR_END
#endif /* !MKDIR_END */
#ifndef MKREG_RO
#define MKREG_RO(ops_symbol_name, printer)
#endif /* !MKREG_RO */
#ifndef MKREG_RW
#define MKREG_RW(ops_symbol_name, printer, writer)
#endif /* !MKREG_RW */
#ifndef MKLNK
#define MKLNK(ops_symbol_name, readlink)
#endif /* !MKLNK */

#include <__stdinc.h>
#include <hybrid/compiler.h>

#include <hybrid/host.h>

#include <compat/config.h>

/* clang-format off */



/* NOTE: All filename listings must be sorted lexicographically ascending */

/* /proc/[PID] */
ROOTENT("attr",      DT_DIR, 0555, &procfs_pp_attr,      /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0x6181769, 0x72747461, 0x6d181802, 0x72747461)/*[[[end]]]*/)
ROOTENT("cmdline",   DT_REG, 0444, &procfs_pp_cmdline,   /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0xcfed46e4, 0x656e696c646d63, 0x7f3df635, 0x656e696c646d63)/*[[[end]]]*/)
ROOTENT("comm",      DT_REG, 0644, &procfs_pp_comm,      /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0xd8d8ea7b, 0x6d6d6f63, 0x7eead8d5, 0x6d6d6f63)/*[[[end]]]*/)
ROOTENT("cwd",       DT_LNK, 0777, &procfs_pp_cwd,       /*[[[fdirent_hash]]]*/0x647763/*[[[end]]]*/)
ROOTENT("environ",   DT_REG, 0444, &procfs_pp_environ,   /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0xb59850ff, 0x6e6f7269766e65, 0x91509923, 0x6e6f7269766e65)/*[[[end]]]*/)
ROOTENT("exe",       DT_LNK, 0777, &procfs_pp_exe,       /*[[[fdirent_hash]]]*/0x657865/*[[[end]]]*/)
ROOTENT("fd",        DT_DIR, 0500, &procfs_pp_fd,        /*[[[fdirent_hash]]]*/0x6466/*[[[end]]]*/)
ROOTENT("fdinfo",    DT_DIR, 0500, &procfs_pp_fdinfo,    /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0xe1b4f6fc, 0x6f666e696466, 0x99882444, 0x6f666e696466)/*[[[end]]]*/)
ROOTENT("kos",       DT_DIR, 0555, &procfs_pp_kos,       /*[[[fdirent_hash]]]*/0x736f6b/*[[[end]]]*/)
ROOTENT("map_files", DT_DIR, 0500, &procfs_pp_map_files, /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0xc35e8886, 0x90cfb4995af36d48, 0x35895e0f, 0xd86cf35a99b4d000)/*[[[end]]]*/)
ROOTENT("maps",      DT_REG, 0444, &procfs_pp_maps,      /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0xef36cd5, 0x7370616d, 0xd86cf40b, 0x7370616d)/*[[[end]]]*/)
ROOTENT("mounts",    DT_REG, 0444, &procfs_pp_mounts,    /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0xe2215e49, 0x73746e756f6d, 0xd8eb9452, 0x73746e756f6d)/*[[[end]]]*/)
ROOTENT("root",      DT_LNK, 0777, &procfs_pp_root,      /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0x17eaeb02, 0x746f6f72, 0x5eaeb14, 0x746f6f72)/*[[[end]]]*/)
ROOTENT("smaps",     DT_REG, 0444, &procfs_pp_smaps,     /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0xf36cd97e, 0x7370616d73, 0xed86d63, 0x7370616d73)/*[[[end]]]*/)
ROOTENT("stat",      DT_REG, 0444, &procfs_pp_stat,      /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0x176d180b, 0x74617473, 0xf176d14, 0x74617473)/*[[[end]]]*/)
ROOTENT("status",    DT_REG, 0444, &procfs_pp_status,    /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0x176d8b80, 0x737574617473, 0xf17e089, 0x737574617473)/*[[[end]]]*/)
#ifndef DEFINE_PERTASK_ROOT_DIRECTORY
ROOTENT("task",      DT_DIR, 0555, &procfs_pp_task,      /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0xc70e6d14, 0x6b736174, 0x176d0ec3, 0x6b736174)/*[[[end]]]*/)
#endif /* !DEFINE_PERTASK_ROOT_DIRECTORY */
#if defined(__x86_64__) || defined(__i386__)
ROOTENT("x86",       DT_DIR, 0555, &procfs_pp_x86,       /*[[[fdirent_hash]]]*/0x363878/*[[[end]]]*/)
#endif /* __x86_64__ || __i386__ */

MKREG_RO(procfs_pp_cmdline, procfs_pp_cmdline_print)
MKREG_RW(procfs_pp_comm, procfs_pp_comm_print, procfs_pp_comm_write)
MKREG_RO(procfs_pp_environ, procfs_pp_environ_print)
MKREG_RO(procfs_pp_maps, procfs_pp_maps_print)
MKREG_RO(procfs_pp_mounts, procfs_pp_mounts_print)
MKREG_RO(procfs_pp_smaps, procfs_pp_smaps_print)
MKREG_RO(procfs_pp_stat, procfs_pp_stat_print)
MKREG_RO(procfs_pp_status, procfs_pp_status_print)


/* /proc/[PID]/attr */
MKDIR_BEGIN(procfs_pp_attr)
	MKDIR_ENT("current", DT_REG, 0666, &procfs_pp_attr_current, /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0x67a8ee0, 0x746e6572727563, 0x7f957467, 0x746e6572727563)/*[[[end]]]*/)
MKDIR_END
MKREG_RO(procfs_pp_attr_current, procfs_pp_attr_current_print)

/* /proc/[PID]/kos */
MKDIR_BEGIN(procfs_pp_kos)
	MKDIR_ENT("dcwd",       DT_DIR, 0555, &procfs_pp_kos_dcwd,       /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0x88327e84, 0x64776364, 0x877f3284, 0x64776364)/*[[[end]]]*/)
	MKDIR_ENT("drives",     DT_DIR, 0555, &procfs_pp_kos_drives,     /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0x29b578e9, 0x736576697264, 0x8806288b, 0x736576697264)/*[[[end]]]*/)
	MKDIR_ENT("peb-addr",   DT_REG, 0644, &procfs_pp_kos_peb_addr,   /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0x61a99fd9, 0x587876a987590f0, 0xfc9b983f, 0xf39073986c878802)/*[[[end]]]*/)
#ifdef __ARCH_HAVE_COMPAT
	MKDIR_ENT("peb-compat", DT_REG, 0644, &procfs_pp_kos_peb_compat, /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0x4ffb774c, 0xf3d8ea7c98760551, 0xeff5d8e, 0xf39073987eeb4d51)/*[[[end]]]*/)
#endif /* __ARCH_HAVE_COMPAT */
MKDIR_END
MKREG_RW(procfs_pp_kos_peb_addr, procfs_pp_kos_peb_addr_print, procfs_pp_kos_peb_addr_write)
#ifdef __ARCH_HAVE_COMPAT
MKREG_RW(procfs_pp_kos_peb_compat, procfs_pp_kos_peb_compat_print, procfs_pp_kos_peb_compat_write)
#endif /* __ARCH_HAVE_COMPAT */

#if defined(__x86_64__) || defined(__i386__)
/* /proc/[PID]/x86 */
MKDIR_BEGIN(procfs_pp_x86)
	MKDIR_ENT("iopl", DT_REG, 0666, &procfs_pp_x86_iopl, /*[[[fdirent_hash]]]*/FDIRENT_HASH_INIT(0xcff3eab1, 0x6c706f69, 0xb4eaf3cc, 0x6c706f69)/*[[[end]]]*/)
MKDIR_END
MKREG_RW(procfs_pp_x86_iopl, procfs_pp_x86_iopl_print, procfs_pp_x86_iopl_write)
#endif /* __x86_64__ || __i386__ */


/* clang-format on */

#undef ROOTENT
#undef MKDIR_BEGIN
#undef MKDIR_ENT
#undef MKDIR_END
#undef MKDIR_EN
#undef MKREG_RO
#undef MKREG_RW
#undef MKLNK
