Lines Matching refs:data

107 static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, const zend_string *key)  in ps_files_path_create()  argument
113 if (!data || ZSTR_LEN(key) <= data->dirdepth || in ps_files_path_create()
114 …buflen < (ZSTR_LEN(data->basedir) + 2 * data->dirdepth + ZSTR_LEN(key) + 5 + sizeof(FILE_PREFIX)))… in ps_files_path_create()
119 memcpy(buf, ZSTR_VAL(data->basedir), ZSTR_LEN(data->basedir)); in ps_files_path_create()
120 n = ZSTR_LEN(data->basedir); in ps_files_path_create()
122 for (i = 0; i < (int)data->dirdepth; i++) { in ps_files_path_create()
139 static void ps_files_close(ps_files *data) in ps_files_close() argument
141 if (data->fd != -1) { in ps_files_close()
145 flock(data->fd, LOCK_UN); in ps_files_close()
147 close(data->fd); in ps_files_close()
148 data->fd = -1; in ps_files_close()
152 static void ps_files_open(ps_files *data, /* const */ zend_string *key) in ps_files_open() argument
160 if (data->fd < 0 || !data->last_key || !zend_string_equals(key, data->last_key)) { in ps_files_open()
161 if (data->last_key) { in ps_files_open()
162 zend_string_release_ex(data->last_key, /* persistent */ false); in ps_files_open()
163 data->last_key = NULL; in ps_files_open()
166 ps_files_close(data); in ps_files_open()
173 if (!ps_files_path_create(buf, sizeof(buf), data, key)) { in ps_files_open()
178 data->last_key = zend_string_copy(key); in ps_files_open()
182 data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY | O_NOFOLLOW, data->filemode); in ps_files_open()
189 data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY, data->filemode); in ps_files_open()
192 if (data->fd != -1) { in ps_files_open()
202 …if (zend_fstat(data->fd, &sbuf) || (sbuf.st_uid != 0 && sbuf.st_uid != getuid() && sbuf.st_uid != … in ps_files_open()
203 close(data->fd); in ps_files_open()
204 data->fd = -1; in ps_files_open()
210 ret = flock(data->fd, LOCK_EX); in ps_files_open()
217 if (fcntl(data->fd, F_SETFD, FD_CLOEXEC)) { in ps_files_open()
218 …php_error_docref(NULL, E_WARNING, "fcntl(%d, F_SETFD, FD_CLOEXEC) failed: %s (%d)", data->fd, stre… in ps_files_open()
227 static zend_result ps_files_write(ps_files *data, zend_string *key, zend_string *val) in ps_files_write() argument
234 ps_files_open(data, key); in ps_files_write()
235 if (data->fd < 0) { in ps_files_write()
240 if (ZSTR_LEN(val) < data->st_size) { in ps_files_write()
241 php_ignore_value(ftruncate(data->fd, 0)); in ps_files_write()
245 n = pwrite(data->fd, ZSTR_VAL(val), ZSTR_LEN(val), 0); in ps_files_write()
247 lseek(data->fd, 0, SEEK_SET); in ps_files_write()
255 wrote = _write(data->fd, buf, to_write); in ps_files_write()
264 n = write(data->fd, ZSTR_VAL(val), ZSTR_LEN(val)); in ps_files_write()
335 static zend_result ps_files_key_exists(ps_files *data, const zend_string *key) in ps_files_key_exists() argument
340 if (!key || !ps_files_path_create(buf, sizeof(buf), data, key)) { in ps_files_key_exists()
350 #define PS_FILES_DATA ps_files *data = PS_GET_MOD_DATA()
366 ps_files *data; in PS_OPEN_FUNC() local
412 data = ecalloc(1, sizeof(*data)); in PS_OPEN_FUNC()
414 data->fd = -1; in PS_OPEN_FUNC()
415 data->dirdepth = dirdepth; in PS_OPEN_FUNC()
416 data->filemode = filemode; in PS_OPEN_FUNC()
417 data->basedir = zend_string_init(save_path, strlen(save_path), /* persistent */ false); in PS_OPEN_FUNC()
422 PS_SET_MOD_DATA(data); in PS_OPEN_FUNC()
442 ps_files_close(data); in PS_CLOSE_FUNC()
444 if (data->last_key) { in PS_CLOSE_FUNC()
445 zend_string_release_ex(data->last_key, /* persistent */ false); in PS_CLOSE_FUNC()
446 data->last_key = NULL; in PS_CLOSE_FUNC()
449 zend_string_release_ex(data->basedir, /* persistent */ false); in PS_CLOSE_FUNC()
450 efree(data); in PS_CLOSE_FUNC()
473 ps_files_open(data, key); in PS_READ_FUNC()
474 if (data->fd < 0) { in PS_READ_FUNC()
478 if (zend_fstat(data->fd, &sbuf)) { in PS_READ_FUNC()
482 data->st_size = sbuf.st_size; in PS_READ_FUNC()
492 n = pread(data->fd, ZSTR_VAL(*val), ZSTR_LEN(*val), 0); in PS_READ_FUNC()
494 lseek(data->fd, 0, SEEK_SET); in PS_READ_FUNC()
502 read_in = _read(data->fd, buf, to_read); in PS_READ_FUNC()
512 n = read(data->fd, ZSTR_VAL(*val), ZSTR_LEN(*val)); in PS_READ_FUNC()
544 return ps_files_write(data, key, val); in PS_WRITE_FUNC()
568 if (!ps_files_path_create(buf, sizeof(buf), data, key)) { in PS_UPDATE_TIMESTAMP_FUNC()
576 return ps_files_write(data, key, val); in PS_UPDATE_TIMESTAMP_FUNC()
598 if (!ps_files_path_create(buf, sizeof(buf), data, key)) { in PS_DESTROY_FUNC()
602 if (data->fd != -1) { in PS_DESTROY_FUNC()
603 ps_files_close(data); in PS_DESTROY_FUNC()
637 if (data->dirdepth == 0) { in PS_GC_FUNC()
638 *nrdels = ps_files_cleanup_dir(data->basedir, maxlifetime); in PS_GC_FUNC()
667 sid = php_session_create_id((void**)&data); in PS_CREATE_SID_FUNC()
677 if (data && ps_files_key_exists(data, sid) == SUCCESS) { in PS_CREATE_SID_FUNC()
705 return ps_files_key_exists(data, key); in PS_VALIDATE_SID_FUNC()