home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / dos_ency / 8 / vols.asm < prev   
Encoding:
Assembly Source File  |  1988-08-11  |  7.1 KB  |  210 lines

  1.                 TITLE   'VOLS.ASM'
  2.  
  3. ;-----------------------------------------------------------------------------
  4. ;
  5. ; C-callable routines for manipulating MS-DOS volume labels
  6. ; Note: These routines modify the current DTA address.
  7. ;
  8. ;-----------------------------------------------------------------------------
  9.  
  10. ARG1            EQU     [bp + 4]        ; stack frame addressing
  11.  
  12. DGROUP          GROUP   _DATA
  13.  
  14. _TEXT           SEGMENT byte public 'CODE'
  15.                 ASSUME  cs:_TEXT,ds:DGROUP
  16.  
  17. ;-----------------------------------------------------------------------------
  18. ;
  19. ; char *GetVolLabel();          /* returns pointer to volume label name */
  20. ;
  21. ;-----------------------------------------------------------------------------
  22.  
  23.                 PUBLIC  _GetVolLabel
  24. _GetVolLabel    PROC    near
  25.  
  26.                 push    bp
  27.                 mov     bp,sp
  28.                 push    si
  29.                 push    di
  30.  
  31.                 call    SetDTA          ; pass DTA address to MS-DOS
  32.                 mov     dx,offset DGROUP:ExtendedFCB
  33.                 mov     ah,11h          ; AH = INT 21H function number
  34.                 int     21h             ; Search for First Entry
  35.                 test    al,al
  36.                 jnz     L01
  37.                                         ; label found so make a copy
  38.                 mov     si,offset DGROUP:DTA + 8
  39.                 mov     di,offset DGROUP:VolLabel
  40.                 call    CopyName
  41.                 mov     ax,offset DGROUP:VolLabel ; return the copy's address
  42.                 jmp     short L02
  43.  
  44. L01:            xor     ax,ax           ; no label, return 0 (null pointer)
  45.  
  46. L02:            pop     di
  47.                 pop     si
  48.                 pop     bp
  49.                 ret
  50.  
  51. _GetVolLabel    ENDP
  52.  
  53. ;-----------------------------------------------------------------------------
  54. ;
  55. ; int RenameVolLabel( label );          /* returns error code */
  56. ;         char *label;                  /* pointer to new volume label name */
  57. ;
  58. ;-----------------------------------------------------------------------------
  59.  
  60.                 PUBLIC  _RenameVolLabel
  61. _RenameVolLabel PROC    near
  62.  
  63.                 push    bp
  64.                 mov     bp,sp
  65.                 push    si
  66.                 push    di
  67.  
  68.                 mov     si,offset DGROUP:VolLabel  ; DS:SI -> old volume name
  69.                 mov     di,offset DGROUP:Name1
  70.                 call    CopyName        ; copy old name to FCB
  71.  
  72.                 mov     si,ARG1
  73.                 mov     di,offset DGROUP:Name2
  74.                 call    CopyName        ; copy new name into FCB
  75.  
  76.                 mov     dx,offset DGROUP:ExtendedFCB    ; DS:DX -> FCB
  77.                 mov     ah,17h          ; AH = INT 21H function number
  78.                 int     21h             ; rename
  79.                 xor     ah,ah           ; AX = 00H (success) or 0FFH (failure)
  80.  
  81.                 pop     di              ; restore registers and return
  82.                 pop     si
  83.                 pop     bp
  84.                 ret
  85.  
  86. _RenameVolLabel ENDP
  87.  
  88. ;-----------------------------------------------------------------------------
  89. ;
  90. ; int NewVolLabel( label );             /* returns error code */
  91. ;         char *label;                  /* pointer to new volume label name */
  92. ;
  93. ;-----------------------------------------------------------------------------
  94.  
  95.                 PUBLIC  _NewVolLabel
  96. _NewVolLabel    PROC    near
  97.  
  98.                 push    bp
  99.                 mov     bp,sp
  100.                 push    si
  101.                 push    di
  102.  
  103.                 mov     si,ARG1
  104.                 mov     di,offset DGROUP:Name1
  105.                 call    CopyName        ; copy new name to FCB
  106.  
  107.                 mov     dx,offset DGROUP:ExtendedFCB
  108.                 mov     ah,16h          ; AH = INT 21H function number
  109.                 int     21h             ; create directory entry
  110.                 xor     ah,ah           ; AX = 00H (success) or 0FFH (failure)
  111.  
  112.                 pop     di              ; restore registers and return
  113.                 pop     si
  114.                 pop     bp
  115.                 ret
  116.  
  117. _NewVolLabel    ENDP
  118.  
  119. ;-----------------------------------------------------------------------------
  120. ;
  121. ; int DeleteVolLabel();                 /* returns error code */
  122. ;
  123. ;-----------------------------------------------------------------------------
  124.  
  125.                 PUBLIC  _DeleteVolLabel
  126. _DeleteVolLabel PROC    near
  127.  
  128.                 push    bp
  129.                 mov     bp,sp
  130.                 push    si
  131.                 push    di
  132.  
  133.                 mov     si,offset DGROUP:VolLabel
  134.                 mov     di,offset DGROUP:Name1
  135.                 call    CopyName        ; copy current volume name to FCB
  136.  
  137.                 mov     dx,offset DGROUP:ExtendedFCB
  138.                 mov     ah,13h          ; AH = INT 21H function number
  139.                 int     21h             ; delete directory entry
  140.                 xor     ah,ah           ; AX = 0 (success) or 0FFH (failure)
  141.  
  142.                 pop     di              ; restore registers and return
  143.                 pop     si
  144.                 pop     bp
  145.                 ret
  146.  
  147. _DeleteVolLabel ENDP
  148.  
  149. ;-----------------------------------------------------------------------------
  150. ;
  151. ; miscellaneous subroutines
  152. ;
  153. ;-----------------------------------------------------------------------------
  154.  
  155. SetDTA          PROC    near
  156.  
  157.                 push    ax              ; preserve registers used
  158.                 push    dx
  159.  
  160.                 mov     dx,offset DGROUP:DTA    ; DS:DX -> DTA
  161.                 mov     ah,1Ah          ; AH = INT 21H function number
  162.                 int     21h             ; set DTA
  163.  
  164.                 pop     dx              ; restore registers and return
  165.                 pop     ax
  166.                 ret
  167.  
  168. SetDTA          ENDP
  169.  
  170.  
  171. CopyName        PROC    near            ; Caller:  SI -> ASCIIZ source
  172.                                         ;          DI -> destination
  173.                 push    ds
  174.                 pop     es              ; ES = DGROUP
  175.                 mov     cx,11           ; length of name field
  176.  
  177. L11:            lodsb                   ; copy new name into FCB ..
  178.                 test    al,al
  179.                 jz      L12             ; .. until null character is reached
  180.                 stosb
  181.                 loop    L11
  182.  
  183. L12:            mov     al,' '          ; pad new name with blanks
  184.                 rep     stosb
  185.                 ret
  186.  
  187. CopyName        ENDP
  188.  
  189. _TEXT           ENDS
  190.  
  191.  
  192. _DATA           SEGMENT word public 'DATA'
  193.  
  194. VolLabel        DB      11 dup(0),0
  195.  
  196. ExtendedFCB     DB      0FFh            ; must be 0FFH for extended FCB
  197.                 DB      5 dup(0)        ; (reserved)
  198.                 DB      1000b           ; attribute byte (bit 3 = 1)
  199.                 DB      0               ; default drive ID
  200. Name1           DB      11 dup('?')     ; global wildcard name
  201.                 DB      5 dup(0)        ; (unused)
  202. Name2           DB      11 dup(0)       ; second name (for renaming entry)
  203.                 DB      9 dup(0)        ; (unused)
  204.  
  205. DTA             DB      64 dup(0)
  206.  
  207. _DATA           ENDS
  208.  
  209.                 END
  210.