mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-27 15:32:52 +02:00
Merge remote-tracking branch 'check/next-cc'
...only build-tested, needs fixes
Origin commit data
------------------
Branch: ni/coolstream
Commit: ecd62d81d1
Author: Stefan Seyfried <seife@tuxbox-git.slipkontur.de>
Date: 2014-02-15 (Sat, 15 Feb 2014)
------------------
This commit was generated by Migit
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
@@ -39,6 +40,9 @@
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <stdarg.h>
|
||||
#include <mntent.h>
|
||||
#include <linux/hdreg.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include <system/helpers.h>
|
||||
#include <gui/update_ext.h>
|
||||
@@ -77,12 +81,24 @@ bool file_exists(const char *filename)
|
||||
|
||||
void wakeup_hdd(const char *hdd_dir)
|
||||
{
|
||||
if(!check_dir(hdd_dir)){
|
||||
if(!check_dir(hdd_dir) && hdd_get_standby(hdd_dir)){
|
||||
std::string wakeup_file = hdd_dir;
|
||||
wakeup_file += "/.wakeup";
|
||||
int fd = open(wakeup_file.c_str(), O_SYNC | O_WRONLY | O_CREAT | O_TRUNC);
|
||||
if (fd >= 0) {
|
||||
unsigned char buf[512];
|
||||
memset(buf, 0xFF, sizeof(buf));
|
||||
for (int i = 0; i < 20; i++) {
|
||||
if (write(fd, buf, sizeof(buf)) < 0) {
|
||||
perror("write to .wakeup");
|
||||
break;
|
||||
}
|
||||
}
|
||||
fdatasync(fd);
|
||||
close(fd);
|
||||
}
|
||||
hdd_flush(hdd_dir);
|
||||
remove(wakeup_file.c_str());
|
||||
creat(wakeup_file.c_str(),S_IREAD|S_IWRITE);
|
||||
sync();
|
||||
}
|
||||
}
|
||||
//use for script with full path
|
||||
@@ -576,3 +592,73 @@ bool CFileHelpers::removeDir(const char *Dir)
|
||||
errno = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int hdd_open_dev(const char * fname)
|
||||
{
|
||||
FILE * fp;
|
||||
struct mntent * mnt;
|
||||
dev_t dev;
|
||||
struct stat st;
|
||||
int fd = -1;
|
||||
|
||||
if (stat(fname, &st) != 0) {
|
||||
perror(fname);
|
||||
return fd;
|
||||
}
|
||||
|
||||
dev = st.st_dev;
|
||||
fp = setmntent("/proc/mounts", "r");
|
||||
if (fp == NULL) {
|
||||
perror("setmntent");
|
||||
return fd;
|
||||
}
|
||||
|
||||
while ((mnt = getmntent(fp)) != NULL) {
|
||||
if (stat(mnt->mnt_fsname, &st) != 0)
|
||||
continue;
|
||||
if (S_ISBLK(st.st_mode) && st.st_rdev == dev) {
|
||||
printf("[hdd] file [%s] -> dev [%s]\n", fname, mnt->mnt_fsname);
|
||||
fd = open(mnt->mnt_fsname, O_RDONLY|O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
perror(mnt->mnt_fsname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
endmntent(fp);
|
||||
return fd;
|
||||
}
|
||||
|
||||
bool hdd_get_standby(const char * fname)
|
||||
{
|
||||
bool standby = false;
|
||||
|
||||
int fd = hdd_open_dev(fname);
|
||||
if (fd >= 0) {
|
||||
unsigned char args[4] = {WIN_CHECKPOWERMODE1,0,0,0};
|
||||
int ret = ioctl(fd, HDIO_DRIVE_CMD, args);
|
||||
if (ret) {
|
||||
args[0] = WIN_CHECKPOWERMODE2;
|
||||
ret = ioctl(fd, HDIO_DRIVE_CMD, args);
|
||||
}
|
||||
if ((ret == 0) && (args[2] != 0xFF))
|
||||
standby = true;
|
||||
|
||||
printf("[hdd] %s\n", standby ? "standby" : "active");
|
||||
close(fd);
|
||||
}
|
||||
return standby;
|
||||
}
|
||||
|
||||
void hdd_flush(const char * fname)
|
||||
{
|
||||
int fd = hdd_open_dev(fname);
|
||||
if (fd >= 0) {
|
||||
printf("[hdd] flush buffers...\n");
|
||||
fsync(fd);
|
||||
if (ioctl(fd, BLKFLSBUF, NULL))
|
||||
perror("BLKFLSBUF");
|
||||
else
|
||||
ioctl(fd, HDIO_DRIVE_CMD, NULL);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user