libsaria: Find library id from inode number

I want to eventually use this to create a library file for each library
path.  The "visible" field will be used to enable and disable different
paths during run time.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-03-15 08:12:22 -04:00
parent 0a8600fd01
commit 30e2003a27
4 changed files with 23 additions and 0 deletions

View File

@ -1,9 +1,12 @@
#ifndef LIBSARIA_FS_H
#define LIBSARIA_FS_H
#include <sys/types.h>
#include <string>
using namespace std;
typedef ino_t sid_t;
enum DataState {
DIRTY,
CLEAN,
@ -11,6 +14,7 @@ enum DataState {
namespace libsaria
{
sid_t lookup_fileid(string &);
namespace app
{

View File

@ -1,6 +1,8 @@
#ifndef LIBSARIA_LIBRARY_H
#define LIBSARIA_LIBRARY_H
#include <libsaria/fs.h>
#include <string>
using namespace std;
@ -11,6 +13,8 @@ namespace libsaria
{
struct Path {
bool visible;
sid_t lib_id;
string path;
};

View File

@ -20,6 +20,15 @@ static void make_dir(string path)
namespace libsaria
{
sid_t lookup_fileid(string &filepath)
{
struct stat stat;
int err = lstat(filepath.c_str(), &stat);
if (err != 0)
return err;
return stat.st_ino;
}
void app::mkdir()
{
make_dir(appdir.c_str());

View File

@ -83,7 +83,13 @@ namespace libsaria
void library::Driver::add_path(string dir)
{
struct Path path;
path.visible = true;
path.lib_id = lookup_fileid(dir);
path.path = dir;
if (path.lib_id < 0)
return;
path_list.push_back(path);
path_added(&path);
}