storage_common.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. /*
  2. * storage_common.c -- Common definitions for mass storage functionality
  3. *
  4. * Copyright (C) 2003-2008 Alan Stern
  5. * Copyeight (C) 2009 Samsung Electronics
  6. * Author: Michal Nazarewicz (m.nazarewicz@samsung.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. /*
  23. * This file requires the following identifiers used in USB strings to
  24. * be defined (each of type pointer to char):
  25. * - fsg_string_manufacturer -- name of the manufacturer
  26. * - fsg_string_product -- name of the product
  27. * - fsg_string_serial -- product's serial
  28. * - fsg_string_config -- name of the configuration
  29. * - fsg_string_interface -- name of the interface
  30. * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS
  31. * macro is defined prior to including this file.
  32. */
  33. #include <asm/unaligned.h>
  34. /*-------------------------------------------------------------------------*/
  35. #ifndef DEBUG
  36. #undef VERBOSE_DEBUG
  37. #undef DUMP_MSGS
  38. #endif /* !DEBUG */
  39. #ifdef VERBOSE_DEBUG
  40. #define VLDBG LDBG
  41. #else
  42. #define VLDBG(lun, fmt, args...) do { } while (0)
  43. #endif /* VERBOSE_DEBUG */
  44. #define LDBG(lun, fmt, args...) dev_dbg (&(lun)->dev, fmt, ## args)
  45. #define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args)
  46. #define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args)
  47. #define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args)
  48. #define DBG(d, fmt, args...) dev_dbg (&(d)->gadget->dev, fmt, ## args)
  49. #define VDBG(d, fmt, args...) dev_vdbg(&(d)->gadget->dev, fmt, ## args)
  50. #define ERROR(d, fmt, args...) dev_err (&(d)->gadget->dev, fmt, ## args)
  51. #define WARNING(d, fmt, args...) dev_warn(&(d)->gadget->dev, fmt, ## args)
  52. #define INFO(d, fmt, args...) dev_info(&(d)->gadget->dev, fmt, ## args)
  53. #ifdef DUMP_MSGS
  54. # define dump_msg(fsg, /* const char * */ label, \
  55. /* const u8 * */ buf, /* unsigned */ length) do { \
  56. if (length < 512) { \
  57. DBG(fsg, "%s, length %u:\n", label, length); \
  58. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \
  59. 16, 1, buf, length, 0); \
  60. } \
  61. } while (0)
  62. # define dump_cdb(fsg) do { } while (0)
  63. #else
  64. # define dump_msg(fsg, /* const char * */ label, \
  65. /* const u8 * */ buf, /* unsigned */ length) do { } while (0)
  66. # ifdef VERBOSE_DEBUG
  67. #define dump_cdb(fsg) \
  68. print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \
  69. 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \
  70. # else
  71. # define dump_cdb(fsg) do { } while (0)
  72. # endif /* VERBOSE_DEBUG */
  73. #endif /* DUMP_MSGS */
  74. /*-------------------------------------------------------------------------*/
  75. /* SCSI device types */
  76. #define TYPE_DISK 0x00
  77. #define TYPE_CDROM 0x05
  78. /* USB protocol value = the transport method */
  79. #define USB_PR_CBI 0x00 // Control/Bulk/Interrupt
  80. #define USB_PR_CB 0x01 // Control/Bulk w/o interrupt
  81. #define USB_PR_BULK 0x50 // Bulk-only
  82. /* USB subclass value = the protocol encapsulation */
  83. #define USB_SC_RBC 0x01 // Reduced Block Commands (flash)
  84. #define USB_SC_8020 0x02 // SFF-8020i, MMC-2, ATAPI (CD-ROM)
  85. #define USB_SC_QIC 0x03 // QIC-157 (tape)
  86. #define USB_SC_UFI 0x04 // UFI (floppy)
  87. #define USB_SC_8070 0x05 // SFF-8070i (removable)
  88. #define USB_SC_SCSI 0x06 // Transparent SCSI
  89. /* Bulk-only data structures */
  90. /* Command Block Wrapper */
  91. struct fsg_bulk_cb_wrap {
  92. __le32 Signature; // Contains 'USBC'
  93. u32 Tag; // Unique per command id
  94. __le32 DataTransferLength; // Size of the data
  95. u8 Flags; // Direction in bit 7
  96. u8 Lun; // LUN (normally 0)
  97. u8 Length; // Of the CDB, <= MAX_COMMAND_SIZE
  98. u8 CDB[16]; // Command Data Block
  99. };
  100. #define USB_BULK_CB_WRAP_LEN 31
  101. #define USB_BULK_CB_SIG 0x43425355 // Spells out USBC
  102. #define USB_BULK_IN_FLAG 0x80
  103. /* Command Status Wrapper */
  104. struct bulk_cs_wrap {
  105. __le32 Signature; // Should = 'USBS'
  106. u32 Tag; // Same as original command
  107. __le32 Residue; // Amount not transferred
  108. u8 Status; // See below
  109. };
  110. #define USB_BULK_CS_WRAP_LEN 13
  111. #define USB_BULK_CS_SIG 0x53425355 // Spells out 'USBS'
  112. #define USB_STATUS_PASS 0
  113. #define USB_STATUS_FAIL 1
  114. #define USB_STATUS_PHASE_ERROR 2
  115. /* Bulk-only class specific requests */
  116. #define USB_BULK_RESET_REQUEST 0xff
  117. #define USB_BULK_GET_MAX_LUN_REQUEST 0xfe
  118. /* CBI Interrupt data structure */
  119. struct interrupt_data {
  120. u8 bType;
  121. u8 bValue;
  122. };
  123. #define CBI_INTERRUPT_DATA_LEN 2
  124. /* CBI Accept Device-Specific Command request */
  125. #define USB_CBI_ADSC_REQUEST 0x00
  126. #define MAX_COMMAND_SIZE 16 // Length of a SCSI Command Data Block
  127. /* SCSI commands that we recognize */
  128. #define SC_FORMAT_UNIT 0x04
  129. #define SC_INQUIRY 0x12
  130. #define SC_MODE_SELECT_6 0x15
  131. #define SC_MODE_SELECT_10 0x55
  132. #define SC_MODE_SENSE_6 0x1a
  133. #define SC_MODE_SENSE_10 0x5a
  134. #define SC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
  135. #define SC_READ_6 0x08
  136. #define SC_READ_10 0x28
  137. #define SC_READ_12 0xa8
  138. #define SC_READ_CAPACITY 0x25
  139. #define SC_READ_FORMAT_CAPACITIES 0x23
  140. #define SC_READ_HEADER 0x44
  141. #define SC_READ_TOC 0x43
  142. #define SC_RELEASE 0x17
  143. #define SC_REQUEST_SENSE 0x03
  144. #define SC_RESERVE 0x16
  145. #define SC_SEND_DIAGNOSTIC 0x1d
  146. #define SC_START_STOP_UNIT 0x1b
  147. #define SC_SYNCHRONIZE_CACHE 0x35
  148. #define SC_TEST_UNIT_READY 0x00
  149. #define SC_VERIFY 0x2f
  150. #define SC_WRITE_6 0x0a
  151. #define SC_WRITE_10 0x2a
  152. #define SC_WRITE_12 0xaa
  153. /* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
  154. #define SS_NO_SENSE 0
  155. #define SS_COMMUNICATION_FAILURE 0x040800
  156. #define SS_INVALID_COMMAND 0x052000
  157. #define SS_INVALID_FIELD_IN_CDB 0x052400
  158. #define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100
  159. #define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500
  160. #define SS_MEDIUM_NOT_PRESENT 0x023a00
  161. #define SS_MEDIUM_REMOVAL_PREVENTED 0x055302
  162. #define SS_NOT_READY_TO_READY_TRANSITION 0x062800
  163. #define SS_RESET_OCCURRED 0x062900
  164. #define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900
  165. #define SS_UNRECOVERED_READ_ERROR 0x031100
  166. #define SS_WRITE_ERROR 0x030c02
  167. #define SS_WRITE_PROTECTED 0x072700
  168. #define SK(x) ((u8) ((x) >> 16)) // Sense Key byte, etc.
  169. #define ASC(x) ((u8) ((x) >> 8))
  170. #define ASCQ(x) ((u8) (x))
  171. /*-------------------------------------------------------------------------*/
  172. struct fsg_lun {
  173. struct file *filp;
  174. loff_t file_length;
  175. loff_t num_sectors;
  176. unsigned int ro : 1;
  177. unsigned int prevent_medium_removal : 1;
  178. unsigned int registered : 1;
  179. unsigned int info_valid : 1;
  180. u32 sense_data;
  181. u32 sense_data_info;
  182. u32 unit_attention_data;
  183. struct device dev;
  184. };
  185. #define fsg_lun_is_open(curlun) ((curlun)->filp != NULL)
  186. static struct fsg_lun *fsg_lun_from_dev(struct device *dev)
  187. {
  188. return container_of(dev, struct fsg_lun, dev);
  189. }
  190. /* Big enough to hold our biggest descriptor */
  191. #define EP0_BUFSIZE 256
  192. #define DELAYED_STATUS (EP0_BUFSIZE + 999) // An impossibly large value
  193. /* Number of buffers we will use. 2 is enough for double-buffering */
  194. #define FSG_NUM_BUFFERS 2
  195. enum fsg_buffer_state {
  196. BUF_STATE_EMPTY = 0,
  197. BUF_STATE_FULL,
  198. BUF_STATE_BUSY
  199. };
  200. struct fsg_buffhd {
  201. void *buf;
  202. enum fsg_buffer_state state;
  203. struct fsg_buffhd *next;
  204. /* The NetChip 2280 is faster, and handles some protocol faults
  205. * better, if we don't submit any short bulk-out read requests.
  206. * So we will record the intended request length here. */
  207. unsigned int bulk_out_intended_length;
  208. struct usb_request *inreq;
  209. int inreq_busy;
  210. struct usb_request *outreq;
  211. int outreq_busy;
  212. };
  213. enum fsg_state {
  214. FSG_STATE_COMMAND_PHASE = -10, // This one isn't used anywhere
  215. FSG_STATE_DATA_PHASE,
  216. FSG_STATE_STATUS_PHASE,
  217. FSG_STATE_IDLE = 0,
  218. FSG_STATE_ABORT_BULK_OUT,
  219. FSG_STATE_RESET,
  220. FSG_STATE_INTERFACE_CHANGE,
  221. FSG_STATE_CONFIG_CHANGE,
  222. FSG_STATE_DISCONNECT,
  223. FSG_STATE_EXIT,
  224. FSG_STATE_TERMINATED
  225. };
  226. enum data_direction {
  227. DATA_DIR_UNKNOWN = 0,
  228. DATA_DIR_FROM_HOST,
  229. DATA_DIR_TO_HOST,
  230. DATA_DIR_NONE
  231. };
  232. /*-------------------------------------------------------------------------*/
  233. static inline u32 get_unaligned_be24(u8 *buf)
  234. {
  235. return 0xffffff & (u32) get_unaligned_be32(buf - 1);
  236. }
  237. /*-------------------------------------------------------------------------*/
  238. enum {
  239. FSG_STRING_MANUFACTURER = 1,
  240. FSG_STRING_PRODUCT,
  241. FSG_STRING_SERIAL,
  242. FSG_STRING_CONFIG,
  243. FSG_STRING_INTERFACE
  244. };
  245. static struct usb_otg_descriptor
  246. fsg_otg_desc = {
  247. .bLength = sizeof fsg_otg_desc,
  248. .bDescriptorType = USB_DT_OTG,
  249. .bmAttributes = USB_OTG_SRP,
  250. };
  251. /* There is only one interface. */
  252. static struct usb_interface_descriptor
  253. fsg_intf_desc = {
  254. .bLength = sizeof fsg_intf_desc,
  255. .bDescriptorType = USB_DT_INTERFACE,
  256. .bNumEndpoints = 2, // Adjusted during fsg_bind()
  257. .bInterfaceClass = USB_CLASS_MASS_STORAGE,
  258. .bInterfaceSubClass = USB_SC_SCSI, // Adjusted during fsg_bind()
  259. .bInterfaceProtocol = USB_PR_BULK, // Adjusted during fsg_bind()
  260. .iInterface = FSG_STRING_INTERFACE,
  261. };
  262. /* Three full-speed endpoint descriptors: bulk-in, bulk-out,
  263. * and interrupt-in. */
  264. static struct usb_endpoint_descriptor
  265. fsg_fs_bulk_in_desc = {
  266. .bLength = USB_DT_ENDPOINT_SIZE,
  267. .bDescriptorType = USB_DT_ENDPOINT,
  268. .bEndpointAddress = USB_DIR_IN,
  269. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  270. /* wMaxPacketSize set by autoconfiguration */
  271. };
  272. static struct usb_endpoint_descriptor
  273. fsg_fs_bulk_out_desc = {
  274. .bLength = USB_DT_ENDPOINT_SIZE,
  275. .bDescriptorType = USB_DT_ENDPOINT,
  276. .bEndpointAddress = USB_DIR_OUT,
  277. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  278. /* wMaxPacketSize set by autoconfiguration */
  279. };
  280. static struct usb_endpoint_descriptor
  281. fsg_fs_intr_in_desc = {
  282. .bLength = USB_DT_ENDPOINT_SIZE,
  283. .bDescriptorType = USB_DT_ENDPOINT,
  284. .bEndpointAddress = USB_DIR_IN,
  285. .bmAttributes = USB_ENDPOINT_XFER_INT,
  286. .wMaxPacketSize = cpu_to_le16(2),
  287. .bInterval = 32, // frames -> 32 ms
  288. };
  289. static const struct usb_descriptor_header *fsg_fs_function[] = {
  290. (struct usb_descriptor_header *) &fsg_otg_desc,
  291. (struct usb_descriptor_header *) &fsg_intf_desc,
  292. (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc,
  293. (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc,
  294. (struct usb_descriptor_header *) &fsg_fs_intr_in_desc,
  295. NULL,
  296. };
  297. #define FSG_FS_FUNCTION_PRE_EP_ENTRIES 2
  298. /*
  299. * USB 2.0 devices need to expose both high speed and full speed
  300. * descriptors, unless they only run at full speed.
  301. *
  302. * That means alternate endpoint descriptors (bigger packets)
  303. * and a "device qualifier" ... plus more construction options
  304. * for the config descriptor.
  305. */
  306. static struct usb_endpoint_descriptor
  307. fsg_hs_bulk_in_desc = {
  308. .bLength = USB_DT_ENDPOINT_SIZE,
  309. .bDescriptorType = USB_DT_ENDPOINT,
  310. /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */
  311. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  312. .wMaxPacketSize = cpu_to_le16(512),
  313. };
  314. static struct usb_endpoint_descriptor
  315. fsg_hs_bulk_out_desc = {
  316. .bLength = USB_DT_ENDPOINT_SIZE,
  317. .bDescriptorType = USB_DT_ENDPOINT,
  318. /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */
  319. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  320. .wMaxPacketSize = cpu_to_le16(512),
  321. .bInterval = 1, // NAK every 1 uframe
  322. };
  323. static struct usb_endpoint_descriptor
  324. fsg_hs_intr_in_desc = {
  325. .bLength = USB_DT_ENDPOINT_SIZE,
  326. .bDescriptorType = USB_DT_ENDPOINT,
  327. /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */
  328. .bmAttributes = USB_ENDPOINT_XFER_INT,
  329. .wMaxPacketSize = cpu_to_le16(2),
  330. .bInterval = 9, // 2**(9-1) = 256 uframes -> 32 ms
  331. };
  332. static const struct usb_descriptor_header *fsg_hs_function[] = {
  333. (struct usb_descriptor_header *) &fsg_otg_desc,
  334. (struct usb_descriptor_header *) &fsg_intf_desc,
  335. (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc,
  336. (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc,
  337. (struct usb_descriptor_header *) &fsg_hs_intr_in_desc,
  338. NULL,
  339. };
  340. #define FSG_HS_FUNCTION_PRE_EP_ENTRIES 2
  341. /* Maxpacket and other transfer characteristics vary by speed. */
  342. static struct usb_endpoint_descriptor *
  343. fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
  344. struct usb_endpoint_descriptor *hs)
  345. {
  346. if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
  347. return hs;
  348. return fs;
  349. }
  350. /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
  351. static struct usb_string fsg_strings[] = {
  352. {FSG_STRING_MANUFACTURER, fsg_string_manufacturer},
  353. {FSG_STRING_PRODUCT, fsg_string_product},
  354. {FSG_STRING_SERIAL, fsg_string_serial},
  355. {FSG_STRING_CONFIG, fsg_string_config},
  356. {FSG_STRING_INTERFACE, fsg_string_interface},
  357. {}
  358. };
  359. static struct usb_gadget_strings fsg_stringtab = {
  360. .language = 0x0409, // en-us
  361. .strings = fsg_strings,
  362. };
  363. /*-------------------------------------------------------------------------*/
  364. /* If the next two routines are called while the gadget is registered,
  365. * the caller must own fsg->filesem for writing. */
  366. static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
  367. {
  368. int ro;
  369. struct file *filp = NULL;
  370. int rc = -EINVAL;
  371. struct inode *inode = NULL;
  372. loff_t size;
  373. loff_t num_sectors;
  374. loff_t min_sectors;
  375. /* R/W if we can, R/O if we must */
  376. ro = curlun->ro;
  377. if (!ro) {
  378. filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0);
  379. if (-EROFS == PTR_ERR(filp))
  380. ro = 1;
  381. }
  382. if (ro)
  383. filp = filp_open(filename, O_RDONLY | O_LARGEFILE, 0);
  384. if (IS_ERR(filp)) {
  385. LINFO(curlun, "unable to open backing file: %s\n", filename);
  386. return PTR_ERR(filp);
  387. }
  388. if (!(filp->f_mode & FMODE_WRITE))
  389. ro = 1;
  390. if (filp->f_path.dentry)
  391. inode = filp->f_path.dentry->d_inode;
  392. if (inode && S_ISBLK(inode->i_mode)) {
  393. if (bdev_read_only(inode->i_bdev))
  394. ro = 1;
  395. } else if (!inode || !S_ISREG(inode->i_mode)) {
  396. LINFO(curlun, "invalid file type: %s\n", filename);
  397. goto out;
  398. }
  399. /* If we can't read the file, it's no good.
  400. * If we can't write the file, use it read-only. */
  401. if (!filp->f_op || !(filp->f_op->read || filp->f_op->aio_read)) {
  402. LINFO(curlun, "file not readable: %s\n", filename);
  403. goto out;
  404. }
  405. if (!(filp->f_op->write || filp->f_op->aio_write))
  406. ro = 1;
  407. size = i_size_read(inode->i_mapping->host);
  408. if (size < 0) {
  409. LINFO(curlun, "unable to find file size: %s\n", filename);
  410. rc = (int) size;
  411. goto out;
  412. }
  413. num_sectors = size >> 9; // File size in 512-byte blocks
  414. min_sectors = 1;
  415. if (mod_data.cdrom) {
  416. num_sectors &= ~3; // Reduce to a multiple of 2048
  417. min_sectors = 300*4; // Smallest track is 300 frames
  418. if (num_sectors >= 256*60*75*4) {
  419. num_sectors = (256*60*75 - 1) * 4;
  420. LINFO(curlun, "file too big: %s\n", filename);
  421. LINFO(curlun, "using only first %d blocks\n",
  422. (int) num_sectors);
  423. }
  424. }
  425. if (num_sectors < min_sectors) {
  426. LINFO(curlun, "file too small: %s\n", filename);
  427. rc = -ETOOSMALL;
  428. goto out;
  429. }
  430. get_file(filp);
  431. curlun->ro = ro;
  432. curlun->filp = filp;
  433. curlun->file_length = size;
  434. curlun->num_sectors = num_sectors;
  435. LDBG(curlun, "open backing file: %s\n", filename);
  436. rc = 0;
  437. out:
  438. filp_close(filp, current->files);
  439. return rc;
  440. }
  441. static void fsg_lun_close(struct fsg_lun *curlun)
  442. {
  443. if (curlun->filp) {
  444. LDBG(curlun, "close backing file\n");
  445. fput(curlun->filp);
  446. curlun->filp = NULL;
  447. }
  448. }
  449. /*-------------------------------------------------------------------------*/
  450. /* Sync the file data, don't bother with the metadata.
  451. * This code was copied from fs/buffer.c:sys_fdatasync(). */
  452. static int fsg_lun_fsync_sub(struct fsg_lun *curlun)
  453. {
  454. struct file *filp = curlun->filp;
  455. if (curlun->ro || !filp)
  456. return 0;
  457. return vfs_fsync(filp, filp->f_path.dentry, 1);
  458. }
  459. static void store_cdrom_address(u8 *dest, int msf, u32 addr)
  460. {
  461. if (msf) {
  462. /* Convert to Minutes-Seconds-Frames */
  463. addr >>= 2; /* Convert to 2048-byte frames */
  464. addr += 2*75; /* Lead-in occupies 2 seconds */
  465. dest[3] = addr % 75; /* Frames */
  466. addr /= 75;
  467. dest[2] = addr % 60; /* Seconds */
  468. addr /= 60;
  469. dest[1] = addr; /* Minutes */
  470. dest[0] = 0; /* Reserved */
  471. } else {
  472. /* Absolute sector */
  473. put_unaligned_be32(addr, dest);
  474. }
  475. }