예제 #1
0
void __FreeDPMIBlocks( void )
{
    mheapptr    mhp;
    dpmi_hdr    *dpmi;

    mhp = __nheapbeg;
    while( mhp != NULL ) {
        // see if the last free entry has the full size of
        // the DPMI block ( - overhead).  If it is then we can give this
        // DPMI block back to the DPMI host.
        if( (mhp->freehead.prev)->len + sizeof( miniheapblkp ) == mhp->len ) {
            mheapptr    pnext;

            dpmi = ((dpmi_hdr *)mhp) - 1;
            pnext = mhp->next;
            __unlink( mhp );
            mhp = pnext;
            if( dpmi->dos_seg_value == 0 ) {    // if DPMI block
                TinyDPMIFree( dpmi->dpmi_handle );
            } else {                            // else DOS block below 1MB
                TinyFreeBlock( dpmi->dos_seg_value );
            }
        } else {
            mhp = mhp->next;
        }
    }
}
예제 #2
0
/* This returns a new stream opened on a temporary file (generated
   by tmpnam).  The file is opened with mode "w+b" (binary read/write).
   If we couldn't generate a unique filename or the file couldn't
   be opened, NULL is returned.  */
FILE *
tmpfile (void)
{
  char buf[FILENAME_MAX];
  int fd;
  FILE *f;

  if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0))
    return NULL;
  int flags = 0;
#ifdef FLAGS
  flags = FLAGS;
#endif
  fd = __gen_tempname (buf, 0, flags, __GT_FILE);
  if (fd < 0)
    return NULL;

  /* Note that this relies on the Unix semantics that
     a file is not really removed until it is closed.  */
  (void) __unlink (buf);

  if ((f = __fdopen (fd, "w+b")) == NULL)
    __close (fd);

  return f;
}
예제 #3
0
void *__ReAllocDPMIBlock( frlptr p1, unsigned req_size )
{
    mheapptr            mhp;
    struct dpmi_hdr     *dpmi;
    struct dpmi_hdr     *prev_dpmi;
    unsigned            size;
    frlptr              flp, flp2;

    if( !__heap_enabled )
        return( 0 );
    __FreeDPMIBlocks();
    prev_dpmi = NULL;
    for( mhp = __nheapbeg; mhp; mhp = mhp->next ) {
        if( ((PTR)mhp + sizeof(struct miniheapblkp) == (PTR)p1)
          && (mhp->numalloc == 1) ) {
            // The mini-heap contains only this memblk
            __unlink( mhp );
            dpmi = ((struct dpmi_hdr *)mhp) - 1;
            if( dpmi->dos_seg_value != 0 )
                return( NULL );
            size = mhp->len + sizeof(struct dpmi_hdr) + TAG_SIZE;
            size += ( req_size - (p1->len-TAG_SIZE) );
            size += BLKSIZE_ALIGN_MASK;
            size &= ~BLKSIZE_ALIGN_MASK;
            prev_dpmi = dpmi;
            dpmi = TinyDPMIRealloc( dpmi, size );
            if( dpmi == NULL ) {
                dpmi = prev_dpmi;
                return( NULL );         // indicate resize failed
            }
            dpmi->dos_seg_value = 0;
            mhp = (mheapptr)( dpmi + 1 );
            mhp->len = size - sizeof(struct dpmi_hdr) - TAG_SIZE;
            flp = __LinkUpNewMHeap( mhp );
            mhp->numalloc = 1;

            // round up to even number
            req_size = (req_size + 1) & ~1;
            size = flp->len - req_size;
            if( size >= FRL_SIZE ) {    // Enough to spare a free block
                flp->len = req_size | 1;// adjust size and set allocated bit
                // Make up a free block at the end
                flp2 = (frlptr)((PTR)flp + req_size);
                flp2->len = size | 1;
                ++mhp->numalloc;
                mhp->largest_blk = 0;
                _nfree( (PTR)flp2 + TAG_SIZE );
            } else {
                flp->len |= 1; // set allocated bit
            }
            return( flp );
        }
    }
    return( NULL );
}
예제 #4
0
파일: libwipe.c 프로젝트: anttikantee/toys
int unlink( const char *pathname )
{
	struct stat st;

	lstat(pathname, &st);
//printf("%x %d %d\n", st.st_mode, S_ISLNK(st.st_mode), S_ISREG(st.st_mode));
	if (S_ISREG(st.st_mode)==1) {
		if (do_wipe(pathname, st.st_blksize))
			return -1;
	}

	return (int)(__unlink( pathname ));
}
예제 #5
0
int unlink(const char *filename)
{
	int e;
	funcptr __unlink;

	DPRINT(("unlink filename=%s \n", filename));
	check_file(filename, CRUMB_ACCESS_TYPE_MODIFY, CRUMB_ACCESS_TYPE_UNLINK);
	__unlink = load_library_symbol("unlink");
	if (__unlink == NULL) {
		errno = ENOENT;
		return -1;
	}
	DPRINT(("unlink = %p\n", __unlink));
	e = __unlink(filename);
	DPRINT(("unlink filename=%s e=%d\n", filename, e));
	return e;
}
예제 #6
0
/* Trap attempts to unlink a file outside the sandbox.
 */
int unlink(const char* path) {
#define __unlink(x) syscall(SYS_unlink, (x))
	int result = 0;
	int isInSandbox = __darwintrace_is_in_sandbox(path, 0);
	if (isInSandbox == 1) {
		debug_printf("darwintrace: unlink was allowed at %s\n", path);
	} else if (isInSandbox == 0) {
		/* outside sandbox, but sandbox is defined: forbid */
		debug_printf("darwintrace: unlink was forbidden at %s\n", path);
		errno = EACCES;
		result = -1;
	}
	
	if (result == 0) {
		result = __unlink(path);
	}
	
	return result;
}
예제 #7
0
attribute_compat_text_section
__old_tmpfile (void)
{
  char buf[FILENAME_MAX];
  int fd;
  FILE *f;

  if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0))
    return NULL;
  fd = __gen_tempname (buf, 0, 0, __GT_FILE);
  if (fd < 0)
    return NULL;

  /* Note that this relies on the Unix semantics that
     a file is not really removed until it is closed.  */
  (void) __unlink (buf);

  if ((f = _IO_old_fdopen (fd, "w+b")) == NULL)
    __close (fd);

  return f;
}
예제 #8
0
파일: shmctl.c 프로젝트: OSLL/elfperf
/* Provide operations to control over shared memory segments.  */
int
__shmctl (int id, int cmd, struct shmid_ds *buf)
{
  error_t err = 0;
  int fd;
  int res;
  char filename[sizeof (SHM_DIR) - 1 + SHM_NAMEMAX];
  struct stat statbuf;

  sprintf (filename, SHM_DIR SHM_NAMEPRI, id);
  /* SysV requires read access for IPC_STAT.  */
  fd = __open (filename, O_NORW);
  if (fd < 0)
    {
      if (errno == ENOENT)
	errno = EINVAL;
      return -1;
    }

  res = __fstat (fd, &statbuf);
  if (res < 0)
    {
      err = errno;
      __close (fd);
      errno = err;
      return -1;
    }
  
  switch (cmd)
    {
    case IPC_STAT:

      buf->shm_perm.__key = id;
      buf->shm_perm.uid = statbuf.st_uid;
      buf->shm_perm.gid = statbuf.st_gid;

      /* We do not support the creator.  */
      buf->shm_perm.cuid = statbuf.st_uid;
      buf->shm_perm.cgid = statbuf.st_gid;

      /* We just want the protection bits.  */
      buf->shm_perm.mode = statbuf.st_mode & 0777;
      /* Hopeless.  We do not support a sequence number.  */
      buf->shm_perm.__seq = statbuf.st_ino;
      buf->shm_segsz = statbuf.st_size;

      /* Hopeless.  We do not support any of these.  */
      buf->shm_atime = statbuf.st_atime;
      buf->shm_dtime = statbuf.st_mtime;
      /* Well, this comes at least close.  */
      buf->shm_ctime = statbuf.st_ctime;

      /* We do not support the PID.  */
      buf->shm_cpid = 0;
      buf->shm_lpid = 0;

      if (statbuf.st_mode & S_IMMAP0)
        buf->shm_nattch = 0;
      else
        /* 42 is the answer.  Of course this is bogus, but for most
	   applications, this should be fine.  */
        buf->shm_nattch = 42;

      break;

    case IPC_SET:
      if (statbuf.st_uid != buf->shm_perm.uid
	  || statbuf.st_gid != buf->shm_perm.gid)
	{
	  res = __fchown (fd,
			  (statbuf.st_uid != buf->shm_perm.uid)
			  ? buf->shm_perm.uid : -1,
			  (statbuf.st_gid != buf->shm_perm.gid)
			  ? buf->shm_perm.gid : -1);
	  if (res < 0)
	    err = errno;
	}

      if (!err && statbuf.st_mode & 0777 != buf->shm_perm.mode & 0777)
	{
	  res = __fchmod (fd, (statbuf.st_mode & ~0777)
			  | (buf->shm_perm.mode & 0777));
	  if (res < 0)
	    err = errno;
	}
      break;

    case IPC_RMID:
      res = __unlink (filename);
      /* FIXME: Check error (mapping ENOENT to EINVAL).  */
      break;

    default:
      err = EINVAL;
    }

  __close (fd);
  errno = err;
  return err ? -1 : 0;
}
예제 #9
0
파일: hooks.c 프로젝트: krichter722/gfarm
int
unlink(const char *path)
{
	_gfs_hook_debug_v(fputs("Hooking unlink\n", stderr));
	return (__unlink(path));
}
예제 #10
0
int mv ()
{
  if (!out[1])
  {
    printf("Usage: cp SRC DEST\n");
    return -1;
  }
  if (!out[2])
  {
    printf("Missing target destination.\n");
    return -2;
  }
  if (strcmp(out[1], out[2]) == 0)
  {
    printf("Cannot move a file into itself.\n");
    return -3;
  }

  int ino, p_ino, sp_ino, src_dev = running->cwd->dev, dest_dev = running->cwd->dev, src_parent_dev = src_dev;
  char src[INODE_NAME*2], dest[INODE_NAME*2], dest_parent_path[INODE_NAME*2], src_parent_path[INODE_NAME*2];

  strcpy(src, out[1]);
  strcpy(dest, out[2]);
  strcpy(src_parent_path, dirname(out[1]));
  strcpy(dest_parent_path, dirname(out[2]));

  if (out[2][0] == '/')
  {
    src_parent_dev = src_dev = root->dev;
    dest_dev = root->dev;
  }


  p_ino = get_inode(dest_parent_path, &dest_dev, FALSE); // Make sure that the destination's parent exists
  if (p_ino < 0)
  {
    printf("\"%s\" : parent directory does not exist.\n", basename(dest_parent_path));
    return -4;
  }
  ino = get_inode(dest, &dest_dev, TRUE);       // Make sure that the destination file does not already exist
  if (ino > 0)                                    // Destination file already exists
  {
    printf("\"%s\" : file already exists with this name.\n", dest);
    return -4;
  }
  ino = get_inode(src, &src_dev, FALSE);       // Make sure that the source file does exist
  if (ino < 0)
  {
    return ino;
  }

  sp_ino = get_inode(src_parent_path, &src_parent_dev, TRUE);

  MINODE *mip   = iget(src_dev, ino);
  MINODE *d_pip = iget(dest_dev, p_ino);
  MINODE *s_pip = iget(src_dev, sp_ino);

  if (src_dev == dest_dev) // the source and destination are on the same device
  {
    enter_name(d_pip, ino, basename(dest), mip->Inode.i_mode);

    d_pip->dirty = TRUE;
    mip->dirty = TRUE;

    remove_name(s_pip, mip->ino, basename(src));
  }
  else
  {
    _cp(src, dest);

    mip->Inode.i_links_count--;
    if (mip->Inode.i_links_count == 0)
    {
      __unlink(mip, s_pip, basename(src));
    }

    remove_name(s_pip, mip->ino, basename(src));

    if (DEBUGGING)
      debug_dir(s_pip);

    s_pip->Inode.i_atime = time(0L);
    s_pip->dirty = TRUE;
    mip->dirty = TRUE;
  }
  // TODO: moving files across devices
  iput(mip);
  iput(d_pip);
  iput(s_pip);

  return 0;
}
예제 #11
0
파일: remove.c 프로젝트: alexfru/SmallerC
int remove(char* name)
{
  return __unlink(name);
}