netatalk  4.4.0dev
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
volume.c File Reference
#include <arpa/inet.h>
#include <ctype.h>
#include <errno.h>
#include <grp.h>
#include <inttypes.h>
#include <netinet/in.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <time.h>
#include <utime.h>
#include <bstrlib.h>
#include <iniparser.h>
#include <atalk/adouble.h>
#include <atalk/afp.h>
#include <atalk/dsi.h>
#include <atalk/ea.h>
#include <atalk/errchk.h>
#include <atalk/fce_api.h>
#include <atalk/globals.h>
#include <atalk/logger.h>
#include <atalk/netatalk_conf.h>
#include <atalk/server_ipc.h>
#include <atalk/unix.h>
#include <atalk/util.h>
#include <atalk/uuid.h>
#include <atalk/vfs.h>
#include <atalk/volume.h>
#include "acls.h"
#include "directory.h"
#include "file.h"
#include "fork.h"
#include "hash.h"
#include "mangle.h"
#include "unix.h"
#include "volume.h"

Macros

#define TM_USED_CACHETIME   60
#define VOLPASSLEN   8

Functions

int afprun (char *cmd, int *outfd)
static long long int get_tm_bandsize (const char *path)
static long long int get_tm_bands (const char *path)
static int get_tm_used (struct vol *restrict vol)
static int getvolspace (const AFPObj *obj, struct vol *vol, uint32_t *bfree, uint32_t *btotal, VolSpace *xbfree, VolSpace *xbtotal, uint32_t *bsize)
static void vol_setdate (uint16_t id, struct adouble *adp, time_t date)
static int getvolparams (const AFPObj *obj, uint16_t bitmap, struct vol *vol, struct stat *st, char *buf, size_t *buflen)
static int stat_vol (const AFPObj *obj, uint16_t bitmap, struct vol *vol, char *rbuf, size_t *rbuflen)
int afp_getsrvrparms (AFPObj *obj, char *ibuf _U_, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
static int volume_codepage (AFPObj *obj, struct vol *volume)
static int volume_openDB (const AFPObj *obj _U_, struct vol *volume)
static void server_ipc_volumes (AFPObj *obj)
int afp_openvol (AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
void closevol (const AFPObj *obj, struct vol *vol)
void close_all_vol (const AFPObj *obj)
int afp_closevol (AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
int pollvoltime (AFPObj *obj)
void setvoltime (AFPObj *obj, struct vol *vol)
int afp_getvolparams (AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
int afp_setvolparams (AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)

Macro Definition Documentation

◆ TM_USED_CACHETIME

#define TM_USED_CACHETIME   60

◆ VOLPASSLEN

#define VOLPASSLEN   8

Function Documentation

◆ afp_closevol()

int afp_closevol ( AFPObj * obj,
char * ibuf,
size_t ibuflen _U_,
char *rbuf _U_,
size_t * rbuflen )

◆ afp_getsrvrparms()

int afp_getsrvrparms ( AFPObj * obj,
char *ibuf _U_,
size_t ibuflen _U_,
char * rbuf,
size_t * rbuflen )

◆ afp_getvolparams()

int afp_getvolparams ( AFPObj * obj,
char * ibuf,
size_t ibuflen _U_,
char * rbuf,
size_t * rbuflen )

◆ afp_openvol()

int afp_openvol ( AFPObj * obj,
char * ibuf,
size_t ibuflen _U_,
char * rbuf,
size_t * rbuflen )

◆ afp_setvolparams()

int afp_setvolparams ( AFPObj *obj _U_,
char * ibuf,
size_t ibuflen _U_,
char *rbuf _U_,
size_t * rbuflen )

◆ afprun()

int afprun ( char * cmd,
int * outfd )
extern

◆ close_all_vol()

void close_all_vol ( const AFPObj * obj)

◆ closevol()

void closevol ( const AFPObj * obj,
struct vol * vol )

◆ get_tm_bands()

long long int get_tm_bands ( const char * path)
static

Return number on entries in a directory

Parameters
path(r) path to dir
Returns
number of entries, -1 on error

◆ get_tm_bandsize()

long long int get_tm_bandsize ( const char * path)
static

Read band-size info from Info.plist XML file of an TM sparsebundle

Parameters
path(r) path to Info.plist file
Returns
band-size in bytes, -1 on error

◆ get_tm_used()

int get_tm_used ( struct vol *restrict vol)
static

Calculate used size of a TimeMachine volume

This assumes that the volume is used only for TimeMachine.

1) readdir(path of volume) 2) for every element that matches regex "\‍(.*\‍)\.sparsebundle$" : 3) parse "\1.sparsebundle/Info.plist" and read the band-size XML key integer value 4) readdir "\1.sparsebundle/bands/" counting files 5) calculate used size as: (file_count - 1) * band-size

The result of the calculation is returned in "volume->v_tm_used". "volume->v_appended" gets reset to 0. "volume->v_tm_cachetime" is updated with the current time from time(NULL).

"volume->v_tm_used" is cached for TM_USED_CACHETIME seconds and updated by "volume->v_appended". The latter is increased by X every time the client appends X bytes to a file (in fork.c).

Parameters
vol(rw) volume to calculate
Returns
0 on success, -1 on error

◆ getvolparams()

int getvolparams ( const AFPObj * obj,
uint16_t bitmap,
struct vol * vol,
struct stat * st,
char * buf,
size_t * buflen )
static

◆ getvolspace()

int getvolspace ( const AFPObj * obj,
struct vol * vol,
uint32_t * bfree,
uint32_t * btotal,
VolSpace * xbfree,
VolSpace * xbtotal,
uint32_t * bsize )
static

◆ pollvoltime()

int pollvoltime ( AFPObj * obj)

◆ server_ipc_volumes()

void server_ipc_volumes ( AFPObj * obj)
static

◆ setvoltime()

void setvoltime ( AFPObj * obj,
struct vol * vol )

◆ stat_vol()

int stat_vol ( const AFPObj * obj,
uint16_t bitmap,
struct vol * vol,
char * rbuf,
size_t * rbuflen )
static

◆ vol_setdate()

void vol_setdate ( uint16_t id,
struct adouble * adp,
time_t date )
static

◆ volume_codepage()

int volume_codepage ( AFPObj * obj,
struct vol * volume )
static

◆ volume_openDB()

int volume_openDB ( const AFPObj *obj _U_,
struct vol * volume )
static