Solved

To know the disks block size, should i use "Read capacity" or "Mode sense" command?

Posted on 2011-02-17
7
838 Views
Last Modified: 2012-05-11
Hi,

The block size of a SCSI disk is stored in one of the Mode pages. Now if i want to know the disk's block size, what is the difference between firing a mode sense command and reading that particular page and issuing a read capacity command? Are they both same?
0
Comment
Question by:raj_ksrt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 47

Expert Comment

by:dlethe
ID: 34915571

The purposes of the READ capacity is to tell you the NUMBER of blocks.  The block headers returned with ANY mode sense command will give you the block size (I.e, # of bytes per block).  So go with READ CAPACITY and get both.

Warning, there is also a READ CAPACITY(16) which is required for HDDs > then 2TB.
0
 
LVL 47

Expert Comment

by:dlethe
ID: 34915792
Sorry gave you some bad info ... in penance ... here is some code that will work (replace the SCSIME with whatever passthrough mechanism for your O/S.
The X8ToU64 converts a sequence of 8 bytes where byte0 is most significant into 64bit unsigned number.

This shows how to fall back with a 16-byte command if the disk is larger than what can be returned in a 10-byte CDB.  

Note you have to add 1 because the sneaky commands return HIGHEST block #, not total # of blocks.



    CDB_T           CDB;
    Sense_T  Sense;
    int             status;
    U8              CapData[8],CapDataLong[12];
    U64             Total,Work;
    U32             U32BlockCount;
    U32             U32BlockLength;

    memset(CDB,0,sizeof(CDB));
    CDB[0] = READ_CAPACITY10;
    status = SCSIME(Read,CDB,10,CapData,8,&Sense);
    if (status == 0) {  /* This didn't work before 1.24 in LINUX if really big. It works now */
        U32BlockCount =  ((U32)CapData[0] * 0x1000000) + ((U32)CapData[1] * 0x10000) + ((U32)CapData[2] * 0x100) + (U32)CapData[3];
        U32BlockLength = ((U32)CapData[4] * 0x1000000) + ((U32)CapData[5] * 0x10000) + ((U32)CapData[6] * 0x100) + (U32)CapData[7];
        if (U32BlockCount != 0xffffffff) {
            ++U32BlockCount;        /*  This returns highest block number, need to add 1 for # of blocks */
            Total = U32BlockLength;
            Total *= 0x1000000000000LL;
            Total += U32BlockCount;
            return (Total);
        }
        memset(CDB,0,sizeof(CDB));
        memset(CapDataLong,0,sizeof(CapDataLong));
        CDB[0] = 0x9e;              /* SERVICE ACTION IN(16) */
        CDB[1] = 0x10;              /* READ_CAPACITY(16) OPCODE */
        status = SCSIME(Read,CDB,16,CapDataLong,12,&Sense);
        if (status == 0) {
            Work = X8ToU64(CapDataLong,8);
            ++Work;     /*  highest block # needs to change to # of blocks */
            U32BlockLength = ((U32)CapDataLong[8] * 0x1000000) + ((U32)CapDataLong[9] * 0x10000) + ((U32)CapDataLong[10] * 0x100) + (U32)CapDataLong[11];
            Total = U32BlockLength;
            Total *= 0x100000000000LL;
            Total += Work;      /* this is correct, I am not multiplying in what I send back */
            return (Total);
        }
    }   /* This can fail if reservation conflict, or if 16-byte CDB not supported */
    return FALSE;
}
0
 

Author Comment

by:raj_ksrt
ID: 34940560
Hi dlethe,

THanks for your reply. Although it kind of gave me some info, but didn't exactly answer my question.

I'll rephrase my question to make it more to the point.

The "Read capacity" and "mode sense" commands both can be used to find the block size of a SCSI disk. Now is there any specific situation in which only "Read Capacity"  should be used for knowing the block size? or is there a situation where only "mode sense" command should be used??
0
Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

 
LVL 47

Expert Comment

by:dlethe
ID: 34941722
What if capacity is greater than 2.09TB and/or you have one of the disks that has 4KB sector size, or are attached to a large virtual drive?  You have to use the Read Capacity(16), then fall back on the Read capacity(10).  No other way to do it.  

     
0
 

Author Comment

by:raj_ksrt
ID: 34942060
SO can i conclude that for disks with huge size ( e.g. more than 2.0 TB), i can't use "mode sense" command to find out the block size of the disk?? and that's where i'll need "Read Capacity" comamnd?
0
 
LVL 47

Accepted Solution

by:
dlethe earned 125 total points
ID: 34943547
I just double-checked the spec, to remind me why I didn't use the mode sense when it was convenient in my code when I deal with disks with block count < 0xFFFFFFFF blocks.
This quote is from the ANSI SCSI spec itself,

"Support for the mode parameter block descriptors is optional."

There you have it.  The block header support is OPTIONAL.  Your code will break when you use it on devices that do not support the block headers.  You MUST use the READ CAPACITY command if you want your code to always work. READ CAPACITY is required, block headers.  Now I remember, I got burned one time years ago by a device that chose not to support the headers.

You MUST use the READ CAPACITY.  Period. Or your code will eventually break.
0
 

Author Comment

by:raj_ksrt
ID: 34948792
Thanks!!. That answers my question...
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
This Micro Tutorial will teach you how to reformat your flash drive. Sometimes your flash drive may have issues carrying files so this will completely restore it to manufacturing settings. Make sure to backup all files before reformatting. This w…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question