• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * storage_common.c -- Common definitions for mass storage functionality
4  *
5  * Copyright (C) 2003-2008 Alan Stern
6  * Copyeight (C) 2009 Samsung Electronics
7  * Author: Michal Nazarewicz (m.nazarewicz@samsung.com)
8  *
9  * Ported to u-boot:
10  * Andrzej Pietrasiewicz <andrzej.p@samsung.com>
11  *
12  * Code refactoring & cleanup:
13  * Łukasz Majewski <l.majewski@samsung.com>
14  */
15 
16 
17 /*
18  * This file requires the following identifiers used in USB strings to
19  * be defined (each of type pointer to char):
20  *  - fsg_string_manufacturer -- name of the manufacturer
21  *  - fsg_string_product      -- name of the product
22  *  - fsg_string_serial       -- product's serial
23  *  - fsg_string_config       -- name of the configuration
24  *  - fsg_string_interface    -- name of the interface
25  * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS
26  * macro is defined prior to including this file.
27  */
28 
29 /*
30  * When FSG_NO_INTR_EP is defined fsg_fs_intr_in_desc and
31  * fsg_hs_intr_in_desc objects as well as
32  * FSG_FS_FUNCTION_PRE_EP_ENTRIES and FSG_HS_FUNCTION_PRE_EP_ENTRIES
33  * macros are not defined.
34  *
35  * When FSG_NO_DEVICE_STRINGS is defined FSG_STRING_MANUFACTURER,
36  * FSG_STRING_PRODUCT, FSG_STRING_SERIAL and FSG_STRING_CONFIG are not
37  * defined (as well as corresponding entries in string tables are
38  * missing) and FSG_STRING_INTERFACE has value of zero.
39  *
40  * When FSG_NO_OTG is defined fsg_otg_desc won't be defined.
41  */
42 
43 /*
44  * When FSG_BUFFHD_STATIC_BUFFER is defined when this file is included
45  * the fsg_buffhd structure's buf field will be an array of FSG_BUFLEN
46  * characters rather then a pointer to void.
47  */
48 
49 
50 /* #include <asm/unaligned.h> */
51 
52 
53 /*
54  * Thanks to NetChip Technologies for donating this product ID.
55  *
56  * DO NOT REUSE THESE IDs with any other driver!!  Ever!!
57  * Instead:  allocate your own, using normal USB-IF procedures.
58  */
59 #define FSG_VENDOR_ID	0x0525	/* NetChip */
60 #define FSG_PRODUCT_ID	0xa4a5	/* Linux-USB File-backed Storage Gadget */
61 
62 /*-------------------------------------------------------------------------*/
63 
64 #ifndef DEBUG
65 #undef VERBOSE_DEBUG
66 #undef DUMP_MSGS
67 #endif /* !DEBUG */
68 
69 #ifdef VERBOSE_DEBUG
70 #define VLDBG	LDBG
71 #else
72 #define VLDBG(lun, fmt, args...) do { } while (0)
73 #endif /* VERBOSE_DEBUG */
74 
75 /*
76 #define LDBG(lun, fmt, args...)   dev_dbg (&(lun)->dev, fmt, ## args)
77 #define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args)
78 #define LWARN(lun, fmt, args...)  dev_warn(&(lun)->dev, fmt, ## args)
79 #define LINFO(lun, fmt, args...)  dev_info(&(lun)->dev, fmt, ## args)
80 */
81 
82 #define LDBG(lun, fmt, args...) do { } while (0)
83 #define LERROR(lun, fmt, args...) do { } while (0)
84 #define LWARN(lun, fmt, args...) do { } while (0)
85 #define LINFO(lun, fmt, args...) do { } while (0)
86 
87 /*
88  * Keep those macros in sync with those in
89  * include/linux/usb/composite.h or else GCC will complain.  If they
90  * are identical (the same names of arguments, white spaces in the
91  * same places) GCC will allow redefinition otherwise (even if some
92  * white space is removed or added) warning will be issued.
93  *
94  * Those macros are needed here because File Storage Gadget does not
95  * include the composite.h header.  For composite gadgets those macros
96  * are redundant since composite.h is included any way.
97  *
98  * One could check whether those macros are already defined (which
99  * would indicate composite.h had been included) or not (which would
100  * indicate we were in FSG) but this is not done because a warning is
101  * desired if definitions here differ from the ones in composite.h.
102  *
103  * We want the definitions to match and be the same in File Storage
104  * Gadget as well as Mass Storage Function (and so composite gadgets
105  * using MSF).  If someone changes them in composite.h it will produce
106  * a warning in this file when building MSF.
107  */
108 
109 #define DBG(d, fmt, args...)     debug(fmt , ## args)
110 #define VDBG(d, fmt, args...)    debug(fmt , ## args)
111 /* #define ERROR(d, fmt, args...)   printf(fmt , ## args) */
112 /* #define WARNING(d, fmt, args...) printf(fmt , ## args) */
113 /* #define INFO(d, fmt, args...)    printf(fmt , ## args) */
114 
115 /* #define DBG(d, fmt, args...)     do { } while (0) */
116 /* #define VDBG(d, fmt, args...)    do { } while (0) */
117 #define ERROR(d, fmt, args...)   do { } while (0)
118 #define WARNING(d, fmt, args...) do { } while (0)
119 #define INFO(d, fmt, args...)    do { } while (0)
120 
121 #ifdef DUMP_MSGS
122 
123 /* dump_msg(fsg, const char * label, const u8 * buf, unsigned length); */
124 # define dump_msg(fsg, label, buf, length) do {                         \
125 	if (length < 512) {						\
126 		DBG(fsg, "%s, length %u:\n", label, length);		\
127 		print_hex_dump("", DUMP_PREFIX_OFFSET,	\
128 			       16, 1, buf, length, 0);			\
129 	}								\
130 } while (0)
131 
132 #  define dump_cdb(fsg) do { } while (0)
133 
134 #else
135 
136 #  define dump_msg(fsg, /* const char * */ label, \
137 		   /* const u8 * */ buf, /* unsigned */ length) do { } while (0)
138 
139 #  ifdef VERBOSE_DEBUG
140 
141 #    define dump_cdb(fsg)						\
142 	print_hex_dump("SCSI CDB: ", DUMP_PREFIX_NONE,	\
143 		       16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0)		\
144 
145 #  else
146 
147 #    define dump_cdb(fsg) do { } while (0)
148 
149 #  endif /* VERBOSE_DEBUG */
150 
151 #endif /* DUMP_MSGS */
152 
153 /*-------------------------------------------------------------------------*/
154 
155 /* SCSI device types */
156 #define TYPE_DISK	0x00
157 #define TYPE_CDROM	0x05
158 
159 /* USB protocol value = the transport method */
160 #define USB_PR_CBI	0x00		/* Control/Bulk/Interrupt */
161 #define USB_PR_CB	0x01		/* Control/Bulk w/o interrupt */
162 #define USB_PR_BULK	0x50		/* Bulk-only */
163 
164 /* USB subclass value = the protocol encapsulation */
165 #define USB_SC_RBC	0x01		/* Reduced Block Commands (flash) */
166 #define USB_SC_8020	0x02		/* SFF-8020i, MMC-2, ATAPI (CD-ROM) */
167 #define USB_SC_QIC	0x03		/* QIC-157 (tape) */
168 #define USB_SC_UFI	0x04		/* UFI (floppy) */
169 #define USB_SC_8070	0x05		/* SFF-8070i (removable) */
170 #define USB_SC_SCSI	0x06		/* Transparent SCSI */
171 
172 /* Bulk-only data structures */
173 
174 /* Command Block Wrapper */
175 struct fsg_bulk_cb_wrap {
176 	__le32	Signature;		/* Contains 'USBC' */
177 	u32	Tag;			/* Unique per command id */
178 	__le32	DataTransferLength;	/* Size of the data */
179 	u8	Flags;			/* Direction in bit 7 */
180 	u8	Lun;			/* LUN (normally 0) */
181 	u8	Length;			/* Of the CDB, <= MAX_COMMAND_SIZE */
182 	u8	CDB[16];		/* Command Data Block */
183 };
184 
185 #define USB_BULK_CB_WRAP_LEN	31
186 #define USB_BULK_CB_SIG		0x43425355	/* Spells out USBC */
187 #define USB_BULK_IN_FLAG	0x80
188 
189 /* Command Status Wrapper */
190 struct bulk_cs_wrap {
191 	__le32	Signature;		/* Should = 'USBS' */
192 	u32	Tag;			/* Same as original command */
193 	__le32	Residue;		/* Amount not transferred */
194 	u8	Status;			/* See below */
195 };
196 
197 #define USB_BULK_CS_WRAP_LEN	13
198 #define USB_BULK_CS_SIG		0x53425355	/* Spells out 'USBS' */
199 #define USB_STATUS_PASS		0
200 #define USB_STATUS_FAIL		1
201 #define USB_STATUS_PHASE_ERROR	2
202 
203 /* Bulk-only class specific requests */
204 #define USB_BULK_RESET_REQUEST		0xff
205 #define USB_BULK_GET_MAX_LUN_REQUEST	0xfe
206 
207 /* CBI Interrupt data structure */
208 struct interrupt_data {
209 	u8	bType;
210 	u8	bValue;
211 };
212 
213 #define CBI_INTERRUPT_DATA_LEN		2
214 
215 /* CBI Accept Device-Specific Command request */
216 #define USB_CBI_ADSC_REQUEST		0x00
217 
218 /* Length of a SCSI Command Data Block */
219 #define MAX_COMMAND_SIZE	16
220 
221 /* SCSI commands that we recognize */
222 #define SC_FORMAT_UNIT			0x04
223 #define SC_INQUIRY			0x12
224 #define SC_MODE_SELECT_6		0x15
225 #define SC_MODE_SELECT_10		0x55
226 #define SC_MODE_SENSE_6			0x1a
227 #define SC_MODE_SENSE_10		0x5a
228 #define SC_PREVENT_ALLOW_MEDIUM_REMOVAL	0x1e
229 #define SC_READ_6			0x08
230 #define SC_READ_10			0x28
231 #define SC_READ_12			0xa8
232 #define SC_READ_CAPACITY		0x25
233 #define SC_READ_FORMAT_CAPACITIES	0x23
234 #define SC_READ_HEADER			0x44
235 #define SC_READ_TOC			0x43
236 #define SC_RELEASE			0x17
237 #define SC_REQUEST_SENSE		0x03
238 #define SC_RESERVE			0x16
239 #define SC_SEND_DIAGNOSTIC		0x1d
240 #define SC_START_STOP_UNIT		0x1b
241 #define SC_SYNCHRONIZE_CACHE		0x35
242 #define SC_TEST_UNIT_READY		0x00
243 #define SC_VERIFY			0x2f
244 #define SC_WRITE_6			0x0a
245 #define SC_WRITE_10			0x2a
246 #define SC_WRITE_12			0xaa
247 
248 /* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
249 #define SS_NO_SENSE				0
250 #define SS_COMMUNICATION_FAILURE		0x040800
251 #define SS_INVALID_COMMAND			0x052000
252 #define SS_INVALID_FIELD_IN_CDB			0x052400
253 #define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE	0x052100
254 #define SS_LOGICAL_UNIT_NOT_SUPPORTED		0x052500
255 #define SS_MEDIUM_NOT_PRESENT			0x023a00
256 #define SS_MEDIUM_REMOVAL_PREVENTED		0x055302
257 #define SS_NOT_READY_TO_READY_TRANSITION	0x062800
258 #define SS_RESET_OCCURRED			0x062900
259 #define SS_SAVING_PARAMETERS_NOT_SUPPORTED	0x053900
260 #define SS_UNRECOVERED_READ_ERROR		0x031100
261 #define SS_WRITE_ERROR				0x030c02
262 #define SS_WRITE_PROTECTED			0x072700
263 
264 #define SK(x)		((u8) ((x) >> 16))	/* Sense Key byte, etc. */
265 #define ASC(x)		((u8) ((x) >> 8))
266 #define ASCQ(x)		((u8) (x))
267 
268 struct device_attribute { int i; };
269 #define ETOOSMALL	525
270 
271 #include <usb_mass_storage.h>
272 
273 /*-------------------------------------------------------------------------*/
274 
275 struct fsg_lun {
276 	loff_t		file_length;
277 	loff_t		num_sectors;
278 
279 	unsigned int	initially_ro:1;
280 	unsigned int	ro:1;
281 	unsigned int	removable:1;
282 	unsigned int	cdrom:1;
283 	unsigned int	prevent_medium_removal:1;
284 	unsigned int	registered:1;
285 	unsigned int	info_valid:1;
286 	unsigned int	nofua:1;
287 
288 	u32		sense_data;
289 	u32		sense_data_info;
290 	u32		unit_attention_data;
291 
292 	struct device	dev;
293 };
294 
295 #define fsg_lun_is_open(curlun)	((curlun)->filp != NULL)
296 #if 0
297 static struct fsg_lun *fsg_lun_from_dev(struct device *dev)
298 {
299 	return container_of(dev, struct fsg_lun, dev);
300 }
301 #endif
302 
303 /* Big enough to hold our biggest descriptor */
304 #define EP0_BUFSIZE	256
305 #define DELAYED_STATUS	(EP0_BUFSIZE + 999)	/* An impossibly large value */
306 
307 /* Number of buffers we will use.  2 is enough for double-buffering */
308 #define FSG_NUM_BUFFERS	2
309 
310 /* Default size of buffer length. */
311 #define FSG_BUFLEN	((u32)131072)
312 
313 /* Maximal number of LUNs supported in mass storage function */
314 #define FSG_MAX_LUNS	8
315 
316 enum fsg_buffer_state {
317 	BUF_STATE_EMPTY = 0,
318 	BUF_STATE_FULL,
319 	BUF_STATE_BUSY
320 };
321 
322 struct fsg_buffhd {
323 #ifdef FSG_BUFFHD_STATIC_BUFFER
324 	char				buf[FSG_BUFLEN];
325 #else
326 	void				*buf;
327 #endif
328 	enum fsg_buffer_state		state;
329 	struct fsg_buffhd		*next;
330 
331 	/*
332 	 * The NetChip 2280 is faster, and handles some protocol faults
333 	 * better, if we don't submit any short bulk-out read requests.
334 	 * So we will record the intended request length here.
335 	 */
336 	unsigned int			bulk_out_intended_length;
337 
338 	struct usb_request		*inreq;
339 	int				inreq_busy;
340 	struct usb_request		*outreq;
341 	int				outreq_busy;
342 };
343 
344 enum fsg_state {
345 	/* This one isn't used anywhere */
346 	FSG_STATE_COMMAND_PHASE = -10,
347 	FSG_STATE_DATA_PHASE,
348 	FSG_STATE_STATUS_PHASE,
349 
350 	FSG_STATE_IDLE = 0,
351 	FSG_STATE_ABORT_BULK_OUT,
352 	FSG_STATE_RESET,
353 	FSG_STATE_INTERFACE_CHANGE,
354 	FSG_STATE_CONFIG_CHANGE,
355 	FSG_STATE_DISCONNECT,
356 	FSG_STATE_EXIT,
357 	FSG_STATE_TERMINATED
358 };
359 
360 enum data_direction {
361 	DATA_DIR_UNKNOWN = 0,
362 	DATA_DIR_FROM_HOST,
363 	DATA_DIR_TO_HOST,
364 	DATA_DIR_NONE
365 };
366 
367 /*-------------------------------------------------------------------------*/
368 
get_unaligned_be24(u8 * buf)369 static inline u32 get_unaligned_be24(u8 *buf)
370 {
371 	return 0xffffff & (u32) get_unaligned_be32(buf - 1);
372 }
373 
374 /*-------------------------------------------------------------------------*/
375 
376 enum {
377 #ifndef FSG_NO_DEVICE_STRINGS
378 	FSG_STRING_MANUFACTURER	= 1,
379 	FSG_STRING_PRODUCT,
380 	FSG_STRING_SERIAL,
381 	FSG_STRING_CONFIG,
382 #endif
383 	FSG_STRING_INTERFACE
384 };
385 
386 #ifndef FSG_NO_OTG
387 static struct usb_otg_descriptor
388 fsg_otg_desc = {
389 	.bLength =		sizeof fsg_otg_desc,
390 	.bDescriptorType =	USB_DT_OTG,
391 
392 	.bmAttributes =		USB_OTG_SRP,
393 };
394 #endif
395 
396 /* There is only one interface. */
397 
398 static struct usb_interface_descriptor
399 fsg_intf_desc = {
400 	.bLength =		sizeof fsg_intf_desc,
401 	.bDescriptorType =	USB_DT_INTERFACE,
402 
403 	.bNumEndpoints =	2,		/* Adjusted during fsg_bind() */
404 	.bInterfaceClass =	USB_CLASS_MASS_STORAGE,
405 	.bInterfaceSubClass =	USB_SC_SCSI,	/* Adjusted during fsg_bind() */
406 	.bInterfaceProtocol =	USB_PR_BULK,	/* Adjusted during fsg_bind() */
407 	.iInterface =		FSG_STRING_INTERFACE,
408 };
409 
410 /*
411  * Three full-speed endpoint descriptors: bulk-in, bulk-out, and
412  * interrupt-in.
413  */
414 
415 static struct usb_endpoint_descriptor
416 fsg_fs_bulk_in_desc = {
417 	.bLength =		USB_DT_ENDPOINT_SIZE,
418 	.bDescriptorType =	USB_DT_ENDPOINT,
419 
420 	.bEndpointAddress =	USB_DIR_IN,
421 	.bmAttributes =		USB_ENDPOINT_XFER_BULK,
422 	/* wMaxPacketSize set by autoconfiguration */
423 };
424 
425 static struct usb_endpoint_descriptor
426 fsg_fs_bulk_out_desc = {
427 	.bLength =		USB_DT_ENDPOINT_SIZE,
428 	.bDescriptorType =	USB_DT_ENDPOINT,
429 
430 	.bEndpointAddress =	USB_DIR_OUT,
431 	.bmAttributes =		USB_ENDPOINT_XFER_BULK,
432 	/* wMaxPacketSize set by autoconfiguration */
433 };
434 
435 #ifndef FSG_NO_INTR_EP
436 
437 static struct usb_endpoint_descriptor
438 fsg_fs_intr_in_desc = {
439 	.bLength =		USB_DT_ENDPOINT_SIZE,
440 	.bDescriptorType =	USB_DT_ENDPOINT,
441 
442 	.bEndpointAddress =	USB_DIR_IN,
443 	.bmAttributes =		USB_ENDPOINT_XFER_INT,
444 	.wMaxPacketSize =	cpu_to_le16(2),
445 	.bInterval =		32,	/* frames -> 32 ms */
446 };
447 
448 #ifndef FSG_NO_OTG
449 #  define FSG_FS_FUNCTION_PRE_EP_ENTRIES	2
450 #else
451 #  define FSG_FS_FUNCTION_PRE_EP_ENTRIES	1
452 #endif
453 
454 #endif
455 
456 static struct usb_descriptor_header *fsg_fs_function[] = {
457 #ifndef FSG_NO_OTG
458 	(struct usb_descriptor_header *) &fsg_otg_desc,
459 #endif
460 	(struct usb_descriptor_header *) &fsg_intf_desc,
461 	(struct usb_descriptor_header *) &fsg_fs_bulk_in_desc,
462 	(struct usb_descriptor_header *) &fsg_fs_bulk_out_desc,
463 #ifndef FSG_NO_INTR_EP
464 	(struct usb_descriptor_header *) &fsg_fs_intr_in_desc,
465 #endif
466 	NULL,
467 };
468 
469 /*
470  * USB 2.0 devices need to expose both high speed and full speed
471  * descriptors, unless they only run at full speed.
472  *
473  * That means alternate endpoint descriptors (bigger packets)
474  * and a "device qualifier" ... plus more construction options
475  * for the configuration descriptor.
476  */
477 static struct usb_endpoint_descriptor
478 fsg_hs_bulk_in_desc = {
479 	.bLength =		USB_DT_ENDPOINT_SIZE,
480 	.bDescriptorType =	USB_DT_ENDPOINT,
481 
482 	/* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */
483 	.bmAttributes =		USB_ENDPOINT_XFER_BULK,
484 	.wMaxPacketSize =	cpu_to_le16(512),
485 };
486 
487 static struct usb_endpoint_descriptor
488 fsg_hs_bulk_out_desc = {
489 	.bLength =		USB_DT_ENDPOINT_SIZE,
490 	.bDescriptorType =	USB_DT_ENDPOINT,
491 
492 	/* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */
493 	.bmAttributes =		USB_ENDPOINT_XFER_BULK,
494 	.wMaxPacketSize =	cpu_to_le16(512),
495 	.bInterval =		1,	/* NAK every 1 uframe */
496 };
497 
498 #ifndef FSG_NO_INTR_EP
499 
500 static struct usb_endpoint_descriptor
501 fsg_hs_intr_in_desc = {
502 	.bLength =		USB_DT_ENDPOINT_SIZE,
503 	.bDescriptorType =	USB_DT_ENDPOINT,
504 
505 	/* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */
506 	.bmAttributes =		USB_ENDPOINT_XFER_INT,
507 	.wMaxPacketSize =	cpu_to_le16(2),
508 	.bInterval =		9,	/* 2**(9-1) = 256 uframes -> 32 ms */
509 };
510 
511 #ifndef FSG_NO_OTG
512 #  define FSG_HS_FUNCTION_PRE_EP_ENTRIES	2
513 #else
514 #  define FSG_HS_FUNCTION_PRE_EP_ENTRIES	1
515 #endif
516 
517 #endif
518 
519 static struct usb_descriptor_header *fsg_hs_function[] = {
520 #ifndef FSG_NO_OTG
521 	(struct usb_descriptor_header *) &fsg_otg_desc,
522 #endif
523 	(struct usb_descriptor_header *) &fsg_intf_desc,
524 	(struct usb_descriptor_header *) &fsg_hs_bulk_in_desc,
525 	(struct usb_descriptor_header *) &fsg_hs_bulk_out_desc,
526 #ifndef FSG_NO_INTR_EP
527 	(struct usb_descriptor_header *) &fsg_hs_intr_in_desc,
528 #endif
529 	NULL,
530 };
531 
532 /* Maxpacket and other transfer characteristics vary by speed. */
533 static struct usb_endpoint_descriptor *
fsg_ep_desc(struct usb_gadget * g,struct usb_endpoint_descriptor * fs,struct usb_endpoint_descriptor * hs)534 fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
535 		struct usb_endpoint_descriptor *hs)
536 {
537 	if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
538 		return hs;
539 	return fs;
540 }
541 
542 /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
543 static struct usb_string		fsg_strings[] = {
544 #ifndef FSG_NO_DEVICE_STRINGS
545 	{FSG_STRING_MANUFACTURER,	fsg_string_manufacturer},
546 	{FSG_STRING_PRODUCT,		fsg_string_product},
547 	{FSG_STRING_SERIAL,		fsg_string_serial},
548 	{FSG_STRING_CONFIG,		fsg_string_config},
549 #endif
550 	{FSG_STRING_INTERFACE,		fsg_string_interface},
551 	{}
552 };
553 
554 static struct usb_gadget_strings	fsg_stringtab = {
555 	.language	= 0x0409,		/* en-us */
556 	.strings	= fsg_strings,
557 };
558 
559 /*-------------------------------------------------------------------------*/
560 
561 /*
562  * If the next two routines are called while the gadget is registered,
563  * the caller must own fsg->filesem for writing.
564  */
565 
fsg_lun_open(struct fsg_lun * curlun,unsigned int num_sectors,const char * filename)566 static int fsg_lun_open(struct fsg_lun *curlun, unsigned int num_sectors,
567 			const char *filename)
568 {
569 	int				ro;
570 
571 	/* R/W if we can, R/O if we must */
572 	ro = curlun->initially_ro;
573 
574 	curlun->ro = ro;
575 	curlun->file_length = num_sectors << 9;
576 	curlun->num_sectors = num_sectors;
577 	debug("open backing file: %s\n", filename);
578 
579 	return 0;
580 }
581 
fsg_lun_close(struct fsg_lun * curlun)582 static void fsg_lun_close(struct fsg_lun *curlun)
583 {
584 }
585 
586 /*-------------------------------------------------------------------------*/
587 
588 /*
589  * Sync the file data, don't bother with the metadata.
590  * This code was copied from fs/buffer.c:sys_fdatasync().
591  */
fsg_lun_fsync_sub(struct fsg_lun * curlun)592 static int fsg_lun_fsync_sub(struct fsg_lun *curlun)
593 {
594 	return 0;
595 }
596 
store_cdrom_address(u8 * dest,int msf,u32 addr)597 static void store_cdrom_address(u8 *dest, int msf, u32 addr)
598 {
599 	if (msf) {
600 		/* Convert to Minutes-Seconds-Frames */
601 		addr >>= 2;		/* Convert to 2048-byte frames */
602 		addr += 2*75;		/* Lead-in occupies 2 seconds */
603 		dest[3] = addr % 75;	/* Frames */
604 		addr /= 75;
605 		dest[2] = addr % 60;	/* Seconds */
606 		addr /= 60;
607 		dest[1] = addr;		/* Minutes */
608 		dest[0] = 0;		/* Reserved */
609 	} else {
610 		/* Absolute sector */
611 		put_unaligned_be32(addr, dest);
612 	}
613 }
614 
615 /*-------------------------------------------------------------------------*/
616