Subversion Repositories Kolibri OS

Rev

Rev 2455 | Rev 3164 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2455 mario79 3
;; Copyright (C) KolibriOS team 2011-2012. All rights reserved. ;;
2288 clevermous 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
$Revision: 2643 $
9
 
10
; =============================================================================
11
; ================================= Constants =================================
12
; =============================================================================
13
; Error codes for callback functions.
14
DISK_STATUS_OK              = 0 ; success
15
DISK_STATUS_GENERAL_ERROR   = -1; if no other code is suitable
16
DISK_STATUS_INVALID_CALL    = 1 ; invalid input parameters
17
DISK_STATUS_NO_MEDIA        = 2 ; no media present
18
DISK_STATUS_END_OF_MEDIA    = 3 ; end of media while reading/writing data
19
; Driver flags. Represent bits in DISK.DriverFlags.
20
DISK_NO_INSERT_NOTIFICATION = 1
21
; Media flags. Represent bits in DISKMEDIAINFO.Flags.
22
DISK_MEDIA_READONLY = 1
23
 
24
; If too many partitions are detected,there is probably an error on the disk.
25
; 256 partitions should be enough for any reasonable use.
26
; Also, the same number is limiting the number of MBRs to process; if
27
; too many MBRs are visible,there probably is a loop in the MBR structure.
28
MAX_NUM_PARTITIONS = 256
29
 
30
; =============================================================================
31
; ================================ Structures =================================
32
; =============================================================================
33
; This structure defines all callback functions for working with the physical
34
; device. They are implemented by a driver. Objects with this structure reside
35
; in a driver.
2381 hidnplayr 36
struct  DISKFUNC
37
        strucsize       dd ?
2288 clevermous 38
; Size of the structure. This field is intended for possible extensions of
39
; this structure. If a new function is added to this structure and a driver
40
; implements an old version, the caller can detect this by checking .strucsize,
41
; so the driver remains compatible.
2381 hidnplayr 42
        close           dd ?
2288 clevermous 43
; The pointer to the function which frees all driver-specific resources for
44
; the disk.
45
; Optional, may be NULL.
46
; void close(void* userdata);
2381 hidnplayr 47
        closemedia      dd ?
2288 clevermous 48
; The pointer to the function which informs the driver that the kernel has
49
; finished all processing with the current media. If media is removed, the
50
; driver should decline all requests to that media with DISK_STATUS_NO_MEDIA,
51
; even if new media is inserted, until this function is called. If media is
52
; removed, a new call to 'disk_media_changed' is not allowed until this
53
; function is called.
54
; Optional, may be NULL (if media is not removable).
55
; void closemedia(void* userdata);
2381 hidnplayr 56
        querymedia      dd ?
2288 clevermous 57
; The pointer to the function which determines capabilities of the media.
58
; int querymedia(void* userdata, DISKMEDIAINFO* info);
59
; Return value: one of DISK_STATUS_*
2381 hidnplayr 60
        read            dd ?
2288 clevermous 61
; The pointer to the function which reads data from the device.
62
; int read(void* userdata, void* buffer, __int64 startsector, int* numsectors);
63
; input: *numsectors = number of sectors to read
64
; output: *numsectors = number of sectors which were successfully read
65
; Return value: one of DISK_STATUS_*
2381 hidnplayr 66
        write           dd ?
2288 clevermous 67
; The pointer to the function which writes data to the device.
68
; Optional, may be NULL.
69
; int write(void* userdata, void* buffer, __int64 startsector, int* numsectors);
70
; input: *numsectors = number of sectors to write
71
; output: *numsectors = number of sectors which were successfully written
72
; Return value: one of DISK_STATUS_*
2381 hidnplayr 73
        flush           dd ?
2288 clevermous 74
; The pointer to the function which flushes the internal device cache.
75
; Optional, may be NULL.
76
; int flush(void* userdata);
77
; Return value: one of DISK_STATUS_*
78
; Note that read/write are called by the cache manager, so a driver should not
79
; create a software cache. This function is implemented for flushing a hardware
80
; cache, if it exists.
2381 hidnplayr 81
        adjust_cache_size       dd ?
2288 clevermous 82
; The pointer to the function which returns the cache size for this device.
83
; Optional, may be NULL.
84
; unsigned int adjust_cache_size(unsigned int suggested_size);
85
; Return value: 0 = disable cache, otherwise = used cache size in bytes.
86
ends
87
 
88
; This structure holds information on a medium.
89
; Objects with this structure are allocated by the kernel as a part of the DISK
90
; structure and are filled by a driver in the 'querymedia' callback.
2381 hidnplayr 91
struct  DISKMEDIAINFO
92
        Flags           dd ?
2288 clevermous 93
; Combination of DISK_MEDIA_* bits.
2381 hidnplayr 94
        SectorSize      dd ?
2288 clevermous 95
; Size of the sector.
2381 hidnplayr 96
        Capacity        dq ?
2288 clevermous 97
; Size of the media in sectors.
98
ends
99
 
100
; This structure represents the disk cache. To follow the old implementation,
101
; there are two distinct caches for a disk, one for "system" data,and the other
102
; for "application" data.
2381 hidnplayr 103
struct  DISKCACHE
104
        mutex           MUTEX
2288 clevermous 105
; Lock to protect the cache.
106
; The following fields are inherited from data32.inc:cache_ideX.
2381 hidnplayr 107
        pointer         dd ?
108
        data_size       dd ?    ; unused
109
        data            dd ?
110
        sad_size        dd ?
111
        search_start    dd ?
2288 clevermous 112
ends
113
 
114
; This structure represents a disk device and its media for the kernel.
115
; This structure is allocated by the kernel in the 'disk_add' function,
116
; freed in the 'disk_dereference' function.
2381 hidnplayr 117
struct  DISK
2288 clevermous 118
; Fields of disk object
2381 hidnplayr 119
        Next            dd ?
120
        Prev            dd ?
2288 clevermous 121
; All disk devices are linked in one list with these two fields.
122
; Head of the list is the 'disk_list' variable.
2381 hidnplayr 123
        Functions       dd ?
2288 clevermous 124
; Pointer to the 'DISKFUNC' structure with driver functions.
2381 hidnplayr 125
        Name            dd ?
2288 clevermous 126
; Pointer to the string used for accesses through the global filesystem.
2381 hidnplayr 127
        UserData        dd ?
2288 clevermous 128
; This field is passed to all callback functions so a driver can decide which
129
; physical device is addressed.
2381 hidnplayr 130
        DriverFlags     dd ?
2288 clevermous 131
; Bitfield. Currently only DISK_NO_INSERT_NOTIFICATION bit is defined.
132
; If it is set, the driver will never issue 'disk_media_changed' notification
133
; with argument set to true, so the kernel must try to detect media during
134
; requests from the file system.
2381 hidnplayr 135
        RefCount        dd ?
2288 clevermous 136
; Count of active references to this structure. One reference is kept during
137
; the lifetime of the structure between 'disk_add' and 'disk_del'.
138
; Another reference is taken during any filesystem operation for this disk.
139
; One reference is added if media is inserted.
140
; The structure is destroyed when the reference count decrements to zero:
141
; this usually occurs in 'disk_del', but can be delayed to the end of last
142
; filesystem operation, if one is active.
2381 hidnplayr 143
        MediaLock       MUTEX
2288 clevermous 144
; Lock to protect the MEDIA structure. See the description after
145
; 'disk_list_mutex' for the locking strategy.
146
; Fields of media object
2381 hidnplayr 147
        MediaInserted   db ?
2288 clevermous 148
; 0 if media is not inserted, nonzero otherwise.
2381 hidnplayr 149
        MediaUsed       db ?
2288 clevermous 150
; 0 if media fields are not used, nonzero otherwise. If .MediaRefCount is
151
; nonzero, this field is nonzero too; however, when .MediaRefCount goes
152
; to zero, there is some time interval during which media object is still used.
2381 hidnplayr 153
        align 4
2288 clevermous 154
; The following fields are not valid unless either .MediaInserted is nonzero
155
; or they are accessed from a code which has obtained the reference when
156
; .MediaInserted was nonzero.
2381 hidnplayr 157
        MediaRefCount   dd ?
2288 clevermous 158
; Count of active references to the media object. One reference is kept during
159
; the lifetime of the media between two calls to 'disk_media_changed'.
160
; Another reference is taken during any filesystem operation for this media.
161
; The callback 'closemedia' is called when the reference count decrements to
162
; zero: this usually occurs in 'disk_media_changed', but can be delayed to the
163
; end of the last filesystem operation, if one is active.
2381 hidnplayr 164
        MediaInfo       DISKMEDIAINFO
2288 clevermous 165
; This field keeps information on the current media.
2381 hidnplayr 166
        NumPartitions   dd ?
2288 clevermous 167
; Number of partitions on this media.
2381 hidnplayr 168
        Partitions      dd ?
2288 clevermous 169
; Pointer to array of .NumPartitions pointers to PARTITION structures.
2381 hidnplayr 170
        cache_size      dd ?
2288 clevermous 171
; inherited from cache_ideX_size
2381 hidnplayr 172
        SysCache        DISKCACHE
173
        AppCache        DISKCACHE
2288 clevermous 174
; Two caches for the disk.
175
ends
176
 
177
; This structure represents one partition for the kernel. This is a base
178
; template, the actual contents after common fields is determined by the
179
; file system code for this partition.
2381 hidnplayr 180
struct  PARTITION
181
        FirstSector     dq ?
2288 clevermous 182
; First sector of the partition.
2381 hidnplayr 183
        Length          dq ?
2288 clevermous 184
; Length of the partition in sectors.
2381 hidnplayr 185
        Disk            dd ?
2288 clevermous 186
; Pointer to parent DISK structure.
2381 hidnplayr 187
        FSUserFunctions dd ?
2288 clevermous 188
; Handlers for the sysfunction 70h. This field is a pointer to the following
189
; array. The first dword is a number of supported subfunctions, other dwords
190
; point to handlers of corresponding subfunctions.
191
; This field is 0 if file system is not recognized.
192
; ...fs-specific data may follow...
193
ends
194
 
195
; This is an external structure, it represents an entry in the partition table.