LinuxQuestions.org
Help answer threads with 0 replies.
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: 622

Rep: Reputation: 42
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: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 6,709
Blog Entries: 12

Rep: Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360
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: 622

Original Poster
Rep: Reputation: 42
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: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 6,709
Blog Entries: 12

Rep: Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360Reputation: 2360
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: CentOS
Posts: 3,905

Rep: Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683Reputation: 1683
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: 9,078
Blog Entries: 4

Rep: Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165
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: 622

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 05:28 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration