Thread: Question about filemodes??!!

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    12

    Question about filemodes??!!

    Code:
    Hi,
        Please see the program below.
    
    ==============================================
    #include <stdio.h>
    #include <sys/stat.h>
    #include <pwd.h>
    #include <grp.h>
    #include <time.h>
    struct passwd *getpwuid();
    struct group *getgrgid();
    
    main ( int argc , char *argv[] ) {
            struct stat thebuf;
            char *path;
            int i;
    
            for ( i = 1 ; i < argc ; i++ ) {
                    path = argv[i];
                    printf("path : %s\n",path);
    
            if ( !stat(path,&thebuf)) {
                    printf("File mode : %o\n",thebuf.st_mode);
                    printf("inode no : %d\n",thebuf.st_ino);
                    printf("Device Id : %d\n",thebuf.st_dev);
                    printf("Spl device Id : %d\n",thebuf.st_rdev);
                    printf("No of links : %d\n",thebuf.st_nlink);
                    printf("User id : %d\n",thebuf.st_uid);
                    printf("(%s)\n",getpwuid(thebuf.st_uid)->pw_name);
                    printf("Group id : %d\n",thebuf.st_gid);
                    printf("(%s)\n",getgrgid(thebuf.st_gid)->gr_name);
                    printf("size in bytes : %ld\n",thebuf.st_size);
                    printf("Last access time : %s\n",ctime(&thebuf.st_atime));
                    printf("Last modification time : %s\n",ctime(&thebuf.st_mtime));
                    printf("Last status time : %s\n",ctime(&thebuf.st_ctime));
                    printf("\n");
    
            } }
    }
    ============================================================
    
    I have a doubt in filemode.Actually for directory file mode gives 40755.
    For files it gives 100644.755 and 644 are the permissions.
    What is 40 and 100 here?
    Could anybody explain this little briefly?
    
    Thanks,
    Rajisankar

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So have you read the manual, or used google?

    This is your second 'stat' question which basically begs the STFW response. We're not going to spoon-feed you answers to every question you have as you slowly work your way through the members of the stat structure.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    12
    Quote Originally Posted by Salem View Post
    So have you read the manual, or used google?

    This is your second 'stat' question which basically begs the STFW response. We're not going to spoon-feed you answers to every question you have as you slowly work your way through the members of the stat structure.
    I'm not asking this quesions for time passing..I studied and worked on this.I'm not able to find answer for it in internet.Afterwards only i posted in this forum.Without knowing answer for this,i can't able to move ahead in this topic.Thats why i seeked help here.Asking help is not a wrong thing.Ok?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So you haven't read the manual then.
    Quote Originally Posted by RTFM
    STAT(2) Linux Programmer's Manual STAT(2)



    NAME
    stat, fstat, lstat - get file status

    SYNOPSIS
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <unistd.h>

    int stat(const char *path, struct stat *buf);
    int fstat(int fd, struct stat *buf);
    int lstat(const char *path, struct stat *buf);

    Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

    lstat(): _BSD_SOURCE || _XOPEN_SOURCE >= 500

    DESCRIPTION
    These functions return information about a file. No permissions are required on the file itself, but — in the case of stat() and lstat() — execute
    (search) permission is required on all of the directories in path that lead to the file.

    <<< snip >>>
    The following flags are defined for the st_mode field:

    S_IFMT 0170000 bit mask for the file type bit fields
    S_IFSOCK 0140000 socket
    S_IFLNK 0120000 symbolic link
    S_IFREG 0100000 regular file
    S_IFBLK 0060000 block device
    S_IFDIR 0040000 directory

    S_IFCHR 0020000 character device
    S_IFIFO 0010000 FIFO
    S_ISUID 0004000 set UID bit
    S_ISGID 0002000 set-group-ID bit (see below)
    S_ISVTX 0001000 sticky bit (see below)
    S_IRWXU 00700 mask for file owner permissions
    S_IRUSR 00400 owner has read permission
    S_IWUSR 00200 owner has write permission
    S_IXUSR 00100 owner has execute permission
    S_IRWXG 00070 mask for group permissions
    S_IRGRP 00040 group has read permission
    S_IWGRP 00020 group has write permission
    S_IXGRP 00010 group has execute permission
    S_IRWXO 00007 mask for permissions for others (not in group)
    S_IROTH 00004 others have read permission
    S_IWOTH 00002 others have write permission
    S_IXOTH 00001 others have execute permission

    <<< snip >>>
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Apr 2011
    Posts
    12
    Quote Originally Posted by Salem View Post
    So you haven't read the manual then.
    Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-23-2011, 09:00 AM
  2. *szString = things question/memory question
    By Jang in forum C Programming
    Replies: 3
    Last Post: 01-20-2011, 04:59 AM
  3. Newbish Question file reading question....
    By kas2002 in forum C Programming
    Replies: 23
    Last Post: 05-17-2007, 12:06 PM
  4. Self regiserting DLLs question and libraries question.
    By ApocalypticTime in forum Windows Programming
    Replies: 2
    Last Post: 03-22-2003, 02:02 PM
  5. A question of color...(not a racial question)
    By Sebastiani in forum Windows Programming
    Replies: 7
    Last Post: 01-15-2003, 08:05 PM