1 /**
2 * Copyright (c) 2008-2015 Alper Akcan <alper.akcan@gmail.com>
3 * Copyright (c) 2009 Renzo Davoli <renzo@cs.unibo.it>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program (in the main directory of the fuse-ext2
17 * distribution in the file COPYING); if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "fuse-ext2.h"
22
op_init(struct fuse_conn_info * conn)23 void * op_init (struct fuse_conn_info *conn)
24 {
25 errcode_t rc;
26 struct fuse_context *cntx=fuse_get_context();
27 struct extfs_data *e2data=cntx->private_data;
28
29 debugf("enter %s", e2data->device);
30
31 rc = ext2fs_open(e2data->device,
32 (e2data->readonly) ? 0 : EXT2_FLAG_RW,
33 0, 0, unix_io_manager, &e2data->e2fs);
34 if (rc) {
35 debugf("Error while trying to open %s", e2data->device);
36 exit(1);
37 }
38 #if 1
39 if (e2data->readonly != 1)
40 #endif
41 rc = ext2fs_read_bitmaps(e2data->e2fs);
42 if (rc) {
43 debugf("Error while reading bitmaps");
44 ext2fs_close(e2data->e2fs);
45 exit(1);
46 }
47 debugf("FileSystem %s", (e2data->e2fs->flags & EXT2_FLAG_RW) ? "Read&Write" : "ReadOnly");
48
49 debugf("leave");
50
51 return e2data;
52 }
53