1

There is one problem after learning the file system in Linux kernel, what happens when copy files across two different file systems.

Since we could use mount -t ntfs DEV_BLK MOUNT_POINT to mount NTFS on Linux, the kernel must know how the data organized in disk, so if we try to copy a file from NTFS to ext4, the kernel should process data, attribute, permission, etc.

But NTFS and ext4 use different permission control, is it default behavior for Linux kernel to give 777 permission to the file copied from NTFS when it creates dentry, inode, etc.?

1
  • The permissions and ownership of files in Microsoft file systems cannot be managed individually by Linux, but are set when mounting the file system, and all directories and files get the same settings. There are more details in this link.
    – sudodus
    Commented Nov 9, 2021 at 18:45

2 Answers 2

2

Just an extract of the Linux Kernel source 4.19 :

/* We do not support NTFS ACLs yet. */

Then most of permissions are set accordingly to this quite commented code :

        /* Everyone gets all permissions. */
        vi->i_mode |= S_IRWXUGO;
        /* If read-only, no one gets write permissions. */
        if (IS_RDONLY(vi))
                vi->i_mode &= ~S_IWUGO;
        if (m->flags & MFT_RECORD_IS_DIRECTORY) {
                vi->i_mode |= S_IFDIR;
                /*
                 * Apply the directory permissions mask set in the mount
                 * options.
                 */
                vi->i_mode &= ~vol->dmask;
                /* Things break without this kludge! */
                if (vi->i_nlink > 1)
                        set_nlink(vi, 1);
        } else {
                vi->i_mode |= S_IFREG;
                /* Apply the file permissions mask set in the mount options. */
                vi->i_mode &= ~vol->fmask;
        }

In other words, mainly the permissions of the mount options, not inherited by the ACLs from the file system.

2
  • So the Linux won't map ACL into USER|GROUP|OTHERS because they are incompatible? That's why we get the 777 permission because of vi->i_mode |= S_IRWXUGO?
    – Pawn Pod
    Commented Nov 10, 2021 at 1:57
  • Linux does support ACL, but not on all file systems. Supporting it with NTFS would need a Linux UID - Windows SUID mapping. And there are things like inherited ACL (a directory is marked to ‘copy’ its parent ACL) which could not match the POSIX model. Commented Nov 10, 2021 at 5:25
0

Since we could use mount -t ntfs DEV_BLK MOUNT_POINT to mount NTFS on Linux, the kernel must know how the data organized in disk, so if we try to copy a file from NTFS to ext4, the kernel should process data, attribute, permission, etc.

exactly. This is the case for any file system: a file system driver is needed so that the operating system knows how to read and store data.

But NTFS and ext4 use different permission control, is it default behavior for Linux kernel to give 777 permission to the file copied from NTFS when it creates dentry, inode, etc.?

It's a pretty common phenomenon that different file systems support different access control semantics; that's why most file system drivers (and mount helpers) allow you to set up the mappings at mount time!

So: You can configure that for the ntfs / ntfs3g drivers at mount time. man mount.ntfs-3g will tell you what options it knows, how users and permissions are mapped and so on.

4
  • it's generally not the case that the kernel would give 0777 permissions by default to files on basically any file system
    – ilkkachu
    Commented Nov 9, 2021 at 19:17
  • I did not claim that anywhere, @ilkkachu! Commented Nov 9, 2021 at 21:22
  • yes, you at least implied it: "is it default behavior for Linux kernel to give 777 permission to the file copied from NTFS?" - "That's not only the case for NTFS, but for basically any file system"
    – ilkkachu
    Commented Nov 10, 2021 at 11:00
  • @ilkkachu aaah, I understand! What I meant is that "different permission control" is basically the case for every file system. Very few actually-in-use file systems only support a common (e.g. POSIX) denominator. Let me fix that! Thanks for the comment! Commented Nov 10, 2021 at 11:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .