Third party developers wishing to add Netatalk support to their applications have two choices
Please note that you need at least Netatalk 3.0.1 for approach 2 to work, because in earlier Netatalk versions some necessary headers are not installed correctly.
This examples links a trivial example program with the libatalk shared library. Assuming Netatalk has been installed to /usr/local/netatalk, compiling backup_demo.c is done like this:
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#define ERROR(...) \
do { \
_log(__VA_ARGS__); \
exit(1); \
} while (0)
static void _log(
char *fmt, ...)
{
int len;
static char logbuffer[1024];
len = vsnprintf(logbuffer, 1023, fmt,
args);
logbuffer[1023] = 0;
printf("%s\n", logbuffer);
}
int main(
int argc,
char **argv)
{
const char *file, *newfile;
struct stat st;
if (argc != 3) {
ERROR(
"usage: backup_demo FILE NEWFILE");
}
file = argv[1];
newfile = argv[2];
ERROR(
"No Netatalk 3 afp.conf found", file);
ERROR(
"Couldn't load volumes");
ERROR(
"Not a Netatalk volume for file \"%s\"", file);
printf("Volume adouble version v2\n");
printf("Volume adouble version ea\n");
} else {
ERROR(
"Unknown adouble version");
}
ERROR(
"Couldn't open metadata of \"%s\"", file);
printf(
"%d bytes in adouble metadata buffer ad->ad_data\n",
ad_size);
ERROR(
"Couldn't open ressource of \"%s\"", file);
printf(
"File has ressource fork of size: %d, fd: %d\n", ad.ad_rlen,
ad_reso_fileno(&ad));
if (lstat(newfile, &st) != 0)
ERROR(
"Can't stat \"%s\", must exist, create with eg touch", newfile);
ERROR(
"Couldn't create metadata/ressource of \"%s\"", newfile);
memcpy(adnew.ad_data, ad.ad_data,
ad_size);
ERROR(
"Couln't copy ressource to \"%s\"", newfile);
#if 0
#endif
return 0;
}
#define ADFLAGS_CREATE
Definition adouble.h:243
#define AD_DATE_CREATE
Definition adouble.h:287
#define AD_VERSION2
Definition adouble.h:45
#define AD_DATASZ_EA
Definition adouble.h:127
#define AD_DATE_START
Definition adouble.h:294
#define ADFLAGS_RDWR
Definition adouble.h:241
void ad_init(struct adouble *, const struct vol *)
Definition ad_open.c:2243
int ad_open(struct adouble *ad, const char *path, int adflags,...)
Open data-, metadata(header)- or resource fork.
Definition ad_open.c:2304
off_t ad_size(const struct adouble *, uint32_t)
Definition ad_size.c:18
#define AD_DATE_UNIX
Definition adouble.h:293
#define AD_DATE_BACKUP
Definition adouble.h:289
int ad_flush(struct adouble *)
Definition ad_flush.c:439
int ad_close(struct adouble *, int)
Close a struct adouble freeing all resources.
Definition ad_flush.c:476
#define AD_DATASZ2
Definition adouble.h:119
#define AD_VERSION_EA
Definition adouble.h:46
#define ADFLAGS_HF
Definition adouble.h:235
#define ADFLAGS_RDONLY
Definition adouble.h:242
#define ad_reso_fileno(ad)
Definition adouble.h:359
#define AD_DATE_MODIFY
Definition adouble.h:288
#define ADFLAGS_RF
Definition adouble.h:234
#define AD_DATE_ACCESS
Definition adouble.h:290
int ad_setdate(struct adouble *, unsigned int, uint32_t)
Definition ad_date.c:10
void setuplog(const char *loglevel, const char *logfile, const bool log_us_timestamp)
Definition logger.c:547
#define ERROR(...)
Definition nad.h:45
void _log(enum logtype lt, char *fmt,...)
Definition nad_util.c:79
static AFPObj obj
Definition netatalk.c:62
struct vol * getvolbypath(AFPObj *obj, const char *path)
Search volume by path, creating user home vols as necessary.
Definition netatalk_conf.c:2199
int load_volumes(AFPObj *obj, lv_flags_t flags)
Initialize volumes and load ini configfile.
Definition netatalk_conf.c:1932
int afp_config_parse(AFPObj *obj, char *processname)
Initialize an AFPObj and options from ini config file.
Definition netatalk_conf.c:2439
int(* vfs_copyfile)(const struct vol *vol, int sfd, const char *src, const char *dst)
Definition vfs.h:109
Definition include/atalk/volume.h:32
int v_adouble
Definition include/atalk/volume.h:51
char * v_path
Definition include/atalk/volume.h:37
struct vfs_ops * vfs
Definition include/atalk/volume.h:79
static char * args[]
Definition test.c:48
int main()
Definition test.c:51