Whamcloud - gitweb
Land b_smallfix onto HEAD (20040512_1806)
[fs/lustre-release.git] / lustre / tests / copy_attr.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4 #include <stdio.h>
5 #include <liblustre.h>
6 #include <linux/lustre_lib.h>
7 #include <linux/lustre_idl.h>
8 #include <linux/lustre_mds.h>
9 #include <sys/types.h>
10 #include <attr/xattr.h>
11
12 #define XATTR_LUSTRE_MDS_OBJID          "trusted.lov"
13
14 int
15 main(int argc, char *argv[])
16 {
17         struct lov_user_md *lmm1,*lmm2;
18         int size;
19         struct stat statbuf;
20
21         if (argc != 3) {
22                 fprintf(stderr,"usage: copy_attr file1 file2 \n");
23                 exit(1);
24         }
25
26         size = getxattr(argv[1], XATTR_LUSTRE_MDS_OBJID, NULL, 0);
27         if (size < 0) {
28                 perror("getting attr size");
29                 exit(1);
30         }
31         lmm1 = malloc(size);
32         lmm2 = malloc(size);
33         if (lmm1 == NULL || lmm2 == NULL) {
34                 fprintf(stderr,"Failure to get memory \n");
35                 exit(1);
36         }
37
38         if (getxattr(argv[1], XATTR_LUSTRE_MDS_OBJID, lmm1, size) < 0) {
39                 perror("getting xattr :");
40                 exit(1);
41         }
42
43         if (stat(argv[2], &statbuf)) {
44                 perror("stat");
45                 exit(1);
46         }
47
48         memcpy(lmm2, lmm1, size);
49         lmm2->lmm_object_id = statbuf.st_ino;
50         if (setxattr(argv[2], XATTR_LUSTRE_MDS_OBJID, lmm2, size, 0) < 0) {
51                 perror("setxattr");
52                 exit(1);
53         }
54
55         exit(0);
56 }