Question

2 File Management System Write a basic file managment system with following capabilities. Suppose the name of the program is

write the following code using C language. It will be ran in Ubuntu running linux OS

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:

#include <unistd.h>

#include <stdio.h>

#include <sys/stat.h>

#include <sys/types.h>

#include <dirent.h>

#include <stdlib.h>

#include <string.h>

#include <errno.h>

#include <unistd.h>

void disPerm(char file[]) {

struct stat fileStat;

lstat(file, &fileStat);

//printf(File permissions: \t.);

printf((S_ISDIR(fileStat.st_mode)) ? "d":"-");

printf((fileStat.st_mode & S_IRUSR) ? "r":"-");

printf((fileStat.st_mode & S_IWUSR) ? "w":"-");

printf((fileStat.st_mode & S_IXUSR) ? "x":"-");

printf((fileStat.st_mode & S_IRGRP) ? "r":"-");

printf((fileStat.st_mode & S_IWGRP) ? "w":"-");

printf((fileStat.st_mode & S_IXGRP) ? "x":"-");

printf((fileStat.st_mode & S_IROTH) ? "r":"-");

printf((fileStat.st_mode & S_IWOTH) ? "w":"-");

printf((fileStat.st_mode & S_IXOTH) ? "x":"-");

printf("\t%ld",fileStat.st_nlink);

//printf(.\t%d.,fileStat.st_uid);

printf("\t%ld",fileStat.st_size);

printf("\t%ld",fileStat.st_atime);

printf("\t%s",file);

printf("\n");

}

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

//pointer for dir entry

struct dirent *de;

DIR *dr = opendir(argv[1]);

if(dr == NULL) {

//opendir returns null if it couldn't open dir

printf("Could not open %s directory", argv[1]);

return 0;

}

while((de=readdir(dr)) != NULL) {

char f[50];

strcpy(f,de->d_name);

disPerm(f);

}

closedir(dr); //close directory

return 0;

/*pif(argc .. 1) dlsPerm(...);

else f while(--argc)

{ printf(.%s:\n., *1.1.argv);

disPerm(*argv); 1 1*/

}

Add a comment
Know the answer?
Add Answer to:
write the following code using C language. It will be ran in Ubuntu running linux OS...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The program is written in c. How to implement the following code without using printf basically...

    The program is written in c. How to implement the following code without using printf basically without stdio library? You are NOT allowed to use any functions available in <stdio.h> . This means you cannot use printf() to produce output. (For example: to print output in the terminal, you will need to write to standard output directly, using appropriate file system calls.) 1. Opens a file named logfle.txt in the current working directory. 2. Outputs (to standard output usually the...

  • Questions Given this data: drwxr-xr-x 2 asmith staff 4096 Feb 6 19:44 scripts Answer questions 6...

    Questions Given this data: drwxr-xr-x 2 asmith staff 4096 Feb 6 19:44 scripts Answer questions 6 through 13. 6. In the line above, what does the d on the extreme left mean or refer to? 7. What does the letter r mean? 8. What does the letter w mean? 9. What does the letter x mean? 10. On what date was the directory in the line above last modified? 11. To whom or what does the leftmost rwx apply? 12....

  • Purpose This assignment should give you experience in using file descriptors, open(), close(), wr...

    Purpose This assignment should give you experience in using file descriptors, open(), close(), write(), stat() and chmod(), perror(), and command line arguments. Program Write a C++ program that will allow you to add messages to a file that has NO permissions for any user. A Unix system has many files that have sensitive information in them. Permissions help keep these files secure. Some files can be publicly read, but can not be altered by a regular user (ex.: /etc/passwd). Other...

  • Objective : Write a C Shell script which copies all files(*.java and *.class) from your home dire...

    Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output:                                                    << CS Directory Analysis >>      Date:   ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files:   0 files Plain text files:   10 files File have read permissions: 3 files File have...

  • Overview Writing in the C language, implement a very basic shell, called smash. In this project,...

    Overview Writing in the C language, implement a very basic shell, called smash. In this project, we will work on processing strings and using the appropriate system calls. Build System setup Before we can start writing code we need to get our build system all setup. This will involve writing a very simple makefile. You should leverage your Makefile project for this part of the assignment! Write a Makefile that provides the three targets listed below all - The default...

  • Consider the following function://To compile this code by itself, naturally you need a main method. #include...

    Consider the following function://To compile this code by itself, naturally you need a main method. #include <stdio.h> #include <sys/stat.h> void printFileIndexNumber(char *path){ struct stat statbuf; if (stat(path, &statbuf) == -1) perror("Failed to get file status"); else printf("%s inode number is %d", path, &statbuf.st_ino);} It uses the stat system call to get information about the file indicated by the parameter *path. It puts the information about the file in the structure struct stat statbuf and prints out the file index number/inode...

  • The last 3 cases are tests .cpp files to test the code. The language of this...

    The last 3 cases are tests .cpp files to test the code. The language of this code must be C++ because that is the only I am familiar with. Soreland, a software company, is planning on releasing its first C++ compiler with the hopes of putting MiniSoft's Visual C++ out of business (that reminds me of another story). Consequently, Soreland has contracted with the Fruugle Corporation to design and build part of their compiler. Of course, since Fruugle gets all...

  • I have the following code....from the previous lab....the above needs to be added to what is...

    I have the following code....from the previous lab....the above needs to be added to what is already existing. ALSO MODIFY SEMAPHORES TO USE pthreads instead of the pipe constructs P() & V() #include <stdio.h> #include <string.h> #include <sys/types.h> #include <unistd.h> #include <sys/wait.h> #include <stdlib.h> #include <sys/stat.h> void printStat(char *filename); //Main int main(int argc, char *argv[]) { //Process Id (storing)    pid_t pid;    int j;    //printf("Welcome to Project Three\n”);    // For loop*/    for (j = 1; j...

  • C linux please write it by only using “if and else” conditions, thanks so much this...

    C linux please write it by only using “if and else” conditions, thanks so much this is my task 3 Requirements 1. Copy your solution for Task 3 t3.c to a new file t4.c. 2. The input is guaranteed to contain at least one non-whitespace character. 3. If the input is well-formed, i.e., can be parsed to a number, the program should behave identically to Task 3. All the requirements of Task 3 still apply except the file name. 4....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT