Exemplo n.º 1
0
int cryptofs_readdir(void *ctx, char *_dir_name, struct directory *ddir)
{
    gchar *dir_name;
    DIR *dir;
    struct lufs_fattr fattr;
    struct dirent *dent;
    int res;

    dir_name = crypto_translate_path(ctx, _dir_name);

    if(chdir(dir_name) < 0) {
	g_free(dir_name);
        return -1;
    }

    if(!(dir = opendir(dir_name))) {
	g_free(dir_name);
        return -1;
    }
    g_free(dir_name);

    while((dent = readdir(dir))){
	gchar *decname;

        if((res = lufs_stat(ctx, dent->d_name, &fattr)) < 0) {
            closedir(dir);
            return -1;
        }

	if (!strcmp(dent->d_name, ".cryptofs"))
	    continue;
        
	decname = crypto_decrypt_name(ctx, dent->d_name);
        lu_cache_add2dir(ddir, decname, NULL, &fattr);
	g_free(decname);
    }

    closedir(dir);

    return 0;
}
Exemplo n.º 2
0
int 
LiveCDFS::doReaddir(const char *name, 
		    struct directory *dir)
{
	FUNC_START("name='%s', dir=%p", name, dir);
	
	if (!whiteout->isVisible(name)) {
		FUNC_RET("%d", -1, -1);
	}
	
	DIR *rdir = NULL, *tdir = NULL;
	struct lufs_fattr attr;
	struct dirent *ent;
	vector<string> entries;
	
	string rootpath = path->mkroot(name);
	string tmppath = path->mktmp(name);
	
	if ((tdir = opendir(tmppath.c_str()))) {
		while ((ent = readdir(tdir))) {
			string subpath = path->join(name, ent->d_name);
			if (whiteout->isVisible(subpath)) {
				TRACE("Adding direntry='%s'", ent->d_name);
				if ((doStat(subpath.c_str(), &attr)) < 0) {
					ERROR("Could not stat file='%s'", ent->d_name);
					closedir(rdir);
					FUNC_RET("%d", -1, -1);
				}
				lu_cache_add2dir(dir, ent->d_name, NULL, &attr);
			}
			entries.push_back(subpath);
		}
		closedir(tdir);
	}
	else {
		path->recurseMkdir(name);
	}
	
	if (whiteout->isVisible(name) && 
	    Path::exists(rootpath, S_IFDIR) && 
	    (rdir = opendir(rootpath.c_str()))) {
		while ((ent = readdir(rdir))){
			string subpath = path->join(name, ent->d_name);
			bool found = false;
			vector<string>::iterator i = entries.begin();
			while (!found && (i != entries.end())) {
				if (i->compare(subpath) == 0) { 
					found = true;
				} 
				i++;
			}
			if (!found && whiteout->isVisible(subpath)) {
				TRACE("Adding direntry='%s'", ent->d_name);
				if ((doStat(subpath.c_str(), &attr)) < 0) {
					ERROR("could not stat file='%s'", ent->d_name);
					closedir(rdir);
					FUNC_RET("%d", -1, -1);
				}
				lu_cache_add2dir(dir, ent->d_name, NULL, &attr);
			}
		}
		closedir(rdir);
	}
	else {
		WARN("could not open directory, name='%s'", name);
	}
	
	FUNC_RET("%d", 0, 0);
}