1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2012 STRATO AG. All rights reserved.
  24  */
  25 
  26 #ifndef _SYS_FITS_IMPL_H
  27 #define _SYS_FITS_IMPL_H
  28 
  29 #include <sys/inttypes.h>
  30 #include <sys/types.h>
  31 #include <sys/cmn_err.h>
  32 #include <sys/spa.h>
  33 #include <sys/arc.h>
  34 #include <sys/dsl_dataset.h>
  35 #include <sys/dnode.h>
  36 #include <sys/sa.h>
  37 
  38 #define FITS_NO_INO     0
  39 
  40 enum pass {
  41         PASS_LINK,
  42         PASS_UNLINK
  43 };
  44 
  45 typedef struct _fits_count_elem {
  46         struct _fits_count_elem *fce_next;
  47         uint64_t fce_ino;
  48         uint64_t fce_count;
  49         uint64_t fce_aux;
  50 } fits_count_elem_t;
  51 
  52 typedef struct _fits_counter {
  53         fits_count_elem_t *fc_head;
  54         const char *fc_name;
  55 } fits_counter_t;
  56 
  57 typedef struct blklevel {
  58         uint64_t        bl_blk;
  59         int             bl_nslots;
  60         blkptr_t        *bl_bp;
  61         arc_buf_t       *bl_buf;
  62 } blklevel_t;
  63 
  64 typedef struct _fits {
  65         enum pass f_pass;
  66         struct _fits_ops        *f_ops;
  67         fits_counter_t f_del_dir_cnt;
  68         fits_counter_t f_put_back_cnt;
  69         fits_counter_t f_link_add_cnt;
  70         uint64_t f_current_ino;
  71         struct _fits_path *f_current_path;
  72         int             f_alloc_len;
  73         uint8_t         *f_buf;
  74         int             f_size;
  75         struct vnode    *f_vp;          /* file to which we are reporting */
  76         offset_t        *f_offp;
  77         int             f_err;          /* error that stopped diff search */
  78         dsl_dataset_t   *f_fromds;
  79         dsl_dataset_t   *f_tods;
  80         objset_t        *f_fromsnap;
  81         objset_t        *f_tosnap;
  82         dnode_phys_t    *f_dnp;
  83         blklevel_t      *f_bl;
  84         blklevel_t      *f_filebl;
  85         uint64_t        f_fromtxg;
  86         sa_attr_type_t  *f_from_sa_table;
  87         sa_attr_type_t  *f_to_sa_table;
  88         uint64_t        f_shares_dir;
  89 } fits_t;
  90 
  91 typedef struct _fits_ops {
  92         int (*fits_dir_add)(fits_t *f, uint64_t ino);
  93         int (*fits_dir_del)(fits_t *f, uint64_t ino);
  94         int (*fits_dir_mod)(fits_t *f, uint64_t ino);
  95         int (*fits_dirent_add)(void *fits_enump, char *name, uint64_t ino);
  96         int (*fits_dirent_del)(void *fits_enump, char *name, uint64_t ino);
  97         int (*fits_dirent_mod)(void *fits_enump, char *name,
  98             uint64_t ino_old, uint64_t ino_new);
  99         int (*fits_dirent_unmod)(void *fits_enump, char *name, uint64_t ino);
 100         int (*fits_file_add)(fits_t *f, uint64_t ino);
 101         int (*fits_file_del)(fits_t *f, uint64_t ino);
 102         int (*fits_file_mod)(fits_t *f, uint64_t ino);
 103         int (*fits_file_data)(void *fits_filep, void *data, uint64_t off,
 104             uint64_t len);
 105 } fits_ops_t;
 106 
 107 typedef struct _fits_path {
 108         struct _fits_path *fp_next;
 109         int fp_len;
 110         int fp_total_len;
 111         char fp_buf[0];
 112 } fits_path_t;
 113 
 114 typedef struct _fits_dirent {
 115         char *fd_name;
 116         uint64_t fd_parent_ino;
 117         struct _fits_dirent *fd_prev;
 118 } fits_dirent_t;
 119 
 120 typedef enum _fits_which {
 121         FITS_UNDEF,
 122         FITS_OLD,
 123         FITS_NEW
 124 } fits_which_t;
 125 
 126 typedef struct _fits_time {
 127         uint64_t        st_sec;
 128         uint64_t        st_nsec;
 129 } fits_time_t;
 130 
 131 #define FI_ATTR_ATIME           (1 <<  0)
 132 #define FI_ATTR_MTIME           (1 <<  1)
 133 #define FI_ATTR_CTIME           (1 <<  2)
 134 #define FI_ATTR_OTIME           (1 <<  3)
 135 #define FI_ATTR_MODE            (1 <<  4)
 136 #define FI_ATTR_SIZE            (1 <<  5)
 137 #define FI_ATTR_NENTRIES        (1 <<  5)
 138 #define FI_ATTR_PARENT          (1 <<  6)
 139 #define FI_ATTR_LINKS           (1 <<  7)
 140 #define FI_ATTR_RDEV            (1 <<  8)
 141 #define FI_ATTR_UID             (1 <<  9)
 142 #define FI_ATTR_GID             (1 << 10)
 143 #define FI_ATTR_GEN             (1 << 11)
 144 /* XXX TODO xattr, acl, dacl */
 145 
 146 #undef si_uid   /* XXX defined in siginfo.h */
 147 #undef si_gid   /* XXX defined in siginfo.h */
 148 typedef struct _fits_info {
 149         uint64_t        si_nlinks;
 150         uint64_t        si_parent;
 151         union {
 152                 uint64_t        si_nentries;
 153                 uint64_t        si_size;
 154         };
 155         fits_time_t     si_atime;
 156         fits_time_t     si_mtime;
 157         fits_time_t     si_ctime;
 158         fits_time_t     si_otime;
 159         uint64_t        si_mode;
 160         /* XXX TODO xattr */
 161         uint64_t        si_rdev;
 162         uint64_t        si_uid;
 163         uint64_t        si_gid;
 164         uint64_t        si_gen;
 165 } fits_info_t;
 166 
 167 int fits_start(fits_t *f, fits_ops_t **);
 168 int fits_start2(fits_t *f, fits_ops_t **);
 169 int fits_abort(fits_t *f);
 170 int fits_end(fits_t *f);
 171 
 172 int fits_dirent_add_file(fits_t *f, fits_dirent_t *dirent,
 173     uint64_t ino, uint64_t mode, int exists);
 174 void fits_path_free(fits_path_t *fp);
 175 
 176 int fits_get_info(fits_t *f, uint64_t dnobj, fits_which_t which,
 177     fits_info_t *sp, uint64_t flags);
 178 
 179 typedef int (*fits_file_cb_t)(void *ctx, void *data, int len);
 180 int fits_file_contents(fits_t *f, uint64_t dnobj, void *ctx);
 181 int fits_dir_contents(fits_t *f, uint64_t dnobj, void *ctx);
 182 int fits_find_entry(fits_t *f, uint64_t dirobj, uint64_t dnobj,
 183     fits_which_t which, char **name);
 184 void fits_free_name(char *name);
 185 int fits_lookup_entry(fits_t *f, uint64_t dirobj, char *name,
 186     fits_which_t which, uint64_t *dnobj);
 187 int fits_write(fits_t *f, const uint8_t *data, int len);
 188 int fits_get_uuid(fits_t *f, fits_which_t which, uint8_t data[16]);
 189 int fits_get_ctransid(fits_t *f, fits_which_t which,
 190     uint64_t *ctransid);
 191 int fits_get_snapname(fits_t *f, fits_which_t which,
 192     char **name, int *len);
 193 int fits_read_symlink(fits_t *f, uint64_t dnobj, fits_which_t which,
 194     char **target, int *plen);
 195 
 196 int fits_send_start(fits_t *f);
 197 int fits_send_create_file(fits_t *f, fits_dirent_t *dirent, uint64_t ino,
 198 int devise_tempname, fits_path_t **path_ret);
 199 int fits_send_link(fits_t *f, fits_dirent_t *new_dirent, uint64_t ino,
 200     uint64_t old_parent_ino, fits_which_t which,
 201 int devise_tempname);
 202 int fits_send_mkdir(fits_t *f, fits_dirent_t *dirent, uint64_t ino,
 203 int devise_tempname);
 204 int fits_send_rename(fits_t *f, fits_dirent_t *dirent, uint64_t ino,
 205     uint64_t old_parent_ino, int devise_tempname);
 206 int fits_send_rename_from_tempname(fits_t *f, fits_dirent_t *dirent,
 207     uint64_t ino, uint64_t old);
 208 int fits_send_unlink(fits_t *f, fits_dirent_t *dirent, uint64_t ino);
 209 int fits_send_rmdir(fits_t *f, fits_dirent_t *dirent, uint64_t ino);
 210 /* TODO: make **path *path or do we really still alloc it? */
 211 int fits_send_file_data(fits_t *f,
 212     fits_path_t **path, fits_dirent_t *dirent,
 213     uint64_t ino, uint64_t off, uint64_t len, void *data);
 214 int fits_send_mtime_update(fits_t *f, fits_dirent_t *dirent, uint64_t ino);
 215 int fits_send_truncate(fits_t *f, fits_dirent_t *dirent, uint64_t ino,
 216     uint64_t new_size);
 217 int fits_send_chown(fits_t *f, fits_dirent_t *dirent, uint64_t ino,
 218     uint64_t new_uid, uint64_t new_gid);
 219 int fits_send_chmod(fits_t *f, fits_dirent_t *dirent, uint64_t ino,
 220     uint64_t new_mode);
 221 int fits_send_end(fits_t *f);
 222 int fits_add_count(fits_counter_t *fc, uint64_t ino, uint64_t inc,
 223     uint64_t aux, uint64_t *new_count, uint64_t *old_aux);
 224 void fits_free_count(fits_counter_t *fc, uint64_t ino);
 225 int fits_get_count(fits_counter_t *fc, uint64_t ino, uint64_t *new_count,
 226     uint64_t *old_aux);
 227 int fits_assert_count_empty(fits_counter_t *fc);
 228 
 229 void fits_send_init(fits_t *f);
 230 void fits_send_fini(fits_t *f);
 231 
 232 #endif /* _SYS_FITS_IMPL_H */