Thursday 1 September 2016

Dealing with permissions in the fat 32 sd card in linux system


-----------
FAT filesystems really don't have permissions.

The way that linux handles this is that when you mount a FAT drive, all
the files are given the _same_ file permissions at mount time.
Furthermore, once mounted, these permissions can't be modified.

The default permissions that mount will use for FAT partitions is
"rwxr-xr-x". To change this, you can add an option "umask=" in the fstab
file. For example, on my computer, I use:

/dev/hda1       /mnt/c          vfat    defaults,umask=0000 0 0

The argument to umask is and octal number. To understand what this number
means, you have to understand how file permissions actually work in unix.

The way file permissions are stored on the disk is as a 9-bit binary
number. The best way to show this is with examples. File permission are
commonly represented in three ways:

rwxr-xr-x  - human readable
111101101  - binary number
7  5  5    - 3 octal numbers

The last one is the most important. If you read the manpage for chmod, you
will notice that you can specify the desired permissions using and octal
number. Examples:

gsteele@atlas:~$ chmod 0755  foo
gsteele@atlas:~$ ls -l foo
-rwxr-xr-x    1 gsteele  gsteele   1123166 Mar 27 11:42 foo*
gsteele@atlas:~$ chmod 0766  foo
gsteele@atlas:~$ ls -l foo
-rwxrw-rw-    1 gsteele  gsteele   1123166 Mar 27 11:42 foo*
gsteele@atlas:~$ chmod 0777  foo
gsteele@atlas:~$ ls -l foo
-rwxrwxrwx    1 gsteele  gsteele   1123166 Mar 27 11:42 foo*

(Note: the first number is related to "special file permissions". You
should always leave this number as 0. You can read about these here:
http://www.lns.cornell.edu/public/COMP/info/fileutils/fileutils_3.html#SEC4)

Now, umask is like the binary NOT of the file permissions you want. For
example:

rwxr-xr-x  - desired file permissions
111101101  - binary file permissions
000010010  - umask
0  2  2    - octal umask

So, for example, in my fstab file, I use umask=0000, so that the
permissions on my dos drive are rwxrwxrwx. If you wanted the permissions
on the dos drive to be rwxrwxr-x, you would set umask=0002.
---------------
 

Extracted from http://electron.mit.edu/~gsteele/linuxfaq/index.html#2