netatalk  4.4.0
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/ldapconfig.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)
 run a command
static long long int get_tm_bandsize (const char *path)
 Read band-size info from Info.plist XML file of an TM sparsebundle.
static long long int get_tm_bands (const char *path)
 Return number on entries in a directory.
static int get_tm_used (struct vol *vol)
 Calculate used size of a TimeMachine volume.
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)
 set volume creation 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, size_t ibuflen, char *rbuf, size_t *rbuflen)
static int volume_codepage (AFPObj *obj, struct vol *volume)
static int volume_openDB (const AFPObj *obj, struct vol *volume)
static void server_ipc_volumes (AFPObj *obj)
int afp_openvol (AFPObj *obj, char *ibuf, size_t ibuflen, 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, char *rbuf, size_t *rbuflen)
int pollvoltime (AFPObj *obj)
 poll if a volume is changed by other processes.
void setvoltime (AFPObj *obj, struct vol *vol)
int afp_getvolparams (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)
int afp_setvolparams (AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_t *rbuflen)

Macro Definition Documentation

◆ TM_USED_CACHETIME

#define TM_USED_CACHETIME   60

Time Machine cache for 60 seconds

◆ VOLPASSLEN

#define VOLPASSLEN   8

Function Documentation

◆ afp_closevol()

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

◆ afp_getsrvrparms()

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

◆ afp_getvolparams()

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

◆ afp_openvol()

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

◆ afp_setvolparams()

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

◆ afprun()

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

run a command

Note
being careful about uid/gid handling and putting the output in outfd (or discard it if outfd is NULL).

◆ 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
[in]pathpath 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
[in]pathpath to Info.plist file
Returns
band-size in bytes, -1 on error

◆ get_tm_used()

int get_tm_used ( struct vol * 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)

poll if a volume is changed by other processes.

Parameters
objAFP connection object
Returns
0 no attention msg sent, 1 attention msg sent, -1 error (socket closed)
Note
if attention return -1 no packet has been sent because the buffer is full, we don't care either there's no reader or there's a lot of traffic and another pollvoltime will follow

◆ server_ipc_volumes()

void server_ipc_volumes ( AFPObj * obj)
static

Send list of open volumes to afpd master via IPC

◆ 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

set volume creation date


Note
avoid duplicate, well at least it tries

◆ volume_codepage()

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

◆ volume_openDB()

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