:github_url: https://github.com/nyx-org/gaia .. _program_listing_file_fs_devfs.hpp: Program Listing for File devfs.hpp ================================== |exhale_lsh| :ref:`Return to documentation for file ` (``fs/devfs.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #define MINORBITS 20 #define MINORMASK ((1U << MINORBITS) - 1) #define MINOR(dev) ((unsigned int)((dev) >> MINORBITS)) #define MAJOR(dev) ((unsigned int)((dev)&MINORMASK)) #define MAKEDEV(ma, mi) (((mi) << MINORBITS) | (ma)) // Pretty much the same thing as tmpfs, but for devices namespace Gaia::Fs { class Devfs : public VnodeOps { public: Result write(Vnode *vn, frg::span buf, off_t off) override; Result read(Vnode *vn, frg::span buf, off_t off) override; Result create(Vnode *cwd, frg::string_view name, VnodeAttr attr, dev_t dev) override; Result link(Vnode *cwd, frg::string_view path, frg::string_view link, VnodeAttr attr) override; Result lookup(Vnode *cwd, frg::string_view name) override; Result mkdir(Vnode *dir, frg::string_view name, VnodeAttr attr) override; Result ioctl(Vnode *node, uint64_t request, void *arg) override; Result getattr(Vnode *node) override; Vm::String get_absolute_path(Vnode *node) override; Result readdir(Vnode *vn, void *buf, size_t max_size, off_t offset) override; }; class DeviceOps { public: virtual Result write(dev_t minor, frg::span buf, off_t off) = 0; virtual Result read(dev_t minor, frg::span buf, off_t off) = 0; virtual Result ioctl(dev_t minor, uint64_t request, void *arg) = 0; virtual Result getattr(dev_t minor) = 0; // TODO: mmap }; Result dev_alloc_major(DeviceOps *ops); void devfs_init(); Devfs *get_devfs(); } // namespace Gaia::Fs