Unable to find the Stat command in busybox in I.MX28 BSP

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unable to find the Stat command in busybox in I.MX28 BSP

2,035 Views
srinivasanshanm
Contributor III

Dear I.MX community,

Could you please let me know how to get the stat command in busybox of i.MX28 BSP, as I require the stat command inorder to utilize this stat command in application for getting timestamps of the files & folder entries

Kindly do the needful as early as possible

Thanks in advance,

Labels (2)
0 Kudos
6 Replies

1,521 Views
YixingKong
Senior Contributor IV

Srinivasan

We have not got your response yet and will close the discussion in 3 days. If you still need help, please feel free to reply with an update to this discussion.

Thanks,

Yixing

0 Kudos

1,521 Views
srinivasanshanm
Contributor III

Pls close this thread... thanks a lot for your support it is really helpfull to me n other s as well

0 Kudos

1,521 Views
YixingKong
Senior Contributor IV

Srinivasan

Had your issue got resolved? If yes, we are going to close the discussion in 3 days. If you still need help, please feel free to reply with an update to this discussion.

Thanks,

Yixing

0 Kudos

1,521 Views
BrilliantovKiri
Senior Contributor I

Hello!

1. You can reconfigure busybox and enable stat command in it.

2. You can simple programm, as example:

#include <stdio.h>

#include <sys/stat.h>

#include <errno.h>

#include <string.h>

int main(int argc, char *argv[])

{

    if (argc != 2)

        printf("Unknown file!\n");

    else {

        struct stat info;

        const char *file = argv[1];

        if (stat(file, &info))

            printf("Failed get information abot \"%s\", errno %d (%s)\n",

                    file, errno, strerror(errno));

        else

            printf("Information about %s\n"

                    "inode %u\n"

                    "owner %u\n"

                    "group %u\n"

                    "size %u\n",

                    file,

                    info.st_ino,

                    info.st_uid,

                    info.st_gid,

                    info.st_size);

    }

    return 0;

}

0 Kudos

1,521 Views
srinivasanshanm
Contributor III

As am new to busy box, Could you pls let me know how to reconfigure the busybox with stat command,

But the above code snippet doesn't give timestamps of folders & file entries, where basically I need to check for time stamps of files & folder entries present in my usb stick in my application

I verified the same in my pc for the file & folders, could you pls help me out how this can be achieved in the i.mx28 target

Timestamp for file

user@user-desktop:~/Desktop$ stat 2.txt

  File: `2.txt'

  Size: 4065          Blocks: 8          IO Block: 4096   regular file

Device: 807h/2055d    Inode: 15469810    Links: 1

Access: (0644/-rw-r--r--)  Uid: ( 1000/    user)   Gid: ( 1000/    user)

Access: 2014-03-20 11:51:10.111574933 +0530

Modify: 2014-03-20 11:51:09.191579414 +0530

Change: 2014-03-20 11:51:09.191579414 +0530

Time stamp for folder

user@user-desktop:~/Desktop$ stat parser_test

  File: `parser_test'

  Size: 4096          Blocks: 8          IO Block: 4096   directory

Device: 807h/2055d    Inode: 17448127    Links: 5

Access: (0755/drwxr-xr-x)  Uid: ( 1000/    user)   Gid: ( 1000/    user)

Access: 2014-03-20 12:08:16.591577008 +0530

Modify: 2014-03-20 12:08:15.581889479 +0530

Change: 2014-03-20 12:08:15.581889479 +0530

user@user-desktop:~/Desktop$

Kindly do the needful as early as possible

0 Kudos

1,521 Views
BrilliantovKiri
Senior Contributor I

Hello!

For reconfigure BusyBox you should change directory to BusyBox source directory and run "make config" config.

For output format time string you can use  http://man7.org/linux/man-pages/man3/strftime.3.html and http://man7.org/linux/man-pages/man2/stat.2.html for get information, example:

#include <stdio.h>

#include <sys/stat.h>

#include <errno.h>

#include <string.h>

#include <time.h>

int main(int argc, char *argv[])

{

    if (argc != 2)

        printf("Unknown file!\n");

    else {

        struct stat info;

        const char *file = argv[1];

        if (stat(file, &info))

            printf("Failed get information abot \"%s\", errno %d (%s)\n",

                    file, errno, strerror(errno));

        else {

            char at[30] = {0}, mt[30] = , ct[30] = ;

            strftime(at, 30, "%F %T %z", localtime(&info.st_atime));

            strftime(mt, 30, "%F %T %z", localtime(&info.st_mtime));

            strftime(ct, 30, "%F %T %z", localtime(&info.st_ctime));

            printf("Information about %s\n"

                    "inode %u\n"

                    "owner %u\n"

                    "group %u\n"

                    "size %u\n"

                    "last access %s\n"

                    "last modification %s\n"

                    "last change %s\n",

                    file,

                    info.st_ino,

                    info.st_uid,

                    info.st_gid,

                    info.st_size,

                    at,

                    mt,

                    ct);

        }

    }

    return 0;

}

And output:

$ ./a.out a.out

Information about a.out

inode 6291480

owner 1000

group 1000

size 8118

last access 2014-03-20 11:16:12 +0400

last modification 2014-03-20 11:16:11 +0400

last change 2014-03-20 11:16:11 +0400

$ ./a.out /etc

Information about /etc

inode 7340033

owner 0

group 0

size 4096

last access 2014-03-20 11:07:01 +0400

last modification 2014-03-20 11:06:55 +0400

last change 2014-03-20 11:06:55 +0400

0 Kudos