125 lines
2.2 KiB
C++
Executable File
125 lines
2.2 KiB
C++
Executable File
/*
|
|
* This file is a part of CMSLU -- Content Management System like Unix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2009, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include "mounts.h"
|
|
#include "data.h"
|
|
#include "request.h"
|
|
#include "log.h"
|
|
#include "mountparser.h"
|
|
#include "db.h"
|
|
|
|
|
|
|
|
Mounts::Mounts()
|
|
{
|
|
pmount = 0;
|
|
}
|
|
|
|
|
|
|
|
// reading from 'mounts'
|
|
Error Mounts::ReadMounts(const std::string & mounts)
|
|
{
|
|
MountParser mp;
|
|
Error err = mp.Parse(mounts, mount_tab);
|
|
|
|
if( err != Error::ok )
|
|
{
|
|
log << log1 << "M: some problems with mountpoints (mountpoints table will be empty)" << logend;
|
|
mount_tab.clear();
|
|
}
|
|
|
|
CalcCurMount();
|
|
|
|
return err;
|
|
}
|
|
|
|
|
|
|
|
// reading from /etc/fstab
|
|
Error Mounts::ReadMounts()
|
|
{
|
|
static std::string file = "fstab";
|
|
|
|
Item * etc = data.dirs.GetEtcDir();
|
|
|
|
if( !etc )
|
|
{
|
|
log << log1 << "M: there is no /etc directory" << logend;
|
|
return Error::no_item;
|
|
}
|
|
|
|
Item fstab;
|
|
Error err = db.GetItem(etc->id, file, fstab);
|
|
|
|
if( err == Error::no_item )
|
|
{
|
|
log << log1 << "M: there is no /etc/fstab file" << logend;
|
|
return err;
|
|
}
|
|
|
|
if( err != Error::ok )
|
|
{
|
|
log << log1 << "M: cannot read /etc/fstab" << logend;
|
|
return err;
|
|
}
|
|
|
|
return ReadMounts(fstab.content);
|
|
}
|
|
|
|
|
|
void Mounts::MountCmsForRoot()
|
|
{
|
|
Mount mount;
|
|
mount.type = Mount::cms;
|
|
|
|
Item * proot = data.dirs.GetRootDir();
|
|
|
|
if( proot )
|
|
mount.dir_id = proot->id;
|
|
else
|
|
{
|
|
mount.dir_id = -1;
|
|
log << log1 << "M: there is no a root dir" << logend;
|
|
}
|
|
|
|
std::pair<MountTab::iterator, bool> res = mount_tab.insert( std::make_pair(mount.dir_id, mount) );
|
|
pmount = &(res.first->second);
|
|
}
|
|
|
|
|
|
|
|
|
|
void Mounts::CalcCurMount()
|
|
{
|
|
std::vector<Item*>::reverse_iterator i;
|
|
|
|
// when the program starts (when the dir_table is empty()
|
|
// we don't want to call MountCmsForRoot()
|
|
if( request.dir_table.empty() )
|
|
return;
|
|
|
|
for(i = request.dir_table.rbegin() ; i!=request.dir_table.rend() ; ++i)
|
|
{
|
|
std::map<long, Mount>::iterator m = mount_tab.find( (*i)->id );
|
|
|
|
if( m != mount_tab.end() )
|
|
{
|
|
pmount = &(m->second);
|
|
log << log2 << "M: current mount point is: " << pmount->TypeToStr() << logend;
|
|
return;
|
|
}
|
|
}
|
|
|
|
// if nothing was found
|
|
// we assume that 'cms' mount point is used
|
|
MountCmsForRoot();
|
|
log << log2 << "M: current mount point is: cms (default)" << logend;
|
|
}
|