Go to the documentation of this file.00001 #include <fcntl.h>
00002 #ifdef HAVE_CONFIG_H
00003 #include "config.h"
00004 #endif
00005 #include "grpc.h"
00006
00007 int
00008 grpc_dsi_ibp_store(DSI_FILE *dsi_file, char *data, int length)
00009 {
00010 #ifdef DSI_IBP
00011 struct ibp_timer t;
00012 IBP_cap wcap;
00013
00014 t.ServerSync = 10;
00015 t.ClientTimeout = 10;
00016
00017 wcap = dsi_file->dsi_specifics.ibp.cap->writeCap;
00018
00019 if(IBP_store(wcap, &t, data, length) < 0) {
00020 ERRPRINTF("IBP_store failed\n");
00021 return -1;
00022 }
00023
00024 return 0;
00025 #else
00026 return -1;
00027 #endif
00028 }
00029
00030 int
00031 grpc_dsi_store(DSI_FILE *dsi_file, char *data, int length)
00032 {
00033 if(dsi_file->storage_system == GS_DSI_IBP) {
00034 #ifdef DSI_IBP
00035 return grpc_dsi_ibp_store(dsi_file, data, length);
00036 #endif
00037 }
00038
00039 return -1;
00040 }
00041
00042 grpc_error_t
00043 grpc_dsi_write_vector(DSI_OBJECT **robject, DSI_FILE *dsi_file,
00044 void *data, int count, enum datatype data_type)
00045 {
00046 #ifdef DSI
00047 int write_allowed;
00048 int perm;
00049 int extent, length;
00050 uid_t my_uid;
00051 DSI_OBJECT* dsi_obj;
00052 int my_dsig;
00053
00054 my_dsig = pvmgetdsig();
00055 extent = gs_get_element_size(data_type, my_dsig);
00056 length = count*extent;
00057
00058 my_uid = getuid();
00059
00060 if(my_uid == dsi_file->uid)
00061 perm = dsi_file->perm / 100;
00062 else
00063 perm = dsi_file->perm % 10;
00064
00065 write_allowed = perm & 2;
00066
00067 if(write_allowed && ((dsi_file->flag&O_WRONLY) || (dsi_file->flag&O_RDWR))) {
00068 if(grpc_dsi_store(dsi_file, data, length) < 0)
00069 GRPC_RETURN(GRPC_OTHER_ERROR_CODE, GRPC_DSI_STORE_ERROR);
00070
00071 dsi_obj = (DSI_OBJECT*)malloc(sizeof(DSI_OBJECT));
00072 dsi_obj->offset = dsi_file->written_count;
00073 dsi_obj->dsi_file = dsi_file;
00074 dsi_file->written_count += length;
00075
00076 if(gs_insert_dsi_object(dsi_obj) < 0)
00077 GRPC_RETURN(GRPC_OTHER_ERROR_CODE, GRPC_DSI_INTERNAL_ERROR);
00078
00079 *robject = dsi_obj;
00080 GRPC_RETURN(GRPC_NO_ERROR, GRPC_NO_MINOR_ERROR);
00081 }
00082 else
00083 GRPC_RETURN(GRPC_OTHER_ERROR_CODE, GRPC_DSI_EACCES);
00084 #endif
00085
00086 GRPC_RETURN(GRPC_OTHER_ERROR_CODE, GRPC_DSI_DISABLED);
00087 }
00088
00089 grpc_error_t
00090 grpc_dsi_write_matrix(DSI_OBJECT **robject, DSI_FILE *dsi_file, void *data,
00091 int rows, int cols, enum datatype data_type)
00092 {
00093 return grpc_dsi_write_vector(robject, dsi_file, data, rows*cols, data_type);
00094 }