/*------------------------------------------------------------------------- * cfs_filename.h * Compressed File Store (CFS) — frontend-safe on-disk format lexicon. * * Sidecar files are named after the MAIN fork path of a relation, with an * extra suffix that identifies the kind of file: * * .cfp compressed page data (may be segmented: .cfp.N) * .cfsmap page map snapshot * .cfsjrn page map journal * * This header is deliberately frontend-safe and is compiled into every * build, with or without CFS support: frontend tools that were built * without CFS (pg_upgrade, pg_checksums) still need the naming lexicon * and the .cfsmap prologue constants to recognize sidecar files and * refuse or skip them. It must not include anything backend-only. * * The suffix macros, CfsFileKind and the map header constants here are * the single source of truth for the on-disk format; the server-side * cfs.h includes this header instead of redefining them. * * Copyright (c) 2026, Kirillov Vyacheslav, QDB Development Group * * IDENTIFICATION * src/include/common/cfs_filename.h * *------------------------------------------------------------------------- */ #ifndef CFS_FILENAME_H #define CFS_FILENAME_H #include "c.h" #include "common/relpath.h" /* ---------------------------------------------------------------- * File extension conventions * ---------------------------------------------------------------- */ #define CFS_DATA_SUFFIX ".cfp" #define CFS_MAP_SUFFIX ".cfsmap" #define CFS_JOURNAL_SUFFIX ".cfsjrn" /* ---------------------------------------------------------------- * CfsFileKind — identifies which sidecar file a path refers to. * * Kept in sync with the suffix macros above through cfs_file_suffix() * in the server's cfs_path.c. * ---------------------------------------------------------------- */ typedef enum CfsFileKind { CFS_FILE_DATA = 0, /* .cfp — append-only compressed page * data */ CFS_FILE_MAP = 1, /* .cfsmap — page map snapshot */ CFS_FILE_JOURNAL = 2, /* .cfsjrn — page map journal */ /* sentinel — keep last */ CFS_FILE_KIND_COUNT } CfsFileKind; /* ---------------------------------------------------------------- * Page Map file prologue (the first bytes of .cfsmap). * * CfsMapPrologue covers only the part a frontend tool needs to check * (magic + version); the server treats the rest of the file as an array * of positional rows (storage/cfs/cfs.h). The prologue is written once * when the file is created and is never rewritten. * ---------------------------------------------------------------- */ /* * CFS is pre-release and no on-disk format has shipped, so the layout may * change without a CFS_MAP_VERSION bump: there are no older builds to * stay compatible with. A released format change must bump the version. */ #define CFS_MAP_MAGIC UINT32_C(0xCF5A4700) #define CFS_MAP_VERSION UINT16_C(2) typedef struct CfsMapPrologue { uint32 magic; /* CFS_MAP_MAGIC */ uint16 version; /* CFS_MAP_VERSION */ uint16 _reserved; /* must be zero */ } CfsMapPrologue; StaticAssertDecl(sizeof(CfsMapPrologue) == 8, "CfsMapPrologue layout matches the on-disk .cfsmap prologue"); /* ---------------------------------------------------------------- * Strict parsing of a putative CFS sidecar filename. * ---------------------------------------------------------------- */ /* * parse_cfs_sidecar_filename * Strict parsing of a putative CFS sidecar filename, mirroring the * rules of parse_filename_for_nontemp_relation(): the name must be * ".cfp"[.], ".cfsmap" or * ".cfsjrn", with no leading zeroes in the numbers. * * Returns true and sets *relnumber, *kind and *segno on success; returns * false (zeroing the outputs) for anything else, including transient * compaction files (".cfp.tmp", ".cfsswap", ...). */ extern bool parse_cfs_sidecar_filename(const char *name, RelFileNumber *relnumber, CfsFileKind *kind, unsigned *segno); #endif /* CFS_FILENAME_H */