The Pedigree Project  0.1
posix.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 "DevFs.h"
21 #include "PosixSyscallManager.h"
22 #include "ProcFs.h"
23 #include "UnixFilesystem.h"
24 #include "modules/Module.h"
26 #include "modules/system/vfs/VFS.h"
27 #include "net-syscalls.h"
28 #include "pedigree/kernel/Log.h"
29 #include "pedigree/kernel/process/Process.h"
30 #include "pedigree/kernel/process/Scheduler.h"
31 #include "pedigree/kernel/processor/Processor.h"
32 #include "signal-syscalls.h"
33 #include "system-syscalls.h"
34 
35 static PosixSyscallManager g_PosixSyscallManager;
36 
37 UnixFilesystem *g_pUnixFilesystem = 0;
38 static RamFs *g_pRunFilesystem = 0;
39 
40 DevFs *g_pDevFs = 0;
41 static ProcFs *g_pProcFs = 0;
42 
43 static bool init()
44 {
45  g_PosixSyscallManager.initialise();
46 
47  g_pDevFs = new DevFs();
48  g_pDevFs->initialise(0);
49 
50  g_pProcFs = new ProcFs();
51  g_pProcFs->initialise(0);
52 
53  g_pUnixFilesystem = new UnixFilesystem();
54 
55  g_pRunFilesystem = new RamFs;
56  g_pRunFilesystem->initialise(0);
57  VFS::instance().addAlias(g_pRunFilesystem, String("posix-runtime"));
58 
60  g_pUnixFilesystem, g_pUnixFilesystem->getVolumeLabel());
61  VFS::instance().addAlias(g_pDevFs, g_pDevFs->getVolumeLabel());
62  VFS::instance().addAlias(g_pProcFs, g_pProcFs->getVolumeLabel());
63 
64  Filesystem *scratchfs =
66 
67  // Set up default reparse points. normalisePath in file-syscalls.cc is not
68  // sufficient in many cases, as it requires matching the _entire_ path to
69  // actually work. Reparse points work a lot better and they let us override
70  // the directory layout that already exists on disk. If the directory
71  // doesn't exist on disk, we won't add a reparse point for it here.
72  struct reparse
73  {
74  String path;
75  File *target;
76  } reparses[] = {
77  // {"root»/dev", g_pDevFs->getRoot()},
78  {"root»/var/run", g_pRunFilesystem->getRoot()},
79  {"root»/proc", g_pProcFs->getRoot()},
80  {"root»/tmp", scratchfs ? scratchfs->getRoot() : 0},
81  };
82 
83  for (auto &p : reparses)
84  {
85  if (!p.target)
86  {
87  continue;
88  }
89 
90  File *point = VFS::instance().find(p.path);
91  if (point && point->isDirectory())
92  {
93  Directory *pDir = Directory::fromFile(point);
94  pDir->setReparsePoint(Directory::fromFile(p.target));
95  }
96  }
97 
98  return true;
99 }
100 
101 static void destroy()
102 {
103  VFS::instance().removeAllAliases(g_pProcFs);
104  VFS::instance().removeAllAliases(g_pDevFs);
105  VFS::instance().removeAllAliases(g_pUnixFilesystem);
106  VFS::instance().removeAllAliases(g_pRunFilesystem);
107 }
108 
109 #ifdef ARM_COMMON
110 MODULE_INFO("posix", &init, &destroy, "console", "mountroot");
111 #else
112 MODULE_INFO(
113  "posix", &init, &destroy, "console", "network-stack", "mountroot", "lwip");
114 #endif
virtual String getVolumeLabel() const
Definition: DevFs.h:302
File * find(const String &path, File *pStartNode=0)
Definition: VFS.cc:243
virtual bool initialise(Disk *pDisk)
Definition: ProcFs.cc:379
virtual bool initialise(Disk *pDisk)
Definition: RamFs.cc:139
virtual String getVolumeLabel() const
Definition: ProcFs.h:207
Definition: ProcFs.h:192
An in-RAM filesystem.
void addAlias(Filesystem *pFs, const String &alias)
Definition: VFS.cc:123
static Directory * fromFile(File *pF)
Definition: Directory.h:50
void removeAllAliases(Filesystem *pFs, bool canDelete=true)
Definition: VFS.cc:185
void setReparsePoint(Directory *pTarget)
Definition: Directory.cc:154
Definition: String.h:49
Filesystem * lookupFilesystem(const String &alias)
Definition: VFS.cc:221
virtual bool initialise(Disk *pDisk)
Definition: DevFs.cc:491
static VFS & instance()
Definition: VFS.cc:56
virtual File * getRoot() const
Definition: RamFs.h:104
virtual String getVolumeLabel() const
Definition: RamFs.h:86
Definition: DevFs.h:287
virtual bool isDirectory()
Definition: File.cc:436
Definition: File.h:66
virtual File * getRoot() const
Definition: ProcFs.h:203
virtual File * getRoot() const =0