Welcome to The Fiwix Project
A UNIX-like kernel for the i386 architecture
1 /* 2 * fiwix/fs/iso9660/symlink.c 3 * 4 * Copyright 2018-2021, Jordi Sanfeliu. All rights reserved. 5 * Distributed under the terms of the Fiwix License. 6 */ 7 8 #include <fiwix/types.h> 9 #include <fiwix/errno.h> 10 #include <fiwix/buffer.h> 11 #include <fiwix/fs.h> 12 #include <fiwix/filesystems.h> 13 #include <fiwix/fs_iso9660.h> 14 #include <fiwix/stat.h> 15 #include <fiwix/mm.h> 16 #include <fiwix/stdio.h> 17 #include <fiwix/string.h> 18 19 struct fs_operations iso9660_symlink_fsop = { 20 0, 21 0, 22 23 NULL, /* open */ 24 NULL, /* close */ 25 NULL, /* read */ 26 NULL, /* write */ 27 NULL, /* ioctl */ 28 NULL, /* lseek */ 29 NULL, /* readdir */ 30 NULL, /* mmap */ 31 NULL, /* select */ 32 33 iso9660_readlink, 34 iso9660_followlink, 35 NULL, /* bmap */ 36 NULL, /* lookup */ 37 NULL, /* rmdir */ 38 NULL, /* link */ 39 NULL, /* unlink */ 40 NULL, /* symlink */ 41 NULL, /* mkdir */ 42 NULL, /* mknod */ 43 NULL, /* truncate */ 44 NULL, /* create */ 45 NULL, /* rename */ 46 47 NULL, /* read_block */ 48 NULL, /* write_block */ 49 50 NULL, /* read_inode */ 51 NULL, /* write_inode */ 52 NULL, /* ialloc */ 53 NULL, /* ifree */ 54 NULL, /* statfs */ 55 NULL, /* read_superblock */ 56 NULL, /* remount_fs */ 57 NULL, /* write_superblock */ 58 NULL /* release_superblock */ 59 }; 60 61 int iso9660_readlink(struct inode *i, char *buffer, __size_t count) 62 { 63 __off_t size_read; 64 char *name; 65 66 if(!(name = (char *)kmalloc())) { 67 return -ENOMEM; 68 } 69 70 inode_lock(i); 71 name[0] = NULL; 72 if((size_read = get_rrip_symlink(i, name))) { 73 size_read = MIN(size_read, count); 74 memcpy_b(buffer, name, size_read); 75 } 76 kfree((unsigned int)name); 77 inode_unlock(i); 78 return size_read; 79 } 80 81 int iso9660_followlink(struct inode *dir, struct inode *i, struct inode **i_res) 82 { 83 char *name; 84 __ino_t errno; 85 86 if(!i) { 87 return -ENOENT; 88 } 89 if(!S_ISLNK(i->i_mode)) { 90 printk("%s(): Oops, inode '%d' is not a symlink (!?).\n", __FUNCTION__, i->inode); 91 return 0; 92 } 93 94 if(!(name = (char *)kmalloc())) { 95 return -ENOMEM; 96 } 97 98 name[0] = NULL; 99 if(get_rrip_symlink(i, name)) { 100 iput(i); 101 if((errno = parse_namei(name, dir, i_res, NULL, FOLLOW_LINKS))) { 102 kfree((unsigned int)name); 103 return errno; 104 } 105 } 106 kfree((unsigned int)name); 107 return 0; 108 }