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 
23 #define VOLNAME_SIZE_MAX 16
24 
do_probe(struct extfs_data * opts)25 int do_probe (struct extfs_data *opts)
26 {
27 	errcode_t rc;
28 	ext2_filsys e2fs;
29 
30 	debugf_main("enter");
31 
32 	rc = ext2fs_open(opts->device, EXT2_FLAG_RW, 0, 0, unix_io_manager, &e2fs);
33 	if (rc) {
34 		debugf_main("Error while trying to open %s (rc=%d)", opts->device, rc);
35 		return -1;
36 	}
37 #if 0
38 	rc = ext2fs_read_bitmaps(e2fs);
39 	if (rc) {
40 		debugf_main("Error while reading bitmaps (rc=%d)", rc);
41 		ext2fs_close(e2fs);
42 		return -2;
43 	}
44 #endif
45 	if (e2fs->super != NULL) {
46 		opts->volname = (char *) malloc(sizeof(char) * (VOLNAME_SIZE_MAX + 1));
47 		if (opts->volname != NULL) {
48 			memset(opts->volname, 0, sizeof(char) * (VOLNAME_SIZE_MAX + 1));
49 			strncpy(opts->volname, e2fs->super->s_volume_name, VOLNAME_SIZE_MAX);
50 			opts->volname[VOLNAME_SIZE_MAX] = '\0';
51 		}
52 	}
53 	ext2fs_close(e2fs);
54 
55 	debugf_main("leave");
56 	return 0;
57 }
58