summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorNurhak ALTIN <nurhakaltin@gmail.com>2016-05-01 10:45:30 +0300
committerMichael Meeks <michael.meeks@collabora.com>2016-05-01 15:47:33 +0000
commita42169cdae80f88e1c4b52c333e928d239d917f5 (patch)
treef2c5b5a88ce2beeb8cf57e0a2d282b7be580e9ee /desktop
parent75d9f7a4332f8dec141159c88fe70a9f18a5daae (diff)
tdf#99311 Detect SSDs in pagein
Avoid doing the pagein work if we can detect a non-rotational disk. Change-Id: I1ce11050d7ed2a805568343cd385f2612d7c8939 Reviewed-on: https://gerrit.libreoffice.org/24560 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'desktop')
-rw-r--r--desktop/unx/source/pagein.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/desktop/unx/source/pagein.c b/desktop/unx/source/pagein.c
index 7db52d83c1d6..03b26dc00419 100644
--- a/desktop/unx/source/pagein.c
+++ b/desktop/unx/source/pagein.c
@@ -24,6 +24,8 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
/* do_pagein */
static void do_pagein (const char * filename)
@@ -42,11 +44,38 @@ static void do_pagein (const char * filename)
file_image_close (&image);
}
+int isRotational(char const * path)
+{
+#ifdef LINUX
+ FILE * fp = NULL;
+ char fullpath[4096];
+ struct stat out;
+ int major, minor;
+ char type;
+ if( !stat( path , &out ) == 0)
+ return 1;
+ major = major(out.st_dev);
+ minor = 0; /* minor(out.st_dev); only the device itself has a queue */
+ sprintf(fullpath,"/sys/dev/block/%d:%d/queue/rotational",major,minor);
+ if ((fp = fopen (fullpath, "r")))
+ {
+ if (fgets(&type, 1, fp))
+ {
+ fclose(fp);
+ return type == '1';
+ }
+ }
+#endif
+ return 1;
+}
+
void pagein_execute(char const * path, char const * file)
{
char fullpath[4096];
char *p = NULL;
FILE * fp = NULL;
+ if(!isRotational(path))
+ return;
memset(fullpath, 0, sizeof(fullpath));
strncpy (fullpath, path, 3000);
if (!(p = strrchr (fullpath, '/')))