winix/core/mounts.cpp

132 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"
// reading from 'mounts'
void Mounts::ReadMounts(const std::string & mounts)
{
MountParser mp;
Error err = mp.Parse(mounts, mount_table);
if( err != Error::ok )
{
log << log1 << "M: some problems with mountpoints (mountpoints table will be empty)" << logend;
mount_table.clear();
}
}
// 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;
}
if( err != Error::ok )
{
log << log1 << "M: cannot read /etc/fstab" << logend;
return;
}
ReadMounts(fstab.content);
}
/*
Mount Mounts::GetCurrentMountPoint()
{
return current_dir;
}
*/
Mount::Type Mounts::CurrentMountType()
{
return current_dir.type;
}
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);
}
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;
}