Solved

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

Posted on 2011-02-17
7
825 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
  • 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

AWS Glacier is Amazons cheapest storage option and is their answer to a ‘Cold’ storage service.  Customers primarily use this service for archival purposes and storage of infrastructure backups.  Its unlimited storage potential and low storage cost …
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
This video teaches viewers how to encrypt an external drive that requires a password to read and edit the drive. All tasks are done in Disk Utility. Plug in the external drive you wish to encrypt: Make sure all previous data on the drive has been …
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…

803 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