static Eina_Bool _eina_xattr_value_ls_fd_iterator_next(Eina_Xattr_Iterator *it, void **data) { char *tmp; if (it->offset >= it->length) return EINA_FALSE; *data = it->attr; it->attr->name = it->xattr + it->offset; it->offset += strlen(it->attr->name) + 1; it->attr->length = fgetxattr(it->fd, it->attr->name, NULL, 0); if (it->attr->length) { tmp = realloc((void*) it->attr->value, it->attr->length + 1); if (!tmp) { free((void*) it->attr->value); it->attr->value = NULL; it->attr->length = 0; } else { it->attr->value = tmp; it->attr->length = fgetxattr(it->fd, it->attr->name, (void *) it->attr->value, it->attr->length); tmp[it->attr->length] = '\0'; } } return EINA_TRUE; }
/** * File's stored metadata */ xa_t getstoredxa(FILE *f) { int fd=fileno(f); xa_t xa; xa.s=0; xa.ns=0; /* * Initialize to zero-length string - if fgetxattr fails this is what we get */ xa.sha256[0]=0; fgetxattr(fd, "user.shatag.sha256", xa.sha256, sizeof(xa.sha256)); xa.sha256[HASHLEN*2]=0; /* * Example: * 1335974989.123456789 * 10 . 9 => len=20 */ char ts[100]; /* * Initialize to zero-length string - if fgetxattr fails this is what we get */ ts[0]=0; fgetxattr(fd, "user.shatag.ts", ts, sizeof(ts)); /* * If sscanf fails (because ts is zero-length) variables stay zero */ sscanf(ts,"%llu.%lu",&xa.s,&xa.ns); return xa; }
/* 23.4.15 */ acl_t acl_get_fd(int fd) { const size_t size_guess = acl_ea_size(16); char *ext_acl_p = alloca(size_guess); int retval; if (!ext_acl_p) return NULL; retval = fgetxattr(fd, ACL_EA_ACCESS, ext_acl_p, size_guess); if (retval == -1 && errno == ERANGE) { retval = fgetxattr(fd, ACL_EA_ACCESS, NULL, 0); if (retval > 0) { ext_acl_p = alloca(retval); if (!ext_acl_p) return NULL; retval = fgetxattr(fd, ACL_EA_ACCESS, ext_acl_p,retval); } } if (retval > 0) { acl_t acl = __acl_from_xattr(ext_acl_p, retval); return acl; } else if (retval == 0 || errno == ENOATTR || errno == ENODATA) { struct stat st; if (fstat(fd, &st) == 0) return acl_from_mode(st.st_mode); else return NULL; } else return NULL; }
ssize_t ceph_os_fgetxattr(int fd, const char *name, void *value, size_t size) { ssize_t error = -1; #if defined(__FreeBSD__) if (value == NULL || size == 0) { error = extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, name, value, size); } else { error = extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, name, NULL, 0); if (error > 0) { if (error > size) { errno = ERANGE; error = -1; } else { error = extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, name, value, size); } } } #elif defined(__linux__) error = fgetxattr(fd, name, value, size); #elif defined(DARWIN) error = fgetxattr(fd, name, value, size, 0, 0 /* no options */); /* ENOATTR and ENODATA have different values */ if (error < 0 && errno == ENOATTR) errno = ENODATA; #endif return (error); }
static int local_fstat(FsContext *fs_ctx, int fd, struct stat *stbuf) { int err; err = fstat(fd, stbuf); if (err) { return err; } if (fs_ctx->fs_sm == SM_MAPPED) { /* Actual credentials are part of extended attrs */ uid_t tmp_uid; gid_t tmp_gid; mode_t tmp_mode; dev_t tmp_dev; if (fgetxattr(fd, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0) { stbuf->st_uid = tmp_uid; } if (fgetxattr(fd, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0) { stbuf->st_gid = tmp_gid; } if (fgetxattr(fd, "user.virtfs.mode", &tmp_mode, sizeof(mode_t)) > 0) { stbuf->st_mode = tmp_mode; } if (fgetxattr(fd, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0) { stbuf->st_rdev = tmp_dev; } } return err; }
ssize_t ceph_os_fgetxattr(int fd, const char *name, void *value, size_t size) { ssize_t error = -1; #if defined(__FreeBSD__) if (value == NULL || size == 0) { error = extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, name, value, size); } else { error = extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, name, NULL, 0); if (error > 0) { if (error > size) { errno = ERANGE; error = -1; } else { error = extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, name, value, size); } } } #elif defined(__linux__) error = fgetxattr(fd, name, value, size); #elif defined(DARWIN) error = fgetxattr(fd, name, value, size, 0); #endif return (error); }
static INT64_T chirp_fs_local_fgetxattr(int fd, const char *name, void *data, size_t size) { #ifdef CCTOOLS_OPSYS_DARWIN return fgetxattr(fd, name, data, size, 0, 0); #else return fgetxattr(fd, name, data, size); #endif }
ssize_t rep_fgetxattr (int filedes, const char *name, void *value, size_t size) { #if defined(HAVE_FGETXATTR) #ifndef XATTR_ADDITIONAL_OPTIONS return fgetxattr(filedes, name, value, size); #else /* So that we do not recursivly call this function */ #undef fgetxattr int options = 0; return fgetxattr(filedes, name, value, size, 0, options); #endif #elif defined(HAVE_FGETEA) return fgetea(filedes, name, value, size); #elif defined(HAVE_EXTATTR_GET_FD) char *s; ssize_t retval; int attrnamespace = (strncmp(name, "system", 6) == 0) ? EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER; const char *attrname = ((s=strchr(name, '.')) == NULL) ? name : s + 1; if((retval=extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0)) >= 0) { if (size == 0) { return retval; } else if (retval > size) { errno = ERANGE; return -1; } if((retval=extattr_get_fd(filedes, attrnamespace, attrname, value, size)) >= 0) return retval; } return -1; #elif defined(HAVE_ATTR_GETF) int retval, flags = 0; int valuelength = (int)size; char *attrname = strchr(name,'.') + 1; if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT; retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags); if (size == 0 && retval == -1 && errno == E2BIG) { return valuelength; } return retval ? retval : valuelength; #elif defined(HAVE_ATTROPEN) ssize_t ret = -1; int attrfd = solaris_openat(filedes, name, O_RDONLY|O_XATTR, 0); if (attrfd >= 0) { ret = solaris_read_xattr(attrfd, value, size); close(attrfd); } return ret; #else errno = ENOSYS; return -1; #endif }
Boolean XAAttributeLoadFileDescriptor(XAAttributeRef attributeRef, int fd, char *key) { Boolean bRet = 0x00; UInt8 *bytes = 0x00; size_t size = 0x00; UInt32 position = 0x00; int options = 0x00; size = fgetxattr(fd, key, (void *)bytes, size, position, options); if(size > 0x00) { bytes = calloc(size, sizeof(*bytes)); size = fgetxattr(fd, key, (void *)bytes, size, position, options); if(size > 0x00) { CFAllocatorRef alloc = CFGetAllocator(attributeRef); CFStringRef sTemp = 0x00; CFStringRef dTemp = 0x00; CFDataRef dNice = 0x00; dNice = CFDataCreateWithBytesNoCopy(alloc, bytes, size, kCFAllocatorMalloc); sTemp = CFStringCreateWithCString(alloc, key, kCFStringEncodingUTF8); if(XAPrintableData(bytes, size)) { dTemp = CFStringCreateWithBytes(alloc, bytes, size, kCFStringEncodingUTF8, 0x00); }else { dTemp = CFCopyDescription(dNice); } XAAttributeSetData(attributeRef, dNice); CFRelease(dNice); XAAttributeSetName(attributeRef, sTemp); CFRelease(sTemp); XAAttributeSetString(attributeRef, dTemp); CFRelease(dTemp); bRet = 0x01; } } return(bRet); }
static INT64_T chirp_fs_local_fgetxattr(int fd, const char *name, void *data, size_t size) { PREAMBLE("fgetxattr(%d, `%s', %p, %zu)", fd, name, data, size); SETUP_FILE #ifdef CCTOOLS_OPSYS_DARWIN rc = fgetxattr(lfd, name, data, size, 0, 0); #else rc = fgetxattr(lfd, name, data, size); #endif PROLOGUE }
ssize_t sys_fgetxattr (int filedes, const char *uname, void *value, size_t size) { const char *name = prefix(uname); #if defined(HAVE_FGETXATTR) #ifndef XATTR_ADD_OPT return fgetxattr(filedes, name, value, size); #else int options = 0; return fgetxattr(filedes, name, value, size, 0, options); #endif #elif defined(HAVE_FGETEA) return fgetea(filedes, name, value, size); #elif defined(HAVE_EXTATTR_GET_FD) char *s; ssize_t retval; int attrnamespace = (strncmp(name, "system", 6) == 0) ? EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER; const char *attrname = ((s=strchr(name, '.')) == NULL) ? name : s + 1; if((retval=extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0)) >= 0) { if(retval > size) { errno = ERANGE; return -1; } if((retval=extattr_get_fd(filedes, attrnamespace, attrname, value, size)) >= 0) return retval; } LOG(log_debug, logtype_default, "sys_fgetxattr: extattr_get_fd(): %s", strerror(errno)); return -1; #elif defined(HAVE_ATTR_GETF) int retval, flags = 0; int valuelength = (int)size; char *attrname = strchr(name,'.') + 1; if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT; retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags); return retval ? retval : valuelength; #elif defined(HAVE_ATTROPEN) ssize_t ret = -1; int attrfd = solaris_openat(filedes, name, O_RDONLY|O_XATTR, 0); if (attrfd >= 0) { ret = solaris_read_xattr(attrfd, value, size); close(attrfd); } return ret; #else errno = ENOSYS; return -1; #endif }
char *xattrkv_get(int db, char *key) { size_t size; size = (size_t) fgetxattr(db, key, NULL, 0, 0, 0); char *value = malloc(size + 1); ssize_t ok = fgetxattr(db, key, value, size, 0, 0); if (ok == -1) { free(value); return NULL; } value[size] = '\0'; return value; }
ssize_t smack_new_label_from_file(int fd, const char *xattr, char **label) { char buf[SMACK_LABEL_LEN + 1]; char *result; ssize_t ret = 0; ret = fgetxattr(fd, xattr, buf, SMACK_LABEL_LEN + 1); if (ret < 0) return -1; buf[ret] = '\0'; result = calloc(ret + 1, 1); if (result == NULL) return -1; ret = get_label(result, buf, NULL); if (ret < 0) { free(result); return -1; } *label = result; return ret; }
ssize_t mslnk_get_xattr(mslnk_t *mslnk, const char *name, void *value, size_t size) { ssize_t status; status = fgetxattr(mslnk->fdattrs, name, value, size); return status; }
fsal_status_t vfs_getextattr_value_by_id(struct fsal_obj_handle *obj_hdl, const struct req_op_context *opctx, unsigned int xattr_id, caddr_t buffer_addr, size_t buffer_size, size_t *p_output_size) { struct vfs_fsal_obj_handle *obj_handle = NULL; int fd = -1; int rc = 0; obj_handle = container_of(obj_hdl, struct vfs_fsal_obj_handle, obj_handle); /* check that this index match the type of entry */ if ((xattr_id < XATTR_COUNT) && !do_match_type(xattr_list[xattr_id].flags, obj_hdl->attributes.type)) { return fsalstat(ERR_FSAL_INVAL, 0); } else if (xattr_id >= XATTR_COUNT) { char attr_name[MAXPATHLEN]; fsal_errors_t fe; fd = (obj_hdl->type == DIRECTORY) ? vfs_fsal_open(obj_handle, O_DIRECTORY, &fe) : vfs_fsal_open(obj_handle, O_RDWR, &fe); if (fd < 0) return fsalstat(fe, -fd); /* get the name for this attr */ rc = xattr_id_to_name(fd, xattr_id, attr_name); if (rc) { close(fd); return fsalstat(rc, errno); } rc = fgetxattr(fd, attr_name, buffer_addr, buffer_size); if (rc < 0) { close(fd); return fsalstat(posix2fsal_error(errno), errno); } /* the xattr value can be a binary, or a string. * trying to determine its type... */ *p_output_size = rc; close(fd); rc = ERR_FSAL_NO_ERROR; } else { /* built-in attr */ /* get the value */ rc = xattr_list[xattr_id].get_func(obj_hdl, buffer_addr, buffer_size, p_output_size, xattr_list[xattr_id].arg); } return fsalstat(rc, 0); }
cap_t cap_get_fd(int fildes) { cap_t result; /* allocate a new capability set */ result = cap_init(); if (result) { struct vfs_cap_data rawvfscap; int sizeofcaps; _cap_debug("getting fildes capabilities"); /* fill the capability sets via a system call */ sizeofcaps = fgetxattr(fildes, XATTR_NAME_CAPS, &rawvfscap, sizeof(rawvfscap)); if (sizeofcaps < ssizeof(rawvfscap.magic_etc)) { cap_free(result); result = NULL; } else { result = _fcaps_load(&rawvfscap, result, sizeofcaps); } } return result; }
static ssize_t _getxattr(const char *path, int fd, const char *k, char *v, ssize_t vs) { if (fd >= 0) return fgetxattr(fd, k, v, vs); else return getxattr(path, k, v, vs); }
ssize_t mdir_get_xattr(mdir_t *mdir, const char *name, void *value, size_t size) { ssize_t status; status = fgetxattr(mdir->fdp, name, value, size); return status; }
/** * @brief is_local_file Check a location of file by file descriptor * (local or remote). * * @note Operation is atomic according to * http://man7.org/linux/man-pages/man7/xattr.7.html. * * @param[in] fd File descriptor to check location. * @param[in] flags Flags with which file descriptor was opened. * * @return 1: if file is in local storage * 0: if file is in remote storage * -1: error happen during an attempt to get extended attribute's value */ int is_local_file( int fd, int flags ) { /* if file was opened in write-only mode, use fsetxattr with XATTR_REPLACE which will produce result equivalent to fgetxattr */ int ret = ( ( flags & O_WRONLY ) == O_WRONLY ) ? fsetxattr( fd, xattr_str[e_stub], NULL, 0, XATTR_REPLACE ) : fgetxattr( fd, xattr_str[e_stub], NULL, 0 ); if ( ret == -1 ) { if ( IS_LOCAL_PREDICATE ) { /* if ENOTSUP then the file not in our target filesystem and we not manage lifecycle of this file, if ERANGE then e_stub attribute should have a value which is not possible according to then logic of this program and if ENOATTR then the file is definitely local by our convention which means that we can safetly report that file is local */ return 1; } else if ( errno == EPERM ) { /* only fsetxattr can produce this errno; we are here only in case linux-specific feature inode flags-attributes plays its role; more specifically either FS_APPEND_FL or FS_IMMUTABLE_FL flags are set (see setxattr(2) and ioctl_iflags(2)); in many cases the current process can read the file either, so we want to get extended attribute using /proc/self/fd/<fd> file path and, if not works, give up and return error */ char path[PROC_SELF_FD_FD_PATH_MAX_LEN]; snprintf(path, PROC_SELF_FD_FD_PATH_MAX_LEN, PROC_SELF_FD_FD_PATH_TEMPLATE, (unsigned long long int)fd); if ( getxattr( path, xattr_str[e_stub], NULL, 0) == -1 ) { if ( IS_LOCAL_PREDICATE ) { /* as before, this conditional branch indicates that file is local */ return 1; } /* we can do nothing here, return a error produced by inner stat call */ return -1; } /* e_stub atribute is set which means that file is remote */ return 0; } else { /* errors from stat(2) which should be handled separately in each public libc wrapper function so we return the error here */ return -1; } } /* e_stub atribute is set which means that file is remote */ return 0; }
int acl_extended_fd(int fd) { int base_size = sizeof(acl_ea_header) + 3 * sizeof(acl_ea_entry); int retval; retval = fgetxattr(fd, ACL_EA_ACCESS, NULL, 0); if (retval < 0 && errno != ENOATTR && errno != ENODATA) return -1; if (retval > base_size) return 1; retval = fgetxattr(fd, ACL_EA_DEFAULT, NULL, 0); if (retval < 0 && errno != ENOATTR && errno != ENODATA) return -1; if (retval >= base_size) return 1; return 0; }
static int local_fstat(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs, struct stat *stbuf) { int err, fd; if (fid_type == P9_FID_DIR) { fd = dirfd(fs->dir); } else { fd = fs->fd; } err = fstat(fd, stbuf); if (err) { return err; } if (fs_ctx->export_flags & V9FS_SM_MAPPED) { /* Actual credentials are part of extended attrs */ uid_t tmp_uid; gid_t tmp_gid; mode_t tmp_mode; dev_t tmp_dev; if (fgetxattr(fd, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0) { stbuf->st_uid = tmp_uid; } if (fgetxattr(fd, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0) { stbuf->st_gid = tmp_gid; } if (fgetxattr(fd, "user.virtfs.mode", &tmp_mode, sizeof(mode_t)) > 0) { stbuf->st_mode = tmp_mode; } if (fgetxattr(fd, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0) { stbuf->st_rdev = tmp_dev; } } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { errno = EOPNOTSUPP; return -1; } return err; }
static ssize_t xattr_fgetxattr(int fd, const char *name, void *value, ssize_t size, u_int32_t position, int options) { if (position != 0 || !(options == 0 || options == XATTR_XATTR_NOFOLLOW)) { return -1; } if (options & XATTR_XATTR_NOFOLLOW) { return -1; } else { return fgetxattr(fd, name, value, size); } }
fsal_status_t vfs_getextattr_value_by_name(struct fsal_obj_handle *obj_hdl, const struct req_op_context *opctx, const char *xattr_name, caddr_t buffer_addr, size_t buffer_size, size_t *p_output_size) { struct vfs_fsal_obj_handle *obj_handle = NULL; int fd = -1; int rc = 0; unsigned int index; fsal_errors_t fe; obj_handle = container_of(obj_hdl, struct vfs_fsal_obj_handle, obj_handle); /* sanity checks */ if (!obj_hdl || !p_output_size || !buffer_addr || !xattr_name) return fsalstat(ERR_FSAL_FAULT, 0); /* look for this name */ for (index = 0; index < XATTR_COUNT; index++) { if (do_match_type(xattr_list[index].flags, obj_hdl->attributes.type) && !strcmp(xattr_list[index].xattr_name, xattr_name)) { return vfs_getextattr_value_by_id(obj_hdl, opctx, index, buffer_addr, buffer_size, p_output_size); } } fd = (obj_hdl->type == DIRECTORY) ? vfs_fsal_open(obj_handle, O_DIRECTORY, &fe) : vfs_fsal_open(obj_handle, O_RDWR, &fe); if (fd < 0) return fsalstat(fe, -fd); /* is it an xattr? */ rc = fgetxattr(fd, xattr_name, buffer_addr, buffer_size); if (rc < 0) { close(fd); return fsalstat(posix2fsal_error(errno), errno); } /* the xattr value can be a binary, or a string. * trying to determine its type... */ *p_output_size = rc; close(fd); return fsalstat(ERR_FSAL_NO_ERROR, 0); }
static void verify_fgetxattr(void) { TEST(fgetxattr(fd, XATTR_TEST_KEY, NULL, 0)); if (TST_RET == XATTR_TEST_VALUE_SIZE) { tst_res(TPASS, "fgetxattr(2) returned correct value"); return; } tst_res(TFAIL | TTERRNO, "fgetxattr(2) failed with %li", TST_RET); }
int fgetfilecon_raw(int fd, security_context_t * context) { char *buf; ssize_t size; ssize_t ret; size = INITCONTEXTLEN + 1; buf = malloc(size); if (!buf) return -1; memset(buf, 0, size); ret = fgetxattr(fd, XATTR_NAME_SELINUX, buf, size - 1); if (ret < 0 && errno == ERANGE) { char *newbuf; size = fgetxattr(fd, XATTR_NAME_SELINUX, NULL, 0); if (size < 0) goto out; size++; newbuf = realloc(buf, size); if (!newbuf) goto out; buf = newbuf; memset(buf, 0, size); ret = fgetxattr(fd, XATTR_NAME_SELINUX, buf, size - 1); } out: if (ret == 0) { /* Re-map empty attribute values to errors. */ errno = ENOTSUP; ret = -1; } if (ret < 0) free(buf); else *context = buf; return ret; }
int main(int argc, char* argv[]) { char path[PATH_MAX]; const char* home = getenv("HOME"); int fd; int ret; snprintf(path, sizeof(path), "%s/rr-xattr-XXXXXX", home ? home : "/tmp"); path[sizeof(path) - 1] = 0; fd = mkstemp(path); test_assert(0 <= fd); ret = setxattr(path, attr_name, attr_value, sizeof(attr_value), XATTR_CREATE); if (ret < 0 && errno == EOPNOTSUPP) { atomic_printf("Extended attributes not supported on file %s, " "skipping test\n", path); } else { char buf[sizeof(attr_value) + 1]; test_assert(ret == 0); memset(buf, '-', sizeof(buf)); ret = fgetxattr(fd, attr_name, buf, sizeof(buf) - 5); test_assert(ret == -1); test_assert(errno == ERANGE); test_assert(buf[0] == '-'); ret = fsetxattr(fd, attr_name, attr_value, sizeof(attr_value), XATTR_REPLACE); test_assert(ret == 0); ret = getxattr(path, attr_name, buf, sizeof(buf)); test_assert(ret == sizeof(attr_value)); test_assert(0 == memcmp(attr_value, buf, sizeof(attr_value))); test_assert(buf[sizeof(attr_value)] == '-'); ret = fremovexattr(fd, attr_name); test_assert(ret == 0); memset(buf, '-', sizeof(buf)); ret = getxattr(path, attr_name, buf, sizeof(buf)); test_assert(ret == -1); test_assert(errno == ENODATA); test_assert(buf[0] == '-'); } test_assert(0 == unlink(path)); atomic_puts("EXIT-SUCCESS"); return 0; }
/** * Get the striping layout for the file referenced by file descriptor \a fd. * * If the filesystem does not support the "lustre." xattr namespace, the * file must be on a non-Lustre filesystem, so set errno to ENOTTY per * convention. If the file has no "lustre.lov" data, the file will * inherit default values, so return a default layout. * * If the kernel gives us back less than the expected amount of data, * we fail with errno set to EINTR. * * \param[in] fd open file descriptor * \param[in] flags open file descriptor * * \retval valid llapi_layout pointer on success * \retval NULL if an error occurs */ struct llapi_layout *llapi_layout_get_by_fd(int fd, uint32_t flags) { size_t lum_len; struct lov_user_md *lum; struct llapi_layout *layout = NULL; ssize_t bytes_read; int object_count; struct stat st; lum_len = XATTR_SIZE_MAX; lum = malloc(lum_len); if (lum == NULL) return NULL; bytes_read = fgetxattr(fd, XATTR_LUSTRE_LOV, lum, lum_len); if (bytes_read < 0) { if (errno == EOPNOTSUPP) errno = ENOTTY; else if (errno == ENODATA) layout = llapi_layout_alloc(); goto out; } /* Return an error if we got back a partial layout. */ if (llapi_layout_lum_truncated(lum, bytes_read)) { errno = EINTR; goto out; } object_count = llapi_layout_objects_in_lum(lum, bytes_read); /* Directories may have a positive non-zero lum->lmm_stripe_count * yet have an empty lum->lmm_objects array. For non-directories the * amount of data returned from the kernel must be consistent * with the stripe count. */ if (fstat(fd, &st) < 0) goto out; if (!S_ISDIR(st.st_mode) && object_count != lum->lmm_stripe_count) { errno = EINTR; goto out; } if (lum->lmm_magic == __swab32(LOV_MAGIC_V1) || lum->lmm_magic == __swab32(LOV_MAGIC_V3)) llapi_layout_swab_lov_user_md(lum, object_count); layout = llapi_layout_from_lum(lum, object_count); out: free(lum); return layout; }
int main (int argc, char *argv[]) { char *file; int fd; punyopt(argc, argv, NULL, NULL); file = Option.file; fd = openq(file, O_RDWR | O_CREAT); mystat(fd, "after open/create"); sleep(2); writeq(fd, Write, sizeof(Write)); mystat(fd, "after write"); closeq(fd); sleep(2); fd = openq(file, O_RDWR | O_NOATIME); sleep(2); mystat(fd, "after open noatime"); sleep(2); mystat(fd, "before read noatime"); readq(fd, Read, sizeof(Read)); mystat(fd, "after read noatime"); closeq(fd); sleep(2); fd = openq(file, O_RDWR); mystat(fd, "after open rdwr"); sleep(2); mystat(fd, "before read"); readq(fd, Read, sizeof(Read)); mystat(fd, "after read"); closeq(fd); sleep(2); fd = openq(file, O_RDWR); mystat(fd, "after open"); sleep(2); fsetxattr(fd, "noatime", Test, sizeof(Test), 0); mystat(fd, "after setxattr"); sleep(2); mystat(fd, "before read"); readq(fd, Read, sizeof(Read)); mystat(fd, "after read"); sleep(2); fgetxattr(fd, "noatime", Read, sizeof(Read)); mystat(fd, "after getxattr"); closeq(fd); return 0; }
uint16_t get_xt_flags(int fd) { char buf[FLAGS_SIZE]; uint16_t xt_flags = UINT16_MAX; memset(buf, 0, FLAGS_SIZE); if(fgetxattr(fd, PAX_NAMESPACE, buf, FLAGS_SIZE) != -1) xt_flags = string2bin(buf); return xt_flags; }
bool selinux_fget_context(int fd, std::string *context) { ssize_t size; std::vector<char> value; size = fgetxattr(fd, SELINUX_XATTR, nullptr, 0); if (size < 0) { return false; } value.resize(size); size = fgetxattr(fd, SELINUX_XATTR, value.data(), size); if (size < 0) { return false; } value.push_back('\0'); *context = value.data(); return true; }