Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MTGL_SNAP_UTIL_H
00024 #define MTGL_SNAP_UTIL_H
00025
00026
00027 #ifdef __MTA__
00028
00029 #include <luc/luc_exported.h>
00030 #include <snapshot/client.h>
00031
00032 #else
00033
00034 #include <cstdio>
00035 #include <cassert>
00036 #include <cfloat>
00037 #include <climits>
00038 #include <cstdlib>
00039 #include <iostream>
00040
00041
00042 #ifndef WIN32
00043 #include <stdint.h>
00044 #endif
00045
00046 #if defined(sun) || defined(__sun)
00047 typedef uint64_t u_int64_t;
00048 #endif
00049
00050
00051 #include <sys/types.h>
00052 #include <sys/stat.h>
00053
00054 typedef int luc_error_t;
00055 typedef uint64_t luc_endpoint_id_t;
00056 typedef struct stat snap_stat_buf;
00057
00058
00059 #define LUC_ERR_OK 1
00060 #define SNAP_ERR_OK 1
00061 #define LUC_ERR_TIMEOUT -13
00062 #define SNAP_ERR_BAD_PARAMETER 2
00063 #define SNAP_ERR_OPEN_FAILED 3
00064 #define SNAP_ERR_READ_FAILED 4
00065 #define SNAP_ERR_RESOURCE_FAILURE 5
00066 #define SNAP_ERR_RESTORE_FAILED 6
00067 #define SNAP_ERR_SNAPSHOT_FAILED 7
00068 #define SNAP_ERR_WRITE_FAILED 8
00069
00070 namespace mtgl {
00071
00072
00073 inline luc_error_t snap_init()
00074 {
00075 return SNAP_ERR_OK;
00076 }
00077
00078
00079 inline luc_error_t snap_snapshot(
00080 char fname[],
00081 void *buf,
00082 size_t count,
00083 int64_t *err)
00084 {
00085 FILE *fp = fopen(fname, "w");
00086
00087 if (fp == NULL)
00088 {
00089 fprintf(stderr, "ERROR in snap_snapshot: File %s not found\n", fname);
00090
00091 if (err != NULL) *err = -1;
00092
00093 return SNAP_ERR_SNAPSHOT_FAILED;
00094 }
00095
00096 fwrite(buf, 1, count, fp);
00097 fclose(fp);
00098
00099 if (err != NULL) *err = 0;
00100
00101 return SNAP_ERR_OK;
00102 }
00103
00104
00105 inline luc_error_t snap_restore(
00106 char fname[],
00107 void *buf,
00108 size_t count,
00109 int64_t *err)
00110 {
00111 FILE *fp = fopen(fname, "r");
00112
00113 if (fp == NULL)
00114 {
00115 fprintf(stderr, "ERROR in snap_restore: File %s not found\n", fname);
00116
00117 if (err != NULL) *err = -1;
00118
00119 return SNAP_ERR_RESTORE_FAILED;
00120 }
00121
00122 if (fread(buf, 1, count, fp) == 0)
00123 {
00124 return SNAP_ERR_RESTORE_FAILED;
00125 }
00126
00127 fclose(fp);
00128
00129 if (err != NULL) *err = 0;
00130
00131 return SNAP_ERR_OK;
00132 }
00133
00134
00135 inline luc_error_t snap_pwrite(
00136 char fname[],
00137 luc_endpoint_id_t swEP,
00138 const void *buf,
00139 size_t count,
00140 off_t offset,
00141 int64_t *err)
00142 {
00143 fprintf(stderr, "ERROR: snap_pwrite not yet implemented.\n");
00144
00145 if (err != NULL) *err = -1;
00146
00147 return SNAP_ERR_WRITE_FAILED;
00148 }
00149
00150
00151 inline luc_error_t snap_pread(
00152 char fname[],
00153 luc_endpoint_id_t swEP,
00154 void *buf,
00155 size_t count,
00156 off_t offset,
00157 int64_t *err)
00158 {
00159 fprintf(stderr, "ERROR: snap_pread not yet implemented.\n");
00160
00161 if (err != NULL) *err = -1;
00162
00163 return SNAP_ERR_READ_FAILED;
00164 }
00165
00166
00167
00168
00169
00170 inline luc_error_t snap_stat(
00171 char fname[],
00172 luc_endpoint_id_t swEP,
00173 snap_stat_buf *statBuf,
00174 int64_t *err)
00175 {
00176 int tmp = stat(fname, statBuf);
00177
00178 if (err != NULL) *err = tmp;
00179
00180 return SNAP_ERR_OK;
00181 }
00182
00183 }
00184
00185 #endif
00186
00187 #endif