46

I tried this command to mount manually :

sudo mount -t vfat /dev/sdb1 /media/external -o uid=1000,gid=1000,utf8,dmask=027,fmask=137

I am not getting what dmask and fmask do here. I know they are used to set up permissions, but when I check permissions of files and folders inside the mounted directory, they are not the same as I set using fmask and dmask.

So, what are they actually doing?

1 Answer 1

80

fmask and dmask are mount options for the FAT filesystem, based on fstab.

They are used to define permissions (umask sets them to both files and directories, while fmask only applies to files and dmask to directories).

The masks are NOT the permissions of the file, they are used to get the permissions you want. In addition, masks can't add any permissions, they only limit what permissions a file or a directory can have.


The umask is the default for files and folders, if you want to customize files and folders’s permissions you should use fmask and dmask same use as the umask.

The mask permissions are not like the octal permission codes passed to the chmod command, however this table is really helpful understanding how the masks permissions work :

    0   1   2   3   4   5   6   7
r   +   +   +   +   -   -   -   -
w   +   +   -   -   +   +   -   -
x   +   -   +   -   +   -   +   -

It works as the normal octal permissions but subtracted from 7, and use the absolute value. for instance if you want to set the permissions to 0777 you will need to set it 0000 in the umask (e.g. umask=0000), if you want to set it to 0755 you will set it to 0022 :

  • The first character represents that its an octal permissions
  • The second is for the owner
  • The third is the group
  • The fourth is for other, i.e any other user

(Source)


man mount gives this :

   umask=value
          Set the umask (the bitmask  of  the  permissions  that  are  not
          present).  The default is the umask of the current process.  The
          value is given in octal.

   dmask=value
          Set the umask applied to directories only.  The default  is  the
          umask of the current process.  The value is given in octal.

   fmask=value
          Set the umask applied to regular files only.  The default is the
          umask of the current process.  The value is given in octal.

You'll also find examples and technical explaination from Drenriza on Ubuntuforums and of course Wikipedia helps a lot, as usual.

3
  • 1
    Did you try changing the first digit from 0 to others? Bitmask of 1=setuid 2=setgid 4=sticky. Apr 25, 2016 at 12:56
  • I think there is something wrong with the fstab mask mechanism. For example, if one wants to mount a VFAT partition like esp_part in order to access all paths and files as a non-root user, while not to write nor execute them, he may find it is awkward to do this. If the partition is mounted with umask 0022, then the executable files become executable to all; If mounted with umask 0033, then the directories become non-accessible. The extra option fmask=0022 does not help neither, while the extra option fmask=0033 causes extra file-inaccessible problems.
    – funicorn
    Sep 17, 2020 at 3:06
  • Substracted from 7 for directories, substracted from 6 for files.
    – mook765
    Jul 5, 2022 at 21:19

You must log in to answer this question.

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