Lines Matching refs:data
109 static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, const char *key) in ps_files_path_create() argument
117 if (!data || key_len <= data->dirdepth || in ps_files_path_create()
118 buflen < (strlen(data->basedir) + 2 * data->dirdepth + key_len + 5 + sizeof(FILE_PREFIX))) { in ps_files_path_create()
123 memcpy(buf, data->basedir, data->basedir_len); in ps_files_path_create()
124 n = data->basedir_len; in ps_files_path_create()
126 for (i = 0; i < (int)data->dirdepth; i++) { in ps_files_path_create()
143 static void ps_files_close(ps_files *data) in ps_files_close() argument
145 if (data->fd != -1) { in ps_files_close()
149 flock(data->fd, LOCK_UN); in ps_files_close()
151 close(data->fd); in ps_files_close()
152 data->fd = -1; in ps_files_close()
156 static void ps_files_open(ps_files *data, const char *key) in ps_files_open() argument
164 if (data->fd < 0 || !data->lastkey || strcmp(key, data->lastkey)) { in ps_files_open()
165 if (data->lastkey) { in ps_files_open()
166 efree(data->lastkey); in ps_files_open()
167 data->lastkey = NULL; in ps_files_open()
170 ps_files_close(data); in ps_files_open()
177 if (!ps_files_path_create(buf, sizeof(buf), data, key)) { in ps_files_open()
182 data->lastkey = estrdup(key); in ps_files_open()
186 data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY | O_NOFOLLOW, data->filemode); in ps_files_open()
193 data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY, data->filemode); in ps_files_open()
196 if (data->fd != -1) { in ps_files_open()
206 …if (zend_fstat(data->fd, &sbuf) || (sbuf.st_uid != 0 && sbuf.st_uid != getuid() && sbuf.st_uid != … in ps_files_open()
207 close(data->fd); in ps_files_open()
208 data->fd = -1; in ps_files_open()
214 ret = flock(data->fd, LOCK_EX); in ps_files_open()
221 if (fcntl(data->fd, F_SETFD, FD_CLOEXEC)) { in ps_files_open()
222 …php_error_docref(NULL, E_WARNING, "fcntl(%d, F_SETFD, FD_CLOEXEC) failed: %s (%d)", data->fd, stre… in ps_files_open()
231 static int ps_files_write(ps_files *data, zend_string *key, zend_string *val) in ps_files_write() argument
238 ps_files_open(data, ZSTR_VAL(key)); in ps_files_write()
239 if (data->fd < 0) { in ps_files_write()
244 if (ZSTR_LEN(val) < data->st_size) { in ps_files_write()
245 php_ignore_value(ftruncate(data->fd, 0)); in ps_files_write()
249 n = pwrite(data->fd, ZSTR_VAL(val), ZSTR_LEN(val), 0); in ps_files_write()
251 lseek(data->fd, 0, SEEK_SET); in ps_files_write()
259 wrote = _write(data->fd, buf, to_write); in ps_files_write()
268 n = write(data->fd, ZSTR_VAL(val), ZSTR_LEN(val)); in ps_files_write()
343 static int ps_files_key_exists(ps_files *data, const char *key) in ps_files_key_exists() argument
348 if (!key || !ps_files_path_create(buf, sizeof(buf), data, key)) { in ps_files_key_exists()
358 #define PS_FILES_DATA ps_files *data = PS_GET_MOD_DATA()
374 ps_files *data; in PS_OPEN_FUNC() local
420 data = ecalloc(1, sizeof(*data)); in PS_OPEN_FUNC()
422 data->fd = -1; in PS_OPEN_FUNC()
423 data->dirdepth = dirdepth; in PS_OPEN_FUNC()
424 data->filemode = filemode; in PS_OPEN_FUNC()
425 data->basedir_len = strlen(save_path); in PS_OPEN_FUNC()
426 data->basedir = estrndup(save_path, data->basedir_len); in PS_OPEN_FUNC()
431 PS_SET_MOD_DATA(data); in PS_OPEN_FUNC()
451 ps_files_close(data); in PS_CLOSE_FUNC()
453 if (data->lastkey) { in PS_CLOSE_FUNC()
454 efree(data->lastkey); in PS_CLOSE_FUNC()
455 data->lastkey = NULL; in PS_CLOSE_FUNC()
458 efree(data->basedir); in PS_CLOSE_FUNC()
459 efree(data); in PS_CLOSE_FUNC()
482 ps_files_open(data, ZSTR_VAL(key)); in PS_READ_FUNC()
483 if (data->fd < 0) { in PS_READ_FUNC()
487 if (zend_fstat(data->fd, &sbuf)) { in PS_READ_FUNC()
491 data->st_size = sbuf.st_size; in PS_READ_FUNC()
501 n = pread(data->fd, ZSTR_VAL(*val), ZSTR_LEN(*val), 0); in PS_READ_FUNC()
503 lseek(data->fd, 0, SEEK_SET); in PS_READ_FUNC()
511 read_in = _read(data->fd, buf, to_read); in PS_READ_FUNC()
521 n = read(data->fd, ZSTR_VAL(*val), ZSTR_LEN(*val)); in PS_READ_FUNC()
553 return ps_files_write(data, key, val); in PS_WRITE_FUNC()
579 if (!ps_files_path_create(buf, sizeof(buf), data, ZSTR_VAL(key))) { in PS_UPDATE_TIMESTAMP_FUNC()
592 return ps_files_write(data, key, val); in PS_UPDATE_TIMESTAMP_FUNC()
614 if (!ps_files_path_create(buf, sizeof(buf), data, ZSTR_VAL(key))) { in PS_DESTROY_FUNC()
618 if (data->fd != -1) { in PS_DESTROY_FUNC()
619 ps_files_close(data); in PS_DESTROY_FUNC()
653 if (data->dirdepth == 0) { in PS_GC_FUNC()
654 *nrdels = ps_files_cleanup_dir(data->basedir, maxlifetime); in PS_GC_FUNC()
683 sid = php_session_create_id((void**)&data); in PS_CREATE_SID_FUNC()
693 if (data && ps_files_key_exists(data, ZSTR_VAL(sid)) == SUCCESS) { in PS_CREATE_SID_FUNC()
721 return ps_files_key_exists(data, ZSTR_VAL(key)); in PS_VALIDATE_SID_FUNC()