2009-04-20 00:13:21 +02:00
|
|
|
/*
|
|
|
|
* 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"
|
2009-04-21 22:50:55 +02:00
|
|
|
#include "request.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "mountparser.h"
|
2009-11-16 00:55:11 +01:00
|
|
|
#include "db.h"
|
2009-04-20 00:13:21 +02:00
|
|
|
|
|
|
|
|
2009-11-16 00:55:11 +01:00
|
|
|
|
|
|
|
// reading from 'mounts'
|
|
|
|
void Mounts::ReadMounts(const std::string & mounts)
|
2009-04-20 00:13:21 +02:00
|
|
|
{
|
|
|
|
MountParser mp;
|
2009-11-16 00:55:11 +01:00
|
|
|
Error err = mp.Parse(mounts, mount_table);
|
2009-04-20 00:13:21 +02:00
|
|
|
|
2009-11-16 00:55:11 +01:00
|
|
|
if( err != Error::ok )
|
|
|
|
{
|
|
|
|
log << log1 << "M: some problems with mountpoints (mountpoints table will be empty)" << logend;
|
|
|
|
mount_table.clear();
|
|
|
|
}
|
|
|
|
}
|
2009-06-08 00:17:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-16 00:55:11 +01:00
|
|
|
// reading from /etc/fstab
|
|
|
|
void Mounts::ReadMounts()
|
|
|
|
{
|
|
|
|
static std::string file = "fstab";
|
|
|
|
|
|
|
|
Item * etc = data.dirs.GetEtcDir();
|
|
|
|
|
|
|
|
if( !etc )
|
|
|
|
{
|
|
|
|
log << log1 << "M: there is no /etc directory" << logend;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Item fstab;
|
|
|
|
Error err = db.GetItem(etc->id, file, fstab);
|
|
|
|
|
|
|
|
if( err == Error::db_no_item )
|
|
|
|
{
|
|
|
|
log << log1 << "M: there is no /etc/fstab file" << logend;
|
|
|
|
return;
|
|
|
|
}
|
2009-06-08 00:17:07 +02:00
|
|
|
|
2009-04-20 00:13:21 +02:00
|
|
|
if( err != Error::ok )
|
|
|
|
{
|
2009-11-16 00:55:11 +01:00
|
|
|
log << log1 << "M: cannot read /etc/fstab" << logend;
|
|
|
|
return;
|
2009-04-20 00:13:21 +02:00
|
|
|
}
|
2009-11-16 00:55:11 +01:00
|
|
|
|
|
|
|
ReadMounts(fstab.content);
|
2009-04-20 00:13:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
/*
|
2009-04-20 00:13:21 +02:00
|
|
|
Mount Mounts::GetCurrentMountPoint()
|
|
|
|
{
|
|
|
|
return current_dir;
|
|
|
|
}
|
2009-06-05 22:29:06 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
Mount::Type Mounts::CurrentMountType()
|
|
|
|
{
|
|
|
|
return current_dir.type;
|
|
|
|
}
|
2009-04-20 00:13:21 +02:00
|
|
|
|
2009-06-05 22:29:06 +02:00
|
|
|
bool Mounts::CurrentMountIsParam(Mount::Param p)
|
|
|
|
{
|
|
|
|
return current_dir.IsParam(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Mounts::CurrentMountIsParam(Mount::Param p, int * first_arg)
|
|
|
|
{
|
|
|
|
return current_dir.IsParam(p, first_arg);
|
|
|
|
}
|
2009-04-20 00:13:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
void Mounts::MountCmsForRoot()
|
|
|
|
{
|
|
|
|
current_dir.type = Mount::cms;
|
|
|
|
|
|
|
|
Item * proot = data.dirs.GetRootDir();
|
|
|
|
|
|
|
|
if( proot )
|
|
|
|
current_dir.dir_id = proot->id;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
current_dir.dir_id = -1;
|
|
|
|
log << log1 << "M: there is no a root dir" << logend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Mounts::CalculateCurrentMountType()
|
|
|
|
{
|
|
|
|
std::vector<Item*>::reverse_iterator i;
|
|
|
|
|
|
|
|
|
|
|
|
for(i = request.dir_table.rbegin() ; i!=request.dir_table.rend() ; ++i)
|
|
|
|
{
|
|
|
|
std::map<long, Mount>::iterator m = mount_table.find( (*i)->id );
|
|
|
|
|
|
|
|
if( m != mount_table.end() )
|
|
|
|
{
|
|
|
|
current_dir = m->second;
|
|
|
|
log << log2 << "M: current mount point is: " << current_dir.TypeToStr() << logend;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// we assume that 'cms' mount point is used
|
|
|
|
MountCmsForRoot();
|
|
|
|
log << log2 << "M: current mount point is: cms (default)" << logend;
|
|
|
|
}
|