static int shift_fd(int lvl, const struct tm* tm) { SHIFT_FD_LOCK(); if ( unlikely((fds_info[lvl].opfd < 0) && (open_fd(lvl, tm) < 0)) ) { SHIFT_FD_UNLOCK(); return -1; } off_t length = lseek(fds_info[lvl].opfd, 0, SEEK_END); if (likely((length < log_size) && (fds_info[lvl].day == tm->tm_yday))) { SHIFT_FD_UNLOCK(); return 0; } close(fds_info[lvl].opfd); if (max_log_files) { // if logfile recycle is used fds_info[lvl].seq = (fds_info[lvl].seq + 1) % max_log_files; } else { // if logfile recycle is not used if (fds_info[lvl].day != tm->tm_yday) { fds_info[lvl].seq = 0; } else { fds_info[lvl].seq = (fds_info[lvl].seq + 1) % MAX_LOG_CNT; } } int ret = open_fd(lvl, tm); SHIFT_FD_UNLOCK(); return ret; }
static int do_pipe(register int *fd) { register struct inode *inode; struct file *f; int error = -ENOMEM; if(!(inode = new_inode(NULL, S_IFIFO | S_IRUSR | S_IWUSR))) /* Create inode */ goto no_inodes; /* read file */ if((error = open_fd(O_RDONLY, inode)) < 0) goto no_files; *fd = error; /* write file */ if((error = open_fd(O_WRONLY, inode)) < 0) { f = current->files.fd[*fd]; current->files.fd[*fd] = NULL; close_filp(inode, f); no_files: iput(inode); no_inodes: return error; } (inode->i_count)++; /* Increase inode usage count */ fd[1] = error; return 0; }
static int do_pipe(register int *fd) { register struct inode *inode; int error = -ENOMEM; if (!(inode = new_inode(NULL, S_IFIFO | S_IRUSR | S_IWUSR))) /* Create inode */ goto no_inodes; /* read file */ if ((error = open_fd(O_RDONLY, inode)) < 0) { iput(inode); goto no_inodes; } *fd = error; /* write file */ if ((error = open_fd(O_WRONLY, inode)) < 0) { sys_close(*fd); no_inodes: return error; } (inode->i_count)++; /* Increase inode usage count */ fd[1] = error; return 0; }
int CoolVideoPassthrough(int enable) { int fd; int ret = 0; fd = open_fd(); if (fd >0) { int passthru = 0; ioctl( fd, 0x77, &passthru ); if ((enable == TRUE) && (passthru <= 0)) { ret = 1; ioctl( fd, 1, 2); // TODO: enable audio passthrough too... } else if ((enable == FALSE) && (passthru > 0)) { ret = 1; ioctl( fd, 1, 3); // TODO: disable audio passthrough too... } } return ret; }
static int open_copy_close(int append) { int in; int out; unsigned long ss; unsigned long bytes_in; unsigned long bytes_out; int result; ss = startpos; startpos = 0; if ((out = open_fd(req_param, append ? O_WRONLY | O_APPEND : store_exclusive ? O_WRONLY | O_CREAT | O_EXCL : ss ? O_WRONLY : O_WRONLY | O_CREAT | O_TRUNC, 0666)) == -1) return respond_syserr(550, "Could not open output file"); if (ss && lseek(out, ss, SEEK_SET) != ss) { close(out); return respond(550, 1, "Could not seek to start position in output file."); } if ((in = make_in_connection()) == -1) { close(out); if (store_exclusive) unlink(req_param); return 1; } result = copy_xlate_close(in, out, timeout * 1000, binary_flag ? 0 : xlate_ascii, &bytes_in, &bytes_out); return respond_xferresult(result, bytes_in, 0); }
static int add_log_action(struct logfile *log, int type, char *val) { int fd; fd = open_fd(type, val); if (fd == -1) debug(1, "open_fd() failed"); struct logaction *t, *this; t = realloc(log->actions, sizeof (struct logaction) * (log->numactions + 1)); if (!t) { close(fd); debug(1, "realloc(): %s", strerror(errno)); return(0); } log->actions = t; this = &(t[log->numactions]); this->type = type; this->target = malloc(strlen(val) + 1); strcpy(this->target, val); this->fd = fd; this->outbuf = NULL; this->outbuflen = 0; log->numactions++; return(1); }
/** * Set polling time * @param time * unit is 50ms, for example, time = 1, represent 50ms */ void CoolVideoSetPollingTime(int time) { int fd = -1; fd = open_fd(); ioctl(fd, 0xbb, &time); }
/** * enable/disable polling * @param enable * TRUE: enable poll, FALSE : disable poll */ void CoolVideoSetPolling(int enable) { int fd = -1; fd = open_fd(); (enable) ? ioctl(fd, 0xaa, NULL) : ioctl(fd, 0x99, NULL); }
/** * Check to see if passthru relay is engaged. * * @return * <= 0 disabled, > 0 enabled */ int CoolVideoIsPassthroughRelayEngaged(void) { int fd; int passthru = 0; fd = open_fd(); if (fd >0) ioctl( fd, 0x77, &passthru ); return passthru; }
static struct security_descriptor *file_get_parent_sd( struct fd *root, const char *child_name, int child_len, int is_dir ) { struct security_descriptor *parent_sd, *sd = NULL; mode_t parent_mode = 0555; char *p, *parent_name; struct fd *parent_fd; struct stat st; int unix_fd; if (!(parent_name = mem_alloc( child_len + 1 ))) return NULL; memcpy( parent_name, child_name, child_len ); parent_name[child_len] = 0; /* skip trailing slashes */ p = parent_name + strlen( parent_name ) - 1; while (p > parent_name && *p == '/') p--; /* remove last path component */ if (p == parent_name && *p == '/') { free(parent_name); return NULL; } while (p > parent_name && *p != '/') p--; while (p > parent_name && *p == '/') p--; p[1] = 0; parent_fd = open_fd( root, parent_name, O_NONBLOCK | O_LARGEFILE, &parent_mode, READ_CONTROL|ACCESS_SYSTEM_SECURITY, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN_FOR_BACKUP_INTENT ); free( parent_name ); if (parent_fd) { unix_fd = get_unix_fd( parent_fd ); if (unix_fd != -1) { parent_sd = get_xattr_sd( unix_fd ); if (!parent_sd && fstat( unix_fd, &st ) != -1) parent_sd = get_xattr_acls( unix_fd, security_unix_uid_to_sid( st.st_uid ), token_get_primary_group( current->process->token ) ); if (parent_sd) { sd = inherit_sd( parent_sd, is_dir ); free( parent_sd ); } } release_object( parent_fd ); } return sd; }
static struct object *create_file( const char *nameptr, data_size_t len, unsigned int access, unsigned int sharing, int create, unsigned int options, unsigned int attrs ) { struct object *obj = NULL; struct fd *fd; int flags; char *name; mode_t mode; if (!(name = mem_alloc( len + 1 ))) return NULL; memcpy( name, nameptr, len ); name[len] = 0; switch(create) { case FILE_CREATE: flags = O_CREAT | O_EXCL; break; case FILE_OVERWRITE_IF: /* FIXME: the difference is whether we trash existing attr or not */ case FILE_SUPERSEDE: flags = O_CREAT | O_TRUNC; break; case FILE_OPEN: flags = 0; break; case FILE_OPEN_IF: flags = O_CREAT; break; case FILE_OVERWRITE: flags = O_TRUNC; break; default: set_error( STATUS_INVALID_PARAMETER ); goto done; } mode = (attrs & FILE_ATTRIBUTE_READONLY) ? 0444 : 0666; if (len >= 4 && (!strcasecmp( name + len - 4, ".exe" ) || !strcasecmp( name + len - 4, ".com" ))) mode |= 0111; access = generic_file_map_access( access ); /* FIXME: should set error to STATUS_OBJECT_NAME_COLLISION if file existed before */ fd = open_fd( name, flags | O_NONBLOCK | O_LARGEFILE, &mode, access, sharing, options ); if (!fd) goto done; if (S_ISDIR(mode)) obj = create_dir_obj( fd ); else if (S_ISCHR(mode) && is_serial_fd( fd )) obj = create_serial( fd, options ); else obj = create_file_obj( fd, access, options ); release_object( fd ); done: free( name ); return obj; }
static struct object *device_open_file( struct object *obj, unsigned int access, unsigned int sharing, unsigned int options ) { struct device *device = (struct device *)obj; struct device_file *file; if (!(file = alloc_object( &device_file_ops ))) return NULL; file->device = (struct device *)grab_object( device ); file->user_ptr = 0; list_init( &file->requests ); list_add_tail( &device->files, &file->entry ); if (device->unix_path) { mode_t mode = 0666; access = file->obj.ops->map_access( &file->obj, access ); file->fd = open_fd( NULL, device->unix_path, O_NONBLOCK | O_LARGEFILE, &mode, access, sharing, options ); if (file->fd) set_fd_user( file->fd, &device_file_fd_ops, &file->obj ); } else file->fd = alloc_pseudo_fd( &device_file_fd_ops, &file->obj, 0 ); if (!file->fd) { release_object( file ); return NULL; } if (device->manager) { struct irp_call *irp; irp_params_t params; memset( ¶ms, 0, sizeof(params) ); params.create.major = IRP_MJ_CREATE; params.create.access = access; params.create.sharing = sharing; params.create.options = options; params.create.device = file->device->user_ptr; if ((irp = create_irp( file, ¶ms, NULL, 0, 0 ))) { add_irp_to_queue( file, irp, NULL ); release_object( irp ); } } return &file->obj; }
/** enable composite video source, otherwise S-video. * * * */ void CoolVideoComposite(int enable) { int fd; fd = open_fd(); if (fd >0) { if (enable == TRUE) { ioctl( fd, 1, 0); } else if (enable == FALSE) { ioctl( fd, 1, 1); } } }
void get_file(t_ftp *ftp, char **args) { int fd; if (args[1] == NULL) { send_message("Get command needs an argument\n", ftp); printf("Get command needs an argument\n"); } else if ((fd = open_fd(ftp, args[1])) != -1) { send_message("...", ftp); printf("Transfer starting...\n"); send_file(ftp, fd); } else { send_message("Fail\n", ftp); printf("Transfer failed\n"); } }
int createPipe(int size, int flags) { Spipe *p = newSpipeData(); if(!p) return -1; int pid = getpid(); enterProcessCriticalCode(pid); int fd = open_fd(); if(fd < 0) return fd; idStream *is = getStreamData(getpid(), fd); createMutex(&p->locker); p->memory = malloc(size+4); p->seek = 0; p->offset = 0; p->size = size; p->ready_read_wid = createAdvWaitCond("waiter", 0); p->ready_write_wid = createAdvWaitCond("waiter", 0); p->fully_flushed_wid = createAdvWaitCond("waiter", 0); p->fully_empty_wid = createAdvWaitCond("waiter", 0); p->flags = flags; is->fd = p->id; is->type = PIPE_STREAM; is->mode = O_RDWR; is->pid = pid; is->read = __pread; is->write = __pwrite; is->flush = __pflush; is->lseek = __plseek; is->close = __pclose; wakeOneWaitCond(p->ready_write_wid); leaveProcessCriticalCode(pid); return fd; }
/** * Get video input mode from tvp5150 */ int CoolVideoGetInputMode(void) { int mode = 0; int fd = -1; fd = open_fd(); ioctl( fd, 0x8C, &mode ); DBGLOG("get input mode : %d\n", mode); switch (mode) { case 0x81: // NTSC mode = 0; break; case 0x83: // PAL B,G,H,I,N mode = 1; break; case 0x85: // PAL M mode = 1; break; case 0x87: // PAL N mode = 1; break; case 0x89: // NTSC 4.43 mode = 0; break; case 0x8b: // SECAM mode = 1; break; default: mode = 0; break; } return mode; }
static struct object *create_file( struct fd *root, const char *nameptr, data_size_t len, unsigned int access, unsigned int sharing, int create, unsigned int options, unsigned int attrs, const struct security_descriptor *sd ) { struct object *obj = NULL; struct fd *fd; int flags; char *name; mode_t mode; if (!len || ((nameptr[0] == '/') ^ !root)) { set_error( STATUS_OBJECT_PATH_SYNTAX_BAD ); return NULL; } if (!(name = mem_alloc( len + 1 ))) return NULL; memcpy( name, nameptr, len ); name[len] = 0; switch(create) { case FILE_CREATE: flags = O_CREAT | O_EXCL; break; case FILE_OVERWRITE_IF: /* FIXME: the difference is whether we trash existing attr or not */ access |= FILE_WRITE_ATTRIBUTES; case FILE_SUPERSEDE: flags = O_CREAT | O_TRUNC; break; case FILE_OPEN: flags = 0; break; case FILE_OPEN_IF: flags = O_CREAT; break; case FILE_OVERWRITE: flags = O_TRUNC; access |= FILE_WRITE_ATTRIBUTES; break; default: set_error( STATUS_INVALID_PARAMETER ); goto done; } if (sd) { const SID *owner = sd_get_owner( sd ); if (!owner) owner = token_get_user( current->process->token ); mode = sd_to_mode( sd, owner ); } else if (options & FILE_DIRECTORY_FILE) mode = (attrs & FILE_ATTRIBUTE_READONLY) ? 0555 : 0777; else mode = (attrs & FILE_ATTRIBUTE_READONLY) ? 0444 : 0666; if (len >= 4 && (!strcasecmp( name + len - 4, ".exe" ) || !strcasecmp( name + len - 4, ".com" ))) { if (mode & S_IRUSR) mode |= S_IXUSR; if (mode & S_IRGRP) mode |= S_IXGRP; if (mode & S_IROTH) mode |= S_IXOTH; } access = generic_file_map_access( access ); /* FIXME: should set error to STATUS_OBJECT_NAME_COLLISION if file existed before */ fd = open_fd( root, name, flags | O_NONBLOCK | O_LARGEFILE, &mode, access, sharing, options ); if (!fd) goto done; if (S_ISDIR(mode)) obj = create_dir_obj( fd, access, mode ); else if (S_ISCHR(mode) && is_serial_fd( fd )) obj = create_serial( fd ); else obj = create_file_obj( fd, access, mode ); release_object( fd ); done: free( name ); return obj; }
/** * The dbpf open cache is used primarily to manage open * file descriptors to bstream files on IO servers. PVFS * currently uses a lazy style of creating the actual datafiles for * bstreams. Only on the first write to a bstream is the file * actually created (opened with O_CREAT). This means that if a * read of a bstream that hasn't been written should somehow occur, * an ENOENT error will be returned immediately, instead of allowing * a read to EOF (of a zero-byte file). For us, this is ok, since * the client gets the size of the bstream in the getattr before doing * any IO. All that being said, the open_cache_get call needs to * behave differently based on the desired operation: reads on * files that don't exist should return ENOENT, but writes on files * that don't exist should create and open the file. */ int dbpf_open_cache_get( TROVE_coll_id coll_id, TROVE_handle handle, enum open_cache_open_type type, struct open_cache_ref* out_ref) { struct qlist_head *tmp_link; struct open_cache_entry* tmp_entry = NULL; int found = 0; int ret = 0; gossip_debug(GOSSIP_DBPF_OPEN_CACHE_DEBUG, "dbpf_open_cache_get: called\n"); gen_mutex_lock(&cache_mutex); /* check already opened objects first, reuse ref if possible */ tmp_entry = dbpf_open_cache_find_entry( &used_list, "used list", coll_id, handle); if(!tmp_entry) { tmp_entry = dbpf_open_cache_find_entry( &unused_list, "unused list", coll_id, handle); } out_ref->fd = -1; if (tmp_entry) { if (tmp_entry->fd < 0) { ret = open_fd(&(tmp_entry->fd), coll_id, handle, type); if (ret < 0) { gen_mutex_unlock(&cache_mutex); return ret; } tmp_entry->type = type; } out_ref->fd = tmp_entry->fd; out_ref->type = type; out_ref->internal = tmp_entry; tmp_entry->ref_ct++; /* remove the entry and place it at the used head (assuming it * will be referenced again soon) */ gossip_debug(GOSSIP_DBPF_OPEN_CACHE_DEBUG, "dbpf_open_cache_get: " "moving to (or reordering in) used list.\n"); qlist_del(&tmp_entry->queue_link); qlist_add(&tmp_entry->queue_link, &used_list); gen_mutex_unlock(&cache_mutex); assert(out_ref->fd > 0); return 0; } /* if we fall through to this point, then the object was not found * in the cache. In order of priority we will now try: free list, * unused_list, and then bypass cache */ if (!qlist_empty(&free_list)) { tmp_link = free_list.next; tmp_entry = qlist_entry(tmp_link, struct open_cache_entry, queue_link); qlist_del(&tmp_entry->queue_link); found = 1; gossip_debug(GOSSIP_DBPF_OPEN_CACHE_DEBUG, "dbpf_open_cache_get: resetting entry from free list.\n"); }
/* * Body of the worker thread to log the zfd's stdout and stderr to a log file * and to perform interactive IO to the stdin, stdout and stderr zfd's. * * The stdin, stdout and stderr are from the perspective of the process inside * the zone, so the zoneadmd view is opposite (i.e. we write to the stdin fd * and read from the stdout/stderr fds). */ static void srvr(void *modearg) { zlog_mode_t mode = (zlog_mode_t)modearg; int gzoutfd = -1; int stdinfd = -1; int stdoutfd = -1; sigset_t blockset; int gzerrfd = -1; int stderrfd = -1; if (!shutting_down) { open_logfile(); } /* * This thread should receive SIGHUP so that it can close the log * file, and reopen it, during log rotation. */ sigset(SIGHUP, hup_handler); (void) sigfillset(&blockset); (void) sigdelset(&blockset, SIGHUP); (void) thr_sigsetmask(SIG_BLOCK, &blockset, NULL); if (!shutting_down) { if (pipe(eventstream) != 0) { zerror(zlogp, B_TRUE, "failed to open logger control " "pipe"); return; } } while (!shutting_down) { if (init_server_sock(zlogp, &gzoutfd, "out") == -1) { zerror(zlogp, B_FALSE, "server setup: stdout socket init failed"); goto death; } if (init_server_sock(zlogp, &gzerrfd, "err") == -1) { zerror(zlogp, B_FALSE, "server setup: stderr socket init failed"); goto death; } if (mode == ZLOG_INTERACTIVE) { if ((stdinfd = open_fd(zlogp, 0, O_RDWR)) == -1) { goto death; } stdoutfd = stdinfd; } else { if ((stdinfd = open_fd(zlogp, 0, O_WRONLY)) == -1 || (stdoutfd = open_fd(zlogp, 1, O_RDONLY)) == -1 || (stderrfd = open_fd(zlogp, 2, O_RDONLY)) == -1) { goto death; } } do_zfd_io(gzoutfd, gzerrfd, stdinfd, stdoutfd, stderrfd); death: destroy_server_sock(gzoutfd, "out"); destroy_server_sock(gzerrfd, "err"); (void) close(stdinfd); if (mode != ZLOG_INTERACTIVE) { (void) close(stdoutfd); (void) close(stderrfd); } } (void) close(eventstream[0]); eventstream[0] = -1; (void) close(eventstream[1]); eventstream[1] = -1; (void) close(logfd); }