Subversion Repositories Kolibri OS

Rev

Rev 78 | Rev 86 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 78 Rev 83
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                      ;;
2
;;                                                                      ;;
3
;; RAMDISK functions                                                    ;;
3
;; RAMDISK functions                                                    ;;
4
;; (C) 2004 Ville Turjanmaa, License: GPL                               ;;
4
;; (C) 2004 Ville Turjanmaa, License: GPL                               ;;
5
;; Addings by M.Lisovin                                                 ;;
5
;; Addings by M.Lisovin                                                 ;;
-
 
6
;; LFN support by diamond                                               ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 8...
7
 
8
 
Line 8... Line 9...
8
; calculate fat chain
9
; calculate fat chain
Line 377... Line 378...
377
        mov    edi,0x100000+512*18+512  ;Point at directory
378
        mov    edi,0x100000+512*18+512  ;Point at directory
378
        mov    edx,224 +1
379
        mov    edx,224 +1
379
        ; find an empty spot for filename in the root dir
380
        ; find an empty spot for filename in the root dir
380
     l20ds:
381
     l20ds:
381
        dec    edx
382
        dec    edx
382
        test   edx,edx
-
 
383
        jz     frnoreadds
383
        jz     frnoreadds
384
     l21ds:
384
     l21ds:
385
        cmp    [edi],byte 0xE5
385
        cmp    [edi],byte 0xE5
386
        jz     fifoundds
386
        jz     fifoundds
387
        cmp    [edi],byte 0x0
387
        cmp    [edi],byte 0x0
Line 1074... Line 1074...
1074
        mov     al, ERROR_END_OF_FILE
1074
        mov     al, ERROR_END_OF_FILE
1075
@@:
1075
@@:
1076
        pop     ecx edi esi
1076
        pop     ecx edi esi
1077
        ret
1077
        ret
Line -... Line 1078...
-
 
1078
 
-
 
1079
iglobal
-
 
1080
label fat_legal_chars byte
-
 
1081
; 0 = not allowed
-
 
1082
; 1 = allowed only in long names
-
 
1083
; 3 = allowed
-
 
1084
        times 32 db 0
-
 
1085
;                 ! " # $ % & ' ( ) * + , - . /
-
 
1086
        db      1,3,0,3,3,3,3,3,3,3,0,1,1,3,3,0
-
 
1087
;               0 1 2 3 4 5 6 7 8 9 : ; < = > ?
-
 
1088
        db      3,3,3,3,3,3,3,3,3,3,0,1,0,1,0,0
-
 
1089
;               @ A B C D E F G H I J K L M N O
-
 
1090
        db      3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
-
 
1091
;               P Q R S T U V W X Y Z [ \ ] ^ _
-
 
1092
        db      3,3,3,3,3,3,3,3,3,3,3,1,0,1,3,3
-
 
1093
;               ` a b c d e f g h i j k l m n o
-
 
1094
        db      3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
-
 
1095
;               p q r s t u v w x y z { | } ~
-
 
1096
        db      3,3,3,3,3,3,3,3,3,3,3,3,0,3,3,0
-
 
1097
endg
-
 
1098
 
-
 
1099
fat_name_is_legal:
-
 
1100
; in: esi->(long) name
-
 
1101
; out: CF set <=> legal
-
 
1102
; destroys eax
-
 
1103
        push    esi
-
 
1104
        xor     eax, eax
-
 
1105
@@:
-
 
1106
        lodsb
-
 
1107
        test    al, al
-
 
1108
        jz      .done
-
 
1109
        cmp     al, 80h
-
 
1110
        jae     .big
-
 
1111
        test    [fat_legal_chars+eax], 1
-
 
1112
        jnz     @b
-
 
1113
.err:
-
 
1114
        pop     esi
-
 
1115
        clc
-
 
1116
        ret
-
 
1117
.big:
-
 
1118
; 0x80-0xAF, 0xE0-0xEF
-
 
1119
        cmp     al, 0xB0
-
 
1120
        jb      @b
-
 
1121
        cmp     al, 0xE0
-
 
1122
        jb      .err
-
 
1123
        cmp     al, 0xF0
-
 
1124
        jb      @b
-
 
1125
        jmp     .err
-
 
1126
.done:
-
 
1127
        sub     esi, [esp]
-
 
1128
        cmp     esi, 257
-
 
1129
        pop     esi
-
 
1130
        ret
-
 
1131
 
-
 
1132
fat_next_short_name:
-
 
1133
; in: edi->8+3 name
-
 
1134
; out: name corrected
-
 
1135
;      CF=1 <=> error
-
 
1136
        pushad
-
 
1137
        mov     ecx, 8
-
 
1138
        mov     al, '~'
-
 
1139
        std
-
 
1140
        push    edi
-
 
1141
        add     edi, 7
-
 
1142
        repnz   scasb
-
 
1143
        pop     edi
-
 
1144
        cld
-
 
1145
        jz      .tilde
-
 
1146
; tilde is not found, insert "~1" at end
-
 
1147
        add     edi, 6
-
 
1148
        cmp     word [edi], '  '
-
 
1149
        jnz     .insert_tilde
-
 
1150
@@:     dec     edi
-
 
1151
        cmp     byte [edi], ' '
-
 
1152
        jz      @b
-
 
1153
        inc     edi
-
 
1154
.insert_tilde:
-
 
1155
        mov     word [edi], '~1'
-
 
1156
        popad
-
 
1157
;       clc     ; CF already cleared
-
 
1158
        ret
-
 
1159
.tilde:
-
 
1160
        push    edi
-
 
1161
        add     edi, 7
-
 
1162
        xor     ecx, ecx
-
 
1163
@@:
-
 
1164
; after tilde may be only digits and trailing spaces
-
 
1165
        cmp     byte [edi], '~'
-
 
1166
        jz      .break
-
 
1167
        cmp     byte [edi], ' '
-
 
1168
        jz      .space
-
 
1169
        cmp     byte [edi], '9'
-
 
1170
        jnz     .found
-
 
1171
        dec     edi
-
 
1172
        jmp     @b
-
 
1173
.space:
-
 
1174
        dec     edi
-
 
1175
        inc     ecx
-
 
1176
        jmp     @b
-
 
1177
.found:
-
 
1178
        inc     byte [edi]
-
 
1179
.succ:
-
 
1180
        pop     edi
-
 
1181
        popad
-
 
1182
        clc
-
 
1183
        ret
-
 
1184
.break:
-
 
1185
        jecxz   .noplace
-
 
1186
        inc     edi
-
 
1187
        mov     al, '1'
-
 
1188
@@:
-
 
1189
        xchg    al, [edi]
-
 
1190
        inc     edi
-
 
1191
        cmp     al, ' '
-
 
1192
        mov     al, '0'
-
 
1193
        jnz     @b
-
 
1194
        jmp     .succ
-
 
1195
.noplace:
-
 
1196
        dec     edi
-
 
1197
        cmp     edi, [esp]
-
 
1198
        jz      .err
-
 
1199
        add     dword [esp], 8
-
 
1200
        mov     word [edi], '~1'
-
 
1201
        inc     edi
-
 
1202
        inc     edi
-
 
1203
@@:
-
 
1204
        mov     byte [edi], '0'
-
 
1205
        inc     edi
-
 
1206
        cmp     edi, [esp]
-
 
1207
        jb      @b
-
 
1208
        pop     edi
-
 
1209
        popad
-
 
1210
        ;clc    ; automatically
-
 
1211
        ret
-
 
1212
.err:
-
 
1213
        pop     edi
-
 
1214
        popad
-
 
1215
        stc
-
 
1216
        ret
-
 
1217
 
-
 
1218
fat_gen_short_name:
-
 
1219
; in: esi->long name
-
 
1220
;     edi->buffer (8+3=11 chars)
-
 
1221
; out: buffer filled
-
 
1222
        pushad
-
 
1223
        mov     eax, '    '
-
 
1224
        push    edi
-
 
1225
        stosd
-
 
1226
        stosd
-
 
1227
        stosd
-
 
1228
        pop     edi
-
 
1229
        xor     eax, eax
-
 
1230
        push    8
-
 
1231
        pop     ebx
-
 
1232
        lea     ecx, [edi+8]
-
 
1233
.loop:
-
 
1234
        lodsb
-
 
1235
        test    al, al
-
 
1236
        jz      .done
-
 
1237
        call    char_toupper
-
 
1238
        cmp     al, ' '
-
 
1239
        jz      .space
-
 
1240
        cmp     al, 80h
-
 
1241
        ja      .big
-
 
1242
        test    [fat_legal_chars+eax], 2
-
 
1243
        jnz     .symbol
-
 
1244
.inv_symbol:
-
 
1245
        mov     al, '_'
-
 
1246
        or      bh, 1
-
 
1247
.symbol:
-
 
1248
        cmp     al, '.'
-
 
1249
        jz      .dot
-
 
1250
.normal_symbol:
-
 
1251
        dec     bl
-
 
1252
        jns     .store
-
 
1253
        mov     bl, 0
-
 
1254
.space:
-
 
1255
        or      bh, 1
-
 
1256
        jmp     .loop
-
 
1257
.store:
-
 
1258
        stosb
-
 
1259
        jmp     .loop
-
 
1260
.big:
-
 
1261
        cmp     al, 0xB0
-
 
1262
        jb      .normal_symbol
-
 
1263
        cmp     al, 0xE0
-
 
1264
        jb      .inv_symbol
-
 
1265
        cmp     al, 0xF0
-
 
1266
        jb      .normal_symbol
-
 
1267
        jmp     .inv_symbol
-
 
1268
.dot:
-
 
1269
        test    bh, 2
-
 
1270
        jz      .firstdot
-
 
1271
        pop     ebx
-
 
1272
        add     ebx, edi
-
 
1273
        sub     ebx, ecx
-
 
1274
        push    ebx
-
 
1275
        cmp     edi, ecx
-
 
1276
        jbe     .skip
-
 
1277
@@:
-
 
1278
        dec     edi
-
 
1279
        mov     al, ' '
-
 
1280
        xchg    al, [edi]
-
 
1281
        dec     ebx
-
 
1282
        mov     [ebx], al
-
 
1283
        cmp     edi, ecx
-
 
1284
        ja      @b
-
 
1285
.skip:
-
 
1286
        mov     bh, 3
-
 
1287
        jmp     @f
-
 
1288
.firstdot:
-
 
1289
        cmp     bl, 8
-
 
1290
        jz      .space
-
 
1291
        push    edi
-
 
1292
        or      bh, 2
-
 
1293
@@:
-
 
1294
        mov     edi, ecx
-
 
1295
        mov     bl, 3
-
 
1296
        jmp     .loop
-
 
1297
.done:
-
 
1298
        test    bh, 2
-
 
1299
        jz      @f
-
 
1300
        pop     edi
-
 
1301
@@:
-
 
1302
        lea     edi, [ecx-8]
-
 
1303
        test    bh, 1
-
 
1304
        jz      @f
-
 
1305
        call    fat_next_short_name
-
 
1306
@@:
-
 
1307
        popad
-
 
1308
        ret
-
 
1309
 
-
 
1310
;----------------------------------------------------------------
-
 
1311
;
-
 
1312
;  fs_RamdiskRewrite - LFN variant for writing sys floppy
-
 
1313
;
-
 
1314
;  esi  points to filename
-
 
1315
;  ebx  ignored (reserved)
-
 
1316
;  ecx  number of bytes to write, 0+
-
 
1317
;  edx  mem location to data
-
 
1318
;
-
 
1319
;  ret ebx = number of written bytes
-
 
1320
;      eax = 0 ok read or other = errormsg
-
 
1321
;
-
 
1322
;--------------------------------------------------------------
-
 
1323
@@:
-
 
1324
        mov     eax, ERROR_ACCESS_DENIED
-
 
1325
        xor     ebx, ebx
-
 
1326
        ret
-
 
1327
 
-
 
1328
fs_RamdiskRewrite:
-
 
1329
        cmp     byte [esi], 0
-
 
1330
        jz      @b
-
 
1331
; ramdisk doesn't support folders
-
 
1332
        push    esi
-
 
1333
@@:
-
 
1334
        lodsb
-
 
1335
        test    al, al
-
 
1336
        jz      @f
-
 
1337
        cmp     al, '/'
-
 
1338
        jnz     @b
-
 
1339
        pop     esi
-
 
1340
.err5:
-
 
1341
        mov     eax, 5  ; file not found
-
 
1342
        xor     ebx, ebx
-
 
1343
        ret
-
 
1344
@@:
-
 
1345
        pop     esi
-
 
1346
; check existence
-
 
1347
        push    edi
-
 
1348
        call    rd_find_lfn
-
 
1349
        jc      .notfound
-
 
1350
; found, delete FAT chain
-
 
1351
        push    edi
-
 
1352
        xor     eax, eax
-
 
1353
        mov     dword [edi+28], eax     ; zero size
-
 
1354
        xchg    ax, word [edi+26]       ; start cluster
-
 
1355
        test    eax, eax
-
 
1356
        jz      .done1
-
 
1357
@@:
-
 
1358
        cmp     eax, 0xFF8
-
 
1359
        jae     .done1
-
 
1360
        lea     edi, [0x280000 + eax*2] ; position in FAT
-
 
1361
        xor     eax, eax
-
 
1362
        xchg    ax, [edi]
-
 
1363
        jmp     @b
-
 
1364
.done1:
-
 
1365
        pop     edi
-
 
1366
        call    get_time_for_file
-
 
1367
        mov     [edi+22], ax
-
 
1368
        call    get_date_for_file
-
 
1369
        mov     [edi+24], ax
-
 
1370
        mov     [edi+18], ax
-
 
1371
        or      byte [edi+11], 20h      ; set 'archive' attribute
-
 
1372
        jmp     .doit
-
 
1373
.notfound:
-
 
1374
; file is not found; generate short name
-
 
1375
        call    fat_name_is_legal
-
 
1376
        jc      @f
-
 
1377
        pop     edi
-
 
1378
        jmp     .err5
-
 
1379
@@:
-
 
1380
        sub     esp, 12
-
 
1381
        mov     edi, esp
-
 
1382
        call    fat_gen_short_name
-
 
1383
.test_short_name_loop:
-
 
1384
        push    esi ecx
-
 
1385
        mov     esi, 0x100000+512*19
-
 
1386
.test_short_name_entry:
-
 
1387
        cmp     byte [esi+11], 0xF
-
 
1388
        jz      .test_short_name_cont
-
 
1389
        mov     ecx, 11
-
 
1390
        push    esi edi
-
 
1391
        repz    cmpsb
-
 
1392
        pop     edi esi
-
 
1393
        jz      .short_name_found
-
 
1394
.test_short_name_cont:
-
 
1395
        add     esi, 20h
-
 
1396
        cmp     esi, 0x100000+512*33
-
 
1397
        jb      .test_short_name_entry
-
 
1398
        pop     ecx esi
-
 
1399
        jmp     .found
-
 
1400
.short_name_found:
-
 
1401
        call    fat_next_short_name
-
 
1402
        pop     ecx esi
-
 
1403
        jnc     .test_short_name_loop
-
 
1404
.disk_full:
-
 
1405
        add     esp, 12
-
 
1406
        pop     edi
-
 
1407
        mov     eax, ERROR_DISK_FULL
-
 
1408
        xor     ebx, ebx
-
 
1409
        ret
-
 
1410
.found:
-
 
1411
; now find space in directory
-
 
1412
; we need to save LFN <=> LFN is not equal to short name <=> generated name contains '~'
-
 
1413
        mov     al, '~'
-
 
1414
        push    ecx edi
-
 
1415
        mov     ecx, 8
-
 
1416
        repnz   scasb
-
 
1417
        push    1
-
 
1418
        pop     eax     ; 1 entry
-
 
1419
        jnz     .notilde
-
 
1420
; we need ceil(strlen(esi)/13) additional entries = floor((strlen(esi)+12+13)/13) total
-
 
1421
        xor     eax, eax
-
 
1422
@@:
-
 
1423
        cmp     byte [esi], 0
-
 
1424
        jz      @f
-
 
1425
        inc     esi
-
 
1426
        inc     eax
-
 
1427
        jmp     @b
-
 
1428
@@:
-
 
1429
        sub     esi, eax
-
 
1430
        add     eax, 12+13
-
 
1431
        mov     ecx, 13
-
 
1432
        push    edx
-
 
1433
        cdq
-
 
1434
        div     ecx
-
 
1435
        pop     edx
-
 
1436
.notilde:
-
 
1437
; find  successive entries in directory
-
 
1438
        xor     ecx, ecx
-
 
1439
        mov     edi, 0x100000+512*19
-
 
1440
.scan_dir:
-
 
1441
        cmp     byte [edi], 0
-
 
1442
        jz      .free
-
 
1443
        cmp     byte [edi], 0xE5
-
 
1444
        jz      .free
-
 
1445
        xor     ecx, ecx
-
 
1446
.scan_cont:
-
 
1447
        add     edi, 0x20
-
 
1448
        cmp     edi, 0x100000+512*33
-
 
1449
        jb      .scan_dir
-
 
1450
        pop     edi ecx
-
 
1451
        jmp     .disk_full
-
 
1452
.free:
-
 
1453
        inc     ecx
-
 
1454
        cmp     ecx, eax
-
 
1455
        jb      .scan_cont
-
 
1456
; found!
-
 
1457
; calculate name checksum
-
 
1458
        push    esi ecx
-
 
1459
        mov     esi, [esp+8]
-
 
1460
        mov     ecx, 11
-
 
1461
        xor     eax, eax
-
 
1462
@@:
-
 
1463
        ror     al, 1
-
 
1464
        add     al, [esi]
-
 
1465
        inc     esi
-
 
1466
        loop    @b
-
 
1467
        pop     ecx esi
-
 
1468
; edi points to last entry in free chunk
-
 
1469
        dec     ecx
-
 
1470
        jz      .nolfn
-
 
1471
        push    esi
-
 
1472
        push    edi
-
 
1473
.writelfn:
-
 
1474
        sub     edi, 20h
-
 
1475
        push    ecx eax
-
 
1476
        mov     eax, [esp+8]
-
 
1477
        sub     eax, edi
-
 
1478
        shr     eax, 5
-
 
1479
        cmp     ecx, 1
-
 
1480
        jnz     @f
-
 
1481
        or      al, 40h
-
 
1482
@@:
-
 
1483
        stosb
-
 
1484
        mov     cl, 5
-
 
1485
        call    .read_symbols
-
 
1486
        mov     ax, 0xF
-
 
1487
        stosw
-
 
1488
        pop     eax
-
 
1489
        stosb
-
 
1490
        push    eax
-
 
1491
        mov     cl, 6
-
 
1492
        call    .read_symbols
-
 
1493
        xor     eax, eax
-
 
1494
        stosw
-
 
1495
        mov     cl, 2
-
 
1496
        call    .read_symbols
-
 
1497
        pop     eax ecx
-
 
1498
        sub     edi, 0x20
-
 
1499
        loop    .writelfn
-
 
1500
        pop     edi
-
 
1501
        pop     esi
-
 
1502
.nolfn:
-
 
1503
        xchg    esi, [esp]
-
 
1504
        mov     ecx, 11
-
 
1505
        rep     movsb
-
 
1506
        mov     word [edi], 20h         ; attributes
-
 
1507
        sub     edi, 11
-
 
1508
        pop     esi ecx
-
 
1509
        add     esp, 12
-
 
1510
        mov     byte [edi+13], 0        ; tenths of a second at file creation time
-
 
1511
        call    get_time_for_file
-
 
1512
        mov     [edi+14], ax            ; creation time
-
 
1513
        mov     [edi+22], ax            ; last write time
-
 
1514
        call    get_date_for_file
-
 
1515
        mov     [edi+16], ax            ; creation date
-
 
1516
        mov     [edi+24], ax            ; last write date
-
 
1517
        mov     [edi+18], ax            ; last access date
-
 
1518
        and     word [edi+20], 0        ; high word of cluster
-
 
1519
        and     word [edi+26], 0        ; low word of cluster - to be filled
-
 
1520
        and     dword [edi+28], 0       ; file size - to be filled
-
 
1521
.doit:
-
 
1522
        push    ecx edx
-
 
1523
        push    ecx
-
 
1524
        push    edi
-
 
1525
        add     edi, 26         ; edi points to low word of cluster
-
 
1526
        push    edi
-
 
1527
        jecxz   .done
-
 
1528
        mov     ecx, 2849
-
 
1529
        mov     edi, 0x280000
-
 
1530
.write_loop:
-
 
1531
; allocate new cluster
-
 
1532
        xor     eax, eax
-
 
1533
        repnz   scasw
-
 
1534
        jnz     .disk_full2
-
 
1535
        dec     edi
-
 
1536
        dec     edi
-
 
1537
        lea     eax, [edi-0x280000]
-
 
1538
        shr     eax, 1                  ; eax = cluster
-
 
1539
        mov     word [edi], 0xFFF       ; mark as last cluster
-
 
1540
        xchg    edi, [esp]
-
 
1541
        stosw
-
 
1542
        pop     edi
-
 
1543
        push    edi
-
 
1544
        inc     ecx
-
 
1545
; write data
-
 
1546
        shl     eax, 9
-
 
1547
        add     eax, 0x100000+31*512
-
 
1548
        mov     ebx, edx
-
 
1549
        xchg    eax, ebx
-
 
1550
        push    ecx
-
 
1551
        mov     ecx, 512
-
 
1552
        cmp     dword [esp+12], ecx
-
 
1553
        jae     @f
-
 
1554
        mov     ecx, [esp+12]
-
 
1555
@@:
-
 
1556
        call    memmove
-
 
1557
        add     edx, ecx
-
 
1558
        sub     [esp+12], ecx
-
 
1559
        pop     ecx
-
 
1560
        jnz     .write_loop
-
 
1561
.done:
-
 
1562
        mov     ebx, edx
-
 
1563
        pop     edi edi ecx edx ecx
-
 
1564
        sub     ebx, edx
-
 
1565
        mov     [edi+28], ebx
-
 
1566
        pop     edi
-
 
1567
        xor     eax, eax
-
 
1568
        ret
-
 
1569
.disk_full2:
-
 
1570
        mov     ebx, edx
-
 
1571
        pop     edi edi ecx edx ecx
-
 
1572
        sub     ebx, edx
-
 
1573
        mov     [edi+28], ebx
-
 
1574
        pop     edi
-
 
1575
        push    ERROR_DISK_FULL
-
 
1576
        pop     eax
-
 
1577
        ret
-
 
1578
 
-
 
1579
.read_symbol:
-
 
1580
        or      ax, -1
-
 
1581
        test    esi, esi
-
 
1582
        jz      .retFFFF
-
 
1583
        lodsb
-
 
1584
        test    al, al
-
 
1585
        jnz     ansi2uni_char
-
 
1586
        xor     eax, eax
-
 
1587
        xor     esi, esi
-
 
1588
.retFFFF:
-
 
1589
        ret
-
 
1590
 
-
 
1591
.read_symbols:
-
 
1592
        call    .read_symbol
-
 
1593
        stosw
-
 
1594
        loop    .read_symbols
-
 
1595
        ret
1078
 
1596