⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Source: /u/mark/src/pax/RCS/list.c,v $ * * $Revision: 1.2 $ * * list.c - List all files on an archive * * DESCRIPTION * *	These function are needed to support archive table of contents and *	verbose mode during extraction and creation of achives. * * AUTHOR * *	Mark H. Colburn, NAPS International (mark@jhereg.mn.org) * * Sponsored by The USENIX Association for public distribution.  * * Copyright (c) 1989 Mark H. Colburn. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice is duplicated in all such  * forms and that any documentation, advertising materials, and other  * materials related to such distribution and use acknowledge that the  * software was developed * by Mark H. Colburn and sponsored by The  * USENIX Association.  * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * $Log:	list.c,v $ * Revision 1.2  89/02/12  10:04:43  mark * 1.2 release fixes *  * Revision 1.1  88/12/23  18:02:14  mark * Initial revision *  */#ifndef lintstatic char *ident = "$Id: list.c,v 1.2 89/02/12 10:04:43 mark Exp $";static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";#endif /* ! lint *//* Headers */#include "pax.h"/* Defines *//* * isodigit returns non zero iff argument is an octal digit, zero otherwise */#define	ISODIGIT(c)	(((c) >= '0') && ((c) <= '7'))/* Function Prototypes */#ifdef __STDC__static void cpio_entry(char *, Stat *);static void tar_entry(char *, Stat *);static void pax_entry(char *, Stat *);static void print_mode(ushort);static long from_oct(int digs, char *where);#else /* !__STDC__ */static void cpio_entry();static void tar_entry();static void pax_entry();static void print_mode();static long from_oct();#endif /* __STDC__ *//* Internal Identifiers */static char       *monnames[] = {    "Jan", "Feb", "Mar", "Apr", "May", "Jun",    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};/* read_header - read a header record * * DESCRIPTION * * 	Read a record that's supposed to be a header record. Return its  *	address in "head", and if it is good, the file's size in  *	asb->sb_size.  Decode things from a file header record into a "Stat".  *	Also set "head_standard" to !=0 or ==0 depending whether header record  *	is "Unix Standard" tar format or regular old tar format.  * * PARAMETERS * *	char   *name		- pointer which will contain name of file *	Stat   *asb		- pointer which will contain stat info * * RETURNS * * 	Return 1 for success, 0 if the checksum is bad, EOF on eof, 2 for a  * 	record full of zeros (EOF marker).  */#ifdef __STDC__int read_header(char *name, Stat *asb)#else    int read_header(name, asb)char           *name;Stat           *asb;#endif{    int             i;    long            sum;    long	    recsum;    Link           *link;    char           *p;    char            hdrbuf[BLOCKSIZE];    memset((char *)asb, 0, sizeof(Stat));    /* read the header from the buffer */    if (buf_read(hdrbuf, BLOCKSIZE) != 0) {	return (EOF);    }    strcpy(name, hdrbuf);    recsum = from_oct(8, &hdrbuf[148]);    sum = 0;    p = hdrbuf;    for (i = 0 ; i < 500; i++) {	/*	 * We can't use unsigned char here because of old compilers, e.g. V7. 	 */	sum += 0xFF & *p++;    }    /* Adjust checksum to count the "chksum" field as blanks. */    for (i = 0; i < 8; i++) {	sum -= 0xFF & hdrbuf[148 + i];    }    sum += ' ' * 8;    if (sum == 8 * ' ') {	/*	 * This is a zeroed record...whole record is 0's except for the 8	 * blanks we faked for the checksum field. 	 */	return (2);    }    if (sum == recsum) {	/*	 * Good record.  Decode file size and return. 	 */	if (hdrbuf[156] != LNKTYPE) {	    asb->sb_size = from_oct(1 + 12, &hdrbuf[124]);	}	asb->sb_mtime = from_oct(1 + 12, &hdrbuf[136]);	asb->sb_mode = from_oct(8, &hdrbuf[100]);	if (strcmp(&hdrbuf[257], TMAGIC) == 0) {	    /* Unix Standard tar archive */	    head_standard = 1;#ifdef NONAMES	    asb->sb_uid = from_oct(8, &hdrbuf[108]);	    asb->sb_gid = from_oct(8, &hdrbuf[116]);#else	    asb->sb_uid = finduid(&hdrbuf[265]);	    asb->sb_gid = findgid(&hdrbuf[297]);#endif	    switch (hdrbuf[156]) {	    case BLKTYPE:	    case CHRTYPE:#ifndef _POSIX_SOURCE		asb->sb_rdev = makedev(from_oct(8, &hdrbuf[329]),				      from_oct(8, &hdrbuf[337]));#endif		break;	    default:		/* do nothing... */		break;	    }	} else {	    /* Old fashioned tar archive */	    head_standard = 0;	    asb->sb_uid = from_oct(8, &hdrbuf[108]);	    asb->sb_gid = from_oct(8, &hdrbuf[116]);	}	switch (hdrbuf[156]) {	case REGTYPE:	case AREGTYPE:	    /*	     * Berkeley tar stores directories as regular files with a	     * trailing /	     */	    if (name[strlen(name) - 1] == '/') {		name[strlen(name) - 1] = '\0';		asb->sb_mode |= S_IFDIR;	    } else {		asb->sb_mode |= S_IFREG;	    }	    break;	case LNKTYPE:	    asb->sb_nlink = 2;	    linkto(&hdrbuf[157], asb);	    linkto(name, asb);	    asb->sb_mode |= S_IFREG;	    break;	case BLKTYPE:	    asb->sb_mode |= S_IFBLK;	    break;	case CHRTYPE:	    asb->sb_mode |= S_IFCHR;	    break;	case DIRTYPE:	    asb->sb_mode |= S_IFDIR;	    break;#ifdef S_IFLNK	case SYMTYPE:	    asb->sb_mode |= S_IFLNK;	    strcpy(asb->sb_link, &hdrbuf[157]);	    break;#endif#ifdef S_IFIFO	case FIFOTYPE:	    asb->sb_mode |= S_IFIFO;	    break;#endif#ifdef S_IFCTG	case CONTTYPE:	    asb->sb_mode |= S_IFCTG;	    break;#endif	}	return (1);    }    return (0);}/* print_entry - print a single table-of-contents entry * * DESCRIPTION *  *	Print_entry prints a single line of file information.  The format *	of the line is the same as that used by the LS command.  For some *	archive formats, various fields may not make any sense, such as *	the link count on tar archives.  No error checking is done for bad *	or invalid data. * * PARAMETERS * *	char   *name		- pointer to name to print an entry for *	Stat   *asb		- pointer to the stat structure for the file */#ifdef __STDC__void print_entry(char *name, Stat *asb)#else    void print_entry(name, asb)char		*name;Stat	        *asb;#endif{    switch (ar_interface) {    case TAR:	tar_entry(name, asb);	break;    case CPIO:	cpio_entry(name, asb);	break;    case PAX: pax_entry(name, asb);	break;    }}/* cpio_entry - print a verbose cpio-style entry * * DESCRIPTION * *	Print_entry prints a single line of file information.  The format *	of the line is the same as that used by the traditional cpio  *	command.  No error checking is done for bad or invalid data. * * PARAMETERS * *	char   *name		- pointer to name to print an entry for *	Stat   *asb		- pointer to the stat structure for the file */#ifdef __STDC__static void cpio_entry(char *name, Stat *asb)#else    static void cpio_entry(name, asb)char	       *name;Stat	       *asb;#endif{    struct tm	       *atm;    Link	       *from;    struct passwd      *pwp;    struct group       *grp;    if (f_list && f_verbose) {	fprintf(msgfile, "%-7o", asb->sb_mode);	atm = localtime(&asb->sb_mtime);	if (pwp = getpwuid((int) USH(asb->sb_uid))) {	    fprintf(msgfile, "%-6s", pwp->pw_name);	} else {	    fprintf(msgfile, "%-6u", USH(asb->sb_uid));	}	fprintf(msgfile,"%7ld  %3s %2d %02d:%02d:%02d %4d  ",	               asb->sb_size, monnames[atm->tm_mon], 		       atm->tm_mday, atm->tm_hour, atm->tm_min, 		       atm->tm_sec, atm->tm_year + 1900);

⌨️ 快捷键说明

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