+int main(int argc, char **argv)
+{
+ struct lov_user_md *lum_dir, *lum_file1 = NULL, *lum_file2 = NULL;
+ struct obd_uuid uuid;
+ int lum_size, rc;
+ DIR *dir;
+
+ if (argc < 3) {
+ llapi_err_noerrno(LLAPI_MSG_ERROR,
+ "Usage: %s <dirname> <filename1> [filename2]\n",
+ argv[0]);
+ return 1;
+ }
+
+ dir = opendir(argv[1]);
+ if (dir == NULL) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: %s opendir failed", argv[1]);
+ return rc;
+ }
+
+ lum_size = lov_user_md_size(MAX_LOV_UUID_COUNT, LOV_USER_MAGIC);
+ lum_dir = (struct lov_user_md *)malloc(lum_size);
+ if (lum_dir == NULL) {
+ rc = -ENOMEM;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: can't allocate %d bytes "
+ "for dir EA", lum_size);
+ goto cleanup;
+ }
+
+ rc = llapi_file_get_stripe(argv[1], lum_dir);
+ if (rc == -ENODATA) {
+ char root[PATH_MAX], path[PATH_MAX + 2];
+
+ rc = llapi_search_mounts(argv[1], 0, root, NULL);
+ if (rc) {
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: can't get "
+ "root path for %s\n", argv[1]);
+ goto cleanup;
+ }
+
+ snprintf(path, sizeof(path), "%s/.", root);
+ rc = llapi_file_get_stripe(path, lum_dir);
+ if (rc == -ENODATA) {
+ free(lum_dir);
+ lum_dir = NULL;
+ } else if (rc) {
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: cant't get "
+ "root's LOVEA for %s\n", path);
+ goto cleanup;
+ }
+ } else if (rc) {
+ llapi_error(LLAPI_MSG_ERROR, rc, "error: can't get LOVEA for "
+ "%s", argv[1]);
+ goto cleanup;
+ }
+
+ /* XXX should be llapi_lov_getname() */
+ rc = llapi_file_get_lov_uuid(argv[1], &uuid);
+ if (rc) {
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: can't get lov name for %s",
+ argv[1]);
+ return rc;
+ }
+
+ lum_file1 = malloc(lum_size);
+ if (lum_file1 == NULL) {
+ rc = -ENOMEM;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: can't allocate %d bytes for EA",
+ lum_size);
+ goto cleanup;
+ }
+
+ rc = llapi_file_get_stripe(argv[2], lum_file1);
+ if (rc) {
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: unable to get EA for %s", argv[2]);
+ goto cleanup;
+ }
+
+ if (argc == 4) {
+ lum_file2 = (struct lov_user_md *)malloc(lum_size);
+ if (lum_file2 == NULL) {
+ rc = -ENOMEM;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: can't allocate %d "
+ "bytes for file2 EA", lum_size);
+ goto cleanup;
+ }
+
+ rc = llapi_file_get_stripe(argv[3], lum_file2);
+ if (rc) {
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "error: can't get EA for %s", argv[3]);
+ goto cleanup;
+ }
+ }
+
+ rc = compare_lum(&uuid, lum_dir, lum_file1, lum_file2);