-
Notifications
You must be signed in to change notification settings - Fork 4
/
file_lie.cpp
85 lines (67 loc) · 2.57 KB
/
file_lie.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
Fakeroot Next Generation - run command with fake root privileges
This program is copyrighted. Copyright information is available at the
AUTHORS file at the root of the source tree for the fakeroot-ng project
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include <unordered_map>
#include <sys/types.h>
#include <unistd.h>
#include "file_lie.h"
struct db_key_hash {
size_t operator()(const override_key &key) const { return key.inode; };
};
typedef std::unordered_map<override_key, stat_override, db_key_hash> file_hash;
static file_hash map_hash;
bool get_map( dev_t dev, ptlib_inode_t inode, stat_override *stat )
{
file_hash::iterator i(map_hash.find( override_key( dev, inode) ));
if( i!=map_hash.end() ) {
*stat=i->second;
return true;
} else {
return false;
}
}
void set_map( const stat_override *stat )
{
map_hash[override_key(stat->dev, stat->inode)]=*stat;
}
void remove_map( dev_t dev, ptlib_inode_t inode )
{
file_hash::iterator i(map_hash.find( override_key( dev, inode) ));
if( i!=map_hash.end() )
map_hash.erase(i);
}
void load_map( FILE *file )
{
stat_override override;
int params;
while( (params=fscanf(file, "dev=" DEV_F ", ino=" INODE_F ", mode=%o, uid=%d, gid=%d, rdev=" DEV_F " \n", &override.dev, &override.inode,
&override.mode, &override.uid, &override.gid, &override.dev_id ))==6 )
{
set_map( &override );
}
}
void save_map( FILE *file )
{
for( file_hash::const_iterator i=map_hash.begin(); i!=map_hash.end() ; ++i ) {
const struct stat_override *override;
override=&(i->second);
if( !override->transient ) {
fprintf( file, "dev=" DEV_F ",ino=" INODE_F ",mode=%o,uid=%d,gid=%d,rdev=" DEV_F "\n", override->dev, override->inode,
override->mode, override->uid, override->gid, override->dev_id );
}
}
}