info->fd = file->fd;
info->logical_offset = doffset;
- while (args->length > 0) {
+ while (args->length > 0 || !*ops) {
error = ioctl(fd, XFS_IOC_FILE_EXTENT_SAME, args);
if (error) {
perror("XFS_IOC_FILE_EXTENT_SAME");
printf(_("Extents did not match.\n"));
goto done;
}
- if (info->bytes_deduped == 0 ||
- info->bytes_deduped > args->length)
+ if (args->length != 0 &&
+ (info->bytes_deduped == 0 ||
+ info->bytes_deduped > args->length))
break;
(*ops)++;
args->logical_offset += info->bytes_deduped;
info->logical_offset += info->bytes_deduped;
- args->length -= info->bytes_deduped;
+ if (args->length >= info->bytes_deduped)
+ args->length -= info->bytes_deduped;
deduped += info->bytes_deduped;
}
done:
}
optind++;
count = cvtnum(fsblocksize, fssectsize, argv[optind]);
- if (count < 1) {
+ if (count < 0) {
printf(_("non-positive length argument -- %s\n"), argv[optind]);
return 0;
}
struct xfs_clone_args args;
int error;
- if (len) {
+ if (soffset == 0 && doffset == 0 && len == 0) {
+ error = ioctl(file->fd, XFS_IOC_CLONE, fd);
+ if (error)
+ perror("XFS_IOC_CLONE");
+ } else {
args.src_fd = fd;
args.src_offset = soffset;
args.src_length = len;
error = ioctl(file->fd, XFS_IOC_CLONE_RANGE, &args);
if (error)
perror("XFS_IOC_CLONE_RANGE");
- } else {
- error = ioctl(file->fd, XFS_IOC_CLONE, fd);
- if (error)
- perror("XFS_IOC_CLONE");
}
if (!error)
(*ops)++;
}
optind++;
count = cvtnum(fsblocksize, fssectsize, argv[optind]);
- if (count < 1) {
+ if (count < 0) {
printf(_("non-positive length argument -- %s\n"), argv[optind]);
return 0;
}