remsync.c File Reference

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <limits.h>
#include <time.h>
#include <utime.h>

Include dependency graph for remsync.c:

Go to the source code of this file.

Data Structures

struct  pathname
struct  namelist
struct  entry

Defines

#define nil   0
#define arraysize(a)   (sizeof(a) / sizeof((a)[0]))
#define arraylimit(a)   ((a) + arraysize(a))
#define major(dev)   ((int) ((dev) >> 8))
#define minor(dev)   ((int) ((dev) & 0xFF))
#define S_ISLNK(mode)   (0)
#define lstat   stat
#define symlink(path1, path2)   (errno= ENOSYS, -1)
#define readlink(path, buf, len)   (errno= ENOSYS, -1)
#define NO_DEVICE   (-1)
#define BASE_INDENT   2
#define KEEP_STATE   0
#define KEEP_TRAVERSE   1
#define path_name(pp)   ((const char *) (pp)->path)
#define path_length(pp)   ((pp)->idx)
#define path_drop(pp)   free((void *) (pp)->path)
#define A_MODE1   0x01
#define A_MODE   0x02
#define A_OWNER   0x04
#define A_SIZETIME   0x08
#define A_DEV   0x10
#define A_LINK   0x20

Typedefs

typedef pathname pathname_t
typedef namelist namelist_t
typedef enum filetype filetype_t
typedef entry entry_t

Enumerations

enum  filetype {
  F_DIR, F_FILE, F_BLK, F_CHR,
  F_PIPE, F_LINK
}
enum  {
  DELETE, REPLACE, COPY, SIMILAR,
  EQUAL, ADD
}

Functions

void report (const char *label)
void fatal (const char *label)
void * allocate (void *mem, size_t size)
void deallocate (void *mem)
void forget (void *mem)
char * copystr (const char *s)
void path_init (pathname_t *pp)
void path_add (pathname_t *pp, const char *name)
void path_trunc (pathname_t *pp, size_t didx)
char * rdlink (const char *link, off_t size)
void sort (namelist_t **anl)
namelist_tcollect (const char *dir)
char * pop_name (namelist_t **names)
void linked (entry_t *entry, struct stat *stp)
entry_ttraverse (void)
void checkstate (void)
void indent (int depth)
int print_name (FILE *fp, const char *name)
void mkstatefile (void)
char * read1line (FILE *fp)
void getword (char **pline, char **parg, size_t *plen)
void splitline (char *line, char ***pargv, size_t *pargc)
int getattributes (entry_t *entry, int argc, char **argv)
void state_syntax (off_t line)
entry_treadstate (void)
void checkdiff (void)
 if (local==nil)
 if (remote->type!=local->type)
 switch (remote->type)
void delete (entry_t *old)
void change_modes (entry_t *old, entry_t *new)
int cat (int f, off_t size)
void add (entry_t *old, entry_t *new)
void mkdifferences (void)
void apply_remove (pathname_t *pp)
void apply_mkold (const char *file, const char *err)
void apply_chmod (const char *file, mode_t mode, uid_t uid, gid_t gid, int talk)
void apply_add (pathname_t *pp, entry_t *entry)
void apply_link (const char *file, pathname_t *pp)
void diff_syntax (const char *line)
void apply_differences (void)
void usage (void)
int main (int argc, char **argv)

Variables

int sflag
int dflag
int uflag
int xflag
int Dflag
int vflag
dev_t xdev = NO_DEVICE
int excode = 0
int keep
char * tree
FILEstatefp
char * state_file
FILEdifffp
char * diff_file
struct {
   char *   f_name
   FILE *   f_fp
   int   f_type
   char *   word
   int   type
   int   val
   char *   name
   CMD   code
   void(*   fn )()
   ARGT   argt
   char *   name
   char *   nm
   char   type
   char   flags
   char *   value
   const char *   name
   signed char   fat_bits
   int   tracks
   unsigned short   heads
   unsigned short   sectors
   device_t *   dev
   int   nr_partitions
   int   free_regions
   int   used_regions
   int   sectors
   int   nr_regions
   int   biosdrive
   region_t   regions [NR_REGIONS]
   int   this_month
   int   feb
   int   sept
   int   days_in_month
   int   dow_first
   int   o_file
   int   o_field
   WINDOW *   win
   char   erase
   char   kill
   char   werase
   unsigned   baudr
   int   speedcode
   u16_t   vendor
   u16_t   device
remote
struct {
   char *   f_name
   FILE *   f_fp
   int   f_type
   char *   word
   int   type
   int   val
   char *   name
   CMD   code
   void(*   fn )()
   ARGT   argt
   char *   name
   char *   nm
   char   type
   char   flags
   char *   value
   const char *   name
   signed char   fat_bits
   int   tracks
   unsigned short   heads
   unsigned short   sectors
   device_t *   dev
   int   nr_partitions
   int   free_regions
   int   used_regions
   int   sectors
   int   nr_regions
   int   biosdrive
   region_t   regions [NR_REGIONS]
   int   this_month
   int   feb
   int   sept
   int   days_in_month
   int   dow_first
   int   o_file
   int   o_field
   WINDOW *   win
   char   erase
   char   kill
   char   werase
   unsigned   baudr
   int   speedcode
   u16_t   vendor
   u16_t   device
cmp
return EQUAL


Define Documentation

#define A_DEV   0x10
 

Referenced by getattributes().

#define A_LINK   0x20
 

Referenced by getattributes().

#define A_MODE   0x02
 

Referenced by getattributes().

#define A_MODE1   0x01
 

Referenced by getattributes().

#define A_OWNER   0x04
 

Referenced by getattributes().

#define A_SIZETIME   0x08
 

Referenced by getattributes().

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

Definition at line 20 of file remsync.c.

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

Definition at line 19 of file remsync.c.

#define BASE_INDENT   2
 

Definition at line 47 of file remsync.c.

Referenced by indent().

#define KEEP_STATE   0
 

Definition at line 80 of file remsync.c.

Referenced by readstate().

#define KEEP_TRAVERSE   1
 

Definition at line 81 of file remsync.c.

Referenced by traverse().

#define lstat   stat
 

Definition at line 30 of file remsync.c.

#define major dev   )     ((int) ((dev) >> 8))
 

Definition at line 23 of file remsync.c.

#define minor dev   )     ((int) ((dev) & 0xFF))
 

Definition at line 24 of file remsync.c.

#define nil   0
 

Definition at line 4 of file remsync.c.

#define NO_DEVICE   (-1)
 

Definition at line 42 of file remsync.c.

Referenced by traverse().

#define path_drop pp   )     free((void *) (pp)->path)
 

Definition at line 175 of file remsync.c.

#define path_length pp   )     ((pp)->idx)
 

Definition at line 174 of file remsync.c.

#define path_name pp   )     ((const char *) (pp)->path)
 

Definition at line 173 of file remsync.c.

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

Definition at line 32 of file remsync.c.

#define S_ISLNK mode   )     (0)
 

Definition at line 29 of file remsync.c.

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

Definition at line 31 of file remsync.c.


Typedef Documentation

typedef struct entry entry_t
 

typedef enum filetype filetype_t
 

typedef struct namelist namelist_t
 

typedef struct pathname pathname_t
 


Enumeration Type Documentation

anonymous enum
 

Enumerator:
DELETE 
REPLACE 
COPY 
SIMILAR 
EQUAL 
ADD 

Definition at line 877 of file remsync.c.

enum filetype
 

Enumerator:
F_DIR 
F_FILE 
F_BLK 
F_CHR 
F_PIPE 
F_LINK 

Definition at line 276 of file remsync.c.


Function Documentation

void add entry_t old,
entry_t new
 

Definition at line 1008 of file remsync.c.

References cat(), checkdiff(), close, difffp, EINVAL, EOF, err, errno, F_BLK, F_CHR, F_DIR, F_FILE, F_LINK, F_PIPE, file, fprintf(), fputc(), entry::gid, entry::ignore, entry::link, entry::linked, entry::mode, entry::mtime, nil, O_RDONLY, open, entry::path, path_add(), path_drop, path_init(), path_name, print_name(), entry::rdev, report(), entry::size, stderr, strerror(), tree, entry::type, entry::uid, and vflag.

void* allocate void *  mem,
size_t  size
 

Definition at line 61 of file remsync.c.

References assert, errno, exit(), fatal(), fprintf(), heap_chunks, malloc(), nil, realloc(), stderr, and strerror().

void apply_add pathname_t pp,
entry_t entry
 

Definition at line 1246 of file remsync.c.

References utimbuf::actime, apply_chmod(), apply_mkold(), apply_remove(), arraylimit, c, chmod, close, diff_file, difffp, dirty, entry, EOF, exit(), F_BLK, F_CHR, F_DIR, F_FILE, F_LINK, F_PIPE, feof, ferror, fprintf(), getc, entry::gid, entry::ignore, int(), entry::link, lstat, major, minor, mkdir, mknod, entry::mode, utimbuf::modtime, entry::mtime, nil, O_CREAT, O_TRUNC, O_WRONLY, open, p, path_name, entry::rdev, report(), S_IFBLK, S_IFCHR, S_IFIFO, S_ISREG, entry::size, size, st, stat::st_mode, stat::st_mtime, stderr, symlink, time, entry::type, entry::uid, unlink, utime, vflag, and write.

Referenced by apply_differences().

void apply_chmod const char *  file,
mode_t  mode,
uid_t  uid,
gid_t  gid,
int  talk
 

Definition at line 1215 of file remsync.c.

References chmod, chown, EPERM, errno, file, fprintf(), lstat, report(), st, stat::st_gid, stat::st_mode, stat::st_uid, stderr, and vflag.

Referenced by apply_add(), and apply_differences().

void apply_differences void   ) 
 

Definition at line 1402 of file remsync.c.

References apply_add(), apply_chmod(), apply_link(), apply_mkold(), apply_remove(), argc, argv, checkdiff(), diff_syntax(), difffp, entry, feof, getattributes(), entry::ignore, link, nil, path, path_add(), path_init(), path_length, path_name, path_trunc(), read1line(), splitline(), strcmp, strtoul(), and tree.

void apply_link const char *  file,
pathname_t pp
 

Definition at line 1371 of file remsync.c.

References apply_remove(), errno, excode, fprintf(), link, lstat, path_name, report(), stat::st_dev, stat::st_ino, stderr, strerror(), and vflag.

Referenced by apply_differences().

void apply_mkold const char *  file,
const char *  err
 

Definition at line 1200 of file remsync.c.

References utimbuf::actime, fprintf(), utimbuf::modtime, nil, report(), stderr, and utime.

Referenced by apply_add(), and apply_differences().

void apply_remove pathname_t pp  ) 
 

Definition at line 1159 of file remsync.c.

References collect(), ENOENT, entries, errno, fprintf(), lstat, nil, path_add(), path_length, path_name, path_trunc(), pop_name(), report(), rmdir, S_ISDIR, st, stat::st_mode, stderr, unlink, and vflag.

Referenced by apply_add(), apply_differences(), and apply_link().

int cat int  f,
off_t  size
 

Definition at line 972 of file remsync.c.

References c, checkdiff(), Dflag, difffp, EINVAL, EOF, err, errno, int(), n, p, putc, and read.

Referenced by add(), and categorize().

void change_modes entry_t old,
entry_t new
 

Definition at line 952 of file remsync.c.

References checkdiff(), fprintf(), print_name(), and vflag.

Referenced by mkdifferences().

void checkdiff void   ) 
 

Definition at line 872 of file remsync.c.

References diff_file, difffp, fatal(), and ferror.

Referenced by add(), apply_differences(), cat(), change_modes(), and mkdifferences().

void checkstate void   ) 
 

Definition at line 496 of file remsync.c.

References fatal(), ferror, state_file, and statefp.

Referenced by indent(), mkstatefile(), and readstate().

namelist_t* collect const char *  dir  ) 
 

Definition at line 233 of file remsync.c.

References allocate(), closedir, copystr(), entry, errno, names, name::next, nil, opendir, readdir, and sort().

char* copystr const char *  s  ) 
 

Definition at line 94 of file remsync.c.

References allocate(), c, nil, strcpy(), and strlen().

void deallocate void *  mem  ) 
 

Definition at line 71 of file remsync.c.

References alloc_count, free, and nil.

void delete entry_t old  ) 
 

Definition at line 939 of file remsync.c.

void diff_syntax const char *  line  ) 
 

Definition at line 1395 of file remsync.c.

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

Referenced by apply_differences().

void fatal const char *  label  ) 
 

Definition at line 55 of file remsync.c.

References exit(), and report().

void forget void *  mem  ) 
 

Definition at line 83 of file remsync.c.

References arraylimit, deallocate, and keep.

Referenced by getattributes(), linked(), and pop_name().

int getattributes entry_t entry,
int  argc,
char **  argv
 

Definition at line 681 of file remsync.c.

References A_DEV, A_LINK, A_MODE, A_MODE1, A_OWNER, A_SIZETIME, allocate(), arraysize, copystr(), deallocate, entry, F_BLK, F_CHR, F_DIR, F_FILE, F_LINK, F_PIPE, forget(), entry::gid, i, entry::lastlink, entry::link, entry::linked, lp, entry::mode, entry::mtime, next, nil, entry::path, path, entry::rdev, entry::size, strcmp, strtoul(), entry::type, and entry::uid.

Referenced by apply_differences(), and readstate().

void getword char **  pline,
char **  parg,
size_t plen
 

Definition at line 623 of file remsync.c.

References allocate(), arg, c, and i.

Referenced by servxcheck().

if remote->type = local->type  ) 
 

Definition at line 903 of file remsync.c.

References local, remote, and strcmp.

if local  = = nil  ) 
 

Definition at line 884 of file remsync.c.

void indent int  depth  ) 
 

Definition at line 501 of file remsync.c.

References BASE_INDENT, checkstate(), EOF, n, putc, and statefp.

void linked entry_t entry,
struct stat stp
 

Definition at line 303 of file remsync.c.

References allocate(), arraysize, copystr(), deallocate, dev, entry, entry::fake_ino, forget(), entry::lastlink, entry::link, entry::linked, lp, next, nil, entry::path, path, S_ISDIR, stat::st_dev, stat::st_ino, stat::st_mode, and stat::st_nlink.

Referenced by copy1(), traverse(), and trylink().

int main int  argc,
char **  argv
 

Definition at line 1478 of file remsync.c.

References i, and p.

void mkdifferences void   ) 
 

Definition at line 1108 of file remsync.c.

References ADD, add(), change_modes(), checkdiff(), compare, COPY, DELETE, difffp, EQUAL, F_FILE, fflush(), fprintf(), local, nil, readstate(), remote, SIMILAR, and traverse().

void mkstatefile void   ) 
 

Definition at line 533 of file remsync.c.

References checkstate(), entry::depth, entry, EOF, F_BLK, F_CHR, F_DIR, F_FILE, F_LINK, F_PIPE, entry::fake_ino, fflush(), fprintf(), fputc(), entry::gid, entry::ignore, indent, entry::lastlink, entry::link, entry::mode, entry::mtime, entry::name, nil, print_name(), entry::rdev, entry::size, statefp, strerror(), traverse(), entry::type, and entry::uid.

void path_add pathname_t pp,
const char *  name
 

Definition at line 114 of file remsync.c.

References allocate(), pathname::idx, pathname::lim, p, pathname::path, slash(), and strlen().

void path_init pathname_t pp  ) 
 

Definition at line 107 of file remsync.c.

References allocate(), pathname::idx, pathname::lim, nil, and pathname::path.

void path_trunc pathname_t pp,
size_t  didx
 

Definition at line 146 of file remsync.c.

References pathname::idx, and pathname::path.

char* pop_name namelist_t **  names  ) 
 

Definition at line 262 of file remsync.c.

References deallocate, forget(), namelist::name, names, and namelist::next.

Referenced by apply_remove(), and traverse().

int print_name FILE fp,
const char *  name
 

Definition at line 516 of file remsync.c.

References c, EOF, ferror, fp, fprintf(), p, and putc.

Referenced by add(), change_modes(), and mkstatefile().

char* rdlink const char *  link,
off_t  size
 

Definition at line 182 of file remsync.c.

References allocate(), n, nil, path, and readlink.

Referenced by traverse().

char* read1line FILE fp  ) 
 

Definition at line 592 of file remsync.c.

References allocate(), c, EOF, exit(), ferror, fp, fprintf(), getc, nil, and stderr.

Referenced by apply_differences(), and readstate().

entry_t* readstate void   ) 
 

Definition at line 797 of file remsync.c.

References allocate(), argc, argv, checkstate(), entry::depth, entry, feof, getattributes(), entry::ignore, indent, keep, KEEP_STATE, lineno, entry::link, entry::name, nil, entry::path, path, path_add(), path_init(), path_length, path_name, path_trunc(), read1line(), splitline(), state_syntax(), statefp, and strcmp.

Referenced by mkdifferences().

void report const char *  label  ) 
 

Definition at line 49 of file remsync.c.

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

void sort namelist_t **  anl  ) 
 

Definition at line 197 of file remsync.c.

References if(), namelist::name, namelist::next, nil, sort(), and strcmp.

void splitline char *  line,
char ***  pargv,
size_t pargc
 

Definition at line 653 of file remsync.c.

References allocate(), argv, and nil.

Referenced by apply_differences(), and readstate().

void state_syntax off_t  line  ) 
 

Definition at line 790 of file remsync.c.

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

Referenced by readstate().

switch remote->  type  ) 
 

Definition at line 911 of file remsync.c.

References COPY, F_BLK, F_CHR, F_DIR, F_FILE, F_LINK, F_PIPE, local, remote, SIMILAR, strcmp, and uflag.

Referenced by Do(), do_sigprocmask(), lexi(), m_move(), reduce(), and step().

entry_t* traverse void   ) 
 

Definition at line 359 of file remsync.c.

References allocate(), collect(), copystr(), entry::depth, EINVAL, ENOENT, entries, entry, errno, EXDEV, F_BLK, F_CHR, F_DIR, F_FILE, F_LINK, F_PIPE, entry::gid, entry::ignore, keep, KEEP_TRAVERSE, entry::link, linked(), lstat, entry::mode, entry::mtime, entry::name, nil, NO_DEVICE, entry::path, path, path_add(), path_init(), path_length, path_name, path_trunc(), pop_name(), entry::rdev, rdlink(), report(), S_ISBLK, S_ISCHR, S_ISDIR, S_ISFIFO, S_ISLNK, S_ISREG, entry::size, st, stat::st_dev, stat::st_gid, stat::st_mode, stat::st_mtime, stat::st_rdev, stat::st_size, stat::st_uid, tree, entry::type, entry::uid, xdev, and xflag.

void usage void   ) 
 

Definition at line 1470 of file remsync.c.

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


Variable Documentation

enum { ... } cmp
 

Referenced by bsearch(), cmd_tag(), cmp_fields(), compare(), Findchar(), Findmacro(), Findnum(), Findstr(), inflate_fast(), main(), nm_sort(), Nreq(), qsort1(), search(), search_mnem(), and selected().

int Dflag
 

Definition at line 39 of file remsync.c.

Referenced by cat(), copy(), extract(), and pax_options().

int dflag
 

Definition at line 36 of file remsync.c.

char* diff_file
 

Definition at line 357 of file remsync.c.

Referenced by apply_add(), checkdiff(), and diff_syntax().

FILE* difffp
 

Definition at line 356 of file remsync.c.

Referenced by add(), apply_add(), apply_differences(), cat(), checkdiff(), and mkdifferences().

return EQUAL
 

Definition at line 936 of file remsync.c.

int excode = 0
 

Definition at line 45 of file remsync.c.

int keep
 

Definition at line 79 of file remsync.c.

Referenced by forget(), mkdirp(), readstate(), and traverse().

enum { ... } * remote
 

Referenced by if(), mkdifferences(), and switch().

int sflag
 

Definition at line 35 of file remsync.c.

char* state_file
 

Definition at line 355 of file remsync.c.

Referenced by checkstate(), and state_syntax().

FILE* statefp
 

Definition at line 354 of file remsync.c.

Referenced by checkstate(), indent(), mkstatefile(), and readstate().

char* tree
 

Definition at line 353 of file remsync.c.

Referenced by add(), apply_differences(), build_tree(), gen_bitlen(), io(), newtp(), pqdownheap(), scan_tree(), send_tree(), and traverse().

int uflag
 

Definition at line 37 of file remsync.c.

int vflag
 

Definition at line 40 of file remsync.c.

dev_t xdev = NO_DEVICE
 

Definition at line 43 of file remsync.c.

int xflag
 

Definition at line 38 of file remsync.c.


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