Flacarile
Flacarile

Reputation: 69

Implementing lseek in xv6

First off I need to say it's completely possible I'm missing something. My assignment is to essentially implement 'fprintf'. Now while appending to the file isn't required, I like to go above and beyond. My issue is, I can't find a definition for lseek in xv6, meaning I have to implement it on my own, but I genuinely don't know how to go about it.

Tried reading 512 bytes at a time on an infinite loop in attempt to move the cursor over to the end, as a way to hardcode it, but if the file isn't opened with O_RDWR or I try this with stdout it fails.

I've also tried writing an empty string on an infinite loop. Knew it wouldn't work, but tried anyways.

I can read xv6 fairly well (The user level programs), but I can't understand the source code of lseek for the life of me

It doesn't have to be a genuine lseek. I just need to be able to get to the end of an fd and continue writing, but this cannot be reliant on filemode.

Any help is greatly appreciated.

Upvotes: 2

Views: 919

Answers (1)

Flacarile
Flacarile

Reputation: 69

I found the solution. The reason O_APPEND doesn't work is because the definition of open(), in sysfile.c, doesn't do anything with append. In sys_open, they hardcode a value of 0 for f->off (offset), and this is what I need to change. My planned solution is to figure out the filesize (in bytes) of the file, and set the offset to that number. Probably gonna use stat().

Upvotes: 1

Related Questions