This commit is contained in:
parent
68e9047d04
commit
04659b2a46
@ -1,6 +1,16 @@
|
|||||||
--- src/hddown.c
|
--- src/hddown.c
|
||||||
+++ src/hddown.c 2007-06-05 14:37:50.248140535 +0200
|
+++ src/hddown.c 2007-06-06 15:42:04.799454093 +0200
|
||||||
@@ -18,6 +18,106 @@ char *v_hddown = "@(#)hddown.c 1.02 22
|
@@ -5,6 +5,9 @@
|
||||||
|
*/
|
||||||
|
char *v_hddown = "@(#)hddown.c 1.02 22-Apr-2003 miquels@cistron.nl";
|
||||||
|
|
||||||
|
+#ifndef _GNU_SOURCE
|
||||||
|
+#define _GNU_SOURCE
|
||||||
|
+#endif
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
@@ -18,6 +21,198 @@ char *v_hddown = "@(#)hddown.c 1.02 22
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <linux/hdreg.h>
|
#include <linux/hdreg.h>
|
||||||
|
|
||||||
@ -9,8 +19,13 @@
|
|||||||
+
|
+
|
||||||
+#include <limits.h>
|
+#include <limits.h>
|
||||||
+#include <errno.h>
|
+#include <errno.h>
|
||||||
|
+#include <sys/stat.h>
|
||||||
|
+#include <sys/types.h>
|
||||||
|
+
|
||||||
+#define SYS_BLK "/sys/block"
|
+#define SYS_BLK "/sys/block"
|
||||||
|
+#define SYS_CLASS "/sys/class/scsi_disk"
|
||||||
+#define DEV_BASE "/dev"
|
+#define DEV_BASE "/dev"
|
||||||
|
+#define ISSPACE(c) (((c)==' ')||((c)=='\n')||((c)=='\t')||((c)=='\v')||((c)=='\r')||((c)=='\f'))
|
||||||
+
|
+
|
||||||
+/*
|
+/*
|
||||||
+ * Find all disks through /sys/block.
|
+ * Find all disks through /sys/block.
|
||||||
@ -21,28 +36,102 @@
|
|||||||
+
|
+
|
||||||
+ while ((d = readdir(blk))) {
|
+ while ((d = readdir(blk))) {
|
||||||
+ if (d->d_name[1] == 'd' && (d->d_name[0] == 'h' || d->d_name[0] == 's')) {
|
+ if (d->d_name[1] == 'd' && (d->d_name[0] == 'h' || d->d_name[0] == 's')) {
|
||||||
+ char buf[NAME_MAX+1];
|
+ char buf[NAME_MAX+1], lnk[NAME_MAX+1], *ptr;
|
||||||
|
+ struct stat st;
|
||||||
+ int fd, ret;
|
+ int fd, ret;
|
||||||
|
+ size_t len;
|
||||||
+ FILE *fp;
|
+ FILE *fp;
|
||||||
+
|
+
|
||||||
+ ret = snprintf(buf, sizeof(buf), SYS_BLK "/%s/removable", d->d_name);
|
+ ret = snprintf(buf, sizeof(buf), SYS_BLK "/%s/removable", d->d_name);
|
||||||
+ if ((ret >= sizeof(buf)) || (ret < 0))
|
+ if ((ret >= sizeof(buf)) || (ret < 0))
|
||||||
+ goto empty;
|
+ goto empty; /* error */
|
||||||
+
|
+
|
||||||
+ fd = open(buf, O_RDONLY|O_NOCTTY);
|
+ fd = open(buf, O_RDONLY|O_NOCTTY);
|
||||||
+ if ((fd < 0) && (errno != ENOENT))
|
+ if (fd < 0) {
|
||||||
+ goto empty;
|
+ if (errno != ENOENT)
|
||||||
|
+ goto empty; /* error */
|
||||||
|
+ continue; /* no entry `removable' */
|
||||||
|
+ }
|
||||||
+
|
+
|
||||||
+ fp = fdopen(fd, "r");
|
+ fp = fdopen(fd, "r");
|
||||||
+ if (fp == (FILE*)0) {
|
+ if (fp == (FILE*)0) {
|
||||||
+ close(fd);
|
+ close(fd);
|
||||||
+ goto empty;
|
+ goto empty; /* error */
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ ret = getc(fp);
|
+ ret = getc(fp);
|
||||||
+ fclose(fp);
|
+ fclose(fp);
|
||||||
+
|
+
|
||||||
+ if (ret == '0') break; /* found disk, out here */
|
+ if (ret != '0')
|
||||||
|
+ continue; /* not a hard disk */
|
||||||
|
+
|
||||||
|
+ if (d->d_name[0] == 'h')
|
||||||
|
+ break; /* old IDE disk not managed by kernel, out here */
|
||||||
|
+
|
||||||
|
+ ret = snprintf(buf, sizeof(buf), SYS_BLK "/%s/device", d->d_name);
|
||||||
|
+ if ((ret >= sizeof(buf)) || (ret < 0))
|
||||||
|
+ goto empty; /* error */
|
||||||
|
+
|
||||||
|
+ ret = readlink(buf, lnk, sizeof(lnk));
|
||||||
|
+ if (ret >= sizeof(lnk))
|
||||||
|
+ goto empty; /* error */
|
||||||
|
+ if (ret < 0) {
|
||||||
|
+ if (errno != ENOENT)
|
||||||
|
+ goto empty; /* error */
|
||||||
|
+ continue; /* no entry `device' */
|
||||||
|
+ }
|
||||||
|
+ lnk[ret] = '\0';
|
||||||
|
+
|
||||||
|
+ ptr = basename(lnk);
|
||||||
|
+ if (!ptr || !*ptr)
|
||||||
|
+ continue; /* should not happen */
|
||||||
|
+
|
||||||
|
+ ret = snprintf(buf, sizeof(buf), SYS_CLASS "/%s/manage_start_stop", ptr);
|
||||||
|
+ if ((ret >= sizeof(buf)) || (ret < 0))
|
||||||
|
+ goto empty; /* error */
|
||||||
|
+
|
||||||
|
+ ret = stat(buf, &st);
|
||||||
|
+ if (ret == 0)
|
||||||
|
+ continue; /* disk found but managed by kernel */
|
||||||
|
+
|
||||||
|
+ if (errno != ENOENT)
|
||||||
|
+ goto empty; /* error */
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+ ret = snprintf(buf, sizeof(buf), SYS_BLK "/%s/device/vendor", d->d_name);
|
||||||
|
+ if ((ret >= sizeof(buf)) || (ret < 0))
|
||||||
|
+ goto empty; /* error */
|
||||||
|
+
|
||||||
|
+ fd = open(buf, O_RDONLY|O_NOCTTY);
|
||||||
|
+ if (fd < 0) {
|
||||||
|
+ if (errno != ENOENT)
|
||||||
|
+ goto empty; /* error */
|
||||||
|
+ continue; /* no entry `device/vendor' */
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ fp = fdopen(fd, "r");
|
||||||
|
+ if (fp == (FILE*)0) {
|
||||||
|
+ close(fd);
|
||||||
|
+ goto empty; /* error */
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ ptr = fgets(buf, sizeof(buf), fp);
|
||||||
|
+ fclose(fp);
|
||||||
|
+ if (ptr == (char*)0)
|
||||||
|
+ continue; /* should not happen */
|
||||||
|
+
|
||||||
|
+ if ((len = strlen(buf)) == 0)
|
||||||
|
+ continue; /* should not happen */
|
||||||
|
+
|
||||||
|
+ ptr = &buf[0] + len - 1;
|
||||||
|
+ while ((ptr != &buf[0]) && ISSPACE(*ptr))
|
||||||
|
+ ptr--;
|
||||||
|
+ *(ptr + 1) = '\0'; /* remove trailing white spaces */
|
||||||
|
+
|
||||||
|
+ if (strncmp(buf, "ATA", sizeof(buf)))
|
||||||
|
+ continue; /* no SATA but a real SCSI disk */
|
||||||
|
+
|
||||||
|
+ break; /* new SATA disk to shutdown, out here */
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ if (d == (struct dirent*)0)
|
+ if (d == (struct dirent*)0)
|
||||||
@ -64,8 +153,16 @@
|
|||||||
+#ifndef WIN_STANDBYNOW2
|
+#ifndef WIN_STANDBYNOW2
|
||||||
+#define WIN_STANDBYNOW2 0x94
|
+#define WIN_STANDBYNOW2 0x94
|
||||||
+#endif
|
+#endif
|
||||||
+ unsigned char args1[4] = {WIN_STANDBYNOW1,0,0,0};
|
+#ifndef WIN_FLUSH_CACHE_EXT
|
||||||
+ unsigned char args2[4] = {WIN_STANDBYNOW2,0,0,0};
|
+#define WIN_FLUSH_CACHE_EXT 0xEA
|
||||||
|
+#endif
|
||||||
|
+#ifndef WIN_FLUSH_CACHE
|
||||||
|
+#define WIN_FLUSH_CACHE 0xE7
|
||||||
|
+#endif
|
||||||
|
+ unsigned char flush1[4] = {WIN_FLUSH_CACHE_EXT,0,0,0};
|
||||||
|
+ unsigned char flush2[4] = {WIN_FLUSH_CACHE,0,0,0};
|
||||||
|
+ unsigned char stdby1[4] = {WIN_STANDBYNOW1,0,0,0};
|
||||||
|
+ unsigned char stdby2[4] = {WIN_STANDBYNOW2,0,0,0};
|
||||||
+ char buf[NAME_MAX+1];
|
+ char buf[NAME_MAX+1];
|
||||||
+ int fd, ret;
|
+ int fd, ret;
|
||||||
+
|
+
|
||||||
@ -76,8 +173,13 @@
|
|||||||
+ if ((fd = open(buf, O_RDWR)) < 0)
|
+ if ((fd = open(buf, O_RDWR)) < 0)
|
||||||
+ return -1;
|
+ return -1;
|
||||||
+
|
+
|
||||||
+ ret = ioctl(fd, HDIO_DRIVE_CMD, &args1) &&
|
+ if (ioctl(fd, HDIO_DRIVE_CMD, &flush1)) {
|
||||||
+ ioctl(fd, HDIO_DRIVE_CMD, &args2);
|
+ /* Extend flush rejected, try standard flush */
|
||||||
|
+ ioctl(fd, HDIO_DRIVE_CMD, &flush2);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ ret = ioctl(fd, HDIO_DRIVE_CMD, &stdby1) &&
|
||||||
|
+ ioctl(fd, HDIO_DRIVE_CMD, &stdby2);
|
||||||
+ close(fd);
|
+ close(fd);
|
||||||
+
|
+
|
||||||
+ if (ret)
|
+ if (ret)
|
||||||
@ -107,7 +209,7 @@
|
|||||||
#define MAX_DISKS 64
|
#define MAX_DISKS 64
|
||||||
#define PROC_IDE "/proc/ide"
|
#define PROC_IDE "/proc/ide"
|
||||||
#define DEV_BASE "/dev"
|
#define DEV_BASE "/dev"
|
||||||
@@ -104,7 +204,7 @@ int hddown(void)
|
@@ -104,7 +299,7 @@ int hddown(void)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,14 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Wed Jun 6 15:56:46 CEST 2007 - werner@suse.de
|
||||||
|
|
||||||
|
- For bug #229210: skip real SCSI disks, also flush disk cache for
|
||||||
|
SATA and ATA disks.
|
||||||
|
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
Wed Jun 6 13:01:25 CEST 2007 - werner@suse.de
|
||||||
|
|
||||||
|
- More on bug #229210: do not shutdown allready managed disks
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
Tue Jun 5 14:45:21 CEST 2007 - werner@suse.de
|
Tue Jun 5 14:45:21 CEST 2007 - werner@suse.de
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ Group: System/Base
|
|||||||
PreReq: coreutils
|
PreReq: coreutils
|
||||||
Autoreqprov: on
|
Autoreqprov: on
|
||||||
Version: 2.86
|
Version: 2.86
|
||||||
Release: 74
|
Release: 76
|
||||||
Summary: SysV-Style init
|
Summary: SysV-Style init
|
||||||
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
||||||
Source: sysvinit-2.86.tar.bz2
|
Source: sysvinit-2.86.tar.bz2
|
||||||
@ -282,6 +282,11 @@ rm -rf ${RPM_BUILD_ROOT}
|
|||||||
%doc %{_mandir}/man8/startpar.8.gz
|
%doc %{_mandir}/man8/startpar.8.gz
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Jun 06 2007 - werner@suse.de
|
||||||
|
- For bug #229210: skip real SCSI disks, also flush disk cache for
|
||||||
|
SATA and ATA disks.
|
||||||
|
* Wed Jun 06 2007 - werner@suse.de
|
||||||
|
- More on bug #229210: do not shutdown allready managed disks
|
||||||
* Tue Jun 05 2007 - werner@suse.de
|
* Tue Jun 05 2007 - werner@suse.de
|
||||||
- /sbin/halt: list and powerdown all disks even SATA/SCSI
|
- /sbin/halt: list and powerdown all disks even SATA/SCSI
|
||||||
(bug #229210)
|
(bug #229210)
|
||||||
|
Loading…
Reference in New Issue
Block a user