MCPcopy Create free account
hub / github.com/PiSCSI/piscsi / ModeSense10

Method ModeSense10

cpp/devices/disk.cpp:311–363  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

309}
310
311int Disk::ModeSense10(cdb_t cdb, vector<uint8_t>& buf) const
312{
313 // Get length, clear buffer
314 const auto length = static_cast<int>(min(buf.size(), static_cast<size_t>(GetInt16(cdb, 7))));
315 fill_n(buf.begin(), length, 0);
316
317 // DEVICE SPECIFIC PARAMETER
318 if (IsProtected()) {
319 buf[3] = 0x80;
320 }
321
322 // Basic Information
323 int size = 8;
324
325 // Add block descriptor if DBD is 0, only if ready
326 if ((cdb[1] & 0x08) == 0 && IsReady()) {
327 uint64_t disk_blocks = GetBlockCount();
328 uint32_t disk_size = GetSectorSizeInBytes();
329
330 // Check LLBAA for short or long block descriptor
331 if ((cdb[1] & 0x10) == 0 || disk_blocks <= 0xFFFFFFFF) {
332 // Mode parameter header, block descriptor length
333 buf[7] = 0x08;
334
335 // Short LBA mode parameter block descriptor (number of blocks and block length)
336 if (disk_blocks > 0xFFFFFFFF)
337 disk_blocks = 0xFFFFFFFF;
338 SetInt32(buf, 8, static_cast<uint32_t>(disk_blocks));
339 SetInt32(buf, 12, disk_size);
340
341 size = 16;
342 }
343 else {
344 // Mode parameter header, LONGLBA
345 buf[4] = 0x01;
346
347 // Mode parameter header, block descriptor length
348 buf[7] = 0x10;
349
350 // Long LBA mode parameter block descriptor (number of blocks and block length)
351 SetInt64(buf, 8, disk_blocks);
352 SetInt32(buf, 20, disk_size);
353
354 size = 24;
355 }
356 }
357
358 size = AddModePages(cdb, buf, size, length, 65535);
359
360 SetInt16(buf, 0, size);
361
362 return size;
363}
364
365void Disk::SetUpModePages(map<int, vector<byte>>& pages, int page, bool changeable) const
366{

Callers

nothing calls this directly

Calls 3

SetInt32Function · 0.85
SetInt16Function · 0.85
GetInt16Function · 0.70

Tested by

no test coverage detected