2009-04-20 00:13:21 +02:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2009-04-20 00:13:21 +02:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2010-09-13 01:33:27 +02:00
|
|
|
* Copyright (c) 2009-2010, Tomasz Sowa
|
2009-04-20 00:13:21 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mounts.h"
|
2009-04-21 22:50:55 +02:00
|
|
|
#include "request.h"
|
|
|
|
#include "log.h"
|
2010-09-18 02:51:12 +02:00
|
|
|
#include "db/db.h"
|
2010-09-13 01:33:27 +02:00
|
|
|
#include "plugin.h"
|
2009-04-20 00:13:21 +02:00
|
|
|
|
|
|
|
|
2009-11-16 00:55:11 +01:00
|
|
|
|
2010-06-22 01:53:19 +02:00
|
|
|
|
2010-01-25 05:52:17 +01:00
|
|
|
Mounts::Mounts()
|
|
|
|
{
|
|
|
|
pmount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-13 01:33:27 +02:00
|
|
|
void Mounts::CreateMountType()
|
|
|
|
{
|
|
|
|
mount_type_cms = AddMountType("cms");
|
|
|
|
mount_type_thread = AddMountType("thread");
|
|
|
|
mount_type_ticket = AddMountType("ticket");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Mounts::CreateMountFs()
|
|
|
|
{
|
|
|
|
mount_fs_simplefs = AddMountFs("simplefs");
|
|
|
|
mount_fs_hashfs = AddMountFs("hashfs");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Mounts::CreateMountPar()
|
|
|
|
{
|
|
|
|
mount_par_page = AddMountPar("page");
|
|
|
|
mount_par_thread = AddMountPar("thread");
|
|
|
|
mount_par_ticket = AddMountPar("ticket");
|
|
|
|
mount_par_ticket_type = AddMountPar("ticket_type");
|
|
|
|
mount_par_ticket_type_default = AddMountPar("ticket_type_default");
|
|
|
|
mount_par_ticket_status = AddMountPar("ticket_status");
|
|
|
|
mount_par_ticket_status_default = AddMountPar("ticket_status_default");
|
|
|
|
mount_par_ticket_priority = AddMountPar("ticket_priority");
|
|
|
|
mount_par_ticket_priority_default = AddMountPar("ticket_priority_default");
|
|
|
|
mount_par_ticket_category = AddMountPar("ticket_category");
|
|
|
|
mount_par_ticket_category_default = AddMountPar("ticket_category_default");
|
|
|
|
mount_par_ticket_expected = AddMountPar("ticket_expected");
|
|
|
|
mount_par_ticket_expected_default = AddMountPar("ticket_expected_default");
|
|
|
|
mount_par_createthread_on = AddMountPar("createthread_on");
|
|
|
|
mount_par_createticket_on = AddMountPar("createticket_on");
|
|
|
|
mount_par_only_root_remove = AddMountPar("only_root_remove");
|
|
|
|
mount_par_emacs_on = AddMountPar("emacs_on");
|
|
|
|
mount_par_mkdir_on = AddMountPar("mkdir_on");
|
|
|
|
mount_par_app = AddMountPar("app");
|
|
|
|
mount_par_html_template = AddMountPar("html_template");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Mounts::CreateMounts()
|
|
|
|
{
|
|
|
|
CreateMountType();
|
|
|
|
CreateMountFs();
|
|
|
|
CreateMountPar();
|
|
|
|
|
|
|
|
plugin.Call(WINIX_ADD_MOUNTS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
void Mounts::SetDirs(Dirs * pdirs)
|
|
|
|
{
|
|
|
|
dirs = pdirs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Mounts::SetDb(Db * pdb)
|
|
|
|
{
|
|
|
|
db = pdb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mounts::SetRequest(Request * prequest)
|
|
|
|
{
|
|
|
|
request = prequest;
|
|
|
|
}
|
|
|
|
|
2010-01-25 05:52:17 +01:00
|
|
|
|
2010-06-22 01:53:19 +02:00
|
|
|
|
2010-09-13 01:33:27 +02:00
|
|
|
int Mounts::AddMountType(const char * type)
|
|
|
|
{
|
|
|
|
mount_type_tab.push_back(type);
|
|
|
|
|
|
|
|
return static_cast<int>(mount_type_tab.size()) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Mounts::AddMountType(const std::string & type)
|
|
|
|
{
|
|
|
|
return AddMountType(type.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Mounts::AddMountFs(const char * fs)
|
|
|
|
{
|
|
|
|
mount_fs_tab.push_back(fs);
|
|
|
|
|
|
|
|
return static_cast<int>(mount_fs_tab.size()) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const std::string & Mounts::GetMountType(int id)
|
|
|
|
{
|
|
|
|
if( id < 0 || id >= (int)mount_type_tab.size() )
|
|
|
|
return empty_str;
|
|
|
|
|
|
|
|
return mount_type_tab[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Mounts::AddMountFs(const std::string & fs)
|
|
|
|
{
|
|
|
|
return AddMountFs(fs.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const std::string & Mounts::GetMountFs(int id)
|
|
|
|
{
|
|
|
|
if( id < 0 || id >= (int)mount_fs_tab.size() )
|
|
|
|
return empty_str;
|
|
|
|
|
|
|
|
return mount_fs_tab[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Mounts::AddMountPar(const char * par)
|
|
|
|
{
|
|
|
|
mount_par_tab.push_back(par);
|
|
|
|
|
|
|
|
return static_cast<int>(mount_par_tab.size()) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Mounts::AddMountPar(const std::string & par)
|
|
|
|
{
|
|
|
|
return AddMountPar(par.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const std::string & Mounts::GetMountPar(int id)
|
|
|
|
{
|
|
|
|
if( id < 0 || id >= (int)mount_par_tab.size() )
|
|
|
|
return empty_str;
|
|
|
|
|
|
|
|
return mount_par_tab[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-16 00:55:11 +01:00
|
|
|
// reading from 'mounts'
|
2010-01-25 05:52:17 +01:00
|
|
|
Error Mounts::ReadMounts(const std::string & mounts)
|
2009-04-20 00:13:21 +02:00
|
|
|
{
|
2010-09-13 01:33:27 +02:00
|
|
|
mount_parser.SetDirs(dirs);
|
|
|
|
mount_parser.SetMountTypeTab(mount_type_tab);
|
|
|
|
mount_parser.SetMountFsTab(mount_fs_tab);
|
|
|
|
mount_parser.SetMountParTab(mount_par_tab);
|
|
|
|
|
|
|
|
Error err = mount_parser.Parse(mounts, mount_tab);
|
2010-01-25 05:52:17 +01:00
|
|
|
|
2010-02-28 01:08:10 +01:00
|
|
|
if( err != WINIX_ERR_OK )
|
2009-11-16 00:55:11 +01:00
|
|
|
{
|
|
|
|
log << log1 << "M: some problems with mountpoints (mountpoints table will be empty)" << logend;
|
2010-01-25 05:52:17 +01:00
|
|
|
mount_tab.clear();
|
2009-11-16 00:55:11 +01:00
|
|
|
}
|
2010-01-25 05:52:17 +01:00
|
|
|
|
|
|
|
CalcCurMount();
|
|
|
|
|
|
|
|
return err;
|
2009-11-16 00:55:11 +01:00
|
|
|
}
|
2009-06-08 00:17:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-16 00:55:11 +01:00
|
|
|
// reading from /etc/fstab
|
2010-01-25 05:52:17 +01:00
|
|
|
Error Mounts::ReadMounts()
|
2009-11-16 00:55:11 +01:00
|
|
|
{
|
|
|
|
static std::string file = "fstab";
|
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
Item * etc = dirs->GetEtcDir();
|
2009-11-16 00:55:11 +01:00
|
|
|
|
|
|
|
if( !etc )
|
|
|
|
{
|
|
|
|
log << log1 << "M: there is no /etc directory" << logend;
|
2010-02-28 01:08:10 +01:00
|
|
|
return WINIX_ERR_NO_ITEM;
|
2009-11-16 00:55:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Item fstab;
|
2010-08-10 18:12:50 +02:00
|
|
|
Error err = db->GetItem(etc->id, file, fstab);
|
2009-11-16 00:55:11 +01:00
|
|
|
|
2010-02-28 01:08:10 +01:00
|
|
|
if( err == WINIX_ERR_NO_ITEM )
|
2009-11-16 00:55:11 +01:00
|
|
|
{
|
|
|
|
log << log1 << "M: there is no /etc/fstab file" << logend;
|
2010-01-25 05:52:17 +01:00
|
|
|
return err;
|
2009-11-16 00:55:11 +01:00
|
|
|
}
|
2009-06-08 00:17:07 +02:00
|
|
|
|
2010-02-28 01:08:10 +01:00
|
|
|
if( err != WINIX_ERR_OK )
|
2009-04-20 00:13:21 +02:00
|
|
|
{
|
2009-11-16 00:55:11 +01:00
|
|
|
log << log1 << "M: cannot read /etc/fstab" << logend;
|
2010-01-25 05:52:17 +01:00
|
|
|
return err;
|
2009-04-20 00:13:21 +02:00
|
|
|
}
|
2009-11-16 00:55:11 +01:00
|
|
|
|
2010-01-25 05:52:17 +01:00
|
|
|
return ReadMounts(fstab.content);
|
2009-06-05 22:29:06 +02:00
|
|
|
}
|
2009-04-20 00:13:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
void Mounts::MountCmsForRoot()
|
|
|
|
{
|
2010-01-25 05:52:17 +01:00
|
|
|
Mount mount;
|
2010-09-13 01:33:27 +02:00
|
|
|
mount.type = MountTypeCms();
|
|
|
|
mount.fs = MountFsSimplefs();
|
2010-02-19 00:30:22 +01:00
|
|
|
|
2010-08-10 18:12:50 +02:00
|
|
|
Item * proot = dirs->GetRootDir();
|
2009-04-20 00:13:21 +02:00
|
|
|
|
|
|
|
if( proot )
|
2010-01-25 05:52:17 +01:00
|
|
|
mount.dir_id = proot->id;
|
2009-04-20 00:13:21 +02:00
|
|
|
else
|
|
|
|
{
|
2010-01-25 05:52:17 +01:00
|
|
|
mount.dir_id = -1;
|
2009-04-20 00:13:21 +02:00
|
|
|
log << log1 << "M: there is no a root dir" << logend;
|
|
|
|
}
|
2010-01-25 05:52:17 +01:00
|
|
|
|
|
|
|
std::pair<MountTab::iterator, bool> res = mount_tab.insert( std::make_pair(mount.dir_id, mount) );
|
|
|
|
pmount = &(res.first->second);
|
2009-04-20 00:13:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-25 05:52:17 +01:00
|
|
|
void Mounts::CalcCurMount()
|
2009-04-20 00:13:21 +02:00
|
|
|
{
|
|
|
|
std::vector<Item*>::reverse_iterator i;
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
// when the program starts (when the dir_tab is empty()
|
2010-01-25 05:52:17 +01:00
|
|
|
// we don't want to call MountCmsForRoot()
|
2010-08-10 22:43:38 +02:00
|
|
|
if( request->dir_tab.empty() )
|
2010-01-25 05:52:17 +01:00
|
|
|
return;
|
2009-04-20 00:13:21 +02:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
for(i = request->dir_tab.rbegin() ; i!=request->dir_tab.rend() ; ++i)
|
2009-04-20 00:13:21 +02:00
|
|
|
{
|
2010-01-25 05:52:17 +01:00
|
|
|
std::map<long, Mount>::iterator m = mount_tab.find( (*i)->id );
|
2009-04-20 00:13:21 +02:00
|
|
|
|
2010-01-25 05:52:17 +01:00
|
|
|
if( m != mount_tab.end() )
|
2009-04-20 00:13:21 +02:00
|
|
|
{
|
2010-01-25 05:52:17 +01:00
|
|
|
pmount = &(m->second);
|
2010-09-13 01:33:27 +02:00
|
|
|
log << log2 << "M: current mount point is: " << GetMountType(pmount->type)
|
|
|
|
<< ", fs: " << GetMountFs(pmount->fs) << logend;
|
2009-04-20 00:13:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-25 05:52:17 +01:00
|
|
|
// if nothing was found
|
2009-04-20 00:13:21 +02:00
|
|
|
// we assume that 'cms' mount point is used
|
|
|
|
MountCmsForRoot();
|
2010-09-13 01:33:27 +02:00
|
|
|
log << log2 << "M: current mount point is: " << GetMountType(pmount->type) << " (default)"
|
|
|
|
<< ", fs: " << GetMountFs(pmount->fs) << logend;
|
2009-04-20 00:13:21 +02:00
|
|
|
}
|
2010-03-15 02:47:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
// can return null pointer
|
|
|
|
// and we don't assume cms as a default mount point if nothing is found
|
|
|
|
Mount * Mounts::CalcMount(long dir_id)
|
|
|
|
{
|
|
|
|
while( true )
|
|
|
|
{
|
2010-08-10 18:12:50 +02:00
|
|
|
Item * pdir = dirs->GetDir(dir_id);
|
2010-03-15 02:47:26 +01:00
|
|
|
|
|
|
|
if( !pdir )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
std::map<long, Mount>::iterator m = mount_tab.find( pdir->id );
|
|
|
|
|
|
|
|
if( m != mount_tab.end() )
|
|
|
|
return &(m->second);
|
|
|
|
|
|
|
|
dir_id = pdir->parent_id;
|
|
|
|
}
|
|
|
|
}
|
2010-06-22 01:53:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
const Mounts::MountTab * Mounts::GetMountTab()
|
|
|
|
{
|
|
|
|
return &mount_tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
|