mod_tile 0.9.1
Renders map tiles with Mapnik and serves them using Apache HTTP Server
Loading...
Searching...
No Matches
store_file_utils.h File Reference
#include <sys/types.h>
#include "render_config.h"

Go to the source code of this file.

Functions

time_t get_planet_time (const char *tile_dir, const char *xmlname)
 Retrieve the planet database import timestamp used to determine tile expiry.
int mkdirp (const char *path)
 Recursively create all parent directories required for a target file path.
int path_to_xyz (const char *tilepath, const char *path, char *xmlconfig, int *px, int *py, int *pz)
 Parse a metatile or tile filesystem path back into (xmlconfig, px, py, pz).
int xyzo_to_meta (char *path, size_t len, const char *tile_dir, const char *xmlconfig, const char *options, int x, int y, int z)
 Compute the .meta file path and sub-tile index for (xmlconfig, options, x, y, z).
int xyz_to_meta (char *path, size_t len, const char *tile_dir, const char *xmlconfig, int x, int y, int z)
 Compute the .meta file path and sub-tile index for unparameterized (xmlconfig, x, y, z).

Function Documentation

◆ get_planet_time()

time_t get_planet_time ( const char * tile_dir,
const char * xmlname )

Retrieve the planet database import timestamp used to determine tile expiry.

Checks for a PLANET_TIMESTAMP marker file in the following order:

  1. Map-specific path: <tile_dir>/<xmlname>/<PLANET_TIMESTAMP> (when xmlname is non-empty).
  2. Global fallback path: <tile_dir>/<PLANET_TIMESTAMP>.
  3. Default fallback: now - 3 days (259200 seconds ago) if neither file exists.
Parameters
tile_dirBase tile storage directory path.
xmlnameLogical map style name (may be NULL or empty to skip the map-specific check).
Returns
Modification timestamp (st_mtime) of the timestamp file, or time(NULL) - 3 days if no timestamp file can be stated.

◆ mkdirp()

int mkdirp ( const char * path)

Recursively create all parent directories required for a target file path.

Strips the basename after the final '/' (so mkdirp("/a/b/foo.meta") behaves like mkdir -p /a/b) and creates any missing intermediate directories with mode 0777 (modified by the process umask). Tolerates EEXIST races from concurrent threads.

Parameters
pathFull filesystem path to a target file whose parent directories should exist.
Returns
0 if the parent directory exists or was created successfully, or 1 if a path component exists as a non-directory or mkdir() fails.

◆ path_to_xyz()

int path_to_xyz ( const char * tilepath,
const char * path,
char * xmlconfig,
int * px,
int * py,
int * pz )

Parse a metatile or tile filesystem path back into (xmlconfig, px, py, pz).

Strips the base directory prefix (tilepath, or TILE_PATH when compiled without DIRECTORY_HASH and TILE_PATH is non-empty), then parses either:

  • DIRECTORY_HASH layout: /<xmlconfig>/<z>/<h0>/<h1>/<h2>/<h3>/<h4>..., unpacking each 8-bit hash octet into 4 high bits of x and 4 low bits of y.
  • Flat layout: /<xmlconfig>/<z>/<x>/<y>...
Parameters
tilepathExpected base tile directory prefix.
pathFull filesystem path to parse.
xmlconfigOutput buffer (at least 41 bytes) receiving the parsed map style name.
pxOutput pointer receiving the parsed tile X coordinate.
pyOutput pointer receiving the parsed tile Y coordinate.
pzOutput pointer receiving the parsed tile zoom level.
Returns
0 on valid parse and in-bounds coordinates, 1 on prefix/format mismatch or out-of-bounds coordinates, or 2 if a DIRECTORY_HASH component is outside 0..255.

◆ xyz_to_meta()

int xyz_to_meta ( char * path,
size_t len,
const char * tile_dir,
const char * xmlconfig,
int x,
int y,
int z )

Compute the .meta file path and sub-tile index for unparameterized (xmlconfig, x, y, z).

Convenience wrapper around xyzo_to_meta() with an empty options string ("").

Parameters
pathOutput buffer receiving the formatted .meta filesystem path.
lenCapacity of path in bytes.
tile_dirBase tile storage directory path.
xmlconfigLogical map style name.
xGlobal tile X coordinate.
yGlobal tile Y coordinate.
zTile zoom level.
Returns
Linear sub-tile index within the metatile (0 .. METATILE * METATILE - 1).

◆ xyzo_to_meta()

int xyzo_to_meta ( char * path,
size_t len,
const char * tile_dir,
const char * xmlconfig,
const char * options,
int x,
int y,
int z )

Compute the .meta file path and sub-tile index for (xmlconfig, options, x, y, z).

Aligns (x, y) down to the top-left (0, 0) corner of its METATILE x METATILE block (x &= ~mask, y &= ~mask) and computes the sub-tile's linear index within the metatile header table. Formats path using either:

  • DIRECTORY_HASH layout: <tile_dir>/<xmlconfig>/<z>/<h4..h0>[.<options>].meta (interleaving 4-bit nibbles of x and y across 5 directory levels to prevent excessive directory entry counts in leaf folders).
  • Flat layout: <tile_dir>/<xmlconfig>/<z>/<x>/<y>[.<options>].meta
Parameters
pathOutput buffer receiving the formatted .meta filesystem path.
lenCapacity of path in bytes.
tile_dirBase tile storage directory path.
xmlconfigLogical map style name.
optionsStyle parameterization options string (omitted from filename if empty).
xGlobal tile X coordinate.
yGlobal tile Y coordinate.
zTile zoom level.
Returns
Linear sub-tile index within the metatile (0 .. METATILE * METATILE - 1).