netatalk.io

Information for Netatalk Developers

For basic installation instructions, see the Installation chapter in the html manual published on https://netatalk.io and the INSTALL.md file in the root of the source tree.

Netatalk is an implementation of Apple Filing Protocol (AFP) over TCP. The session layer used to carry AFP over TCP is called DSI.

Netatalk also supports the AppleTalk Protocol Suite for legacy Macs, Lisas and Apple IIs via the “atalkd” daemon. It supports EtherTalk Phase I and II, RTMP, NBP, ZIP, AEP, ATP, PAP, and ASP, while expecting the kernel to supply DDP.

The complete stack looks like this on a BSD-derived system:

AFP                          AFP
 |                            |
ASP    PAP                   DSI
  \   /                       |
   ATP RTMP NBP ZIP AEP       |
    |    |   |   |   |        |
-+---------------------------------------------------+- (kernel boundary)
|                    Socket                         |
+-----------------------+------------+--------------+
|                       |     TCP    |    UDP       |
|          DDP          +------------+--------------+
|                       |           IP              |
+-----------------------+---------------------------+
|                Network-Interface                  |
+---------------------------------------------------+

Error checking and logging

We want rigid error checking and concise log messages. This often leads to significant code bloat where the relevant function call is buried in error checking and logging statements. In order to alleviate error checking and code readability, we provide a set of error checking macros in . These macros compare the return value of statements against 0, NULL, -1 (and maybe more, check it out). Every macro comes in four flavours: EC_CHECK, EC_CHECK_LOG, EC_CHECK_LOG_ERR and EC_CHECK_CUSTOM:

The macros EC_CHECK* unconditionally jump to a cleanup label where the necessary cleanup can be done alongside controlling the return value. EC_CHECK_CUSTOM doesn’t do that, so an extra “goto EC_CLEANUP” may be performed as appropriate.

Example:

- stat() without EC macro:
  static int func(const char *name) {
    int ret = 0;
    ...
    if ((ret = stat(name, &some_struct_stat)) != 0) {
      LOG(...);
      ret = -1; /* often needed to explicitly set the error indicating return value */
      goto cleanup;
    }

    return ret;

  cleanup:
    ...
    return ret;
  }

- stat() with EC macro:
  static int func(const char *name) {
    EC_INIT; /* expands to int ret = 0; */

    char *uppername = NULL
    EC_NULL(uppername = strdup(name));
    EC_ZERO(strtoupper(uppername));

    EC_ZERO(stat(uppername, &some_struct_stat)); /* expands to complete if block from above */

    EC_STATUS(0);

EC_CLEANUP:
    if (uppername) free(uppername);
    EC_EXIT;
  }

A boilerplate function template is:

int func(void)
{
    EC_INIT;

    ...your code here...

    EC_STATUS(0);

EC_CLEANUP:
    EC_EXIT;
}

Ini Parser

The ini parser is taken from https://github.com/ndevilla/iniparser. It has been slightly modified:

CNID Database Daemons

The CNID database daemons cnid_metad and cnid_dbd are an implementation of the netatalk CNID database support that attempts to put all functionality into separate daemons. There is one cnid_dbd daemon per netatalk volume. The underlying database structure is based on Berkeley DB.

Advantages

Disadvantages

i) IPC overhead. ii) r/o access to database pages is possible by more than one process at once, r/w access is possible for non overlapping regions.

The current implementation of cnid_dbd uses unix domain sockets as the IPC mechanism. While this is not the fastest possible method, it is very portable and the cnid_dbd IPC mechanisms can be extended to use faster IPC (like mmap) on architectures where it is supported. As a ballpark figure, 20000 requests/replies to the cnid_dbd daemon take about 0.6 seconds on a Pentium III 733 MHz running Linux Kernel 2.4.18 using unix domain sockets. The requests are “empty” (no database lookups/changes), so this is just the IPC overhead.

I have not measured the effects of the advantages of simultaneous database access.

Installation and configuration

There are two executables that will be built in etc/cnid_dbd and installed into the systems binaries directories of netatalk cnid_metad and cnid_dbd. cnid_metad should run all the time with root permissions. It will be notified when an instance of afpd starts up and will in turn make sure that a cnid_dbd daemon is started for the volume that afpd wishes to access. The cnid_dbd daemon runs as long as necessary and services any other instances of afpd that access the volume. You can safely kill it with SIGTERM, it will be restarted automatically by cnid_metad as soon as the volume is accessed again.

cnid_dbd changes to the Berkeley DB directory on startup and sets effective UID and GID to owner and group of that directory. Database and supporting files should therefore be writeable by that user/group.

Current shortcomings: