Subversion Repositories Kolibri OS

Rev

Rev 379 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 379 Rev 381
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                      ;;
2
;;                                                                      ;;
3
;; System service for filesystem call                                   ;;
3
;; System service for filesystem call                                   ;;
4
;; (C) 2004 Ville Turjanmaa, License: GPL                               ;;
4
;; (C) 2004 Ville Turjanmaa, License: GPL                               ;;
5
;; 29.04.2006 Elimination of hangup after the                           ;;
5
;; 29.04.2006 Elimination of hangup after the                           ;;
6
;;            expiration hd_wait_timeout (for LBA) -  Mario79           ;;
6
;;            expiration hd_wait_timeout (for LBA) -  Mario79           ;;
7
;; 15.01.2005 get file size/attr/date, file_append (only for hd) - ATV  ;;
7
;; 15.01.2005 get file size/attr/date, file_append (only for hd) - ATV  ;;
8
;; 23.11.2004 test if hd/partition is set - ATV                         ;;
8
;; 23.11.2004 test if hd/partition is set - ATV                         ;;
9
;; 18.11.2004 get_disk_info and more error codes - ATV                  ;;
9
;; 18.11.2004 get_disk_info and more error codes - ATV                  ;;
10
;; 08.11.2004 expand_pathz and rename (only for hd) - ATV               ;;
10
;; 08.11.2004 expand_pathz and rename (only for hd) - ATV               ;;
11
;; 20.10.2004 Makedir/Removedir (only for hd) - ATV                     ;;
11
;; 20.10.2004 Makedir/Removedir (only for hd) - ATV                     ;;
12
;;                                                                      ;;
12
;;                                                                      ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14
 
14
 
15
iglobal
15
iglobal
16
dir0:        db  'HARDDISK   '
16
dir0:        db  'HARDDISK   '
17
             db  'RAMDISK    '
17
             db  'RAMDISK    '
18
             db  'FLOPPYDISK '
18
             db  'FLOPPYDISK '
19
             db  0
19
             db  0
20
 
20
 
21
dir1:        db  'FIRST      '
21
dir1:        db  'FIRST      '
22
             db  'SECOND     '
22
             db  'SECOND     '
23
             db  'THIRD      '
23
             db  'THIRD      '
24
             db  'FOURTH     '
24
             db  'FOURTH     '
25
             db  0
25
             db  0
26
 
26
 
27
not_select_IDE db 0
27
not_select_IDE db 0
28
 
28
 
29
hd_address_table:  dd  0x1f0,0x00,0x1f0,0x10
29
hd_address_table:  dd  0x1f0,0x00,0x1f0,0x10
30
                   dd  0x170,0x00,0x170,0x10
30
                   dd  0x170,0x00,0x170,0x10
31
endg
31
endg
32
 
32
 
33
file_system:
33
file_system:
34
 
34
 
35
; IN:
35
; IN:
36
;
36
;
37
; eax = 0  ; read file          /RamDisk/First  6
37
; eax = 0  ; read file          /RamDisk/First  6
38
; eax = 1  ; write file         /RamDisk/First 33   /HardDisk/First 56
38
; eax = 1  ; write file         /RamDisk/First 33   /HardDisk/First 56
39
; eax = 8  ; lba read
39
; eax = 8  ; lba read
40
; eax = 15 ; get_disk_info
40
; eax = 15 ; get_disk_info
41
;
41
;
42
; OUT:
42
; OUT:
43
;
43
;
44
; eax = 0  : read ok
44
; eax = 0  : read ok
45
; eax = 1  : no hd base and/or partition defined
45
; eax = 1  : no hd base and/or partition defined
46
; eax = 2  : function is unsupported for this FS
46
; eax = 2  : function is unsupported for this FS
47
; eax = 3  : unknown FS
47
; eax = 3  : unknown FS
48
; eax = 4  : partition not defined at hd
48
; eax = 4  : partition not defined at hd
49
; eax = 5  : file not found
49
; eax = 5  : file not found
50
; eax = 6  : end of file
50
; eax = 6  : end of file
51
; eax = 7  : memory pointer not in application area
51
; eax = 7  : memory pointer not in application area
52
; eax = 8  : disk full
52
; eax = 8  : disk full
53
; eax = 9  : fat table corrupted
53
; eax = 9  : fat table corrupted
54
; eax = 10 : access denied
54
; eax = 10 : access denied
55
; eax = 11 : disk error
55
; eax = 11 : disk error
56
;
56
;
57
; ebx = size
57
; ebx = size
58
 
58
 
59
; \begin{diamond}[18.03.2006]
59
; \begin{diamond}[18.03.2006]
60
; for subfunction 16 (start application) error codes must be negative
60
; for subfunction 16 (start application) error codes must be negative
61
;    because positive values are valid PIDs
61
;    because positive values are valid PIDs
62
; so possible return values are:
62
; so possible return values are:
63
; eax > 0 : process created, eax=PID
63
; eax > 0 : process created, eax=PID
64
 
64
 
65
; -0x10 <= eax < 0 : -eax is filesystem error code:
65
; -0x10 <= eax < 0 : -eax is filesystem error code:
66
; eax = -1  = 0xFFFFFFFF : no hd base and/or partition defined
66
; eax = -1  = 0xFFFFFFFF : no hd base and/or partition defined
67
; eax = -3  = 0xFFFFFFFD : unknown FS
67
; eax = -3  = 0xFFFFFFFD : unknown FS
68
; eax = -5  = 0xFFFFFFFB : file not found
68
; eax = -5  = 0xFFFFFFFB : file not found
69
; eax = -6  = 0xFFFFFFFA : unexpected end of file (probably not executable file)
69
; eax = -6  = 0xFFFFFFFA : unexpected end of file (probably not executable file)
70
; eax = -9  = 0xFFFFFFF7 : fat table corrupted
70
; eax = -9  = 0xFFFFFFF7 : fat table corrupted
71
; eax = -10 = 0xFFFFFFF6 : access denied
71
; eax = -10 = 0xFFFFFFF6 : access denied
72
 
72
 
73
; -0x20 <= eax < -0x10: eax is process creation error code:
73
; -0x20 <= eax < -0x10: eax is process creation error code:
74
; eax = -0x20 = 0xFFFFFFE0 : too many processes
74
; eax = -0x20 = 0xFFFFFFE0 : too many processes
75
; eax = -0x1F = 0xFFFFFFE1 : not Menuet/Kolibri executable
75
; eax = -0x1F = 0xFFFFFFE1 : not Menuet/Kolibri executable
76
; eax = -0x1E = 0xFFFFFFE2 : no memory
76
; eax = -0x1E = 0xFFFFFFE2 : no memory
77
 
77
 
78
; ebx is not changed
78
; ebx is not changed
79
 
79
 
80
; \end{diamond}[18.03.2006]
80
; \end{diamond}[18.03.2006]
81
 
81
 
82
    ; Extract parameters
82
    ; Extract parameters
83
    add    eax, std_application_base_address    ; abs start of info block
83
    add    eax, std_application_base_address    ; abs start of info block
84
 
84
 
85
    cmp   dword [eax+0],15      ; GET_DISK_INFO
85
    cmp   dword [eax+0],15      ; GET_DISK_INFO
86
    je    fs_info
86
    je    fs_info
87
 
87
 
88
    cmp   dword [CURRENT_TASK],1      ; no memory checks for kernel requests
88
    cmp   dword [CURRENT_TASK],1      ; no memory checks for kernel requests
89
    jz    no_checks_for_kernel
89
    jz    no_checks_for_kernel
90
    mov   edx,eax
90
    mov   edx,eax
91
    cmp   dword [eax+0],1
91
    cmp   dword [eax+0],1
92
    jnz   .usual_check
92
    jnz   .usual_check
93
    mov   ebx,[eax+12]
93
    mov   ebx,[eax+12]
94
    add   ebx,std_application_base_address
94
    add   ebx,std_application_base_address
95
    mov   ecx,[eax+8]
95
    mov   ecx,[eax+8]
96
    call  check_region
96
    call  check_region
97
    test  eax,eax
97
    test  eax,eax
98
    jnz   area_in_app_mem
98
    jnz   area_in_app_mem
99
 
99
 
100
.error_output:
100
.error_output:
101
    mov   esi,buffer_failed
101
    mov   esi,buffer_failed
102
    call  sys_msg_board_str
102
    call  sys_msg_board_str
103
;    mov   eax,7
103
;    mov   eax,7
104
    mov   dword [esp+36],7
104
    mov   dword [esp+36],7
105
    ret
105
    ret
106
iglobal
106
iglobal
107
  buffer_failed db 'K : Buffer check failed',13,10,0
107
  buffer_failed db 'K : Buffer check failed',13,10,0
108
endg
108
endg
109
.usual_check:
109
.usual_check:
110
    cmp   dword [eax+0],0
110
    cmp   dword [eax+0],0
111
    mov   ecx,512
111
    mov   ecx,512
112
    jnz   .small_size
112
    jnz   .small_size
113
    mov   ecx,[eax+8]
113
    mov   ecx,[eax+8]
114
    shl   ecx,9
114
    shl   ecx,9
115
.small_size:
115
.small_size:
116
    mov   ebx,[eax+12]
116
    mov   ebx,[eax+12]
117
    add   ebx,std_application_base_address
117
    add   ebx,std_application_base_address
118
    call  check_region
118
    call  check_region
119
    test  eax,eax
119
    test  eax,eax
120
    jz    .error_output
120
    jz    .error_output
121
  area_in_app_mem:
121
  area_in_app_mem:
122
    mov   eax,edx
122
    mov   eax,edx
123
  no_checks_for_kernel:
123
  no_checks_for_kernel:
124
 
124
 
125
  fs_read:
125
  fs_read:
126
 
126
 
127
    mov   ebx,[eax+20]          ; program wants root directory ?
127
    mov   ebx,[eax+20]          ; program wants root directory ?
128
    test  bl,bl
128
    test  bl,bl
129
    je    fs_getroot
129
    je    fs_getroot
130
    test  bh,bh
130
    test  bh,bh
131
    jne   fs_noroot
131
    jne   fs_noroot
132
  fs_getroot:
132
  fs_getroot:
133
; \begin{diamond}[18.03.2006]
133
; \begin{diamond}[18.03.2006]
134
; root - only read is allowed
134
; root - only read is allowed
135
; other operations return "access denied", eax=10
135
; other operations return "access denied", eax=10
136
; (execute operation returns eax=-10)
136
; (execute operation returns eax=-10)
137
    cmp    dword [eax], 0
137
    cmp    dword [eax], 0
138
    jz    .read_root
138
    jz    .read_root
139
    mov    dword [esp+36], 10
139
    mov    dword [esp+36], 10
140
    ret
140
    ret
141
.read_root:
141
.read_root:
142
; \end{diamond}[18.03.2006]
142
; \end{diamond}[18.03.2006]
143
    mov   esi,dir0
143
    mov   esi,dir0
144
    mov   edi,[eax+12]
144
    mov   edi,[eax+12]
145
    add   edi,std_application_base_address
145
    add   edi,std_application_base_address
146
    mov   ecx,11
146
    mov   ecx,11
147
    push  ecx
147
    push  ecx
148
;    cld    ; already is
148
;    cld    ; already is
149
    rep   movsb
149
    rep   movsb
150
    mov   al,0x10
150
    mov   al,0x10
151
    stosb
151
    stosb
152
    add   edi,32-11-1
152
    add   edi,32-11-1
153
    pop   ecx
153
    pop   ecx
154
    rep   movsb
154
    rep   movsb
155
    stosb
155
    stosb
156
    and   dword [esp+36],0      ; ok read
156
    and   dword [esp+36],0      ; ok read
157
    mov   dword [esp+24],32*2   ; size of root
157
    mov   dword [esp+24],32*2   ; size of root
158
    ret
158
    ret
159
 
159
 
160
  fs_info:                      ;start of code - Mihasik
160
  fs_info:                      ;start of code - Mihasik
161
    push  eax
161
    push  eax
162
    cmp   [eax+21],byte 'h'
162
    cmp   [eax+21],byte 'h'
163
    je    fs_info_h
163
    je    fs_info_h
164
    cmp   [eax+21],byte 'H'
164
    cmp   [eax+21],byte 'H'
165
    je    fs_info_h
165
    je    fs_info_h
166
    cmp   [eax+21],byte 'r'
166
    cmp   [eax+21],byte 'r'
167
    je    fs_info_r
167
    je    fs_info_r
168
    cmp   [eax+21],byte 'R'
168
    cmp   [eax+21],byte 'R'
169
    je    fs_info_r
169
    je    fs_info_r
170
    mov   eax,3                 ;if unknown disk
170
    mov   eax,3                 ;if unknown disk
171
    xor   ebx,ebx
171
    xor   ebx,ebx
172
    xor   ecx,ecx
172
    xor   ecx,ecx
173
    xor   edx,edx
173
    xor   edx,edx
174
    jmp   fs_info1
174
    jmp   fs_info1
175
  fs_info_r:
175
  fs_info_r:
176
    call  ramdisk_free_space    ;if ramdisk
176
    call  ramdisk_free_space    ;if ramdisk
177
    mov   ecx,edi               ;free space in ecx
177
    mov   ecx,edi               ;free space in ecx
178
    shr   ecx,9                 ;free clusters
178
    shr   ecx,9                 ;free clusters
179
    mov   ebx,2847              ;total clusters
179
    mov   ebx,2847              ;total clusters
180
    mov   edx,512               ;cluster size
180
    mov   edx,512               ;cluster size
181
    xor   eax,eax               ;always 0
181
    xor   eax,eax               ;always 0
182
    jmp   fs_info1
182
    jmp   fs_info1
183
  fs_info_h:                    ;if harddisk
183
  fs_info_h:                    ;if harddisk
184
    call  get_hd_info
184
    call  get_hd_info
185
  fs_info1:
185
  fs_info1:
186
    pop   edi
186
    pop   edi
187
    mov   [esp+36],eax
187
    mov   [esp+36],eax
188
    mov   [esp+24],ebx           ; total clusters on disk
188
    mov   [esp+24],ebx           ; total clusters on disk
189
    mov   [esp+32],ecx           ; free clusters on disk
189
    mov   [esp+32],ecx           ; free clusters on disk
190
    mov   [edi],edx              ; cluster size in bytes
190
    mov   [edi],edx              ; cluster size in bytes
191
    ret                          ;end of code - Mihasik
191
    ret                          ;end of code - Mihasik
192
 
192
 
193
  fs_noroot:
193
  fs_noroot:
194
 
194
 
195
    push  dword [eax+0]         ; read/write/delete/.../makedir/rename/lba/run
195
    push  dword [eax+0]         ; read/write/delete/.../makedir/rename/lba/run
196
    push  dword [eax+4]         ; 512 block number to read
196
    push  dword [eax+4]         ; 512 block number to read
197
    push  dword [eax+8]         ; bytes to write/append or 512 blocks to read
197
    push  dword [eax+8]         ; bytes to write/append or 512 blocks to read
198
    mov   ebx,[eax+12]
198
    mov   ebx,[eax+12]
199
    add   ebx,std_application_base_address
199
    add   ebx,std_application_base_address
200
    push  ebx                   ; abs start of return/save area
200
    push  ebx                   ; abs start of return/save area
201
 
201
 
202
    lea   esi,[eax+20]          ; abs start of dir + filename
202
    lea   esi,[eax+20]          ; abs start of dir + filename
203
    mov   edi,[eax+16]
203
    mov   edi,[eax+16]
204
    add   edi,std_application_base_address    ; abs start of work area
204
    add   edi,std_application_base_address    ; abs start of work area
205
 
205
 
206
    call  expand_pathz
206
    call  expand_pathz
207
 
207
 
208
    push  edi                   ; dir start
208
    push  edi                   ; dir start
209
    push  ebx                   ; name of file start
209
    push  ebx                   ; name of file start
210
 
210
 
211
    mov   eax,[edi+1]
211
    mov   eax,[edi+1]
212
    cmp   eax,'RD  '
212
    cmp   eax,'RD  '
213
    je    fs_yesramdisk
213
    je    fs_yesramdisk
214
    cmp   eax,'RAMD'
214
    cmp   eax,'RAMD'
215
    jne   fs_noramdisk
215
    jne   fs_noramdisk
216
 
216
 
217
  fs_yesramdisk:
217
  fs_yesramdisk:
218
 
218
 
219
    cmp   byte [edi+1+11],0
219
    cmp   byte [edi+1+11],0
220
    je    fs_give_dir1
220
    je    fs_give_dir1
221
 
221
 
222
    mov   eax,[edi+1+12]
222
    mov   eax,[edi+1+12]
223
    cmp   eax,'1   '
223
    cmp   eax,'1   '
224
    je    fs_yesramdisk_first
224
    je    fs_yesramdisk_first
225
    cmp   eax,'FIRS'
225
    cmp   eax,'FIRS'
226
    jne   fs_noramdisk
226
    jne   fs_noramdisk
227
 
227
 
228
  fs_yesramdisk_first:
228
  fs_yesramdisk_first:
229
 
229
 
230
    cmp   dword [esp+20],8      ; LBA read ramdisk
230
    cmp   dword [esp+20],8      ; LBA read ramdisk
231
    jne   fs_no_LBA_read_ramdisk
231
    jne   fs_no_LBA_read_ramdisk
232
 
232
 
233
    mov   eax,[esp+16]          ; LBA block to read
233
    mov   eax,[esp+16]          ; LBA block to read
234
    mov   ecx,[esp+8]           ; abs pointer to return area
234
    mov   ecx,[esp+8]           ; abs pointer to return area
235
 
235
 
236
    call  LBA_read_ramdisk
236
    call  LBA_read_ramdisk
237
    jmp   file_system_return
237
    jmp   file_system_return
238
 
238
 
239
 
239
 
240
  fs_no_LBA_read_ramdisk:
240
  fs_no_LBA_read_ramdisk:
241
 
241
 
242
    cmp   dword [esp+20],0      ; READ
242
    cmp   dword [esp+20],0      ; READ
243
    jne   fs_noramdisk_read
243
    jne   fs_noramdisk_read
244
 
244
 
245
    mov   eax,[esp+4]           ; fname
245
    mov   eax,[esp+4]           ; fname
246
    add   eax,2*12+1
246
    add   eax,2*12+1
247
    mov   ebx,[esp+16]          ; block start
247
    mov   ebx,[esp+16]          ; block start
248
    inc   ebx
248
    inc   ebx
249
    mov   ecx,[esp+12]          ; block count
249
    mov   ecx,[esp+12]          ; block count
250
    mov   edx,[esp+8]           ; return
250
    mov   edx,[esp+8]           ; return
251
    mov   esi,[esp+0]
251
    mov   esi,[esp+0]
252
    sub   esi,eax
252
    sub   esi,eax
253
    add   esi,12+1              ; file name length
253
    add   esi,12+1              ; file name length
254
    call  fileread
254
    call  fileread
255
 
255
 
256
    jmp   file_system_return
256
    jmp   file_system_return
257
 
257
 
258
 
258
 
259
  fs_noramdisk_read:
259
  fs_noramdisk_read:
260
 
260
 
261
    cmp   dword [esp+20],1      ; WRITE
261
    cmp   dword [esp+20],1      ; WRITE
262
    jne   fs_noramdisk_write
262
    jne   fs_noramdisk_write
263
 
263
 
264
    mov   eax,[esp+4]           ; fname
264
    mov   eax,[esp+4]           ; fname
265
    add   eax,2*12+1
265
    add   eax,2*12+1
266
    mov   ebx,[esp+8]           ; buffer
266
    mov   ebx,[esp+8]           ; buffer
267
    mov   ecx,[esp+12]          ; count to write
267
    mov   ecx,[esp+12]          ; count to write
268
    mov   edx,0                 ; create new
268
    mov   edx,0                 ; create new
269
    call  filesave
269
    call  filesave
270
 
270
 
271
    ; eax=0 ok - eax=1 not enough free space
271
    ; eax=0 ok - eax=1 not enough free space
272
 
272
 
273
    jmp   file_system_return
273
    jmp   file_system_return
274
 
274
 
275
  fs_noramdisk_write:
275
  fs_noramdisk_write:
276
  fs_noramdisk:
276
  fs_noramdisk:
277
 
277
 
278
  ;********************************************************************
278
  ;********************************************************************
279
    mov   eax,[edi+1]
279
    mov   eax,[edi+1]
280
    cmp   eax,'FD  '
280
    cmp   eax,'FD  '
281
    je    fs_yesflpdisk
281
    je    fs_yesflpdisk
282
    cmp   eax,'FLOP'
282
    cmp   eax,'FLOP'
283
    jne   fs_noflpdisk
283
    jne   fs_noflpdisk
284
 
284
 
285
  fs_yesflpdisk:
285
  fs_yesflpdisk:
286
    call   reserve_flp
286
    call   reserve_flp
287
 
287
 
288
    cmp   byte [edi+1+11],0
288
    cmp   byte [edi+1+11],0
289
    je    fs_give_dir1
289
    je    fs_give_dir1
290
 
290
 
291
    mov   eax,[edi+1+12]
291
    mov   eax,[edi+1+12]
292
    cmp   eax,'1   '
292
    cmp   eax,'1   '
293
    je    fs_yesflpdisk_first
293
    je    fs_yesflpdisk_first
294
    cmp   eax,'FIRS'
294
    cmp   eax,'FIRS'
295
    je    fs_yesflpdisk_first
295
    je    fs_yesflpdisk_first
296
    cmp   eax,'2   '
296
    cmp   eax,'2   '
297
    je    fs_yesflpdisk_second
297
    je    fs_yesflpdisk_second
298
    cmp   eax,'SECO'
298
    cmp   eax,'SECO'
299
    jne   fs_noflpdisk
299
    jne   fs_noflpdisk
300
    jmp   fs_yesflpdisk_second
300
    jmp   fs_yesflpdisk_second
301
 
301
 
302
  fs_yesflpdisk_first:
302
  fs_yesflpdisk_first:
303
    mov   [flp_number],1
303
    mov   [flp_number],1
304
    jmp   fs_yesflpdisk_start
304
    jmp   fs_yesflpdisk_start
305
  fs_yesflpdisk_second:
305
  fs_yesflpdisk_second:
306
    mov   [flp_number],2
306
    mov   [flp_number],2
307
  fs_yesflpdisk_start:
307
  fs_yesflpdisk_start:
308
    cmp   dword [esp+20],0      ; READ
308
    cmp   dword [esp+20],0      ; READ
309
    jne   fs_noflpdisk_read
309
    jne   fs_noflpdisk_read
310
 
310
 
311
    mov   eax,[esp+4]           ; fname
311
    mov   eax,[esp+4]           ; fname
312
    add   eax,2*12+1
312
    add   eax,2*12+1
313
    mov   ebx,[esp+16]          ; block start
313
    mov   ebx,[esp+16]          ; block start
314
    inc   ebx
314
    inc   ebx
315
    mov   ecx,[esp+12]          ; block count
315
    mov   ecx,[esp+12]          ; block count
316
    mov   edx,[esp+8]           ; return
316
    mov   edx,[esp+8]           ; return
317
    mov   esi,[esp+0]
317
    mov   esi,[esp+0]
318
    sub   esi,eax
318
    sub   esi,eax
319
    add   esi,12+1              ; file name length
319
    add   esi,12+1              ; file name length
320
    call  floppy_fileread
320
    call  floppy_fileread
321
 
321
 
322
    jmp   file_system_return
322
    jmp   file_system_return
323
 
323
 
324
 
324
 
325
  fs_noflpdisk_read:
325
  fs_noflpdisk_read:
326
 
326
 
327
    cmp   dword [esp+20],1      ; WRITE
327
    cmp   dword [esp+20],1      ; WRITE
328
    jne   fs_noflpdisk_write
328
    jne   fs_noflpdisk_write
329
 
329
 
330
    mov   eax,[esp+4]           ; fname
330
    mov   eax,[esp+4]           ; fname
331
    add   eax,2*12+1
331
    add   eax,2*12+1
332
    mov   ebx,[esp+8]           ; buffer
332
    mov   ebx,[esp+8]           ; buffer
333
    mov   ecx,[esp+12]          ; count to write
333
    mov   ecx,[esp+12]          ; count to write
334
    mov   edx,0                 ; create new
334
    mov   edx,0                 ; create new
335
    call  floppy_filesave
335
    call  floppy_filesave
336
 
336
 
337
    ; eax=0 ok - eax=1 not enough free space
337
    ; eax=0 ok - eax=1 not enough free space
338
 
338
 
339
    jmp   file_system_return
339
    jmp   file_system_return
340
 
340
 
341
  fs_noflpdisk_write:
341
  fs_noflpdisk_write:
342
 
342
 
343
  fs_noflpdisk:
343
  fs_noflpdisk:
344
  ;*****************************************************************
344
  ;*****************************************************************
345
 
345
 
346
    mov   eax,[edi+1]
346
    mov   eax,[edi+1]
347
    cmp   eax,'HD0 '
347
    cmp   eax,'HD0 '
348
    je    fs_yesharddisk_IDE0
348
    je    fs_yesharddisk_IDE0
349
    cmp   eax,'HD1 '
349
    cmp   eax,'HD1 '
350
    je    fs_yesharddisk_IDE1
350
    je    fs_yesharddisk_IDE1
351
    cmp   eax,'HD2 '
351
    cmp   eax,'HD2 '
352
    je    fs_yesharddisk_IDE2
352
    je    fs_yesharddisk_IDE2
353
    cmp   eax,'HD3 '
353
    cmp   eax,'HD3 '
354
    je    fs_yesharddisk_IDE3
354
    je    fs_yesharddisk_IDE3
355
    jmp   old_path_harddisk
355
    jmp   old_path_harddisk
356
fs_yesharddisk_IDE0:
356
fs_yesharddisk_IDE0:
357
     call  reserve_hd1
357
     call  reserve_hd1
358
     mov  [hdbase],0x1f0
358
     mov  [hdbase],0x1f0
359
     mov  [hdid],0x0
359
     mov  [hdid],0x0
360
     mov  [hdpos],1
360
     mov  [hdpos],1
361
     jmp  fs_yesharddisk_partition
361
     jmp  fs_yesharddisk_partition
362
fs_yesharddisk_IDE1:
362
fs_yesharddisk_IDE1:
363
     call  reserve_hd1
363
     call  reserve_hd1
364
     mov  [hdbase],0x1f0
364
     mov  [hdbase],0x1f0
365
     mov  [hdid],0x10
365
     mov  [hdid],0x10
366
     mov  [hdpos],2
366
     mov  [hdpos],2
367
     jmp  fs_yesharddisk_partition
367
     jmp  fs_yesharddisk_partition
368
fs_yesharddisk_IDE2:
368
fs_yesharddisk_IDE2:
369
     call  reserve_hd1
369
     call  reserve_hd1
370
     mov  [hdbase],0x170
370
     mov  [hdbase],0x170
371
     mov  [hdid],0x0
371
     mov  [hdid],0x0
372
     mov  [hdpos],3
372
     mov  [hdpos],3
373
     jmp  fs_yesharddisk_partition
373
     jmp  fs_yesharddisk_partition
374
fs_yesharddisk_IDE3:
374
fs_yesharddisk_IDE3:
375
     call  reserve_hd1
375
     call  reserve_hd1
376
     mov  [hdbase],0x170
376
     mov  [hdbase],0x170
377
     mov  [hdid],0x10
377
     mov  [hdid],0x10
378
     mov  [hdpos],4
378
     mov  [hdpos],4
379
fs_yesharddisk_partition:
379
fs_yesharddisk_partition:
380
        call    reserve_hd_channel
380
        call    reserve_hd_channel
381
;    call  choice_necessity_partition
381
;    call  choice_necessity_partition
382
;    jmp   fs_yesharddisk_all
382
;    jmp   fs_yesharddisk_all
383
    jmp   fs_for_new_semantic
383
    jmp   fs_for_new_semantic
384
 
384
 
385
choice_necessity_partition:
385
choice_necessity_partition:
386
    mov   eax,[edi+1+12]
386
    mov   eax,[edi+1+12]
387
    call  StringToNumber
387
    call  StringToNumber
388
        mov   [fat32part],eax
388
        mov   [fat32part],eax
389
choice_necessity_partition_1:
389
choice_necessity_partition_1:
390
    mov   ecx,[hdpos]
390
    mov   ecx,[hdpos]
391
    xor   eax,eax
391
    xor   eax,eax
392
    mov   [0xfe10], eax    ; entries in hd cache
392
    mov   [0xfe10], eax    ; entries in hd cache
393
    mov   edx,0x40002
393
    mov   edx,0x40002
394
 search_partition_array:
394
 search_partition_array:
395
    mov   bl,[edx]
395
    mov   bl,[edx]
396
    movzx ebx,bl
396
    movzx ebx,bl
397
    add   eax,ebx
397
    add   eax,ebx
398
    inc   edx
398
    inc   edx
399
    loop  search_partition_array
399
    loop  search_partition_array
400
    sub   eax,ebx
400
    sub   eax,ebx
401
    add   eax,[fat32part]
401
    add   eax,[fat32part]
402
    dec   eax
402
    dec   eax
403
    xor   edx,edx
403
    xor   edx,edx
404
    imul  eax,100
404
    imul  eax,100
405
    add   eax,0x4000a
405
    add   eax,0x4000a
406
    mov   [transfer_adress],eax
406
    mov   [transfer_adress],eax
407
    call  partition_data_transfer_1
407
    call  partition_data_transfer_1
408
    ret
408
    ret
409
 
409
 
410
 old_path_harddisk:
410
 old_path_harddisk:
411
    mov   eax,[edi+1]
411
    mov   eax,[edi+1]
412
    cmp   eax,'HD  '
412
    cmp   eax,'HD  '
413
    je    fs_yesharddisk
413
    je    fs_yesharddisk
414
    cmp   eax,'HARD'
414
    cmp   eax,'HARD'
415
    jne   fs_noharddisk
415
    jne   fs_noharddisk
416
 
416
 
417
  fs_yesharddisk:
417
  fs_yesharddisk:
418
    cmp   dword [esp+20],8      ; LBA read
418
    cmp   dword [esp+20],8      ; LBA read
419
    jne   fs_no_LBA_read
419
    jne   fs_no_LBA_read
420
    mov   eax,[esp+16]          ; LBA block to read
420
    mov   eax,[esp+16]          ; LBA block to read
421
    lea   ebx,[edi+1+12]        ; pointer to FIRST/SECOND/THIRD/FOURTH
421
    lea   ebx,[edi+1+12]        ; pointer to FIRST/SECOND/THIRD/FOURTH
422
    mov   ecx,[esp+8]           ; abs pointer to return area
422
    mov   ecx,[esp+8]           ; abs pointer to return area
423
    call  LBA_read
423
    call  LBA_read
424
    jmp   file_system_return
424
    jmp   file_system_return
425
 
425
 
426
  fs_no_LBA_read:
426
  fs_no_LBA_read:
427
 
427
 
428
    cmp   byte [edi+1+11],0     ; directory read
428
    cmp   byte [edi+1+11],0     ; directory read
429
    je    fs_give_dir1
429
    je    fs_give_dir1
430
    call  reserve_hd1
430
    call  reserve_hd1
431
 fs_for_new_semantic:
431
 fs_for_new_semantic:
432
    call  choice_necessity_partition
432
    call  choice_necessity_partition
433
 
433
 
434
  fs_yesharddisk_all:
434
  fs_yesharddisk_all:
435
    mov   eax,1
435
    mov   eax,1
436
    mov    ebx, [esp+24+24]
436
    mov    ebx, [esp+24+24]
437
    cmp   [hdpos],0             ; is hd base set?
437
    cmp   [hdpos],0             ; is hd base set?
438
    jz    hd_err_return
438
    jz    hd_err_return
439
    cmp   [fat32part],0         ; is partition set?
439
    cmp   [fat32part],0         ; is partition set?
440
    jnz   @f
440
    jnz   @f
441
hd_err_return:
441
hd_err_return:
442
    call  free_hd_channel
442
    call  free_hd_channel
443
    and   [hd1_status], 0
443
    and   [hd1_status], 0
444
    jmp   file_system_return
444
    jmp   file_system_return
445
@@:
445
@@:
446
 
446
 
447
    cmp   dword [esp+20],0      ; READ
447
    cmp   dword [esp+20],0      ; READ
448
    jne   fs_noharddisk_read
448
    jne   fs_noharddisk_read
449
 
449
 
450
    mov   eax,[esp+0]           ; /fname
450
    mov   eax,[esp+0]           ; /fname
451
    lea   edi,[eax+12]
451
    lea   edi,[eax+12]
452
    mov   byte [eax],0          ; path to asciiz
452
    mov   byte [eax],0          ; path to asciiz
453
    inc   eax                   ; filename start
453
    inc   eax                   ; filename start
454
 
454
 
455
    mov   ebx,[esp+12]          ; count to read
455
    mov   ebx,[esp+12]          ; count to read
456
    mov   ecx,[esp+8]           ; buffer
456
    mov   ecx,[esp+8]           ; buffer
457
    mov   edx,[esp+4]
457
    mov   edx,[esp+4]
458
    add   edx,12*2              ; dir start
458
    add   edx,12*2              ; dir start
459
    sub   edi,edx               ; path length
459
    sub   edi,edx               ; path length
460
    mov   esi,[esp+16]          ; blocks to read
460
    mov   esi,[esp+16]          ; blocks to read
461
 
461
 
462
    call  file_read
462
    call  file_read
463
 
463
 
464
    mov   edi,[esp+0]
464
    mov   edi,[esp+0]
465
    mov   byte [edi],'/'
465
    mov   byte [edi],'/'
466
 
466
 
467
    call  free_hd_channel
467
    call  free_hd_channel
468
    and   [hd1_status], 0
468
    and   [hd1_status], 0
469
    jmp   file_system_return
469
    jmp   file_system_return
470
 
470
 
471
  fs_noharddisk_read:
471
  fs_noharddisk_read:
472
 
472
 
473
 
473
 
474
    cmp   dword [esp+20],1      ; WRITE
474
    cmp   dword [esp+20],1      ; WRITE
475
    jne   fs_noharddisk_write
475
    jne   fs_noharddisk_write
476
 
476
 
477
    mov   eax,[esp+0]           ; /fname
477
    mov   eax,[esp+0]           ; /fname
478
    mov   byte [eax],0          ; path to asciiz
478
    mov   byte [eax],0          ; path to asciiz
479
    inc   eax                   ; filename start
479
    inc   eax                   ; filename start
480
 
480
 
481
    mov   ebx,[esp+12]          ; count to write
481
    mov   ebx,[esp+12]          ; count to write
482
    mov   ecx,[esp+8]           ; buffer
482
    mov   ecx,[esp+8]           ; buffer
483
    mov   edx,[esp+4]
483
    mov   edx,[esp+4]
484
    add   edx,12*2              ; path start
484
    add   edx,12*2              ; path start
485
 
485
 
486
    call  file_write
486
    call  file_write
487
 
487
 
488
    mov   edi,[esp+0]
488
    mov   edi,[esp+0]
489
    mov   byte [edi],'/'
489
    mov   byte [edi],'/'
490
 
490
 
491
    ; eax=0 ok - eax=1 not enough free space
491
    ; eax=0 ok - eax=1 not enough free space
492
 
492
 
493
    call  free_hd_channel
493
    call  free_hd_channel
494
    and   [hd1_status], 0
494
    and   [hd1_status], 0
495
    jmp   file_system_return
495
    jmp   file_system_return
496
 
496
 
497
 
497
 
498
  fs_noharddisk_write:
498
  fs_noharddisk_write:
499
 
499
 
500
 
500
 
501
    call  free_hd_channel
501
    call  free_hd_channel
502
    and   [hd1_status], 0
502
    and   [hd1_status], 0
503
 
503
 
504
  fs_noharddisk:
504
  fs_noharddisk:
505
; \begin{diamond}[18.03.2006]
505
; \begin{diamond}[18.03.2006]
506
    mov    eax, 5        ; file not found
506
    mov    eax, 5        ; file not found
507
; à ìîæåò áûòü, âîçâðàùàòü äðóãîé êîä îøèáêè?
507
; à ìîæåò áûòü, âîçâðàùàòü äðóãîé êîä îøèáêè?
508
    mov    ebx, [esp+24+24]    ; do not change ebx in application
508
    mov    ebx, [esp+24+24]    ; do not change ebx in application
509
; \end{diamond}[18.03.2006]
509
; \end{diamond}[18.03.2006]
510
 
510
 
511
  file_system_return:
511
  file_system_return:
512
 
512
 
513
    add   esp,24
513
    add   esp,24
514
 
514
 
515
    mov   [esp+36],eax
515
    mov   [esp+36],eax
516
    mov   [esp+24],ebx
516
    mov   [esp+24],ebx
517
    ret
517
    ret
518
 
518
 
519
 
519
 
520
  fs_give_dir1:
520
  fs_give_dir1:
521
 
521
 
522
; \begin{diamond}[18.03.2006]
522
; \begin{diamond}[18.03.2006]
523
; /RD,/FD,/HD - only read is allowed
523
; /RD,/FD,/HD - only read is allowed
524
; other operations return "access denied", eax=10
524
; other operations return "access denied", eax=10
525
; (execute operation returns eax=-10)
525
; (execute operation returns eax=-10)
526
    cmp    dword [esp+20], 0
526
    cmp    dword [esp+20], 0
527
    jz    .read
527
    jz    .read
528
    add    esp, 20
528
    add    esp, 20
529
    pop    ecx
529
    pop    ecx
530
    mov    dword [esp+36], 10
530
    mov    dword [esp+36], 10
531
    ret
531
    ret
532
.read:
532
.read:
533
; \end{diamond}[18.03.2006]
533
; \end{diamond}[18.03.2006]
534
    mov   al,0x10
534
    mov   al,0x10
535
    mov   ebx,1
535
    mov   ebx,1
536
    mov   edi,[esp+8]
536
    mov   edi,[esp+8]
537
    mov   esi,dir1
537
    mov   esi,dir1
538
  fs_d1_new:
538
  fs_d1_new:
539
    mov   ecx,11
539
    mov   ecx,11
540
;    cld
540
;    cld
541
    rep   movsb
541
    rep   movsb
542
    stosb
542
    stosb
543
    add   edi,32-11-1
543
    add   edi,32-11-1
544
    dec   ebx
544
    dec   ebx
545
    jne   fs_d1_new
545
    jne   fs_d1_new
546
 
546
 
547
    add   esp,24
547
    add   esp,24
548
 
548
 
549
    and   dword [esp+36],0      ; ok read
549
    and   dword [esp+36],0      ; ok read
550
    mov   dword [esp+24],32*1   ; dir/data size
550
    mov   dword [esp+24],32*1   ; dir/data size
551
    ret
551
    ret
552
 
552
 
553
 
553
 
554
 
554
 
555
LBA_read_ramdisk:
555
LBA_read_ramdisk:
556
 
556
 
557
    cmp   [lba_read_enabled],1
557
    cmp   [lba_read_enabled],1
558
    je    lbarrl1
558
    je    lbarrl1
559
 
559
 
560
    xor   ebx,ebx
560
    xor   ebx,ebx
561
    mov   eax,2
561
    mov   eax,2
562
    ret
562
    ret
563
 
563
 
564
  lbarrl1:
564
  lbarrl1:
565
 
565
 
566
    cmp   eax,18*2*80
566
    cmp   eax,18*2*80
567
    jb    lbarrl2
567
    jb    lbarrl2
568
    xor   ebx,ebx
568
    xor   ebx,ebx
569
    mov   eax,3
569
    mov   eax,3
570
    ret
570
    ret
571
 
571
 
572
  lbarrl2:
572
  lbarrl2:
573
 
573
 
574
    pushad
574
    pushad
575
 
575
 
576
    call  restorefatchain
576
    call  restorefatchain
577
 
577
 
578
    mov   edi,ecx
578
    mov   edi,ecx
579
    mov   esi,eax
579
    mov   esi,eax
580
 
580
 
581
    shl   esi,9
581
    shl   esi,9
582
    add   esi,0x100000
582
    add   esi,RAMDISK
583
    mov   ecx,512/4
583
    mov   ecx,512/4
584
;    cld
584
;    cld
585
    rep   movsd
585
    rep   movsd
586
 
586
 
587
    popad
587
    popad
588
 
588
 
589
    xor   ebx,ebx
589
    xor   ebx,ebx
590
    xor   eax,eax
590
    xor   eax,eax
591
    ret
591
    ret
592
 
592
 
593
LBA_read:
593
LBA_read:
594
 
594
 
595
; IN:
595
; IN:
596
;
596
;
597
; eax = LBA block to read
597
; eax = LBA block to read
598
; ebx = pointer to FIRST/SECOND/THIRD/FOURTH
598
; ebx = pointer to FIRST/SECOND/THIRD/FOURTH
599
; ecx = abs pointer to return area
599
; ecx = abs pointer to return area
600
 
600
 
601
    cmp   [lba_read_enabled],1
601
    cmp   [lba_read_enabled],1
602
    je    lbarl1
602
    je    lbarl1
603
    mov   eax,2
603
    mov   eax,2
604
    ret
604
    ret
605
 
605
 
606
  lbarl1:
606
  lbarl1:
607
 
607
 
608
    call  reserve_hd1
608
    call  reserve_hd1
609
 
609
 
610
    push  eax
610
    push  eax
611
    push  ecx
611
    push  ecx
612
 
612
 
613
    mov   edi,hd_address_table
613
    mov   edi,hd_address_table
614
    mov   esi,dir1
614
    mov   esi,dir1
615
    mov   eax,[ebx]
615
    mov   eax,[ebx]
616
    mov   edx,'1   '
616
    mov   edx,'1   '
617
    mov   ecx,4
617
    mov   ecx,4
618
  blar0:
618
  blar0:
619
    cmp   eax,[esi]
619
    cmp   eax,[esi]
620
    je    blar2
620
    je    blar2
621
    cmp   eax,edx
621
    cmp   eax,edx
622
    je    blar2
622
    je    blar2
623
    inc   edx
623
    inc   edx
624
    add   edi,8
624
    add   edi,8
625
    add   esi,11
625
    add   esi,11
626
    dec   ecx
626
    dec   ecx
627
    jnz   blar0
627
    jnz   blar0
628
 
628
 
629
    mov   eax,1
629
    mov   eax,1
630
    mov   ebx,1
630
    mov   ebx,1
631
    jmp   LBA_read_ret
631
    jmp   LBA_read_ret
632
 
632
 
633
  blar2:
633
  blar2:
634
    mov   eax,[edi+0]
634
    mov   eax,[edi+0]
635
    mov   ebx,[edi+4]
635
    mov   ebx,[edi+4]
636
 
636
 
637
    mov  [hdbase],eax
637
    mov  [hdbase],eax
638
    mov  [hdid],ebx
638
    mov  [hdid],ebx
639
 
639
 
640
    call  wait_for_hd_idle
640
    call  wait_for_hd_idle
641
    cmp   [hd_error],0
641
    cmp   [hd_error],0
642
    jne   hd_lba_error
642
    jne   hd_lba_error
643
 
643
 
644
    ; eax = hd port
644
    ; eax = hd port
645
    ; ebx = set for primary (0x00) or slave (0x10)
645
    ; ebx = set for primary (0x00) or slave (0x10)
646
 
646
 
647
    cli
647
    cli
648
 
648
 
649
    mov   edx,eax
649
    mov   edx,eax
650
    inc   edx
650
    inc   edx
651
    xor   eax,eax
651
    xor   eax,eax
652
    out   dx,al
652
    out   dx,al
653
    inc   edx
653
    inc   edx
654
    inc   eax
654
    inc   eax
655
    out   dx,al
655
    out   dx,al
656
    inc   edx
656
    inc   edx
657
    mov   eax,[esp+4]
657
    mov   eax,[esp+4]
658
    out   dx,al
658
    out   dx,al
659
    shr   eax,8
659
    shr   eax,8
660
    inc   edx
660
    inc   edx
661
    out   dx,al
661
    out   dx,al
662
    shr   eax,8
662
    shr   eax,8
663
    inc   edx
663
    inc   edx
664
    out   dx,al
664
    out   dx,al
665
    shr   eax,8
665
    shr   eax,8
666
    inc   edx
666
    inc   edx
667
    and   al,1+2+4+8
667
    and   al,1+2+4+8
668
    add   al,bl
668
    add   al,bl
669
    add   al,128+64+32
669
    add   al,128+64+32
670
    out   dx,al
670
    out   dx,al
671
 
671
 
672
    inc   edx
672
    inc   edx
673
    mov   al,20h
673
    mov   al,20h
674
    out   dx,al
674
    out   dx,al
675
 
675
 
676
    sti
676
    sti
677
 
677
 
678
    call  wait_for_sector_buffer
678
    call  wait_for_sector_buffer
679
    cmp   [hd_error],0
679
    cmp   [hd_error],0
680
    jne   hd_lba_error
680
    jne   hd_lba_error
681
 
681
 
682
    cli
682
    cli
683
 
683
 
684
    mov   edi,[esp+0]
684
    mov   edi,[esp+0]
685
    mov   ecx,256
685
    mov   ecx,256
686
    sub   edx,7
686
    sub   edx,7
687
    cld
687
    cld
688
    rep   insw
688
    rep   insw
689
 
689
 
690
    sti
690
    sti
691
 
691
 
692
    xor   eax,eax
692
    xor   eax,eax
693
    xor   ebx,ebx
693
    xor   ebx,ebx
694
 
694
 
695
  LBA_read_ret:
695
  LBA_read_ret:
696
    mov [hd_error],0
696
    mov [hd_error],0
697
    mov   [hd1_status],0
697
    mov   [hd1_status],0
698
    add   esp,2*4
698
    add   esp,2*4
699
 
699
 
700
    ret
700
    ret
701
 
701
 
702
 
702
 
703
expand_pathz:
703
expand_pathz:
704
; IN:
704
; IN:
705
;   esi = asciiz path & file
705
;   esi = asciiz path & file
706
;   edi = buffer for path & file name
706
;   edi = buffer for path & file name
707
; OUT:
707
; OUT:
708
;   edi = directory & file : / 11 + / 11 + / 11 - zero terminated
708
;   edi = directory & file : / 11 + / 11 + / 11 - zero terminated
709
;   ebx = /file name - zero terminated
709
;   ebx = /file name - zero terminated
710
;   esi = pointer after source
710
;   esi = pointer after source
711
 
711
 
712
    push  eax
712
    push  eax
713
    push  ecx
713
    push  ecx
714
    push  edi ;[esp+0]
714
    push  edi ;[esp+0]
715
 
715
 
716
  pathz_start:
716
  pathz_start:
717
    mov   byte [edi],'/'
717
    mov   byte [edi],'/'
718
    inc   edi
718
    inc   edi
719
    mov   al,32
719
    mov   al,32
720
    mov   ecx,11
720
    mov   ecx,11
721
    cld
721
    cld
722
    rep   stosb                 ; clear filename area
722
    rep   stosb                 ; clear filename area
723
    sub   edi,11
723
    sub   edi,11
724
    mov   ebx,edi               ; start of dir/file name
724
    mov   ebx,edi               ; start of dir/file name
725
 
725
 
726
  pathz_new_char:
726
  pathz_new_char:
727
    mov   al,[esi]
727
    mov   al,[esi]
728
    inc   esi
728
    inc   esi
729
    cmp   al,0
729
    cmp   al,0
730
    je    pathz_end
730
    je    pathz_end
731
 
731
 
732
    cmp   al,'/'
732
    cmp   al,'/'
733
    jne   pathz_not_path
733
    jne   pathz_not_path
734
    cmp   edi,ebx               ; skip first '/'
734
    cmp   edi,ebx               ; skip first '/'
735
    jz    pathz_new_char
735
    jz    pathz_new_char
736
    lea   edi,[ebx+11]          ; start of next directory
736
    lea   edi,[ebx+11]          ; start of next directory
737
    jmp   pathz_start
737
    jmp   pathz_start
738
 
738
 
739
  pathz_not_path:
739
  pathz_not_path:
740
    cmp   al,'.'
740
    cmp   al,'.'
741
    jne   pathz_not_ext
741
    jne   pathz_not_ext
742
    lea   edi,[ebx+8]           ; start of extension
742
    lea   edi,[ebx+8]           ; start of extension
743
    jmp   pathz_new_char
743
    jmp   pathz_new_char
744
 
744
 
745
  pathz_not_ext:
745
  pathz_not_ext:
746
    cmp   al,'a'
746
    cmp   al,'a'
747
    jb    pathz_not_low
747
    jb    pathz_not_low
748
    cmp   al,'z'
748
    cmp   al,'z'
749
    ja    pathz_not_low
749
    ja    pathz_not_low
750
    sub   al,0x20               ; char to uppercase
750
    sub   al,0x20               ; char to uppercase
751
 
751
 
752
  pathz_not_low:
752
  pathz_not_low:
753
    mov   [edi],al
753
    mov   [edi],al
754
    inc   edi
754
    inc   edi
755
    mov   eax,[esp+0]           ; start_of_dest_path
755
    mov   eax,[esp+0]           ; start_of_dest_path
756
    add   eax,512               ; keep maximum path under 512 bytes
756
    add   eax,512               ; keep maximum path under 512 bytes
757
    cmp   edi,eax
757
    cmp   edi,eax
758
    jb    pathz_new_char
758
    jb    pathz_new_char
759
 
759
 
760
  pathz_end:
760
  pathz_end:
761
    cmp   ebx,edi               ; if path end with '/'
761
    cmp   ebx,edi               ; if path end with '/'
762
    jnz   pathz_put_zero        ; go back 1 level
762
    jnz   pathz_put_zero        ; go back 1 level
763
    sub   ebx,12
763
    sub   ebx,12
764
 
764
 
765
  pathz_put_zero:
765
  pathz_put_zero:
766
    mov   byte [ebx+11],0
766
    mov   byte [ebx+11],0
767
    dec   ebx                   ; include '/' char into file name
767
    dec   ebx                   ; include '/' char into file name
768
    pop   edi
768
    pop   edi
769
    pop   ecx
769
    pop   ecx
770
    pop   eax
770
    pop   eax
771
    ret
771
    ret
772
 
772
 
773
;*******************************************
773
;*******************************************
774
;* string to number
774
;* string to number
775
;* input eax - 4 byte string
775
;* input eax - 4 byte string
776
;* output eax - number
776
;* output eax - number
777
;*******************************************
777
;*******************************************
778
StringToNumber:
778
StringToNumber:
779
;    ÏÅÐÅÂÎÄ ÑÒÐÎÊÎÂÎÃÎ ×ÈÑËÀ  ×ÈÑËÎÂÎÉ ÂÈÄ
779
;    ÏÅÐÅÂÎÄ ÑÒÐÎÊÎÂÎÃÎ ×ÈÑËÀ  ×ÈÑËÎÂÎÉ ÂÈÄ
780
;    Âõîä:
780
;    Âõîä:
781
;        EDI - àäðåñ ñòðîêè ñ ÷èñëîì. Êîíåö ÷èñëà îòìå÷åí êîäîì 0Dh
781
;        EDI - àäðåñ ñòðîêè ñ ÷èñëîì. Êîíåö ÷èñëà îòìå÷åí êîäîì 0Dh
782
;    Âûõîä:
782
;    Âûõîä:
783
;        CF - èíäèêàòîð îøèáîê:
783
;        CF - èíäèêàòîð îøèáîê:
784
;            0 - îøèáîê íåò;
784
;            0 - îøèáîê íåò;
785
;            1 - îøèáêà
785
;            1 - îøèáêà
786
;        Åñëè CF=0, òî AX - ÷èñëî.
786
;        Åñëè CF=0, òî AX - ÷èñëî.
787
 
787
 
788
    push    bx
788
    push    bx
789
    push    cx
789
    push    cx
790
    push    dx
790
    push    dx
791
    push    edi
791
    push    edi
792
    mov   [partition_string],eax
792
    mov   [partition_string],eax
793
    mov    edi,partition_string
793
    mov    edi,partition_string
794
    xor    cx,cx
794
    xor    cx,cx
795
i1:
795
i1:
796
    mov    al,[edi]
796
    mov    al,[edi]
797
    cmp    al,32  ;13
797
    cmp    al,32  ;13
798
    je    i_exit
798
    je    i_exit
799
;    cmp    al,'0'
799
;    cmp    al,'0'
800
;    jb    err
800
;    jb    err
801
;    cmp    al,'9'
801
;    cmp    al,'9'
802
;    ja    err
802
;    ja    err
803
    sub    al,48
803
    sub    al,48
804
    shl    cx,1
804
    shl    cx,1
805
    jc    err
805
    jc    err
806
    mov    bx,cx
806
    mov    bx,cx
807
    shl    cx,1
807
    shl    cx,1
808
    jc    err
808
    jc    err
809
    shl    cx,1
809
    shl    cx,1
810
    jc    err
810
    jc    err
811
    add    cx,bx
811
    add    cx,bx
812
    jc    err
812
    jc    err
813
    cbw
813
    cbw
814
    add    cx,ax
814
    add    cx,ax
815
    jc    err
815
    jc    err
816
i3:
816
i3:
817
    inc    edi
817
    inc    edi
818
    jmp    i1
818
    jmp    i1
819
i_exit:
819
i_exit:
820
    mov    ax,cx
820
    mov    ax,cx
821
    clc
821
    clc
822
i4:
822
i4:
823
    movzx  eax,ax
823
    movzx  eax,ax
824
    pop    edi
824
    pop    edi
825
    pop    dx
825
    pop    dx
826
    pop    cx
826
    pop    cx
827
    pop    bx
827
    pop    bx
828
    ret
828
    ret
829
 
829
 
830
err:
830
err:
831
    stc
831
    stc
832
    jmp    i4
832
    jmp    i4
833
 
833
 
834
partition_string: dd 0
834
partition_string: dd 0
835
                  db 32
835
                  db 32