netatalk: fork.c File Reference

netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
fork.c File Reference
`#include <errno.h>`
`#include <fcntl.h>`
`#include <inttypes.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <sys/param.h>`
`#include <sys/socket.h>`
`#include <unistd.h>`
`#include <bstrlib.h>`
`#include <atalk/adouble.h>`
`#include <atalk/afp.h>`
`#include <atalk/asp.h>`
`#include <atalk/cnid.h>`
`#include <atalk/dsi.h>`
`#include <atalk/globals.h>`
`#include <atalk/logger.h>`
`#include <atalk/netatalk_conf.h>`
`#include <atalk/util.h>`
`#include "ad_cache.h"`
`#include "dircache.h"`
`#include "desktop.h"`
`#include "directory.h"`
`#include "file.h"`
`#include "fork.h"`
`#include "virtual_icon.h"`
`#include "volume.h"`

## Macros
#define | ENDBIT(a)
#define | UNLOCKBIT(a)

## Functions
static int | materialize_virtual_icon (struct ofork *ofork)
| Materialize a virtual Icon fork into a real file on disk.
static int | getforkparams (const AFPObj *obj, struct ofork *ofork, uint16_t bitmap, char *buf, size_t *buflen)
static off_t | get_off_t (char **ibuf, int is64)
static int | set_off_t (off_t offset, char *rbuf, int is64)
static int | is_neg (int is64, off_t val)
static int | sum_neg (int is64, off_t offset, off_t reqcount)
static int | fork_setmode (const AFPObj *obj, struct adouble *adp, int eid, int access, int ofrefnum)
int | afp_openfork (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
static void | rfork_invalidate_for_ofork (const struct vol *vol, struct ofork *ofork)
| Invalidate cached rfork data for a file identified by its open fork.
int | afp_setforkparams (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
static int | byte_lock (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen, int is64)
int | afp_bytelock (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
int | afp_bytelock_ext (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
static int | read_file (const struct ofork *ofork, int eid, off_t offset, char *rbuf, size_t *rbuflen)
| Read *rbuflen bytes from fork at offset.
static int | rfork_cache_serve_from_buf (DSI *dsi, struct dir *cached_entry, char *ibuf, off_t offset, off_t reqcount, int err, size_t *rbuflen)
| Serve resource fork data from Tier 2 cache via DSI framing.
static int | read_fork (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen, int is64)
int | afp_read (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
int | afp_read_ext (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
int | afp_flush (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
int | afp_flushfork (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
int | afp_syncfork (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
int | flushfork (struct ofork *ofork)
int | afp_closefork (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
static ssize_t | write_file (struct ofork *ofork, int eid, off_t offset, char *rbuf, size_t rbuflen)
static int | write_fork (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen, int is64)
int | afp_write (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
int | afp_write_ext (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
int | afp_getforkparams (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)

## Macro Definition Documentation

## ◆ ENDBIT

#define ENDBIT | ( |  | a | ) |

Value:
((a) & 0x80)

## ◆ UNLOCKBIT

#define UNLOCKBIT | ( |  | a | ) |

Value:
((a) & 0x01)

## Function Documentation

## ◆ afp_bytelock()

int afp_bytelock | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ afp_bytelock_ext()

int afp_bytelock_ext | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ afp_closefork()

int afp_closefork | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ afp_flush()

int afp_flush | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ afp_flushfork()

int afp_flushfork | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ afp_getforkparams()

int afp_getforkparams | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ afp_openfork()

int afp_openfork | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ afp_read()

int afp_read | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ afp_read_ext()

int afp_read_ext | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ afp_setforkparams()

int afp_setforkparams | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ afp_syncfork()

int afp_syncfork | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

Bug
  There is a lot to tell about fsync, fdatasync, F_FULLFSYNC. fsync(2) on OSX is implemented differently than on other platforms.

See also
  http://mirror.linux.org.au/pub/linux.conf.au/2007/video/talks/278.pdf

## ◆ afp_write()

int afp_write | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ afp_write_ext()

int afp_write_ext | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen )

## ◆ byte_lock()

int byte_lock | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen,
|  | int | is64 )
| static

## ◆ flushfork()

int flushfork | ( | struct ofork * | ofork | ) |

## ◆ fork_setmode()

int fork_setmode | ( | const AFPObj * | obj,
|  | struct adouble * | adp,
|  | int | eid,
|  | int | access,
|  | int | ofrefnum )
| static

## ◆ get_off_t()

off_t get_off_t | ( | char ** | ibuf,
|  | int | is64 )
| static

## ◆ getforkparams()

int getforkparams | ( | const AFPObj * | obj,
|  | struct ofork * | ofork,
|  | uint16_t | bitmap,
|  | char * | buf,
|  | size_t * | buflen )
| static

## ◆ is_neg()

int is_neg | ( | int | is64,
|  | off_t | val )
| static

## ◆ materialize_virtual_icon()

int materialize_virtual_icon | ( | struct ofork * | ofork | ) |
| static

Materialize a virtual Icon fork into a real file on disk.

Creates the physical Icon file, seeds its resource fork with the virtual icon data, sets FinderInfo, and re-opens the fork through ad_open so the ofork has real file descriptors for writing.

Returns
  AFP_OK on success, or an AFP error code

## ◆ read_file()

int read_file | ( | const struct ofork * | ofork,
|  | int | eid,
|  | off_t | offset,
|  | char * | rbuf,
|  | size_t * | rbuflen )
| static

Read *rbuflen bytes from fork at offset.

Parameters

  [in] | ofork | fork handle
  [in] | eid | data fork or resource fork entry id
  [in] | offset | offset
  [in] | rbuf | data buffer
  [in,out] | rbuflen | in: number of bytes to read, out: bytes read

Returns
  AFP status code

## ◆ read_fork()

int read_fork | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen,
|  | int | is64 )
| static

## ◆ rfork_cache_serve_from_buf()

int rfork_cache_serve_from_buf | ( | DSI * | dsi,
|  | struct dir * | cached_entry,
|  | char * | ibuf,
|  | off_t | offset,
|  | off_t | reqcount,
|  | int | err,
|  | size_t * | rbuflen )
| static

Serve resource fork data from Tier 2 cache via DSI framing.

Shared helper for cache-hit and just-populated cache paths in read_fork(). Handles dsi_readinit/dsi_read/dsi_readdone loop and LRU promotion.

Parameters

  [in] | dsi | DSI connection
  [in] | cached_entry | dir entry with populated dcache_rfork_buf
  [in] | ibuf | DSI write buffer (repurposed from command buffer)
  [in] | offset | Starting byte offset in the rfork
  [in] | reqcount | Requested byte count
  [in] | err | AFP error code (AFPERR_EOF or AFP_OK)
  [out] | rbuflen | Output: bytes remaining (set by dsi_read)

Returns
  0 on success (goto afp_read_done), -1 on DSI error (goto afp_read_exit)

## ◆ rfork_invalidate_for_ofork()

void rfork_invalidate_for_ofork | ( | const struct vol * | vol,
|  | struct ofork * | ofork )
| static

Invalidate cached rfork data for a file identified by its open fork.

Looks up the file's dircache entry via parent DID + name, and invalidates the AD cache (Tier 1 + Tier 2). Used after rfork writes and truncations.

## ◆ set_off_t()

int set_off_t | ( | off_t | offset,
|  | char * | rbuf,
|  | int | is64 )
| static

## ◆ sum_neg()

int sum_neg | ( | int | is64,
|  | off_t | offset,
|  | off_t | reqcount )
| static

## ◆ write_file()

ssize_t write_file | ( | struct ofork * | ofork,
|  | int | eid,
|  | off_t | offset,
|  | char * | rbuf,
|  | size_t | rbuflen )
| static

## ◆ write_fork()

int write_fork | ( | AFPObj * | obj,
|  | char * | ibuf,
|  | size_t | ibuflen,
|  | char * | rbuf,
|  | size_t * | rbuflen,
|  | int | is64 )
| static