lkml.org 
[lkml]   [2006]   [Jun]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[Suspend2][ 09/35] [Suspend2] Get filewriter target info.
Date
Given the name of a target (eg /dev/hda3, /my-suspend-file, /dev/ttyS0),
attempt to access it and discover the properties (inode, block size, dev_t,
first block, storage available) we need to work with it.

Signed-off-by: Nigel Cunningham <nigel@suspend2.net>

kernel/power/suspend_file.c | 87 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/kernel/power/suspend_file.c b/kernel/power/suspend_file.c
index 7e06a06..6851977 100644
--- a/kernel/power/suspend_file.c
+++ b/kernel/power/suspend_file.c
@@ -278,3 +278,90 @@ static void reopen_resume_devt(void)
set_devinfo(filewriter_target_bdev, target_inode->i_blkbits);
}

+static void filewriter_get_target_info(char *target, int get_size,
+ int resume2)
+{
+ if (target_file)
+ filewriter_cleanup(0);
+
+ if (!target || !strlen(target))
+ return;
+
+ target_file = filp_open(target, O_RDWR, 0);
+
+ if (IS_ERR(target_file) || !target_file) {
+
+ if (!resume2) {
+ printk("Open file %s returned %p.\n",
+ target, target_file);
+ target_file = NULL;
+ return;
+ }
+
+ target_file = NULL;
+ resume_dev_t = name_to_dev_t(target);
+ if (!resume_dev_t) {
+ printk("Open file %s returned %p and name_to_devt "
+ "failed.\n",
+ target, target_file);
+ if (!resume_dev_t) {
+ struct kstat stat;
+ int error = vfs_stat(target, &stat);
+ if (error) {
+ printk("Stating the file also failed."
+ " Nothing more we can do.\n");
+ return;
+ }
+ resume_dev_t = stat.rdev;
+ }
+ return;
+ }
+ filewriter_target_bdev = open_by_devnum(resume_dev_t, FMODE_READ);
+ if (IS_ERR(filewriter_target_bdev)) {
+ printk("Got a dev_num (%lx) but failed to open it.\n",
+ (unsigned long) resume_dev_t);
+ return;
+ }
+ used_devt = 1;
+ target_inode = filewriter_target_bdev->bd_inode;
+ } else
+ target_inode = target_file->f_mapping->host;
+
+ if (S_ISLNK(target_inode->i_mode) ||
+ S_ISDIR(target_inode->i_mode) ||
+ S_ISSOCK(target_inode->i_mode) ||
+ S_ISFIFO(target_inode->i_mode)) {
+ printk("The filewriter works with regular files, character "
+ "files and block devices.\n");
+ goto cleanup;
+ }
+
+ if (!used_devt) {
+ if (S_ISBLK(target_inode->i_mode)) {
+ filewriter_target_bdev = I_BDEV(target_inode);
+ if (!bd_claim(filewriter_target_bdev, &filewriterops))
+ target_claim = 1;
+ } else
+ filewriter_target_bdev = target_inode->i_sb->s_bdev;
+ resume_dev_t = filewriter_target_bdev->bd_dev;
+ }
+
+ set_devinfo(filewriter_target_bdev, target_inode->i_blkbits);
+
+ if (get_size)
+ target_storage_available = size_ignoring_ignored_pages();
+
+ if (!resume2)
+ target_firstblock = bmap(target_inode, 0) << devinfo.bmap_shift;
+
+ return;
+cleanup:
+ target_inode = NULL;
+ if (target_file) {
+ filp_close(target_file, NULL);
+ target_file = NULL;
+ }
+ set_devinfo(NULL, 0);
+ target_storage_available = 0;
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-06-27 00:42    [W:0.125 / U:0.356 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site