2 * storage_common.c -- Common definitions for mass storage functionality
4 * Copyright (C) 2003-2008 Alan Stern
5 * Copyeight (C) 2009 Samsung Electronics
6 * Author: Michal Nazarewicz (mina86@mina86.com)
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.
15 * This file requires the following identifiers used in USB strings to
16 * be defined (each of type pointer to char):
17 * - fsg_string_interface -- name of the interface
21 * When USB_GADGET_DEBUG_FILES is defined the module param num_buffers
22 * sets the number of pipeline buffers (length of the fsg_buffhd array).
23 * The valid range of num_buffers is: num >= 2 && num <= 4.
27 #include <linux/usb/storage.h>
28 #include <scsi/scsi.h>
29 #include <asm/unaligned.h>
33 * Thanks to NetChip Technologies for donating this product ID.
35 * DO NOT REUSE THESE IDs with any other driver!! Ever!!
36 * Instead: allocate your own, using normal USB-IF procedures.
38 #define FSG_VENDOR_ID 0x0525 /* NetChip */
39 #define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */
42 /*-------------------------------------------------------------------------*/
53 #define VLDBG(lun, fmt, args...) do { } while (0)
54 #endif /* VERBOSE_DEBUG */
56 #define LDBG(lun, fmt, args...) dev_dbg (&(lun)->dev, fmt, ## args)
57 #define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args)
58 #define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args)
59 #define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args)
64 # define dump_msg(fsg, /* const char * */ label, \
65 /* const u8 * */ buf, /* unsigned */ length) do { \
67 DBG(fsg, "%s, length %u:\n", label, length); \
68 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \
69 16, 1, buf, length, 0); \
73 # define dump_cdb(fsg) do { } while (0)
77 # define dump_msg(fsg, /* const char * */ label, \
78 /* const u8 * */ buf, /* unsigned */ length) do { } while (0)
82 # define dump_cdb(fsg) \
83 print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \
84 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \
88 # define dump_cdb(fsg) do { } while (0)
90 # endif /* VERBOSE_DEBUG */
92 #endif /* DUMP_MSGS */
94 /*-------------------------------------------------------------------------*/
96 /* Length of a SCSI Command Data Block */
97 #define MAX_COMMAND_SIZE 16
99 /* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
100 #define SS_NO_SENSE 0
101 #define SS_COMMUNICATION_FAILURE 0x040800
102 #define SS_INVALID_COMMAND 0x052000
103 #define SS_INVALID_FIELD_IN_CDB 0x052400
104 #define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100
105 #define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500
106 #define SS_MEDIUM_NOT_PRESENT 0x023a00
107 #define SS_MEDIUM_REMOVAL_PREVENTED 0x055302
108 #define SS_NOT_READY_TO_READY_TRANSITION 0x062800
109 #define SS_RESET_OCCURRED 0x062900
110 #define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900
111 #define SS_UNRECOVERED_READ_ERROR 0x031100
112 #define SS_WRITE_ERROR 0x030c02
113 #define SS_WRITE_PROTECTED 0x072700
115 #define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */
116 #define ASC(x) ((u8) ((x) >> 8))
117 #define ASCQ(x) ((u8) (x))
120 /*-------------------------------------------------------------------------*/
128 unsigned int initially_ro
:1;
130 unsigned int removable
:1;
131 unsigned int cdrom
:1;
132 unsigned int prevent_medium_removal
:1;
133 unsigned int registered
:1;
134 unsigned int info_valid
:1;
135 unsigned int nofua
:1;
139 u32 unit_attention_data
;
141 unsigned int blkbits
; /* Bits of logical block size of bound block device */
142 unsigned int blksize
; /* logical block size of bound block device */
144 #ifdef CONFIG_MTK_ICUSB_SUPPORT
149 static inline bool fsg_lun_is_open(struct fsg_lun
*curlun
)
151 return curlun
->filp
!= NULL
;
154 static inline struct fsg_lun
*fsg_lun_from_dev(struct device
*dev
)
156 return container_of(dev
, struct fsg_lun
, dev
);
160 /* Big enough to hold our biggest descriptor */
161 #define EP0_BUFSIZE 256
162 #define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */
164 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
166 static unsigned int fsg_num_buffers
= CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
;
167 module_param_named(num_buffers
, fsg_num_buffers
, uint
, S_IRUGO
);
168 MODULE_PARM_DESC(num_buffers
, "Number of pipeline buffers");
173 * Number of buffers we will use.
174 * 2 is usually enough for good buffering pipeline
176 #define fsg_num_buffers CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
178 #endif /* CONFIG_USB_DEBUG */
180 /* check if fsg_num_buffers is within a valid range */
181 static inline int fsg_num_buffers_validate(void)
183 if (fsg_num_buffers
>= 2 && fsg_num_buffers
<= 4)
185 pr_err("fsg_num_buffers %u is out of range (%d to %d)\n",
186 fsg_num_buffers
, 2 ,4);
190 /* Default size of buffer length. */
191 #define FSG_BUFLEN ((u32)16384)
193 /* Maximal number of LUNs supported in mass storage function */
194 #define FSG_MAX_LUNS 8
196 enum fsg_buffer_state
{
204 enum fsg_buffer_state state
;
205 struct fsg_buffhd
*next
;
208 * The NetChip 2280 is faster, and handles some protocol faults
209 * better, if we don't submit any short bulk-out read requests.
210 * So we will record the intended request length here.
212 unsigned int bulk_out_intended_length
;
214 struct usb_request
*inreq
;
216 struct usb_request
*outreq
;
221 /* This one isn't used anywhere */
222 FSG_STATE_COMMAND_PHASE
= -10,
223 FSG_STATE_DATA_PHASE
,
224 FSG_STATE_STATUS_PHASE
,
227 FSG_STATE_ABORT_BULK_OUT
,
229 FSG_STATE_INTERFACE_CHANGE
,
230 FSG_STATE_CONFIG_CHANGE
,
231 FSG_STATE_DISCONNECT
,
236 enum data_direction
{
237 DATA_DIR_UNKNOWN
= 0,
244 /*-------------------------------------------------------------------------*/
247 static inline u32
get_unaligned_be24(u8
*buf
)
249 return 0xffffff & (u32
) get_unaligned_be32(buf
- 1);
253 /*-------------------------------------------------------------------------*/
261 #ifdef CONFIG_USBIF_COMPLIANCE
262 static struct usb_otg_descriptor
264 .bLength
= sizeof fsg_otg_desc
,
265 .bDescriptorType
= USB_DT_OTG
,
267 .bmAttributes
= USB_OTG_SRP
| USB_OTG_HNP
,
268 .bcdOTG
= cpu_to_le16(0x200),
272 /* There is only one interface. */
274 static struct usb_interface_descriptor
276 .bLength
= sizeof fsg_intf_desc
,
277 .bDescriptorType
= USB_DT_INTERFACE
,
279 .bNumEndpoints
= 2, /* Adjusted during fsg_bind() */
280 .bInterfaceClass
= USB_CLASS_MASS_STORAGE
,
281 .bInterfaceSubClass
= USB_SC_SCSI
, /* Adjusted during fsg_bind() */
282 .bInterfaceProtocol
= USB_PR_BULK
, /* Adjusted during fsg_bind() */
283 .iInterface
= FSG_STRING_INTERFACE
,
287 * Three full-speed endpoint descriptors: bulk-in, bulk-out, and
291 static struct usb_endpoint_descriptor
292 fsg_fs_bulk_in_desc
= {
293 .bLength
= USB_DT_ENDPOINT_SIZE
,
294 .bDescriptorType
= USB_DT_ENDPOINT
,
296 .bEndpointAddress
= USB_DIR_IN
,
297 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
298 /* wMaxPacketSize set by autoconfiguration */
301 static struct usb_endpoint_descriptor
302 fsg_fs_bulk_out_desc
= {
303 .bLength
= USB_DT_ENDPOINT_SIZE
,
304 .bDescriptorType
= USB_DT_ENDPOINT
,
306 .bEndpointAddress
= USB_DIR_OUT
,
307 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
308 /* wMaxPacketSize set by autoconfiguration */
311 static struct usb_descriptor_header
*fsg_fs_function
[] = {
312 #ifdef CONFIG_USBIF_COMPLIANCE
313 (struct usb_descriptor_header
*) &fsg_otg_desc
,
315 (struct usb_descriptor_header
*) &fsg_intf_desc
,
316 (struct usb_descriptor_header
*) &fsg_fs_bulk_in_desc
,
317 (struct usb_descriptor_header
*) &fsg_fs_bulk_out_desc
,
323 * USB 2.0 devices need to expose both high speed and full speed
324 * descriptors, unless they only run at full speed.
326 * That means alternate endpoint descriptors (bigger packets)
327 * and a "device qualifier" ... plus more construction options
328 * for the configuration descriptor.
330 static struct usb_endpoint_descriptor
331 fsg_hs_bulk_in_desc
= {
332 .bLength
= USB_DT_ENDPOINT_SIZE
,
333 .bDescriptorType
= USB_DT_ENDPOINT
,
335 /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */
336 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
337 .wMaxPacketSize
= cpu_to_le16(512),
340 static struct usb_endpoint_descriptor
341 fsg_hs_bulk_out_desc
= {
342 .bLength
= USB_DT_ENDPOINT_SIZE
,
343 .bDescriptorType
= USB_DT_ENDPOINT
,
345 /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */
346 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
347 .wMaxPacketSize
= cpu_to_le16(512),
348 .bInterval
= 1, /* NAK every 1 uframe */
352 static struct usb_descriptor_header
*fsg_hs_function
[] = {
353 #ifdef CONFIG_USBIF_COMPLIANCE
354 (struct usb_descriptor_header
*) &fsg_otg_desc
,
356 (struct usb_descriptor_header
*) &fsg_intf_desc
,
357 (struct usb_descriptor_header
*) &fsg_hs_bulk_in_desc
,
358 (struct usb_descriptor_header
*) &fsg_hs_bulk_out_desc
,
362 static struct usb_endpoint_descriptor
363 fsg_ss_bulk_in_desc
= {
364 .bLength
= USB_DT_ENDPOINT_SIZE
,
365 .bDescriptorType
= USB_DT_ENDPOINT
,
367 /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */
368 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
369 .wMaxPacketSize
= cpu_to_le16(1024),
372 static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc
= {
373 .bLength
= sizeof(fsg_ss_bulk_in_comp_desc
),
374 .bDescriptorType
= USB_DT_SS_ENDPOINT_COMP
,
376 /*.bMaxBurst = DYNAMIC, */
379 static struct usb_endpoint_descriptor
380 fsg_ss_bulk_out_desc
= {
381 .bLength
= USB_DT_ENDPOINT_SIZE
,
382 .bDescriptorType
= USB_DT_ENDPOINT
,
384 /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */
385 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
386 .wMaxPacketSize
= cpu_to_le16(1024),
389 static struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc
= {
390 .bLength
= sizeof(fsg_ss_bulk_in_comp_desc
),
391 .bDescriptorType
= USB_DT_SS_ENDPOINT_COMP
,
393 /*.bMaxBurst = DYNAMIC, */
396 static struct usb_descriptor_header
*fsg_ss_function
[] = {
397 #ifdef CONFIG_USBIF_COMPLIANCE
398 (struct usb_descriptor_header
*) &fsg_otg_desc
,
400 (struct usb_descriptor_header
*) &fsg_intf_desc
,
401 (struct usb_descriptor_header
*) &fsg_ss_bulk_in_desc
,
402 (struct usb_descriptor_header
*) &fsg_ss_bulk_in_comp_desc
,
403 (struct usb_descriptor_header
*) &fsg_ss_bulk_out_desc
,
404 (struct usb_descriptor_header
*) &fsg_ss_bulk_out_comp_desc
,
408 /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
409 static struct usb_string fsg_strings
[] = {
410 {FSG_STRING_INTERFACE
, fsg_string_interface
},
414 static struct usb_gadget_strings fsg_stringtab
= {
415 .language
= 0x0409, /* en-us */
416 .strings
= fsg_strings
,
420 /*-------------------------------------------------------------------------*/
423 * If the next two routines are called while the gadget is registered,
424 * the caller must own fsg->filesem for writing.
427 static void fsg_lun_close(struct fsg_lun
*curlun
)
430 LDBG(curlun
, "close backing file\n");
437 static int fsg_lun_open(struct fsg_lun
*curlun
, const char *filename
)
440 struct file
*filp
= NULL
;
442 struct inode
*inode
= NULL
;
446 unsigned int blkbits
;
447 unsigned int blksize
;
449 #ifdef CONFIG_MTK_ICUSB_SUPPORT
450 #define ICUSB_STORAGE_LABEL "/dev/block/vold/8:"
451 if(strstr(filename
, ICUSB_STORAGE_LABEL
))
453 printk(KERN_WARNING
"filename : %s, set isICUSB to 0\n", filename
);
458 printk(KERN_WARNING
"filename : %s, set isICUSB to 1\n", filename
);
463 /* R/W if we can, R/O if we must */
464 ro
= curlun
->initially_ro
;
466 filp
= filp_open(filename
, O_RDWR
| O_LARGEFILE
, 0);
467 if (PTR_ERR(filp
) == -EROFS
|| PTR_ERR(filp
) == -EACCES
)
471 filp
= filp_open(filename
, O_RDONLY
| O_LARGEFILE
, 0);
473 LINFO(curlun
, "unable to open backing file: %s\n", filename
);
474 return PTR_ERR(filp
);
477 if (!(filp
->f_mode
& FMODE_WRITE
))
480 inode
= file_inode(filp
);
481 if ((!S_ISREG(inode
->i_mode
) && !S_ISBLK(inode
->i_mode
))) {
482 LINFO(curlun
, "invalid file type: %s\n", filename
);
487 * If we can't read the file, it's no good.
488 * If we can't write the file, use it read-only.
490 if (!(filp
->f_op
->read
|| filp
->f_op
->aio_read
)) {
491 LINFO(curlun
, "file not readable: %s\n", filename
);
494 if (!(filp
->f_op
->write
|| filp
->f_op
->aio_write
))
497 size
= i_size_read(inode
->i_mapping
->host
);
499 LINFO(curlun
, "unable to find file size: %s\n", filename
);
507 } else if (inode
->i_bdev
) {
508 blksize
= bdev_logical_block_size(inode
->i_bdev
);
509 blkbits
= blksize_bits(blksize
);
515 num_sectors
= size
>> blkbits
; /* File size in logic-block-size blocks */
518 min_sectors
= 300; /* Smallest track is 300 frames */
519 if (num_sectors
>= 256*60*75) {
520 num_sectors
= 256*60*75 - 1;
521 LINFO(curlun
, "file too big: %s\n", filename
);
522 LINFO(curlun
, "using only first %d blocks\n",
526 if (num_sectors
< min_sectors
) {
527 LINFO(curlun
, "file too small: %s\n", filename
);
532 if (fsg_lun_is_open(curlun
))
533 fsg_lun_close(curlun
);
535 curlun
->blksize
= blksize
;
536 curlun
->blkbits
= blkbits
;
539 curlun
->file_length
= size
;
540 curlun
->num_sectors
= num_sectors
;
541 LDBG(curlun
, "open backing file: %s\n", filename
);
550 /*-------------------------------------------------------------------------*/
553 * Sync the file data, don't bother with the metadata.
554 * This code was copied from fs/buffer.c:sys_fdatasync().
556 static int fsg_lun_fsync_sub(struct fsg_lun
*curlun
)
558 struct file
*filp
= curlun
->filp
;
560 if (curlun
->ro
|| !filp
)
562 return vfs_fsync(filp
, 1);
565 static void store_cdrom_address(u8
*dest
, int msf
, u32 addr
)
568 /* Convert to Minutes-Seconds-Frames */
569 addr
>>= 2; /* Convert to 2048-byte frames */
570 addr
+= 2*75; /* Lead-in occupies 2 seconds */
571 dest
[3] = addr
% 75; /* Frames */
573 dest
[2] = addr
% 60; /* Seconds */
575 dest
[1] = addr
; /* Minutes */
576 dest
[0] = 0; /* Reserved */
578 /* Absolute sector */
579 put_unaligned_be32(addr
, dest
);
584 * fsg_get_toc() - Builds a TOC with required format @format.
585 * @curlun: The LUN for which the TOC has to be built
586 * @msf: Min Sec Frame format or LBA format for address
587 * @format: TOC format code
588 * @buf: The buffer into which the TOC is built
590 * Builds a Table of Content which can be used as data for READ_TOC command.
591 * The TOC simulates a single session, single track CD-ROM mode 1 disc.
593 * Returns number of bytes written to @buf, -EINVAL if format not supported.
595 static int fsg_get_toc(struct fsg_lun
*curlun
, int msf
, int format
, u8
*buf
)
602 len
= 4 + 2*8; /* 4 byte header + 2 descriptors */
604 buf
[1] = len
- 2; /* TOC Length excludes length field */
606 buf
[2] = 1; /* First track number */
607 buf
[3] = 1; /* Last track number */
608 buf
[5] = 0x16; /* Data track, copying allowed */
609 buf
[6] = 0x01; /* Only track is number 1 */
610 store_cdrom_address(&buf
[8], msf
, 0);
612 buf
[13] = 0x16; /* Lead-out track is data */
613 buf
[14] = 0xAA; /* Lead-out track number */
614 store_cdrom_address(&buf
[16], msf
, curlun
->num_sectors
);
619 len
= 4 + 3*11; /* 4 byte header + 3 descriptors */
620 memset(buf
, 0, len
); /* Header + A0, A1 & A2 descriptors */
621 buf
[1] = len
- 2; /* TOC Length excludes length field */
622 buf
[2] = 1; /* First complete session */
623 buf
[3] = 1; /* Last complete session */
626 /* fill in A0, A1 and A2 points */
627 for (i
= 0; i
< 3; i
++) {
628 buf
[0] = 1; /* Session number */
629 buf
[1] = 0x16; /* Data track, copying allowed */
630 /* 2 - Track number 0 -> TOC */
631 buf
[3] = 0xA0 + i
; /* A0, A1, A2 point */
632 /* 4, 5, 6 - Min, sec, frame is zero */
633 buf
[8] = 1; /* Pmin: last track number */
634 buf
+= 11; /* go to next track descriptor */
636 buf
-= 11; /* go back to A2 descriptor */
638 /* For A2, 7, 8, 9, 10 - zero, Pmin, Psec, Pframe of Lead out */
639 store_cdrom_address(&buf
[7], msf
, curlun
->num_sectors
);
643 /* Multi-session, PMA, ATIP, CD-TEXT not supported/required */
650 /*-------------------------------------------------------------------------*/
653 static ssize_t
fsg_show_ro(struct device
*dev
, struct device_attribute
*attr
,
656 struct fsg_lun
*curlun
= fsg_lun_from_dev(dev
);
658 return sprintf(buf
, "%d\n", fsg_lun_is_open(curlun
)
660 : curlun
->initially_ro
);
663 static ssize_t
fsg_show_nofua(struct device
*dev
, struct device_attribute
*attr
,
666 struct fsg_lun
*curlun
= fsg_lun_from_dev(dev
);
668 return sprintf(buf
, "%u\n", curlun
->nofua
);
671 static ssize_t
fsg_show_file(struct device
*dev
, struct device_attribute
*attr
,
674 struct fsg_lun
*curlun
= fsg_lun_from_dev(dev
);
675 struct rw_semaphore
*filesem
= dev_get_drvdata(dev
);
680 if (fsg_lun_is_open(curlun
)) { /* Get the complete pathname */
681 p
= d_path(&curlun
->filp
->f_path
, buf
, PAGE_SIZE
- 1);
687 buf
[rc
] = '\n'; /* Add a newline */
690 } else { /* No file, return 0 bytes */
699 static ssize_t
fsg_store_ro(struct device
*dev
, struct device_attribute
*attr
,
700 const char *buf
, size_t count
)
703 struct fsg_lun
*curlun
= fsg_lun_from_dev(dev
);
704 struct rw_semaphore
*filesem
= dev_get_drvdata(dev
);
707 rc
= kstrtouint(buf
, 2, &ro
);
712 * Allow the write-enable status to change only while the
713 * backing file is closed.
716 if (fsg_lun_is_open(curlun
)) {
717 LDBG(curlun
, "read-only status change prevented\n");
721 curlun
->initially_ro
= ro
;
722 LDBG(curlun
, "read-only status set to %d\n", curlun
->ro
);
729 static ssize_t
fsg_store_nofua(struct device
*dev
,
730 struct device_attribute
*attr
,
731 const char *buf
, size_t count
)
733 struct fsg_lun
*curlun
= fsg_lun_from_dev(dev
);
737 ret
= kstrtouint(buf
, 2, &nofua
);
741 /* Sync data when switching from async mode to sync */
742 if (!nofua
&& curlun
->nofua
)
743 fsg_lun_fsync_sub(curlun
);
745 curlun
->nofua
= nofua
;
750 static ssize_t
fsg_store_file(struct device
*dev
, struct device_attribute
*attr
,
751 const char *buf
, size_t count
)
753 struct fsg_lun
*curlun
= fsg_lun_from_dev(dev
);
754 struct rw_semaphore
*filesem
= dev_get_drvdata(dev
);
758 #if !defined(CONFIG_USB_G_ANDROID)
759 /* disabled in android because we need to allow closing the backing file
760 * if the media was removed
762 if (curlun
->prevent_medium_removal
&& fsg_lun_is_open(curlun
)) {
763 LDBG(curlun
, "eject attempt prevented\n");
764 return -EBUSY
; /* "Door is locked" */
768 printk("fsg_store_file file=%s, count=%d, curlun->cdrom=%d\n", buf
, (int)count
, curlun
->cdrom
);
771 * WORKAROUND:VOLD would clean the file path after switching to bicr.
772 * So when the lun is being a CD-ROM a.k.a. BICR. Dont clean the file path to empty.
774 if (curlun
->cdrom
== 1 && count
== 1)
777 /* Remove a trailing newline */
778 if (count
> 0 && buf
[count
-1] == '\n')
779 ((char *) buf
)[count
-1] = 0; /* Ugh! */
781 /* Load new medium */
783 if (count
> 0 && buf
[0]) {
784 /* fsg_lun_open() will close existing file if any. */
785 rc
= fsg_lun_open(curlun
, buf
);
787 curlun
->unit_attention_data
=
788 SS_NOT_READY_TO_READY_TRANSITION
;
789 } else if (fsg_lun_is_open(curlun
)) {
790 fsg_lun_close(curlun
);
791 curlun
->unit_attention_data
= SS_MEDIUM_NOT_PRESENT
;
794 return (rc
< 0 ? rc
: count
);