Read TOC/PMA/ATIP
媒体の種類を取るのに、GET CONFIGURATIONコマンドもあるが、Read TOC/PMA/ATIPコマンドでもそれは可能である。
ググったら、こんなサイトに出会った。さすがはLinux。
Index: linux-2.6.7-ck/Documentation/cdrom/00-INDEXのpkt_media_speed()関数で次のようにしている。
/*
* reads the maximum media speed from ATIP
*/
static int pkt_media_speed(struct pktcdvd_device *pd, unsigned *speed)
{
struct packet_command cgc;
struct request_sense sense;
unsigned char buf[64];
unsigned int size, st, sp;
int ret;
init_cdrom_command(&cgc, buf, 2, CGC_DATA_READ);
cgc.sense = &sense;
cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
cgc.cmd[1] = 2;
cgc.cmd[2] = 4; /* READ ATIP */
cgc.cmd[8] = 2;
ret = pkt_generic_packet(pd, &cgc);
if (ret) {
pkt_dump_sense(&cgc);
return ret;
}
size = ((unsigned int) buf[0]<<8) + buf[1] + 2;
if (size > sizeof(buf))
size = sizeof(buf);
init_cdrom_command(&cgc, buf, size, CGC_DATA_READ);
cgc.sense = &sense;
cgc.cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
cgc.cmd[1] = 2;
cgc.cmd[2] = 4;
cgc.cmd[8] = size;
ret = pkt_generic_packet(pd, &cgc);
if (ret) {
pkt_dump_sense(&cgc);
return ret;
}
if (!buf[6] & 0x40) {
printk("pktcdvd: Disc type is not CD-RW\n");
return 1;
}
if (!buf[6] & 0x4) {
printk("pktcdvd: A1 values on media are not valid, maybe not CDRW?\n");
return 1;
}
st = (buf[6] >> 3) & 0x7; /* disc sub-type */
sp = buf[16] & 0xf; /* max speed from ATIP A1 field */
/* Info from cdrecord */
switch (st) {
case 0: /* standard speed */
*speed = clv_to_speed[sp];
break;
case 1: /* high speed */
*speed = hs_clv_to_speed[sp];
break;
case 2: /* ultra high speed */
*speed = us_clv_to_speed[sp];
break;
default:
printk("pktcdvd: Unknown disc sub-type %d\n",st);
return 1;
}
if (*speed) {
printk("pktcdvd: Max. media speed: %d\n",*speed);
return 0;
} else {
printk("pktcdvd: Unknown speed %d for sub-type %d\n",sp,st);
return 1;
}
}
GET CONFIGURATIONコマンドはCD-RWの速度(Normal/High/Ultra)が取れないので、そのくらいの粒度が必要な場合に使える。また、buffer[6]の落とし方次第で以下のようにも取れる(ようだ)。実際に試していないけど。(w試したら、全然違ったわい!
switch ((buffer[6] >> 6) & 0x01)
{
case 0: // CD-R
case 1: // CD-RW-NS
case 2: // CD-RW-HS
case 3: // CD-RW-US
case 4: // DVD-R
case 5: // DVD-RW
case 6: // DVD+R
case 7: // DVD+RW
}
AnwuLac 说道:骑着 ChromePlus 1.4.1.0 和 Windows 7Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.126 Safari/533.4 ChromePlus/1.4.1.0差不多的吧,void* buf = a+sizeof(struct A);这个写成void* buf = a+1; 这样就可以的。C中的矢量加法,a+1 就表示 指针移动1个单位长度,a的单位是 struct A,就是移动sizeof(struct A)个字节。
Posted by: Mandy | 04 November 2012 at 02:06 AM
Thank you a lot for sharing this with all folks you really recognise what you are speaking about! Bookmarked. Kindly also discuss with my site =). We may have a link trade arrangement between us!
Posted by: onthechallenge.com | 06 November 2013 at 02:47 AM
Do you mind if I quote a few of your posts as long as I provide credit and sources back to your weblog? My blog site is in the very same niche as yours and my visitors would genuinely benefit from a lot of the information you provide here. Please let me know if this ok with you. Thanks!
Posted by: http://groupjk.com | 15 November 2013 at 11:24 AM
I beloved as much as you'll obtain performed right here. The comic strip is tasteful, your authored material stylish. however, you command get got an impatience over that you would like be turning in the following. ill indisputably come further earlier again since exactly the similar nearly a lot ceaselessly inside of case you shield this increase.
Posted by: home kitchen | 24 November 2013 at 05:54 AM
Great site! I am loving it!! Will be back later to read some more. I am bookmarking your feeds also.
Posted by: Russel | 07 December 2013 at 12:57 PM
It is the best time to make some plans for the future and it's time to be happy. I've read this post and if I could I want to suggest you few interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read even more things about it! michael kors outlet online store
Posted by: michael kors outlet online store | 26 April 2014 at 02:52 AM
cheap michael kors,Fans' First Love - Save 80% Off & Easy Return more from:cheap michael kors bags
Posted by: cheap michael kors bags | 26 July 2014 at 02:50 PM
Why people still use to read news papers when in this technological globe the whole thing is available on net?
Posted by: professional integral psx110 | 23 November 2014 at 05:21 AM
Hi, for all time i used to check web site posts here in the early hours in the daylight, as i love to learn more and more.
Posted by: capacity true tmc | 08 December 2014 at 09:43 AM
Good article. I am dealing with many of these issues as well..
Posted by: cookie cutters original | 20 December 2014 at 09:48 AM
whoah this weblog is magnificent i love reading your posts. Keep up the good work! You know, many people are hunting round for this information, you can aid them greatly.
Posted by: plum japanese porcelain | 21 December 2014 at 06:19 AM