---
# System prepended metadata

title: Mini Project 0

---

# Mini Project 0
<!-- > []> []In above thread , u mentioned that stat usage is expected assuming we are using it for   -->
Q: Can we use `strlen()` for part 2?
[DJ]: Yes, there are no restrictions on the functions that can use for this Mini Project.
<!-- > * > []`` -->

Q: Are there any bonuses for speed?
[DJ]: No, there are no bonuses for Mini Project 0.

Q: Can we make numerous commits to the repository before the due date, with the newest contribution receiving credit? Or is it the initial commit?
[PV]: Yes, You can make as many commits as you want. That is the entire point of using git as a version control system.


Q: In the `open` system call, as given in the tutorial document.![](https://hackmd.io/_uploads/BJZlLFoin.png)
can you explain what exactly are multiple file descriptors and how exactly do they work?

[DJ] Let's say you have a file "a.txt" which contains data about some topic. Now, let's say, you have two functions which read two different parts of the document for serving their purposes. One might be reading it from the start of the document while the other might be reading the end part of the document. In this scenario, it will be very useful for us to have 2 file descriptors instead of one (basically call open() twice). This gives you first fd as let's say 5 and the other as 6. These two are independent from each other and calling read() or write() on one (or closing one), won't affect the file pointer of the other.

Q: So does that mean, we can push to remote as many times as want until the Submission date?
[DJ] : Yes.

Q: In Part 2, can the string have multiple words?
[DJ] : No whitespace characters are present in the word (only letters from Latin alphabet), hence it cannot have multiple words.

Q: In case the evaluation is going to be automated, can we please get some examples of the i/o format? Especially in case of the second question, are we supposed to print **"=== Parent Process ==="** and **"=== Child Process ==="** before printing the actual output of each?
[DJ] : Yes, you are supposed to print them. Take the example in mini project as the expected output. On another note, evalutation won't be automated for 2nd part as the order in which the two program print their output is non deterministic.

Q: Can we use any library for the project? Eg: <sys/stat.h>, <fcntl.h>
[DJ] : Yes, you can use any libraries for this Mini Project.

Q: Is being able to reverse a file of size, say, 16 GiB under a minute, good enough? Are we supposed to be able to reverse larger files under a minute? If so, what is the maximum file size that we are supposed to be able to reverse under a minute?
[DJ] : 16 GB is good enough.

Q: The project webpage says: **"The new file created should be named “<filename>_reverse” and must have the same permissions as the original file."** Are we expected to figure out the permissions of the original file, and replicate them? Or, can we just use 0644?
[DJ] : You are expected to figure out the permissions of the original file.
    
Q: Can we use Makefiles to build?
[DJ] : For this mini project, you are not required to do that. It's your choice if you want to include it, as we will run code using an automated script which does not rely on makefiles for this mini project.
    
Q: Do we need to add in the functionality of error handling into our code for Q1 or without it is fine? Say for example while opening file returns -1 then should i consider that case and print no such file exists etc??
[DJ] : You can just return from the program without doing anything in case of error because of missing file etc. We will be feeding your program valid files so there won't be an issue, but it's always good practice to handle errors.
    
Q: Is the input file guaranteed to exist in the same directory as the main.c file, for Part 1?
[VJS] You are expected to take the input file as a command line argument (as mentioned in repo readme and main.c).
    
Q: For Part 1, are we expected to figure out **all** the permissions, as in, those for root user, group and others? Or, would only root suffice? (in case of the latter, say root has r, w, x, then can we just put 0777?) Furthermore, say the input file does NOT have write permissions. In that case, since we are expected to figure out the permissions of the original file, should the output file also not have write permissions? How then, would we write the output to that file?
[DJ] : You are expected to figure out permissions of all three (user, group and others) and copy it as it is to the user, group, and others to the new file permissions. The input file will always have read and write permissions for the user so there should be no issue.
    
Q: Adding onto the above question, I have noticed that even when I try to give 0777 permissions, the max I can get is only 0755 (0022 keeps getting unmasked by default). Are we expected to be able to get 0777? (This query is applicable **BOTH** to the **directory** and the **reversed file.**)
[DJ] : This is because of presence of something called umask, which is applied to the permissions whenever you create a file/directory using open() or mkdir(). If you give permissions to be "mode", then the final permissions are (mode) & ~(umask). The default value of umask is 022. Hence, it's fine if you are getting the correct file permissions based on this (i.e. 0755 when you enter 0777). It is expected to get 0755 when you enter 0777 as the permissions.
    
Q: Will the name of the file in the argument be given as say "newfile" or "newfile.txt"?
[DJ] : newfile.txt

Q: I just am not able to understand what is meant to be done in second question, what sort of answer do you need or expect, please elaborate.
[DJ] : After taking a string input, you have to create a child process and print the string in upper case in the child process and print it in lower case in the parent process. You should print the "PARENT/CHILD PROCESS" as given in Mini Project instructions before printing the string in the respective processes. Elaborate what is your doubt for further clarification.
    
Q: What flags do I set when I am creating a directory using mkdir system call? I mean can S_ROTH and S_IXOTH flags go together?
[DJ] : You can "or" them to pass them together. 
    
Q: Can we assume that the given file is a text file already?
[DJ] : Yes.
    
Q: Is errno == EEXIST a kind of interrupt?
[DJ] : Can you elaborate? As far as I am aware, this is a condition.
    
Q: What permission are expected for the directory? Can we simply create it with the 777 permissions? Also what if the output file already exists? Do you want us to delete that and make a new one with the correct permissions?
[DJ] : I have updated instructions in the Mini Project for clarity (0755). If the output file already exists, you are expected to delete the file and create a new file with the required permissions.
    
Q: Can I push my own branch to the remote as well? Or will it disturb the evaluation of **"main"** branch?    
    And also which branch gets evaluated? "***feedback***" or "***main***"??
[VB] Please use the **main** branch for your submissions. Yes, you can push your own branch to github but make sure to make the relevant changes in **main** as well.
    
Q: Will a checker script be provided for the assignment or something?
[VB] No. Please make your own large file to check whether your implementation works.
    
Q: Regarding part 1, can the command line input be a file path? Or is it just a file name (i.e. guaranteed to be in the same directory as main.c)? Also is the file garanteed to be a .txt file or can it have other/no extension? The readme is unclear.
[VB] Please assume that it will be given a .txt file as the input. To be precise - your code will be run as $./a.out$ $filename.txt$ (You are not expected to handle different paths)
    
Q: Can we use library functions like fopen instead of direct system calls like open?
[VB] No. Please limit yourself to the functions discussed in the tutorial such as open(), read(), write(), lseek(), close() and fork().
    
Q: Which functions can we use?
[VB] Exhaustive list of functions:
1. Functions discussed in tutorial 1 - open(), read(), write(), lseek(), close(), fork()
2. Functions in libraries such as stdio.h and string.h (The only limitation you have is that the core functionalities of the task - i.e., reading a file, writing into a file and so on - should be performed using the functions listed in $1.$)
3. Functions for handling directories - mkdir()
4. Functions for handling permissions - chmod()
    
Q: Could mkdir(), chmod() and stat() be used as well?
[VB] Yes, yes and yes (assuming you wish to use stat() to check file size)
    
Q: Could lseek64 be used for handling large files?
[DJ] : Ideally, you should not have to rely on that. You can play around with the whence argument to achieve the required functionality with lseek (Do not use chunks in the size of GBs if you are)
    
Q: Can we use fstat()?
[DJ] : Yes, it's similar to stat.
    
Q: Is there any limit to the length of the arguments passed to the programs
[DJ] : There will be one argument, the filename. You don't need to know the length of the filename string.
    
Q: In the final submission for Q1, should we submit the original newfile.txt and its reverse or a large text file ?
[DJ] : You are not required to submit text files.

Q: Are we allowed to use `printf()` in part 2 or is it mandatory to use `write` system call?    
[VB] You may use `printf()` for part 2.

Q: For part 1, how much time do you expect to take for a 16 GB text file?
[VB] We expect linear time complexity for the task. Do experiment with different buffer sizes :)
    
Q: What exactly is the difference between open() and fopen()? 
[VB] _the open() function is a low-level call, where the fopen() when called simply calls the open() function in the background and it returns a Filepointer directly._ Taken from [here](https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://www.tutorialspoint.com/what-is-fopen-and-open-in-linux%23:~:text%3DThe%2520key%2520difference%2520between%2520the,it%2520returns%2520a%2520Filepointer%2520directly.&ved=2ahUKEwjN88TLjNWAAxUym1YBHerrBZIQFnoECBAQBQ&usg=AOvVaw1dZwexeqdzrpIi-FaFp-tK).
    
Q: If I define something using #define { } { }, do I put this in main.c or main.h
[VB] Anywhere you like, although its preferable to put it in main.h
    
Q: The directory structure has 2 txt files. Do we submit a run of the sample on a random text?
[VB] If the assignment doesn't explicitly ask for a sample run, please don't submit your code's execution on random text.

Q: What is the leading 0 in '0755' for?
[VB] It's the representation of the 32 bit number in octal form. Not passing the 0 results in it being parsed in base 10. Taken from [here](https://unix.stackexchange.com/questions/103413/is-there-any-difference-between-mode-value-0777-and-777).
    
Q: Can special characters be present in the txt file in part 1?
[DJ] : Special characters can be present in some test cases. However, in the test cases that they are present, the reverse of the file will not be checked. Only the reverse of reverse of the file will be checked and it should still give back the original file.
    
Q: It is not a problem if we print something on the terminal right for Part-1!
[DJ] : Yes, you can print anything.
    
Q:In one of above thread , u mentioned that stat usage is expected assuming we are using it for finding size, but can we also use stat for giving permissions?
[DJ] : You can use it however you like as long as you use open, read, write and lseek as they are intended.


Q: If my output is like :-
        === Child Process ===
        HAPPY
        === Parent Process ===
        happy
   is there any problem?
[DJ] : No.
    
Q: Is it okay to use libraries "tolower" and "toupper" in Part 2?
[DJ] : Yes, that's why I included ctype.h in the template.
    
Q: Reversing the reverse of file and checking the new_file with the original file in online text comparator. Is this a good method of checking the 1st question?
[VB] Sure. However, we can't guarantee anything so it's always safe to run a few simple large files to check.
    
Q: In the GitHub repo, do we also upload a Copies directory containing the newfile_reverse.txt?
[VB] No. Your code should be **making** the directory if it's not already present (as mentioned in the assignment doc)

Q: In github repo , do we upload newfile.txt in Part 1 and Copies directory containing the newfile_reverse.txt and also in Part 2 we should add main.c and main.h only?    
[VB] Please read the previous questions. You only need to add main.c and main.h
    
Q: If the directory Copies is already present, is it assured that it will be having permissions 0755 or do we need to change it?
[VB] Ideally your code should handle it as it's only a single line addition.
    
Q: By mistake I committed a.out in part 2 as well. It shouldn't interfere with anything but will that be fine?
[VB] No, that's alright. However for future reference you can delete files from your repository.
[PV] You can create a gitignore file and add *.out to it
    

    
    
    
    
2 2 4
Espresso 4
Cappuccino 4
1 Cappuccino 0 1
2 Espresso 1 3
3 Espresso 2 3
4 Espresso 2 3