Commit:     af508b34d27e3341287d89e0eae6752fdb1b873f
Parent:     aa6299926950c8dfe2fea638276cad6def092bc9
Author:     Rafael J. Wysocki <[EMAIL PROTECTED]>
AuthorDate: Fri Oct 26 00:59:31 2007 +0200
Committer:  Len Brown <[EMAIL PROTECTED]>
CommitDate: Fri Feb 1 18:30:52 2008 -0500

    Hibernation: Introduce SNAPSHOT_GET_IMAGE_SIZE ioctl
    Add a new ioctl, SNAPSHOT_GET_IMAGE_SIZE, returning the size of the (just
    created) hibernation image, to the hibernation userland interface.
    This ioctl is necessary so that the userland utilities using the interface 
    not access the hibernation image header, owned by the kernel, in order to 
    the size of the image.
    Signed-off-by: Rafael J. Wysocki <[EMAIL PROTECTED]>
    Acked-by: Pavel Machek <[EMAIL PROTECTED]>
    Signed-off-by: Len Brown <[EMAIL PROTECTED]>
 Documentation/power/userland-swsusp.txt |   12 +++++-------
 kernel/power/power.h                    |    4 +++-
 kernel/power/snapshot.c                 |    7 ++++++-
 kernel/power/user.c                     |   18 ++++++++++++++----
 4 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/Documentation/power/userland-swsusp.txt 
index e00c6cf..32f1874 100644
--- a/Documentation/power/userland-swsusp.txt
+++ b/Documentation/power/userland-swsusp.txt
@@ -54,6 +54,8 @@ SNAPSHOT_SET_IMAGE_SIZE - set the preferred maximum size of 
the image
        this number, but if it turns out to be impossible, the kernel will
        create the smallest image possible)
+SNAPSHOT_GET_IMAGE_SIZE - return the actual size of the hibernation image
 SNAPSHOT_AVAIL_SWAP - return the amount of available swap in bytes (the last
        argument should be a pointer to an unsigned int variable that will
        contain the result if the call is successful).
@@ -136,13 +138,9 @@ required, as they can use, for example, a special (blank) 
suspend partition or
 a file on a partition that is unmounted before SNAPSHOT_ATOMIC_SNAPSHOT and
 mounted afterwards.
-These utilities SHOULD NOT make any assumptions regarding the ordering of
-data within the snapshot image, except for the image header that MAY be
-assumed to start with an swsusp_info structure, as specified in
-kernel/power/power.h.  This structure MAY be used by the userland utilities
-to obtain some information about the snapshot image, such as the size
-of the snapshot image, including the metadata and the header itself,
-contained in the .size member of swsusp_info.
+These utilities MUST NOT make any assumptions regarding the ordering of
+data within the snapshot image.  The contents of the image are entirely owned
+by the kernel and its structure may be changed in future kernel releases.
 The snapshot image MUST be written to the kernel unaltered (ie. all of the 
 data, metadata and header MUST be written in _exactly_ the same amount, form
diff --git a/kernel/power/power.h b/kernel/power/power.h
index 2093c3a..23c1703 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -128,6 +128,7 @@ struct snapshot_handle {
 #define data_of(handle)        ((handle).buffer + (handle).buf_offset)
 extern unsigned int snapshot_additional_pages(struct zone *zone);
+extern unsigned long snapshot_get_image_size(void);
 extern int snapshot_read_next(struct snapshot_handle *handle, size_t count);
 extern int snapshot_write_next(struct snapshot_handle *handle, size_t count);
 extern void snapshot_write_finalize(struct snapshot_handle *handle);
@@ -158,7 +159,8 @@ struct resume_swap_area {
 #define SNAPSHOT_PMOPS                 _IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned 
                                                        struct resume_swap_area)
-#define SNAPSHOT_IOC_MAXNR     13
+#define SNAPSHOT_IOC_MAXNR     14
 #define PMOPS_PREPARE  1
 #define PMOPS_ENTER    2
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 78039b4..c5ce0f3 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -1264,12 +1264,17 @@ static char *check_image_kernel(struct swsusp_info 
+unsigned long snapshot_get_image_size(void)
+       return nr_copy_pages + nr_meta_pages + 1;
 static int init_header(struct swsusp_info *info)
        memset(info, 0, sizeof(struct swsusp_info));
        info->num_physpages = num_physpages;
        info->image_pages = nr_copy_pages;
-       info->pages = nr_copy_pages + nr_meta_pages + 1;
+       info->pages = snapshot_get_image_size();
        info->size = info->pages;
        info->size <<= PAGE_SHIFT;
        return init_header_complete(info);
diff --git a/kernel/power/user.c b/kernel/power/user.c
index 5bd321b..88aac26 100644
--- a/kernel/power/user.c
+++ b/kernel/power/user.c
@@ -133,7 +133,7 @@ static int snapshot_ioctl(struct inode *inode, struct file 
        int error = 0;
        struct snapshot_data *data;
-       loff_t avail;
+       loff_t size;
        sector_t offset;
        if (_IOC_TYPE(cmd) != SNAPSHOT_IOC_MAGIC)
@@ -210,10 +210,20 @@ static int snapshot_ioctl(struct inode *inode, struct 
file *filp,
                image_size = arg;
+               if (!data->ready) {
+                       error = -ENODATA;
+                       break;
+               }
+               size = snapshot_get_image_size();
+               size <<= PAGE_SHIFT;
+               error = put_user(size, (loff_t __user *)arg);
+               break;
-               avail = count_swap_pages(data->swap, 1);
-               avail <<= PAGE_SHIFT;
-               error = put_user(avail, (loff_t __user *)arg);
+               size = count_swap_pages(data->swap, 1);
+               size <<= PAGE_SHIFT;
+               error = put_user(size, (loff_t __user *)arg);
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at

Reply via email to