| 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 | #include <sys/time.h> |
|---|
| 9 | #include <time.h> |
|---|
| 10 | #include <stdio.h> |
|---|
| 11 | #include <unistd.h> |
|---|
| 12 | #include <sys/types.h> |
|---|
| 13 | |
|---|
| 14 | #include "pvfs2-util.h" |
|---|
| 15 | #include "str-utils.h" |
|---|
| 16 | #include "pint-sysint-utils.h" |
|---|
| 17 | #include "pvfs2-internal.h" |
|---|
| 18 | |
|---|
| 19 | int main(int argc,char **argv) |
|---|
| 20 | { |
|---|
| 21 | int ret = -1; |
|---|
| 22 | char *dirname = (char *)0; |
|---|
| 23 | char str_buf[256] = {0}; |
|---|
| 24 | char str_buf2[256] = {0}; |
|---|
| 25 | char str_buf3[256] = {0}; |
|---|
| 26 | PVFS_fs_id cur_fs; |
|---|
| 27 | PVFS_sysresp_mkdir resp_mkdir; |
|---|
| 28 | char* entry_name; |
|---|
| 29 | PVFS_object_ref parent_refn; |
|---|
| 30 | PVFS_sys_attr attr; |
|---|
| 31 | PVFS_credentials credentials; |
|---|
| 32 | |
|---|
| 33 | if (argc != 2) |
|---|
| 34 | { |
|---|
| 35 | fprintf(stderr,"Usage: %s dirname\n",argv[0]); |
|---|
| 36 | return ret; |
|---|
| 37 | } |
|---|
| 38 | dirname = argv[1]; |
|---|
| 39 | |
|---|
| 40 | ret = PVFS_util_init_defaults(); |
|---|
| 41 | if (ret < 0) |
|---|
| 42 | { |
|---|
| 43 | PVFS_perror("PVFS_util_init_defaults", ret); |
|---|
| 44 | return (-1); |
|---|
| 45 | } |
|---|
| 46 | ret = PVFS_util_get_default_fsid(&cur_fs); |
|---|
| 47 | if (ret < 0) |
|---|
| 48 | { |
|---|
| 49 | PVFS_perror("PVFS_util_get_default_fsid", ret); |
|---|
| 50 | return (-1); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | if (PINT_remove_base_dir(dirname,str_buf,256)) |
|---|
| 54 | { |
|---|
| 55 | if (dirname[0] != '/') |
|---|
| 56 | { |
|---|
| 57 | printf("You forgot the leading '/'\n"); |
|---|
| 58 | } |
|---|
| 59 | printf("Cannot retrieve dir name for creation on %s\n", |
|---|
| 60 | dirname); |
|---|
| 61 | return(-1); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | snprintf(str_buf2, 256, "%s-%d", str_buf, 1); |
|---|
| 65 | snprintf(str_buf3, 256, "%s-%d", str_buf, 2); |
|---|
| 66 | printf("Directories to be created are %s and %s and %s\n", |
|---|
| 67 | str_buf, str_buf2, str_buf3); |
|---|
| 68 | |
|---|
| 69 | memset(&resp_mkdir, 0, sizeof(PVFS_sysresp_mkdir)); |
|---|
| 70 | PVFS_util_gen_credentials(&credentials); |
|---|
| 71 | |
|---|
| 72 | entry_name = str_buf; |
|---|
| 73 | ret = PINT_lookup_parent(dirname, cur_fs, &credentials, |
|---|
| 74 | &parent_refn.handle); |
|---|
| 75 | if(ret < 0) |
|---|
| 76 | { |
|---|
| 77 | PVFS_perror("PVFS_util_lookup_parent", ret); |
|---|
| 78 | return(-1); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | parent_refn.fs_id = cur_fs; |
|---|
| 82 | attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; |
|---|
| 83 | attr.owner = credentials.uid; |
|---|
| 84 | attr.group = credentials.gid; |
|---|
| 85 | attr.perms = 0777; |
|---|
| 86 | attr.atime = attr.ctime = attr.mtime = time(NULL); |
|---|
| 87 | |
|---|
| 88 | ret = PVFS_sys_mkdir(entry_name, parent_refn, attr, |
|---|
| 89 | &credentials, &resp_mkdir, NULL); |
|---|
| 90 | if (ret < 0) |
|---|
| 91 | { |
|---|
| 92 | printf("mkdir failed\n"); |
|---|
| 93 | return(-1); |
|---|
| 94 | } |
|---|
| 95 | // print the handle |
|---|
| 96 | printf("--mkdir--\n"); |
|---|
| 97 | printf("Handle:%s\n",PVFS_handle_to_str(resp_mkdir.ref.handle)); |
|---|
| 98 | printf("FSID:%d\n",parent_refn.fs_id); |
|---|
| 99 | |
|---|
| 100 | ret = PVFS_sys_mkdir(str_buf2, resp_mkdir.ref, attr, |
|---|
| 101 | &credentials, &resp_mkdir, NULL); |
|---|
| 102 | if (ret < 0) |
|---|
| 103 | { |
|---|
| 104 | printf("mkdir failed\n"); |
|---|
| 105 | return(-1); |
|---|
| 106 | } |
|---|
| 107 | // print the handle |
|---|
| 108 | printf("--mkdir--\n"); |
|---|
| 109 | printf("Handle:%s\n",PVFS_handle_to_str(resp_mkdir.ref.handle)); |
|---|
| 110 | printf("FSID:%d\n",parent_refn.fs_id); |
|---|
| 111 | |
|---|
| 112 | ret = PVFS_sys_mkdir(str_buf3, resp_mkdir.ref, attr, |
|---|
| 113 | &credentials, &resp_mkdir, NULL); |
|---|
| 114 | if (ret < 0) |
|---|
| 115 | { |
|---|
| 116 | printf("mkdir failed\n"); |
|---|
| 117 | return(-1); |
|---|
| 118 | } |
|---|
| 119 | // print the handle |
|---|
| 120 | printf("--mkdir--\n"); |
|---|
| 121 | printf("Handle:%s\n",PVFS_handle_to_str(resp_mkdir.ref.handle)); |
|---|
| 122 | printf("FSID:%d\n",parent_refn.fs_id); |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | //close it down |
|---|
| 126 | ret = PVFS_sys_finalize(); |
|---|
| 127 | if (ret < 0) |
|---|
| 128 | { |
|---|
| 129 | printf("finalizing sysint failed with errcode = %d\n", ret); |
|---|
| 130 | return (-1); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | return(0); |
|---|
| 134 | } |
|---|