rtrepl.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 665 行 · 第 1/2 页

C
665
字号
#ifndef lintstatic  char    *sccsid = "@(#)rtrepl.c	4.1  (ULTRIX)        7/2/90";#endif lint/************************************************************************ *                                                                      * *                      Copyright (c) 1984 by                           * *              Digital Equipment Corporation, Maynard, MA              * *                      All rights reserved.                            * *                                                                      * *   This software is furnished under a license and may be used and     * *   copied  only  in accordance with the terms of such license and     * *   with the  inclusion  of  the  above  copyright  notice.   This     * *   software  or  any  other copies thereof may not be provided or     * *   otherwise made available to any other person.  No title to and     * *   ownership of the software is hereby transferred.                   * *                                                                      * *   The information in this software is subject to change  without     * *   notice  and should not be construed as a commitment by Digital     * *   Equipment Corporation.                                             * *                                                                      * *   Digital assumes no responsibility for the use  or  reliability     * *   of its software on equipment which is not supplied by Digital.     * *                                                                      * ************************************************************************//************************************************************************ *			Modification History				* *									* *	David L Ballenger, 22-Apr-1985					* * 0001	Change tmpnam variable to tmpname to avoid conflicts with 	* *	tmpnam routine declared in <stdio.h>.				* *									* ************************************************************************//*FACILITY:    RT-11 volume manipulation.ABSTRACT:    Replaces a file on an RT-11 device.ENVIRONMENT:    PRO/VENIX user mode.    ULTRIX-11 user mode.    ULTRIX-32 user mode.AUTHOR: Brian Hetrick, CREATION DATE: 1 March 1985.MODIFIED BY:	Brian Hetrick, 01-Mar-85: Version 1.0  000 - Original version of module.*//* * INCLUDE FILES: */#include "arff.h"#include <stdio.h>/* * TABLE OF CONTENTS: *//* *  delent - Delete RT-11 files with specified names. *  freent - Look for free space entry. *  freseg - Look for directory segment with free space entry. *  rtrepl - Replace files on RT-11 volume. *//* * MACROS: *//* * EQUATED SYMBOLS: *//* * OWN STORAGE: */static char    paknam [11],        /*  ASCII RT-11 file name.                  */    tmptmp [] = "/tmp/arffXXXXXX",			/*  Template for temporary name.            */    tmpname [sizeof tmptmp];			/*  Temporary name.                         */static int    frenum,             /*  Number of directory segment.            */    segful;             /*  Directory segment full flag.            */static rad50    r50blk [3];         /*  RADIX 50 RT-11 file name.               */static uword    wrksiz;             /*  Number of free blocks required.         *//* * EXTERNAL REFERENCES: */extern    arwcmt (),          /*  Notify of "wild card" match.            */    exit (),            /*  Terminate program.                      */    fprintf (),         /*  Print message to file.                  */    mktemp (),          /*  Make temporary file name.               */    rtcons (),          /*  Consolidate free space in directory     */			/*   segment.                               */    rtctrd (),          /*  Copy file to RT-11 device.              */    rtddep (),          /*  Decrement directory entry pointer.      */    rtgets (),          /*  Read directory segment.                 */    rtidep (),          /*  Increment directory entry pointer.      */    rtmkfn (),          /*  Make RT-11 file name from native name.  */    rtmvde (),          /*  Move directory entries.                 */    rtputs (),          /*  Write directory segment.                */    rtscnd (),          /*  Scan RT-11 device directory.            */    rtspds (),          /*  Split RT-11 directory segment.          */    strcpy (),          /*  Copy string.                            */    unlink ();          /*  Delete native file.                     */extern int    arvfyn ();          /*  Verify directory initialization.        */extern word    rtdate ();          /*  Get current date in RT-11 format.       */extern uword    rtmkfi ();          /*  Make RT-11 file image.                  */extern char    * pgmnam;           /*  Program's name.                         */extern int    modflg;             /*  Action modifier flags.                  */extern struct dirseg    dirseg;             /*  RT-11 directory segment buffer.         */static delent (de_ptr, filpos)struct dirent    * de_ptr;uword    filpos;/*********************************************************************FUNCTIONAL DESCRIPTION:    Deletes RT-11 files matching a specified file name.FORMAL PARAMETERS:    Directory_entry.mr.r - An RT-11 directory entry.    File_position.ruw.v - The starting block number of the file on the	RT-11 device.  [Unused by this routine.]IMPLICIT INPUTS:    r50blk - The RADIX 50 RT-11 file name block for  the  file  to  be	deleted.IMPLICIT OUTPUTS:    None.ROUTINE VALUE:    None.SIDE EFFECTS:    May exit with an error message.*********************************************************************/{#ifdef DEBUG    fprintf (stderr, "rtrepl\\delent: entry\n");#endif    /*     *  Check if is permanent file with correct name.     */    if ((de_ptr -> de_stat & DE_PERM) &&	(de_ptr -> de_name [0] == r50blk [0]) &&	(de_ptr -> de_name [1] == r50blk [1]) &&	(de_ptr -> de_name [2] == r50blk [2]))    {	/*	 *  Abort if file is protected.	 */	if (de_ptr -> de_stat & DE_PROT)	{	    fprintf (stderr, "%s: Protected file: %s\n", pgmnam, paknam);	    unlink (tmpname);	    exit (1);	}	/*	 *  Delete it.	 */	de_ptr -> de_stat = DE_EMPT;#ifdef DEBUG	fprintf (stderr, "rtrepl\\delent: deleting %s\n", paknam);#endif    }}static freent (de_ptr, filpos)struct dirent    * de_ptr;uword    filpos;/*********************************************************************FUNCTIONAL DESCRIPTION:    Examine the RT-11 device directory for a free area  sufficient  to    store a file image.FORMAL PARAMETERS:    Directory_entry.rr.r - A directory entry from the RT-11 directory.    File_position.ruw.v - The starting position in the RT-11 device of	the space  described  by  Directory_entry.   [Unused  in  this	routine.]IMPLICIT INPUTS:    wrksiz - The number of blocks required.IMPLICIT OUTPUTS:    frenum - The directory segment number of the directory segment  in	which  a  suitably  sized free area exists.  Set to -1 by this	routine as a flag to the freseg() routine;  set to the segment	number by the freseg() routine.ROUTINE VALUE:    None.SIDE EFFECTS:    None.*********************************************************************/{#ifdef DEBUG    fprintf (stderr, "rtrepl\\freent: looking at %06o\n", de_ptr);#endif    if ((de_ptr -> de_stat & DE_EMPT) &&	(de_ptr -> de_nblk >= wrksiz) &&	(0 == frenum))    {	frenum = -1;#ifdef DEBUG	fprintf (stderr, "rtrepl\\freent: free space found\n");#endif    }}static freseg (ds_ptr, segnum)struct dirseg    * ds_ptr;int    segnum;/*********************************************************************FUNCTIONAL DESCRIPTION:    Notes the segment number of a directory  segment  describing  suf-    ficient  free  space  to  store a file, and also notes whether the    segment is full.FORMAL PARAMETERS:    Directory_segment.rr.r - The directory segment.    Segment_number.ruw.v - The directory segment number.IMPLICIT INPUTS:    frenum - The directory segment number of the directory segment  in	which  a  suitably  sized  free area exists.  Set to -1 by the	freent() routine;  set to the segment number by this routine.IMPLICIT OUTPUTS:    frenum - The directory segment number of the directory segment  in	which  a  suitably  sized  free area exists.  Set to -1 by the	freent() routine;  set to the segment number by this routine.    segful - A flag indicating whether the directory segment is full.ROUTINE VALUE:    None.SIDE EFFECTS:    None.*********************************************************************/{    struct dirent	* de_ptr;#ifdef DEBUG    fprintf (stderr, "rtrepl\\freseg: looking at %06o\n", ds_ptr);#endif    /*

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?