synctree.c File Reference

#include <sys/types.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/stat.h>
#include <utime.h>
#include <string.h>
#include <signal.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/wait.h>

Include dependency graph for synctree.c:

Go to the source code of this file.

Data Structures

struct  mode
struct  entry

Defines

#define nil   0
#define LITTLE_ENDIAN   0
#define USE_SHADOWING   0
#define PATH_MAX   1024
#define S_ISLNK(mode)   (0)
#define lstat   stat
#define symlink(path1, path2)   (errno= ENOSYS, -1)
#define readlink(path, buf, len)   (errno= ENOSYS, -1)
#define NUMBYTES   4
#define CHUNK   4096
#define BUCKSIZE   (1+NUMBYTES+CHUNK)
#define DPRINTF(format, arg)
#define transparent   0
#define isvisible(name)   ((void) 0)
#define arraysize(a)   (sizeof(a) / sizeof((a)[0]))
#define arraylimit(a)   ((a) + arraysize(a))
#define cancellink()   ((void) islink())
#define wwrite(buf, n)   (memcpy(buckp, (buf), (n)), buckp+= (n), buckn+= (n))
#define P_EXIT   1
#define P_SHADOW   2

Enumerations

enum  orders {
  ENTER = 128, ADVANCE, CAT, MORE,
  CANCEL, DIE, DIE_BAD, POSITIVE,
  NEGATIVE, PASS_YES, PASS_NO
}
enum  answers {
  PATH = 128, LINK, DATA, NODATA,
  DONE, SYMLINK, YES, NO
}
enum  action { ADD, COMPARE, DELETE }

Functions

static void because ()
static void perr (char *label)
static void perrx (char *label)
static void isbackup (int slave)
static char * addpath (char *p, char *n)
static void setpath (struct entry *e)
static void sort (struct entry **ae)
static void enter ()
static char * link_islink (struct stat *stp, const char *file)
static char * islink ()
static void setstat (ino_t ino, struct stat *stp)
static int getstat (char *name, struct stat *stp)
static int advance ()
static enum orders request ()
static void report ()
static void inform (enum answers a)
static void sendnum (long n)
static void send (char *buf, int n)
static void sendstat (struct stat *stp)
static int ask ()
static void slave ()
static int execute (char **argv)
static int removedir (char *dir)
static void order (enum orders o)
static void rread (char *buf, int n)
static enum answers answer ()
static long recnum ()
static int receive (char *buf, int max)
static void recstat (struct stat *stp)
static int key ()
static int ask (int def)
static void setmodes (int silent)
static void makeold ()
static void bail_out (int sig)
static int makenode (char *name, int mode, dev_t addr, off_t size)
static void add (int update)
static int delete (int update)
static int different ()
static void compare ()
 if (if S done)
 return (c=strcmp(Sp, p))
static void master ()
static void mediator ()
static void startprocess (void(*proc)(), char *machine, char *path, int p_flags)
void splitcolon (char *path, char **amach, char **adir)
static void Usage ()
 main (int argc, char **argv)

Variables

static int install = 0
static int interact = 0
static int force = 0
static int backup = 0
static char SYNCNAME [] = "synctree"
static char SLAVENAME [] = "==SLAVE=="
static char MASTERNAME [] = "==MASTER=="
static char BACKUP [] = ".backup"
static int filemodes
static int chan [2] = { 0, 1 }
static char bucket [BUCKSIZE]
static char * buckp = bucket
static int buckn = 0
static char * arg0
static int ex = 0
static char path [PATH_MAX+1]
static char lnkpth [PATH_MAX+1]
static char * linkpath
static struct stat st
static char Spath [PATH_MAX+1]
static char Slnkpth [PATH_MAX+1]
static char * Slinkpath = nil
static struct stat Sst
static struct entryE = nil
static int busy = 0
static int done = 0
static int Sdone = 0
static enum action c
char * Sp
char * p
if Sp return ADD
if p return DELETE


Define Documentation

#define arraylimit a   )     ((a) + arraysize(a))
 

Definition at line 299 of file synctree.c.

#define arraysize a   )     (sizeof(a) / sizeof((a)[0]))
 

Definition at line 298 of file synctree.c.

#define BUCKSIZE   (1+NUMBYTES+CHUNK)
 

Definition at line 81 of file synctree.c.

Referenced by rread().

 
#define cancellink  )     ((void) islink())
 

Definition at line 409 of file synctree.c.

Referenced by delete(), and slave().

#define CHUNK   4096
 

Definition at line 64 of file synctree.c.

#define DPRINTF format,
arg   ) 
 

Definition at line 124 of file synctree.c.

Referenced by answer(), inform(), order(), and report().

#define isvisible name   )     ((void) 0)
 

Definition at line 170 of file synctree.c.

Referenced by startprocess().

#define LITTLE_ENDIAN   0
 

Definition at line 47 of file synctree.c.

#define lstat   stat
 

Definition at line 58 of file synctree.c.

#define nil   0
 

Definition at line 23 of file synctree.c.

#define NUMBYTES   4
 

Definition at line 63 of file synctree.c.

Referenced by recnum(), and sendnum().

#define P_EXIT   1
 

Definition at line 1284 of file synctree.c.

Referenced by main(), and startprocess().

#define P_SHADOW   2
 

Definition at line 1285 of file synctree.c.

Referenced by main(), and startprocess().

#define PATH_MAX   1024
 

Definition at line 52 of file synctree.c.

#define readlink path,
buf,
len   )     (errno= ENOSYS, -1)
 

Definition at line 60 of file synctree.c.

#define S_ISLNK mode   )     (0)
 

Definition at line 57 of file synctree.c.

#define symlink path1,
path2   )     (errno= ENOSYS, -1)
 

Definition at line 59 of file synctree.c.

#define transparent   0
 

Definition at line 169 of file synctree.c.

Referenced by advance().

#define USE_SHADOWING   0
 

Definition at line 48 of file synctree.c.

Referenced by startprocess().

#define wwrite buf,
n   )     (memcpy(buckp, (buf), (n)), buckp+= (n), buckn+= (n))
 

Definition at line 589 of file synctree.c.

Referenced by send(), and sendnum().


Enumeration Type Documentation

enum action
 

Enumerator:
ADD 
COMPARE 
DELETE 

Definition at line 1171 of file synctree.c.

enum answers
 

Enumerator:
PATH 
LINK 
DATA 
NODATA 
DONE 
SYMLINK 
YES 
NO 

Definition at line 107 of file synctree.c.

enum orders
 

Enumerator:
ENTER 
ADVANCE 
CAT 
MORE 
CANCEL 
DIE 
DIE_BAD 
POSITIVE 
NEGATIVE 
PASS_YES 
PASS_NO 

Definition at line 86 of file synctree.c.


Function Documentation

static void add int  update  )  [static]
 

Definition at line 968 of file synctree.c.

References answer, arg0, ask(), backup, because(), CANCEL, CAT, CHUNK, close, creat, DATA, ENTER, force, fprintf(), interact, link, makenode(), makeold(), mkdir, n, nil, order, perr(), printf, receive, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_ISLNK, setmodes(), Slinkpath, Slnkpth, Spath, Sst, st, stat::st_mode, stat::st_mtime, stat::st_rdev, stat::st_size, stderr, symlink, and write.

static char* addpath char *  p,
char *  n
[static]
 

Definition at line 191 of file synctree.c.

References arg0, exit(), fprintf(), PATH_MAX, stderr, and strlen().

static int advance  )  [static]
 

Definition at line 476 of file synctree.c.

References E, malloc(), nil, strcpy(), and transparent.

static enum answers answer  )  [static]
 

Definition at line 775 of file synctree.c.

References a, c, DPRINTF, PATH, and rread().

static int ask int  def  )  [static]
 

Definition at line 851 of file synctree.c.

References answer, c, chan, fflush(), key, NEGATIVE, order, POSITIVE, printf, stdout, y, and YES.

static int ask  )  [static]
 

static void bail_out int  sig  )  [static]
 

Definition at line 940 of file synctree.c.

References arg0, DIE_BAD, exit(), fprintf(), makeold(), order, SIG_IGN, signal(), Spath, and stderr.

Referenced by master(), and select_image().

static void because  )  [static]
 

Definition at line 138 of file synctree.c.

References errno, ex, fprintf(), stderr, and strerror().

Referenced by add(), delete(), makeold(), setmodes(), and slave().

static void compare  )  [static]
 

Definition at line 1149 of file synctree.c.

References add(), different(), enter(), ENTER, force, install, order, path, printf, S_ISDIR, setmodes(), Sst, st, stat::st_mode, and stat::st_mtime.

static int delete int  update  )  [static]
 

Definition at line 1085 of file synctree.c.

References ask(), because(), cancellink, ex, force, fprintf(), install, interact, path, printf, removedir(), S_ISDIR, st, stat::st_mode, stderr, unlink, and update().

static int different  )  [static]
 

Definition at line 1118 of file synctree.c.

References install, linkpath, lnkpth, nil, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, Slinkpath, Slnkpth, Sst, st, stat::st_mode, stat::st_mtime, stat::st_rdev, stat::st_size, and strcmp.

Referenced by compare().

static void enter  )  [static]
 

Definition at line 267 of file synctree.c.

References arg0, closedir, entry::con, d, e, E, fprintf(), malloc(), entry::next, nil, opendir, path, readdir, sort(), stderr, strcpy(), and strlen().

Referenced by compare(), incr_link(), and slave().

static int execute char **  argv  )  [static]
 

Definition at line 705 of file synctree.c.

References execvp, fork, perr(), perrx(), pid, r, status, and wait.

static int getstat char *  name,
struct stat stp
[static]
 

Definition at line 441 of file synctree.c.

References backup, BACKUP, errno, filemodes, lseek, lstat, md, read, S_IFREG, S_ISBLK, setstat(), stat::st_gid, stat::st_ino, stat::st_mode, stat::st_mtime, stat::st_rdev, stat::st_size, stat::st_uid, and strcmp.

Referenced by modtime(), and setmodes().

if if S  done  ) 
 

Definition at line 1179 of file synctree.c.

static void inform enum answers  a  )  [static]
 

Definition at line 580 of file synctree.c.

References buckn, buckp, DPRINTF, and PATH.

Referenced by slave().

static void isbackup int  slave  )  [static]
 

Definition at line 173 of file synctree.c.

References backup, BACKUP, ENOENT, errno, filemodes, O_RDONLY, O_RDWR, open, and perrx().

Referenced by startprocess().

static char* islink  )  [static]
 

Definition at line 411 of file synctree.c.

References ENOENT, errno, link_islink(), nil, path, perrx(), and st.

static int key  )  [static]
 

Definition at line 834 of file synctree.c.

References c, EOF, feof, getchar, isatty, putchar, and stdin.

static char* link_islink struct stat stp,
const char *  file
[static]
 

Definition at line 301 of file synctree.c.

References arraylimit, close, dev, free, link::ino, lp, link::next, nil, off, and PATH_MAX.

main int  argc,
char **  argv
 

Definition at line 1367 of file synctree.c.

References alarm, arg0, chan, close, dup2, ex, exit(), force, fork, install, interact, master(), MASTERNAME, mediator(), nil, P_EXIT, P_SHADOW, perrx(), pipe, r, slave(), SLAVENAME, splitcolon(), startprocess(), strcmp, strrchr(), Usage(), and wait.

static int makenode char *  name,
int  mode,
dev_t  addr,
off_t  size
[static]
 

Definition at line 955 of file synctree.c.

References backup, close, creat, mknod, and r.

Referenced by add().

static void makeold  )  [static]
 

Definition at line 923 of file synctree.c.

References arg0, because(), ENOENT, errno, fprintf(), Spath, stderr, and utime.

Referenced by add(), and bail_out().

static void master  )  [static]
 

Definition at line 1191 of file synctree.c.

References a, add(), ADD, advance(), ADVANCE, answer, arg0, backup, bail_out(), compare, COMPARE, DELETE, DIE, DIE_BAD, DONE, ex, exit(), fflush(), fprintf(), LINK, nil, order, PATH, receive, recstat(), Sdone, SIG_IGN, SIGHUP, SIGINT, signal(), SIGPIPE, SIGTERM, Slinkpath, Slnkpth, Spath, Sst, stderr, stdout, SYMLINK, and umask.

Referenced by exec_bootstrap(), initialize(), main(), and startprocess().

static void mediator  )  [static]
 

Definition at line 1257 of file synctree.c.

References ask(), DIE, DIE_BAD, ex, NEGATIVE, order, PASS_NO, PASS_YES, POSITIVE, and request.

Referenced by main().

static void order enum orders  o  )  [static]
 

Definition at line 738 of file synctree.c.

References c, chan, DPRINTF, ENTER, perrx(), and write.

static void perr char *  label  )  [static]
 

Definition at line 144 of file synctree.c.

References arg0, errno, ex, fprintf(), stderr, and strerror().

Referenced by add(), execute(), perrx(), and slave().

static void perrx char *  label  )  [static]
 

Definition at line 150 of file synctree.c.

References exit(), and perr().

Referenced by execute(), isbackup(), islink(), main(), order(), report(), request(), rread(), setstat(), and startprocess().

static int receive char *  buf,
int  max
[static]
 

Definition at line 810 of file synctree.c.

References arg0, exit(), fprintf(), n, recnum(), rread(), and stderr.

static long recnum  )  [static]
 

Definition at line 789 of file synctree.c.

References long(), n, NUMBYTES, and rread().

Referenced by receive(), and recstat().

static void recstat struct stat stp  )  [static]
 

Definition at line 824 of file synctree.c.

References recnum().

Referenced by master().

static int removedir char *  dir  )  [static]
 

Definition at line 727 of file synctree.c.

References argv, execute(), nil, and printf.

Referenced by delete().

static void report  )  [static]
 

Definition at line 559 of file synctree.c.

References buckn, buckp, chan, DPRINTF, perrx(), r, and write.

static enum orders request  )  [static]
 

Definition at line 529 of file synctree.c.

References arg0, bp, chan, exit(), fprintf(), perrx(), read, and stderr.

return c  = strcmp(Spp)  ) 
 

Referenced by _get_entry(), dcheck(), getmp(), lexi(), lookup(), meta(), sole_reduction(), and unzReadCurrentFile().

static void rread char *  buf,
int  n
[static]
 

Definition at line 748 of file synctree.c.

References arg0, buckn, buckp, BUCKSIZE, chan, exit(), fprintf(), memcpy(), perrx(), r, read, and stderr.

Referenced by answer(), receive(), and recnum().

static void send char *  buf,
int  n
[static]
 

Definition at line 607 of file synctree.c.

References sendnum(), and wwrite.

static void sendnum long  n  )  [static]
 

Definition at line 591 of file synctree.c.

References NUMBYTES, and wwrite.

Referenced by send(), and sendstat().

static void sendstat struct stat stp  )  [static]
 

Definition at line 614 of file synctree.c.

References sendnum().

Referenced by slave().

static void setmodes int  silent  )  [static]
 

Definition at line 877 of file synctree.c.

References utimbuf::actime, arg0, backup, because(), change(), chmod, chown, errno, fprintf(), geteuid, getstat(), utimbuf::modtime, printf, S_ISLNK, S_ISREG, setstat(), Spath, Sst, st, stat::st_gid, stat::st_ino, stat::st_mode, stat::st_mtime, stat::st_uid, stderr, time, and utime.

Referenced by add(), and compare().

static void setpath struct entry e  )  [static]
 

Definition at line 218 of file synctree.c.

References addpath(), and nil.

static void setstat ino_t  ino,
struct stat stp
[static]
 

Definition at line 425 of file synctree.c.

References BACKUP, filemodes, lseek, md, perrx(), stat::st_gid, stat::st_mode, stat::st_rdev, stat::st_size, stat::st_uid, and write.

static void slave  )  [static]
 

Definition at line 626 of file synctree.c.

References advance(), ADVANCE, arg0, ask(), because(), CANCEL, cancellink, CAT, CHUNK, close, DATA, DIE, die, DIE_BAD, DONE, done, enter(), ENTER, ex, exit(), fprintf(), inform(), LINK, linkpath, lnkpth, n, NEGATIVE, nil, NO, NODATA, O_RDONLY, open, PASS_NO, PASS_YES, path, PATH, perr(), POSITIVE, read, report(), request, run(), S_ISLNK, send, sendstat(), st, stat::st_mode, stderr, strlen(), SYMLINK, and YES.

Referenced by main(), and startprocess().

static void sort struct entry **  ae  )  [static]
 

Definition at line 231 of file synctree.c.

References e1, e2, if(), entry::next, nil, sort(), and strcmp.

void splitcolon char *  path,
char **  amach,
char **  adir
 

Definition at line 1339 of file synctree.c.

Referenced by main().

static void startprocess void (*)()  proc,
char *  machine,
char *  path,
int  p_flags
[static]
 

Definition at line 1287 of file synctree.c.

References argv, chdir, ENOENT, errno, ex, execvp, exit(), flags, force, fprintf(), install, interact, isbackup(), isvisible, m, master(), MASTERNAME, mkdir, nil, P_EXIT, P_SHADOW, perrx(), printf, slave(), SLAVENAME, stderr, strchr, SYNCNAME, and USE_SHADOWING.

Referenced by main().

static void Usage  )  [static]
 

Definition at line 1359 of file synctree.c.

References arg0, exit(), fprintf(), and stderr.


Variable Documentation

if Sp return ADD
 

Definition at line 1186 of file synctree.c.

char* arg0 [static]
 

Definition at line 135 of file synctree.c.

char BACKUP[] = ".backup" [static]
 

Definition at line 76 of file synctree.c.

Referenced by getstat(), isbackup(), and setstat().

int backup = 0 [static]
 

Definition at line 69 of file synctree.c.

Referenced by add(), getstat(), isbackup(), makenode(), master(), and setmodes().

char bucket[BUCKSIZE] [static]
 

Definition at line 82 of file synctree.c.

int buckn = 0 [static]
 

Definition at line 84 of file synctree.c.

Referenced by inform(), report(), and rread().

char* buckp = bucket [static]
 

Definition at line 83 of file synctree.c.

Referenced by inform(), report(), and rread().

int busy = 0 [static]
 

Definition at line 938 of file synctree.c.

enum action c [static]
 

int chan[2] = { 0, 1 } [static]
 

Definition at line 79 of file synctree.c.

Referenced by ask(), main(), order(), report(), request(), and rread().

if p return DELETE
 

Definition at line 1187 of file synctree.c.

int done = 0 [static]
 

Definition at line 1169 of file synctree.c.

struct entry* E = nil [static]
 

Definition at line 216 of file synctree.c.

Referenced by advance(), and enter().

int ex = 0 [static]
 

Definition at line 136 of file synctree.c.

int filemodes [static]
 

Definition at line 77 of file synctree.c.

Referenced by getstat(), isbackup(), and setstat().

int force = 0 [static]
 

Definition at line 68 of file synctree.c.

int install = 0 [static]
 

Definition at line 66 of file synctree.c.

Referenced by compare(), delete(), different(), init(), initarg(), main(), setvar(), and startprocess().

int interact = 0 [static]
 

Definition at line 67 of file synctree.c.

Referenced by add(), delete(), main(), parsecmd(), and startprocess().

char* linkpath [static]
 

Definition at line 184 of file synctree.c.

Referenced by different(), and slave().

char lnkpth[PATH_MAX+1] [static]
 

Definition at line 183 of file synctree.c.

Referenced by different(), and slave().

char MASTERNAME[] = "==MASTER==" [static]
 

Definition at line 73 of file synctree.c.

Referenced by main(), and startprocess().

char * p
 

Definition at line 1177 of file synctree.c.

char path[PATH_MAX+1] [static]
 

Definition at line 182 of file synctree.c.

int Sdone = 0 [static]
 

Definition at line 1169 of file synctree.c.

Referenced by master().

char SLAVENAME[] = "==SLAVE==" [static]
 

Definition at line 72 of file synctree.c.

Referenced by main(), and startprocess().

char* Slinkpath = nil [static]
 

Definition at line 188 of file synctree.c.

Referenced by add(), different(), and master().

char Slnkpth[PATH_MAX+1] [static]
 

Definition at line 187 of file synctree.c.

Referenced by add(), different(), and master().

char* Sp
 

Definition at line 1177 of file synctree.c.

char Spath[PATH_MAX+1] [static]
 

Definition at line 186 of file synctree.c.

Referenced by add(), bail_out(), makeold(), master(), and setmodes().

struct stat Sst [static]
 

Definition at line 189 of file synctree.c.

Referenced by add(), compare(), different(), master(), and setmodes().

struct stat st [static]
 

Definition at line 185 of file synctree.c.

char SYNCNAME[] = "synctree" [static]
 

Definition at line 71 of file synctree.c.

Referenced by startprocess().


Generated on Fri Apr 14 23:07:33 2006 for minix by  doxygen 1.4.6