2

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.

Flacarile
  • 69
  • 5
  • Why would `fprintf` need to seek? – melpomene Jun 06 '19 at 16:23
  • @melpomene I'm trying to get the append mode ("a") to work properly – Flacarile Jun 06 '19 at 16:29
  • `fprintf` doesn't need to care about modes. `"a"` should be implemented in `fopen` (by just passing `O_APPEND` to `open`). – melpomene Jun 06 '19 at 16:31
  • @melpomene Now that you mention it... I already AM passing O_APPEND into open(). I found something in sys_open's definition name 'off', so I'm thinking that's offset. Imma mess around with it and see if I can get O_APPEND to work. Thanks – Flacarile Jun 06 '19 at 16:46

1 Answers1

1

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().

Flacarile
  • 69
  • 5