1

i don't know the reason why but Linux user permissions is not working on NTFS file system... anyway, if a file was copied from windows to Ubuntu, Ubuntu has to give them an ownership and a user permission as well.. so where does Ubuntu save user permission of a file? the thing is, moving a file from Linux distro to another doesn't change permissions. so it should be inside of the file for sure. does Ubuntu rewrite each and every file?

  • 1
    Appears to be a related question superuser.com/questions/638326/… – f01 Dec 2 '14 at 12:53
  • 2
    It's saved in the filesystem, and if the filesystem doesn't support Unix permissions, the umask set for the filesystem if used. – muru Dec 2 '14 at 12:54
  • Further to what muru said, permissions are stored as an inode - en.wikipedia.org/wiki/Inode – NGRhodes Dec 2 '14 at 13:08
2

Linux uses NTFS via software called NTFS3G (google for details if interested). Linux and NTFS have totally different concepts of users, groups and file permissions. This means it's not simple to translate permissions between systems.

To adjust NTFS permissions into Linux form NTFS3G has 2 possibilities: (a) just ignore what NTFS has and set all files and all directories to the same umasks; or (b) provided that user mapping was done, it attempts to guess what meaning of Linux permission are resulted from NTFS permissions of a paricular file/dir.

In case (a) Linux-supplied permissions are not stored anywhere and any attempts to change them are ignored. Case (b) reads and stores file permissions in NTFS.

4

In the ext filesystem, which is used in Linux, inodes are used to describe stored files. An inode contains attributes of a file as well as its data block locations (these are the blocks that contain the actual contents of the file). The following is briefly what is stored in an inode:

Inode number File access, modify and changed timestamps File size Permissions Owner Group Data Block Locations

So to answer your question, Unix stores the permissions of a file in its inode, which is in the filesystem, for example ext4.

If you want to see the inode information of a file, you can use the stat command:

$ stat /bin/bash
  File: ‘/bin/bash’
  Size: 635933          Blocks: 624        IO Block: 65536  regular file
Device: 2e208854h/773883988d    Inode: 281474976901122  Links: 1
Access: (0755/-rwxr-xr-x)  Uid: ( 1000/    Alaa)   Gid: (  513/    None)
Access: 2014-10-18 13:45:13.375853300 -0400
Modify: 2014-10-08 16:54:16.000000000 -0400
Change: 2014-10-18 13:45:13.438253400 -0400
 Birth: 2014-10-18 13:45:13.375853300 -0400

To point out something in your question: by default, when you copy a file from a Linux distribution to another, the permissions are not copied. What happens is that the data blocks (the actual contents) are copied, but all the other attributes are not. So for example, if you are copying files from your internal to your external hard drive (both formatted as ext4), the owner of the copied data on the external hard drive becomes (I think) the user that did the copy command. If you wanted to preserve the permissions (and other attributes) of a file, you would have to use an extra flag, such as -p (or --preserve) in the cp command:

   -p     same as --preserve=mode,ownership,timestamps

   --preserve[=ATTR_LIST]
      preserve   the   specified   attributes   (default:  mode,owner-
      ship,timestamps), if possible  additional  attributes:  context,
      links, xattr, all

Where mode is the permissions. Using options like the -p copies over those inode attributes to the new file.

Windows uses the FAT32 or NTFS which are completely different filesystems that don't understand inodes. That's why, when you copy something from Linux (ext4) into Windows (NTFS or FAT32), Windows applies its own attributes to the file.

When you mount an NTFS filesystem in Ubuntu, it sets permissions on everything in the partition using the umask command (or options fmask and dmask in fstab). When you copy something over to that mounted partition, those files take whatever the umask command entails, and the permissions cannot be changed unless you remount the whole partition with new options.

For more information, read the manpage of ntfs-3g here: http://linux.die.net/man/8/ntfs-3g.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.