OPEN_CTREE_PARTIAL |
OPEN_CTREE_RESTORE);
if (!info) {
- int e = errno;
fprintf(stderr, "unable to open %s error = %s\n",
- target, strerror(e));
+ target, strerror(errno));
return 1;
}
static int lookup_ino_path(int fd, struct root_info *ri)
{
struct btrfs_ioctl_ino_lookup_args args;
- int ret, e;
+ int ret;
if (ri->path)
return 0;
args.objectid = ri->dir_id;
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
- e = errno;
if (ret) {
- if (e == ENOENT) {
+ if (errno == ENOENT) {
ri->ref_tree = 0;
return -ENOENT;
}
fprintf(stderr, "ERROR: Failed to lookup path for root %llu - %s\n",
(unsigned long long)ri->ref_tree,
- strerror(e));
+ strerror(errno));
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 - %s\n",
(unsigned long long)BTRFS_FIRST_FREE_OBJECTID,
- strerror(e));
+ strerror(errno));
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 - %s\n",
- strerror(e));
+ strerror(errno));
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 - %s\n",
- (unsigned long long)dirid, strerror(e) );
+ (unsigned long long)dirid, strerror(errno));
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 - %s\n",
- strerror(e));
+ strerror(errno));
return NULL;
}
/* 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 - %s\n",
- strerror(e));
+ strerror(errno));
break;
}
/* the ioctl returns the number of item it found in nr_items */
ret = pread64(fd, super_block_data, BTRFS_SUPER_INFO_SIZE, sb_bytenr);
if (ret != BTRFS_SUPER_INFO_SIZE) {
- int e = errno;
-
/* check if the disk if too short for further superblock */
- if (ret == 0 && e == 0)
+ if (ret == 0 && errno == 0)
return 0;
fprintf(stderr,
"ERROR: Failed to read the superblock on %s at %llu\n",
filename, (unsigned long long)sb_bytenr);
fprintf(stderr,
- "ERROR: error = '%s', errno = %d\n", strerror(e), e);
+ "ERROR: error = '%s', errno = %d\n", strerror(errno), errno);
return 1;
}
printf("superblock: bytenr=%llu, device=%s\n", sb_bytenr, filename);
static int cmd_device_add(int argc, char **argv)
{
char *mntpnt;
- int i, fdmnt, ret=0, e;
+ int i, fdmnt, ret = 0;
DIR *dirstream = NULL;
int discard = 1;
int force = 0;
memset(&ioctl_args, 0, sizeof(ioctl_args));
strncpy_null(ioctl_args.name, path);
res = ioctl(fdmnt, BTRFS_IOC_ADD_DEV, &ioctl_args);
- e = errno;
if (res < 0) {
error("error adding device '%s': %s",
- path, strerror(e));
+ path, strerror(errno));
ret++;
}
free(path);
const char * const *usagestr)
{
char *mntpnt;
- int i, fdmnt, ret=0, e;
+ int i, fdmnt, ret = 0;
DIR *dirstream = NULL;
if (check_argc_min(argc, 3))
memset(&arg, 0, sizeof(arg));
strncpy_null(arg.name, argv[i]);
res = ioctl(fdmnt, BTRFS_IOC_RM_DEV, &arg);
- e = errno;
if (res) {
const char *msg;
if (res > 0)
msg = btrfs_err_str(res);
else
- msg = strerror(e);
+ msg = strerror(errno);
error("error removing device '%s': %s",
argv[i], msg);
ret++;
static struct btrfs_ioctl_space_args *load_space_info(int fd, char *path)
{
struct btrfs_ioctl_space_args *sargs = NULL, *sargs_orig = NULL;
- int e, ret, count;
+ int ret, count;
sargs_orig = sargs = calloc(1, sizeof(struct btrfs_ioctl_space_args));
if (!sargs) {
sargs->total_spaces = 0;
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
- e = errno;
if (ret) {
- error("cannot get space info on '%s': %s", path, strerror(e));
+ error("cannot get space info on '%s': %s", path,
+ strerror(errno));
free(sargs);
return NULL;
}
sargs->total_spaces = 0;
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
- e = errno;
-
if (ret) {
error("cannot get space info with %u slots: %s",
- count, strerror(e));
+ count, strerror(errno));
free(sargs);
return NULL;
}
static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret)
{
u64 count = 0;
- int ret, e;
+ int ret;
struct btrfs_ioctl_space_args *sargs;
sargs = malloc(sizeof(struct btrfs_ioctl_space_args));
sargs->total_spaces = 0;
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
- e = errno;
if (ret) {
- error("cannot get space info: %s\n", strerror(e));
+ error("cannot get space info: %s\n", strerror(errno));
free(sargs);
- return -e;
+ return -errno;
}
/* This really should never happen */
if (!sargs->total_spaces) {
sargs->space_slots = count;
sargs->total_spaces = 0;
ret = ioctl(fd, BTRFS_IOC_SPACE_INFO, sargs);
- e = errno;
if (ret) {
error("cannot get space info with %llu slots: %s",
- count, strerror(e));
+ count, strerror(errno));
free(sargs);
- return -e;
+ return -errno;
}
*sargs_ret = sargs;
return 0;
if (defrag_global_verbose)
printf("%s\n", fpath);
fd = open(fpath, O_RDWR);
- e = errno;
if (fd < 0)
goto error;
ret = do_defrag(fd, defrag_global_fancy_ioctl, &defrag_global_range);
{
int ret = 0;
int fd;
- int e;
int rescan = 0;
char *path;
struct btrfs_ioctl_qgroup_assign_args args;
return 1;
ret = ioctl(fd, BTRFS_IOC_QGROUP_ASSIGN, &args);
- e = errno;
if (ret < 0) {
- error("unable to assign quota group: %s", strerror(e));
+ error("unable to assign quota group: %s", strerror(errno));
close_file_or_dir(fd, dirstream);
return 1;
}
len);
data_len = len;
- if (fsetxattr(fd, name, data, data_len, 0)) {
- int err = errno;
-
+ if (fsetxattr(fd, name, data, data_len, 0))
fprintf(stderr,
"Error setting extended attribute %s on file %s: %s\n",
- name, file_name, strerror(err));
- }
+ name, file_name, strerror(errno));
len = sizeof(*di) + name_len + data_len;
cur += len;
static int cmd_subvol_delete(int argc, char **argv)
{
- int res, e, ret = 0;
+ int res, ret = 0;
int cnt;
int fd = -1;
struct btrfs_ioctl_vol_args args;
memset(&args, 0, sizeof(args));
strncpy_null(args.name, vname);
res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args);
- e = errno;
-
if(res < 0 ){
- error("cannot delete '%s/%s': %s", dname, vname, strerror(e));
+ error("cannot delete '%s/%s': %s", dname, vname,
+ strerror(errno));
ret = 1;
goto out;
}
struct btrfs_ioctl_search_header *sh;
unsigned long off = 0;
unsigned int i;
- int e;
struct btrfs_qgroup_info_item *info;
struct btrfs_qgroup_limit_item *limit;
struct btrfs_qgroup *bq;
while (1) {
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
- e = errno;
if (ret < 0) {
fprintf(stderr,
"ERROR: can't perform the search - %s\n",
- strerror(e));
+ strerror(errno));
return ret;
}
/* the ioctl returns the number of item it found in nr_items */
int root_item_valid = 0;
unsigned long off = 0;
int i;
- int e;
char *path;
s->mnt_fd = mnt_fd;
while (1) {
ret = ioctl(mnt_fd, BTRFS_IOC_TREE_SEARCH, &args);
- e = errno;
if (ret < 0) {
fprintf(stderr, "ERROR: can't perform the search - %s\n",
- strerror(e));
+ strerror(errno));
return ret;
}
if (sk->nr_items == 0)
struct btrfs_ioctl_vol_args args;
int fd;
int ret;
- int e;
fd = open("/dev/btrfs-control", O_RDWR);
if (fd < 0) {
memset(&args, 0, sizeof(args));
strncpy_null(args.name, fname);
ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
- e = errno;
if (ret < 0) {
fprintf(stderr, "ERROR: device scan failed '%s' - %s\n",
- fname, strerror(e));
- ret = -e;
+ fname, strerror(errno));
+ ret = -errno;
}
close(fd);
return ret;
{
struct btrfs_ioctl_ino_lookup_args args;
int ret;
- int e;
memset(&args, 0, sizeof(args));
args.treeid = 0;
args.objectid = BTRFS_FIRST_FREE_OBJECTID;
ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args);
- e = errno;
if (ret) {
fprintf(stderr, "ERROR: Failed to lookup root id - %s\n",
- strerror(e));
+ strerror(errno));
return ret;
}