btrfs-progs: free-space-cache: Enhance free space cache free space check
[platform/upstream/btrfs-progs.git] / disk-io.c
index 3d8785d..76958ae 100644 (file)
--- a/disk-io.c
+++ b/disk-io.c
@@ -1212,7 +1212,7 @@ struct btrfs_fs_info *open_ctree_fs_info(const char *filename,
 
        ret = stat(filename, &st);
        if (ret < 0) {
-               error("cannot stat '%s': %s", filename, strerror(errno));
+               error("cannot stat '%s': %m", filename);
                return NULL;
        }
        if (!(((st.st_mode & S_IFMT) == S_IFREG) || ((st.st_mode & S_IFMT) == S_IFBLK))) {
@@ -1225,7 +1225,7 @@ struct btrfs_fs_info *open_ctree_fs_info(const char *filename,
 
        fp = open(filename, oflags);
        if (fp < 0) {
-               error("cannot open '%s': %s", filename, strerror(errno));
+               error("cannot open '%s': %m", filename);
                return NULL;
        }
        info = __open_ctree_fd(fp, filename, sb_bytenr, root_tree_bytenr,
@@ -1419,6 +1419,23 @@ error_out:
        return -EIO;
 }
 
+/*
+ * btrfs_read_dev_super - read a valid superblock from a block device
+ * @fd:                file descriptor of the device
+ * @sb:                buffer where the superblock is going to be read in
+ * @sb_bytenr:  offset of the particular superblock copy we want
+ * @sbflags:   flags controlling how the superblock is read
+ *
+ * This function is used by various btrfs comands to obtain a valid superblock.
+ *
+ * It's mode of operation is controlled by the @sb_bytenr and @sbdflags
+ * parameters. If SBREAD_RECOVER flag is set and @sb_bytenr is
+ * BTRFS_SUPER_INFO_OFFSET then the function reads all 3 superblock copies and
+ * returns the newest one. If SBREAD_RECOVER is not set then only a single
+ * copy is read, which one is decided by @sb_bytenr. If @sb_bytenr !=
+ * BTRFS_SUPER_INFO_OFFSET then the @sbflags is effectively ignored and only a
+ * single copy is read.
+ */
 int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
                         unsigned sbflags)
 {
@@ -1549,8 +1566,7 @@ write_err:
        if (ret > 0)
                fprintf(stderr, "WARNING: failed to write all sb data\n");
        else
-               fprintf(stderr, "WARNING: failed to write sb: %s\n",
-                       strerror(errno));
+               fprintf(stderr, "WARNING: failed to write sb: %m\n");
        return ret;
 }