STATIC_ROUTINE int CopyFile(char *src, char *dst, int dont_replace) { /* int status=0; char *cmd = (char *)malloc(strlen(src)+strlen(dst) + 100); sprintf(cmd,"cp %s %s",src,dst); status = system(cmd); if (status != 0) printf("Error creating pulse with command: %s, status = %d\n",cmd,status); else { sprintf(cmd,"SetMdsplusFileProtection %s 2> /dev/null",dst); system(cmd); } free(cmd); return status == 0; */ int status = TreeFAILURE; int src_fd = MDS_IO_OPEN(src,O_RDONLY | O_BINARY | O_RANDOM, 0); if (src_fd != -1) { off_t src_len = MDS_IO_LSEEK(src_fd, 0, SEEK_END); int dst_fd = MDS_IO_OPEN(dst,O_RDWR | O_CREAT | O_TRUNC, 0664); if (dst_fd != -1) { MDS_IO_LSEEK(src_fd, 0, SEEK_SET); MDS_IO_LOCK(src_fd,0,src_len,1); if (src_len > 0) { void *buff = malloc(src_len); size_t bytes_read = MDS_IO_READ(src_fd,buff,(size_t)src_len); if (bytes_read == src_len) { int bytes_written = MDS_IO_WRITE(dst_fd,buff,(size_t)src_len); if (bytes_written == src_len) status = TreeSUCCESS; } if (buff) free(buff); } else if (src_len == 0) status = TreeSUCCESS; MDS_IO_LOCK(src_fd,0,src_len,0); MDS_IO_CLOSE(dst_fd); } MDS_IO_CLOSE(src_fd); } return status; }
STATIC_ROUTINE int _CopyFile(char *src, char *dst, int lock_it) { int status = TreeFAILURE; int src_fd = MDS_IO_OPEN(src,O_RDONLY | O_BINARY | O_RANDOM, 0); if (src_fd != -1) { ssize_t src_len = MDS_IO_LSEEK(src_fd, 0, SEEK_END); int dst_fd = MDS_IO_OPEN(dst,O_RDWR | O_CREAT | O_TRUNC, 0664); if ((dst_fd != -1) && (src_len != -1)) { MDS_IO_LSEEK(src_fd, 0, SEEK_SET); if (lock_it) MDS_IO_LOCK(src_fd,0,(int)src_len,MDS_IO_LOCK_RD,0); if (src_len > 0) { size_t chunk_size = (size_t)(MIN(MAX_CHUNK, src_len)); void *buff = malloc(chunk_size); size_t bytes_to_go = (size_t)src_len; while(bytes_to_go > 0) { size_t io_size = MIN(bytes_to_go, chunk_size); ssize_t bytes_read = MDS_IO_READ(src_fd,buff,io_size); if (bytes_read == io_size) { ssize_t bytes_written = MDS_IO_WRITE(dst_fd,buff,io_size); if (bytes_written != io_size) break; } bytes_to_go -= io_size; } if (buff) free(buff); if (bytes_to_go == 0) status = TreeSUCCESS; } else if (src_len == 0) status = TreeSUCCESS; if (lock_it) MDS_IO_LOCK(src_fd,0,(int)src_len,MDS_IO_LOCK_NONE,0); MDS_IO_CLOSE(dst_fd); } MDS_IO_CLOSE(src_fd); } return status; }
int TreePutNci(TREE_INFO *info, int node_num, NCI *nci, int flush) { int status; status = TreeNORMAL; /*************************************** If the tree is not open for edit ****************************************/ if ((info->edit == 0) || (node_num < info->edit->first_in_mem)) { /********************** Update the NCI record ***********************/ status = TreeLockNci(info, 0, node_num,0); if (status & 1) { char nci_bytes[42]; memset(nci_bytes,0,sizeof(nci_bytes)); TreeSerializeNciOut(nci,nci_bytes); MDS_IO_LSEEK(info->nci_file->put,sizeof(nci_bytes) * node_num, SEEK_SET); status = (MDS_IO_WRITE(info->nci_file->put,nci_bytes,sizeof(nci_bytes)) == sizeof(nci_bytes)) ? TreeNORMAL : TreeFAILURE; TreeUnLockNci(info, 0, node_num); } } /**************************** Else it is open for edit so the characteristics are just a memory reference away. *****************************/ else memcpy(info->edit->nci + (node_num - info->edit->first_in_mem),nci,sizeof(*nci)); TreeUnLockNci(info,0,node_num); return status; }
int TreeSetCurrentShotId(char *experiment, int shot) { int status = 0; char *path = 0; char *exp = strcpy(malloc(strlen(experiment)+6),experiment); int slen; int i; for (i=0;exp[i] != '\0';i++) exp[i] = _ToLower(exp[i]); strcat(exp,"_path"); path = TranslateLogical(exp); exp[strlen(experiment)]='\0'; if (path && ((slen = strlen(path)) > 2) && (path[slen-1] == ':') && (path[slen-2] == ':')) { path[slen-2] = 0; status = TreeSetCurrentShotIdRemote(exp, path, shot); } else { int fd = OpenShotIdFile(exp,O_WRONLY); if (fd != -1) { int lshot = shot; #ifdef WORDS_BIGENDIAN int i; char *optr = (char *)&lshot; char *iptr = (char *)&shot; for (i=0;i<4;i++) optr[i] = iptr[3-i]; #endif status = MDS_IO_WRITE(fd,&lshot,sizeof(shot)) == sizeof(shot); MDS_IO_CLOSE(fd); } } if (path) TranslateLogicalFree(path); free(exp); return status; }