LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 02-27-2018, 06:06 AM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
Reading an sd card id in c


Hi All,
can anyone show me how to read the CID from a sd card in c(++) code? I've searched and found how to using cat /sys/block/mmcblk0/device/cid but can't find anyway in C. I could use system but don't know how I'd get the id numbers from that.
Thanks for the advise.
 
Old 02-27-2018, 06:33 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
From within your program will you know the file to access all the time? Because you can use open() or fopen() from within the C program to open any file on the system, and then read from it. What I typically find is that I have to also do some in program research to find the correct file, because you can have stuff like /dev/sda1, or /dev/sdb2, and so forth and you want the correct reference file.
 
Old 02-27-2018, 08:03 AM   #3
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Original Poster
Rep: Reputation: 43
Thanks but I'm unsure how I can read the CID from that?
 
Old 02-27-2018, 08:13 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
What exactly do you not understand? How to open a file and read it using C?
 
Old 02-27-2018, 08:17 AM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,777

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by knobby67 View Post
I've searched and found how to using cat /sys/block/mmcblk0/device/cid but can't find anyway in C.
Since you appear to know the file name, you can open that file in C with open() or fopen() just as you could any other file.
 
Old 02-28-2018, 09:09 AM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939
Quote:
Originally Posted by rknichols View Post
Since you appear to know the file name, you can open that file in C with open() or fopen() just as you could any other file.
And that would be "the way to do it in Linux."

All of these so-called "pseudo file-systems" are, in fact, a kernel API. This is the (only) way that the kernel presents this information to you. When you "open and read from" one of these "files" – and/or in some cases "write to" them – you are communicating with a kernel interface that is presenting data to you in text form.
 
Old 02-28-2018, 09:31 AM   #7
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Original Poster
Rep: Reputation: 43
Thanks All. Thought I could use open.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SIM Card reading software? gbowden Slackware 4 10-15-2017 05:44 AM
Reading SD Card mickeyboa Fedora 4 12-18-2009 09:57 AM
problem in reading my SDHC card ! beta-tester Linux - Hardware 1 09-28-2009 08:44 PM
fedora smart card reading haxpak Linux - Newbie 0 01-24-2009 11:20 PM
USB SD Card Reading Issues Matir Linux - Hardware 3 06-07-2007 08:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration