root/branches/windows-client/test/client/sysint/mkdir.c @ 8638

Revision 8638, 2.4 KB (checked in by sampson, 3 years ago)

Testing client

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