简体   繁体   English

如何在 EXT2 文件系统中创建符号链接

[英]how to create a symbolic link in EXT2 file system

I am working with the EXT2 File System and spent the last 2 days trying to figure out how to create a symbolic link.我正在使用 EXT2 文件系统,并在过去 2 天里试图找出如何创建符号链接。 From http://www.nongnu.org/ext2-doc/ext2.html#DEF-SYMBOLIC-LINKS , "For all symlink shorter than 60 bytes long, the data is stored within the inode itself; it uses the fields which would normally be used to store the pointers to data blocks. This is a worthwhile optimization as it we avoid allocating a full block for the symlink, and most symlinks are less than 60 characters long"来自http://www.nongnu.org/ext2-doc/ext2.html#DEF-SYMBOLIC-LINKS ,“对于所有长度小于 60 字节的符号链接,数据存储在 inode 本身中;它使用的字段通常用于存储指向数据块的指针。这是一个有价值的优化,因为我们避免为符号链接分配一个完整的块,并且大多数符号链接的长度小于 60 个字符”

To create a sym link at /link1 to /source I create a new inode and say it gets index 24. Since it's <60 characters, I placed the string "/source" starting at the i_block[0] field (so printing new_inode->i_block[0] in gdb shows "/dir2/source") and set i_links_count to 1, i_size and i_blocks to 0. I then created a directory entry at the inode 2 (root inode) with the properties 24, "link1", and file type EXT2_FT_SYMLINK.为了在 /link1 到 /source 创建一个符号链接,我创建了一个新的 inode 并说它的索引为 24。由于它是 <60 个字符,我将字符串“/source”放在 i_block[0] 字段开始(因此打印 new_inode- >i_block[0] 在 gdb 中显示“/dir2/source”)并将 i_links_count 设置为 1,i_size 和 i_blocks 为 0。然后我在 inode 2(根 inode)上创建了一个目录条目,属性为 24,“link1”,和文件类型 EXT2_FT_SYMLINK。

A link called "link1" gets created but its a directory and when I click it it goes to "/".创建了一个名为“link1”的链接,但它是一个目录,当我单击它时,它会转到“/”。 I'm wondering what I'm doing wrong...我想知道我做错了什么...

A (very) late response, but just because the symlink's data is in the block pointers that doesn't mean the file size is 0!一个(非常)迟到的响应,但仅仅因为符号链接的数据在块指针中并不意味着文件大小为 0! You need to set the i_size field in the symlink's inode equal to the length of the path您需要将符号链接的 inode 中的i_size字段设置为等于路径的长度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM