From c64bc8a46c4d5590d03a571f9b3bc48b76ec2625 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Sat, 28 Oct 1995 01:03:40 +0000 Subject: [PATCH] Implement new primitives: NT-COPY-FILE, NT-GET-FILE-ATTRIBUTES, and NT-SET-FILE-ATTRIBUTES. --- v7/src/microcode/ntfs.c | 63 ++++++++++++++++++++++++++++++--------- v7/src/microcode/prntfs.c | 36 +++++++++++++++++++++- 2 files changed, 84 insertions(+), 15 deletions(-) diff --git a/v7/src/microcode/ntfs.c b/v7/src/microcode/ntfs.c index 551e8c996..fb1aa7902 100644 --- a/v7/src/microcode/ntfs.c +++ b/v7/src/microcode/ntfs.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntfs.c,v 1.8 1995/10/24 04:56:58 cph Exp $ +$Id: ntfs.c,v 1.9 1995/10/28 01:03:40 cph Exp $ Copyright (c) 1992-95 Massachusetts Institute of Technology @@ -95,9 +95,31 @@ DEFUN (OS_file_soft_link_p, (name), CONST char * name) return (0); } +static void +DEFUN (guarantee_writable, (name, errorp), + CONST char * name AND + int errorp) +{ + DWORD attributes = (GetFileAttributes (name)); + if (attributes == 0xFFFFFFFF) + { + DWORD error_code = (GetLastError ()); + if ((error_code != ERROR_FILE_NOT_FOUND) && errorp) + error_system_call (error_code, syscall_stat); + } + else if ((attributes & FILE_ATTRIBUTE_READONLY) != 0) + { + if ((! (SetFileAttributes (name, + (attributes &~ FILE_ATTRIBUTE_READONLY)))) + && errorp) + error_system_call ((GetLastError ()), syscall_chmod); + } +} + void DEFUN (OS_file_remove, (name), CONST char * name) { + guarantee_writable (name, 1); STD_VOID_SYSTEM_CALL (syscall_unlink, (NT_unlink (name))); } @@ -105,35 +127,48 @@ void DEFUN (OS_file_remove_link, (name), CONST char * name) { struct stat s; - if ( (NT_stat (name, (&s)) == 0) && - (((s . st_mode) & S_IFMT) == S_IFREG) ) - NT_unlink (name); - return; + if ((NT_stat (name, (&s)) == 0) + && (((s . st_mode) & S_IFMT) == S_IFREG)) + { + guarantee_writable (name, 0); + NT_unlink (name); + } } void -DEFUN (OS_file_link_hard, (from_name, to_name), - CONST char * from_name AND - CONST char * to_name) +DEFUN (OS_file_rename, (from, to), + CONST char * from AND + CONST char * to) { - error_unimplemented_primitive (); + guarantee_writable (name, 1); + STD_BOOL_SYSTEM_CALL (syscall_rename, (MoveFile (from, to))); } void -DEFUN (OS_file_link_soft, (from_name, to_name), +DEFUN (OS_file_copy, (from, to), + CONST char * from AND + CONST char * to) +{ + guarantee_writable (name, 1); + /* This system-call name is wrong, but there's no corresponding unix + operation, and I don't feel like customizing this for NT now. */ + STD_BOOL_SYSTEM_CALL (syscall_rename, (CopyFile (from, to, FALSE))); +} + +void +DEFUN (OS_file_link_hard, (from_name, to_name), CONST char * from_name AND CONST char * to_name) { error_unimplemented_primitive (); } - + void -DEFUN (OS_file_rename, (from_name, to_name), +DEFUN (OS_file_link_soft, (from_name, to_name), CONST char * from_name AND CONST char * to_name) { - if ((NT_rename (from_name, to_name)) != 0) - error_system_call (errno, syscall_rename); + error_unimplemented_primitive (); } void diff --git a/v7/src/microcode/prntfs.c b/v7/src/microcode/prntfs.c index c966c60f3..244f86820 100644 --- a/v7/src/microcode/prntfs.c +++ b/v7/src/microcode/prntfs.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: prntfs.c,v 1.4 1995/10/27 07:55:05 cph Exp $ +$Id: prntfs.c,v 1.5 1995/10/28 01:03:30 cph Exp $ Copyright (c) 1993-95 Massachusetts Institute of Technology @@ -46,6 +46,7 @@ MIT in each case. */ extern int EXFUN (NT_read_file_status, (CONST char * filename, struct stat * s)); +extern void EXFUN (OS_file_copy, (CONST char *, CONST char *)); static SCHEME_OBJECT EXFUN (file_attributes_internal, (struct stat * s)); static void EXFUN (file_mode_string, (struct stat * s, char * a)); @@ -413,3 +414,36 @@ DEFINE_PRIMITIVE ("NT-GET-VOLUME-INFORMATION", Prim_NT_get_vol_info, 1, 1, 0) VECTOR_SET (result, 4, (char_pointer_to_string (file_system_name))); PRIMITIVE_RETURN (result); } + +DEFINE_PRIMITIVE ("NT-COPY-FILE", Prim_NT_copy_file, 2, 2, 0) +{ + PRIMITIVE_HEADER (2); + OS_file_copy ((STRING_ARG (1)), (STRING_ARG (2))); + PRIMITIVE_RETURN (UNSPECIFIC); +} + +DEFINE_PRIMITIVE ("NT-GET-FILE-ATTRIBUTES", Prim_NT_get_file_attributes, 1, 1, 0) +{ + PRIMITIVE_HEADER (1); + { + CONST char * filename = (STRING_ARG (1)); + DWORD attributes = (GetFileAttributes (filename)); + if (attributes == 0xFFFFFFFF) + { + DWORD error_code = (GetLastError ()); + if (error_code != ERROR_FILE_NOT_FOUND) + error_system_call (error_code, syscall_stat); + PRIMITIVE_RETURN (SHARP_F); + } + PRIMITIVE_RETURN (ulong_to_integer (attributes)); + } +} + +DEFINE_PRIMITIVE ("NT-SET-FILE-ATTRIBUTES", Prim_NT_set_file_attributes, 2, 2, 0) +{ + PRIMITIVE_HEADER (2); + STD_BOOL_SYSTEM_CALL + (syscall_chmod, + (SetFileAttributes ((STRING_ARG (1)), (arg_ulong_integer (2))))); + PRIMITIVE_RETURN (UNSPECIFIC); +} -- 2.25.1