@@ -746,6 +746,9 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
746
746
#endif
747
747
{
748
748
int ret ;
749
+ enum lxcfs_virt_t type ;
750
+
751
+ type = file_info_type (fi );
749
752
750
753
if (strcmp (path , "/" ) == 0 ) {
751
754
if (dir_filler (filler , buf , "." , 0 ) != 0 ||
@@ -758,21 +761,21 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
758
761
return 0 ;
759
762
}
760
763
761
- if (cgroup_is_enabled && strncmp ( path , "/cgroup" , 7 ) == 0 ) {
764
+ if (cgroup_is_enabled && LXCFS_TYPE_CGROUP ( type ) ) {
762
765
up_users ();
763
766
ret = do_cg_readdir (path , buf , filler , offset , fi );
764
767
down_users ();
765
768
return ret ;
766
769
}
767
770
768
- if (strcmp ( path , "/proc" ) == 0 ) {
771
+ if (LXCFS_TYPE_PROC ( type ) ) {
769
772
up_users ();
770
773
ret = do_proc_readdir (path , buf , filler , offset , fi );
771
774
down_users ();
772
775
return ret ;
773
776
}
774
777
775
- if (strncmp ( path , "/sys" , 4 ) == 0 ) {
778
+ if (LXCFS_TYPE_SYS ( type ) ) {
776
779
up_users ();
777
780
ret = do_sys_readdir (path , buf , filler , offset , fi );
778
781
down_users ();
@@ -879,44 +882,53 @@ static int lxcfs_read(const char *path, char *buf, size_t size, off_t offset,
879
882
struct fuse_file_info * fi )
880
883
{
881
884
int ret ;
885
+ enum lxcfs_virt_t type ;
886
+
887
+ type = file_info_type (fi );
882
888
883
- if (cgroup_is_enabled && strncmp ( path , "/cgroup" , 7 ) == 0 ) {
889
+ if (cgroup_is_enabled && LXCFS_TYPE_CGROUP ( type ) ) {
884
890
up_users ();
885
891
ret = do_cg_read (path , buf , size , offset , fi );
886
892
down_users ();
887
893
return ret ;
888
894
}
889
895
890
- if (strncmp ( path , "/proc" , 5 ) == 0 ) {
896
+ if (LXCFS_TYPE_PROC ( type ) ) {
891
897
up_users ();
892
898
ret = do_proc_read (path , buf , size , offset , fi );
893
899
down_users ();
894
900
return ret ;
895
901
}
896
902
897
- if (strncmp ( path , "/sys" , 4 ) == 0 ) {
903
+ if (LXCFS_TYPE_SYS ( type ) ) {
898
904
up_users ();
899
905
ret = do_sys_read (path , buf , size , offset , fi );
900
906
down_users ();
901
907
return ret ;
902
908
}
903
909
910
+ lxcfs_error ("unknown file type: path=%s, type=%d, fi->fh=%" PRIu64 ,
911
+ path , type , fi -> fh );
912
+
904
913
return - EINVAL ;
905
914
}
906
915
907
916
int lxcfs_write (const char * path , const char * buf , size_t size , off_t offset ,
908
917
struct fuse_file_info * fi )
909
918
{
910
919
int ret ;
920
+ enum lxcfs_virt_t type ;
921
+
922
+ type = file_info_type (fi );
911
923
912
- if (cgroup_is_enabled && strncmp ( path , "/cgroup" , 7 ) == 0 ) {
924
+ if (cgroup_is_enabled && LXCFS_TYPE_CGROUP ( type ) ) {
913
925
up_users ();
914
926
ret = do_cg_write (path , buf , size , offset , fi );
915
927
down_users ();
916
928
return ret ;
917
929
}
918
930
919
- if (strncmp ( path , "/sys" , 4 ) == 0 ) {
931
+ if (LXCFS_TYPE_SYS ( type ) ) {
920
932
up_users ();
921
933
ret = do_sys_write (path , buf , size , offset , fi );
922
934
down_users ();
0 commit comments