The Pedigree Project  0.1
modules/system/preload/main.cc
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "modules/Module.h"
21 #include "modules/system/vfs/File.h"
22 #include "modules/system/vfs/VFS.h"
23 #include "pedigree/kernel/Log.h"
24 #include "pedigree/kernel/process/Semaphore.h"
25 #include "pedigree/kernel/processor/types.h"
26 #include "pedigree/kernel/utilities/String.h"
27 
28 static const char *g_FilesToPreload[] = {
29  "root»/applications/init", "root»/applications/ttyterm",
30  "root»/applications/winman", "root»/applications/tui",
31  "root»/applications/TUI", "root»/applications/login",
32  "root»/libraries/libload.so", "root»/libraries/libc.so",
33  "root»/libraries/libm.so", "root»/libraries/libstdc++.so",
34  "root»/libraries/libpedigree.so", "root»/libraries/libpedigree-c.so",
35  "root»/libraries/libpthread.so", 0};
36 
37 static Semaphore g_Preloads(0);
38 
39 static int preloadThread(void *p)
40 {
41  const char *s = reinterpret_cast<const char *>(p);
42 
43  NOTICE("PRELOAD: " << s);
44 
45  File *pFile = VFS::instance().find(String(s));
46  if (pFile)
47  {
48  NOTICE("PRELOAD: preloading " << s << "...");
49  size_t sz = 0;
50  while (sz < pFile->getSize())
51  {
52  pFile->read(sz, 0x1000, 0);
53  sz += 0x1000;
54  }
55  }
56 
57  NOTICE("PRELOAD: preload " << s << " has completed.");
58  g_Preloads.release();
59 
60  return 0;
61 }
62 
63 static bool init()
64 {
66  return false;
67  /*
68  size_t n = 0;
69  const char *s = g_FilesToPreload[n++];
70  do
71  {
72  NOTICE("PRELOAD: Queue " << s);
73  Thread *pThread = new Thread(
74  Processor::information().getCurrentThread()->getParent(),
75  preloadThread, const_cast<char *>(s));
76  pThread->detach();
77  s = g_FilesToPreload[n++];
78  } while (s);
79 
80  g_Preloads.acquire(n - 1);
81  NOTICE("PRELOAD: preloaded " << n << " files.");
82 
83  // Trick: return false, which unloads this module (its purpose is
84  complete.) return false;
85  */
86 }
87 
88 static void destroy()
89 {
90 }
91 
92 MODULE_INFO("File Cache Preload", &init, &destroy, "vfs");
93 MODULE_OPTIONAL_DEPENDS("filesystems", "mountroot");
File * find(const String &path, File *pStartNode=0)
Definition: VFS.cc:243
Definition: String.h:49
static VFS & instance()
Definition: VFS.cc:56
void release(size_t n=1)
Definition: Semaphore.cc:239
#define NOTICE(text)
Definition: Log.h:74
virtual uint64_t read(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true) final
Definition: File.cc:116
Definition: File.h:66