Term Papers

Only available on StudyMode
  • Download(s) : 61
  • Published : April 7, 2013
Open Document
Text Preview
term paper
Project on Linux Programming (CSE207)

[pic]

Project—SIMULATION OF CHMOD,CHOWN AND CHGRP USING C PROGRAMMING AND WITHOUT USING ANY INBUILT COMMAND.

Submitted by --Submitted to aman Miss. Anjlee Verma

INTRODUCTION TO STUDY/COURSE

The present course Linux programming deals with various aspects of a very widely used operating system i.e. LINUX. Actually LINUX is not an OS in itself but a kernel i.e., Heart of any operating system. Many OS use Linux kernel to interact with hardware. Some examples are

FEDORA

REDHAT

DEBIAN

UBUNTU

and many more…

In this course we study about the internal variables and commands of the operating system which it uses to interact with the hardware and also use them in any way we like. Also I learnt to simulate some commands which were already present in LINUX.

The course also deals with teaching the basic principles of any LINUX kernel using operating system. Thus we can code in either shell scripts or create a C program to establish our task.

INTRODUCTION TO TOPIC

The topic of my project is to simulate commands i.e.,

➢ Chmod

➢ Chown

➢ Chgrp

1: Chmod command-: It is used to change the permissions of the file for the user who owns it, the group to which it belongs and others.

Syntax:

chmod permissions filename

permission type:

a) Numeric –

Read =4

Write=2

Execute=1

b) Alphabetic

Read=r

Write=w

Execute=e

2: Chown command-: It is used to change the ownership of the given file

Syntax:

chown username filename

3:Chgrp command-:It is used to change the group of the given file

Syntax:

chgrp groupname filename

PROBLEM TO BE SOLVED

Create a shell script or a c program to simulate the behavior of following linux commands without using any in built command. Chmod
Chown
Chgrp commands

Solution:

The following pages contains codes for the given linux commands.

The header files included

unistd.h

fcntl.h

sys/stat.h

stdio.h

pwd.h

grp.h

The major structures used are-:

Group

Stat

Passwd

The major inbuilt functions used

getpwnam()

stat()

chown()

getgrnam()

S_ISREG()

chmod()

CODE FOR CHMOD COMMAND

#include

#include

#include

#include

#include

//The following function changes permission when numeric value of user,group,others

when filename and values as specified is passed.

void cp(char *file,int pusr,int pgrp,int poth)

{

int p=1000+100*pusr+10*pgrp+poth;

if(pusr==0)

{

if(pgrp==0)

p=1000+100*pusr+10*pgrp+poth+24;

else if(pgrp==1)

p=1000+100*pusr+10*pgrp+poth+22;

else if(pgrp==2)

p=1000+100*pusr+10*pgrp+poth+20;

else if(pgrp==3)

p=1000+100*pusr+10*pgrp+poth+18;

else if(pgrp==4)

p=1000+100*pusr+10*pgrp+poth+16;

else if(pgrp==5)

p=1000+100*pusr+10*pgrp+poth+14;

else if(pgrp==6)

p=1000+100*pusr+10*pgrp+poth+12;

else if(pgrp==7)

p=1000+100*pusr+10*pgrp+poth+10;

}

if(pusr==1)

{

if(pgrp==0)

p=2000+100*pusr+10*pgrp+poth+12;

else if(pgrp==1)

p=2000+100*pusr+10*pgrp+poth+10;

else if(pgrp==2)

p=2000+100*pusr+10*pgrp+poth+8;

else if(pgrp==3)

p=2000+100*pusr+10*pgrp+poth+6;

else if(pgrp==4)

p=2000+100*pusr+10*pgrp+poth+4;

else if(pgrp==5)

p=2000+100*pusr+10*pgrp+poth+2;

else if(pgrp==6)

p=2000+100*pusr+10*pgrp+poth;

else if(pgrp==7)

p=2000+100*pusr+10*pgrp+poth-2;

}

if(pusr==2)

{

if(pgrp==0)

p=3000+100*pusr+10*pgrp+poth;

else...
tracking img