| 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 | |
|---|
| 18 | int 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_credential *cred; |
|---|
| 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 | cred = PVFS_util_gen_fake_credential(); |
|---|
| 63 | assert(cred); |
|---|
| 64 | |
|---|
| 65 | entry_name = str_buf; |
|---|
| 66 | attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; |
|---|
| 67 | attr.owner = cred->userid; |
|---|
| 68 | attr.group = cred->group_array[0]; |
|---|
| 69 | attr.perms = 1877; |
|---|
| 70 | attr.atime = attr.ctime = attr.mtime = |
|---|
| 71 | time(NULL); |
|---|
| 72 | |
|---|
| 73 | ret = PINT_lookup_parent(filename, cur_fs, cred, |
|---|
| 74 | &parent_refn.handle); |
|---|
| 75 | if(ret < 0) |
|---|
| 76 | { |
|---|
| 77 | PVFS_perror("PVFS_util_lookup_parent", ret); |
|---|
| 78 | return(-1); |
|---|
| 79 | } |
|---|
| 80 | parent_refn.fs_id = cur_fs; |
|---|
| 81 | |
|---|
| 82 | printf("File to be created is %s under parent %llu\n", |
|---|
| 83 | str_buf, llu(parent_refn.handle)); |
|---|
| 84 | |
|---|
| 85 | ret = PVFS_sys_create(entry_name, parent_refn, attr, |
|---|
| 86 | cred, NULL, NULL, &resp_create); |
|---|
| 87 | if (ret < 0) |
|---|
| 88 | { |
|---|
| 89 | PVFS_perror("create failed with errcode", ret); |
|---|
| 90 | return(-1); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | // print the handle |
|---|
| 94 | printf("--create--\n"); |
|---|
| 95 | printf("Handle: %lld\n",lld(resp_create.ref.handle)); |
|---|
| 96 | |
|---|
| 97 | ret = PVFS_sys_finalize(); |
|---|
| 98 | if (ret < 0) |
|---|
| 99 | { |
|---|
| 100 | printf("finalizing sysint failed with errcode = %d\n", ret); |
|---|
| 101 | return (-1); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | return(0); |
|---|
| 105 | } |
|---|