     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: 08/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[71000000]            	mov	eax, usage_msg
    93                                  p_msg_exit:
    94 0000000C E846000000              	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[B3000000]            	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 721A                    	jc	short umnt_err
   114                                  	;
   115                                  	; Temporary! 08/05/2022 
   116                                  	; device number of /dev/fd0 is 0 and this
   117                                  	; affects sysumount system call return 
   118                                  	; because [mdev] = 0 when there is not
   119                                  	; a mounted device and sysumount checks this!.
   120                                  	;
   121                                  	; (It does not cause an error in file system
   122                                  	;  but sysumount returns to user with wrong
   123                                  	; 'ok'. For now, till sysumount system call
   124                                  	; modification, 'ok.' message must/will not
   125                                  	; be written for /dev/fd0.) 
   126                                  
   127 00000036 8B07                    	mov	eax, [edi]
   128 00000038 3D2F646576              	cmp	eax, '/dev'
   129 0000003D 7503                    	jne	short umnt_3
   130 0000003F 8B4705                  	mov	eax, [edi+5]  ; '/'+'fd0'+0
   131                                  umnt_3:
   132 00000042 3D66643000              	cmp	eax, 'fd0'
   133 00000047 74C8                    	je	short exit ; do not write 'OK.'	
   134                                  
   135 00000049 B8[F5000000]            	mov	eax, ok_msg
   136 0000004E EBBC                    	jmp	short p_msg_exit
   137                                  umnt_err:
   138 00000050 B8[E9000000]            	mov	eax, err_msg
   139 00000055 EBB5                    	jmp	short p_msg_exit
   140                                  
   141                                  ;-----------------------------------------------------------------
   142                                  
   143                                  print_msg:
   144                                  	; 08/05/2022
   145                                  	; eax = asciiz string address
   146 00000057 89C2                    	mov	edx, eax
   147 00000059 4A                      	dec	edx
   148                                  nextchr:
   149 0000005A 42                      	inc	edx
   150 0000005B 803A00                  	cmp	byte [edx], 0
   151 0000005E 77FA                    	ja	short nextchr
   152                                  	;cmp	[edx], 0Dh
   153                                  	;ja	short nextchr
   154 00000060 29C2                    	sub	edx, eax
   155                                  	; edx = asciiz string length
   156                                  	;
   157                                  	sys	_write, 1, eax
    57                              <1> 
    58                              <1> 
    59                              <1> 
    60                              <1>  %if %0 >= 2
    61 00000062 BB01000000          <1>  mov ebx, %2
    62                              <1>  %if %0 >= 3
    63 00000067 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 00000069 B804000000          <1>  mov eax, %1
    70 0000006E CD30                <1>  int 30h
   158                                  	;
   159 00000070 C3                      	retn
   160                                  
   161                                  ;-----------------------------------------------------------------
   162                                  ;  data - initialized data
   163                                  ;-----------------------------------------------------------------
   164                                  
   165                                  ; 08/05/2022
   166                                  
   167                                  usage_msg:
   168 00000071 0D0A                    	db 0Dh, 0Ah
   169 00000073 55736167653A20756D-     	db "Usage: umount <block device name> "
   169 0000007C 6F756E74203C626C6F-
   169 00000085 636B20646576696365-
   169 0000008E 206E616D653E20     
   170 00000095 0D0A                    	db 0Dh, 0Ah
   171 00000097 4578616D706C653A20-     	db "Example: umount /dev/fd1 "
   171 000000A0 756D6F756E74202F64-
   171 000000A9 65762F66643120     
   172 000000B0 0D0A00                  	db 0Dh, 0Ah, 0
   173                                  
   174                                  deny_msg:
   175 000000B3 0D0A                    	db 0Dh, 0Ah	
   176 000000B5 556D6F756E743A204F-     	db "Umount: Only superuser/root can dismount devices!"	
   176 000000BE 6E6C79207375706572-
   176 000000C7 757365722F726F6F74-
   176 000000D0 2063616E206469736D-
   176 000000D9 6F756E742064657669-
   176 000000E2 63657321           
   177 000000E6 0D0A00                   	db 0Dh, 0Ah, 0  		
   178                                  err_msg:
   179 000000E9 0D0A                    	db 0Dh, 0Ah
   180 000000EB 4572726F722120          	db 'Error! '
   181 000000F2 0D0A00                  	db 0Dh, 0Ah, 0
   182                                  ok_msg:
   183 000000F5 0D0A                    	db 0Dh, 0Ah
   184 000000F7 4F4B2E20                	db 'OK. '
   185                                  nextline:
   186 000000FB 0D0A00                  	db 0Dh, 0Ah, 0
   187                                  
   188                                  ;-----------------------------------------------------------------
