这篇文章主要介绍“linux怎么实现软链接相关的功能”,在日常操作中,相信很多人在linux怎么实现软链接相关的功能问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”linux怎么实现软链接相关的功能”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
/* * linux/fs/minix/symlink.c * * Copyright (C) 1991, 1992 Linus Torvalds * * minix symlink handling code */#ifdef MODULE#include <linux/module.h>#endif#include <asm/segment.h>#include <linux/errno.h>#include <linux/sched.h>#include <linux/fs.h>#include <linux/minix_fs.h>#include <linux/stat.h>static int minix_readlink(struct inode *, char *, int);static int minix_follow_link(struct inode *, struct inode *, int, int, struct inode **);/* * symlinks can't do much... */// 操作软链接文件的函数集,在新建软链接文件的时候赋值给inode结构体struct inode_operations minix_symlink_inode_operations = { NULL, /* no file-operations */ NULL, /* create */ NULL, /* lookup */ NULL, /* link */ NULL, /* unlink */ NULL, /* symlink */ NULL, /* mkdir */ NULL, /* rmdir */ NULL, /* mknod */ NULL, /* rename */ minix_readlink, /* readlink */ minix_follow_link, /* follow_link */ NULL, /* bmap */ NULL, /* truncate */ NULL /* permission */};// 打开软链对应的文件static int minix_follow_link(struct inode * dir, struct inode * inode, int flag, int mode, struct inode ** res_inode){ int error; struct buffer_head * bh; *res_inode = NULL; if (!dir) { dir = current->fs->root; dir->i_count++; } if (!inode) { iput(dir); return -ENOENT; } if (!S_ISLNK(inode->i_mode)) { iput(dir); *res_inode = inode; return 0; } if (current->link_count > 5) { iput(inode); iput(dir); return -ELOOP; } // 读取文件第一块内容 if (!(bh = minix_bread(inode, 0, 0))) { iput(inode); iput(dir); return -EIO; } iput(inode); current->link_count++; // 打开b_data里的保存的文件名对应的文件 error = open_namei(bh->b_data,flag,mode,res_inode,dir); current->link_count--; brelse(bh); return error;}// 读取软链文件的内容,即文件路径static int minix_readlink(struct inode * inode, char * buffer, int buflen){ struct buffer_head * bh; int i; char c; if (!S_ISLNK(inode->i_mode)) { iput(inode); return -EINVAL; } if (buflen > 1023) buflen = 1023; bh = minix_bread(inode, 0, 0); iput(inode); if (!bh) return 0; i = 0; while (i<buflen && (c = bh->b_data[i])) { i++; put_fs_byte(c,buffer++); } brelse(bh); return i;}
到此,关于“linux怎么实现软链接相关的功能”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/u/4217331/blog/4379656