summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2013-03-18 02:00:36 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2013-03-18 02:00:36 (GMT)
commit05e32465167317f9346b7561ba37b53f9f1a8476 (patch)
tree745c74a8040c86a2c1d4f645dc536c829e607e13
parent26325096ac0a86dcb637a41046a637eb13d72d73 (diff)
downloadvirtio9p-05e32465167317f9346b7561ba37b53f9f1a8476.zip
virtio9p-05e32465167317f9346b7561ba37b53f9f1a8476.tar.gz
virtio9p-05e32465167317f9346b7561ba37b53f9f1a8476.tar.bz2
virtio9p-05e32465167317f9346b7561ba37b53f9f1a8476.tar.xz
Move the diskspace function to a separate file
-rw-r--r--Makefile1
-rw-r--r--diskspc.asm192
-rw-r--r--fxn.asm158
3 files changed, 193 insertions, 158 deletions
diff --git a/Makefile b/Makefile
index 8029477..dba99df 100644
--- a/Makefile
+++ b/Makefile
@@ -37,6 +37,7 @@ XTOOLS := $(wildcard ../dostools/*.com ../dostools/*.exe)
OBJS = header.o start.o printmsg.o \
int2f.o acc.o fxn.o \
+ diskspc.o \
utf.o datetime.o \
message.o protomsg.o pathname.o
diff --git a/diskspc.asm b/diskspc.asm
new file mode 100644
index 0000000..218f427
--- /dev/null
+++ b/diskspc.asm
@@ -0,0 +1,192 @@
+/* -*- asm -*- ----------------------------------------------------------- *
+ *
+ * Copyright 2013 H. Peter Anvin - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+#include "v9fs.h"
+
+ .code16
+ .section ".rtext","ax"
+
+/* ------------------------------------------------------------------------- *
+ * fxn_diskspace
+ *
+ * Get free disk space in a format DOS can deal with. Since each path
+ * may have different values, return the value for the current directory.
+ * ------------------------------------------------------------------------- */
+
+GPROC(fxn_diskspace)
+ movw F_ES,%fs
+ movw F_DI,%si
+ addw %fs:CDS_ROOTOFFSET(%si),%si
+ movl $FID_DISKSPACE,%eax
+ pushl %eax
+ call path_walk
+
+ movw msgbuf7,%di
+ popl %eax
+ stosl
+ movb $P9_TSTATFS,%al
+ call simple_message
+ jc 12f
+
+ /*
+ * In the response:
+ * dword @ 4(%di) = block size
+ * qword @ 8(%di) = total blocks
+ * qword @ 24(%di) = free blocks for non-superuser
+ */
+#ifdef DEBUG
+ debugmsg "diskspace: "
+ pushl 4(%di)
+ call debug_printhex8
+ debugmsg " "
+ pushl 12(%di)
+ call debug_printhex8
+ pushl 8(%di)
+ call debug_printhex8
+ debugmsg " "
+ pushl 28(%di)
+ call debug_printhex8
+ pushl 24(%di)
+ call debug_printhex8
+ call debug_crlf
+#endif
+ movl 12(%di),%eax
+ mull 4(%di)
+ andl %edx,%edx
+ jne 10f /* > 2^64 bytes! */
+ movl %eax,%ebx
+ movl 8(%di),%eax
+ mull 4(%di)
+ addl %ebx,%edx
+ jc 10f
+
+ /*
+ * %edx:%eax now contains a byte count; we can represent it in
+ * a meaningful way iff it is < 2^38...
+ */
+#ifdef DEBUG
+ debugmsg "bytes: "
+ pushl %edx
+ call debug_printhex8
+ pushl %eax
+ call debug_printhex8
+ call debug_crlf
+#endif
+ bsrl %edx,%ecx
+ jnz 2f
+ bsrl %eax,%ecx
+ jmp 3f
+2:
+ addb $32,%cl
+3:
+ cmpb $37,%cl
+ ja 10f
+ subb $15,%cl
+ jnb 31f
+ xorb %cl,%cl
+31:
+ shrdl %cl,%edx,%eax
+
+#ifdef DEBUG
+ debugmsg "shift: "
+ pushw %cx
+ call debug_printhex2
+ debugmsg "\r\nclusters: "
+ pushw %ax
+ call debug_printhex4
+ call debug_crlf
+#endif
+
+4:
+ movw %ax,F_BX /* Total clusters */
+
+ movl 28(%di),%eax
+ mull 4(%di)
+ andl %edx,%edx
+ jne 11f
+ movl %eax,%ebx
+ movl 24(%di),%eax
+ mull 4(%di)
+ addl %ebx,%edx
+ jc 11f
+
+ shrdl %cl,%edx,%eax
+ shrl %cl,%edx
+
+ andl %edx,%edx
+ jnz 11f
+ cmpl $0x10000,%eax
+ jbe 5f
+11:
+ debugmsg "Free space overflow\r\n"
+ movw $0xffff,%ax
+
+5:
+ movw %ax,F_DX /* Available clusters */
+
+ /* Now, we need to turn %cl into a count */
+#ifdef DEBUG
+ debugmsg "Shift: "
+ pushw %cx
+ call debug_printhex2
+ call debug_crlf
+#endif
+ movw $1,%ax
+ movb $15,%ch
+ pushw %ax
+ cmpb %ch,%cl
+ jbe 6f
+ subb %ch,%cl
+ shlw %cl,%ax
+ movb %ch,%cl
+6:
+ movb %al,F_AL /* Sectors/cluster */
+ popw %ax /* %ax <- 1 */
+ shlw %cl,%ax
+ movw %ax,F_CX /* Bytes/sector */
+
+7:
+ movl $FID_DISKSPACE,%eax
+ call clunk
+
+ xorw %ax,%ax
+ retw
+
+10: /* Total size overflow */
+ debugmsg "Size overflow\r\n"
+ movb $(37-15),%cl
+ movw $0xffff,%ax
+ jmp 4b
+
+12: /* Error, but DOS doesn't like this. Return zero space. */
+ xorw %ax,%ax
+ movw $512,F_CX
+ movb $64,F_AL
+ movw %ax,F_BX
+ movw %ax,F_DX
+ jmp 7b
+END(fxn_diskspace)
diff --git a/fxn.asm b/fxn.asm
index 5b40108..d399cda 100644
--- a/fxn.asm
+++ b/fxn.asm
@@ -76,164 +76,6 @@ GPROC(fxn_delete)
END(fxn_delete)
/* ------------------------------------------------------------------------- *
- * fxn_diskspace
- * ------------------------------------------------------------------------- */
-
-GPROC(fxn_diskspace)
- movw F_ES,%fs
- movw F_DI,%si
- addw %fs:CDS_ROOTOFFSET(%si),%si
- movl $FID_DISKSPACE,%eax
- pushl %eax
- call path_walk
-
- movw msgbuf7,%di
- popl %eax
- stosl
- movb $P9_TSTATFS,%al
- call simple_message
- jc 12f
-
- /*
- * In the response:
- * dword @ 4(%di) = block size
- * qword @ 8(%di) = total blocks
- * qword @ 24(%di) = free blocks for non-superuser
- */
-#ifdef DEBUG
- debugmsg "diskspace: "
- pushl 4(%di)
- call debug_printhex8
- debugmsg " "
- pushl 12(%di)
- call debug_printhex8
- pushl 8(%di)
- call debug_printhex8
- debugmsg " "
- pushl 28(%di)
- call debug_printhex8
- pushl 24(%di)
- call debug_printhex8
- call debug_crlf
-#endif
- movl 12(%di),%eax
- mull 4(%di)
- andl %edx,%edx
- jne 10f /* > 2^64 bytes! */
- movl %eax,%ebx
- movl 8(%di),%eax
- mull 4(%di)
- addl %ebx,%edx
- jc 10f
-
- /*
- * %edx:%eax now contains a byte count; we can represent it in
- * a meaningful way iff it is < 2^38...
- */
-#ifdef DEBUG
- debugmsg "bytes: "
- pushl %edx
- call debug_printhex8
- pushl %eax
- call debug_printhex8
- call debug_crlf
-#endif
- bsrl %edx,%ecx
- jnz 2f
- bsrl %eax,%ecx
- jmp 3f
-2:
- addb $32,%cl
-3:
- cmpb $37,%cl
- ja 10f
- subb $15,%cl
- jnb 31f
- xorb %cl,%cl
-31:
- shrdl %cl,%edx,%eax
-
-#ifdef DEBUG
- debugmsg "shift: "
- pushw %cx
- call debug_printhex2
- debugmsg "\r\nclusters: "
- pushw %ax
- call debug_printhex4
- call debug_crlf
-#endif
-
-4:
- movw %ax,F_BX /* Total clusters */
-
- movl 28(%di),%eax
- mull 4(%di)
- andl %edx,%edx
- jne 11f
- movl %eax,%ebx
- movl 24(%di),%eax
- mull 4(%di)
- addl %ebx,%edx
- jc 11f
-
- shrdl %cl,%edx,%eax
- shrl %cl,%edx
-
- andl %edx,%edx
- jnz 11f
- cmpl $0x10000,%eax
- jbe 5f
-11:
- debugmsg "Free space overflow\r\n"
- movw $0xffff,%ax
-
-5:
- movw %ax,F_DX /* Available clusters */
-
- /* Now, we need to turn %cl into a count */
-#ifdef DEBUG
- debugmsg "Shift: "
- pushw %cx
- call debug_printhex2
- call debug_crlf
-#endif
- movw $1,%ax
- movb $15,%ch
- pushw %ax
- cmpb %ch,%cl
- jbe 6f
- subb %ch,%cl
- shlw %cl,%ax
- movb %ch,%cl
-6:
- movb %al,F_AL /* Sectors/cluster */
- popw %ax /* %ax <- 1 */
- shlw %cl,%ax
- movw %ax,F_CX /* Bytes/sector */
-
-7:
- movl $FID_DISKSPACE,%eax
- call clunk
-
- xorw %ax,%ax
- retw
-
-10: /* Total size overflow */
- debugmsg "Size overflow\r\n"
- movb $(37-15),%cl
- movw $0xffff,%ax
- jmp 4b
-
-12: /* Error, but DOS doesn't like this. Return zero space. */
- xorw %ax,%ax
- movw $512,F_CX
- movb $64,F_AL
- movw %ax,F_BX
- movw %ax,F_DX
- jmp 7b
-END(fxn_diskspace)
-
-/* ------------------------------------------------------------------------- *
* fxn_findfirst
* ------------------------------------------------------------------------- */