Functions

dsi_open.c File Reference

#include <string.h>
#include <fcntl.h>
#include <time.h>
#include "grpc.h"
Include dependency graph for dsi_open.c:

Go to the source code of this file.

Functions

grpc_error_t grpc_dsi_open (DSI_FILE **rfile, char *host_name, int flag, int permissions, int size, dsi_type storage_system)

Function Documentation

grpc_error_t grpc_dsi_open ( DSI_FILE **  rfile,
char *  host_name,
int  flag,
int  permissions,
int  size,
dsi_type  storage_system 
)

Definition at line 12 of file dsi_open.c.

{
#ifdef DSI
  uid_t my_uid;
  DSI_FILE* dsi_file;
#ifdef DSI_IBP
  IBP_depot depot;
  IBP_set_of_caps cap;
  IBP_attributes attr;
  struct ibp_timer ls_timeout;
#endif
  time_t ls_now;

  my_uid = getuid();

  /* the file is not present */
  if(!(flag & O_CREAT)) {
    GRPC_RETURN(GRPC_OTHER_ERROR_CODE, GRPC_DSI_UNKNOWN_FILE);
  }
  else {
    if(storage_system == GS_DSI_IBP) {
#ifdef DSI_IBP
      char *cp;

      ls_timeout.ServerSync = 10;
      ls_timeout.ClientTimeout = 10;

      depot = (IBP_depot)calloc(1, sizeof(struct ibp_depot));
      attr = (IBP_attributes)calloc(1, sizeof(struct ibp_attributes));

      time(&ls_now);
      attr->duration = (ls_now + 24*3600);
      attr->reliability = IBP_STABLE;
      attr->type = IBP_BYTEARRAY;

      if((cp = strchr(host_name, ':'))) {
        strncpy(depot->host, host_name, cp - host_name);
        depot->host[cp - host_name] = 0;
        depot->port = atoi(cp+1);
      }
      else {
        strncpy(depot->host, host_name, IBP_MAX_HOSTNAME_LEN-1);
        depot->host[IBP_MAX_HOSTNAME_LEN-1] = 0;
        depot->port = 6714;
      }

      cap = IBP_allocate(depot, &ls_timeout, size, attr);

      if(cap == NULL)
        GRPC_RETURN(GRPC_OTHER_ERROR_CODE, GRPC_DSI_ALLOCATE_ERROR);
#endif

      dsi_file = (DSI_FILE*)malloc(sizeof(DSI_FILE));
      dsi_file->flag = flag;
      dsi_file->perm = permissions;
      dsi_file->uid = my_uid;
      dsi_file->storage_system = GS_DSI_IBP;
    #ifdef DSI_IBP
      dsi_file->dsi_specifics.ibp.depot = depot;
      dsi_file->dsi_specifics.ibp.cap = cap;
    #endif
      dsi_file->written_count = 0;

      *rfile = dsi_file;
      GRPC_RETURN(GRPC_NO_ERROR, GRPC_NO_MINOR_ERROR);
    }
  }

#endif

  GRPC_RETURN(GRPC_OTHER_ERROR_CODE, GRPC_DSI_DISABLED);
}

Here is the caller graph for this function: