Added proper license headers
This commit is contained in:
		| @@ -1,28 +1,15 @@ | ||||
|  | ||||
| /* | ||||
|   FUSE: Filesystem in Userspace | ||||
|   Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu> | ||||
|   Copyright (C) 2011       Sebastian Pipping <sebastian@pipping.org> | ||||
|  | ||||
|   This program can be distributed under the terms of the GNU GPLv2. | ||||
|   See the file COPYING. | ||||
| */ | ||||
|   ICFS: Interactively Controlled File System | ||||
|   Copyright (C) 2024-2025  Fedir Kovalov | ||||
|  | ||||
| /** @file | ||||
|  * | ||||
|  * This file system mirrors the existing file system hierarchy of the | ||||
|  * system, starting at the root file system. This is implemented by | ||||
|  * just "passing through" all requests to the corresponding user-space | ||||
|  * libc functions. This implementation is a little more sophisticated | ||||
|  * than the one in passthrough.c, so performance is not quite as bad. | ||||
|  * | ||||
|  * Compile with: | ||||
|  * | ||||
|  *     gcc -Wall passthrough_fh.c `pkg-config fuse3 --cflags --libs` -lulockmgr | ||||
|  * -o passthrough_fh | ||||
|  * | ||||
|  * ## Source code ## | ||||
|  * \include passthrough_fh.c | ||||
|  */ | ||||
|   This program can be distributed under the terms of the GNU GPLv2. | ||||
|   See the file LICENSE. | ||||
| */ | ||||
|  | ||||
| #define FUSE_USE_VERSION 31 | ||||
|  | ||||
| @@ -52,6 +39,28 @@ | ||||
| #include "sourcefs.h" | ||||
| #include "ui-socket.h" | ||||
|  | ||||
| // TODO: move this to other file | ||||
| const char *get_process_name_by_pid(const int pid) { | ||||
|   char *name = (char *)calloc(1024, sizeof(char)); | ||||
|   if (name) { | ||||
|     sprintf(name, "/proc/%d/cmdline", pid); | ||||
|     FILE *f = fopen(name, "r"); | ||||
|     if (f) { | ||||
|       size_t size; | ||||
|       size = fread(name, sizeof(char), 1024, f); | ||||
|       if (size > 0) { | ||||
|         if ('\n' == name[size - 1]) | ||||
|           name[size - 1] = '\0'; | ||||
|       } | ||||
|       fclose(f); | ||||
|     } | ||||
|   } | ||||
|   return name; | ||||
| } | ||||
|  | ||||
| // TODO: move this somewhere else | ||||
| const char *real_filename(const char *filename) { return filename; } | ||||
|  | ||||
| static void *xmp_init(struct fuse_conn_info *conn, struct fuse_config *cfg) { | ||||
|   (void)conn; | ||||
|   cfg->use_ino = 1; | ||||
| @@ -245,6 +254,21 @@ static int xmp_mkdir(const char *path, mode_t mode) { | ||||
|  | ||||
| static int xmp_unlink(const char *path) { | ||||
|   int res; | ||||
|   struct process_info pi; | ||||
|   struct fuse_context *fc = fuse_get_context(); | ||||
|  | ||||
|   // ask the user for the permission for deleting the file | ||||
|   pi.PID = fc->pid; | ||||
|   pi.UID = fc->uid; | ||||
|   pi.name = get_process_name_by_pid(pi.PID); | ||||
|  | ||||
|   // fprintf(stderr, "%s, %d\n", path, ask_access(path, pi)); | ||||
|  | ||||
|   if (ask_access(real_filename(path), pi)) { | ||||
|     free(pi.name); | ||||
|     return -EACCES; | ||||
|   } | ||||
|   free(pi.name); | ||||
|  | ||||
|   res = source_unlink(path); | ||||
|   if (res == -1) | ||||
| @@ -356,34 +380,10 @@ static int xmp_utimens(const char *path, const struct timespec ts[2], | ||||
| } | ||||
| #endif | ||||
|  | ||||
| // TODO: move this to other file | ||||
| const char *get_process_name_by_pid(const int pid) { | ||||
|   char *name = (char *)calloc(1024, sizeof(char)); | ||||
|   if (name) { | ||||
|     sprintf(name, "/proc/%d/cmdline", pid); | ||||
|     FILE *f = fopen(name, "r"); | ||||
|     if (f) { | ||||
|       size_t size; | ||||
|       size = fread(name, sizeof(char), 1024, f); | ||||
|       if (size > 0) { | ||||
|         if ('\n' == name[size - 1]) | ||||
|           name[size - 1] = '\0'; | ||||
|       } | ||||
|       fclose(f); | ||||
|     } | ||||
|   } | ||||
|   return name; | ||||
| } | ||||
|  | ||||
| // TODO: move this somewhere else | ||||
| const char *real_filename(const char *filename) { return filename; } | ||||
|  | ||||
| static int xmp_create(const char *path, mode_t mode, | ||||
|                       struct fuse_file_info *fi) { | ||||
|   int fd; | ||||
|  | ||||
|   struct process_info pi; | ||||
|  | ||||
|   struct fuse_context *fc = fuse_get_context(); | ||||
|  | ||||
|   pi.PID = fc->pid; | ||||
| @@ -409,9 +409,7 @@ static int xmp_create(const char *path, mode_t mode, | ||||
|  | ||||
| static int xmp_open(const char *path, struct fuse_file_info *fi) { | ||||
|   int fd; | ||||
|  | ||||
|   struct process_info pi; | ||||
|  | ||||
|   struct fuse_context *fc = fuse_get_context(); | ||||
|  | ||||
|   pi.PID = fc->pid; | ||||
|   | ||||
| @@ -1,3 +1,11 @@ | ||||
| /* | ||||
|   ICFS: Interactively Controlled File System | ||||
|   Copyright (C) 2024-2025  Fedir Kovalov | ||||
|  | ||||
|   This program can be distributed under the terms of the GNU GPLv2. | ||||
|   See the file LICENSE. | ||||
| */ | ||||
|  | ||||
| #ifndef FUSE_OPERATIONS | ||||
| #define FUSE_OPERATIONS | ||||
|  | ||||
|   | ||||
							
								
								
									
										27
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								src/main.c
									
									
									
									
									
								
							| @@ -3,26 +3,12 @@ | ||||
|   Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu> | ||||
|   Copyright (C) 2011       Sebastian Pipping <sebastian@pipping.org> | ||||
|  | ||||
|   This program can be distributed under the terms of the GNU GPLv2. | ||||
|   See the file COPYING. | ||||
| */ | ||||
|   ICFS: Interactively Controlled File System | ||||
|   Copyright (C) 2024-2025  Fedir Kovalov | ||||
|  | ||||
| /** @file | ||||
|  * | ||||
|  * This file system mirrors the existing file system hierarchy of the | ||||
|  * system, starting at the root file system. This is implemented by | ||||
|  * just "passing through" all requests to the corresponding user-space | ||||
|  * libc functions. This implementation is a little more sophisticated | ||||
|  * than the one in passthrough.c, so performance is not quite as bad. | ||||
|  * | ||||
|  * Compile with: | ||||
|  * | ||||
|  *     gcc -Wall passthrough_fh.c `pkg-config fuse3 --cflags --libs` -lulockmgr | ||||
|  * -o passthrough_fh | ||||
|  * | ||||
|  * ## Source code ## | ||||
|  * \include passthrough_fh.c | ||||
|  */ | ||||
|   This program can be distributed under the terms of the GNU GPLv2. | ||||
|   See the file LICENSE. | ||||
| */ | ||||
|  | ||||
| #define FUSE_USE_VERSION 31 | ||||
|  | ||||
| @@ -42,8 +28,6 @@ const char *mountpoint = NULL; | ||||
| int main(int argc, char *argv[]) { | ||||
|   umask(0); | ||||
|  | ||||
|   // FUSE won't tell us the mountpoint on it's own, so we need to extract it | ||||
|   // ourselves. | ||||
|   mountpoint = realpath(argv[argc - 1], NULL); | ||||
|  | ||||
|   int ret = source_init(mountpoint); | ||||
| @@ -59,6 +43,7 @@ int main(int argc, char *argv[]) { | ||||
|   } | ||||
|  | ||||
|   ret = fuse_main(argc, argv, get_fuse_operations(), NULL); | ||||
|  | ||||
|   free(mountpoint); | ||||
|   return ret; | ||||
| } | ||||
|   | ||||
| @@ -1,3 +1,11 @@ | ||||
| /* | ||||
|   ICFS: Interactively Controlled File System | ||||
|   Copyright (C) 2024-2025  Fedir Kovalov | ||||
|  | ||||
|   This program can be distributed under the terms of the GNU GPLv2. | ||||
|   See the file LICENSE. | ||||
| */ | ||||
|  | ||||
| #define _GNU_SOURCE | ||||
|  | ||||
| #include "sourcefs.h" | ||||
|   | ||||
| @@ -1,4 +1,10 @@ | ||||
| /* | ||||
|   ICFS: Interactively Controlled File System | ||||
|   Copyright (C) 2024-2025  Fedir Kovalov | ||||
|  | ||||
|   This program can be distributed under the terms of the GNU GPLv2. | ||||
|   See the file LICENSE. | ||||
| */ | ||||
|  | ||||
| #ifndef SOURCEFS_H | ||||
| #define SOURCEFS_H | ||||
|   | ||||
| @@ -1,3 +1,11 @@ | ||||
| /* | ||||
|   ICFS: Interactively Controlled File System | ||||
|   Copyright (C) 2024-2025  Fedir Kovalov | ||||
|  | ||||
|   This program can be distributed under the terms of the GNU GPLv2. | ||||
|   See the file LICENSE. | ||||
| */ | ||||
|  | ||||
| #include <stddef.h> | ||||
| #include <sys/types.h> | ||||
| #define _GNU_SOURCE | ||||
|   | ||||
| @@ -1,3 +1,10 @@ | ||||
| /* | ||||
|   ICFS: Interactively Controlled File System | ||||
|   Copyright (C) 2024-2025  Fedir Kovalov | ||||
|  | ||||
|   This program can be distributed under the terms of the GNU GPLv2. | ||||
|   See the file LICENSE. | ||||
| */ | ||||
|  | ||||
| /* | ||||
|  * Interface for controlling communication with the UI. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 BritishTeapot
					BritishTeapot