Example #1
1
mdb_io_t *
mdb_fdio_create_path(const char *path[], const char *fname,
    int flags, mode_t mode)
{
	int fd;
	char buf[MAXPATHLEN];

	if (path != NULL && strchr(fname, '/') == NULL) {
		int i;

		for (fd = -1, i = 0; path[i] != NULL; i++) {
			(void) mdb_iob_snprintf(buf, MAXPATHLEN, "%s/%s",
			    path[i], fname);

			if (access(buf, F_OK) == 0) {
				fd = open64(buf, flags, mode);
				fname = buf;
				break;
			}
		}

		if (fd == -1)
			(void) set_errno(ENOENT);
	} else
		fd = open64(fname, flags, mode);

	if (fd >= 0)
		return (mdb_fdio_create_named(fd, fname));

	return (NULL);
}
Example #2
0
/*
 * Open file on local machine.
 */
static int
openLocalFile(
	SamrftImpl_t *rftd,
	char *filename,
	int oflag,
	SamrftCreateAttr_t *creat)
{
	int rc = -1;

	rftd->fd = -1;
	if (creat != NULL) {
		rftd->fd = open64(filename, oflag, creat->mode & S_IAMB);
	} else {
		rftd->fd = open64(filename, oflag);
	}

	if (rftd->fd >= 0) {
		rc = 0;				/* open okay */

		if (creat != NULL) {
			/*
			 * If creating a file on an NFS mount point, daemon
			 * does not have permission to change the ownership.
			 * Ignore chown errors.
			 */
			(void) chown(filename, creat->uid, creat->gid);
		}
	}

	return (rc);
}
Example #3
0
STATIC int
openredirect(union node *redir)
{
	char *fname;
	int f;

	switch (redir->nfile.type) {
	case NFROM:
		fname = redir->nfile.expfname;
		if ((f = open64(fname, O_RDONLY)) < 0)
			goto eopen;
		break;
	case NFROMTO:
		fname = redir->nfile.expfname;
		if ((f = open64(fname, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
			goto ecreate;
		break;
	case NTO:
		/* Take care of noclobber mode. */
		if (Cflag) {
			fname = redir->nfile.expfname;
			if ((f = noclobberopen(fname)) < 0)
				goto ecreate;
			break;
		}
		/* FALLTHROUGH */
	case NCLOBBER:
		fname = redir->nfile.expfname;
		if ((f = open64(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
			goto ecreate;
		break;
	case NAPPEND:
		fname = redir->nfile.expfname;
		if ((f = open64(fname, O_WRONLY|O_CREAT|O_APPEND, 0666)) < 0)
			goto ecreate;
		break;
	default:
#ifdef DEBUG
		abort();
#endif
		/* Fall through to eliminate warning. */
	case NTOFD:
	case NFROMFD:
		f = -1;
		break;
	case NHERE:
	case NXHERE:
		f = openhere(redir);
		break;
	}

	return f;
ecreate:
	sh_error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
eopen:
	sh_error("cannot open %s: %s", fname, errmsg(errno, E_OPEN));
}
static int dofhelper_open() {
  int fd;
  if ((fd = open64(devname, O_RDWR)) < 0) {
    // Optimize next calls
    devname = olddevname;
    if ((fd = open64(devname, O_RDWR)) < 0) {
      return -1;
    }
  }
  return fd;
}
Example #5
0
static TACommandVerdict open64_fifo_cmd(TAThread thread,TAInputStream stream)
{
    char* path;
    int oflag;
    int is_not_null;
    int mode;
    int res;

    // Prepare
    path = readString(&stream);
    oflag = readOpenFlags(&stream);
    if (startsWith_TAInputStream(&stream,"null:"))
    {
        is_not_null = 0;
        verifyType_TAInputStream(&stream,"null");
    }
    else
    {
        is_not_null = 1;
        mode = readFilePermissions(&stream);
    }

    BEFORE_BLOCKED_TARGET_OPERATION(thread);

    writeString(thread,"Ok");
    sendResponse(thread);
    errno = 0;

    START_TARGET_OPERATION(thread);

    // Execute
    if (is_not_null)
    {
        res = open64(path,oflag,mode);
    }
    else
    {
        res = open64(path,oflag);
    }

    END_TARGET_OPERATION(thread);


    writeDeferredReaction(thread, "open_fifo_return");


    // Response
    writeInt(thread,res);
    writeInt(thread,errno);
    sendResponse(thread);

    return taDefaultVerdict;
}
Example #6
0
void
git_get_blob(CCS sha1, CCS path)
{
    CCS blob;
    int fd, ret, i;
    uint64_t fsize;
    struct stat64 stbuf;
    z_stream stream;
    unsigned char cprsbuf[4096], *fdata, *p;

    blob = git_path_to_blob(sha1);
    if ((fd = open64(blob, O_RDONLY|O_BINARY)) == -1) {
	putil_syserr(2, blob);
    }
    if (fstat64(fd, &stbuf)) {
	close(fd);
	putil_syserr(2, blob);
    }
    fsize = stbuf.st_size;
    fdata = util_map_file(blob, fd, 0, fsize);
    close(fd);

    if ((fd = open64(path, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0775)) == -1) {
	putil_syserr(2, path);
    }
    memset(&stream, 0, sizeof(stream));
    stream.next_in = fdata;
    stream.avail_in = (uInt)fsize;
    if (inflateInit(&stream) != Z_OK) {
	putil_die("inflateInit()");
    }
    for (i = 0, ret = Z_OK; ret != Z_STREAM_END; i++) {
	stream.avail_out = sizeof(cprsbuf);
	stream.next_out = cprsbuf;
	ret = inflate(&stream, Z_NO_FLUSH);
	if (i == 0) {
	    p = (unsigned char *)strchr((char *)cprsbuf, '\0') + 1;
	} else {
	    p = cprsbuf;
	}
	if (util_write_all(fd, p, stream.next_out - p) < 0) {
	    putil_syserr(2, blob);
	}
    }
    if (inflateEnd(&stream) != Z_OK) {
	putil_die("inflateEnd(): %s", stream.msg ? stream.msg : "failed");
    }
    close(fd);
    util_unmap_file(fdata, fsize);
}
Example #7
0
// =======================================================
QWORD CImageDisk::getPartitionSize(const char *szDevice) // [Main-Thread]
{
  QWORD qwSize;
  long lSize;
  int fdDevice;

  showDebug(1, "begin\n");
  qwSize = 0;
	
#ifdef HAVE_OPEN64
  fdDevice = open64(szDevice, O_RDONLY);
#else 
  fdDevice = open(szDevice, O_RDONLY);
#endif
  if (fdDevice < 0)
    THROW( ERR_ERRNO, errno);

#ifdef OS_LINUX
  if (!ioctl(fdDevice, BLKGETSIZE, &lSize))
    {
      qwSize = ((QWORD) 512) * ((QWORD) lSize);
    }
  else
    THROW( ERR_ERRNO, errno);
#endif

  if (::close(fdDevice))
    THROW( ERR_ERRNO, errno);

  return qwSize;
}
/* Lookup the latest process contract */
static ctid_t
get_active_process_contract_id(void)
{
	int stat_fd;
	ctid_t ctid = -1;
	ct_stathdl_t stathdl;

	if ((stat_fd = open64(CT_LATEST, O_RDONLY)) == -1) {
		error("%s: Error opening 'latest' process "
		    "contract: %s", __func__, strerror(errno));
		return -1;
	}
	if (ct_status_read(stat_fd, CTD_COMMON, &stathdl) != 0) {
		error("%s: Error reading process contract "
		    "status: %s", __func__, strerror(errno));
		goto out;
	}
	if ((ctid = ct_status_get_id(stathdl)) < 0) {
		error("%s: Error getting process contract id: %s",
		    __func__, strerror(errno));
		goto out;
	}

	ct_status_free(stathdl);
 out:
	close(stat_fd);
	return ctid;
}
Example #9
0
MemMappedFile::MemMappedFile(int objSize, int nrObj, int memSize, const char *fileN, bool isWr)
{
  isWritable   = isWr;
  pageSize     = sysconf(_SC_PAGE_SIZE);
  objectSize   = objSize;
  totNrObjects = nrObj;
  firstObject  = 0;
  memBlockSize = (memSize/pageSize + 1) * pageSize;
  nrObjects    = memBlockSize / objectSize - 1;

  assert(nrObjects > 1);

  FILE *memFile = fopen64(fileN,  "wb");
  char tmp      = 1;
  int written   = 0;
  int writeSize = pageSize*100;
  while(written < objectSize * totNrObjects + memBlockSize)
  {
    fseek(memFile, writeSize-1, SEEK_CUR);
    fwrite(&tmp,1,1,memFile);
    written += writeSize;
  }
  fclose(memFile);

  fileDescriptor = open64(fileN, O_RDWR);
  assert(fileDescriptor >= 0);
  memoryPool = (char*) mmap(0, memBlockSize, PROT_READ | PROT_WRITE, MAP_SHARED, fileDescriptor, 0);
  assert(memoryPool != (caddr_t) - 1);
}
Example #10
0
int xfs_test(char *devname)
{
    struct xfs_sb sb;
    int fd;
    
    if ((fd=open64(devname, O_RDONLY|O_LARGEFILE))<0)
    {
        msgprintf(MSG_DEBUG1, "open64(%s) failed\n", devname);
        return false;
    }
    
    memset(&sb, 0, sizeof(sb));
    if (read(fd, &sb, sizeof(sb))!=sizeof(sb))
    {   close(fd);
        msgprintf(MSG_DEBUG1, "read failed\n");
        return false;
    }
    
    // ---- check it's an XFS file system
    if (be32_to_cpu(sb.sb_magicnum) != XFS_SB_MAGIC)
    {   close(fd);
        msgprintf(MSG_DEBUG1, "(be32_to_cpu(sb.sb_magicnum)=%.8x) != (XFS_SB_MAGIC=%.8x)\n", be32_to_cpu(sb.sb_magicnum), XFS_SB_MAGIC);
        return false;
    }
    
    close(fd);
    return true;
}
Example #11
0
extern jlong file_open(JNIEnv *env, const char *filename, int open_flags, int flag)
{
  int fd;
  int rc;
  int access_type;


  /* Determine access: */
  if (flag & 0x01 == 1)
    access_type = ( O_RDWR | O_CREAT );
  else
    access_type = ( O_RDONLY );

  /* Add flags requested by caller: */
  access_type |= open_flags;

  /* Open the file: */
  fd = open64(filename, (access_type), 0666);
  if ( fd == -1 )
  {
    PTOD1("error: %d", errno);
    PTOD1("file_open(), open %s failed", filename);
    return -1;
  }

  return fd;
}
Example #12
0
/*ARGSUSED*/
int
vn_open(char *path, enum uio_seg x1, int flags, int mode, vnode_t **vpp, enum create x2, mode_t x3)
{
    int fd;
    int old_umask = 0;
    struct stat64 st;

    if (!(flags & FCREAT) && stat64(path, &st) == -1)
        return (errno);

    if (flags & FCREAT)
        old_umask = umask(0);

    if (!(flags & FCREAT) && S_ISBLK(st.st_mode)) {
        flags |= O_DIRECT;
        /* O_EXCL can't be passed for hot spares : they can be shared
         * between pools */
        /*	if (flags & FWRITE)
        		flags |= O_EXCL; */
    }

    /*
     * The construct 'flags - FREAD' conveniently maps combinations of
     * FREAD and FWRITE to the corresponding O_RDONLY, O_WRONLY, and O_RDWR.
     */
    fd = open64(path, flags - FREAD, mode);

    if (flags & FCREAT)
        (void) umask(old_umask);

    if (fd == -1)
        return (errno);

    return vn_fromfd(fd, path, flags, vpp, B_FALSE);
}
Example #13
0
static void
dtrace_dof_fini(void)
{
#if illumos
	int fd;

	if ((fd = open64(devnamep, O_RDWR)) < 0) {
		dprintf(1, "failed to open helper device %s", devnamep);
		return;
	}

	if ((gen = ioctl(fd, DTRACEHIOC_REMOVE, &gen)) == -1)
		dprintf(1, "DTrace ioctl failed to remove DOF (%d)\n", gen);
	else
		dprintf(1, "DTrace ioctl removed DOF (%d)\n", gen);

	(void) close(fd);
#else
	HANDLE fd;
	DWORD ret;
	
	if ((fd = CreateFile(devnamep, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == NULL) {
		dprintf(1, "failed to open helper device %s", devnamep);
		return;
	}
	
	if ((gen = DeviceIoControl(fd, DTRACEHIOC_REMOVE, &gen, 0, &gen, 0, &ret, NULL)) == 0)
		dprintf(1, "DTrace ioctl failed to remove DOF (%d)\n", gen);
	else
		dprintf(1, "DTrace ioctl removed DOF (%d)\n", gen);
#endif
	
}
Example #14
0
static inline Dwfl_Error
open_elf_file (Elf **elf, int *fd, char **name)
{
  if (*elf == NULL)
    {
      /* CBFAIL uses errno if it's set, so clear it first in case we don't
	 set it with an open failure below.  */
      errno = 0;

      /* If there was a pre-primed file name left that the callback left
	 behind, try to open that file name.  */
      if (*fd < 0 && *name != NULL)
	*fd = TEMP_FAILURE_RETRY (open64 (*name, O_RDONLY));

      if (*fd < 0)
	return CBFAIL;

      return __libdw_open_file (fd, elf, true, false);
    }
  else if (unlikely (elf_kind (*elf) != ELF_K_ELF))
    {
      elf_end (*elf);
      *elf = NULL;
      close (*fd);
      *fd = -1;
      return DWFL_E_BADELF;
    }

  /* Elf file already open and looks fine.  */
  return DWFL_E_NOERROR;
}
Example #15
0
/*
 * Open a file through the POSIX interface.
 */
static void *POSIX_Open(char *testFileName, IOR_param_t * param)
{
        int fd_oflag = O_BINARY;
        int *fd;

        fd = (int *)malloc(sizeof(int));
        if (fd == NULL)
                ERR("Unable to malloc file descriptor");

        if (param->useO_DIRECT == TRUE)
                set_o_direct_flag(&fd_oflag);

        fd_oflag |= O_RDWR;
        *fd = open64(testFileName, fd_oflag);
        if (*fd < 0)
                ERR("open64 failed");

#ifdef HAVE_LUSTRE_LUSTRE_USER_H
        if (param->lustre_ignore_locks) {
                int lustre_ioctl_flags = LL_FILE_IGNORE_LOCK;
                if (verbose >= VERBOSE_1) {
                        fprintf(stdout,
                                "** Disabling lustre range locking **\n");
                }
                if (ioctl(*fd, LL_IOC_SETFLAGS, &lustre_ioctl_flags) == -1)
                        ERR("ioctl(LL_IOC_SETFLAGS) failed");
        }
#endif                          /* HAVE_LUSTRE_LUSTRE_USER_H */

        return ((void *)fd);
}
Example #16
0
static struct fileStore *ds_open(const char *filename, size_t blockSize, size_t blockCount) 
{
	struct fileStore* fs = (struct fileStore*) malloc(sizeof(struct fileStore));

	assert(fs);

	fs->data_file = open64(filename, O_RDWR|O_CREAT, S_IRWXU);
	fs->used_index = NULL;

	if(fs->data_file < 0) {
		perror("");
	}

	if(blockCount < 8) {
		blockCount = 8;
	}
	blockCount = (blockCount / 8) * 8;

	fs->blockSize = blockSize;
	fs->newLastBlock = 0;
	fs->calledFree = 0;

	fs->blockCount = 0;
	ds_grow_files(fs, blockCount);

	assert(!(fs->blockCount % 8));
	return fs;
}
Example #17
0
/*
 * Common function
 */
static char *
getl_r_common(char *answer, size_t namelen, size_t maxlen)
{
	int		uf;
	off64_t		me;
	struct futmpx	ubuf;

	if ((me = (off64_t)ttyslot()) < 0)
		return (NULL);
	if ((uf = open64(UTMPX_FILE, 0)) < 0)
		return (NULL);
	(void) lseek64(uf, me * sizeof (ubuf), SEEK_SET);
	if (read(uf, &ubuf, sizeof (ubuf)) != sizeof (ubuf)) {
		(void) close(uf);
		return (NULL);
	}
	(void) close(uf);
	if (ubuf.ut_user[0] == '\0')
		return (NULL);

	/* Insufficient buffer size */
	if (namelen < strnlen(&ubuf.ut_user[0], maxlen)) {
		errno = ERANGE;
		return (NULL);
	}
	(void) strncpy(&answer[0], &ubuf.ut_user[0], maxlen);
	answer[maxlen] = '\0';
	return (&answer[0]);
}
Example #18
0
int jfs_test(char *devname)
{
    struct jfs_superblock sb;
    int fd;
    
    if ((fd=open64(devname, O_RDONLY|O_LARGEFILE))<0)
        return false;
    
    if (lseek(fd, JFS_SUPER1_OFF, SEEK_SET)!=JFS_SUPER1_OFF)
    {   close(fd);
        return false;
    }
    
    if (read(fd, &sb, sizeof(sb))!=sizeof(sb))
    {   close(fd);
        return false;
    }
    
    if (strncmp(sb.s_magic, JFS_MAGIC, strlen(JFS_MAGIC)) != 0)
    {   close(fd);
        return false;
    }
    
    close(fd);
    return true;
}
Example #19
0
int os_open_file(char *file, struct openflags flags, int mode)
{
	int fd, f = 0;

	if(flags.r && flags.w) f = O_RDWR;
	else if(flags.r) f = O_RDONLY;
	else if(flags.w) f = O_WRONLY;
	else f = 0;

	if(flags.s) f |= O_SYNC;
	if(flags.c) f |= O_CREAT;
	if(flags.t) f |= O_TRUNC;
	if(flags.e) f |= O_EXCL;

	fd = open64(file, f, mode);
	if(fd < 0) return(-errno);
	
	if(flags.cl){
		if(fcntl(fd, F_SETFD, 1)){
			close(fd);
			return(-errno);
		}
	}

 	return(fd);
	return(fd);
}
Example #20
0
int os_file_size(char *file, long long *size_out)
{
	struct stat64 buf;

	if(stat64(file, &buf) == -1){
		printk("Couldn't stat \"%s\" : errno = %d\n", file, errno);
		return(-errno);
	}
	if(S_ISBLK(buf.st_mode)){
		int fd, blocks;

		if((fd = open64(file, O_RDONLY)) < 0){
			printk("Couldn't open \"%s\", errno = %d\n", file,
			       errno);
			return(-errno);
		}
		if(ioctl(fd, BLKGETSIZE, &blocks) < 0){
			printk("Couldn't get the block size of \"%s\", "
			       "errno = %d\n", file, errno);
			close(fd);
			return(-errno);
		}
		*size_out = ((long long) blocks) * 512;
		close(fd);
		return(0);
	}
	*size_out = buf.st_size;
	return(0);
}
Example #21
0
int
main (int argc, char *argv[])
{
	int fd;
	off64_t off;

	if (argc != 3 || strcmp (argv[1], "--help") == 0) {
		printf ("usage: %s <pathname> <offset>\n", argv[0]);
		return 1;
	}

	fd = open64 (argv[1], O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
	if (fd == -1) {
		perror ("open64()");
		return 1;
	}

	off = atoll (argv[2]);
	if (lseek64 (fd, off, SEEK_SET) == -1) {
		perror ("lseek64()");
		return 1;
	}

	if (write (fd, "test", 4) == -1) {
		perror ("write()");
		return 1;
	}

	return EXIT_SUCCESS;
}
/* Try to open the given file as it is or under the debuginfo directory.  */
static int
try_kernel_name (Dwfl *dwfl, char **fname, bool try_debug)
{
  if (*fname == NULL)
    return -1;

  /* Don't bother trying *FNAME itself here if the path will cause it to be
     tried because we give its own basename as DEBUGLINK_FILE.  */
  int fd = ((((dwfl->callbacks->debuginfo_path
	       ? *dwfl->callbacks->debuginfo_path : NULL)
	      ?: DEFAULT_DEBUGINFO_PATH)[0] == ':') ? -1
	    : TEMP_FAILURE_RETRY (open64 (*fname, O_RDONLY)));

  if (fd < 0)
    {
      Dwfl_Module fakemod = { .dwfl = dwfl };
      /* First try the file's unadorned basename as DEBUGLINK_FILE,
	 to look for "vmlinux" files.  */
      fd = INTUSE(dwfl_standard_find_debuginfo) (&fakemod, NULL, NULL, 0,
						 *fname, basename (*fname), 0,
						 &fakemod.debug.name);
      if (fd < 0 && try_debug)
	/* Next, let the call use the default of basename + ".debug",
	   to look for "vmlinux.debug" files.  */
	fd = INTUSE(dwfl_standard_find_debuginfo) (&fakemod, NULL, NULL, 0,
						   *fname, NULL, 0,
						   &fakemod.debug.name);
      if (fakemod.debug.name != NULL)
	{
	  free (*fname);
	  *fname = fakemod.debug.name;
	}
    }
Example #23
0
void
getsb(struct fs *fs, char *file)
{

	fi = open64(file, O_RDWR);
	if (fi < 0) {
		fprintf(stderr, "Cannot open ");
		perror(file);
		exit(31+3);
	}
	if (bread((diskaddr_t)SBLOCK, (char *)fs, SBSIZE)) {
		fprintf(stderr, "Bad super block ");
		perror(file);
		exit(31+4);
	}
	if ((fs->fs_magic != FS_MAGIC) && (fs->fs_magic != MTB_UFS_MAGIC)) {
		fprintf(stderr, "%s: bad magic number\n", file);
		exit(31+5);
	}
	if (fs->fs_magic == FS_MAGIC &&
	    (fs->fs_version != UFS_EFISTYLE4NONEFI_VERSION_2 &&
	    fs->fs_version != UFS_VERSION_MIN)) {
		fprintf(stderr, "%s: unrecognized ufs version: %d\n", file,
		    fs->fs_version);
		exit(31+5);
	}
	if (fs->fs_magic == MTB_UFS_MAGIC &&
	    (fs->fs_version > MTB_UFS_VERSION_1 ||
	    fs->fs_version < MTB_UFS_VERSION_MIN)) {
		fprintf(stderr, "%s: unrecognized ufs version: %d\n", file,
		    fs->fs_version);
		exit(31+5);
	}
}
Example #24
0
/* Read at most size bytes from the memory of the given thread using the /proc/.../mem entry starting at the given
 * address.  Write results to out. Out must be large enough to hold size bytes. Return bytes written (which is size
 * or less). */
size_t procfs_mem_read(thread_t * thread, address_t offset, size_t size, void * out) {

    const char * path = procfs_thread_get_path(thread, "mem");
    int fd = -1;
    ssize_t count = 0;
    
    if ((fd = open64(path, O_RDONLY)) == -1) {
        error("Error opening %s.", path);
        goto out;
    }
    
    if (lseek64(fd, (off64_t) offset, SEEK_SET) == -1) {
        error("Error seeking through %s.", path);
        goto out;
    }
    
    count = read(fd, out, size);
    
    if (count != (ssize_t) size)
        error("Error reading %zu bytes from %s at %lx: %s", size, path, offset, strerror(errno));

out:
    if (fd >= 0)
        close(fd);
    if (count >= 0)
        return (size_t) count;
    else
        return 0;
}
Example #25
0
int
main(int argc, char *argv[])
{
    int fd;
    off64_t off;

    if (argc != 3 || strcmp(argv[1], "--help") == 0) {
        fprintf(stderr, "Usage: %s pathname offset\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    fd = open64(argv[1], O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
    if (fd == -1) {
        perror("open64");
        exit(EXIT_FAILURE);
    }

    off = atoll(argv[2]);
    if (lseek64(fd, off, SEEK_SET) == -1) {
        perror("lseek64");
        exit(EXIT_FAILURE);
    }

    if (write(fd, "test", 4) == -1) {
        perror("write");
        exit(EXIT_FAILURE);
    }

    exit(EXIT_SUCCESS);
}
Example #26
0
int
_zexec_init_template(void)
{
	int fd;
	int err = 0;

	fd = open64(CTFS_ROOT "/process/template", O_RDWR);
	if (fd == -1) {
		return (-1);
	}

	/*
	 * zlogin doesn't do anything with the contract.
	 * Deliver no events, don't inherit, and allow it to be orphaned.
	 */
	err |= ct_tmpl_set_critical(fd, 0);
	err |= ct_tmpl_set_informative(fd, 0);
	err |= ct_pr_tmpl_set_fatal(fd, CT_PR_EV_HWERR);
	err |= ct_pr_tmpl_set_param(fd, CT_PR_PGRPONLY | CT_PR_REGENT);
	if (err || ct_tmpl_activate(fd)) {
		(void) close(fd);
		return (-1);
	}

	return (fd);
}
Example #27
0
int btrfs_test(char *devname)
{
    struct btrfs_super_block sb;
    int fd;
    
    if ((fd=open64(devname, O_RDONLY|O_LARGEFILE))<0)
        return false;
    
    if (lseek(fd, BTRFS_SUPER_INFO_OFFSET, SEEK_SET)!=BTRFS_SUPER_INFO_OFFSET)
    {   close(fd);
        return false;
    }
    
    if (read(fd, &sb, sizeof(sb))!=sizeof(sb))
    {   close(fd);
        return false;
    }
    
    if (strncmp((char*)&sb.magic, BTRFS_MAGIC, sizeof(sb.magic))!=0)
    {   close(fd);
        return false;
    }
    
    close(fd);
    return true;
}
Example #28
0
static void
putdiscq(uid_t uid)
{
	struct fsquot *fsqp;

	for (fsqp = fsqlist; fsqp; fsqp = fsqp->fsq_next) {
		if (quotactl(Q_SETQLIM, fsqp->fsq_dev, uid,
		    (caddr_t)&fsqp->fsq_dqb) != 0) {
			int fd;

			if ((fd = open64(fsqp->fsq_qfile, O_RDWR)) < 0) {
				(void) fprintf(stderr, "edquota: ");
				perror(fsqp->fsq_qfile);
				continue;
			}
			(void) llseek(fd, (offset_t)dqoff(uid), L_SET);
			if (write(fd, (char *)&fsqp->fsq_dqb,
			    sizeof (struct dqblk)) != sizeof (struct dqblk)) {
				(void) fprintf(stderr, "edquota: ");
				perror(fsqp->fsq_qfile);
			}
			(void) close(fd);
		}
	}
}
/* Open libelf FILE->fd and compute the load base of ELF as loaded in MOD.
   When we return success, FILE->elf and FILE->bias are set up.  */
static inline Dwfl_Error
open_elf (Dwfl_Module *mod, struct dwfl_file *file)
{
  if (file->elf == NULL)
    {
      /* If there was a pre-primed file name left that the callback left
	 behind, try to open that file name.  */
      if (file->fd < 0 && file->name != NULL)
	file->fd = TEMP_FAILURE_RETRY (open64 (file->name, O_RDONLY));

      if (file->fd < 0)
	return CBFAIL;

      file->elf = elf_begin (file->fd, ELF_C_READ_MMAP_PRIVATE, NULL);
    }

  if (unlikely (elf_kind (file->elf) != ELF_K_ELF))
    {
      close (file->fd);
      file->fd = -1;
      return DWFL_E_BADELF;
    }

  GElf_Ehdr ehdr_mem, *ehdr = gelf_getehdr (file->elf, &ehdr_mem);
  if (ehdr == NULL)
    {
    elf_error:
      close (file->fd);
      file->fd = -1;
      return DWFL_E (LIBELF, elf_errno ());
    }

  /* The addresses in an ET_EXEC file are absolute.  The lowest p_vaddr of
     the main file can differ from that of the debug file due to prelink.
     But that doesn't not change addresses that symbols, debuginfo, or
     sh_addr of any program sections refer to.  */
  file->bias = 0;
  if (mod->e_type != ET_EXEC)
    for (uint_fast16_t i = 0; i < ehdr->e_phnum; ++i)
      {
	GElf_Phdr ph_mem;
	GElf_Phdr *ph = gelf_getphdr (file->elf, i, &ph_mem);
	if (ph == NULL)
	  goto elf_error;
	if (ph->p_type == PT_LOAD)
	  {
	    file->bias = ((mod->low_addr & -ph->p_align)
			  - (ph->p_vaddr & -ph->p_align));
	    break;
	  }
      }

  mod->e_type = ehdr->e_type;

  /* Relocatable Linux kernels are ET_EXEC but act like ET_DYN.  */
  if (mod->e_type == ET_EXEC && file->bias != 0)
    mod->e_type = ET_DYN;

  return DWFL_E_NOERROR;
}
Example #30
0
int main(void)
{
   fopen("", "r");
   fopen64("", "r");
   freopen("", "r", NULL);
   freopen64("", "r", NULL);
   open("", O_RDONLY);
   open64("", O_RDONLY);
   creat("", S_IRWXU);
   creat64("", S_IRWXU);
   
   unlink("");
   rename("", "");
   
#ifdef AT_FUNCTIONS

   unlinkat(0, "", 0);
   renameat(0, "", 0, "");
   openat(0, "", 0);
   openat64(0, "", 0);

#endif
     
   return 0;
}