Lab 8 File System: Symbolic links
Add symbolic links to xv6
Introduction
Task
Solution
Create system call, add new file type and new flag
Implement the symlink(target, path) system call
symlink(target, path) system calluint64
sys_symlink(void)
{
char target[MAXPATH], path[MAXARG];
if(argstr(0, target, MAXPATH) < 0 || argstr(1, path, MAXPATH) < 0){
return -1;
}
//printf(“creating a sym link. Target(%s). Path(%s)\n”, target, path);
begin_op(ROOTDEV);
struct inode *ip = create(path, T_SYMLINK, 0, 0);
if(ip == 0){
end_op(ROOTDEV);
return -1;
}
int len = strlen(target);
writei(ip, 0, (uint64)&len, 0, sizeof(int));
writei(ip, 0, (uint64)target, sizeof(int), len + 1);
iupdate(ip);
iunlockput(ip);
end_op(ROOTDEV);
return 0;
}Modify open system call to work with symbolic link
open system call to work with symbolic linkThoughts
Reference: How readi works
readi worksHow bmap works
bmap worksHow bread works
心得
Last updated