Merge branch 'gerow-symlink-60fix' into strawberry-dev
This commit is contained in:
commit
0c1a9e5584
@ -1305,8 +1305,8 @@ static void symlink_ext2(fs_node_t * parent, char * target, char * name) {
|
||||
/* Write the osd blocks to 0 */
|
||||
memset(inode->osd2, 0x00, sizeof(inode->osd2));
|
||||
|
||||
size_t target_len = strlen(target) + 1;
|
||||
int embedded = target_len < 60; // sizeof(_symlink(inode));
|
||||
size_t target_len = strlen(target);
|
||||
int embedded = target_len <= 60; // sizeof(_symlink(inode));
|
||||
if (embedded) {
|
||||
memcpy(_symlink(inode), target, target_len);
|
||||
inode->size = target_len;
|
||||
@ -1339,7 +1339,9 @@ static int readlink_ext2(fs_node_t * node, char * buf, size_t size) {
|
||||
}
|
||||
|
||||
/* Believe it or not, we actually aren't supposed to include the nul in the length. */
|
||||
buf[read_size] = '\0';
|
||||
if (read_size < size) {
|
||||
buf[read_size] = '\0';
|
||||
}
|
||||
|
||||
free(inode);
|
||||
return read_size;
|
||||
|
74
userspace/tests/test-symlink.c
Normal file
74
userspace/tests/test-symlink.c
Normal file
@ -0,0 +1,74 @@
|
||||
/* 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
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "lib/testing.h"
|
||||
|
||||
static char test58[] =
|
||||
"0000000000000000000000000000000000000000000000000000000000";
|
||||
static char test59[] =
|
||||
"00000000000000000000000000000000000000000000000000000000000";
|
||||
static char test60[] =
|
||||
"000000000000000000000000000000000000000000000000000000000000";
|
||||
static char test61[] =
|
||||
"0000000000000000000000000000000000000000000000000000000000000";
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
INFO("Starting symlink test");
|
||||
if (symlink(test58, "/home/root/test58") < 0) {
|
||||
perror("symlink(/home/root/test58)");
|
||||
}
|
||||
if (symlink(test59, "/home/root/test59") < 0) {
|
||||
perror("symlink(/home/root/test59)");
|
||||
}
|
||||
if (symlink(test60, "/home/root/test60") < 0) {
|
||||
perror("symlink(/home/root/test60)");
|
||||
}
|
||||
if (symlink(test61, "/home/root/test61") < 0) {
|
||||
perror("symlink(/home/root/test61)");
|
||||
}
|
||||
|
||||
char buf[128];
|
||||
int failed = 0;
|
||||
|
||||
if (readlink("/home/root/test58", buf, sizeof(buf)) < 0) {
|
||||
perror("readlink(/home/root/test58)");
|
||||
}
|
||||
if (strcmp(buf, test58) != 0) {
|
||||
FAIL("Link sized 58 is wrong");
|
||||
failed = 1;
|
||||
}
|
||||
if (readlink("/home/root/test59", buf, sizeof(buf)) < 0) {
|
||||
perror("readlink(/home/root/test59)");
|
||||
}
|
||||
if (strcmp(buf, test59) != 0) {
|
||||
FAIL("Link sized 59 is wrong");
|
||||
failed = 1;
|
||||
}
|
||||
if (readlink("/home/root/test60", buf, sizeof(buf)) < 0) {
|
||||
perror("readlink(/home/root/test60)");
|
||||
}
|
||||
if (strcmp(buf, test60) != 0) {
|
||||
FAIL("Link sized 60 is wrong");
|
||||
failed = 1;
|
||||
}
|
||||
if (readlink("/home/root/test61", buf, sizeof(buf)) < 0) {
|
||||
perror("readlink(/home/root/test61)");
|
||||
}
|
||||
if (strcmp(buf, test61) != 0) {
|
||||
FAIL("Link sized 61 is wrong");
|
||||
failed = 1;
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user