netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
ad_cache.h File Reference
`#include <stdbool.h>`
`#include <sys/stat.h>`
`#include <atalk/adouble.h>`
`#include <atalk/directory.h>`
`#include <atalk/volume.h>`

Go to the source code of this file.

## Functions
void | ad_store_to_cache (struct adouble *adp, struct dir *cached)
| Store AD metadata results into struct dir cache fields.
void | ad_rebuild_from_cache (struct adouble *adp, const struct dir *cached)
| Populate struct adouble from struct dir cache fields.
int | ad_metadata_cached (const char *name, int flags, struct adouble *adp, const struct vol *vol, struct dir *dir, bool strict, struct stat *recent_st)
| Unified AD metadata access with integrated cache management.
int | rfork_cache_store_from_fd (struct dir *entry, struct adouble *adp, int eid)
| Store resource fork data by reading directly from the ad fd.
void | rfork_cache_free (struct dir *entry)
| Free a single entry's rfork buffer, remove from rfork LRU, update counter.
void | rfork_cache_evict_to_budget (size_t needed)
| Evict rfork buffers from rfork LRU head (oldest/LRU) until under budget.

## Variables
unsigned long long | ad_cache_hits
unsigned long long | ad_cache_misses
unsigned long long | ad_cache_no_ad

## Function Documentation

## ◆ ad_metadata_cached()

int ad_metadata_cached | ( | const char * | name,
|  | int | flags,
|  | struct adouble * | adp,
|  | const struct vol * | vol,
|  | struct dir * | dir,
|  | bool | strict,
|  | struct stat * | recent_st )
| extern

Unified AD metadata access with integrated cache management.

Read-only metadata accessor with internal ad_close(). Callers needing a writable fd (e.g., for ad_setid/ad_flush) must call ad_open() separately.

strict=false: cache-first (enumerate, FPGetFileDirParms). strict=true: validate ctime/inode before serving (moveandrename, deletecurdir). recent_st: optional stat to avoid duplicate ostat() in strict path.

## ◆ ad_rebuild_from_cache()

void ad_rebuild_from_cache | ( | struct adouble * | adp,
|  | const struct dir * | cached )
| extern

Populate struct adouble from struct dir cache fields.

Sets up the entry directory in adp so that ad_getattr(), ad_getdate(), ad_entry() all work normally — downstream code is completely unchanged.

Precondition
  ad_init() must have been called on adp to set up ad_eid[] offsets and valid_data_len via ad_init_offsets(). As of E-006, ad_init() now calls ad_init_offsets() internally.

## ◆ ad_store_to_cache()

void ad_store_to_cache | ( | struct adouble * | adp,
|  | struct dir * | cached )
| extern

Store AD metadata results into struct dir cache fields.

Called after every ad_metadata() disk read when a cached entry is available. Pre-computes the served FILPBIT_MDATE value as max(ad_mdate, dcache_mtime).

ad_entry() returns NULL if the entry doesn't exist in this AD version. This is fine — zero-initialized cache fields are valid defaults: zero FinderInfo = no custom attributes zero FileDatesI = overridden by stat mtime fallback zero AFPFileI = no attributes

## ◆ rfork_cache_evict_to_budget()

void rfork_cache_evict_to_budget | ( | size_t | needed | ) |
| extern

Evict rfork buffers from rfork LRU head (oldest/LRU) until under budget.

Queue convention: sentinel->next = head = LRU (oldest), sentinel->prev = tail = MRU (newest). Called by rfork_cache_store_from_fd() when budget would be exceeded. O(k) where k = entries evicted.

## ◆ rfork_cache_free()

void rfork_cache_free | ( | struct dir * | entry | ) |
| extern

Free a single entry's rfork buffer, remove from rfork LRU, update counter.

Uses dcache_rlen for the buffer size. INVARIANT: dcache_rlen >= 0 when dcache_rfork_buf != NULL. Uses production-safe fallback: if dcache_rlen < 0 (invariant violation), logs error, frees buffer, but does NOT touch budget counter (unknown size). Handles rfork_lru_node == NULL gracefully (orphaned buffer from enqueue failure — budget is still decremented correctly). Decrements rfork_lru_count when removing from LRU. Does NOT reset dcache_rlen — the AD metadata remains valid.

## ◆ rfork_cache_store_from_fd()

int rfork_cache_store_from_fd | ( | struct dir * | entry,
|  | struct adouble * | adp,
|  | int | eid )
| extern

Store resource fork data by reading directly from the ad fd.

Allocates dcache_rlen bytes and does ad_read(adp, eid, 0, buf, dcache_rlen). ad_read() handles all storage formats (EA, macOS xattr, AD v2 sidecar). Guards: returns -1 if !AD_RSRC_OPEN(adp) (fd not open), dcache_rlen <= 0, or rlen > rfork_max_entry_size. Validates that ad_read returns exactly dcache_rlen bytes — if not, the fork size changed since Tier 1 metadata was cached: invalidates ALL cached AD metadata (Tier 1) and returns -1 (self-healing).

Returns
  0 on success, -1 if not cacheable, short read, or ad_read failed.

## Variable Documentation

## ◆ ad_cache_hits

unsigned long long ad_cache_hits
| extern

## ◆ ad_cache_misses

unsigned long long ad_cache_misses
| extern

## ◆ ad_cache_no_ad

unsigned long long ad_cache_no_ad
| extern