Search code examples
camazon-web-services32bit-64bitamazon-efs

Cannot access EFS file programmatically with 32bits executable (on a 64bits OS)


I've got a problem accessing files programmatically on an Amazon EFS filesystem : the same C program will work with a 64 bits executable, but not with a 32bits executable.

Mount point is /EFS, the program below will list both EFS directory (/EFS/data) and local directory (/home/centos) :

Here is the test program :

#include <stdio.h>
#include <dirent.h>

int main(void) {
   struct dirent *d;

   char efs_dir[]   = "/EFS/data";
   char local_dir[] = "/home/centos";

   printf("EFS dir : %s\n",efs_dir);
   DIR *dirEFS = opendir(efs_dir);
   if (dirEFS == NULL) {
      printf("Could not open current directory");
      return 1;
   }
   while ((d = readdir(dirEFS)) != NULL)
     printf("%s\n", d->d_name);

   closedir(dirEFS);

   printf("\nlocal filesystem dir : %s\n",local_dir);
   DIR *dirLOCAL = opendir(local_dir);
   if (dirLOCAL == NULL) {
      printf("Could not open current directory");
      return 1;
   }
   while ((d = readdir(dirLOCAL)) != NULL)
     printf("%s\n", d->d_name);

   closedir(dirLOCAL);
   return 0;
}

Unix view :

[centos@ec2-instance ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/nvme0n1p1         20G  3.4G   16G  19% /
tmpfs                 3.7G     0  3.7G   0% /dev/shm
/dev/nvme1n1p1         94G  6.1G   83G   7% /opt/data
fs-XXXXXXXX.eu-west-3.amazonaws.com:/
              8.0E  5.3G  8.0E   1% /EFS

[centos@ec2-instance ~]$]$ ls -l /EFS/data
-rw-r--r-- 1 centos centos 2796 Sep 15 12:18 efs_file1.txt
-rw-r--r-- 1 centos centos 2812 Sep 15 12:18 efs_file2.txt
-rw-r--r-- 1 centos centos 3625 Sep 15 12:18 efs_file3.txt
-rw-r--r-- 1 centos centos 2768 Sep 15 12:18 efs_file4.txt

[centos@ec2-instance ~]$]$ ls -l /home/centos
-rw-rw-r-- 1 centos centos 2796 Sep 15 14:15 local_file1.txt
-rw-rw-r-- 1 centos centos 2812 Sep 15 14:15 local_file2.txt
-rw-rw-r-- 1 centos centos 3625 Sep 15 14:15 local_file3.txt
-rw-rw-r-- 1 centos centos 2768 Sep 15 14:15 local_file4.txt
-rw-r--r-- 1 centos centos   792 Sep 15 14:21 test_dir.c
-rwxrwxr-x 1 centos centos  7392 Sep 15 14:22 test_dir

When I compile test_dir.c in 32 bits compatibility mode, no results for the EFS directory :

[centos@ec2-instance ~]$ gcc test_dir.c -o test_dir -m32
[centos@ec2-instance ~]$ ./test_dir
EFS dir : /EFS/data

local filesystem dir : /home/centos
test_dir
.
..
local_file1.txt
local_file2.txt
local_file3.txt
local_file4.txt
test_dir.c

But for 64 bits executable it is fine :

[centos@ec2-instance ~]$ gcc test_dir.c -o test_dir
[centos@ec2-instance ~]$ ./test_dir
EFS dir : /EFS/data
.
..
efs_file1.txt
efs_file2.txt
efs_file3.txt
efs_file4.txt

local filesystem dir : /home/centos
test_dir
.
..
local_file1.txt
local_file2.txt
local_file3.txt
local_file4.txt
test_dir.c

Anyone has an idea of what is happening here ? Thanks.

edit (solution) : compress the 64 bits inodes number to 32 bits with the kernel option nfs.enable_ino64=0

[root@eai ~]# cat /etc/modprobe.d/nfs.conf
options nfs enable_ino64=0
[root@eai ~]# reboot

and it's done ! Thanks DNT.


Solution

  • Function readdir returns an inode. In your 32bit build it expects to find 32bit inodes. But with a file system with 64bit inodes it will fail if the particular inode number cannot be expressed in 32bits.

    To see the inode numbers you may want to use ls -li /EFS/data/efs_file1.txt. The leftmost number is the inode number and if it exceeds 4294967295 then it is 64bit and 32bit readdir cannot handle it.