|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
|
Thread Tools | Display Modes |
|
|
|||
How to get a list of volumes?
I can use the system call getmntinfo on a FreeBSD system to get a list of all mounted volumes, but how can I get a list that contains *all* volumes, even those that are not mounted? I cannot seem to find an equivalent to getmntinfo for this, but I assume there must be a system call to retrieve this information. Any pointers would be appreciated.
|
|
|||
Wow that's strange terminology you use.
If you read sysctl(3), you'll find HW_DISKNAMES in the CTL_HW section. You can view the currently detected devices via sysctl(8): $ sysctl hw.disknames It's quite trivial to write a program which prints the results as well. Code:
#include <stdio.h> #include <sys/param.h> #include <sys/sysctl.h> #include <err.h> int main(void) { int mib[2]; size_t len; char *p; mib[0] = CTL_HW; mib[1] = HW_DISKNAMES; /* Determine how much space to allocate. */ if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1) err(1, "sysctl"); if ((p = (char *)malloc(len)) == NULL) err(1, NULL); /* Populate the allocated area with the string returned * by sysctl. */ if (sysctl(mib, 2, p, &len, NULL, 0) == -1) err(1, "sysctl"); printf("%s\n", p); return 0; } Last edited by BSDfan666; 11th July 2008 at 11:44 PM. |
|
|||
That's unfortunate. I had started to get my hopes up when I started reading your reply. And then you ended it with a "psych!"
Thanks anyway. I'll keep looking... |
|
||||
why not use df -ah df(1)
__________________
Theory is when you know all and nothing works. Practice is when all works and nobody knows why. In this case we have put together theory and practice: nothing works... and nobody knows why! (Albert Einstein) |
|
|||
Well, for one thing I want a programmatic solution--some kind of system call that returns a list of structures, similar to getmntinfo(). But even if I was to use "df -ah" and capture/parse the output, it only lists information for mounted file systems. I want to get a list of all mounted *and* unmounted file systems.
|
|
|||
The user asked how to display all "unmounted" disk devices. (Well, volumes..).
In the end, I think parsing the dmesg output may be the only option... poor FreeBSD users. EDIT: Strange, browsing the FreeBSD CVS I found that HW_DISKNAMES is defined in sysctl.h? It's not documented in the man page though... can anyone check and see if the above works? Last edited by BSDfan666; 13th July 2008 at 05:29 PM. |
|
||||
Quote:
Quote:
%sysctl kern.disks PeterSteele: The above command plus some sort of listing /dev/ad0*, /dev/da0*...would be a solution for you |
|
|||
Well, we were originally using getmntinfo, but our requirements have changed and we cannot rely solely on getmntinfo, mainly because we are not automounting our filesystems any more. Instead we mount them programmatically after possibly repartitioning them based on parameters supplied by the user during OOB. But this is ultimately getting too deep into our application. From what I gather it seems I will have to explicitly look at /dev/ad* to determine what volumes are defined and then use ioctl calls to get further information on these unmounted volumes. There doesn't seem to be any equivalent to getmntinfo for unmounted volumes.
|
|
|||
Quote:
It may be that you have valid reasons for not mounting what you want to query, but by going this route, you are taking on a lot of responsibility. The complexity of your application is now magnitudes more complicated. |
|
|||
I can appreciate that it appears we are making our lives more complex, but we have a custom application that uses raw partitions to store data on. The raw partitions are not formatted with a standard file system but instead something of our own creation. We do have some mounted file systems as well and we can get the information for those easy enough. It's these raw partitions that we looking for a way to query their size. The disklabel command looks to be sufficient for our purposes though. Thanks for the pointer.
Peter |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Buy/Sell/Free Hardware List | DrJ | Off-Topic | 30 | 21st October 2023 12:59 PM |
PHP~MYSQL - Get list of all the fields within a table | cksraj | Programming | 2 | 22nd April 2009 05:57 AM |
List of users connected by sftp. | amscotti | OpenBSD General | 7 | 1st April 2009 07:26 PM |
Command to list all installed ports? | windependence | FreeBSD Ports and Packages | 2 | 13th May 2008 11:10 AM |