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

Revision 8994, 4.1 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 <stdio.h>
8#include <stdlib.h>
9#include <time.h>
10#include <unistd.h>
11#include <sys/types.h>
12
13#include "client.h"
14#include "pvfs2-util.h"
15#include "pvfs2-internal.h"
16
17int main(int argc, char **argv)
18{
19    int ret = -1;
20    char *filename = NULL;
21    PVFS_fs_id fs_id;
22    PVFS_credentials credentials;
23    PVFS_sysresp_lookup resp_look;
24    PVFS_sysresp_getattr resp_getattr;
25    PVFS_object_ref pinode_refn;
26    time_t r_atime, r_mtime, r_ctime;
27
28    if (argc == 2)
29    {
30        filename = argv[1];
31    }
32    else
33    {
34        fprintf(stderr, "usage: %s /file_to_set_info_on\n", argv[0]);
35        return ret;
36    }
37
38    ret = PVFS_util_init_defaults();
39    if (ret < 0)
40    {
41        PVFS_perror("PVFS_util_init_defaults", ret);
42        return (-1);
43    }
44    ret = PVFS_util_get_default_fsid(&fs_id);
45    if (ret < 0)
46    {
47        PVFS_perror("PVFS_util_get_default_fsid", ret);
48        return (-1);
49    }
50
51    PVFS_util_gen_credentials(&credentials);
52
53    printf("about to lookup %s\n", filename);
54
55    ret = PVFS_sys_lookup(fs_id, filename, &credentials,
56                          &resp_look, PVFS2_LOOKUP_LINK_NO_FOLLOW, NULL);
57    if (ret < 0)
58    {
59        fprintf(stderr, "Lookup failed with errcode = %d\n", ret);
60        return ret;
61    }
62
63    pinode_refn.handle = resp_look.ref.handle;
64    pinode_refn.fs_id = fs_id;
65
66    printf("about to getattr on %s\n", filename);
67
68    ret = PVFS_sys_getattr(pinode_refn, PVFS_ATTR_SYS_ALL_SETABLE,
69                           &credentials, &resp_getattr, NULL);
70    if (ret < 0)
71    {
72        printf("getattr failed with errcode = %d\n", ret);
73        return ret;
74    }
75
76    r_atime = (time_t)resp_getattr.attr.atime;
77    r_mtime = (time_t)resp_getattr.attr.mtime;
78    r_ctime = (time_t)resp_getattr.attr.ctime;
79
80    printf("Retrieved the following attributes\n");
81    printf("Handle      : %s\n", PVFS_handle_to_str(pinode_refn.handle));
82    printf("FSID        : %d\n", (int)pinode_refn.fs_id);
83    printf("mask        : %d\n", resp_getattr.attr.mask);
84    printf("uid         : %d\n", resp_getattr.attr.owner);
85    printf("gid         : %d\n", resp_getattr.attr.group);
86    printf("permissions : %d\n", resp_getattr.attr.perms);
87    printf("atime       : %s", ctime(&r_atime));
88    printf("mtime       : %s", ctime(&r_mtime));
89    printf("ctime       : %s", ctime(&r_ctime));
90
91    /* take the retrieved attributes and update the modification time */
92    resp_getattr.attr.mtime = time(NULL);
93    resp_getattr.attr.mask &= ~PVFS_ATTR_SYS_TYPE;
94    /*
95      explicitly set the PVFS_ATTR_COMMON_ATIME, since we
96      want to update the atime field in particular
97    */
98    resp_getattr.attr.mask |= PVFS_ATTR_SYS_ATIME;
99
100    /* use stored credentials here */
101    credentials.uid = resp_getattr.attr.owner;
102    credentials.gid = resp_getattr.attr.group;
103
104    printf("about to setattr on %s\n", filename);
105
106    ret = PVFS_sys_setattr(pinode_refn, resp_getattr.attr, &credentials, NULL);
107    if (ret < 0)
108    {
109        fprintf(stderr, "setattr failed with errcode = %d\n", ret);
110        return ret;
111    }
112    else
113    {
114        printf("setattr returned success\n");
115
116        r_atime = (time_t)resp_getattr.attr.atime;
117        r_mtime = (time_t)resp_getattr.attr.mtime;
118        r_ctime = (time_t)resp_getattr.attr.ctime;
119
120        printf("Set the following attributes\n");
121        printf("Handle      : %llu\n", llu(pinode_refn.handle));
122        printf("FSID        : %d\n", (int)pinode_refn.fs_id);
123        printf("mask        : %d\n", resp_getattr.attr.mask);
124        printf("uid         : %d\n", resp_getattr.attr.owner);
125        printf("gid         : %d\n", resp_getattr.attr.group);
126        printf("permissions : %d\n", resp_getattr.attr.perms);
127        printf("atime       : %s", ctime(&r_atime));
128        printf("mtime       : %s", ctime(&r_mtime));
129        printf("ctime       : %s", ctime(&r_ctime));
130    }
131
132    ret = PVFS_sys_finalize();
133    if (ret < 0)
134    {
135        fprintf(stderr, "finalizing sysint failed with errcode = %d\n", ret);
136        return ret;
137    }
138
139    return 0;
140}
141
142/*
143 * Local variables:
144 *  c-indent-level: 4
145 *  c-basic-offset: 4
146 * End:
147 *
148 * vim: ts=8 sts=4 sw=4 expandtab
149 */
Note: See TracBrowser for help on using the browser.