Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-08-2007, 12:54 PM
|
#1
|
LQ Newbie
Registered: Jan 2007
Posts: 10
Rep:
|
Drive volume serial number: any similar concept in Linux?
Hallo experts,
i am a newbie in Linux. As far as i know, in Windows each drive (i mean, a logical partition, not physical hard disk) is assigned an unique serial number, named 'volume number or volume ID', when it is formatted. So i wonder if there is any similar concept in Linux?
If so, how can i program to get the volume number of the current working logical partition in Linux (if exists) using C++?
Thanks in advance!
Best regards,
.viettrung.
Last edited by viettrung; 01-08-2007 at 12:56 PM.
|
|
|
01-08-2007, 01:35 PM
|
#2
|
Member
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892
Rep:
|
I think you're thinking of the device node name? (Like /dev/sda, IIRC for Linux; in BSD they are things like sd0a and wd1b because they have a different partitioning / slicing method than Linux & Windows.)
I'm not sure, but I would think the answer would be no, because the filesystem abstracts this information away (since disks can be mounted at any point). Theoretically you could check the active mount table with the current working directory, but the notion of a union filesystem would make this method kind of useless.
Last edited by taylor_venable; 01-08-2007 at 01:37 PM.
|
|
|
01-09-2007, 02:20 AM
|
#3
|
Amigo developer
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928
|
I think he means the disk LABEL which is file system dependent. ext2 and maybe others linux file systems have it. 'tune2fs' can be used(for ext2-3) to set the label or it can be set during creation.
|
|
|
01-09-2007, 04:48 AM
|
#4
|
Member
Registered: Jul 2006
Location: Paraná, Argentina
Distribution: Frugalware 0.6 (Terminus) - Kubuntu 7.04 (Feisty Fawn Herd 5)
Posts: 217
Rep:
|
Hi, be welcome.
I can be wrong at this, but I believe he/she means exactly what it says there, "logical partition [...] unique serial number", that will be the Universally Unique Identifier (UUID).
An UUID (128 bits) into /etc/fstab looks like this:
Code:
# /dev/hdb10
UUID=2c619834-f4fe-4038-bc5a-f1a0c9c80178 /usr/local reiserfs defaults 0 2
You can see all your partitions UUID's at /dev/disk/by-uuid
I _suck_ at programming, so excuse that, but perhaps this tiny code might help you to understand how to copy the UUID from a source to a destination, using the uuid library:
Code:
#include <uuid/uuid.h>
void uuid_copy(uuid_t destination, uuid_t source);
Please everyone excuse that if it doesn't help.
|
|
|
01-09-2007, 11:44 AM
|
#5
|
LQ Newbie
Registered: Jan 2007
Posts: 10
Original Poster
Rep:
|
Hi experts,
Thanks for all your suggestions. I'm sorry for replying late.
It seems to me that the concept of Universally Unique Identifier (UUID) that 'runnerfrog' suggested is quite close to what i need to know. I have tried to google this concept to get deeper understanding. Thanks!
If you have any more suggestions or explaination, please let me know. Thanks so much for your time.
Best regards,
.viettrung.
|
|
|
01-09-2007, 12:38 PM
|
#6
|
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307
Rep:
|
If its for protection of contents or security measure or whatever copyright thinggy, you have to know that its easy to bypass.
|
|
|
01-09-2007, 02:15 PM
|
#7
|
LQ Newbie
Registered: Jan 2007
Posts: 10
Original Poster
Rep:
|
Thanks so much for your advice, nx5000. I will consider about that.
I have tried to google what UUID is, and know that UUID for disk partition in Linux is just one use of UUID. So I think the library <uuid/uuid.h> may be not particularly used for getting UUID of a disk partition. Now I try to find out the way to get the UUID of current working partition in Linux using C++. I have tried hard with Google, but so far I get no suitable result. Can anybody help?
Thanks in advance.
.viettrung.
|
|
|
01-11-2007, 02:37 AM
|
#8
|
Amigo developer
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928
|
The command 'blkid' will return the UUID label.
|
|
|
01-12-2007, 08:54 AM
|
#9
|
LQ Newbie
Registered: Jan 2007
Posts: 10
Original Poster
Rep:
|
Hi gnashley,
Thank you very much for your suggestion. Actually i also got the same idea from my friend just few minutes before i've read your reply. Thank you!
By the way, i have found a reference of using library libblkid (#include "libblkid/libblkid.h") to get the uuid of a existing partition in Linux: http://thunk.org/hg/e2fsprogs/?f=292...c/libblkid.txt.
i hope it may be helpful for someone who deals with the same matter.
Thank experts for helps so far!
.viettrung.
|
|
|
All times are GMT -5. The time now is 08:05 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|