Beispiel #1
0
/** 
 * PVFSIOStore::Symlink: create a symbolic link
 *
 * @param oldpath
 * @param newpath
 * @return PLFS_SUCCESS or PLFS_E* on error
 */
plfs_error_t PVFSIOStore::Symlink(const char* oldpath, const char* newpath) {
    int nev, pev;
    PVFS_object_ref ref;
    PVFS_credentials creds;
    char *node, *parent;
    PVFS_sys_attr attr;
    PVFS_sysresp_symlink resp;

    /* need parent dir of newpath */
    nev = pvfsios_get_node_and_parent(&this->fsid, newpath, &ref, &creds,
                                      &node, &parent);
    if (nev < 0) {
        return errno_to_plfs_error(-nev);
    }

    attr.owner = creds.uid;
    attr.group = creds.gid;
    attr.perms = 0777;
    attr.mask = PVFS_ATTR_SYS_ALL_SETABLE;
    memset(&resp, 0, sizeof(resp));
    pev = PVFS_sys_symlink(node, ref, (char *)oldpath, attr, &creds, &resp);
    nev = get_err(pev);

    free(parent);
    return errno_to_plfs_error(-nev);
}
Beispiel #2
0
int main(int argc, char **argv)
{
    int ret = -1;
    char str_buf[256] = {0};
    char *filename = (char *)0;
    PVFS_fs_id cur_fs;
    PVFS_sysresp_symlink resp_sym;
    char* entry_name = NULL;
    char *target = NULL;
    PVFS_object_ref parent_refn;
    PVFS_sys_attr attr;
    PVFS_credentials credentials;

    if (argc != 3)
    {
        fprintf(stderr,"Usage: %s filename target\n",argv[0]);
        return ret;
    }
    filename = argv[1];
    target = argv[2];

    ret = PVFS_util_init_defaults();
    if (ret < 0)
    {
	PVFS_perror("PVFS_util_init_defaults", ret);
	return (-1);
    }
    ret = PVFS_util_get_default_fsid(&cur_fs);
    if (ret < 0)
    {
	PVFS_perror("PVFS_util_get_default_fsid", ret);
	return (-1);
    }

    if (PINT_remove_base_dir(filename,str_buf,256))
    {
        if (filename[0] != '/')
        {
            printf("You forgot the leading '/'\n");
        }
        printf("Cannot retrieve link name for creation on %s\n",
               filename);
        return(-1);
    }
    printf("Link to be created is %s\n",str_buf);

    memset(&resp_sym, 0, sizeof(PVFS_sysresp_symlink));
    PVFS_util_gen_credentials(&credentials);

    entry_name = str_buf;
    attr.mask = PVFS_ATTR_SYS_ALL_SETABLE;
    attr.owner = credentials.uid;
    attr.group = credentials.gid;
    attr.perms = 1877;
    attr.atime = attr.ctime = attr.mtime = time(NULL);

    ret = PINT_lookup_parent(filename, cur_fs, &credentials, 
                             &parent_refn.handle);
    if(ret < 0)
    {
	PVFS_perror("PVFS_util_lookup_parent", ret);
	return(-1);
    }
    parent_refn.fs_id = cur_fs;

    ret = PVFS_sys_symlink(entry_name, parent_refn, target,
                           attr, &credentials, &resp_sym, NULL);
    if (ret < 0)
    {
        printf("symlink failed with errcode = %d\n", ret);
        return(-1);
    }
	
    printf("--symlink--\n"); 
    printf("Handle: %lld\n", lld(resp_sym.ref.handle));

    ret = PVFS_sys_finalize();
    if (ret < 0)
    {
        printf("finalizing sysint failed with errcode = %d\n", ret);
        return (-1);
    }

    return(0);
}