Announcement

Collapse
No announcement yet.

[os] linode - list files in a directory with inode number

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [os] linode - list files in a directory with inode number

    PHP Code:
    #include <stdlib.h>
    #include <sys/stat.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <dirent.h>
    #include <st***.h>
    #include <string.h>

    /*
     *               _            _                          
     *              (_)          (_)                          
     *    __  ____ _ _  _____   ___  ___   ___ ___  _ __ ___  
     *    \ \/ / _` | |/ _ \ \ / / |/ _ \ / __/ _ \| '_ ` _ \
     *     >  < (_| | | (_) \ V /| | (_) | (_| (_) | | | | | |
     *    /_/\_\__, |_|\___/ \_/ |_|\___(_)___\___/|_| |_| |_|
     *          __/ |                                        
     *         |___/  
     *
     *      List files in a directory with relative inode number
     *      Usage: linode <directory>
     *      v1.0
     *
     */

    typedef struct contents {
            
            
    char name[255];
            
    int node_number;
            
    struct contents next;
            
        } 
    contents_struct;
        
    contents_struct getdata (char nameint number) {
        
        
    contents_struct punt;
        
        
    punt = (contents_struct *) malloc sizeof(contents_struct));
                if ( 
    punt == NULL) {
                        
    fprintf(stderr"Errore di allocazione\n");
                        exit(-
    3);
                }
                
    strcpy (punt->namename);
                
    punt->node_number number;
                
    punt->next NULL;
                
        return 
    punt;
        
    }

    contents_struct add_to_list (contents_struct * list, contents_struct t_list){
        
        if (list==
    NULL){
                        list = 
    t_list;
                        return list;
                        
                    } else {
                        
                        if ( 
    strcmp (list->namet_list->name ) > ){
                            
                            
    t_list->next = list;
                            list=
    t_list;
                            return list;
                            
                        } else{
                            
                            list->
    next add_to_list ( list->nextt_list);
                            return list;
                            
                        }
        }
        
        
    }
        

    int main int n_entry char** name_entry) {

        if ( 
    n_entry 2){return 0;};
        
        
    struct stat file_info;
        
        
    DIR directory;
        
    struct dirent  dir_entry;
        
        
    int err,i;
        
        
    char array [1000];
        
        
    contents_struct * list;
        
    contents_struct t_list;
            list = 
    NULL;
        
        
        
    directory =  opendir (*(name_entry 1));
        if ( 
    directory == NULL){ fprintf(stderr"Impossibile aprire directory\n"); exit(-1);}
        
            for(
    dir_entry readdir(directory); \
                
    dir_entry != NULL;              \
                
    dir_entry readdir(directory)){
                
                
                
    strcpy ( array, *(name_entry 1));
                for(
    i=0;*(array+i)!=0;i++){};
                if (*(array+
    i-1)!='/'){
                    
    strcat ( array, "/");
                }
                
    strcat ( array, dir_entry->d_name);
                    
                    
                
    err stat (array, &file_info );
                    if ( 
    err == -1){ fprintf(stderr,"Errore lettura file\n"); exit(-2);}
                
                
    t_list=getdata(dir_entry->d_name, (int)(file_info.st_ino));
                list = 
    add_to_list(list, t_list);
                
            }
            
            for(
    t_list=list;t_list!=NULL;t_list=t_list->next){
                
                
    fprintf(stdout,"%s - %d\n",t_list->name,t_list->node_number);
                    
            }

        return 
    0;

    | VFX Artist, C++ Programmer, HW Overclocker | Web: xgiovio.com Email: xgiovio@gmail.com Twitter: @xgiovio
Working...
X

Google Profile


My name is Giovanni Di Grezia, but people call me xgiovio.

Here is my homepage:.

I'm a VFX Artist and Software Developer.

Giovanni Di Grezia