-
Notifications
You must be signed in to change notification settings - Fork 6
/
IOBlockStorageDriver.h
1536 lines (1341 loc) · 57.5 KB
/
IOBlockStorageDriver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1998-2019 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*!
* @header IOBlockStorageDriver
* @abstract
* This header contains the IOBlockStorageDriver class definition.
*/
#ifndef _IOBLOCKSTORAGEDRIVER_H
#define _IOBLOCKSTORAGEDRIVER_H
#include <IOKit/IOTypes.h>
/*!
* @defined kIOBlockStorageDriverClass
* @abstract
* The name of the IOBlockStorageDriver class.
*/
#define kIOBlockStorageDriverClass "IOBlockStorageDriver"
/*!
* @defined kIOBlockStorageDriverStatisticsKey
* @abstract
* Holds a table of numeric values describing the driver's
* operating statistics.
* @discussion
* This property holds a table of numeric values describing the driver's
* operating statistics. The table is an OSDictionary, where each entry
* describes one given statistic.
*/
#define kIOBlockStorageDriverStatisticsKey "Statistics"
/*!
* @defined kIOBlockStorageDriverStatisticsBytesReadKey
* @abstract
* Describes the number of bytes read since the block storage
* driver was instantiated.
* @discussion
* This property describes the number of bytes read since the block storage
* driver was instantiated. It is one of the statistic entries listed under
* the top-level kIOBlockStorageDriverStatisticsKey property table. It has
* an OSNumber value.
*/
#define kIOBlockStorageDriverStatisticsBytesReadKey "Bytes (Read)"
/*!
* @defined kIOBlockStorageDriverStatisticsBytesWrittenKey
* @abstract
* Describes the number of bytes written since the block storage
* driver was instantiated.
* @discussion
* This property describes the number of bytes written since the block storage
* driver was instantiated. It is one of the statistic entries listed under the
* top-level kIOBlockStorageDriverStatisticsKey property table. It has an
* OSNumber value.
*/
#define kIOBlockStorageDriverStatisticsBytesWrittenKey "Bytes (Write)"
/*!
* @defined kIOBlockStorageDriverStatisticsReadErrorsKey
* @abstract
* Describes the number of read errors encountered since the block
* storage driver was instantiated.
* @discussion
* This property describes the number of read errors encountered since the block
* storage driver was instantiated. It is one of the statistic entries listed
* under the top-level kIOBlockStorageDriverStatisticsKey property table. It
* has an OSNumber value.
*/
#define kIOBlockStorageDriverStatisticsReadErrorsKey "Errors (Read)"
/*!
* @defined kIOBlockStorageDriverStatisticsWriteErrorsKey
* @abstract
* Describes the number of write errors encountered since the
* block storage driver was instantiated.
* @discussion
* This property describes the number of write errors encountered since the
* block storage driver was instantiated. It is one of the statistic entries
* listed under the top-level kIOBlockStorageDriverStatisticsKey property table.
* It has an OSNumber value.
*/
#define kIOBlockStorageDriverStatisticsWriteErrorsKey "Errors (Write)"
/*!
* @defined kIOBlockStorageDriverStatisticsLatentReadTimeKey
* @abstract
* Describes the number of nanoseconds of latency during reads
* since the block storage driver was instantiated.
* @discussion
* This property describes the number of nanoseconds of latency during reads
* since the block storage driver was instantiated. It is one of the statistic
* entries listed under the top-level kIOBlockStorageDriverStatisticsKey
* property table. It has an OSNumber value.
*/
#define kIOBlockStorageDriverStatisticsLatentReadTimeKey "Latency Time (Read)"
/*!
* @defined kIOBlockStorageDriverStatisticsLatentWriteTimeKey
* @abstract
* Describes the number of nanoseconds of latency during writes
* since the block storage driver was instantiated.
* @discussion
* This property describes the number of nanoseconds of latency during writes
* since the block storage driver was instantiated. It is one of the statistic
* entries listed under the top-level kIOBlockStorageDriverStatisticsKey
* property table. It has an OSNumber value.
*/
#define kIOBlockStorageDriverStatisticsLatentWriteTimeKey "Latency Time (Write)"
/*!
* @defined kIOBlockStorageDriverStatisticsReadsKey
* @abstract
* Describes the number of read operations processed since the
* block storage driver was instantiated.
* @discussion
* This property describes the number of read operations processed since the
* block storage driver was instantiated. It is one of the statistic entries
* listed under the top-level kIOBlockStorageDriverStatisticsKey property table.
* It has an OSNumber value.
*/
#define kIOBlockStorageDriverStatisticsReadsKey "Operations (Read)"
/*!
* @defined kIOBlockStorageDriverStatisticsWritesKey
* @abstract
* Describes the number of write operations processed since the
* block storage driver was instantiated.
* @discussion
* This property describes the number of write operations processed since the
* block storage driver was instantiated. It is one of the statistic entries
* listed under the top-level kIOBlockStorageDriverStatisticsKey property table.
* It has an OSNumber value.
*/
#define kIOBlockStorageDriverStatisticsWritesKey "Operations (Write)"
/*!
* @defined kIOBlockStorageDriverStatisticsReadRetriesKey
* @abstract
* Describes the number of read retries required since the block
* storage driver was instantiated.
* @discussion
* This property describes the number of read retries required since the block
* storage driver was instantiated. It is one of the statistic entries listed
* under the top-level kIOBlockStorageDriverStatisticsKey property table. It
* has an OSNumber value.
*/
#define kIOBlockStorageDriverStatisticsReadRetriesKey "Retries (Read)"
/*!
* @defined kIOBlockStorageDriverStatisticsWriteRetriesKey
* @abstract
* Describes the number of write retries required since the block
* storage driver was instantiated.
* @discussion
* This property describes the number of write retries required since the block
* storage driver was instantiated. It is one of the statistic entries listed
* under the top-level kIOBlockStorageDriverStatisticsKey property table. It
* has an OSNumber value.
*/
#define kIOBlockStorageDriverStatisticsWriteRetriesKey "Retries (Write)"
/*!
* @defined kIOBlockStorageDriverStatisticsTotalReadTimeKey
* @abstract
* Describes the number of nanoseconds spent performing reads
* since the block storage driver was instantiated.
* @discussion
* This property describes the number of nanoseconds spent performing reads
* since the block storage driver was instantiated. It is one of the statistic
* entries listed under the top-level kIOBlockStorageDriverStatisticsKey
* property table. It has an OSNumber value.
*/
#define kIOBlockStorageDriverStatisticsTotalReadTimeKey "Total Time (Read)"
/*!
* @defined kIOBlockStorageDriverStatisticsTotalWriteTimeKey
* @abstract
* Describes the number of nanoseconds spent performing writes
* since the block storage driver was instantiated.
* @discussion
* This property describes the number of nanoseconds spent performing writes
* since the block storage driver was instantiated. It is one of the statistic
* entries listed under the top-level kIOBlockStorageDriverStatisticsKey
* property table. It has an OSNumber value.
*/
#define kIOBlockStorageDriverStatisticsTotalWriteTimeKey "Total Time (Write)"
/*!
* @enum IOMediaState
* @abstract
* The different states that getMediaState() can report.
* @constant kIOMediaStateOffline
* Media is not available.
* @constant kIOMediaStateOnline
* Media is available and ready for operations.
* @constant kIOMediaStateBusy
* Media is available, but not ready for operations.
*/
enum
{
kIOMediaStateOffline = 0,
kIOMediaStateOnline = 1,
kIOMediaStateBusy = 2
};
typedef UInt32 IOMediaState;
#ifdef KERNEL
#ifdef __cplusplus
/*
* Kernel
*/
class IOPerfControlClient;
class IOUserBlockStorageDevice;
#include <IOKit/storage/IOBlockStorageDevice.h>
#include <IOKit/storage/IOMedia.h>
#include <IOKit/storage/IOStorage.h>
/*!
* @class IOBlockStorageDriver
* @abstract
* The common base class for generic block storage drivers.
* @discussion
* The IOBlockStorageDriver class is the common base class for generic block
* storage drivers. It matches and communicates via an IOBlockStorageDevice
* interface, and connects to the remainder of the storage framework via the
* IOStorage protocol. It extends the IOStorage protocol by implementing the
* appropriate open and close semantics, deblocking for unaligned transfers,
* polling for ejectable media, locking and ejection policies, media object
* creation and tear-down, and statistics gathering and reporting.
*
* Block storage drivers are split into two parts: the generic driver handles
* all generic device issues, independent of the lower-level transport
* mechanism (e.g. SCSI, ATA, USB, FireWire). All storage operations
* at the generic driver level are translated into a series of generic
* device operations. These operations are passed via the IOBlockStorageDevice
* nub to a transport driver, which implements the appropriate
* transport-dependent protocol to execute these operations.
*
* To determine the write-protect state of a device (or media), for
* example, the generic driver would issue a call to the
* Transport Driver's reportWriteProtection method. If this were a SCSI
* device, its transport driver would issue a Mode Sense command to
* extract the write-protection status bit. The transport driver then
* reports true or false to the generic driver.
*
* The generic driver therefore has no knowledge of, or involvement
* with, the actual commands and mechanisms used to communicate with
* the device. It is expected that the generic driver will rarely, if
* ever, need to be subclassed to handle device idiosyncrasies; rather,
* the transport driver should be changed via overrides.
*
* A generic driver could be subclassed to create a different type of
* generic device. The generic driver IOCDBlockStorageDriver class is
* a subclass of IOBlockStorageDriver, adding CD functions.
*/
class __exported IOBlockStorageDriver : public IOStorage
{
OSDeclareDefaultStructors(IOBlockStorageDriver);
public:
/*!
* @enum Statistics
* @abstract
* Indices for the different statistics that getStatistics() can report.
* @constant kStatisticsReads Number of read operations thus far.
* @constant kStatisticsBytesRead Number of bytes read thus far.
* @constant kStatisticsTotalReadTime Nanoseconds spent performing reads thus far.
* @constant kStatisticsLatentReadTime Nanoseconds of latency during reads thus far.
* @constant kStatisticsReadRetries Number of read retries thus far.
* @constant kStatisticsReadErrors Number of read errors thus far.
* @constant kStatisticsWrites Number of write operations thus far.
* @constant kStatisticsSingleBlockWrites Number of write operations for a single block thus far.
* @constant kStatisticsBytesWritten Number of bytes written thus far.
* @constant kStatisticsTotalWriteTime Nanoseconds spent performing writes thus far.
* @constant kStatisticsLatentWriteTime Nanoseconds of latency during writes thus far.
* @constant kStatisticsWriteRetries Number of write retries thus far.
* @constant kStatisticsWriteErrors Number of write errors thus far.
*/
enum Statistics
{
kStatisticsReads,
kStatisticsBytesRead,
kStatisticsTotalReadTime,
kStatisticsLatentReadTime,
kStatisticsReadRetries,
kStatisticsReadErrors,
kStatisticsWrites,
kStatisticsSingleBlockWrites,
kStatisticsBytesWritten,
kStatisticsTotalWriteTime,
kStatisticsLatentWriteTime,
kStatisticsWriteRetries,
kStatisticsWriteErrors
};
static const UInt32 kStatisticsCount = kStatisticsWriteErrors + 1;
protected:
struct Context;
struct ExpansionData
{
UInt64 reserved0000;
UInt64 maxReadBlockTransfer;
UInt64 maxWriteBlockTransfer;
UInt32 deblockRequestWriteLockCount;
UInt64 maxReadSegmentTransfer;
UInt64 maxWriteSegmentTransfer;
UInt64 maxReadSegmentByteTransfer;
UInt64 maxWriteSegmentByteTransfer;
UInt64 minSegmentAlignmentByteTransfer;
UInt64 maxSegmentWidthByteTransfer;
Context * contexts;
IOSimpleLock * contextsLock;
UInt32 contextsCount;
UInt32 contextsMaxCount;
IOPerfControlClient * perfControlClient;
IOUserBlockStorageDevice * userBlockStorageDevice;
};
ExpansionData * _expansionData;
#define _maxReadBlockTransfer \
IOBlockStorageDriver::_expansionData->maxReadBlockTransfer
#define _maxWriteBlockTransfer \
IOBlockStorageDriver::_expansionData->maxWriteBlockTransfer
#define _deblockRequestWriteLockCount \
IOBlockStorageDriver::_expansionData->deblockRequestWriteLockCount
#define _maxReadSegmentTransfer \
IOBlockStorageDriver::_expansionData->maxReadSegmentTransfer
#define _maxWriteSegmentTransfer \
IOBlockStorageDriver::_expansionData->maxWriteSegmentTransfer
#define _maxReadSegmentByteTransfer \
IOBlockStorageDriver::_expansionData->maxReadSegmentByteTransfer
#define _maxWriteSegmentByteTransfer \
IOBlockStorageDriver::_expansionData->maxWriteSegmentByteTransfer
#define _minSegmentAlignmentByteTransfer \
IOBlockStorageDriver::_expansionData->minSegmentAlignmentByteTransfer
#define _maxSegmentWidthByteTransfer \
IOBlockStorageDriver::_expansionData->maxSegmentWidthByteTransfer
#define _contexts \
IOBlockStorageDriver::_expansionData->contexts
#define _contextsLock \
IOBlockStorageDriver::_expansionData->contextsLock
#define _contextsCount \
IOBlockStorageDriver::_expansionData->contextsCount
#define _contextsMaxCount \
IOBlockStorageDriver::_expansionData->contextsMaxCount
#define _perfControlClient \
IOBlockStorageDriver::_expansionData->perfControlClient
#define _userBlockStorageDevice \
IOBlockStorageDriver::_expansionData->userBlockStorageDevice
OSSet * _openClients;
OSNumber * _statistics[kStatisticsCount];
/*
* @struct Context
* @discussion
* Context structure for a read/write operation. It describes the block size,
* and where applicable, a block type and block sub-type, for a data transfer,
* as well as the completion information for the original request. Note that
* the block type field is unused in the IOBlockStorageDriver class.
* @field block.size
* Block size for the operation.
* @field block.type
* Block type for the operation. Unused in IOBlockStorageDriver. The default
* value for this field is IOBlockStorageDriver::kBlockTypeStandard.
* @field block.typeSub
* Block sub-type for the operation. It's definition depends on block.type.
* Unused in IOBlockStorageDriver.
* @field request.byteStart
* Starting byte offset for the data transfer.
* @param request.buffer
* Buffer for the data transfer. The size of the buffer implies the size of
* the data transfer.
* @param request.attributes
* Attributes of the data transfer. See IOStorageAttributes.
* @param request.completion
* Completion routine to call once the data transfer is complete.
*/
struct Context
{
struct
{
UInt64 byteStart;
IOMemoryDescriptor * buffer;
IOStorageAttributes attributes;
IOStorageCompletion completion;
} request;
struct
{
UInt32 size;
UInt8 type;
UInt8 typeSub[3];
} block;
AbsoluteTime timeStart;
OSObject * perfControlContext;
UInt64 reserved0768;
UInt64 reserved0832;
UInt64 reserved0896;
Context * next;
};
static const UInt8 kBlockTypeStandard = 0x00;
using IOService::open;
/*
* Free all of this object's outstanding resources.
*
* This method's implementation is not typically overridden.
*/
void free() APPLE_KEXT_OVERRIDE;
/*!
* @function handleOpen
* @discussion
* The handleOpen method grants or denies permission to access this object
* to an interested client. The argument is an IOStorageAccess value that
* specifies the level of access desired -- reader or reader-writer.
*
* This method can be invoked to upgrade or downgrade the access level for
* an existing client as well. The previous access level will prevail for
* upgrades that fail, of course. A downgrade should never fail. If the
* new access level should be the same as the old for a given client, this
* method will do nothing and return success. In all cases, one, singular
* close-per-client is expected for all opens-per-client received.
*
* This implementation replaces the IOService definition of handleIsOpen().
* @param client
* Client requesting the open.
* @param options
* Options for the open. Set to zero.
* @param access
* Access level for the open. Set to kIOStorageAccessReader or
* kIOStorageAccessReaderWriter.
* @result
* Returns true if the open was successful, false otherwise.
*/
virtual bool handleOpen(IOService * client,
IOOptionBits options,
void * access) APPLE_KEXT_OVERRIDE;
/*!
* @function handleIsOpen
* @discussion
* The handleIsOpen method determines whether the specified client, or any
* client if none is specified, presently has an open on this object.
*
* This implementation replaces the IOService definition of handleIsOpen().
* @param client
* Client to check the open state of. Set to zero to check the open state
* of all clients.
* @result
* Returns true if the client was (or clients were) open, false otherwise.
*/
virtual bool handleIsOpen(const IOService * client) const APPLE_KEXT_OVERRIDE;
/*!
* @function handleClose
* @discussion
* The handleClose method closes the client's access to this object.
*
* This implementation replaces the IOService definition of handleIsOpen().
* @param client
* Client requesting the close.
* @param options
* Options for the close. Set to zero.
*/
virtual void handleClose(IOService * client, IOOptionBits options) APPLE_KEXT_OVERRIDE;
/*!
* @function addToBytesTransferred
* @discussion
* Update the total number of bytes transferred, the total transfer time,
* and the total latency time -- used for statistics.
*
* This method's implementation is not typically overridden.
* @param bytesTransferred
* Number of bytes transferred in this operation.
* @param totalTime
* Nanoseconds spent performing this operation.
* @param latentTime
* Nanoseconds of latency during this operation.
* @param isWrite
* Indicates whether this operation was a write, otherwise is was a read.
*/
virtual void addToBytesTransferred(UInt64 bytesTransferred,
UInt64 totalTime,
UInt64 latentTime,
bool isWrite);
/*!
* @function incrementErrors
* @discussion
* Update the total error count -- used for statistics.
*
* This method's implementation is not typically overridden.
* @param isWrite
* Indicates whether this operation was a write, otherwise is was a read.
*/
virtual void incrementErrors(bool isWrite);
/*!
* @function incrementRetries
* @discussion
* Update the total retry count -- used for statistics.
*
* This method's implementation is not typically overridden.
* @param isWrite
* Indicates whether this operation was a write, otherwise is was a read.
*/
virtual void incrementRetries(bool isWrite);
/*!
* @function allocateContext
* @discussion
* Allocate a context structure for a read/write operation.
* @result
* Context structure.
*/
virtual Context * allocateContext();
/*!
* @function deleteContext
* @discussion
* Delete a context structure from a read/write operation.
* @param context
* Context structure to be deleted.
*/
virtual void deleteContext(Context * context);
/*!
* @function deblockRequest
* @discussion
* The deblockRequest method checks to see if the incoming request rests
* on the media's block boundaries, and if not, deblocks it. Deblocking
* involves rounding out the request to the nearest block boundaries and
* transferring the excess bytes into a scratch buffer.
*
* This method is part of a sequence of methods invoked for each read/write
* request. The first is prepareRequest, which allocates and prepares some
* context for the transfer; the second is deblockRequest, which aligns the
* transfer at the media's block boundaries; third is breakUpRequest, which
* breaks up the transfer into multiple sub-transfers when certain hardware
* constraints are exceeded; fourth is executeRequest, which implements the
* actual transfer from the block storage device.
*
* This method's implementation is not typically overridden.
* @param byteStart
* Starting byte offset for the data transfer.
* @param buffer
* Buffer for the data transfer. The size of the buffer implies the size of
* the data transfer.
* @param attributes
* Attributes of the data transfer. See IOStorageAttributes. It is the
* responsibility of the callee to maintain the information for the duration
* of the data transfer, as necessary.
* @param completion
* Completion routine to call once the data transfer is complete. It is the
* responsibility of the callee to maintain the information for the duration
* of the data transfer, as necessary.
* @param context
* Additional context information for the data transfer (e.g. block size).
*/
virtual void deblockRequest(UInt64 byteStart,
IOMemoryDescriptor * buffer,
IOStorageAttributes * attributes,
IOStorageCompletion * completion,
Context * context);
/*!
* @function executeRequest
* @discussion
* Execute an asynchronous storage request. The request is guaranteed to be
* block-aligned.
*
* This method is part of a sequence of methods invoked for each read/write
* request. The first is prepareRequest, which allocates and prepares some
* context for the transfer; the second is deblockRequest, which aligns the
* transfer at the media's block boundaries; third is breakUpRequest, which
* breaks up the transfer into multiple sub-transfers when certain hardware
* constraints are exceeded; fourth is executeRequest, which implements the
* actual transfer from the block storage device.
* @param byteStart
* Starting byte offset for the data transfer.
* @param buffer
* Buffer for the data transfer. The size of the buffer implies the size of
* the data transfer.
* @param attributes
* Attributes of the data transfer. See IOStorageAttributes. It is the
* responsibility of the callee to maintain the information for the duration
* of the data transfer, as necessary.
* @param completion
* Completion routine to call once the data transfer is complete. It is the
* responsibility of the callee to maintain the information for the duration
* of the data transfer, as necessary.
* @param context
* Additional context information for the data transfer (e.g. block size).
*/
virtual void executeRequest(UInt64 byteStart,
IOMemoryDescriptor * buffer,
IOStorageAttributes * attributes,
IOStorageCompletion * completion,
Context * context);
/*!
* @function handleStart
* @discussion
* Prepare the block storage driver for operation.
*
* This is where a media object needs to be created for fixed media, and
* optionally for removable media.
*
* Note that this method is called from within the start() routine;
* if this method returns successfully, it should be prepared to accept
* any of IOBlockStorageDriver's APIs.
* @param provider
* This object's provider.
* @result
* Returns true on success, false otherwise.
*/
virtual bool handleStart(IOService * provider);
#if TARGET_OS_OSX
virtual bool handleYield(IOService * provider,
IOOptionBits options = 0,
void * argument = 0) __attribute__ ((deprecated));
#endif /* TARGET_OS_OSX */
/*!
* @function getMediaBlockSize
* @discussion
* Ask the driver about the media's natural block size.
* @result
* Natural block size, in bytes.
*/
virtual UInt64 getMediaBlockSize() const;
public:
using IOStorage::open;
using IOStorage::read;
using IOStorage::write;
/*
* Initialize this object's minimal state.
*
* This method's implementation is not typically overridden.
*/
virtual bool init(OSDictionary * properties = 0) APPLE_KEXT_OVERRIDE;
/*
* This method is called once we have been attached to the provider object.
*
* This method's implementation is not typically overridden.
*/
virtual bool start(IOService * provider) APPLE_KEXT_OVERRIDE;
/*
* This method is called before we are detached from the provider object.
*
* This method's implementation is not typically overridden.
*/
virtual void stop(IOService * provider) APPLE_KEXT_OVERRIDE;
virtual bool didTerminate(IOService * provider,
IOOptionBits options,
bool * defer) APPLE_KEXT_OVERRIDE;
#if TARGET_OS_OSX
virtual bool yield(IOService * provider,
IOOptionBits options = 0,
void * argument = 0) __attribute__ ((deprecated));
#endif /* TARGET_OS_OSX */
/*!
* @function read
* @discussion
* The read method is the receiving end for all read requests from the
* storage framework (through the media object created by this driver).
*
* This method initiates a sequence of methods (stages) for each read/write
* request. The first is prepareRequest, which allocates and prepares some
* context for the transfer; the second is deblockRequest, which aligns the
* transfer at the media's block boundaries; third is breakUpRequest, which
* breaks up the transfer into multiple sub-transfers when certain hardware
* constraints are exceeded; fourth is executeRequest, which implements the
* actual transfer from the block storage device.
*
* This method's implementation is not typically overridden.
* @param client
* Client requesting the read.
* @param byteStart
* Starting byte offset for the data transfer.
* @param buffer
* Buffer for the data transfer. The size of the buffer implies the size of
* the data transfer.
* @param attributes
* Attributes of the data transfer. See IOStorageAttributes. It is the
* responsibility of the callee to maintain the information for the duration
* of the data transfer, as necessary.
* @param completion
* Completion routine to call once the data transfer is complete. It is the
* responsibility of the callee to maintain the information for the duration
* of the data transfer, as necessary.
*/
virtual void read(IOService * client,
UInt64 byteStart,
IOMemoryDescriptor * buffer,
IOStorageAttributes * attributes,
IOStorageCompletion * completion) APPLE_KEXT_OVERRIDE;
/*!
* @function write
* @discussion
* The write method is the receiving end for all write requests from the
* storage framework (through the media object created by this driver).
*
* This method initiates a sequence of methods (stages) for each read/write
* request. The first is prepareRequest, which allocates and prepares some
* context for the transfer; the second is deblockRequest, which aligns the
* transfer at the media's block boundaries; third is breakUpRequest, which
* breaks up the transfer into multiple sub-transfers when certain hardware
* constraints are exceeded; fourth is executeRequest, which implements the
* actual transfer from the block storage device.
*
* This method's implementation is not typically overridden.
* @param client
* Client requesting the write.
* @param byteStart
* Starting byte offset for the data transfer.
* @param buffer
* Buffer for the data transfer. The size of the buffer implies the size of
* the data transfer.
* @param attributes
* Attributes of the data transfer. See IOStorageAttributes. It is the
* responsibility of the callee to maintain the information for the duration
* of the data transfer, as necessary.
* @param completion
* Completion routine to call once the data transfer is complete. It is the
* responsibility of the callee to maintain the information for the duration
* of the data transfer, as necessary.
*/
virtual void write(IOService * client,
UInt64 byteStart,
IOMemoryDescriptor * buffer,
IOStorageAttributes * attributes,
IOStorageCompletion * completion) APPLE_KEXT_OVERRIDE;
/*!
* @function synchronize
* @discussion
* Flush the cached data in the storage object, if any.
* @param client
* Client requesting the synchronization.
* @param byteStart
* Starting byte offset for the synchronization.
* @param byteCount
* Size of the synchronization. Set to zero to specify the end-of-media.
* @param options
* Options for the synchronization. See IOStorageSynchronizeOptions.
* @result
* Returns the status of the synchronization.
*/
virtual IOReturn synchronize(IOService * client,
UInt64 byteStart,
UInt64 byteCount,
IOStorageSynchronizeOptions options = 0) APPLE_KEXT_OVERRIDE;
/*!
* @function unmap
* @discussion
* Delete unused data from the storage object at the specified byte offsets.
* @param client
* Client requesting the operation.
* @param extents
* List of extents. See IOStorageExtent. It is legal for the callee to
* overwrite the contents of this buffer in order to satisfy the request.
* @param extentsCount
* Number of extents.
* @param options
* Options for the unmap. See IOStorageUnmapOptions.
* @result
* Returns the status of the operation.
*/
virtual IOReturn unmap(IOService * client,
IOStorageExtent * extents,
UInt32 extentsCount,
IOStorageUnmapOptions options = 0) APPLE_KEXT_OVERRIDE;
/*!
* @function getProvisionStatus
* @discussion
* Get device block provision status
* @param client
* Client requesting the synchronization.
* @param byteStart
* Byte offset of logical extent on the device.
* @param byteCount
* Byte length of logical extent on the device, 0 mean the entire remaining space.
* @param extentsCount
* Number of extents allocated in extents. On return, this parameter indicate number
* of provision extents returned.
* @param extents
* List of provision extents. See IOStorageProvisionExtents.
* @result
* Returns the status of the getProvisionStatus.
*/
virtual IOReturn getProvisionStatus(IOService * client,
UInt64 byteStart,
UInt64 byteCount,
UInt32 * extentsCount,
IOStorageProvisionExtent * extents,
IOStorageGetProvisionStatusOptions options = 0) APPLE_KEXT_OVERRIDE;
/*!
* @function lockPhysicalExtents
* @discussion
* Lock the contents of the storage object against relocation temporarily,
* for the purpose of getting physical extents.
* @param client
* Client requesting the operation.
* @result
* Returns true if the lock was successful, false otherwise.
*/
virtual bool lockPhysicalExtents(IOService * client) APPLE_KEXT_OVERRIDE;
/*!
* @function copyPhysicalExtent
* @discussion
* Convert the specified byte offset into a physical byte offset, relative
* to a physical storage object. This call should only be made within the
* context of lockPhysicalExtents().
* @param client
* Client requesting the operation.
* @param byteStart
* Starting byte offset for the operation. Returns a physical byte offset,
* relative to the physical storage object, on success.
* @param byteCount
* Size of the operation. Returns the actual number of bytes which can be
* transferred, relative to the physical storage object, on success.
* @result
* A reference to the physical storage object, which should be released by
* the caller, or a null on error.
*/
virtual IOStorage * copyPhysicalExtent(IOService * client,
UInt64 * byteStart,
UInt64 * byteCount) APPLE_KEXT_OVERRIDE;
/*!
* @function unlockPhysicalExtents
* @discussion
* Unlock the contents of the storage object for relocation again. This
* call must balance a successful call to lockPhysicalExtents().
* @param client
* Client requesting the operation.
*/
virtual void unlockPhysicalExtents(IOService * client) APPLE_KEXT_OVERRIDE;
/*!
* @function setPriority
* @discussion
* Reprioritize read or write requests at the specified byte offsets.
* @param client
* Client requesting the operation.
* @param extents
* List of extents. See IOStorageExtent. It is legal for the callee to
* overwrite the contents of this buffer in order to satisfy the request.
* @param extentsCount
* Number of extents.
* @param priority
* New priority. See IOStoragePriority.
* @result
* Returns the status of the operation.
*/
virtual IOReturn setPriority(IOService * client,
IOStorageExtent * extents,
UInt32 extentsCount,
IOStoragePriority priority) APPLE_KEXT_OVERRIDE;
/*!
* @function ejectMedia
* @discussion
* Eject the media from the device. The driver is responsible for tearing
* down the media object it created before proceeding with the eject. If
* the tear-down fails, an error should be returned.
* @result
* An IOReturn code.
*/
virtual IOReturn ejectMedia();
/*!
* @function formatMedia
* @discussion
* Format the media with the specified byte capacity. The driver is
* responsible for tearing down the media object and recreating it.
* @param byteCapacity
* Number of bytes to format media to.
* @result
* An IOReturn code.
*/
virtual IOReturn formatMedia(UInt64 byteCapacity);
#if TARGET_OS_OSX
virtual IOReturn lockMedia(bool lock) __attribute__ ((deprecated));
virtual IOReturn pollMedia() __attribute__ ((deprecated));
#endif /* TARGET_OS_OSX */
/*!
* @function isMediaEjectable
* @discussion
* Ask the driver whether the media is ejectable.
* @result
* Returns true if the media is ejectable, false otherwise.
*/
virtual bool isMediaEjectable() const;
/*!
* @function isMediaRemovable