Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FUSE_USE_VERSION 26
- #include <fuse.h>
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <dirent.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- static const char *hello_str = "Hello World!\n";
- static const char *hello_path = "/hello";
- static int dfs_open(const char *path, struct fuse_file_info * info){
- if (strcmp(path, hello_path) != 0)
- return -ENOENT;
- if ((info->flags & 3) != O_RDONLY)
- return -EACCES;
- return 0;
- }
- static int dfs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info * info) {
- size_t len;
- (void) info;
- if(strcmp(path, hello_path) != 0)
- return -ENOENT;
- len = strlen(hello_str);
- if (offset < len) {
- if (offset + size > len)
- size = len - offset;
- memcpy(buf, hello_str + offset, size);
- } else
- size = 0;
- return size;
- }
- static int dfs_write (const char * a, const char * b, size_t count, off_t d, struct fuse_file_info * info){
- return 0;
- }
- static int dfs_release (const char * a, struct fuse_file_info * info){
- return 0;
- }
- static int dfs_rename (const char * oldpath, const char * newpath){
- return rename(oldpath, newpath);
- }
- static int dfs_unlink (const char * pathname){
- return unlink(pathname);
- }
- static int dfs_rmdir (const char * pathname){
- printf("Removing Directory With Name: %s\n", pathname);
- return rmdir(pathname);
- }
- typedef struct{
- int mode;
- char dir_name[100];
- } socket_struct;
- void my_mkdir(int network_socket, struct sockaddr_in sin, socket_struct a){
- printf("sheyvanili teqsti: %s\n", a.dir_name);
- printf("Sending You Peace of shit\n");
- sendto(network_socket, &a, sizeof(socket_struct), 0, (struct sockaddr*) &sin, sizeof(sin));
- // send(network_socket, server_message, sizeof(server_message), 0);
- }
- static int dfs_mkdir (const char * pathname, mode_t mode){
- int network_socket;
- network_socket = socket(AF_INET, SOCK_STREAM, 0);
- struct sockaddr_in server_address;
- server_address.sin_family = AF_INET;
- server_address.sin_port = htons(10018);
- server_address.sin_addr.s_addr = INADDR_ANY;
- printf("HERE BROOOO!!!!\n");
- int connection_status = connect(network_socket, (struct sockaddr *) &server_address, sizeof(server_address));
- socket_struct bla;
- strcpy(bla.dir_name, pathname);
- bla.mode = mode;
- printf("connection_status: %d\n", connection_status);
- if (connection_status == -1) {
- printf("There was an error making a connection.\n");
- }
- my_mkdir(network_socket, server_address, bla);
- close(network_socket);
- return 0;
- // printf("Creating Directory With Name: %s\n", pathname);
- // return mkdir(pathname, mode);
- }
- static int dfs_opendir (const char * name, struct fuse_file_info * info){
- printf("Opening Directory With Name: %s\n", name);
- return opendir(name);
- }
- static int dfs_releasedir (const char * name, struct fuse_file_info * info){
- printf("Closing Directory With Name: %s\n", name);
- DIR * dirp = opendir(name);
- return closedir(dirp);
- }
- static int dfs_truncate (const char * path, off_t length){
- return truncate(path, length);
- }
- static int dfs_create (const char * pathname, mode_t mode, struct fuse_file_info * info){
- return creat(pathname, mode);
- }
- static int dfs_getattr(const char * path, struct stat * stbuf){
- int res = 0;
- memset(stbuf, 0, sizeof(struct stat));
- if (strcmp(path, "/") == 0) {
- stbuf->st_mode = S_IFDIR | 0755;
- stbuf->st_nlink = 2;
- } else if (strcmp(path, hello_path) == 0) {
- stbuf->st_mode = S_IFREG | 0444;
- stbuf->st_nlink = 1;
- stbuf->st_size = strlen(hello_str);
- } else
- res = -ENOENT;
- return res;
- }
- static struct fuse_operations dfs_oper = {
- .open = dfs_open,
- .read = dfs_read,
- .write = dfs_write,
- .release = dfs_release,
- .rename = dfs_rename,
- .unlink = dfs_unlink,
- .rmdir = dfs_rmdir,
- .mkdir = dfs_mkdir,
- .opendir = dfs_opendir,
- .releasedir = dfs_releasedir,
- .create = dfs_create,
- .getattr = dfs_getattr,
- .truncate = dfs_truncate,
- };
- int main(int argc, char *argv[])
- {
- return fuse_main(argc, argv, &dfs_oper, NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement