| 1 | /* |
|---|
| 2 | * (C) 2001 Clemson University and The University of Chicago |
|---|
| 3 | * |
|---|
| 4 | * See COPYING in top-level directory. |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | #include <assert.h> |
|---|
| 8 | #include <sys/time.h> |
|---|
| 9 | #include <stdio.h> |
|---|
| 10 | #include <stdlib.h> |
|---|
| 11 | #include <string.h> |
|---|
| 12 | #include <unistd.h> |
|---|
| 13 | #include <sys/types.h> |
|---|
| 14 | |
|---|
| 15 | #include "client.h" |
|---|
| 16 | #include "pvfs2-util.h" |
|---|
| 17 | #include "pvfs2-internal.h" |
|---|
| 18 | |
|---|
| 19 | void gen_rand_str(int len, char** gen_str); |
|---|
| 20 | |
|---|
| 21 | int main(int argc,char **argv) |
|---|
| 22 | { |
|---|
| 23 | int ret = -1; |
|---|
| 24 | int follow_link = PVFS2_LOOKUP_LINK_NO_FOLLOW; |
|---|
| 25 | PVFS_sysresp_lookup resp_lk; |
|---|
| 26 | PVFS_fs_id fs_id; |
|---|
| 27 | PVFS_credentials credentials; |
|---|
| 28 | char *filename = NULL; |
|---|
| 29 | |
|---|
| 30 | if (argc != 2) |
|---|
| 31 | { |
|---|
| 32 | if ((argc == 3) && (atoi(argv[2]) == 1)) |
|---|
| 33 | { |
|---|
| 34 | follow_link = PVFS2_LOOKUP_LINK_FOLLOW; |
|---|
| 35 | goto lookup_continue; |
|---|
| 36 | } |
|---|
| 37 | printf("USAGE: %s /path/to/lookup [ 1 ]\n", argv[0]); |
|---|
| 38 | printf(" -- if '1' is the last argument, links " |
|---|
| 39 | "will be followed\n"); |
|---|
| 40 | return 1; |
|---|
| 41 | } |
|---|
| 42 | lookup_continue: |
|---|
| 43 | |
|---|
| 44 | filename = argv[1]; |
|---|
| 45 | printf("lookup up path %s\n", filename); |
|---|
| 46 | |
|---|
| 47 | PVFS_util_gen_credentials(&credentials); |
|---|
| 48 | |
|---|
| 49 | ret = PVFS_util_init_defaults(); |
|---|
| 50 | if (ret < 0) |
|---|
| 51 | { |
|---|
| 52 | PVFS_perror("PVFS_util_init_defaults", ret); |
|---|
| 53 | return (-1); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | ret = PVFS_util_get_default_fsid(&fs_id); |
|---|
| 57 | if (ret < 0) |
|---|
| 58 | { |
|---|
| 59 | PVFS_perror("PVFS_util_get_default_fsid", ret); |
|---|
| 60 | return (-1); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | memset(&resp_lk,0,sizeof(PVFS_sysresp_lookup)); |
|---|
| 64 | |
|---|
| 65 | ret = PVFS_sys_lookup(fs_id, filename, &credentials, |
|---|
| 66 | &resp_lk, follow_link, NULL); |
|---|
| 67 | if (ret < 0) |
|---|
| 68 | { |
|---|
| 69 | printf("Lookup failed with errcode = %d\n", ret); |
|---|
| 70 | PVFS_perror("PVFS_perror says", ret); |
|---|
| 71 | return(-1); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | printf("Handle : %s\n", PVFS_handle_to_str(resp_lk.ref.handle)); |
|---|
| 75 | printf("FS ID : %d\n", resp_lk.ref.fs_id); |
|---|
| 76 | |
|---|
| 77 | ret = PVFS_sys_finalize(); |
|---|
| 78 | if (ret < 0) |
|---|
| 79 | { |
|---|
| 80 | printf("finalizing sysint failed with errcode = %d\n", ret); |
|---|
| 81 | return (-1); |
|---|
| 82 | } |
|---|
| 83 | return 0; |
|---|
| 84 | } |
|---|