@Override
protected void startPlugin() throws PluginException {
log.info("start ramfs");
try {
FileSystemService fSS = InitialNaming.lookup(FileSystemService.NAME);
RAMFileSystemType type = fSS.getFileSystemType(RAMFileSystemType.ID);
try {
VirtualDevice dev =
VirtualDeviceFactory.createDevice(RAMFileSystemType.VIRTUAL_DEVICE_NAME);
log.info(dev.getId() + " registered");
final RAMFileSystem fs = type.create(dev, true);
fSS.registerFileSystem(fs);
final String mountPath = "jnode";
fSS.mount(mountPath, fs, null);
log.info("Mounted " + type.getName() + " on " + mountPath);
FSDirectory root_dir = fs.getRootEntry().getDirectory();
root_dir.addDirectory("home");
root_dir.addDirectory("tmp");
// adding files to /jnode/lib/ required by thecore classes
FSDirectory libDir = (FSDirectory) root_dir.addDirectory("lib");
InputStream is = RAMFSPlugin.class.getResourceAsStream("flavormap.properties");
if (is != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int c;
while ((c = is.read(buf)) > -1)
baos.write(buf, 0, c);
is.close();
baos.flush();
baos.close();
ByteBuffer data = ByteBuffer.wrap(baos.toByteArray());
FSFile fmp = (FSFile) libDir.addFile("flavormap.properties");
fmp.write(0, data);
fmp.flush();
}
} catch (DeviceAlreadyRegisteredException ex) {
log.error("RAMFS is allready running.");
} catch (FileSystemException ex) {
log.error("Cannot mount " + type.getName() + " filesystem ", ex);
} catch (DeviceException ex) {
log.debug("DeviceExeption.", ex);
} catch (IOException ex) {
log.error("Cannot mount RAMFS", ex);
}