+ int rc;
+ char dpath[PATH_MAX + 1];
+ char fpath[PATH_MAX + 1];
+
+ if ((rc = clilovpath(fsname, pathname, dpath)) != 0)
+ return rc;
+
+ if (scount) {
+ snprintf(fpath, PATH_MAX, "%s/stripecount", dpath);
+ if ((rc = sattr_read_attr(fpath, scount)) != 0)
+ return rc;
+ }
+
+ if (ssize) {
+ snprintf(fpath, PATH_MAX, "%s/stripesize", dpath);
+ if ((rc = sattr_read_attr(fpath, ssize)) != 0)
+ return rc;
+ }
+
+ if (soffset) {
+ snprintf(fpath, PATH_MAX, "%s/stripeoffset", dpath);
+ if ((rc = sattr_read_attr(fpath, soffset)) != 0)
+ return rc;
+ }
+
+ return 0;
+}
+
+/*
+ * Tries to gather the default stripe attributes for a given filesystem. If
+ * the attributes can be determined, they are cached for easy retreival the
+ * next time they are needed. Only a single filesystem's attributes are
+ * cached at a time.
+ */
+static int sattr_cache_get_defaults(const char *const fsname,
+ const char *const pathname,
+ unsigned int *scount,
+ unsigned int *ssize,
+ unsigned int *soffset)
+{
+ static struct {
+ char fsname[PATH_MAX + 1];
+ unsigned int stripecount;
+ unsigned int stripesize;
+ unsigned int stripeoffset;
+ } cache = {
+ .fsname = {'\0'}
+ };
+
+ int rc;
+ char fsname_buf[PATH_MAX + 1];
+ unsigned int tmp[3];
+
+ if (fsname == NULL)
+ llapi_search_fsname(pathname, fsname_buf);
+ else
+ strncpy(fsname_buf, fsname, PATH_MAX);
+
+ if (strncmp(fsname_buf, cache.fsname, PATH_MAX) != 0) {
+ /*
+ * Ensure all 3 sattrs (count, size, and offset) are
+ * successfully retrieved and stored in tmp before writing to
+ * cache.
+ */
+ if ((rc = sattr_get_defaults(fsname_buf, NULL, &tmp[0],
+ &tmp[1], &tmp[2])) != 0)
+ return rc;
+
+ cache.stripecount = tmp[0];
+ cache.stripesize = tmp[1];
+ cache.stripeoffset = tmp[2];
+ strncpy(cache.fsname, fsname_buf, PATH_MAX);
+ }
+
+ if (scount)
+ *scount = cache.stripecount;
+ if (ssize)
+ *ssize = cache.stripesize;
+ if (soffset)
+ *soffset = cache.stripeoffset;
+
+ return 0;