Subversion Repositories Kolibri OS

Rev

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

Rev 2455 Rev 2643
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
$Revision: 2455 $
8
$Revision: 2643 $
9
 
9
 
10
 
10
 
Line 31... Line 31...
31
align 4
31
align 4
Line 32... Line 32...
32
 
32
 
33
fs_dependent_data_start:
33
fs_dependent_data_start:
Line 34... Line -...
34
; FATxx data
-
 
35
 
-
 
36
SECTORS_PER_FAT      dd 0x1f3a
-
 
37
NUMBER_OF_FATS       dd 0x2
-
 
38
SECTORS_PER_CLUSTER  dd 0x8
-
 
39
BYTES_PER_SECTOR     dd 0x200   ; Note: if BPS <> 512 need lots of changes
-
 
40
ROOT_CLUSTER         dd 2       ; first rootdir cluster
-
 
41
FAT_START            dd 0       ; start of fat table
-
 
42
ROOT_START           dd 0       ; start of rootdir (only fat16)
-
 
43
ROOT_SECTORS         dd 0       ; count of rootdir sectors (only fat16)
-
 
44
DATA_START           dd 0       ; start of data area (=first cluster 2)
-
 
45
LAST_CLUSTER         dd 0       ; last availabe cluster
-
 
46
ADR_FSINFO           dd 0       ; used only by fat32
-
 
47
 
34
; FATxx data
48
fatRESERVED          dd 0x0FFFFFF6
35
 
49
fatBAD               dd 0x0FFFFFF7
-
 
50
fatEND               dd 0x0FFFFFF8
-
 
51
fatMASK              dd 0x0FFFFFFF
-
 
Line 52... Line 36...
52
 
36
.partition      dd      ?
53
fatStartScan         dd 2
37
                rb      80
54
 
38
 
55
fs_dependent_data_end:
39
fs_dependent_data_end:
Line 425... Line 409...
425
        mov     eax, [PARTITION_START]  ;ext2 test changes [buffer]
409
        mov     eax, [PARTITION_START]  ;ext2 test changes [buffer]
426
        call    hd_read
410
        call    hd_read
427
        cmp     [hd_error], 0
411
        cmp     [hd_error], 0
428
        jnz     problem_fat_dec_count
412
        jnz     problem_fat_dec_count
Line 429... Line -...
429
 
-
 
430
        cmp     word [ebx+0x1fe], 0xaa55; is it valid boot sector?
413
 
431
        jnz     problem_fat_dec_count
-
 
432
 
414
        push    0
433
        movzx   eax, word [ebx+0xe]; sectors reserved
415
        mov     eax, [PARTITION_END]
434
        add     eax, [PARTITION_START]
-
 
435
        mov     [FAT_START], eax; fat_start = partition_start + reserved
-
 
436
 
-
 
437
        movzx   eax, byte [ebx+0xd]; sectors per cluster
416
        sub     eax, [PARTITION_START]
438
        test    eax, eax
417
        inc     eax
439
        jz      problem_fat_dec_count
-
 
440
        mov     [SECTORS_PER_CLUSTER], eax
-
 
441
 
-
 
442
        movzx   ecx, word [ebx+0xb]; bytes per sector
418
        push    eax
443
        cmp     ecx, 0x200
-
 
444
        jnz     problem_fat_dec_count
419
        push    0
445
        mov     [BYTES_PER_SECTOR], ecx
-
 
446
 
-
 
447
        movzx   eax, word [ebx+0x11]; count of rootdir entries (=0 fat32)
420
        push    [PARTITION_START]
448
        mov     edx, 32
421
        push    ebp
449
        mul     edx
422
        push    ebp
450
        dec     ecx
423
        mov     ebp, esp
451
        add     eax, ecx        ; round up if not equal count
424
        mov     esi, 'old'      ; special value: there is no DISK structure
452
        inc     ecx             ; bytes per sector
425
        push    1       ; bootsector read successfully
453
        div     ecx
-
 
454
        mov     [ROOT_SECTORS], eax; count of rootdir sectors
-
 
455
 
426
        call    fat_create_partition
456
        movzx   eax, word [ebx+0x16]; sectors per fat <65536
427
        add     esp, 4*7
457
        test    eax, eax
-
 
458
        jnz     fat16_fatsize
-
 
459
        mov     eax, [ebx+0x24] ; sectors per fat
-
 
460
  fat16_fatsize:
-
 
461
        mov     [SECTORS_PER_FAT], eax
-
 
462
 
-
 
463
        movzx   eax, byte [ebx+0x10]; number of fats
-
 
464
        test    eax, eax        ; if 0 it's not fat partition
428
        test    eax, eax
465
        jz      problem_fat_dec_count
-
 
466
        mov     [NUMBER_OF_FATS], eax
-
 
467
        imul    eax, [SECTORS_PER_FAT]
-
 
468
        add     eax, [FAT_START]
-
 
469
        mov     [ROOT_START], eax; rootdir = fat_start + fat_size * fat_count
-
 
470
        add     eax, [ROOT_SECTORS]; rootdir sectors should be 0 on fat32
-
 
471
        mov     [DATA_START], eax; data area = rootdir + rootdir_size
-
 
472
 
-
 
473
        movzx   eax, word [ebx+0x13]; total sector count <65536
-
 
474
        test    eax, eax
-
 
475
        jnz     fat16_total
-
 
476
        mov     eax, [ebx+0x20] ; total sector count
-
 
477
  fat16_total:
-
 
478
        add     eax, [PARTITION_START]
-
 
479
        dec     eax
-
 
480
        mov     [PARTITION_END], eax
-
 
481
        inc     eax
-
 
482
        sub     eax, [DATA_START]; eax = count of data sectors
-
 
483
        xor     edx, edx
-
 
484
        div     dword [SECTORS_PER_CLUSTER]
-
 
485
        inc     eax
-
 
486
        mov     [LAST_CLUSTER], eax
-
 
487
        dec     eax             ; cluster count
429
        jz      problem_fat_dec_count
488
        mov     [fatStartScan], 2
-
 
489
 
-
 
490
    ; limits by Microsoft Hardware White Paper v1.03
-
 
491
        cmp     eax, 4085       ; 0xff5
-
 
492
        jb      problem_fat_dec_count; fat12 not supported
-
 
493
        cmp     eax, 65525      ; 0xfff5
-
 
494
        jb      fat16_partition
-
 
495
 
-
 
496
fat32_partition:
-
 
497
        mov     eax, [ebx+0x2c] ; rootdir cluster
-
 
498
        mov     [ROOT_CLUSTER], eax
-
 
499
        movzx   eax, word [ebx+0x30]; fs info sector
-
 
500
        add     eax, [PARTITION_START]
-
 
501
        mov     [ADR_FSINFO], eax
-
 
502
        call    hd_read
430
        mov     [fs_dependent_data_start.partition], eax
503
        mov     eax, [ebx+0x1ec]
-
 
504
        cmp     eax, -1
-
 
505
        jz      @f
-
 
506
        mov     [fatStartScan], eax
-
 
507
@@:
-
 
508
 
-
 
509
        popad
-
 
510
 
-
 
511
        mov     [fatRESERVED], 0x0FFFFFF6
-
 
512
        mov     [fatBAD], 0x0FFFFFF7
-
 
513
        mov     [fatEND], 0x0FFFFFF8
-
 
514
        mov     [fatMASK], 0x0FFFFFFF
431
        mov     al, [eax+FAT.fs_type]
515
        mov     [fs_type], 32  ; Fat32
-
 
516
        call    free_hd_channel
-
 
517
        mov     [hd1_status], 0 ; free
-
 
518
        ret
-
 
519
 
-
 
520
fat16_partition:
-
 
521
        xor     eax, eax
-
 
Line 522... Line 432...
522
        mov     [ROOT_CLUSTER], eax
432
        mov     [fs_type], al
523
 
-
 
524
        popad
-
 
525
 
-
 
526
        mov     [fatRESERVED], 0x0000FFF6
-
 
527
        mov     [fatBAD], 0x0000FFF7
-
 
528
        mov     [fatEND], 0x0000FFF8
-
 
529
        mov     [fatMASK], 0x0000FFFF
433
 
530
        mov     [fs_type], 16  ; Fat16
434
        popad
531
        call    free_hd_channel
435
        call    free_hd_channel
532
        mov     [hd1_status], 0 ; free
-