Beispiel #1
0
/**
* Function to process a file, based on type of operation being 
* performed. By default, this prints the path. Stat information 
* for the file may be printed if the verbose option is turned 
* on. Output from this function can be turned off with the quiet
* option. Then only statistics are reported by the treewalk.
*
* @param infile		a FileInfo structure containing the
*			file name and stat information
* @param perf		a PerfStat structure to be used to
* 			record any statistics resulting from
* 			processing a file
* @param o		the options structure holding the global
*			options values and other shared variables
*
* @return zero is returned if there are no problems process the
*	file. Non-zero is returned if there are!
*/
int treewalk_process_file(FileInfo *infile, PerfStat *perf, options o) {
	AppOptions *twp_o = (AppOptions *)o.app_ops;			// Treewalk options

	if(twp_o->quiet) return(0);					// don't want any output, so simply return

	if(!infile || strIsBlank(infile->path)) {
	  fprintf(stderr,"Worker Rank %d: treewalk_process_file() cannot print path. Blank path or no file information\n",o.rank);
	  return(-1);
	}

	if(!twp_o->verbose)						// No verbose -> just want the path
	  printf("%s\n",infile->path);
	else {								// stat info in ls-like format
	  if(infile->exists < 0)					// if exists flag < 0  -> no stat structure
	    printf("[  no stat information! ] %s\n", infile->path);
	  else {							// print the whole enchilada
	    struct tm sttm;
    	    char modebuf[15], timebuf[30];

	    printmode(infile->st.st_mode, modebuf);
 	    memcpy(&sttm, localtime(&infile->st.st_mtime), sizeof(sttm));
	    strftime(timebuf, sizeof(timebuf), "%a %b %d %Y %T", &sttm);

	    printf("%s %6d %6d %21zd %s %s\n", 
			modebuf, infile->st.st_uid, infile->st.st_gid, (size_t) infile->st.st_size, timebuf, infile->path);
	  }
	}
	return(0);
}
static int do_hardware_modes (ctl_table *table, int write,
			      void __user *result,
			      size_t *lenp, loff_t *ppos)
{
	struct parport *port = (struct parport *)table->extra1;
	char buffer[40];
	int len = 0;

	if (*ppos) {
		*lenp = 0;
		return 0;
	}

	if (write) /* permissions prevent this anyway */
		return -EACCES;

	{
#define printmode(x) {if(port->modes&PARPORT_MODE_##x){len+=sprintf(buffer+len,"%s%s",f?",":"",#x);f++;}}
		int f = 0;
		printmode(PCSPP);
		printmode(TRISTATE);
		printmode(COMPAT);
		printmode(EPP);
		printmode(ECP);
		printmode(DMA);
#undef printmode
	}
	buffer[len++] = '\n';

	if (len > *lenp)
		len = *lenp;
	else
		*lenp = len;

	*ppos += len;

	return copy_to_user(result, buffer, len) ? -EFAULT : 0;
}
Beispiel #3
0
int
init_one_port(struct linux_ebus_device *dev)
{
    struct parport tmpport, *p;
    unsigned long base;
    unsigned long config;
    int irq, dma;

    /* Pointer to NS87303 Configuration Registers */
    config = dev->base_address[1];

    /* Setup temporary access to Device operations */
    tmpport.base = dev->base_address[0];
    tmpport.ops = &parport_ax_ops;

    /* Configure IRQ to Push Pull, Level Low */
    /* Enable ECP mode, set bit 2 of the CTR first */
    tmpport.ops->write_control(&tmpport, 0x04);
    ns87303_modify(config, PCR,
                   PCR_EPP_ENABLE | PCR_IRQ_ODRAIN,
                   PCR_ECP_ENABLE | PCR_ECP_CLK_ENA | PCR_IRQ_POLAR);

    /* LPT CTR bit 5 controls direction of parallel port */
    ns87303_modify(config, PTR, 0, PTR_LPT_REG_DIR);

    /*
     * Now continue initializing the port
     */
    base = dev->base_address[0];
    irq = dev->irqs[0];
    dma = PARPORT_DMA_AUTO;

    if (!(p = parport_register_port(base, irq, dma, &parport_ax_ops)))
        return 0;

    /* Save away pointer to our EBus DMA */
    p->private_data = (void *)dev->base_address[2];

    p->modes = PARPORT_MODE_PCSPP | parport_PS2_supported(p);
    if (!check_region(p->base + 0x400, 3)) {
        p->modes |= parport_ECR_present(p);
        p->modes |= parport_ECP_supported(p);
        p->modes |= parport_ECPPS2_supported(p);
    }
    p->size = 3;

    if (p->dma == PARPORT_DMA_AUTO)
        p->dma = (p->modes & PARPORT_MODE_PCECP) ? 0 : PARPORT_DMA_NONE;

    printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
    if (p->irq != PARPORT_IRQ_NONE)
        printk(", irq %s", __irq_itoa(p->irq));
    if (p->dma != PARPORT_DMA_NONE)
        printk(", dma %d", p->dma);
    printk(" [");
    {
        int f = 0;
        printmode(SPP);
        printmode(PS2);
        printmode(ECP);
        printmode(ECPPS2);
    }
    printk("]\n");
    parport_proc_register(p);
    p->flags |= PARPORT_FLAG_COMA;

    p->ops->write_control(p, 0x0c);
    p->ops->write_data(p, 0);

    if (parport_probe_hook)
        (*parport_probe_hook)(p);

    return 1;
}
struct parport *__devinit parport_gsc_probe_port (unsigned long base,
						 unsigned long base_hi,
						 int irq, int dma,
						 struct pci_dev *dev)
{
	struct parport_gsc_private *priv;
	struct parport_operations *ops;
	struct parport tmp;
	struct parport *p = &tmp;

	priv = kmalloc (sizeof (struct parport_gsc_private), GFP_KERNEL);
	if (!priv) {
		printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base);
		return NULL;
	}
	ops = kmalloc (sizeof (struct parport_operations), GFP_KERNEL);
	if (!ops) {
		printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n",
			base);
		kfree (priv);
		return NULL;
	}
	memcpy (ops, &parport_gsc_ops, sizeof (struct parport_operations));
	priv->ctr = 0xc;
	priv->ctr_writable = 0xff;
	priv->dma_buf = 0;
	priv->dma_handle = 0;
	priv->dev = dev;
	p->base = base;
	p->base_hi = base_hi;
	p->irq = irq;
	p->dma = dma;
	p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
	p->ops = ops;
	p->private_data = priv;
	p->physport = p;
	if (!parport_SPP_supported (p)) {
		/* No port. */
		kfree (priv);
		return NULL;
	}
	parport_PS2_supported (p);

	if (!(p = parport_register_port(base, PARPORT_IRQ_NONE,
					PARPORT_DMA_NONE, ops))) {
		kfree (priv);
		kfree (ops);
		return NULL;
	}

	p->base_hi = base_hi;
	p->modes = tmp.modes;
	p->size = (p->modes & PARPORT_MODE_EPP)?8:3;
	p->private_data = priv;

	printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
	p->irq = irq;
	if (p->irq == PARPORT_IRQ_AUTO) {
		p->irq = PARPORT_IRQ_NONE;
	}
	if (p->irq != PARPORT_IRQ_NONE) {
		printk(", irq %d", p->irq);

		if (p->dma == PARPORT_DMA_AUTO) {
			p->dma = PARPORT_DMA_NONE;
		}
	}
	if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq
                                           is mandatory (see above) */
		p->dma = PARPORT_DMA_NONE;

	printk(" [");
#define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}}
	{
		int f = 0;
		printmode(PCSPP);
		printmode(TRISTATE);
		printmode(COMPAT)
		printmode(EPP);
//		printmode(ECP);
//		printmode(DMA);
	}
#undef printmode
	printk("]\n");

	if (p->irq != PARPORT_IRQ_NONE) {
		if (request_irq (p->irq, parport_gsc_interrupt,
				 0, p->name, p)) {
			printk (KERN_WARNING "%s: irq %d in use, "
				"resorting to polled operation\n",
				p->name, p->irq);
			p->irq = PARPORT_IRQ_NONE;
			p->dma = PARPORT_DMA_NONE;
		}
	}

	/* Done probing.  Now put the port into a sensible start-up state. */

	parport_gsc_write_data(p, 0);
	parport_gsc_data_forward (p);

	/* Now that we've told the sharing engine about the port, and
	   found out its characteristics, let the high-level drivers
	   know about it. */
	parport_announce_port (p);

	return p;
}
void do_file_entry(const u8* base,
		   const char* dir,
	           const char* path,
		   const char* name, int namelen, 
		   const struct cramfs_inode* inode)
{
   int dirlen=strlen(dir);
   int pathlen=strlen(path);
   char pname[dirlen+pathlen+namelen+3];
   const char* basename;
   
   if (dirlen) {
      strncpy(pname, dir, dirlen);
   }
   
   if (pathlen) {
      if (dirlen) {
	 pname[dirlen]='/';
	 ++dirlen;
      }
      strncpy(pname+dirlen, path, pathlen);
   }
   
   if (namelen) {
      if (pathlen+dirlen) {
	 pname[dirlen+pathlen]='/';
	 ++pathlen;
      }
      strncpy(pname+dirlen+pathlen, name, namelen);
   }

   pname[pathlen+dirlen+namelen]=0;
   basename=namelen ? pname+dirlen+pathlen : "/";
   
   // Create things here
   printmode(inode);
   printuidgid(inode);
   
   if (S_ISREG(inode->mode)) {
      do_file(base, inode->offset<<2, inode->size, pname, basename, inode->mode);
   } else  if (S_ISDIR(inode->mode)) {
      do_directory(base, inode->offset<<2, inode->size, pname, basename, inode->mode);
   } else  if (S_ISLNK(inode->mode)) {
      do_symlink(base, inode->offset<<2, inode->size, pname, basename, inode->mode);
   } else  if (S_ISFIFO(inode->mode)) {
      do_fifo(base, inode->offset<<2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);
   } else  if (S_ISSOCK(inode->mode)) {
      do_socket(base, inode->offset<<2, inode->size, pname, basename, inode->mode);
   } else  if (S_ISCHR(inode->mode)) {
      do_chrdev(base, inode->offset<<2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);
   } else  if (S_ISBLK(inode->mode)) {
      do_blkdev(base, inode->offset<<2, inode->size, pname, basename, inode->mode, inode->uid, inode->gid);
   } else {
      do_unknown(base, inode->offset<<2, inode->size, pname, basename, inode->mode);
   }
   
   if (geteuid() == 0) {
      if (lchown(pname, inode->uid, inode->gid) == -1)
         perror("cannot change owner or group");
   } else if(opt_idsfile && path && path[0]) {
      char dfp[1024];
      char *p;
      FILE *f;

      strcpy(dfp,pname);
      p = strrchr(dfp,'/');
      if (!p) {
         fprintf(stderr,"could not find path in '%s'\n",pname);
         return;
      }
      strcpy(p+1,opt_idsfile);
      f = fopen(dfp,"at");
      if (!f) {
   	    perror(dfp);
   	    return;
      }
	  fprintf(f,"%s,%u,%u,%08x\n",basename,inode->uid,inode->gid,inode->mode);
      fclose(f);
   }

   if (geteuid() == 0 || !opt_idsfile) {
      if (inode->mode & (S_ISGID|S_ISUID|S_ISVTX)) {
        if (0 != chmod(pname, inode->mode)){
          perror("chmod");
          return;
        }
      }
   }


   
   printf("\n");
}