1 /***************************************************************************
2 * Copyright (c) 2005, 2006 by Dmitry Morozhnikov <dmiceman@mail.ru > *
3 * Copyright (c) 2005-10 Simon Peter *
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. *
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. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
30 #include <linux/stat.h>
32 #include <sys/param.h>
33 #include <linux/iso_fs.h>
35 #define FUSE_USE_VERSION 22
40 # define UNUSED(x) x __attribute__((unused))
45 static char *imagefile
= NULL
;
46 static char *mount_point
= NULL
;
47 static int image_fd
= -1;
49 int maintain_mount_point
= 1;
53 char* normalize_name(const char* fname
) {
54 char* abs_fname
= (char *) malloc(PATH_MAX
);
55 realpath(fname
, abs_fname
);
56 // ignore errors from realpath()
60 int check_mount_point() {
62 int rc
= lstat(mount_point
, &st
);
63 if(rc
== -1 && errno
== ENOENT
) {
64 // directory does not exists, createcontext
65 rc
= mkdir(mount_point
, 0777); // let`s underlying filesystem manage permissions
67 perror("Can't create mount point");
71 perror("Can't check mount point");
77 void del_mount_point() {
78 int rc
= rmdir(mount_point
);
80 perror("Can't delete mount point");
84 static int isofs_getattr(const char *path
, struct stat
*stbuf
)
86 return isofs_real_getattr(path
, stbuf
);
89 static int isofs_readlink(const char *path
, char *target
, size_t size
) {
90 return isofs_real_readlink(path
, target
, size
);
93 static int isofs_open(const char *path
, struct fuse_file_info
*UNUSED(fi
))
95 return isofs_real_open(path
);
98 static int isofs_read(const char *path
, char *buf
, size_t size
,
99 off_t offset
, struct fuse_file_info
*UNUSED(fi
))
101 return isofs_real_read(path
, buf
, size
, offset
);
104 static int isofs_flush(const char *UNUSED(path
), struct fuse_file_info
*UNUSED(fi
)) {
108 static void* isofs_init() {
110 run_when_fuse_fs_mounted();
111 return isofs_real_init();
114 static void isofs_destroy(void* param
) {
118 static int isofs_opendir(const char *path
, struct fuse_file_info
*UNUSED(fi
)) {
119 return isofs_real_opendir(path
);
122 static int isofs_readdir(const char *path
, void *buf
, fuse_fill_dir_t filler
, off_t
UNUSED(offset
),
123 struct fuse_file_info
*UNUSED(fi
)) {
124 return isofs_real_readdir(path
, buf
, filler
);
127 static int isofs_statfs(const char *UNUSED(path
), struct statfs
*stbuf
)
129 return isofs_real_statfs(stbuf
);
132 static struct fuse_operations isofs_oper
= {
133 .getattr
= isofs_getattr
,
134 .readlink
= isofs_readlink
,
137 .flush
= isofs_flush
,
139 .destroy
= isofs_destroy
,
140 .opendir
= isofs_opendir
,
141 .readdir
= isofs_readdir
,
142 .statfs
= isofs_statfs
,
145 int ext2_main(int argc
, char *argv
[])
147 imagefile
= normalize_name(argv
[0]);
148 image_fd
= open(imagefile
, O_RDONLY
);
150 perror("Can't open image file");
151 fprintf(stderr
, "Supplied image file name: \"%s\"\n", imagefile
);
155 mount_point
= normalize_name(argv
[1]);
158 iocharset
= "UTF-8//IGNORE";
162 if(maintain_mount_point
) {
163 rc
= check_mount_point();
168 if(maintain_mount_point
) {
169 rc
= atexit(del_mount_point
);
171 fprintf(stderr
, "Can't set exit function\n");
176 // will exit in case of failure
177 rc
= isofs_real_preinit(imagefile
, image_fd
);
179 return fuse_main(argc
, argv
, &isofs_oper
);