# File Size Reservation Method?

**URL:** <https://forum.opencyphal.org/t/file-size-reservation-method/1893>\
**Category:** Applications & Usage\
**Created:** [May 18, 2023, 7:23pm UTC](https://forum.opencyphal.org/t/file-size-reservation-method/1893 "2023-05-18T19:23:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![erik.rainey](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/erik.rainey/32/20_2.png) [@erik.rainey](https://forum.opencyphal.org/u/erik.rainey)\
**Post date:** [May 18, 2023, 7:23pm UTC](https://forum.opencyphal.org/t/file-size-reservation-method/1893/1 "2023-05-18T19:23:26Z")

</div>

Today, if you wanted to upload a file over the `uavcan.file.*` protocols, you can do the follow order or operations:

1.) Using `uavcan.file.Modify` to configure as a “Touch” to create the file & parent directories. If the server is running out of resources it can be determined early here.  
2.) `uavcan.file.Write` repeat `file_size`/`block_size` times until the file is uploaded, then send the “EOF” call)

A failure could occur very far into the upload where the File System (or an emulation of one) could run out of space.

The “EOF” call of the `uavcan.file.Write` message is documented as being sent at the end of the file to notate that all the data has been sent and to truncate any other existing data (if a resize is needed).

Is the intent to _also_ use the EOF style to “reserve” the file space as well?

Sequence:

1. `uavcan.file.Modify` (as “Touch”)
2. `uavcan.file.Write` (as “EOF” w/ intended size)  
a. does it fill the file with undefined bytes? or  
b. Does it simply ask if there is enough room to support a file of that size? (it can respond with FILE\_TOO\_LARGE)
3. `uavcan.file.Write` (file data transactions + another “EOF” to note the end transactions).

---

<div class="post-metadata">

**Author:** ![erik.rainey](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/erik.rainey/32/20_2.png) [@erik.rainey](https://forum.opencyphal.org/u/erik.rainey)\
**Post date:** [May 27, 2023, 8:40pm UTC](https://forum.opencyphal.org/t/file-size-reservation-method/1893/2 "2023-05-27T20:40:56Z")

</div>

Proposed specification change for the wording of `uavcan.file.Write`:

> Write into a remote file.  
> The server shall place the contents of the field ‘data’ into the file pointed by ‘path’ at the offset specified by the field ‘offset’.

> [new] Before writing the file, the sender may test to see if the receiving end can contain the intended size of the file by sending a request with the offset field set to the size of the file and the data field empty. The server can then inform the client if the file size would be possible at the time of the request. This would not necessarily be guaranteed in subsequent transactions but the server may pre-allocate that memory if the implementation could support that.

> When writing a file, the client should repeatedly call this service with data while advancing the offset until the file is written completely. When the write sequence is completed, the client shall call the service one last time, with the offset set to the size of the file and with the data field empty, which will signal the server that the transfer is finished.

> When the write operation is complete, the server shall truncate the resulting file past the specified offset.
