From 6f454424153fc205e519f7aada62837487600a8e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 8 Jul 2025 09:28:31 +0200 Subject: refactor: New Embfs TeX specs, and reworked SNU-LIB's fix module. Signed-off-by: Amlal El Mahrouss --- compile_flags.txt | 3 +- examples/fix/fix.cc | 6 +-- lib/embdfs.hpp | 26 +++++----- lib/fix/network.hpp | 5 ++ lib/fix/parser.hpp | 28 +++++------ meta/tex/embdfs.tex | 141 ---------------------------------------------------- meta/tex/embfs.tex | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 178 insertions(+), 172 deletions(-) delete mode 100644 meta/tex/embdfs.tex create mode 100644 meta/tex/embfs.tex diff --git a/compile_flags.txt b/compile_flags.txt index 9863035..b804da6 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,3 +1,4 @@ -I./ -std=c++20 --DEMBDFS_28BIT_LBA \ No newline at end of file +-DEMBFS_28BIT_LBA +-xc++ \ No newline at end of file diff --git a/examples/fix/fix.cc b/examples/fix/fix.cc index 9b983de..af57ae1 100644 --- a/examples/fix/fix.cc +++ b/examples/fix/fix.cc @@ -10,15 +10,15 @@ /* finally test it */ int main(int argc, char** argv) { - snu::fix::fix_visitor visitor; - auto fix = visitor.visit("8=FIX.4.2|9=65|35=A|49=SERVER|56=CLIENT|34=177|52=20090107-18:15:16|98=0|108=30|10=062|"); + snu::fix::visitor visitor; + snu::fix::range_data fix = visitor.visit("8=FIX.4.2|9=65|35=A|49=SERVER|56=CLIENT|34=177|52=20090107-18:15:16|98=0|108=30|10=062|"); std::cout << "magic: " << fix.msg_magic_ << std::endl; for (auto fields : fix.msg_body_) { std::cout << "key: " << fields.first; - std::cout << ",value: " << fields.second << std::endl; + std::cout << ", value: " << fields.second << std::endl; } return 0; diff --git a/lib/embdfs.hpp b/lib/embdfs.hpp index 9ec82d4..7beb1db 100644 --- a/lib/embdfs.hpp +++ b/lib/embdfs.hpp @@ -5,21 +5,21 @@ * Copyright 2025, Amlal El Mahrouss all rights reserved. */ -#ifndef _SNU_EMBDFS_HPP -#define _SNU_EMBDFS_HPP +#ifndef _SNU_EMBFS_HPP +#define _SNU_EMBFS_HPP #include #include -/// @brief A Filesystem designed for tiny storage medias. +/// @brief A filesystem designed for tiny storage medias. /// @author Amlal EL Mahrouss (founder@snu.systems) -namespace snu::embdfs +namespace snu::embfs { namespace details { - struct embdfs_superblock; - struct embdfs_inode; + struct embfs_superblock; + struct embfs_inode; inline constexpr const size_t _superblock_name_len = 16; inline constexpr const size_t _superblock_reserve_len = 462; @@ -27,9 +27,9 @@ namespace snu::embdfs inline constexpr const size_t _inode_arr_len = 12; inline constexpr const size_t _inode_lookup_len = 8; -#ifdef EMBDFS_28BIT_LBA +#ifdef EMBFS_28BIT_LBA typedef std::uint32_t lba_t; -#elif defined(EMBDFS_48BIT_LBA) +#elif defined(EMBFS_48BIT_LBA) typedef std::uint64_t lba_t; #endif @@ -39,7 +39,7 @@ namespace snu::embdfs typedef std::uint8_t utf8_char_t; /// @brief Superblock data structure - struct embdfs_superblock + struct embfs_superblock { sword_t s_block_mag; sdword_t s_num_inodes; @@ -60,7 +60,7 @@ namespace snu::embdfs /// @brief i_checksum crc32 checksum. /// @brief i_flags_perms flags and permissions /// @brief i_acl_* ACL to keep track of inode allocation status. - struct embdfs_inode + struct embfs_inode { utf8_char_t i_name[_inode_name_len]; sword_t i_size_virt, i_size_phys; @@ -70,8 +70,8 @@ namespace snu::embdfs }; /// @brief Indexed node linear array. - typedef embdfs_inode embdfs_inode_arr_t[_inode_arr_len]; + typedef embfs_inode embfs_inode_arr_t[_inode_arr_len]; } // namespace details -} // namespace snu::embdfs +} // namespace snu::embfs -#endif // ifndef _SNU_EMBDFS_HPP \ No newline at end of file +#endif // ifndef _SNU_EMBFS_HPP \ No newline at end of file diff --git a/lib/fix/network.hpp b/lib/fix/network.hpp index 0c167e5..95de49b 100644 --- a/lib/fix/network.hpp +++ b/lib/fix/network.hpp @@ -11,4 +11,9 @@ #include #include +namespace snu::fix +{ + +} + #endif // ifndef _SNU_FIX_NETWORK_HPP \ No newline at end of file diff --git a/lib/fix/parser.hpp b/lib/fix/parser.hpp index c20fe2f..edafc5a 100644 --- a/lib/fix/parser.hpp +++ b/lib/fix/parser.hpp @@ -17,21 +17,21 @@ namespace snu::fix { - struct fix_visitor; - struct fix_range; - struct fix_range_data; + struct visitor; + struct range; + struct range_data; /// @brief Buffer+Length structure - typedef fix_range* fix_range_ptr_t; + typedef range* range_ptr_t; - struct fix_range final + struct range final { char* ascii_bytes_; uint16_t length_; }; /// @brief Convert range to usable string. - inline std::string to_string(fix_range& range) noexcept + inline std::string to_string(range& range) noexcept { if (range.length_ < 0) return ""; @@ -39,7 +39,7 @@ namespace snu::fix return std::string(range.ascii_bytes_, range.length_); } - class fix_range_data final + class range_data final { public: std::string msg_magic_; @@ -47,21 +47,21 @@ namespace snu::fix std::vector> msg_body_; }; - class fix_visitor final + class visitor final { public: static constexpr auto soh = '|'; static constexpr auto base = 10U; - explicit fix_visitor() = default; - ~fix_visitor() = default; + explicit visitor() = default; + ~visitor() = default; - fix_visitor& operator=(const fix_visitor&) = default; - fix_visitor(const fix_visitor&) = default; + visitor& operator=(const visitor&) = default; + visitor(const visitor&) = default; - fix_range_data visit(const std::string& in) + range_data visit(const std::string& in) { - fix_range_data ret{}; + range_data ret{}; std::string in_tmp; diff --git a/meta/tex/embdfs.tex b/meta/tex/embdfs.tex deleted file mode 100644 index d6e6e99..0000000 --- a/meta/tex/embdfs.tex +++ /dev/null @@ -1,141 +0,0 @@ -\documentclass{article} -\usepackage[a4paper,margin=1in]{geometry} -\usepackage{listings} -\usepackage{xcolor} -\usepackage{amsmath} -\usepackage{hyperref} -\usepackage{longtable} -\usepackage{graphicx} -\usepackage{fancyhdr} -\usepackage{titlesec} -\usepackage{caption} - -\titleformat{\section}{\normalfont\Large\bfseries}{\thesection}{1em}{} - -\definecolor{codegray}{gray}{0.95} -\lstset{ - backgroundcolor=\color{codegray}, - basicstyle=\ttfamily\small, - breaklines=true, - frame=single, - tabsize=4, - language=C++, - showstringspaces=false -} - -\title{Embedded File System (EMBFS) Specification} -\author{Amlal El Mahrouss} -\date{2025} - -\begin{document} - -\maketitle - -\section{Overview} -The \textbf{Embedded File System (EMBFS)} is a compact and minimal filesystem designed for use in embedded environments with limited storage media. This specification describes its key data structures, constants, and layout. - -\section{Namespace} -The EMBFS implementation resides under: -\begin{lstlisting} -namespace snu::embdfs -\end{lstlisting} - -\section{Supported Logical Block Addressing (LBA) Modes} -Two LBA addressing modes are supported via macro definitions: -\begin{itemize} - \item \texttt{EMBDFS\_28BIT\_LBA} — Uses \texttt{uint32\_t}. - \item \texttt{EMBDFS\_48BIT\_LBA} — Uses \texttt{uint64\_t}. -\end{itemize} - -\section{Fundamental Types} -\begin{longtable}{|l|l|} -\hline -\textbf{Type} & \textbf{Definition} \\ -\hline -\texttt{lba\_t} & 28-bit or 48-bit logical block address \\ -\texttt{sword\_t} & \texttt{int16\_t} \\ -\texttt{sdword\_t} & \texttt{int32\_t} \\ -\texttt{utf8\_char\_t} & \texttt{uint8\_t}, used for file names and labels \\ -\hline -\end{longtable} - -\section{Constants} -\begin{longtable}{|l|l|} -\hline -\textbf{Constant} & \textbf{Description} \\ -\hline -\texttt{\_superblock\_name\_len} & Length of superblock name (16 bytes) \\ -\texttt{\_superblock\_reserve\_len} & Reserved bytes in superblock (462 bytes) \\ -\texttt{\_inode\_name\_len} & Length of inode file name (128 bytes) \\ -\texttt{\_inode\_arr\_len} & Number of inodes per partition (12) \\ -\texttt{\_inode\_lookup\_len} & Number of direct LBA pointers in inode (8) \\ -\hline -\end{longtable} - -\section{Superblock Structure} -\textbf{Structure:} \texttt{embdfs\_superblock} -\begin{lstlisting} -struct embdfs_superblock { - sword_t s_block_mag; - sdword_t s_num_inodes; - sdword_t s_part_size; - sdword_t s_part_used; - sdword_t s_version; - sword_t s_sector_sz; - lba_t s_inode_start; - lba_t s_inode_end; - utf8_char_t s_name[16]; - utf8_char_t s_reserved[462]; -}; -\end{lstlisting} - -\textbf{Description:} -\begin{itemize} - \item \texttt{s\_block\_mag} — Magic number identifying the filesystem - \item \texttt{s\_num\_inodes} — Total number of inodes - \item \texttt{s\_part\_size} — Total size of the partition (in sectors) - \item \texttt{s\_part\_used} — Used size of the partition - \item \texttt{s\_version} — Filesystem version - \item \texttt{s\_sector\_sz} — Sector size (in bytes) - \item \texttt{s\_inode\_start}, \texttt{s\_inode\_end} — LBA range where inodes are stored - \item \texttt{s\_name} — Filesystem label - \item \texttt{s\_reserved} — Reserved for future use -\end{itemize} - -\section{Inode Structure} -\textbf{Structure:} \texttt{embdfs\_inode} -\begin{lstlisting} -struct embdfs_inode { - utf8_char_t i_name[128]; - sword_t i_size_virt, i_size_phys; - lba_t i_offset[8]; - sword_t i_checksum, i_flags_perms; - lba_t i_acl_creat, i_acl_edit, i_acl_delet; -}; -\end{lstlisting} - -\textbf{Description:} -\begin{itemize} - \item \texttt{i\_name} — UTF-8 encoded file name - \item \texttt{i\_size\_virt} — Virtual file size (logical size) - \item \texttt{i\_size\_phys} — Physical size in sectors - \item \texttt{i\_offset} — Array of direct LBA pointers - \item \texttt{i\_checksum} — CRC32 checksum of file contents - \item \texttt{i\_flags\_perms} — Flags and permissions field - \item \texttt{i\_acl\_creat}, \texttt{i\_acl\_edit}, \texttt{i\_acl\_delet} — ACLs for access control -\end{itemize} - -\section{Inode Array Type} -\begin{lstlisting} -typedef embdfs_inode embdfs_inode_arr_t[12]; -\end{lstlisting} -Represents a fixed-size array of 12 inodes within a given partition. - -\section{License} -\begin{itemize} - \item Copyright © 2025 Amlal El Mahrouss - \item All rights reserved. - \item For questions or licensing requests, contact: \texttt{founder@snu.systems} -\end{itemize} - -\end{document} \ No newline at end of file diff --git a/meta/tex/embfs.tex b/meta/tex/embfs.tex new file mode 100644 index 0000000..e72d4b4 --- /dev/null +++ b/meta/tex/embfs.tex @@ -0,0 +1,141 @@ +\documentclass{article} +\usepackage[a4paper,margin=1in]{geometry} +\usepackage{listings} +\usepackage{xcolor} +\usepackage{amsmath} +\usepackage{hyperref} +\usepackage{longtable} +\usepackage{graphicx} +\usepackage{fancyhdr} +\usepackage{titlesec} +\usepackage{caption} + +\titleformat{\section}{\normalfont\Large\bfseries}{\thesection}{1em}{} + +\definecolor{codegray}{gray}{0.95} +\lstset{ + backgroundcolor=\color{codegray}, + basicstyle=\ttfamily\small, + breaklines=true, + frame=single, + tabsize=4, + language=C++, + showstringspaces=false +} + +\title{Embedded File System (EMBFS) Specification} +\author{Amlal El Mahrouss} +\date{2025} + +\begin{document} + +\maketitle + +\section{Overview} +The \textbf{Embedded File System (EMBFS)} is a compact and minimal filesystem designed for use in embedded environments with limited storage media. This specification describes its key data structures, constants, and layout. + +\section{Namespace} +The EMBFS implementation resides under: +\begin{lstlisting} +namespace snu::embfs +\end{lstlisting} + +\section{Supported Logical Block Addressing (LBA) Modes} +Two LBA addressing modes are supported via macro definitions: +\begin{itemize} + \item \texttt{EMBFS\_28BIT\_LBA} — Uses \texttt{uint32\_t}. + \item \texttt{EMBFS\_48BIT\_LBA} — Uses \texttt{uint64\_t}. +\end{itemize} + +\section{Fundamental Types} +\begin{longtable}{|l|l|} +\hline +\textbf{Type} & \textbf{Definition} \\ +\hline +\texttt{lba\_t} & 28-bit or 48-bit logical block address \\ +\texttt{sword\_t} & \texttt{int16\_t} \\ +\texttt{sdword\_t} & \texttt{int32\_t} \\ +\texttt{utf8\_char\_t} & \texttt{uint8\_t}, used for file names and labels \\ +\hline +\end{longtable} + +\section{Constants} +\begin{longtable}{|l|l|} +\hline +\textbf{Constant} & \textbf{Description} \\ +\hline +\texttt{\_superblock\_name\_len} & Length of superblock name (16 bytes) \\ +\texttt{\_superblock\_reserve\_len} & Reserved bytes in superblock (462 bytes) \\ +\texttt{\_inode\_name\_len} & Length of inode file name (128 bytes) \\ +\texttt{\_inode\_arr\_len} & Number of inodes per partition (12) \\ +\texttt{\_inode\_lookup\_len} & Number of direct LBA pointers in inode (8) \\ +\hline +\end{longtable} + +\section{Superblock Structure} +\textbf{Structure:} \texttt{embfs\_superblock} +\begin{lstlisting} +struct embfs_superblock { + sword_t s_block_mag; + sdword_t s_num_inodes; + sdword_t s_part_size; + sdword_t s_part_used; + sdword_t s_version; + sword_t s_sector_sz; + lba_t s_inode_start; + lba_t s_inode_end; + utf8_char_t s_name[16]; + utf8_char_t s_reserved[462]; +}; +\end{lstlisting} + +\textbf{Description:} +\begin{itemize} + \item \texttt{s\_block\_mag} — Magic number identifying the filesystem + \item \texttt{s\_num\_inodes} — Total number of inodes + \item \texttt{s\_part\_size} — Total size of the partition (in sectors) + \item \texttt{s\_part\_used} — Used size of the partition + \item \texttt{s\_version} — Filesystem version + \item \texttt{s\_sector\_sz} — Sector size (in bytes) + \item \texttt{s\_inode\_start}, \texttt{s\_inode\_end} — LBA range where inodes are stored + \item \texttt{s\_name} — Filesystem label + \item \texttt{s\_reserved} — Reserved for future use +\end{itemize} + +\section{Inode Structure} +\textbf{Structure:} \texttt{embfs\_inode} +\begin{lstlisting} +struct embfs_inode { + utf8_char_t i_name[128]; + sword_t i_size_virt, i_size_phys; + lba_t i_offset[8]; + sword_t i_checksum, i_flags_perms; + lba_t i_acl_creat, i_acl_edit, i_acl_delet; +}; +\end{lstlisting} + +\textbf{Description:} +\begin{itemize} + \item \texttt{i\_name} — UTF-8 encoded file name + \item \texttt{i\_size\_virt} — Virtual file size (logical size) + \item \texttt{i\_size\_phys} — Physical size in sectors + \item \texttt{i\_offset} — Array of direct LBA pointers + \item \texttt{i\_checksum} — CRC32 checksum of file contents + \item \texttt{i\_flags\_perms} — Flags and permissions field + \item \texttt{i\_acl\_creat}, \texttt{i\_acl\_edit}, \texttt{i\_acl\_delet} — ACLs for access control +\end{itemize} + +\section{Inode Array Type} +\begin{lstlisting} +typedef embfs_inode embfs_inode_arr_t[12]; +\end{lstlisting} +Represents a fixed-size array of 12 inodes within a given partition. + +\section{License} +\begin{itemize} + \item Copyright © 2025 Amlal El Mahrouss + \item All rights reserved. + \item For questions or licensing requests, contact: \texttt{founder@snu.systems} +\end{itemize} + +\end{document} \ No newline at end of file -- cgit v1.2.3