]>
git.proxmox.com Git - pve-cluster.git/blob - data/src/create_pmxcfs_db.c
c59df6fd67c996f3d95393b5775367a55b625e3a
2 Copyright (C) 2010-2012 Proxmox Server Solutions GmbH
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Affero General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Affero General Public License for more details.
14 You should have received a copy of the GNU Affero General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Author: Dietmar Maurer <dietmar@proxmox.com>
19 Note: we use this with the installer to create the initial db
20 without starting pmxcfs/fuse
31 #include <sys/types.h>
34 #include "cfs-utils.h"
43 static memdb_t
*memdb
;
48 fprintf(stderr
, "Usage: create_pmxcfs_db /a/dir /a/filename.db\n");
53 main(int argc
, char *argv
[])
61 const char *dir_name
= argv
[1];
62 const char *dbfile
= argv
[2];
64 DIR *dh
= opendir(dir_name
);
66 perror("unable to open dir");
69 memdb
= memdb_open(dbfile
);
72 time_t ctime
= time(NULL
);
74 while((de
= readdir(dh
))) {
75 if (de
->d_type
!= DT_REG
) {
81 char *fn
= g_strdup_printf("%s/%s", dir_name
, de
->d_name
);
82 if (g_file_get_contents(fn
, &cdata
, &clen
, NULL
)) {
83 //printf("FOUND %ld %s\n", clen, fn);
84 if (memdb_create(memdb
, de
->d_name
, 0, ctime
) != 0) {
85 fprintf(stderr
, "memdb_create '%s' failed\n", de
->d_name
);
88 if (memdb_write(memdb
, de
->d_name
, 0, ctime
, cdata
, clen
, 0, 1) != clen
) {
89 fprintf(stderr
, "memdb_write '%s' failed\n", de
->d_name
);