{"action":"created","issue":{"url":"https://api.github.com/repos/jhermsmeier/node-mbr/issues/4","labels_url":"https://api.github.com/repos/jhermsmeier/node-mbr/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/jhermsmeier/node-mbr/issues/4/comments","events_url":"https://api.github.com/repos/jhermsmeier/node-mbr/issues/4/events","html_url":"https://github.com/jhermsmeier/node-mbr/issues/4","id":74150215,"number":4,"title":"Incorrect firstLBA & sectors in logical partitions","user":{"login":"jviotti","id":2192773,"avatar_url":"https://avatars.githubusercontent.com/u/2192773?v=3","gravatar_id":"","url":"https://api.github.com/users/jviotti","html_url":"https://github.com/jviotti","followers_url":"https://api.github.com/users/jviotti/followers","following_url":"https://api.github.com/users/jviotti/following{/other_user}","gists_url":"https://api.github.com/users/jviotti/gists{/gist_id}","starred_url":"https://api.github.com/users/jviotti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jviotti/subscriptions","organizations_url":"https://api.github.com/users/jviotti/orgs","repos_url":"https://api.github.com/users/jviotti/repos","events_url":"https://api.github.com/users/jviotti/events{/privacy}","received_events_url":"https://api.github.com/users/jviotti/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-07T22:33:34Z","updated_at":"2015-05-07T22:37:56Z","closed_at":null,"body":"Hi, I have a disk with the following partitions:\r\n\r\n```sh\r\n$ fdisk ~/Desktop/resin.img\r\nDisk: /Users/jviotti/Desktop/resin.img\tgeometry: 717/64/63 [2891776 sectors]\r\nSignature: 0xAA55\r\n         Starting       Ending\r\n #: id  cyl  hd sec -  cyl  hd sec [     start -       size]\r\n------------------------------------------------------------------------\r\n 1: 0C 1023 254  63 - 1023 254  63 [      8192 -      40960] Win95 FAT32L\r\n 2: 83 1023 254  63 - 1023 254  63 [     49152 -     360448] Linux files*\r\n 3: 83 1023 254  63 - 1023 254  63 [    409600 -     360448] Linux files*\r\n 4: 05 1023 254  63 - 1023 254  63 [    770048 -    2121728] Extended DOS\r\nSignature: 0xAA55\r\n         Starting       Ending\r\n #: id  cyl  hd sec -  cyl  hd sec [     start -       size]\r\n------------------------------------------------------------------------\r\n*1: 0B 1023 254  63 - 1023 254  63 [    778240 -       8192] Win95 FAT-32\r\n 2: 05 1023 254  63 - 1023 254  63 [    786432 -    2105344] Extended DOS\r\n 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused\r\n 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused\r\nSignature: 0xAA55\r\n         Starting       Ending\r\n #: id  cyl  hd sec -  cyl  hd sec [     start -       size]\r\n------------------------------------------------------------------------\r\n 1: 83 1023 254  63 - 1023 254  63 [    794624 -    2097152] Linux files*\r\n 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused\r\n 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused\r\n 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused\r\n```\r\n\r\nParsing the MBR returns the correct `firstLBA` for the primary partitions:\r\n\r\n```sh\r\n  partitions:\r\n   [ { status: 0,\r\n       type: 12,\r\n       sectors: 40960,\r\n       firstLBA: 8192,\r\n       firstCHS: <CHS { cylinder: 0, head: 0, sector: 0 }>,\r\n       lastCHS: <CHS { cylinder: 0, head: 0, sector: 0 }> },\r\n     { status: 0,\r\n       type: 131,\r\n       sectors: 360448,\r\n       firstLBA: 49152,\r\n       firstCHS: <CHS { cylinder: 0, head: 0, sector: 0 }>,\r\n       lastCHS: <CHS { cylinder: 0, head: 0, sector: 0 }> },\r\n     { status: 0,\r\n       type: 131,\r\n       sectors: 360448,\r\n       firstLBA: 409600,\r\n       firstCHS: <CHS { cylinder: 0, head: 0, sector: 0 }>,\r\n       lastCHS: <CHS { cylinder: 0, head: 0, sector: 0 }> },\r\n     { status: 0,\r\n       type: 5,\r\n       sectors: 2121728,\r\n       firstLBA: 770048,\r\n       firstCHS: <CHS { cylinder: 0, head: 0, sector: 0 }>,\r\n       lastCHS: <CHS { cylinder: 0, head: 0, sector: 0 }> } ],\r\n```\r\n\r\nThis perfectly matches `fdisk`:\r\n\r\n```sh\r\n #: id  cyl  hd sec -  cyl  hd sec [     start -       size]\r\n------------------------------------------------------------------------\r\n 1: 0C 1023 254  63 - 1023 254  63 [      8192 -      40960] Win95 FAT32L\r\n 2: 83 1023 254  63 - 1023 254  63 [     49152 -     360448] Linux files*\r\n 3: 83 1023 254  63 - 1023 254  63 [    409600 -     360448] Linux files*\r\n 4: 05 1023 254  63 - 1023 254  63 [    770048 -    2121728] Extended DOS\r\n```\r\n\r\nI happen to know the fourth partition is an extended partition. Reading it's EBR returns:\r\n\r\n```sh\r\n  partitions:\r\n   [ { status: 0,\r\n       type: 12,\r\n       sectors: 40960,\r\n       firstLBA: 8192,\r\n       firstCHS: <CHS { cylinder: 0, head: 0, sector: 0 }>,\r\n       lastCHS: <CHS { cylinder: 0, head: 0, sector: 0 }> },\r\n     { status: 0,\r\n       type: 131,\r\n       sectors: 360448,\r\n       firstLBA: 49152,\r\n       firstCHS: <CHS { cylinder: 0, head: 0, sector: 0 }>,\r\n       lastCHS: <CHS { cylinder: 0, head: 0, sector: 0 }> },\r\n     { status: 0,\r\n       type: 131,\r\n       sectors: 360448,\r\n       firstLBA: 409600,\r\n       firstCHS: <CHS { cylinder: 0, head: 0, sector: 0 }>,\r\n       lastCHS: <CHS { cylinder: 0, head: 0, sector: 0 }> },\r\n     { status: 0,\r\n       type: 5,\r\n       sectors: 2121728,\r\n       firstLBA: 770048,\r\n       firstCHS: <CHS { cylinder: 0, head: 0, sector: 0 }>,\r\n       lastCHS: <CHS { cylinder: 0, head: 0, sector: 0 }> } ],\r\n```\r\n\r\nNow compare that to the output of `fdisk`:\r\n\r\n```sh\r\n         Starting       Ending\r\n #: id  cyl  hd sec -  cyl  hd sec [     start -       size]\r\n------------------------------------------------------------------------\r\n*1: 0B 1023 254  63 - 1023 254  63 [    778240 -       8192] Win95 FAT-32\r\n 2: 05 1023 254  63 - 1023 254  63 [    786432 -    2105344] Extended DOS\r\n 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused\r\n 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused\r\nSignature: 0xAA55\r\n         Starting       Ending\r\n #: id  cyl  hd sec -  cyl  hd sec [     start -       size]\r\n------------------------------------------------------------------------\r\n 1: 83 1023 254  63 - 1023 254  63 [    794624 -    2097152] Linux files*\r\n 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused\r\n 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused\r\n 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused\r\n```\r\n\r\nThe first logical partition says:\r\n\r\n```\r\n       sectors: 40960,\r\n       firstLBA: 8192,\r\n```\r\n\r\nAssuming the returned `firstLBA` is relative to the primary partitions `firstLBA`, I get `770048 + 8192 = 778240`.\r\n\r\n`fdisk` says:\r\n\r\n```sh\r\n*1: 0B 1023 254  63 - 1023 254  63 [    778240 -       8192] Win95 FAT-32\r\n```\r\n\r\nThe start offset clearly matches, however `fdisk` says the size is `8192`, while `node-mgr` says `40960`.\r\n\r\nThe second logical partition says:\r\n\r\n```\r\n       sectors: 360448,\r\n       firstLBA: 49152,\r\n```\r\n\r\nIf I take the second logical partition `firstLBA`, assuming is relative I get `770048 + 49152 = 819200`, which doesn't match `fdisk`:\r\n\r\n```sh\r\n 2: 05 1023 254  63 - 1023 254  63 [    786432 -    2105344] Extended DOS\r\n```\r\n\r\nAnd so on with the following logical partitions.\r\n\r\nAm I doing anything wrong?\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/jhermsmeier/node-mbr/issues/comments/100039565","html_url":"https://github.com/jhermsmeier/node-mbr/issues/4#issuecomment-100039565","issue_url":"https://api.github.com/repos/jhermsmeier/node-mbr/issues/4","id":100039565,"user":{"login":"jviotti","id":2192773,"avatar_url":"https://avatars.githubusercontent.com/u/2192773?v=3","gravatar_id":"","url":"https://api.github.com/users/jviotti","html_url":"https://github.com/jviotti","followers_url":"https://api.github.com/users/jviotti/followers","following_url":"https://api.github.com/users/jviotti/following{/other_user}","gists_url":"https://api.github.com/users/jviotti/gists{/gist_id}","starred_url":"https://api.github.com/users/jviotti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jviotti/subscriptions","organizations_url":"https://api.github.com/users/jviotti/orgs","repos_url":"https://api.github.com/users/jviotti/repos","events_url":"https://api.github.com/users/jviotti/events{/privacy}","received_events_url":"https://api.github.com/users/jviotti/received_events","type":"User","site_admin":false},"created_at":"2015-05-07T22:37:56Z","updated_at":"2015-05-07T22:37:56Z","body":"I've uploaded the *.img file to Dropbox in case you want to experiment with it yourself: https://dl.dropboxusercontent.com/u/18129309/resin.img."}}