dsi_open.c

Go to the documentation of this file.
00001 #include <string.h>
00002 #include <fcntl.h>
00003 #include <time.h>
00004 
00005 #ifdef HAVE_CONFIG_H
00006 #include "config.h"
00007 #endif /* HAVE_CONFIG_H */
00008 
00009 #include "grpc.h"
00010 
00011 grpc_error_t
00012 grpc_dsi_open(DSI_FILE **rfile, char *host_name, int flag, int permissions, 
00013   int size, dsi_type storage_system)
00014 {
00015 #ifdef DSI
00016   uid_t my_uid;
00017   DSI_FILE* dsi_file;
00018 #ifdef DSI_IBP
00019   IBP_depot depot;
00020   IBP_set_of_caps cap;
00021   IBP_attributes attr;
00022   struct ibp_timer ls_timeout;
00023 #endif
00024   time_t ls_now;
00025 
00026   my_uid = getuid();
00027 
00028   /* the file is not present */
00029   if(!(flag & O_CREAT)) {
00030     GRPC_RETURN(GRPC_OTHER_ERROR_CODE, GRPC_DSI_UNKNOWN_FILE);
00031   }
00032   else {
00033     if(storage_system == GS_DSI_IBP) {
00034 #ifdef DSI_IBP
00035       char *cp;
00036 
00037       ls_timeout.ServerSync = 10;
00038       ls_timeout.ClientTimeout = 10;
00039 
00040       depot = (IBP_depot)calloc(1, sizeof(struct ibp_depot));
00041       attr = (IBP_attributes)calloc(1, sizeof(struct ibp_attributes));
00042 
00043       time(&ls_now);
00044       attr->duration = (ls_now + 24*3600);
00045       attr->reliability = IBP_STABLE;
00046       attr->type = IBP_BYTEARRAY;
00047 
00048       if((cp = strchr(host_name, ':'))) {
00049         strncpy(depot->host, host_name, cp - host_name);
00050         depot->host[cp - host_name] = 0;
00051         depot->port = atoi(cp+1);
00052       }
00053       else {
00054         strncpy(depot->host, host_name, IBP_MAX_HOSTNAME_LEN-1);
00055         depot->host[IBP_MAX_HOSTNAME_LEN-1] = 0;
00056         depot->port = 6714;
00057       }
00058 
00059       cap = IBP_allocate(depot, &ls_timeout, size, attr);
00060 
00061       if(cap == NULL)
00062         GRPC_RETURN(GRPC_OTHER_ERROR_CODE, GRPC_DSI_ALLOCATE_ERROR);
00063 #endif
00064 
00065       dsi_file = (DSI_FILE*)malloc(sizeof(DSI_FILE));
00066       dsi_file->flag = flag;
00067       dsi_file->perm = permissions;
00068       dsi_file->uid = my_uid;
00069       dsi_file->storage_system = GS_DSI_IBP;
00070     #ifdef DSI_IBP
00071       dsi_file->dsi_specifics.ibp.depot = depot;
00072       dsi_file->dsi_specifics.ibp.cap = cap;
00073     #endif
00074       dsi_file->written_count = 0;
00075 
00076       *rfile = dsi_file;
00077       GRPC_RETURN(GRPC_NO_ERROR, GRPC_NO_MINOR_ERROR);
00078     }
00079   }
00080 
00081 #endif
00082 
00083   GRPC_RETURN(GRPC_OTHER_ERROR_CODE, GRPC_DSI_DISABLED);
00084 }