4 * jigdo file system interface using FUSE
6 * jigdoofus is a simple, read-only filesystem. It will transform any
7 * jigdo template files into ISO images, but will pass anything else
8 * through raw, similar to the fuse example filesystem fusexmp.
10 * Copyright (c) 2005 Steve McIntyre <steve@einval.com>
12 * GPL v2 - see COPYING
22 #include <sys/statfs.h>
27 /* Some definitions needed */
29 char *G_base_dir = NULL;
30 struct fuse *M_fuse_state = NULL;
32 static int jdfs_is_template(const char *path)
34 int length = strlen(path);
35 if (!strcmp(&path[length - 9], ".template"))
41 static int jdfs_getattr(const char *path, struct stat *stbuf)
45 res = lstat(path, stbuf);
52 static int jdfs_readlink(const char *path, char *buf, size_t size)
56 res = readlink(path, buf, size - 1);
64 static int jdfs_getdir(const char *path, fuse_dirh_t h, fuse_dirfil_t filler)
74 while((de = readdir(dp)) != NULL)
76 if (jdfs_is_template(de->d_name))
79 int length = strlen(de->d_name);
81 strcpy(buf, de->d_name);
82 strcpy(&buf[length - 9], ".iso");
83 res = filler(h, buf, de->d_type);
86 res = filler(h, de->d_name, de->d_type);
95 static int jdfs_mknod(const char *path, mode_t mode, dev_t rdev)
100 static int jdfs_mkdir(const char *path, mode_t mode)
105 static int jdfs_unlink(const char *path)
110 static int jdfs_rmdir(const char *path)
115 static int jdfs_symlink(const char *from, const char *to)
120 static int jdfs_rename(const char *from, const char *to)
125 static int jdfs_link(const char *from, const char *to)
130 static int jdfs_chmod(const char *path, mode_t mode)
135 static int jdfs_chown(const char *path, uid_t uid, gid_t gid)
140 static int jdfs_truncate(const char *path, off_t size)
145 static int jdfs_utime(const char *path, struct utimbuf *buf)
150 static int jdfs_open(const char *path, int flags)
154 res = open(path, flags);
162 static int jdfs_read(const char *path, char *buf, size_t size, off_t offset)
166 off_t seek_offset = 0;
168 fd = open(path, O_RDONLY);
172 seek_offset = lseek(fd, offset, SEEK_SET);
173 if (seek_offset != offset)
176 res = read(fd, buf, size);
184 static int jdfs_write(const char *path, const char *buf, size_t size, off_t offset)
189 static int jdfs_statfs(const char *path, struct statfs *stbuf)
193 res = statfs(path, stbuf);
200 static int jdfs_release(const char *path, int flags)
202 /* Just a stub. This method is optional and can safely be left
210 static int jdfs_fsync(const char *path, int isdatasync)
212 /* Just a stub. This method is optional and can safely be left
220 static struct fuse_operations jdfs_oper = {
221 .getattr = jdfs_getattr,
222 .readlink = jdfs_readlink,
223 .getdir = jdfs_getdir,
226 .symlink = jdfs_symlink,
227 .unlink = jdfs_unlink,
229 .rename = jdfs_rename,
233 .truncate = jdfs_truncate,
238 .statfs = jdfs_statfs,
239 .release = jdfs_release,
243 int jd_log(int level, char *fmt, ...)
248 if (level <= G_verbose)
251 error = vfprintf(stderr, fmt, ap);
257 void display_progress(int verbose_level, INT64 image_size, INT64 current_offset, char *text)
259 if ((verbose_level <= G_verbose) && (image_size > 0))
260 jd_log(1, "\r %5.2f%% %-60.60s",
261 100.0 * current_offset / image_size, text);
264 extern void file_missing(char *missing, char *filename)
266 jd_log(1, "Missing file %s\n", filename);
269 int main(int argc, char *argv[])
271 const char *opts = "default_permissions,allow_other,allow_root,fsname=jigdoofus";
279 fprintf(stderr, "jigdoofus: not enough args!\n");
280 fprintf(stderr, "Needs base directory and mount point\n");
284 G_base_dir = argv[1];
285 mountpoint = argv[2];
287 error = lstat(G_base_dir, &sb);
290 fprintf(stderr, "jigdoofus: can't open base dir %s (error %d)! Abort.\n", G_base_dir, error);
294 fuse_fd = fuse_mount(mountpoint, opts);
297 fprintf(stderr, "jigdoofus: Unable to open FUSE control connection (error %d)! Abort.\n", errno);
301 M_fuse_state = fuse_new(fuse_fd, NULL, &jdfs_oper);
304 fprintf(stderr, "jigdoofus: Unable to mount filesystem (error %d)! Abort.\n", errno);
308 fuse_loop_mt(M_fuse_state);
309 fuse_unmount(mountpoint);