coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[coreutils] Is, 'df' when run as UID=0 NOT privileged ? Re, FAQ question


From: Mike Hodson
Subject: [coreutils] Is, 'df' when run as UID=0 NOT privileged ? Re, FAQ question 32 and tune2fs manpage
Date: Fri, 12 Nov 2010 01:19:58 -0700

I read the FAQ first, and this doesn't properly answer the question I
am about to ask.

As a refresher:
----------------------------------------snip----------------------------------------
32 df Size and Used and Available do not add up

The df report simply does not add up? Why not?

     $ df /
     Filesystem           1K-blocks      Used Available Use% Mounted on
     /dev/sda1             40559188  35847132   2651768  94% /
     $ df -h /
     Filesystem            Size  Used Avail Use% Mounted on
     /dev/sda1              39G   35G  2.6G  94% /

The most natural thing in the world is to add the values of Used plus
Available and expect to have a result that equals Size. But as we see
here 35847132 plus 2651768 is not equal to 40559188 and is missing
aproximately 2G of disk. Where did it go?

This data is in the minfree percentage of reserved filesystem disk
blocks. A typical filesystem value for minfree is 5% reserved to
superuser processes. Root can make use of all of the disk space but
non-root processes will be restricted by the minfree value. If a user
or user process fills up a partition the root user can still create
files within the provided space.

Additionally modern filesystems attempt to control the amount of disk
fragmentation automatically. This requires that there is sufficient
free disk space available. When the filesystem is operated very close
to 100% full then undesirable fragmentation is increased. This may
significantly decrease disk performance. Keeping a minfree reserved is
one way to ensure a sufficient amount of disk space for the filesystem
to operate at high efficiency.

In this example 5% of 39G is reserved and not included in the
Available value. 39G * 5% is about 1.9G minfree. 35G used plus 2.6G
available plus 1.9G minfree is aproximately 39G and equal to the size
of the filesystem.

The tunefs command using the tunefs -m NUM option is the traditional
command to adjust the filesystem minfree value. More information may
be found in the manual pages and documentation for that command.

----------------------------------------snip----------------------------------------

EXT3fs reserves space for the "privigeled user" or "privileged group"

The way that I see it, 'df' should show what is available for the
UID/GID that calls it, especially if the user is "privileged" such as
root running the 'df' process.

'df' should report what said "privileged" user can write.

Why, if 'df' is run as UID=0, does it not report what UID=0 is able to consume?

I *expect* programs, run as the root user, to realize that things may
be different than if run as a non-root user.

In pseudocode, this simple logic should work:

IF ((running_as_uid == superblock_privileged_uid) || (running_as_gid
== superblock_privileged_gid))
  {
    get_fs_blocks_avail_for_privileged_user
  }
ELSE
  {
    get_fs_blocks_avail_for_normal_user
  }
ENDIF

running 'tune2fs -l' states:

Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)

Thus, when run as root, I would *really expect* 'df' to realize this
and show all blocks available to this "privileged user".

The 'tune2fs' manpage states:
 -m reserved-blocks-percentage
          Set the percentage of the filesystem which may only be  allocated  by
          privileged  processes.    Reserving  some number of filesystem blocks
          for use by privileged processes is done to avoid filesystem  fragmen‐
          tation,  and to allow system daemons, such as syslogd(8), to continue
          to function correctly after non-privileged  processes  are  prevented
          from  writing to the filesystem.  Normally, the default percentage of
          reserved blocks is 5%.

It does *not* specifically state that userspace tools should *never*
report this as being 'free'.  Only that it is 'reserved for
"privileged processes"'.

So, I am wondering why 'df' chooses to take the "least common
denominator" approach and only display what is available to a
"NON-privileged" user.  I ask again, is 'df' when run as UID=0 NOT
considering that it is privileged ?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]