int sysfile_linux_fstat64(int fd, struct linux_stat64 __user * buf) { struct mm_struct *mm = pls_read(current)->mm; int ret; struct stat __local_stat, *kstat = &__local_stat; if ((ret = file_fstat(fd, kstat)) != 0) { return -1; } struct linux_stat64 *kls = kmalloc(sizeof(struct linux_stat64)); if (!kls) { return -1; } memset(kls, 0, sizeof(struct linux_stat64)); kls->st_ino = 1; /* ucore never check access permision */ kls->st_mode = kstat->st_mode | 0777; kls->st_nlink = kstat->st_nlinks; kls->st_blksize = 512; kls->st_blocks = kstat->st_blocks; kls->st_size = kstat->st_size; ret = 0; lock_mm(mm); { if (!copy_to_user(mm, buf, kls, sizeof(struct linux_stat64))) { ret = -1; } } unlock_mm(mm); kfree(kls); return ret; }
/* * Do an fstat on the file. */ int wtap_fstat(wtap *wth, ws_statb64 *statb, int *err) { if (file_fstat((wth->fh == NULL) ? wth->random_fh : wth->fh, statb, err) == -1) return -1; return 0; }
/* * Return the size of the file, as reported by the OS. * (gint64, in case that's 64 bits.) */ gint64 wtap_file_size(wtap *wth, int *err) { ws_statb64 statb; if (file_fstat((wth->fh == NULL) ? wth->random_fh : wth->fh, &statb, err) == -1) return -1; return statb.st_size; }
int fstat(int fd, FAR struct stat *buf) { FAR struct file *filep; int ret; /* Did we get a valid file descriptor? */ if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS) { #if CONFIG_NSOCKET_DESCRIPTORS > 0 /* Let the networking logic handle the fstat() */ ret = net_fstat(fd, buf); if (ret < 0) { goto errout; } return OK; #else /* No networking... it is just a bad descriptor */ ret = -EBADF; goto errout; #endif } /* The descriptor is in a valid range for a file descriptor... do the * fstat. First, get the file structure. Note that on failure, * fs_getfilep() will set the errno variable. */ ret = fs_getfilep(fd, &filep); if (ret < 0) { goto errout; } /* Perform the fstat operation */ ret = file_fstat(filep, buf); /* Check if the fstat operation was successful */ if (ret >= 0) { /* Successfully fstat'ed the file */ return OK; } errout: set_errno(-ret); return ERROR; }
/* sysfile_fstat - stat file */ int sysfile_fstat(int fd, struct stat *__stat) { struct mm_struct *mm = current->mm; int ret; struct stat __local_stat, *stat = &__local_stat; if ((ret = file_fstat(fd, stat)) != 0) { return ret; } lock_mm(mm); { if (!copy_to_user(mm, __stat, stat, sizeof(struct stat))) { ret = -E_INVAL; } } unlock_mm(mm); return ret; }