uint32_t sys_fcntl(struct registers_t* regs) { int fd = (int)REG_ARG1(regs); int cmd = (int)REG_ARG2(regs); int arg = (uint32_t)REG_ARG3(regs); return do_fcntl(fd, cmd, arg); }
int __libc_fcntl (int fd, int cmd, ...) { va_list ap; void *arg; va_start (ap, cmd); arg = va_arg (ap, void *); va_end (ap); if (SINGLE_THREAD_P || cmd != F_SETLKW) return do_fcntl (fd, cmd, arg); int oldtype = LIBC_CANCEL_ASYNC (); int result = do_fcntl (fd, cmd, arg); LIBC_CANCEL_RESET (oldtype); return result; }
int __fcntl_nocancel (int fd, int cmd, ...) { va_list ap; void *arg; va_start (ap, cmd); arg = va_arg (ap, void *); va_end (ap); return do_fcntl (fd, cmd, arg); }
SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd, unsigned long, arg) { void __user *argp = (void __user *)arg; struct fd f = fdget_raw(fd); struct flock64 flock; long err = -EBADF; if (!f.file) goto out; if (unlikely(f.file->f_mode & FMODE_PATH)) { if (!check_fcntl_cmd(cmd)) goto out1; } err = security_file_fcntl(f.file, cmd, arg); if (err) goto out1; switch (cmd) { case F_GETLK64: case F_OFD_GETLK: err = -EFAULT; if (copy_from_user(&flock, argp, sizeof(flock))) break; err = fcntl_getlk64(f.file, cmd, &flock); if (!err && copy_to_user(argp, &flock, sizeof(flock))) err = -EFAULT; break; case F_SETLK64: case F_SETLKW64: case F_OFD_SETLK: case F_OFD_SETLKW: err = -EFAULT; if (copy_from_user(&flock, argp, sizeof(flock))) break; err = fcntl_setlk64(fd, f.file, cmd, &flock); break; default: err = do_fcntl(fd, cmd, arg, f.file); break; } out1: fdput(f); out: return err; }
/* Perform file control operations on FD. */ int __fcntl (int fd, int cmd, ...) { va_list ap; void *arg; va_start (ap, cmd); arg = va_arg (ap, void *); va_end (ap); if (fd < 0) { __set_errno (EBADF); return -1; } return do_fcntl (fd, cmd, arg); }
int expressos_ipc_fcntl64(int helper_pid, int fd, int cmd, int arg0) { int ret; mm_segment_t fs_save; struct expressos_venus_proc *proc; struct file *file; if (!(proc = expressos_venus_find_proc(helper_pid))) return -EINVAL; if (!(file = expressos_venus_fget(proc, fd))) return -EBADF; fs_save = get_fs(); set_fs(get_ds()); ret = do_fcntl(-1, cmd, arg0, file); set_fs(fs_save); fput(file); return ret; }
SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd, unsigned long, arg) { struct fd f = fdget_raw(fd); long err = -EBADF; if (!f.file) goto out; if (unlikely(f.file->f_mode & FMODE_PATH)) { if (!check_fcntl_cmd(cmd)) goto out1; } err = security_file_fcntl(f.file, cmd, arg); if (err) goto out1; switch (cmd) { case F_GETLK64: case F_OFD_GETLK: err = fcntl_getlk64(f.file, cmd, (struct flock64 __user *) arg); break; case F_SETLK64: case F_SETLKW64: case F_OFD_SETLK: case F_OFD_SETLKW: err = fcntl_setlk64(fd, f.file, cmd, (struct flock64 __user *) arg); break; default: err = do_fcntl(fd, cmd, arg, f.file); break; } out1: fdput(f); out: return err; }
SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) { struct fd f = fdget_raw(fd); long err = -EBADF; if (!f.file) goto out; if (unlikely(f.file->f_mode & FMODE_PATH)) { if (!check_fcntl_cmd(cmd)) goto out1; } err = security_file_fcntl(f.file, cmd, arg); if (!err) err = do_fcntl(fd, cmd, arg, f.file); out1: fdput(f); out: return err; }
int main(int argc, char *argv[]) { unsigned int ip, ip_arr[4]; size_t len; struct timeval start, end; struct stat stat; if (argc < 4) { fprintf(stderr, "Usage: %s <output_file> <method> <IP>\n", argv[0]); exit(1); } if ((fdin = open("/dev/rs232_slave", O_RDONLY)) < 0) { perror("open device fail"); exit(1); } if(gettimeofday(&start, NULL) < 0) { perror("gettimeofday to start fail"); exit(1); } if ((fdout = open(argv[1], O_RDWR | O_TRUNC | O_CREAT, 0644)) < 0) { perror("open fail"); exit(1); } if (sscanf(argv[3], "%u.%u.%u.%u", &ip_arr[0], &ip_arr[1], &ip_arr[2], &ip_arr[3]) != 4) { fprintf(stderr, "invalid IP\n"); exit(1); } ENCODE_IP(ip, ip_arr); if (ioctl(fdin, IOCTL_OPENCONN, &ip) < 0) { perror("ioctl open connect fail"); exit(1); } len = strlen(argv[2]); if (strncmp("fcntl", argv[2], len) == 0) { do_fcntl(); } else if (strncmp("mmap", argv[2], len) == 0) { do_mmap(); } else { fprintf(stderr, "invalid method\n"); exit(1); } if (ioctl(fdin, IOCTL_CLOSECONN) < 0) { perror("ioctl close connect fail"); exit(1); } if (close(fdin) < 0) { perror("close"); exit(1); } if (fstat(fdout, &stat) < 0) { perror("fstat fail"); exit(1); } if (close(fdout) < 0) { perror("close"); exit(1); } if (gettimeofday(&end, NULL) < 0) { perror("gettimeofday to end fail"); exit(1); } if (end.tv_usec < start.tv_usec) { end.tv_sec -= 1; end.tv_usec += 1000000; } printf("Transmission time: %lf ms, File size: %lu bytes\n", ((end.tv_sec - start.tv_sec) * 1000 + ((double)(end.tv_usec - start.tv_usec) / 1000)), (size_t)(stat.st_size)); return 0; }
COMPAT_SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd, compat_ulong_t, arg) { struct fd f = fdget_raw(fd); struct flock flock; long err = -EBADF; if (!f.file) return err; if (unlikely(f.file->f_mode & FMODE_PATH)) { if (!check_fcntl_cmd(cmd)) goto out_put; } err = security_file_fcntl(f.file, cmd, arg); if (err) goto out_put; switch (cmd) { case F_GETLK: err = get_compat_flock(&flock, compat_ptr(arg)); if (err) break; err = fcntl_getlk(f.file, convert_fcntl_cmd(cmd), &flock); if (err) break; err = fixup_compat_flock(&flock); if (!err) err = put_compat_flock(&flock, compat_ptr(arg)); break; case F_GETLK64: case F_OFD_GETLK: err = get_compat_flock64(&flock, compat_ptr(arg)); if (err) break; err = fcntl_getlk(f.file, convert_fcntl_cmd(cmd), &flock); if (!err) err = put_compat_flock64(&flock, compat_ptr(arg)); break; case F_SETLK: case F_SETLKW: err = get_compat_flock(&flock, compat_ptr(arg)); if (err) break; err = fcntl_setlk(fd, f.file, convert_fcntl_cmd(cmd), &flock); break; case F_SETLK64: case F_SETLKW64: case F_OFD_SETLK: case F_OFD_SETLKW: err = get_compat_flock64(&flock, compat_ptr(arg)); if (err) break; err = fcntl_setlk(fd, f.file, convert_fcntl_cmd(cmd), &flock); break; default: err = do_fcntl(fd, cmd, arg, f.file); break; } out_put: fdput(f); return err; }