首页 > > 详细

C辅导 Project 5解析R、Python编程讲解


Introduction

:,...
Requirement
CPS 536 Homework 5
Deadline: In class, at class time, Thursday, 20 April 2017
Write a program in C that takes root, low, and high as input and reports all the links in the file
subsystem rooted at root whose file-size is at least low and at most high. Note that root is to be
interpreted relative to the current working directory unless it starts with a slash (in which case use
the absolute path given).
Invocation
Your program is to be invoked as
$
Output
For each link that qualifies (other than “.” and “..”), your program should output the entire name
of the link (containing the complete path to the link) and its size. Also, your program should
output the total number of such links found. If multiple (hard) links exist to the same physical
file, you may report all such links.
Assumptions
• You may assume that there are no symbolic links (these were not discussed in class).
• The unit for low and high is kilo bytes. For example, the invocation
$ 2.2 9
is supposed to report all the links whose size is at least 2.2 kilo bytes and at most 9 kilo bytes.
Restrictions
• You are not to use any UNIX utility as part of your program.
Reference
Refer to discussions in class (and the textbook USP). I suggest that you first obtain the value of
the current working directory (consult the class-discussion on getcwd()) and use that to
construct the full path name for any link on which you would invoke stat(). As you traverse
the file subsystem (what sort of traversal/search would you use?), you will then be able to keep
the complete path name for any file that you deal with. Consult class discussion on including
limits.h and the symbolic constant PATH_MAX defined there and the handouts from the class
dealing with the file system, traversing directories, etc.
What needs to be turned in?
Source code and sample output. Note that the command ls –Rla dir will list the contents of
the entire file subsystem rooted at dir in the long format. For each of the test cases, turn in the
output produced by your program and the response of the above command.
What to leave on the system ?
Create a directory with the name hwk5 in your home directory. Give the group r-x permission for
directory hwk5 and for all the files there. Leave your files there.
- 2 -
$ pwd
/home/rsritharan/s17/hwk5
$
$ ls -lRa test
test:
total 4
drwxr-xr-x 4 rsritharan rsritharan 31 Apr 3 13:06 .
drwxr-xr-x 3 rsritharan rsritharan 61 Apr 3 13:12 ..
drwxr-xr-x 2 rsritharan rsritharan 24 Apr 3 13:06 A
drwxr-xr-x 4 rsritharan rsritharan 31 Apr 3 13:05 B
-rw-r–r– 1 rsritharan rsritharan 2910 Apr 3 12:59 f1
test/A:
total 8
drwxr-xr-x 2 rsritharan rsritharan 24 Apr 3 13:06 .
drwxr-xr-x 4 rsritharan rsritharan 31 Apr 3 13:06 ..
-rw-r–r– 1 rsritharan rsritharan 3236 Apr 3 13:00 f2
-rw-r–r– 1 rsritharan rsritharan 352 Apr 3 13:06 f3
test/B:
total 8
drwxr-xr-x 4 rsritharan rsritharan 31 Apr 3 13:05 .
drwxr-xr-x 4 rsritharan rsritharan 31 Apr 3 13:06 ..
drwxr-xr-x 2 rsritharan rsritharan 24 Apr 3 13:09 C
drwxr-xr-x 2 rsritharan rsritharan 15 Apr 3 13:10 D
-rw-r–r– 1 rsritharan rsritharan 6472 Apr 3 13:01 f7
test/B/C:
total 24
drwxr-xr-x 2 rsritharan rsritharan 24 Apr 3 13:09 .
drwxr-xr-x 4 rsritharan rsritharan 31 Apr 3 13:05 ..
-rw-r–r– 1 rsritharan rsritharan 9708 Apr 3 13:08 f4
-rw-r–r– 1 rsritharan rsritharan 9382 Apr 3 13:09 f5
test/B/D:
total 8
drwxr-xr-x 2 rsritharan rsritharan 15 Apr 3 13:10 .
drwxr-xr-x 4 rsritharan rsritharan 31 Apr 3 13:05 ..
-rw-r–r– 1 rsritharan rsritharan 6146 Apr 3 13:10 f6
$
$ h5 /home/rsritharan/s17/hwk5/test 2.2 9
Links with size (in kilobytes) in [2252, 9216]:
3236 /home/rsritharan/s17/hwk5/test/A/f2
6472 /home/rsritharan/s17/hwk5/test/B/f7
6146 /home/rsritharan/s17/hwk5/test/B/D/f6
2910 /home/rsritharan/s17/hwk5/test/f1
Total number of links found = 4
$
$ h5 test 0 3
Links with size (in kilobytes) in [0, 3072]:
24 /home/rsritharan/s17/hwk5/test/A
352 /home/rsritharan/s17/hwk5/test/A/f3
31 /home/rsritharan/s17/hwk5/test/B
24 /home/rsritharan/s17/hwk5/test/B/C
15 /home/rsritharan/s17/hwk5/test/B/D
2910 /home/rsritharan/s17/hwk5/test/f1
Total number of links found = 6

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!