Ticket #915: ticket-915.patch

File ticket-915.patch, 5.4 KB (added by Christian Franke, 2 years ago)

Proposed patch for atacmds.cpp: replace swapx(&x) by SWAPV(x)

  • atacmds.cpp

     
    339339  return;
    340340}
    341341
     342// When using the overloaded swapx() function with member of packed ATA structs,
     343// it is required to pass a possibly unaligned pointer as argument.
     344// Clang++ 4.0 prints -Waddress-of-packed-member warning in this case.
     345// The SWAPV() macro below is a replacement which prevents the use of such pointers.
     346template <typename T>
     347static T get_swapx_val(T x)
     348  { swapx(&x); return x; }
     349
     350#define SWAPV(x)  ((x) = get_swapx_val(x))
     351
    342352// Invalidate serial number and WWN and adjust checksum in IDENTIFY data
    343353static void invalidate_serno(ata_identify_device * id)
    344354{
     
    355365#ifndef __NetBSD__
    356366  bool must_swap = !!isbigendian();
    357367  if (must_swap)
    358     swapx(id->words088_255+255-88);
     368    SWAPV(id->words088_255[255-88]);
    359369#endif
    360370  if ((id->words088_255[255-88] & 0x00ff) == 0x00a5)
    361371    id->words088_255[255-88] += sum << 8;
    362372#ifndef __NetBSD__
    363373  if (must_swap)
    364     swapx(id->words088_255+255-88);
     374    SWAPV(id->words088_255[255-88]);
    365375#endif
    366376}
    367377
     
    10011011    swap2((char *)&(data->revnumber));
    10021012    swap2((char *)&(data->total_time_to_complete_off_line));
    10031013    swap2((char *)&(data->smart_capability));
    1004     swapx(&data->extend_test_completion_time_w);
     1014    SWAPV(data->extend_test_completion_time_w);
    10051015    for (i=0; i<NUMBER_ATA_SMART_ATTRIBUTES; i++){
    10061016      struct ata_smart_attribute *x=data->vendor_attributes+i;
    10071017      swap2((char *)&(x->flags));
     
    10881098  check_multi_sector_sum(log, nsectors, "SMART Extended Self-test Log Structure");
    10891099
    10901100  if (isbigendian()) {
    1091     swapx(&log->log_desc_index);
     1101    SWAPV(log->log_desc_index);
    10921102    for (unsigned i = 0; i < nsectors; i++) {
    10931103      for (unsigned j = 0; j < 19; j++)
    1094         swapx(&log->log_descs[i].timestamp);
     1104        SWAPV(log->log_descs[i].timestamp);
    10951105    }
    10961106  }
    10971107  return true;
     
    11951205
    11961206  // swap endian order if needed
    11971207  if (isbigendian())
    1198     swapx(&data->logversion);
     1208    SWAPV(data->logversion);
    11991209
    12001210  return 0;
    12011211}
     
    15181528  check_multi_sector_sum(log, nsectors, "SMART Extended Comprehensive Error Log Structure");
    15191529
    15201530  if (isbigendian()) {
    1521     swapx(&log->device_error_count);
    1522     swapx(&log->error_log_index);
     1531    SWAPV(log->device_error_count);
     1532    SWAPV(log->error_log_index);
    15231533    for (unsigned i = 0; i < nsectors; i++) {
    15241534      for (unsigned j = 0; j < 4; j++) {
    15251535        for (unsigned k = 0; k < 5; k++)
    1526            swapx(&log[i].error_logs[j].commands[k].timestamp);
    1527         swapx(&log[i].error_logs[j].error.timestamp);
     1536           SWAPV(log[i].error_logs[j].commands[k].timestamp);
     1537        SWAPV(log[i].error_logs[j].error.timestamp);
    15281538      }
    15291539    }
    15301540  }
     
    22572267
    22582268  // swap endian order if needed
    22592269  if (isbigendian()){
    2260     swapx(&sts->format_version);
    2261     swapx(&sts->sct_version);
    2262     swapx(&sts->sct_spec);
    2263     swapx(&sts->ext_status_code);
    2264     swapx(&sts->action_code);
    2265     swapx(&sts->function_code);
    2266     swapx(&sts->over_limit_count);
    2267     swapx(&sts->under_limit_count);
    2268     swapx(&sts->smart_status);
    2269     swapx(&sts->min_erc_time);
     2270    SWAPV(sts->format_version);
     2271    SWAPV(sts->sct_version);
     2272    SWAPV(sts->sct_spec);
     2273    SWAPV(sts->ext_status_code);
     2274    SWAPV(sts->action_code);
     2275    SWAPV(sts->function_code);
     2276    SWAPV(sts->over_limit_count);
     2277    SWAPV(sts->under_limit_count);
     2278    SWAPV(sts->smart_status);
     2279    SWAPV(sts->min_erc_time);
    22702280  }
    22712281
    22722282  // Check format version
     
    22992309
    23002310  // swap endian order if needed
    23012311  if (isbigendian()) {
    2302     swapx(&cmd.action_code);
    2303     swapx(&cmd.function_code);
    2304     swapx(&cmd.table_id);
     2312    SWAPV(cmd.action_code);
     2313    SWAPV(cmd.function_code);
     2314    SWAPV(cmd.table_id);
    23052315  }
    23062316
    23072317  // write command via SMART log page 0xe0
     
    23292339
    23302340  // swap endian order if needed
    23312341  if (isbigendian()){
    2332     swapx(&tmh->format_version);
    2333     swapx(&tmh->sampling_period);
    2334     swapx(&tmh->interval);
    2335     swapx(&tmh->cb_index);
    2336     swapx(&tmh->cb_size);
     2342    SWAPV(tmh->format_version);
     2343    SWAPV(tmh->sampling_period);
     2344    SWAPV(tmh->interval);
     2345    SWAPV(tmh->cb_index);
     2346    SWAPV(tmh->cb_size);
    23372347  }
    23382348  return 0;
    23392349}
     
    23662376
    23672377  // swap endian order if needed
    23682378  if (isbigendian()) {
    2369     swapx(&cmd.action_code);
    2370     swapx(&cmd.function_code);
    2371     swapx(&cmd.feature_code);
    2372     swapx(&cmd.state);
    2373     swapx(&cmd.option_flags);
     2379    SWAPV(cmd.action_code);
     2380    SWAPV(cmd.function_code);
     2381    SWAPV(cmd.feature_code);
     2382    SWAPV(cmd.state);
     2383    SWAPV(cmd.option_flags);
    23742384  }
    23752385
    23762386  // write command via SMART log page 0xe0
     
    24462456
    24472457  // swap endian order if needed
    24482458  if (isbigendian()) {
    2449     swapx(&cmd.action_code);
    2450     swapx(&cmd.function_code);
    2451     swapx(&cmd.feature_code);
    2452     swapx(&cmd.state);
    2453     swapx(&cmd.option_flags);
     2459    SWAPV(cmd.action_code);
     2460    SWAPV(cmd.function_code);
     2461    SWAPV(cmd.feature_code);
     2462    SWAPV(cmd.state);
     2463    SWAPV(cmd.option_flags);
    24542464  }
    24552465
    24562466  // write command via SMART log page 0xe0
     
    24982508
    24992509  // swap endian order if needed
    25002510  if (isbigendian()) {
    2501     swapx(&cmd.action_code);
    2502     swapx(&cmd.function_code);
    2503     swapx(&cmd.selection_code);
    2504     swapx(&cmd.time_limit);
     2511    SWAPV(cmd.action_code);
     2512    SWAPV(cmd.function_code);
     2513    SWAPV(cmd.selection_code);
     2514    SWAPV(cmd.time_limit);
    25052515  }
    25062516
    25072517  // write command via SMART log page 0xe0