28 #include <sys/types.h> 33 #define S_ISDIR(m) ((m) & S_IFDIR) 46 #if defined (SERVER_MODE) 51 #if defined (SA_MODE) || defined (SERVER_MODE) 53 static char es_base_dir[PATH_MAX];
55 static void es_get_unique_name (
char *dirname1,
char *dirname2,
const char *metaname,
char *filename);
56 static int es_make_dirs (
const char *dirname1,
const char *dirname2);
57 static void es_rename_path (
char *src,
char *tgt,
char *metaname);
68 es_get_unique_name (
char *dirname1,
char *dirname2,
const char *metaname,
char *filename)
74 #if defined(SERVER_MODE) 80 r = rand_r (&thread_p->rand_seed);
89 snprintf (filename, NAME_MAX,
"%s.%020llu_%04d", metaname, (
unsigned long long) unum, r % 10000);
92 snprintf (dirname1, NAME_MAX,
"ces_%03d", hashval);
95 snprintf (dirname2, NAME_MAX,
"ces_%03d", hashval);
106 es_make_dirs (
const char *dirname1,
const char *dirname2)
108 char dirbuf[PATH_MAX];
111 #if defined (CUBRID_OWFS_POSIX_TWO_DEPTH_DIRECTORY) 119 ret = mkdir (dirbuf, 0755);
120 if (ret < 0 && errno == ENOENT)
122 n = snprintf (dirbuf, PATH_MAX - 1,
"%s%c%s", es_base_dir,
PATH_SEPARATOR, dirname1);
123 ret = mkdir (dirbuf, 0755);
124 if (ret == 0 || errno == EEXIST)
130 if (snprintf (dirbuf, PATH_MAX - 1,
"%s%c%s", es_base_dir,
PATH_SEPARATOR, dirname1) < 0)
135 ret = mkdir (dirbuf, 0755);
138 if (ret < 0 && errno != EEXIST)
155 es_rename_path (
char *src,
char *tgt,
char *metaname)
177 t = tgt + (s - src) + 1;
191 sprintf (t,
"%s%s", metaname, s);
206 #if defined(SA_MODE) || defined(SERVER_MODE) 210 ret = stat (base_path, &sbuf);
211 if (ret != 0 || !S_ISDIR (sbuf.st_mode))
219 strlcpy (es_base_dir, base_path, PATH_MAX);
237 #if defined(SA_MODE) || defined(SERVER_MODE) 245 xes_posix_create_file (
char *new_path)
249 char dirname1[NAME_MAX], dirname2[NAME_MAX], filename[NAME_MAX];
252 es_get_unique_name (dirname1, dirname2,
"ces_temp", filename);
253 #if defined (CUBRID_OWFS_POSIX_TWO_DEPTH_DIRECTORY) 266 es_log (
"xes_posix_create_file(): %s\n", new_path);
268 #if defined (WINDOWS) 269 fd = open (new_path, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, S_IRWXU);
271 fd = open (new_path, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_LARGEFILE);
277 ret = es_make_dirs (dirname1, dirname2);
282 #if defined (WINDOWS) 283 fd = open (new_path, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, S_IRWXU);
285 fd = open (new_path, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_LARGEFILE);
310 xes_posix_write_file (
const char *path,
const void *buf,
size_t count, off_t offset)
317 es_log (
"xes_posix_write_file(%s, count %d offset %ld)\n", path, count, offset);
325 if (stat (path, &pstat) < 0)
330 if (offset != pstat.st_size)
333 snprintf (buf, PATH_MAX,
"offset error %s", path);
338 #if defined (WINDOWS) 339 fd = open (path, O_WRONLY | O_APPEND | O_BINARY, S_IRWXU);
341 fd = open (path, O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_LARGEFILE);
351 if (lseek (fd, offset, SEEK_SET) != offset)
358 nbytes = write (fd, buf, (
unsigned) count);
377 buf = (
char *) buf + nbytes;
392 xes_posix_read_file (
const char *path,
void *buf,
size_t count, off_t offset)
398 es_log (
"xes_posix_read_file(%s, count %d offset %ld)\n", path, count, offset);
400 #if defined (WINDOWS) 401 fd = open (path, O_RDONLY | O_BINARY);
403 fd = open (path, O_RDONLY | O_LARGEFILE);
421 if (lseek (fd, offset, SEEK_SET) != offset)
428 nbytes = read (fd, buf, (
unsigned) count);
451 buf = (
char *) buf + nbytes;
466 xes_posix_delete_file (
const char *path)
470 es_log (
"xes_posix_delete_file(%s)\n", path);
490 xes_posix_copy_file (
const char *src_path,
char *metaname,
char *new_path)
492 #define ES_POSIX_COPY_BUFSIZE (4096 * 4) 496 char dirname1[NAME_MAX], dirname2[NAME_MAX], filename[NAME_MAX];
497 char buf[ES_POSIX_COPY_BUFSIZE];
500 #if defined (WINDOWS) 501 rd_fd = open (src_path, O_RDONLY | O_BINARY);
503 rd_fd = open (src_path, O_RDONLY | O_LARGEFILE);
513 es_get_unique_name (dirname1, dirname2, metaname, filename);
514 #if defined (CUBRID_OWFS_POSIX_TWO_DEPTH_DIRECTORY) 527 es_log (
"xes_posix_copy_file(%s, %s): %s\n", src_path, metaname, new_path);
529 #if defined (WINDOWS) 530 wr_fd = open (new_path, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, S_IRWXU);
532 wr_fd = open (new_path, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_LARGEFILE);
538 ret = es_make_dirs (dirname1, dirname2);
544 #if defined (WINDOWS) 545 wr_fd = open (new_path, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, S_IRWXU);
547 wr_fd = open (new_path, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_LARGEFILE);
566 ret = read (rd_fd, buf, ES_POSIX_COPY_BUFSIZE);
577 ret = write (wr_fd, buf, (
unsigned) ret);
601 xes_posix_rename_file (
const char *src_path,
const char *metaname,
char *new_path)
605 es_rename_path ((
char *) src_path, new_path, (
char *) metaname);
607 es_log (
"xes_posix_rename_file(%s, %s): %s\n", src_path, metaname, new_path);
622 xes_posix_get_file_size (
const char *path)
627 es_log (
"xes_posix_get_file_size(%s)\n", path);
629 ret = stat (path, &pstat);
636 return pstat.st_size;
653 es_log (
"es_local_read_file(%s, count %d offset %ld)\n", path, count, offset);
655 #if defined (WINDOWS) 656 fd = open (path, O_RDONLY | O_BINARY);
658 fd = open (path, O_RDONLY | O_LARGEFILE);
668 if (lseek (fd, offset, SEEK_SET) != offset)
675 nbytes = read (fd, buf, (
unsigned) count);
698 buf = (
char *) buf + nbytes;
718 es_log (
"es_local_get_file_size(%s)\n", path);
720 ret = stat (path, &pstat);
727 return pstat.st_size;
int os_rename_file(const char *src_path, const char *dest_path)
cubthread::entry * thread_get_thread_entry_info(void)
UINT64 es_get_unique_num(void)
#define ER_ES_INVALID_PATH
int es_posix_init(const char *base_path)
off_t es_local_get_file_size(const char *path)
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
int es_local_read_file(const char *path, void *buf, size_t count, off_t offset)
void er_set_with_oserror(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
int count(int &result, const cub_regex_object ®, const std::string &src, const int position, const INTL_CODESET codeset)
size_t strlcpy(char *dst, const char *src, size_t siz)
void es_posix_final(void)
#define ER_ES_FILE_NOT_FOUND
unsigned int es_name_hash_func(int size, const char *name)