which function should I use to list all of the FILE SYSTEMS in UNIX?? - Unix

This is a discussion on which function should I use to list all of the FILE SYSTEMS in UNIX?? - Unix ; I want to make a program to minitor the usages of all of the file systems on my AIX or Linux systems. But I will not use shell commands like "df -k" for some FILE SYSTEMS maybe not mounted and ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: which function should I use to list all of the FILE SYSTEMS in UNIX??

  1. which function should I use to list all of the FILE SYSTEMS in UNIX??

    I want to make a program to minitor the usages of all of the file systems on
    my AIX or Linux systems.
    But I will not use shell commands like "df -k" for some FILE SYSTEMS maybe
    not mounted and "df -k" will not collect info about that FILE SYSTEM ,so I
    want to obtain theses info from system calls or lib functions .

    First I want to list all the FILE SYSTEMS on my OS ,which c function should
    I use ?

    Thanks!



  2. Re: which function should I use to list all of the FILE SYSTEMS in UNIX??

    Tommy wrote:
    > I want to make a program to minitor the usages of all of the file systems on
    > my AIX or Linux systems.
    > But I will not use shell commands like "df -k" for some FILE SYSTEMS maybe
    > not mounted and "df -k" will not collect info about that FILE SYSTEM ,so I
    > want to obtain theses info from system calls or lib functions .


    > First I want to list all the FILE SYSTEMS on my OS ,which c function should
    > I use ?


    What is a "file system on my OS"? A file system is something on some
    media, not something of your OS. Just consider a USB drive you can
    unplug - unless it has been mounted your OS won't know nothing about
    it. Only when mounting it the OS can analyze the file system on that
    drive and figures out how large it is etc. Without mounting the file
    system the OS simply does not have that kind of information and so
    there can't be a function that would return it.

    Regards, Jens
    --
    \ Jens Thoms Toerring ___ jt@toerring.de
    \__________________________ http://toerring.de

  3. Re: which function should I use to list all of the FILE SYSTEMS in UNIX??

    You are right.But please consider about this case:
    [cuitao@mytest c]$ df -k
    Filesystem 1K-blocks Used Available Use% Mounted on
    /dev/sda5 18287056 9783828 7574272 57% /
    /dev/sda1 101086 9042 86825 10% /boot
    none 358400 0 358400 0% /dev/shm
    /dev/sda3 1035692 34232 948848 4% /tmp
    /dev/sda6 1000000 000000 900000 90% /app

    There are tow points I care:1 is whether the FS is mounted or unmounted; 2
    is the Use% of FS.
    I must know the list of my FS and the Use% of the FS if it is mounted.

    Now I want to get the function that can list the FS all,not funcation which
    can obtain the Use% of unmounted FS.


    "Jens Thoms Toerring" 写入消息新闻:6gl6ufFg9rmlU1@mid.uni-berlin.de...
    > Tommy wrote:
    >> I want to make a program to minitor the usages of all of the file systems
    >> on
    >> my AIX or Linux systems.
    >> But I will not use shell commands like "df -k" for some FILE SYSTEMS
    >> maybe
    >> not mounted and "df -k" will not collect info about that FILE SYSTEM ,so
    >> I
    >> want to obtain theses info from system calls or lib functions .

    >
    >> First I want to list all the FILE SYSTEMS on my OS ,which c function
    >> should
    >> I use ?

    >
    > What is a "file system on my OS"? A file system is something on some
    > media, not something of your OS. Just consider a USB drive you can
    > unplug - unless it has been mounted your OS won't know nothing about
    > it. Only when mounting it the OS can analyze the file system on that
    > drive and figures out how large it is etc. Without mounting the file
    > system the OS simply does not have that kind of information and so
    > there can't be a function that would return it.
    >
    > Regards, Jens
    > --
    > \ Jens Thoms Toerring ___ jt@toerring.de
    > \__________________________ http://toerring.de




  4. Re: which function should I use to list all of the FILE SYSTEMS in UNIX??

    Tommy wrote:
    > You are right.But please consider about this case:
    > [cuitao@mytest c]$ df -k
    > Filesystem 1K-blocks Used Available Use% Mounted on
    > /dev/sda5 18287056 9783828 7574272 57% /
    > /dev/sda1 101086 9042 86825 10% /boot
    > none 358400 0 358400 0% /dev/shm
    > /dev/sda3 1035692 34232 948848 4% /tmp
    > /dev/sda6 1000000 000000 900000 90% /app


    > There are tow points I care:1 is whether the FS is mounted or unmounted; 2
    > is the Use% of FS.
    > I must know the list of my FS and the Use% of the FS if it is mounted.


    There probably the simplest method is to parse the output of
    'df -k' since you seem to be looking for a solution that works
    on different systems and any other solution is rather likely to
    be highly system dependent. 'df' has the advantage to be specified
    by POSIX, so you have a good chance that it works identical on all
    systems. But if you insist on doing it yourself download the
    GNU coreutils package and have a look how it's done there - but
    be warned: just figuring out which file systems are currently
    mounted is done in at least 10 different ways depending on the
    type of the system df is running on...

    > Now I want to get the function that can list the FS all,not funcation which
    > can obtain the Use% of unmounted FS.


    There's the file /etc/fstab that gets used by 'mount' and contains a
    list of all file systems someone cared to put into it. That's all
    the information you can get about possibly available file systems.
    And I write 'possibly available' since the mere existence of an
    entry in /etc/fstab doesn't guarantee that the file system is really
    accessible. Again, consider the case of an USB drive - many people
    have an entry in /etc/fstab for making it easy to mount such a drive
    but that doesn't tell you if such a drive is currently plugged in.
    On the other hand there's nothing keeping someone with root permis-
    sions from mounting a file system that's not listed in /etc/fstab.

    Regards, Jens
    --
    \ Jens Thoms Toerring ___ jt@toerring.de
    \__________________________ http://toerring.de

  5. Re: which function should I use to list all of the FILE SYSTEMS in UNIX??

    "Tommy" writes:
    >You are right.But please consider about this case:
    >[cuitao@mytest c]$ df -k
    >Filesystem 1K-blocks Used Available Use% Mounted on
    >/dev/sda5 18287056 9783828 7574272 57% /
    >/dev/sda1 101086 9042 86825 10% /boot
    >none 358400 0 358400 0% /dev/shm
    >/dev/sda3 1035692 34232 948848 4% /tmp
    >/dev/sda6 1000000 000000 900000 90% /app
    >
    >There are tow points I care:1 is whether the FS is mounted or unmounted; 2
    >is the Use% of FS.
    >I must know the list of my FS and the Use% of the FS if it is mounted.
    >
    >Now I want to get the function that can list the FS all,not funcation which
    >can obtain the Use% of unmounted FS.


    Please don't top post.

    With traditional unix systems, the mount(1m) utility would maintain
    a file in the /etc directory '/etc/mounts' which contained an
    series of binary records for each mounted filesystem.

    With linux, the kernel itself provides such a list via /proc/mounts.

    The statvfs(2) system call can be used once the mount point is derived
    to obtain free space information.

    scott

  6. Re: which function should I use to list all of the FILE SYSTEMS in UNIX??

    scott@slp53.sl.home (Scott Lurndal) writes:
    >"
    >With traditional unix systems, the mount(1m) utility would maintain
    >a file in the /etc directory '/etc/mounts' which contained an


    make that '/etc/mnttab'.

    scott

  7. Re: which function should I use to list all of the FILE SYSTEMS in UNIX??

    >I want to make a program to minitor the usages of all of the file systems on
    >my AIX or Linux systems.
    >But I will not use shell commands like "df -k" for some FILE SYSTEMS maybe
    >not mounted and "df -k" will not collect info about that FILE SYSTEM ,so I
    >want to obtain theses info from system calls or lib functions .
    >
    >First I want to list all the FILE SYSTEMS on my OS ,which c function should
    >I use ?


    What's the difference between a FILE SYSTEM and a hunk of storage?
    A disk partition or raw disk device might be used for one of several
    things:

    1. Any of a lot of different types of file system. (ufs, msdosfs,
    ntfs, ext2, ext3, cd9660, mfs, nfs, xfs, reiserfs, etc.). You cannot
    necessarily identify this as one specific type of file system. Trying
    the possibilities one by one might yield more than one choice.
    2. Swap space.
    3. A raw hunk of disk space used by an application, e.g. Oracle.
    Depending on your point of view, it has no file system or an
    application file system on it.
    4. An uninitialized partition with no file system on it. The administrator
    hasn't set it up yet. This happens sometimes when application
    requirements haven't been determined yet.
    5. A partition used by another OS on this system but not by this
    OS (multi-boot).
    6. A disk drive with no media in it.

    Information that you do have:
    getmntinfo() or similar functions that list currently mounted file systems.
    /etc/fstab, which identifies commonly mounted file systems and their
    types. This probably identifies all the swap space. /etc/fstab
    may identify devices not currently plugged in (e.g. USB or hot-swapable
    SATA drives) or have no media (CD-ROM, DVD-ROM drives).

    Currently mounted filesystems and filesystems listed in /etc/fstab
    are the easy part.

    If you know the OS you are on, you can go by the name of the device
    in /dev. Such guessing has lots of pitfalls. Depending on the OS,
    a device node in /dev may or may not indicate that the device exists.
    For example on FreeBSD:

    ad[0-9] is a FreeBSD (ATA) disk device
    da[0-9] is a SCSI disk device, virtual or otherwise.
    {ad,da}[0-9]s[1-4] is a DOS-style slice of a disk
    {ad,da}[0-9]s[1-4][a-h] is a BSD partition of a DOS-style slice

    USB mass-storage devices appear as virtual SCSI disks. You may
    have to attempt to mount the da[0-9] disk, which will always fail,
    in order to make the other disk devices appear (e.g. da0s1, which
    might be a DOS filesystem on a USB memory stick).

    Depending on the version of FreeBSD, the existence of a ad[0-9]
    node may or may not indicate that the disk exists. DOS-style slices
    may overlap or, I think, be zero-length, but still show up. Some
    of the BSD-style partitions are virtual: traditionally ad0s1c
    refers to a chunk of disk containing the whole disk, so it overlaps
    ad0s1[abdefgh], and you don't want to try to use it as a filesystem.

    Trying to probe devices for file systems may be time-consuming and
    cause error messsages (e.g. trying to spin up media that is not
    present). Trying to probe a non-disk device may cause undesirable
    side effects (e.g. rewinding a tape, although nowadays that probably
    isn't a big issue).


    Questions:

    Did you want your program to list read-only devices, e.g. CD-ROM
    or DVD-ROM drives with a disk present? Does your answer change if
    it's a burner with a blank writable disk in it?

    Did you want your program to list devices with no media present?



  8. Re: which function should I use to list all of the FILE SYSTEMS inUNIX??

    Jens Thoms Toerring wrote:
    > Tommy wrote:
    >> You are right.But please consider about this case:
    >> [cuitao@mytest c]$ df -k
    >> Filesystem 1K-blocks Used Available Use% Mounted on
    >> /dev/sda5 18287056 9783828 7574272 57% /
    >> /dev/sda1 101086 9042 86825 10% /boot
    >> none 358400 0 358400 0% /dev/shm
    >> /dev/sda3 1035692 34232 948848 4% /tmp
    >> /dev/sda6 1000000 000000 900000 90% /app

    >
    >> There are tow points I care:1 is whether the FS is mounted or unmounted; 2
    >> is the Use% of FS.
    >> I must know the list of my FS and the Use% of the FS if it is mounted.

    >
    > There probably the simplest method is to parse the output of
    > 'df -k' since you seem to be looking for a solution that works
    > on different systems and any other solution is rather likely to
    > be highly system dependent. 'df' has the advantage to be specified
    > by POSIX, so you have a good chance that it works identical on all
    > systems.


    That'll certainly be the best way. You may be able to select system
    specific options to get the most appropriate output format. For
    example, 'df -h' on Solaris.

    --
    Ian Collins.

+ Reply to Thread