summaryrefslogtreecommitdiffstats
path: root/xlators/features/metadisp/src/backend.c
blob: ee2c25bfaa7394cb09ef4fc02009401b8f97b703 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#define GFID_STR_LEN 37

#include "metadisp.h"

/*
 * backend.c
 *
 * functions responsible for converting user-facing paths to backend-style
 * "/$GFID" paths.
 */

int32_t
build_backend_loc(uuid_t gfid, loc_t *src_loc, loc_t *dst_loc)
{
    static uuid_t root = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
    char gfid_buf[GFID_STR_LEN + 1] = {
        0,
    };
    char *path = NULL;

    GF_VALIDATE_OR_GOTO("metadisp", src_loc, out);
    GF_VALIDATE_OR_GOTO("metadisp", dst_loc, out);

    loc_copy(dst_loc, src_loc);
    memcpy(dst_loc->pargfid, root, sizeof(root));
    GF_FREE((char *)dst_loc->path);  // we are overwriting path so nuke
                                     // whatever loc_copy gave us

    uuid_utoa_r(gfid, gfid_buf);

    path = GF_CALLOC(GFID_STR_LEN + 1, sizeof(char),
                     gf_common_mt_char);  // freed via loc_wipe

    path[0] = '/';
    strncpy(path + 1, gfid_buf, GFID_STR_LEN);
    path[GFID_STR_LEN] = 0;
    dst_loc->path = path;
    if (src_loc->name)
        dst_loc->name = strrchr(dst_loc->path, '/');
    if (dst_loc->name)
        dst_loc->name++;
    return 0;
out:
    return -1;
}