     1                                  ; ****************************************************************************
     2                                  ; umount386.s (umount1.s) - by Erdogan Tan - 08/05/2022
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; Retro UNIX 386 v1 - umount -- dismount file system
     5                                  ;
     6                                  ; [ Last Modification: 14/05/2022 ]
     7                                  ;
     8                                  ; ****************************************************************************
     9                                  ; (/etc/umount)
    10                                  
    11                                  ; umount0.s - Retro UNIX 8086 v1 (16 bit version of 'umount1.s')
    12                                  ; umount1.s - Retro UNIX 386 v1 (& v1.1 & v1.2)
    13                                  
    14                                  ; UNIX v1 system calls
    15                                  _rele 	equ 0
    16                                  _exit 	equ 1
    17                                  _fork 	equ 2
    18                                  _read 	equ 3
    19                                  _write	equ 4
    20                                  _open	equ 5
    21                                  _close 	equ 6
    22                                  _wait 	equ 7
    23                                  _creat 	equ 8
    24                                  _link 	equ 9
    25                                  _unlink	equ 10
    26                                  _exec	equ 11
    27                                  _chdir	equ 12
    28                                  _time 	equ 13
    29                                  _mkdir 	equ 14
    30                                  _chmod	equ 15
    31                                  _chown	equ 16
    32                                  _break	equ 17
    33                                  _stat	equ 18
    34                                  _seek	equ 19
    35                                  _tell 	equ 20
    36                                  _mount	equ 21
    37                                  _umount	equ 22
    38                                  _setuid	equ 23
    39                                  _getuid	equ 24
    40                                  _stime	equ 25
    41                                  _quit	equ 26	
    42                                  _intr	equ 27
    43                                  _fstat	equ 28
    44                                  _emt 	equ 29
    45                                  _mdate 	equ 30
    46                                  _stty 	equ 31
    47                                  _gtty	equ 32
    48                                  _ilgins	equ 33
    49                                  _sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
    50                                  _msg    equ 35 ; Retro UNIX 386 v1 feature only !
    51                                  
    52                                  ;;;
    53                                  ESCKey equ 1Bh
    54                                  EnterKey equ 0Dh
    55                                  
    56                                  %macro sys 1-4
    57                                      ; 03/09/2015	
    58                                      ; 13/04/2015
    59                                      ; Retro UNIX 386 v1 system call.		
    60                                      %if %0 >= 2   
    61                                  	mov ebx, %2
    62                                  	%if %0 >= 3    
    63                                  	    mov ecx, %3
    64                                  	    %if %0 = 4
    65                                  	       mov edx, %4   
    66                                  	    %endif
    67                                  	%endif
    68                                      %endif
    69                                      mov eax, %1
    70                                      int 30h	   
    71                                  %endmacro
    72                                  
    73                                  ; Retro UNIX 386 v1 system call format:
    74                                  ; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
    75                                  
    76                                  [BITS 32] ; 32-bit intructions (for 80386 protected mode)
    77                                  
    78                                  [ORG 0] 
    79                                  
    80                                  START_CODE:
    81                                  	; 08/05/2022
    82 00000000 59                      	pop	ecx ; ecx = number of arguments
    83                                  	;
    84 00000001 58                      	pop	eax ; eax = argument 0 = executable file name
    85                                  	;
    86                                  	;cmp	ecx, 2
    87 00000002 80F902                  	cmp	cl, 2
    88 00000005 7411                    	je	short umnt_1
    89                                  
    90                                  	; print usage message and then exit
    91                                  umnt_0:
    92 00000007 B8[5E000000]            	mov	eax, usage_msg
    93                                  p_msg_exit:
    94 0000000C E833000000              	call	print_msg
    95                                  exit:
    96                                  	sys	_exit
    57                              <1> 
    58                              <1> 
    59                              <1> 
    60                              <1>  %if %0 >= 2
    61                              <1>  mov ebx, %2
    62                              <1>  %if %0 >= 3
    63                              <1>  mov ecx, %3
    64                              <1>  %if %0 = 4
    65                              <1>  mov edx, %4
    66                              <1>  %endif
    67                              <1>  %endif
    68                              <1>  %endif
    69 00000011 B801000000          <1>  mov eax, %1
    70 00000016 CD30                <1>  int 30h
    97                                  ;hang:
    98                                  ;	nop
    99                                  ;	jmp	short hang
   100                                  
   101                                  umnt_1:
   102 00000018 5F                      	pop	edi ; argument 1 = device name
   103                                  
   104                                  	; only superuser (root) can do mount/umount
   105                                  	sys	_getuid
    57                              <1> 
    58                              <1> 
    59                              <1> 
    60                              <1>  %if %0 >= 2
    61                              <1>  mov ebx, %2
    62                              <1>  %if %0 >= 3
    63                              <1>  mov ecx, %3
    64                              <1>  %if %0 = 4
    65                              <1>  mov edx, %4
    66                              <1>  %endif
    67                              <1>  %endif
    68                              <1>  %endif
    69 00000019 B818000000          <1>  mov eax, %1
    70 0000001E CD30                <1>  int 30h
   106 00000020 21C0                    	and	eax, eax ; uid = 0 -> root
   107 00000022 7407                    	jz	short umnt_2
   108 00000024 B8[A0000000]            	mov	eax, deny_msg
   109 00000029 EBE1                    	jmp	short p_msg_exit
   110                                  umnt_2:
   111                                  	; edi = device name address
   112                                  	sys	_umount, edi
    57                              <1> 
    58                              <1> 
    59                              <1> 
    60                              <1>  %if %0 >= 2
    61 0000002B 89FB                <1>  mov ebx, %2
    62                              <1>  %if %0 >= 3
    63                              <1>  mov ecx, %3
    64                              <1>  %if %0 = 4
    65                              <1>  mov edx, %4
    66                              <1>  %endif
    67                              <1>  %endif
    68                              <1>  %endif
    69 0000002D B816000000          <1>  mov eax, %1
    70 00000032 CD30                <1>  int 30h
   113 00000034 7207                    	jc	short umnt_err
   114                                  
   115                                  	; 14/05/2022
   116                                  	; Following -temporary- code is not needed..
   117                                  	; (If /dev/fd0 is not mounted, -Retro Unix 8086 v1-
   118                                  	;  sysumount system call returns with error -cf=1-)
   119                                  
   120                                  	; ----
   121                                  	
   122                                  ;	; Temporary! 08/05/2022 
   123                                  ;	; device number of /dev/fd0 is 0 and this
   124                                  ;	; affects sysumount system call return 
   125                                  ;	; because [mdev] = 0 when there is not
   126                                  ;	; a mounted device and sysumount checks this!.
   127                                  ;	;
   128                                  ;	; (It does not cause an error in file system
   129                                  ;	;  but sysumount returns to user with wrong
   130                                  ;	; 'ok'. For now, till sysumount system call
   131                                  ;	; modification, 'ok.' message must/will not
   132                                  ;	; be written for /dev/fd0.) 
   133                                  ;
   134                                  ;	mov	eax, [edi]
   135                                  ;	cmp	eax, '/dev'
   136                                  ;	jne	short umnt_3
   137                                  ;	mov	eax, [edi+5]  ; '/'+'fd0'+0
   138                                  ;umnt_3:
   139                                  ;	cmp	eax, 'fd0'
   140                                  ;	je	short exit ; do not write 'OK.'	
   141                                  ;
   142                                  
   143 00000036 B8[E2000000]            	mov	eax, ok_msg
   144 0000003B EBCF                    	jmp	short p_msg_exit
   145                                  umnt_err:
   146 0000003D B8[D6000000]            	mov	eax, err_msg
   147 00000042 EBC8                    	jmp	short p_msg_exit
   148                                  
   149                                  ;-----------------------------------------------------------------
   150                                  
   151                                  print_msg:
   152                                  	; 08/05/2022
   153                                  	; eax = asciiz string address
   154 00000044 89C2                    	mov	edx, eax
   155 00000046 4A                      	dec	edx
   156                                  nextchr:
   157 00000047 42                      	inc	edx
   158 00000048 803A00                  	cmp	byte [edx], 0
   159 0000004B 77FA                    	ja	short nextchr
   160                                  	;cmp	[edx], 0Dh
   161                                  	;ja	short nextchr
   162 0000004D 29C2                    	sub	edx, eax
   163                                  	; edx = asciiz string length
   164                                  	;
   165                                  	sys	_write, 1, eax
    57                              <1> 
    58                              <1> 
    59                              <1> 
    60                              <1>  %if %0 >= 2
    61 0000004F BB01000000          <1>  mov ebx, %2
    62                              <1>  %if %0 >= 3
    63 00000054 89C1                <1>  mov ecx, %3
    64                              <1>  %if %0 = 4
    65                              <1>  mov edx, %4
    66                              <1>  %endif
    67                              <1>  %endif
    68                              <1>  %endif
    69 00000056 B804000000          <1>  mov eax, %1
    70 0000005B CD30                <1>  int 30h
   166                                  	;
   167 0000005D C3                      	retn
   168                                  
   169                                  ;-----------------------------------------------------------------
   170                                  ;  data - initialized data
   171                                  ;-----------------------------------------------------------------
   172                                  
   173                                  ; 08/05/2022
   174                                  
   175                                  usage_msg:
   176 0000005E 0D0A                    	db 0Dh, 0Ah
   177 00000060 55736167653A20756D-     	db "Usage: umount <block device name> "
   177 00000069 6F756E74203C626C6F-
   177 00000072 636B20646576696365-
   177 0000007B 206E616D653E20     
   178 00000082 0D0A                    	db 0Dh, 0Ah
   179 00000084 4578616D706C653A20-     	db "Example: umount /dev/fd1 "
   179 0000008D 756D6F756E74202F64-
   179 00000096 65762F66643120     
   180 0000009D 0D0A00                  	db 0Dh, 0Ah, 0
   181                                  
   182                                  deny_msg:
   183 000000A0 0D0A                    	db 0Dh, 0Ah	
   184 000000A2 556D6F756E743A204F-     	db "Umount: Only superuser/root can dismount devices!"	
   184 000000AB 6E6C79207375706572-
   184 000000B4 757365722F726F6F74-
   184 000000BD 2063616E206469736D-
   184 000000C6 6F756E742064657669-
   184 000000CF 63657321           
   185 000000D3 0D0A00                   	db 0Dh, 0Ah, 0  		
   186                                  err_msg:
   187 000000D6 0D0A                    	db 0Dh, 0Ah
   188 000000D8 4572726F722120          	db 'Error! '
   189 000000DF 0D0A00                  	db 0Dh, 0Ah, 0
   190                                  ok_msg:
   191 000000E2 0D0A                    	db 0Dh, 0Ah
   192 000000E4 4F4B2E20                	db 'OK. '
   193                                  nextline:
   194 000000E8 0D0A00                  	db 0Dh, 0Ah, 0
   195                                  
   196                                  ;-----------------------------------------------------------------
