Name
file_open
Auth
yes
Description
Opens a file descriptor.
Output
On success returns fd file descriptor which can be used in successive operations. Also returns the fileid of the file (useful when creating file).
Required
Parameter | Description |
flags | int which can be a combination of the file_open flags. |
Optional
Parameter | Description |
path | string path to the file, for which the file descirptior is created. |
fileid | int id of the folder, for which the file descirptior is created. |
folderid | int id of the folder, in which new file is created and file descirptior is returned. |
name | string name of the file, in which new file is created and file descirptior is returned. |
Example
{ result: 0, fd: 1, fileid: 3489 }
Errors
Code | Description |
1000 | Log in required. |
1001 | No full path or name/folderid provided. |
1004 | No fileid or path provided. |
1006 | Please provide flags. |
2000 | Log in failed. |
2001 | Invalid file/folder name. |
2002 | A component of parent directory does not exist. |
2003 | Access denied. You do not have permissions to preform this operation. |
2004 | File or folder alredy exists. |
2008 | User is over quota. |
2009 | File not found. |
2010 | Invalid path. |
4000 | Too many login tries from this IP address. |
5000 | Internal error. Try again later. |
5001 | Internal upload error. |
Code | Description |
0x0002 | O_WRITE |
0x0040 | O_CREAT |
0x0080 | O_EXCL |
0x0200 | O_TRUNC |
0x0400 | O_APPEND |
If O_CREAT is set, file_open will create the file. In this case full "path" or "folderid" and "name" MUST be provided for the new file. If the file already exists the old file will be open unless O_EXCL is set, in which case open will fail.
If O_CREAT is not set, than full "path" or "fileid" MUST be provided. The function will fail if the file does not exist.
O_TRUNC will truncate files when opening existing files.
Files opened with O_APPEND will always write to the end of file (unless you use pwrite). That is the only reliable method without race conditions for writing in the end of file when there are multiple writers.
You do not need to specify O_WRITE even if you intend to write to the file. However that will preform write access control and quota checking and you will get possible errors during open, not at the first write.