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
  • Implement a Linux application (C program) that shows a file listing of a directory in the...

    Implement a Linux application (C program) that shows a file listing of a directory in the terminal. In the list include the file name, size, and date modified. This would mimic what you see in a standard file explorer/ftp. Allow for 2 optional flags: -n: will sort the given directories files by size -m: will sort the given directories files by last modified Notes: The -n and -m flags are optional, allow for one or both to be used, or...

  • 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...

  • This assignment should give you experience in using file descriptors, open(), close(), write(), stat() and chmod(),...

    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 files...

  • 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...

  • One can incidentally terminate sushi by pressing Ctrl+C (Ctrl+Break, Command+dot) or a similar combination of keys...

    One can incidentally terminate sushi by pressing Ctrl+C (Ctrl+Break, Command+dot) or a similar combination of keys that sends SIGNIT to the shell. Function prevent_interruption() sets up a signal handler that intercepts SIGINT and displays message “Type exit to exit the shell” on stderr. The name of the handler is refuse_to_die(), its skeleton and the skeleton of prevent_interruption() are provided in sushi.c. Hint: use system call sigaction() to set up the handler. As a result, when you attempt to interrupt the...

  • 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...

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