From fd3efeca0f3183e932805db9324689b4dbf5eb7f Mon Sep 17 00:00:00 2001
From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Thu, 28 Jan 2010 19:51:24 +0000
Subject: [PATCH] Linux: Fix spin-up of SATA drive if '-n standby' is used
 (ticket #37).

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@3052 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 smartmontools/CHANGELOG    | 6 +++++-
 smartmontools/NEWS         | 1 +
 smartmontools/os_linux.cpp | 4 +++-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/smartmontools/CHANGELOG b/smartmontools/CHANGELOG
index de4561070..fe79e9014 100644
--- a/smartmontools/CHANGELOG
+++ b/smartmontools/CHANGELOG
@@ -43,8 +43,12 @@ NOTES FOR FUTURE RELEASES: see TODO file.
 
 <DEVELOPERS: ADDITIONS TO THE CHANGE LOG GO JUST BELOW HERE, PLEASE>
 
+  [CF] Linux: Fix spin-up of SATA drive if '-n standby' is used
+       (ticket #37).  For some reason, this happens if the SCSI/SAT
+       device is opened with O_RDWR instead of O_RDONLY.
+
   [CF] Windows: Fix parsing of 'tw_cli' output for 3ware 9.5.x release
-       (ticket #43.)
+       (ticket #43).
 
   [CF] Add USB IDs of Seagate FreeAgent Go, Seagate Expansion Portable
        and WD My Passport (IDE).
diff --git a/smartmontools/NEWS b/smartmontools/NEWS
index 89bc563c1..97f78521b 100644
--- a/smartmontools/NEWS
+++ b/smartmontools/NEWS
@@ -15,6 +15,7 @@ Summary: smartmontools release 5.40
 - Fix regression in smartctl option '-q, --quietmode'.
 - Fix regression in smartd directive '-l selftest'.
 - Linux: Allow smartd 'DEVICESCAN -d sat'.
+- Linux: Fix spin-up of SATA drive if '-n standby' is used.
 - Windows: Fix parsing of 3ware 'tw_cli' output.
 
 Date 2009-12-09
diff --git a/smartmontools/os_linux.cpp b/smartmontools/os_linux.cpp
index 96d7d9383..103af7b26 100644
--- a/smartmontools/os_linux.cpp
+++ b/smartmontools/os_linux.cpp
@@ -845,7 +845,9 @@ private:
 linux_scsi_device::linux_scsi_device(smart_interface * intf,
   const char * dev_name, const char * req_type, bool scanning /*= false*/)
 : smart_device(intf, dev_name, "scsi", req_type),
-  linux_smart_device(O_RDWR | O_NONBLOCK, O_RDONLY | O_NONBLOCK),
+  // If opened with O_RDWR, a SATA disk in standby mode
+  // may spin-up after device close().
+  linux_smart_device(O_RDONLY | O_NONBLOCK),
   m_scanning(scanning)
 {
 }
-- 
GitLab