Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Hardlinks and Symlinks in Android

I am creating an app in which I would like to make use of hardlinks and symlinks in the Android external memory filesystem. I have tried using the commands

Os.link("oldpath", "newpath");
Os.link("oldpath", "newpath");

However, when I try this, I get this error:

link failed: EPERM (Operation not permitted)

This makes me think that you need root access, although I have seen other people do this same thing, and I would not think that they would have these commands if they needed root. Any ideas?

like image 681
Ashwin Kudva Avatar asked Jul 04 '17 21:07

Ashwin Kudva


People also ask

What is the difference between Hardlinks and symlinks?

A simple way to see the difference between a hard link and a symbolic link is through a simple example. A hard link to a file will point to the place where the file is stored, or the inode of that file. A symbolic link will point to the actual file itself.

Is soft link and symbolic link same?

A soft link (also known as Symbolic link) acts as a pointer or a reference to the file name. It does not access the data available in the original file.

What is symlink Android?

Android does support symbolic links, but certain file systems (e.g. FAT or RFS) do not and you cannot create symbolic links in those partitions. If your device uses a filesystem that supports symbolic links (e.g. ext2, ext3, ext4, yaffs2) then you should be able to use ln -s from the Terminal Emulator.


1 Answers

Call to Os.link is failing because Android uses FAT32 file system by default for external storage. FAT32 file system does not support hard links and soft links that is why you are getting operation not permitted error.

EPERM The filesystem containing oldpath and newpath does not support the creation of hard links.

You can read more information about link system call here

Furthermore you cannot fake hard links or soft links on FAT32 accurately. And also note that for creating hard link in Android requires root permission.

like image 114
Kamil Mahmood Avatar answered Oct 15 '22 22:10

Kamil Mahmood