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

📄 sca_read.c

📁 Solaris操作系统下的过滤驱动程序, C源码程序.
💻 C
字号:
/* * Copyright (c) 1997-2003 Erez Zadok * Copyright (c) 2001-2003 Stony Brook University * Copyright (c) 1997-2000 Columbia University * * For specific licensing information, see the COPYING file distributed with * this package, or get one from ftp://ftp.filesystems.org/pub/fist/COPYING. * * This Copyright notice must be kept intact and distributed with all * fistgen sources INCLUDING sources generated by fistgen. *//* *  $Id: sca_read.c,v 1.5 2002/12/27 20:19:06 ezk Exp $ */#include <stdio.h>#include <fcntl.h>#include <sys/stat.h>#include <sys/mman.h>#include <errno.h>#include <limits.h>#include <string.h>#include "sca_aux.h"#include "sca_code.h"	/* replace with your definitions of en/decode _page */intdecode_file(char *name){  char idx[MAXPATHLEN];  int srcfd;  struct fistfs_header hdr;  int i, len;  unsigned char *out;  if (name == NULL)    return(-1);  if ((srcfd = open(name, O_RDONLY)) < 0)    return(-1);  sprintf(idx, "%s.idx", name);  if ((read_idx(idx, &hdr)) < 0)    return(-1); /* read the header */  for(i=0; i<hdr.num_pages; i++) {    if ((get_page(srcfd, &hdr, i, &out, &len)) < 0) {      fprintf(stderr, "get_page returns error!\n");      return(-1);    }    if (len > chunksize) {      fprintf(stderr, "***decode returned %d bytes\n", len);    }    write(1, out, len);    free(out);  }  if(do_fast_tails) {		/* See if there unencoded data at the end */    /* This get_page will return 0 if there is no unencoded tail */    if ((get_page(srcfd, &hdr, i, &out, &len)) < 0) {      fprintf(stderr,"get_page returns error!\n");      return(-1);    }    write(1, out, len);    free(out);  }  return(0);}voidusage(const char *progname){  fprintf(stderr,	  "Usage: %s [-c chunksize] [-d] [-f] file1 [file2 file3 ...]\n",	  progname);}intmain(int argc, char **argv){  int i, rc, cnt = 0;  int debug = 0;  char *name;  if (argc < 2) {    usage(argv[0]);    exit(1);  }  while((i = getopt(argc, argv, "c:df")) != EOF) {    switch(i) {    case 'c':      chunksize = atoi(optarg);      if (chunksize < 0) {	fprintf(stderr, "Please use a positive chunk size\n");	exit(1);      }      break;    case 'f':      do_fast_tails = 1;      break;    case 'd':      debug = 1;      break;    default:      usage(argv[0]);      exit(1);    }  }  for(i=optind; i<argc; i++) {    name = strdup(argv[i]);    if ((rc = decode_file(argv[i])) < 0) {      fprintf(stderr, "\tError decoding %s (%d)\n", argv[i], rc);      cnt++;    }    free(name);  }  if (debug) {    fprintf(stderr,"encodes: %d\n", encode_counter);    fprintf(stderr,"decodes: %d\n", decode_counter);    fprintf(stderr,"writes:  %d\n", write_counter);  }  exit(cnt);}

⌨️ 快捷键说明

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