Advertisement
CSenshi

OS - FUSE (test xattrs)

Jul 13th, 2019
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.83 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # to run please change mode
  4. # chmod +x check_dir.bash
  5.  
  6. if [ "$#" -ne 1 ]; then
  7.     echo "Illegal number of parameters"
  8.     echo 'Call : ./check_dir.sh mounted_dir'
  9.     exit 1
  10. fi
  11.  
  12. MOUNT_DIR=$1
  13. cd $MOUNT_DIR
  14.  
  15. CMD="#### Command : "
  16.  
  17. test1(){
  18.     echo "Test 1 : set/get/remove/list External Attributes"
  19.    
  20.     FILE_NAME="test_attr_1.txt"
  21.    
  22.     echo "$CMD touch $FILE_NAME"
  23.     touch $FILE_NAME
  24.     echo
  25.    
  26.     ATTR_KEY="TEST_KEY"
  27.     ATTR_VAL="TEST_VALUE"
  28.    
  29.     # set atribute
  30.     echo "$CMD setfattr -n user.$ATTR_KEY -v $ATTR_VAL $FILE_NAME"
  31.     setfattr -n user.$ATTR_KEY -v $ATTR_VAL $FILE_NAME
  32.     echo
  33.    
  34.     ATTR_KEY2="TEST_KEY2"
  35.     ATTR_VAL2="TEST_VALUE2"
  36.    
  37.     # set atribute
  38.     echo "$CMD setfattr -n user.$ATTR_KEY2 -v $ATTR_VAL2 $FILE_NAME"
  39.     setfattr -n user.$ATTR_KEY2 -v $ATTR_VAL2 $FILE_NAME
  40.     echo
  41.    
  42.     # get atribute
  43.     echo "$CMD getfattr -n user.$ATTR_KEY $FILE_NAME (should return value)"
  44.     getfattr -n user.$ATTR_KEY $FILE_NAME
  45.    
  46.     # list atributes
  47.     echo "$CMD getfattr -d $FILE_NAME (should return full list of key:value)"
  48.     getfattr -d $FILE_NAME
  49.    
  50.     # remove atribute
  51.     echo "$CMD setfattr -x user.$ATTR_KEY $FILE_NAME"
  52.     setfattr -x user.$ATTR_KEY $FILE_NAME
  53.     echo
  54.    
  55.     # get atribute
  56.     echo "$CMD getfattr -n user.$ATTR_KEY $FILE_NAME (should not return)"
  57.     getfattr -n user.$ATTR_KEY $FILE_NAME
  58.     echo
  59.    
  60.     echo "Done!"
  61.     echo
  62. }
  63.  
  64. test2(){
  65.     echo "Test 2 : set/get/remove External Attributes"
  66.    
  67.     FILE_NAME="test_attr_2.txt"
  68.    
  69.    
  70.     echo "$CMD touch $FILE_NAME"
  71.     touch $FILE_NAME
  72.     echo
  73.    
  74.     ATTR_KEY="TEST_KEY"
  75.     ATTR_VAL="TEST_VALUE"
  76.    
  77.     TOTAL=50
  78.    
  79.     # set atribute
  80.     for t in $(seq 1 $TOTAL);
  81.     do
  82.         setfattr -n user.$ATTR_KEY$t -v $ATTR_VAL$t $FILE_NAME
  83.     done;
  84.    
  85.     # list atributes
  86.     echo "$CMD getfattr -d $FILE_NAME (should return full list of key:value)"
  87.     getfattr -d $FILE_NAME
  88.    
  89.     echo "Removing all of them"
  90.    
  91.     # remove atributes
  92.     for t in $(seq 1 $TOTAL);
  93.     do
  94.         # echo user.$ATTR_KEY$t
  95.         setfattr -x user.$ATTR_KEY$t $FILE_NAME
  96.     done;
  97.    
  98.     # list atributes
  99.     echo "$CMD getfattr -d $FILE_NAME (should not return list)"
  100.     getfattr -d $FILE_NAME
  101.    
  102.     echo "Done!"
  103.     echo
  104. }
  105.  
  106. test3(){
  107.     echo "Test 3 : set/get/remove/list External Attributes"
  108.    
  109.     FILE_NAME="test_attr_3.txt"
  110.    
  111.     echo "$CMD touch $FILE_NAME"
  112.     touch $FILE_NAME
  113.     echo
  114.    
  115.     ATTR_KEY="TEST_KEY"
  116.     ATTR_VAL="TEST_VALUE"
  117.    
  118.     # set atribute
  119.     echo "$CMD setfattr -n user.$ATTR_KEY -v $ATTR_VAL $FILE_NAME"
  120.     setfattr -n user.$ATTR_KEY -v $ATTR_VAL $FILE_NAME
  121.     echo
  122.    
  123.     # get atribute
  124.     echo "$CMD getfattr -n user.$ATTR_KEY $FILE_NAME (should return value)"
  125.     getfattr -n user.$ATTR_KEY $FILE_NAME
  126.    
  127.     # set atribute
  128.     ATTR_VAL="TEST_VALUE_REPL_1"
  129.     echo "$CMD setfattr -n user.$ATTR_KEY -v $ATTR_VAL $FILE_NAME"
  130.     setfattr -n user.$ATTR_KEY -v $ATTR_VAL $FILE_NAME
  131.     echo
  132.    
  133.     # get atribute
  134.     echo "$CMD getfattr -n user.$ATTR_KEY $FILE_NAME (should return value)"
  135.     getfattr -n user.$ATTR_KEY $FILE_NAME
  136.    
  137.     # set atribute
  138.     ATTR_VAL="TEST_VALUE_REPL_2"
  139.     echo "$CMD setfattr -n user.$ATTR_KEY -v $ATTR_VAL $FILE_NAME"
  140.     setfattr -n user.$ATTR_KEY -v $ATTR_VAL $FILE_NAME
  141.     echo
  142.    
  143.     # get atribute
  144.     echo "$CMD getfattr -n user.$ATTR_KEY $FILE_NAME (should return value)"
  145.     getfattr -n user.$ATTR_KEY $FILE_NAME
  146.    
  147. }
  148.  
  149. run_test(){
  150.     # check basic set and get attributes
  151.     test1
  152.    
  153.     # check for multiple attributes
  154.     test2
  155.    
  156.     # check for replacement
  157.     test3
  158. }
  159.  
  160.  
  161. START=$(date +%s.%N)
  162. run_test
  163. END=$(date +%s.%N)
  164. DIFF=$(echo "$END - $START" | bc)
  165.  
  166. echo "Elapsed time : $DIFF seconds"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement