DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 11th July 2008
PeterSteele PeterSteele is offline
Port Guard
 
Join Date: Jul 2008
Posts: 43
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
  #2   (View Single Post)  
Old 11th July 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Helpful companion
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Thanked 193 Times in 184 Posts
Default

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;
}
EDIT: Doh! It would appear you're a FreeBSD user, somehow I didn't catch that in your first reply.. unfortunately it would seem FreeBSD has no equivalent sysctl member.

Last edited by BSDfan666; 11th July 2008 at 11:44 PM.
Reply With Quote
  #3   (View Single Post)  
Old 12th July 2008
PeterSteele PeterSteele is offline
Port Guard
 
Join Date: Jul 2008
Posts: 43
Thanked 0 Times in 0 Posts
Default

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...
Reply With Quote
  #4   (View Single Post)  
Old 13th July 2008
Dr_Death_UAE's Avatar
Dr_Death_UAE Dr_Death_UAE is offline
BSD Daemon
 
Join Date: Jul 2008
Posts: 9
Thanked 0 Times in 0 Posts
Default

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)
Reply With Quote
  #5   (View Single Post)  
Old 13th July 2008
PeterSteele PeterSteele is offline
Port Guard
 
Join Date: Jul 2008
Posts: 43
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #6   (View Single Post)  
Old 13th July 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Helpful companion
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Thanked 193 Times in 184 Posts
Default

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.
Reply With Quote
  #7   (View Single Post)  
Old 13th July 2008
18Googol2's Avatar
18Googol2 18Googol2 is offline
Real Name: whoami
Spam Deminer
 
Join Date: Apr 2008
Location: pwd
Posts: 283
Thanked 20 Times in 18 Posts
Default

Quote:
Originally Posted by BSDfan666 View Post
In the end, I think parsing the dmesg output may be the only option... poor FreeBSD users.
dmesg wont help. dmesg lists only drives, not volumes.

Quote:
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?
Nope, the closest alternative would be:

%sysctl kern.disks

PeterSteele: The above command plus some sort of listing /dev/ad0*, /dev/da0*...would be a solution for you
Reply With Quote
  #8   (View Single Post)  
Old 13th July 2008
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Thanked 49 Times in 43 Posts
Default

are you creating your own application?
if so, exactly what o/p do you want?

from what i understand this is going to be a non-trivial program.
Reply With Quote
  #9   (View Single Post)  
Old 14th July 2008
PeterSteele PeterSteele is offline
Port Guard
 
Join Date: Jul 2008
Posts: 43
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
Old 14th July 2008
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 2,833
Thanked 190 Times in 160 Posts
Default

Quote:
Originally Posted by PeterSteele View Post
There doesn't seem to be any equivalent to getmntinfo for unmounted volumes.
Mounted partitions have had to meet the requirements of a recognized filesystem & communication occurs along known paths. To communicate to physically attached, yet unmounted, devices means that you will have to devise a communication path including sophisticated error handling which will duplicate significant portions of the established filesystem. In other words, it will be easier to simply mount the drives in question.

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.
Reply With Quote
Old 14th July 2008
lvlamb's Avatar
lvlamb lvlamb is offline
Real Name: Louis V. Lambrecht
Spam Deminer
 
Join Date: May 2008
Location: .be
Posts: 221
Thanked 25 Times in 24 Posts
Default

man disklabel
FreeBSD current can list 26 labels (there aare only 26 letters in the alphabet, when do we switch to Mandarin ?)
OpenBSD only lists 8 (i to n) alien FSes autside of it's own volume.
__________________
da more I know I know I know nuttin'
Reply With Quote
Old 14th July 2008
PeterSteele PeterSteele is offline
Port Guard
 
Join Date: Jul 2008
Posts: 43
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Buy/Sell/Free Hardware List DrJ Off-Topic 24 3 Weeks Ago 07:20 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


All times are GMT. The time now is 12:35 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick