static int lookup_ino_path(int fd, struct root_info *ri)
{
struct btrfs_ioctl_ino_lookup_args args;
- int ret;
+ int ret, e;
if (ri->path)
return 0;
args.objectid = ri->dir_id;
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
+ e = errno;
if (ret) {
- fprintf(stderr, "ERROR: Failed to lookup path for root %llu\n",
- (unsigned long long)ri->ref_tree);
+ fprintf(stderr, "ERROR: Failed to lookup path for root %llu - %s\n",
+ (unsigned long long)ri->ref_tree,
+ strerror(e));
return ret;
}
unsigned long off = 0;
u64 max_found = 0;
int i;
+ int e;
memset(&ino_args, 0, sizeof(ino_args));
ino_args.objectid = BTRFS_FIRST_FREE_OBJECTID;
/* this ioctl fills in ino_args->treeid */
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &ino_args);
+ e = errno;
if (ret) {
- fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu\n",
- (unsigned long long)BTRFS_FIRST_FREE_OBJECTID);
+ fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu - %s\n",
+ (unsigned long long)BTRFS_FIRST_FREE_OBJECTID,
+ strerror(e));
return 0;
}
while (1) {
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
+ e = errno;
if (ret < 0) {
- fprintf(stderr, "ERROR: can't perform the search\n");
+ fprintf(stderr, "ERROR: can't perform the search - %s\n",
+ strerror(e));
return 0;
}
/* the ioctl returns the number of item it found in nr_items */
struct btrfs_ioctl_ino_lookup_args args;
int ret;
char *full;
+ int e;
memset(&args, 0, sizeof(args));
args.objectid = dirid;
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
+ e = errno;
if (ret) {
- fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu\n",
- (unsigned long long)dirid);
+ fprintf(stderr, "ERROR: Failed to lookup path for dirid %llu - %s\n",
+ (unsigned long long)dirid, strerror(e) );
return ERR_PTR(ret);
}
struct btrfs_ioctl_search_header *sh;
unsigned long off = 0;
int namelen;
+ int e;
memset(&args, 0, sizeof(args));
sk->nr_items = 1;
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
+ e = errno;
if (ret < 0) {
- fprintf(stderr, "ERROR: can't perform the search\n");
+ fprintf(stderr, "ERROR: can't perform the search - %s\n",
+ strerror(e));
return NULL;
}
/* the ioctl returns the number of item it found in nr_items */
char *name;
u64 dir_id;
int i;
+ int e;
root_lookup_init(&root_lookup);
while(1) {
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
+ e = errno;
if (ret < 0) {
- fprintf(stderr, "ERROR: can't perform the search\n");
+ fprintf(stderr, "ERROR: can't perform the search - %s\n",
+ strerror(e));
return ret;
}
/* the ioctl returns the number of item it found in nr_items */
u64 found_gen;
u64 max_found = 0;
int i;
+ int e;
u64 cache_dirid = 0;
u64 cache_ino = 0;
char *cache_dir_name = NULL;
max_found = find_root_gen(fd);
while(1) {
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
+ e = errno;
if (ret < 0) {
- fprintf(stderr, "ERROR: can't perform the search\n");
+ fprintf(stderr, "ERROR: can't perform the search- %s\n",
+ strerror(e));
return ret;
}
/* the ioctl returns the number of item it found in nr_items */
int verbose = 0;
int fancy_ioctl = 0;
struct btrfs_ioctl_defrag_range_args range;
+ int e=0;
optind = 1;
while(1) {
}
if (!fancy_ioctl) {
ret = ioctl(fd, BTRFS_IOC_DEFRAG, NULL);
+ e=errno;
} else {
ret = ioctl(fd, BTRFS_IOC_DEFRAG_RANGE, &range);
if (ret && errno == ENOTTY) {
- fprintf(stderr, "defrag range ioctl not "
+ fprintf(stderr, "ERROR: defrag range ioctl not "
"supported in this kernel, please try "
"without any options.\n");
errors++;
+ close(fd);
break;
}
}
if (ret) {
- fprintf(stderr, "ioctl failed on %s ret %d errno %d\n",
- av[i], ret, errno);
+ fprintf(stderr, "ERROR: defrag failed on %s - %s\n",
+ av[i], strerror(e));
errors++;
}
close(fd);
int do_clone(int argc, char **argv)
{
char *subvol, *dst;
- int res, fd, fddst, len;
+ int res, fd, fddst, len, e;
char *newname;
char *dstdir;
args.fd = fd;
strncpy(args.name, newname, BTRFS_PATH_NAME_MAX);
res = ioctl(fddst, BTRFS_IOC_SNAP_CREATE, &args);
+ e = errno;
close(fd);
close(fddst);
if(res < 0 ){
- fprintf( stderr, "ERROR: cannot snapshot '%s'\n",subvol);
+ fprintf( stderr, "ERROR: cannot snapshot '%s' - %s\n",
+ subvol, strerror(e));
return 11;
}
int do_delete_subvolume(int argc, char **argv)
{
- int res, fd, len;
+ int res, fd, len, e;
struct btrfs_ioctl_vol_args args;
char *dname, *vname, *cpath;
char *path = argv[1];
printf("Delete subvolume '%s/%s'\n", dname, vname);
strncpy(args.name, vname, BTRFS_PATH_NAME_MAX);
res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
+ e = errno;
close(fd);
if(res < 0 ){
- fprintf( stderr, "ERROR: cannot delete '%s/%s'\n",dname, vname);
+ fprintf( stderr, "ERROR: cannot delete '%s/%s' - %s\n",
+ dname, vname, strerror(e));
return 11;
}
int do_create_subvol(int argc, char **argv)
{
- int res, fddst, len;
+ int res, fddst, len, e;
char *newname;
char *dstdir;
struct btrfs_ioctl_vol_args args;
printf("Create subvolume '%s/%s'\n", dstdir, newname);
strncpy(args.name, newname, BTRFS_PATH_NAME_MAX);
res = ioctl(fddst, BTRFS_IOC_SUBVOL_CREATE, &args);
+ e = errno;
close(fddst);
if(res < 0 ){
- fprintf( stderr, "ERROR: cannot create subvolume\n");
+ fprintf( stderr, "ERROR: cannot create subvolume - %s\n",
+ strerror(e));
return 11;
}
int do_fssync(int argc, char **argv)
{
- int fd, res;
+ int fd, res, e;
char *path = argv[1];
fd = open_file_or_dir(path);
printf("FSSync '%s'\n", path);
res = ioctl(fd, BTRFS_IOC_SYNC);
+ e = errno;
close(fd);
if( res < 0 ){
- fprintf(stderr, "ERROR: unable to fs-syncing '%s'\n", path);
+ fprintf(stderr, "ERROR: unable to fs-syncing '%s' - %s\n",
+ path, strerror(e));
return 16;
}
int do_scan(int argc, char **argv)
{
- int i, fd;
+ int i, fd, e;
if(argc<=1){
int ret;
* a btrfs filesystem from an I/O error !!!
*/
ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
+ e = errno;
if( ret < 0 ){
close(fd);
- fprintf(stderr, "ERROR: unable to scan the device '%s'\n", argv[i]);
+ fprintf(stderr, "ERROR: unable to scan the device '%s' - %s\n",
+ argv[i], strerror(e));
return 11;
}
}
{
struct btrfs_ioctl_vol_args args;
- int fd, res, len;
+ int fd, res, len, e;
char *amount=argv[1], *path=argv[2];
fd = open_file_or_dir(path);
printf("Resize '%s' of '%s'\n", path, amount);
strncpy(args.name, amount, BTRFS_PATH_NAME_MAX);
res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
+ e = errno;
close(fd);
if( res < 0 ){
- fprintf(stderr, "ERROR: unable to resize '%s'\n", path);
+ fprintf(stderr, "ERROR: unable to resize '%s' - %s\n",
+ path, strerror(e));
return 30;
}
return 0;
{
char *mntpnt = args[nargs-1];
- int i, fdmnt, ret=0;
+ int i, fdmnt, ret=0, e;
fdmnt = open_file_or_dir(mntpnt);
strncpy(ioctl_args.name, args[i], BTRFS_PATH_NAME_MAX);
res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
+ e = errno;
if(res<0){
- fprintf(stderr, "ERROR: error adding the device '%s'\n", args[i]);
+ fprintf(stderr, "ERROR: error adding the device '%s' - %s\n",
+ args[i], strerror(e));
ret++;
}
int do_balance(int argc, char **argv)
{
- int fdmnt, ret=0;
+ int fdmnt, ret=0, e;
struct btrfs_ioctl_vol_args args;
char *path = argv[1];
memset(&args, 0, sizeof(args));
ret = ioctl(fdmnt, BTRFS_IOC_BALANCE, &args);
+ e = errno;
close(fdmnt);
if(ret<0){
- fprintf(stderr, "ERROR: balancing '%s'\n", path);
+ fprintf(stderr, "ERROR: error during balancing '%s' - %s\n",
+ path, strerror(e));
return 19;
}
{
char *mntpnt = args[nargs-1];
- int i, fdmnt, ret=0;
+ int i, fdmnt, ret=0, e;
fdmnt = open_file_or_dir(mntpnt);
if (fdmnt < 0) {
strncpy(arg.name, args[i], BTRFS_PATH_NAME_MAX);
res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
+ e = errno;
if(res<0){
- fprintf(stderr, "ERROR: error removing the device '%s'\n", args[i]);
+ fprintf(stderr, "ERROR: error removing the device '%s' - %s\n",
+ args[i], strerror(e));
ret++;
}
}
int do_set_default_subvol(int nargs, char **argv)
{
- int ret=0, fd;
+ int ret=0, fd, e;
u64 objectid;
char *path = argv[2];
char *subvolid = argv[1];
return 30;
}
ret = ioctl(fd, BTRFS_IOC_DEFAULT_SUBVOL, &objectid);
+ e = errno;
close(fd);
if( ret < 0 ){
- fprintf(stderr, "ERROR: unable to set a new default subvolume\n");
+ fprintf(stderr, "ERROR: unable to set a new default subvolume - %s\n",
+ strerror(e));
return 30;
}
return 0;
u64 count = 0, i;
int ret;
int fd;
+ int e;
char *path = argv[1];
fd = open_file_or_dir(path);
sargs->total_spaces = 0;
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
+ e = errno;
if (ret) {
+ fprintf(stderr, "ERROR: couldn't get space info on '%s' - %s\n",
+ path, strerror(e));
free(sargs);
return ret;
}
sargs->total_spaces = 0;
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
+ e = errno;
if (ret) {
+ fprintf(stderr, "ERROR: couldn't get space info on '%s' - %s\n",
+ path, strerror(e));
+ close(fd);
free(sargs);
return ret;
}