<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Li Wang <<a href="mailto:liwang@redhat.com">liwang@redhat.com</a>> wrote:<br></div></div><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
We (probably) know that maximum filename should be less than 255 chars<br>
(for e.g.), but I think there is a good chance that trying to validate<br>
this will result in false positives and stuff we might want to revert.<br></blockquote><div><br></div><div style="font-size:small">Maybe we can create a concrete size of the device and mount</div><div style="font-size:small">it with a designated FS (e.g. ext4), then extracting the known FS</div><div style="font-size:small">data into `struct statvfs` and validating them.</div></div></div></blockquote><div><br></div></div><div class="gmail_default" style="font-size:small">As some of the data are determined by the FS attribute and</div><div class="gmail_default" style="font-size:small">device size. (e.g. block size, total block, fragment size, and</div><div class="gmail_default" style="font-size:small">total inodes). We can check them directly by known values.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">For those easy change data, e.g. FS free blocks, which</div><div class="gmail_default" style="font-size:small">determined by the real system status, maybe just check</div><div class="gmail_default" style="font-size:small">that is no large than the total block number.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Based on that I draft something below to validate the fields.</div><div class="gmail_default" style="font-size:small">what do you think?</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">#include <sys/statvfs.h><br>#include "tst_test.h"<br><br>#define MNT_POINT "mntpoint"<br>#define TEST_PATH MNT_POINT"/testfile"<br><br>static void run(void)<br>{<br> int type;<br> struct statfs buf;<br> struct statvfs vbuf;<br><br> TST_EXP_PASS_SILENT(statfs(TEST_PATH, &buf));<br> TST_EXP_PASS(statvfs(TEST_PATH, &vbuf));<br><br> tst_res(TINFO, "Extracting FS info from the '%s' file", MNT_POINT);<br> tst_res(TINFO, "vbuf.f_fsid == %lu", vbuf.f_fsid);<br><br> long fs_type = tst_fs_type(TEST_PATH);<br><br> switch (fs_type) {<br> case TST_EXT2_OLD_MAGIC:<br> case TST_EXT234_MAGIC:<br> TST_EXP_EQ_LI(vbuf.f_bsize, 1024);</div><div class="gmail_default" style="font-size:small"> TST_EXP_EQ_LI(vbuf.f_frsize, 1024);</div><div class="gmail_default" style="font-size:small"> ttype = (vbuf.f_bfree <= buf.f_blocks) ? TPASS : TFAIL;</div><div class="gmail_default" style="font-size:small"> tst_res(ttype, "vbuf.f_bfree == %ju", (uintmax_t) vbuf.f_bfree);</div><div class="gmail_default" style="font-size:small"> TST_EXP_EQ_LI(vbuf.f_files, 76912);</div><div class="gmail_default" style="font-size:small"> ttype = (vbuf.f_ffree <= vbuf.f_files) ? TPASS : TFAIL;</div><div class="gmail_default" style="font-size:small"> tst_res(ttype, "vbuf.f_ffree == %ju", (uintmax_t) vbuf.f_ffree);</div><div class="gmail_default" style="font-size:small"> TST_EXP_EQ_LI(vbuf.f_flag, 4096);<br></div><div class="gmail_default" style="font-size:small"> TST_EXP_EQ_LI(vbuf.f_namemax, 255);</div><div class="gmail_default" style="font-size:small"> break;</div><div class="gmail_default" style="font-size:small"> case TST_XFS_MAGIC:<br> TST_EXP_EQ_LI(vbuf.f_bsize, 4096);</div><div class="gmail_default" style="font-size:small"> TST_EXP_EQ_LI(vbuf.f_frsize, 4096);</div><div class="gmail_default" style="font-size:small"> ttype = (vbuf.f_bfree <= buf.f_blocks) ? TPASS : TFAIL;</div><div class="gmail_default" style="font-size:small"> tst_res(ttype, "vbuf.f_bfree == %ju", (uintmax_t) vbuf.f_bfree);</div><div class="gmail_default" style="font-size:small"> TST_EXP_EQ_LI(vbuf.f_files, 153600);</div><div class="gmail_default" style="font-size:small"> ttype = (vbuf.f_ffree <= vbuf.f_files) ? TPASS : TFAIL;</div><div class="gmail_default" style="font-size:small"> tst_res(ttype, "vbuf.f_ffree == %ju", (uintmax_t) vbuf.f_ffree);</div><div class="gmail_default" style="font-size:small"> TST_EXP_EQ_LI(vbuf.f_flag, 4096);<br></div><div class="gmail_default" style="font-size:small"> TST_EXP_EQ_LI(vbuf.f_namemax, 255);</div><div class="gmail_default" style="font-size:small"> break;</div><div class="gmail_default" style="font-size:small"> case TST_BTRFS_MAGIC:<br> TST_EXP_EQ_LI(vbuf.f_bsize, 4096);</div><div class="gmail_default" style="font-size:small"> TST_EXP_EQ_LI(vbuf.f_frsize, 4096);</div><div class="gmail_default" style="font-size:small"> ttype = (vbuf.f_bfree <= buf.f_blocks) ? TPASS : TFAIL;</div><div class="gmail_default" style="font-size:small"> tst_res(ttype, "vbuf.f_bfree == %ju", (uintmax_t) vbuf.f_bfree);</div><div class="gmail_default" style="font-size:small"> TST_EXP_EQ_LI(vbuf.f_files, 0);</div><div class="gmail_default" style="font-size:small"> ttype = (vbuf.f_ffree <= vbuf.f_files) ? TPASS : TFAIL;</div><div class="gmail_default" style="font-size:small"> tst_res(ttype, "vbuf.f_ffree == %ju", (uintmax_t) vbuf.f_ffree);</div><div class="gmail_default" style="font-size:small"> TST_EXP_EQ_LI(vbuf.f_flag, 4096);<br></div><div class="gmail_default" style="font-size:small"> TST_EXP_EQ_LI(vbuf.f_namemax, 255);<br> break;</div><div class="gmail_default" style="font-size:small"> default:<br> tst_res(TINFO, "vbuf.f_bsize == %lu bytes", vbuf.f_bsize);</div><div class="gmail_default" style="font-size:small"> tst_res(TINFO, "vbuf.f_frsize == %lu bytes", vbuf.f_frsize);</div><div class="gmail_default" style="font-size:small"> tst_res(TINFO, "vbuf.f_bfree == %ju", (uintmax_t) vbuf.f_bfree);</div><div class="gmail_default" style="font-size:small"> tst_res(TINFO, "vbuf.f_files == %ju", (uintmax_t) vbuf.f_files);</div><div class="gmail_default" style="font-size:small"> tst_res(TINFO, "vbuf.f_ffree == %ju", (uintmax_t) vbuf.f_ffree);</div><div class="gmail_default" style="font-size:small"> tst_res(TINFO, "vbuf.f_namemax == %lu", vbuf.f_namemax);</div><div class="gmail_default" style="font-size:small"> break;</div><div class="gmail_default" style="font-size:small"> }<br>}<br><br>static void setup(void)<br>{<br> SAFE_TOUCH(TEST_PATH, 0666, NULL);<br>}<br><br>static struct tst_test test = {<br> .test_all = run,<br> .setup = setup,<br> .needs_root = 1,<br> .mount_device = 1,<br> .mntpoint = MNT_POINT,<br> .dev_min_size = 300,<br> .all_filesystems = 1<br>};<br></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>