FUSE itu Rumit, Filesystem in Userspace (FUSE) merupakan mekanisme sistem operasi untuk sistem operasi Unix-like yang memungkinkan pengguna tidak ber-hak istimewa menciptakan file system mereka sendiri tanpa mengubah kode kernel. Hal ini dicapai dengan menjalankan kode file system di userspace, sedangkan modul FUSE hanya menyediakan "jembatan untuk antarmuka kernel yang sebenarnya.
Diagram Cara Kerja Fuse |
Langkah - langkah instalasi FUSE :
- Download FUSE dari http://fuse.sourceforge.net/ pada bagian Download stable release
- Extract file tar.gz dan masuk ke direktori FUSE. (tar –xvzf fuse-2.9.4.tar.gz)
- Lakukan installasi FUSE dengan cara :
- Gunakan hak akses super user (sudo su)
- Ketikkan perintah ./configure
- Ketikkan perintah make
- Ketikkan perintah make install
Membuat FUSE :
Buka gedit, beri nama file berkesteni .c ketik kode berikut ini
#include <fuse.h>Cara menjalankannya:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <sys/statfs.h>
static const char *dirpath = "/home/anandi/Documents/";
char alamat[1000];
static int xmp_getattr(const char *path, struct stat *stbuf)
{
int res;
char fpath[1000];
sprintf(fpath, "%s%s", dirpath, path);
res = lstat(fpath, stbuf);
if (res == -1)
return -errno;
return 0;
}
static int xmp_getdir(const char *path, fuse_dirh_t h, fuse_dirfil_t filler)
{
DIR *dp;
struct dirent *de;
int res = 0;
char fpath[1000];
sprintf(fpath, "%s%s", dirpath, path);
dp = opendir(fpath);
if(dp == NULL)
return -errno;
while((de = readdir(dp)) != NULL)
{
res = filler(h, de->d_name, de->d_type);
if(res != 0)
break;
}
closedir(dp);
return res;
}
static int xmp_read(const char *path, char *buf, size_t size, off_t offset)
{
int fd;
int res;
char fpath[1000];
sprintf(fpath, "%s%s", dirpath, path);
strcpy(alamat,path);
fd = open(fpath, O_RDONLY);
if(fd == -1)
return -errno;
res = pread(fd, buf, size, offset);
if(res == -1)
res = -errno;
close(fd);
return res;
}
static int xmp_mknod(const char *path, mode_t mode, dev_t rdev)
{
int res;
char fpath[1000];
sprintf(fpath, "%s%s", dirpath, path);
res = mknod(fpath, mode, rdev);
if(res == -1)
return -errno;
return 0;
}
static int xmp_chmod(const char *path, mode_t mode)
{
int res;
char fpath[1000];
sprintf(fpath, "%s%s", dirpath, path);
res = chmod(fpath, mode);
if(res == -1)
return -errno;
return 0;
}
static int xmp_write(const char *path, const char *buf, size_t size, off_t offset)
{
int fd;
int res;
int res1;
char fpath[1000],temp1[1000];
sprintf(fpath, "%s%s", dirpath, path);
fd = open(fpath, O_WRONLY);
sprintf(temp1, "%s%s", dirpath, alamat);
res1 = chmod(temp1, 0000);
if(res1 == -1)
res1 = -errno;
if(fd == -1)
return -errno;
res = pwrite(fd, buf, size, offset);
if(res == -1)
res = -errno;
close(fd);
return res;
}
static int xmp_open(const char *path, int flags)
{
int res;
char fpath[1000];
sprintf(fpath, "%s%s", dirpath, path);
res = open(fpath, flags);
if(res == -1)
return -errno;
close(res);
return 0;
}
static struct fuse_operations xmp_oper =
{
.getattr = xmp_getattr,
//.readlink = xmp_readlink,
.getdir = xmp_getdir,
.mknod = xmp_mknod,
//.mkdir = xmp_mkdir,
//.symlink = xmp_symlink,
//.unlink = xmp_unlink,
//.rmdir = xmp_rmdir,
//.rename = xmp_rename,
//.link = xmp_link,
.chmod = xmp_chmod,
//.chown = xmp_chown,
//.truncate = xmp_truncate,
//.utime = xmp_utime,
.open = xmp_open,
.read = xmp_read,
.write = xmp_write,
//.release = xmp_release,
//.fsync = xmp_fsync,
//.readdir = hello_readdir
};
int main(int argc, char *argv[])
{
return fuse_main(argc, argv, &xmp_oper);
}
- Ganti bagian static const char *dirpath = "/home/anandi/Documents" dengan static const char *dirpath = "/home/[nama user]/Documents"
- Simpan kemudian compile dengan menggunakan perintah: gcc -Wall [nama file].c `pkg-config fuse --cflags --libs` -o [nama sembarang file]
- Kemudian buat sebuah direktori, misalnya: /tmp/fuse
- Coba jalankan fuse tadi dengan cara: ./[nama file] /tmp/fuse
Semoga bermanfaat dan Selamat mencoba....