SIMULATION OF EXISTING UNIX COMMAND (MOVE)

AIM:
To write a c program to simulate the existing UNIX command (move) using system calls. Operating System (OS) LAB in LINUX environment
PROGRAM DESCRIPTION:
In this program we have to unit a c program that simulates the move command for moving an existing file into a new file. In this program three system calls are used.

· link()
· unlink()
· access()

1.link ()
Syntax:
link(char *name1, char *name2)

It automatically creates specified directory entry name2 with attribute of underlying objects pointed by name1. if the link is successful it will return 0, else -1 will be returned.

2.unlink ()
Syntax:
unlink(char *name)

It removes the directory entry name and all the links for the indicated file.
3.access ()
Syntax:
access( pathname, int mode )
this system call checks whether the file indicated inside is existing or not. if it exist, it will checks if calling process has read, write or execute permission for that file according to mode specified and various modes are

0 R-ok read
1 W-ok write
2 F-ok file exist or not
3 x-ok executed
ALGORITHM:

· Declare the argument counter and argument vector array (argc,argv).

· if argc<3>4, then display that the move command operation cannot be performed.

· if argc==4, string compare argv[3] with “- I”. if it is true moves into the interactive mode.

· Check whether the file in argv[1] exists using system call access.

· Link the file in argv[1] with argv[2] and check for error condition.

· Unlink the file in argv[1] and check for error condition.

· if argc==3, then link the file in argv[1] with argv[2] and check for error condition

· Unlink the file in argv[1] and check for error condition.

see Source code: copy and move has same source code SIMULATION OF EXISTING UNIX COMMAND (COPY) Using c program .copy and move has the same source code

Related post