dpl_status_t dpl_posix_stream_getmd(dpl_ctx_t *ctx, dpl_stream_t *stream, dpl_dict_t **metadatap, dpl_sysmd_t **sysmdp) { dpl_dict_t *all_mds = NULL; dpl_status_t ret = DPL_FAILURE; DPL_TRACE(ctx, DPL_TRACE_BACKEND, ""); ret = dpl_posix_head_raw(ctx, stream->bucket, stream->locator, NULL, NULL, DPL_FTYPE_REG, NULL, &all_mds, NULL); if (DPL_SUCCESS != ret) goto end; ret = dpl_posix_get_metadata_from_values(all_mds, metadatap, sysmdp ? *sysmdp : NULL); if (DPL_SUCCESS != ret) goto end; ret = DPL_SUCCESS; end: if (all_mds) dpl_dict_free(all_mds); DPL_TRACE(ctx, DPL_TRACE_BACKEND, "ret=%d", ret); return ret; }
dpl_status_t dpl_posix_head(dpl_ctx_t *ctx, const char *bucket, const char *resource, const char *subresource, const dpl_option_t *option, dpl_ftype_t object_type, const dpl_condition_t *condition, dpl_dict_t **metadatap, dpl_sysmd_t *sysmdp, char **locationp) { dpl_status_t ret, ret2; dpl_dict_t *all_mds = NULL; char path[MAXPATHLEN]; DPL_TRACE(ctx, DPL_TRACE_BACKEND, ""); snprintf(path, sizeof (path), "/%s/%s", ctx->base_path ? ctx->base_path : "", resource ? resource : ""); ret2 = dpl_posix_head_raw(ctx, bucket, resource, subresource, option, object_type, condition, &all_mds, locationp); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } ret2 = dpl_posix_get_metadata_from_values(all_mds, metadatap, sysmdp); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } ret = DPL_SUCCESS; end: if (NULL != all_mds) dpl_dict_free(all_mds); DPL_TRACE(ctx, DPL_TRACE_BACKEND, "ret=%d", ret); return ret; }
dpl_status_t dpl_posix_get_buffered(dpl_ctx_t *ctx, const char *bucket, const char *resource, const char *subresource, const dpl_option_t *option, dpl_ftype_t object_type, const dpl_condition_t *condition, const dpl_range_t *range, dpl_metadatum_func_t metadatum_func, dpl_dict_t **metadatap, dpl_sysmd_t *sysmdp, dpl_buffer_func_t buffer_func, void *cb_arg, char **locationp) { dpl_status_t ret, ret2; char path[MAXPATHLEN]; int fd = -1; int iret; char buf[8192]; ssize_t cc; dpl_dict_t *all_mds = NULL; struct get_conven gc; DPL_TRACE(ctx, DPL_TRACE_BACKEND, ""); memset(&gc, 0, sizeof (gc)); gc.metadata = dpl_dict_new(13); if (NULL == gc.metadata) { ret = DPL_ENOMEM; goto end; } gc.sysmdp = sysmdp; gc.metadatum_func = metadatum_func; gc.buffer_func = buffer_func; gc.cb_arg = cb_arg; snprintf(path, sizeof (path), "/%s/%s", ctx->base_path ? ctx->base_path : "", resource); switch (object_type) { case DPL_FTYPE_UNDEF: case DPL_FTYPE_CAP: case DPL_FTYPE_DOM: case DPL_FTYPE_DIR: case DPL_FTYPE_CHRDEV: case DPL_FTYPE_BLKDEV: case DPL_FTYPE_FIFO: case DPL_FTYPE_SOCKET: case DPL_FTYPE_SYMLINK: ret = DPL_EINVAL; goto end; case DPL_FTYPE_ANY: case DPL_FTYPE_REG: fd = open(path, O_RDONLY); if (-1 == fd) { perror("open"); ret = DPL_FAILURE; goto end; } break ; } if (range) { iret = lseek(fd, range->start, SEEK_SET); if (-1 == iret) { perror("lseek"); ret = DPL_FAILURE; goto end; } } ret2 = dpl_posix_head_raw(ctx, bucket, resource, subresource, option, object_type, condition, &all_mds, locationp); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } ret2 = dpl_dict_iterate(all_mds, cb_get_value, &gc); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } while (1) { cc = read(fd, buf, sizeof (buf)); if (-1 == cc) { perror("read"); ret = DPL_FAILURE; goto end; } ret2 = cb_get_buffer(&gc, buf, cc); if (DPL_SUCCESS != ret2) { ret = ret2; goto end; } if (0 == cc) break ; } if (NULL != metadatap) { *metadatap = gc.metadata; gc.metadata = NULL; } ret = DPL_SUCCESS; end: if (NULL != all_mds) dpl_dict_free(all_mds); if (NULL != gc.metadata) dpl_dict_free(gc.metadata); if (-1 == fd) close(fd); DPL_TRACE(ctx, DPL_TRACE_BACKEND, "ret=%d", ret); return ret; }