symlink stuff
This commit is contained in:
parent
35a2a4bc5c
commit
5eddf74c68
60
apps/ln.c
Normal file
60
apps/ln.c
Normal file
@ -0,0 +1,60 @@
|
||||
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
||||
* This file is part of ToaruOS and is released under the terms
|
||||
* of the NCSA / University of Illinois License - see LICENSE.md
|
||||
* Copyright (C) 2015 Mike Gerow
|
||||
* 2018 K. Lange
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char usage[] =
|
||||
"Usage: %s [-s] TARGET NAME\n"
|
||||
" -s: Create a symbolic link.\n"
|
||||
" -h: Print this help message and exit.\n";
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
int symlink_flag = 0;
|
||||
|
||||
int c;
|
||||
while ((c = getopt(argc, argv, "sh")) != -1) {
|
||||
switch (c) {
|
||||
case 's':
|
||||
symlink_flag = 1;
|
||||
break;
|
||||
case 'h':
|
||||
fprintf(stdout, usage, argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
default:
|
||||
fprintf(stderr, usage, argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
if (argc - optind < 2) {
|
||||
fprintf(stderr, usage, argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
char * target = argv[optind];
|
||||
char * name = argv[optind + 1];
|
||||
|
||||
if (symlink_flag) {
|
||||
if(symlink(target, name) < 0) {
|
||||
fprintf(stderr, "%s: %s: %s\n", argv[0], name, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
#ifdef link
|
||||
if (link(target, name) < 0) {
|
||||
fprintf(stderr, "%s: %s: %s\n", argv[0], name, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#else
|
||||
fprintf(stderr, "%s: %s: hard link not supported\n", argv[0], name);
|
||||
#endif
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
@ -74,6 +74,10 @@ static int symlink_tmpfs(fs_node_t * parent, char * target, char * name) {
|
||||
debug_print(NOTICE, "symlink target is [%s]", target);
|
||||
t->target = strdup(target);
|
||||
|
||||
t->mask = 0777;
|
||||
t->uid = current_process->user;
|
||||
t->gid = current_process->user;
|
||||
|
||||
spin_lock(tmpfs_lock);
|
||||
list_insert(d->files, t);
|
||||
spin_unlock(tmpfs_lock);
|
||||
|
Loading…
Reference in New Issue
Block a user