root/branches/orange-next/test/client/sysint/create.c @ 8994

Revision 8994, 2.4 KB (checked in by dcypher, 22 months ago)

replaced %llu->%s for (PVFS|TROVE)_handle

Line 
1/*
2 * (C) 2001 Clemson University and The University of Chicago
3 *
4 * See COPYING in top-level directory.
5 */
6
7#include <time.h>
8#include <stdio.h>
9#include <unistd.h>
10#include <sys/types.h>
11
12#include "client.h"
13#include "pvfs2-util.h"
14#include "str-utils.h"
15#include "pint-sysint-utils.h"
16#include "pvfs2-internal.h"
17
18int main(int argc, char **argv)
19{
20    int ret = -1;
21    char str_buf[256] = {0};
22    char *filename = (char *)0;
23    PVFS_fs_id cur_fs;
24    PVFS_sysresp_create resp_create;
25    char* entry_name;
26    PVFS_object_ref parent_refn;
27    PVFS_sys_attr attr;
28    PVFS_credentials credentials;
29
30    if (argc != 2)
31    {
32        fprintf(stderr,"Usage: %s filename\n",argv[0]);
33        return ret;
34    }
35    filename = argv[1];
36
37    ret = PVFS_util_init_defaults();
38    if (ret < 0)
39    {
40        PVFS_perror("PVFS_util_init_defaults", ret);
41        return (-1);
42    }
43    ret = PVFS_util_get_default_fsid(&cur_fs);
44    if (ret < 0)
45    {
46        PVFS_perror("PVFS_util_get_default_fsid", ret);
47        return (-1);
48    }
49
50    if (PINT_remove_base_dir(filename,str_buf,256))
51    {
52        if (filename[0] != '/')
53        {
54            printf("You forgot the leading '/'\n");
55        }
56        printf("Cannot retrieve entry name for creation on %s\n",
57               filename);
58        return(-1);
59    }
60
61    memset(&resp_create, 0, sizeof(PVFS_sysresp_create));
62    PVFS_util_gen_credentials(&credentials);
63
64    entry_name = str_buf;
65    attr.mask = PVFS_ATTR_SYS_ALL_SETABLE;
66    attr.owner = credentials.uid;
67    attr.group = credentials.gid;
68    attr.perms = 1877;
69    attr.atime = attr.ctime = attr.mtime =
70        time(NULL);
71
72    ret = PINT_lookup_parent(filename, cur_fs, &credentials,
73                             &parent_refn.handle);
74    if(ret < 0)
75    {
76        PVFS_perror("PVFS_util_lookup_parent", ret);
77        return(-1);
78    }
79    parent_refn.fs_id = cur_fs;
80
81    printf("File to be created is %s under parent %s\n",
82           str_buf, PVFS_handle_to_str(parent_refn.handle));
83
84    ret = PVFS_sys_create(entry_name, parent_refn, attr,
85                          &credentials, NULL, &resp_create, NULL, NULL);
86    if (ret < 0)
87    {
88        PVFS_perror("create failed with errcode", ret);
89        return(-1);
90    }
91       
92    // print the handle
93    printf("--create--\n");
94    printf("Handle: %lld\n",lld(resp_create.ref.handle));
95
96    ret = PVFS_sys_finalize();
97    if (ret < 0)
98    {
99        printf("finalizing sysint failed with errcode = %d\n", ret);
100        return (-1);
101    }
102
103    return(0);
104}
Note: See TracBrowser for help on using the browser.