robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:8.1.1413: error when the drive of the swap file was disconnected (#30009)a89088b7a0

master
2.6 KiB68 linesraw
1#pragma once
2
3#include <stdbool.h>
4#include <stdint.h>
5#include <stdlib.h>
6
7#include "nvim/map_defs.h"
8
9/// A block number.
10///
11/// Blocks numbered from 0 upwards have been assigned a place in the actual
12/// file. The block number is equal to the page number in the file. The blocks
13/// with negative numbers are currently in memory only.
14typedef int64_t blocknr_T;
15
16/// A block header.
17///
18/// There is a block header for each previously used block in the memfile.
19///
20/// The block may be linked in the used list OR in the free list.
21///
22/// The used list is a doubly linked list, most recently used block first.
23/// The blocks in the used list have a block of memory allocated.
24/// The free list is a single linked list, not sorted.
25/// The blocks in the free list have no block of memory allocated and
26/// the contents of the block in the file (if any) is irrelevant.
27typedef struct {
28  blocknr_T bh_bnum;                 ///< key used in hash table
29
30  void *bh_data;                     ///< pointer to memory (for used block)
31  unsigned bh_page_count;            ///< number of pages in this block
32
33#define BH_DIRTY    1U
34#define BH_LOCKED   2U
35  unsigned bh_flags;                 ///< BH_DIRTY or BH_LOCKED
36} bhdr_T;
37
38typedef enum {
39  MF_DIRTY_NO = 0,      ///< no dirty blocks
40  MF_DIRTY_YES,         ///< there are dirty blocks
41  MF_DIRTY_YES_NOSYNC,  ///< there are dirty blocks, do not sync yet
42} mfdirty_T;
43
44/// A memory file.
45typedef struct {
46  char *mf_fname;                    ///< name of the file
47  char *mf_ffname;                   ///< idem, full path
48  int mf_fd;                         ///< file descriptor
49  int mf_flags;                      ///< flags used when opening this memfile
50  bool mf_reopen;                    ///< mf_fd was closed, retry opening
51  bhdr_T *mf_free_first;             ///< first block header in free list
52
53  /// The used blocks are kept in mf_hash.
54  /// mf_hash are used to quickly find a block in the used list.
55  PMap(int64_t) mf_hash;
56
57  /// When a block with a negative number is flushed to the file, it gets
58  /// a positive number. Because the reference to the block is still the negative
59  /// number, we remember the translation to the new positive number.
60  Map(int64_t, int64_t) mf_trans;
61
62  blocknr_T mf_blocknr_max;          ///< highest positive block number + 1
63  blocknr_T mf_blocknr_min;          ///< lowest negative block number - 1
64  blocknr_T mf_neg_count;            ///< number of negative blocks numbers
65  blocknr_T mf_infile_count;         ///< number of pages in the file
66  unsigned mf_page_size;             ///< number of bytes in a page
67  mfdirty_T mf_dirty;
68} memfile_T;