From a42169cdae80f88e1c4b52c333e928d239d917f5 Mon Sep 17 00:00:00 2001 From: Nurhak ALTIN Date: Sun, 1 May 2016 10:45:30 +0300 Subject: 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 Reviewed-by: Michael Meeks --- desktop/unx/source/pagein.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'desktop/unx') 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 #include #include +#include +#include /* 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, '/'))) -- cgit