Hi, I think we agree that it would be nice for s2both to have the same commandline options as s2ram. Well, here is a patch;) A few comments:
The logic I choose for s2both is to continue with suspend-to-disk
in case of an error in the s2ram part. Even if the problem is with cli
options. This is how it was until know...
To minimize duplication, I moved some things around in s2ram. Only
the option string is duplicated now. We could of course do a
s2ram_get_optstring function...
I changed the short option for s2both/s2disk --config,
which currently is -f to -c, so we can use -f for --force. This of
course breaks stefan his scripts;)
I could add `force' to the flags,
#define S2RAM_FORCE 0x8000
flags |= S2RAM_FORCE;
etc. Seems cleaner, but maybe you don't like it...
Index: s2ram.c
===================================================================
RCS file: /cvsroot/suspend/suspend/s2ram.c,v
retrieving revision 1.51
diff -u -r1.51 s2ram.c
--- s2ram.c 16 Mar 2007 15:03:08 -0000 1.51
+++ s2ram.c 27 Mar 2007 12:18:20 -0000
@@ -25,7 +25,7 @@
static struct pci_dev vga_dev;
static struct pci_access *pacc;
/* Flags set from whitelist */
-static int flags, vbe_mode = -1;
+static int flags = 0, force = 0, vbe_mode = -1;
char bios_version[1024], sys_vendor[1024], sys_product[1024],
sys_version[1024];
/* return codes for s2ram_prepare */
@@ -229,18 +229,21 @@
return 0;
}
-int s2ram_prepare(void)
+int s2ram_prepare(void)
{
- int ret, id;
+ int ret = 0, id;
- dmi_scan();
- id = machine_match();
- ret = s2ram_check(id);
-
- if (ret)
- return ret;
+ if (flags && !force) {
+ printf("acpi_sleep, vbe_save, vbe_post and radeontool parameter
"
+ "must be used with --force\n\n");
+ return EINVAL;
+ }
- ret = s2ram_hacks();
+ if (!force) {
+ dmi_scan();
+ id = machine_match();
+ ret = s2ram_check(id);
+ }
return ret;
}
@@ -299,6 +302,33 @@
}
}
+void s2ram_add_flag(int opt, const char *opt_arg)
+{
+ switch (opt) {
+ case 's':
+ flags |= VBE_SAVE;
+ break;
+ case 'p':
+ flags |= VBE_POST;
+ break;
+ case 'm':
+ flags |= VBE_MODE;
+ break;
+ case 'r':
+ flags |= RADEON_OFF;
+ break;
+ case 'a':
+ flags |= (atoi(optarg) & (S3_BIOS | S3_MODE));
+ break;
+ case 'v':
+ flags |= PCI_SAVE;
+ break;
+ case 'f':
+ force = 1;
+ break;
+ }
+}
+
#ifndef CONFIG_BOTH
static void usage(void)
{
@@ -328,7 +358,7 @@
int main(int argc, char *argv[])
{
- int i, id = -1, ret = 0, test_mode = 0, force = 0;
+ int i, id = -1, ret = 0, test_mode = 0;
int active_console = -1;
struct option options[] = {
{ "test", no_argument, NULL, 'n'},
@@ -356,48 +386,27 @@
case 'n':
test_mode = 1;
break;
- case 'f':
- force = 1;
- break;
- case 's':
- flags |= VBE_SAVE;
- break;
- case 'p':
- flags |= VBE_POST;
- break;
- case 'm':
- flags |= VBE_MODE;
- break;
- case 'r':
- flags |= RADEON_OFF;
- break;
- case 'a':
- flags |= (atoi(optarg) & (S3_BIOS | S3_MODE));
- break;
- case 'v':
- flags |= PCI_SAVE;
+ case '?':
+ usage();
break;
default:
- usage();
+ s2ram_add_flag(i,optarg);
break;
}
}
- if (flags && !force) {
- printf("acpi_sleep, vbe_save, vbe_post and radeontool parameter
"
- "must be used with --force\n\n");
- usage();
- }
+
if (force && test_mode) {
printf("force and test mode do not make sense together.\n\n");
usage();
}
- if (!force) {
- dmi_scan();
- id = machine_match();
- ret = s2ram_check(id);
+ if (test_mode) {
+ machine_known(id);
+ goto out;
}
+ ret = s2ram_prepare();
+
if (ret == S2RAM_UNKNOWN) {
printf("Machine is unknown.\n");
identify_machine();
@@ -407,11 +416,6 @@
if (ret == S2RAM_NOFB)
printf("This machine can only suspend without framebuffer.\n");
- if (test_mode) {
- machine_known(id);
- goto out;
- }
-
if (ret)
goto out;
Index: s2ram.h
===================================================================
RCS file: /cvsroot/suspend/suspend/s2ram.h,v
retrieving revision 1.4
diff -u -r1.4 s2ram.h
--- s2ram.h 28 Mar 2006 13:16:21 -0000 1.4
+++ s2ram.h 27 Mar 2007 12:18:20 -0000
@@ -18,3 +18,4 @@
int s2ram_prepare(void);
int s2ram_do(void);
void s2ram_resume(void);
+void s2ram_add_flag(int opt, const char *arg);
Index: suspend.c
===================================================================
RCS file: /cvsroot/suspend/suspend/suspend.c,v
retrieving revision 1.70
diff -u -r1.70 suspend.c
--- suspend.c 16 Mar 2007 16:02:22 -0000 1.70
+++ suspend.c 27 Mar 2007 12:18:21 -0000
@@ -1166,9 +1166,18 @@
{
static struct option options[] = {
{ "help", no_argument, NULL, 'h'},
- { "config", required_argument, NULL, 'f'},
+ { "config", required_argument, NULL, 'c'},
{ "image_size", required_argument, NULL, 's'},
{ "resume_offset", required_argument, NULL, 'o'},
+#ifdef CONFIG_BOTH
+ { "force", no_argument, NULL, 'f'},
+ { "vbe_save", no_argument, NULL, 's'},
+ { "vbe_post", no_argument, NULL, 'p'},
+ { "vbe_mode", no_argument, NULL, 'm'},
+ { "radeontool", no_argument, NULL, 'r'},
+ { "acpi_sleep", required_argument, NULL, 'a'},
+ { "pci_save", no_argument, NULL, 'v'},
+#endif
{ NULL, 0, NULL, 0 }
};
int i, error;
@@ -1177,13 +1186,18 @@
unsigned long long int off = 0;
int set_size = 0;
unsigned long int im_size = 0;
+#ifdef CONFIG_BOTH
+ const char *optstring = "hc:s:o:";
+#else
+ const char *optstring = "hc:s:o:fspmra:v";
+#endif
- while ((i = getopt_long(argc, argv, "hf:s:o:", options, NULL)) != -1) {
+ while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) {
switch (i) {
case 'h':
usage("suspend", options);
exit(0);
- case 'f':
+ case 'c':
conf_name = optarg;
break;
case 's':
@@ -1194,9 +1208,14 @@
off = atoll(optarg);
set_off = 1;
break;
- default:
+ case '?':
usage("suspend", options);
return -EINVAL;
+#ifdef CONFIG_BOTH
+ default:
+ s2ram_add_flag(i, optarg);
+ break;
+#endif
}
}
error = parse("suspend", conf_name, PARAM_NO, parameters);
@@ -1385,8 +1404,11 @@
splash.progress(5);
#ifdef CONFIG_BOTH
- /* If s2ram_prepare returns != 0, better not try to suspend to RAM */
+ /* If s2ram_prepare or s2ram_hacks returns != 0, better not try to
+ * suspend to RAM */
s2ram = !s2ram_prepare();
+ if (s2ram)
+ s2ram = !s2ram_hacks();
#endif
#ifdef CONFIG_ENCRYPT
if (encrypt && ! use_RSA) {
signature.asc
Description: PGP signature
------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________ Suspend-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/suspend-devel
