• General
  • My Apps
  • SDKs
  • Protocols
  • Structures
  • Methods
  • Errors
Log in Register Log out
  • General

  • My Apps

  • SDKs
    • C
    • Java
    • Javascript
    • Php
    • Swift

  • Protocols
    • HTTP JSON Protocol
      • Authentication
      • Single Connection
      • Uploading Files
    • Binary Protocol
      • Sending Binary Request
      • Sending Files
      • Receiving Binary Response
      • Receiving Files Data

  • Structures
    • Datetime
    • Event
    • File Descriptors
    • Filenames
    • Metadata
    • Share
    • Tree

  • Methods
    • Intro
      • Global Parameters
      • Authentication
    • General
      • getdigest
      • userinfo
      • supportedlanguages
      • setlanguage
      • feedback
      • currentserver
      • diff
      • getfilehistory
      • getip
      • getapiserver
    • Folder
      • createfolder
      • createfolderifnotexists
      • listfolder
      • renamefolder
      • deletefolder
      • deletefolderrecursive
      • copyfolder
    • File
      • uploadfile
      • uploadprogress
      • downloadfile
      • downloadfileasync
      • copyfile
      • checksumfile
      • deletefile
      • renamefile
      • stat
    • Auth
      • sendverificationemail
      • verifyemail
      • changepassword
      • lostpassword
      • resetpassword
      • register
      • invite
      • userinvites
      • logout
      • listtokens
      • deletetoken
      • sendchangemail
      • changemail
      • senddeactivatemail
      • deactivateuser
    • Streaming
      • getfilelink
      • getvideolink
      • getvideolinks
      • getaudiolink
      • gethlslink
      • gettextfile
    • Archiving
      • getzip
      • getziplink
      • savezip
      • extractarchive
      • extractarchiveprogress
      • savezipprogress
    • Sharing
      • sharefolder
      • listshares
      • sharerequestinfo
      • cancelsharerequest
      • acceptshare
      • declineshare
      • removeshare
      • changeshare
    • Public Links
      • getfilepublink
      • getfolderpublink
      • gettreepublink
      • showpublink
      • getpublinkdownload
      • copypubfile
      • listpublinks
      • listplshort
      • deletepublink
      • changepublink
      • getpubthumb
      • getpubthumblink
      • getpubthumbslinks
      • savepubthumb
      • getpubzip
      • getpubziplink
      • savepubzip
      • getpubvideolinks
      • getpubaudiolink
      • getpubtextfile
      • getcollectionpublink
    • Thumbnails
      • getthumblink
      • getthumbslinks
      • getthumb
      • savethumb
    • Upload Links
      • createuploadlink
      • listuploadlinks
      • deleteuploadlink
      • changeuploadlink
      • showuploadlink
      • uploadtolink
      • uploadlinkprogress
      • copytolink
    • Revisions
      • listrevisions
      • revertrevision
    • Fileops
      • file_open
      • file_write
      • file_pwrite
      • file_read
      • file_pread
      • file_pread_ifmod
      • file_checksum
      • file_size
      • file_truncate
      • file_seek
      • file_close
      • file_lock
    • Newsletter
      • newsletter_subscribe
      • newsletter_check
      • newsletter_verifyemail
      • newsletter_unsubscribe
      • newsletter_unsibscribemail
    • Trash
      • trash_list
      • trash_restorepath
      • trash_restore
      • trash_clear
    • Collection
      • collection_list
      • collection_details
      • collection_create
      • collection_rename
      • collection_delete
      • collection_linkfiles
      • collection_unlinkfiles
      • collection_move
    • OAuth 2.0
      • authorize
      • oauth2_token
    • Transfer
      • uploadtransfer
      • uploadtransferprogress

  • Errors

file_lock

Name

file_lock

Auth

yes

Description

Locks or unlocks a file descriptor fd.

This method works, depending on the type paramater:

typeDescription
0release a lock
1get a shared lock
2get an exclusive lock
If the offset parameter is provided, only bytes starting from this offset are locked.

If the length parameter is provided, only length bytes starting from offset are locked. Length of 0 means lock until the end of file (no matter how big it grows).

The offset of this method could be interpreted depending on whence parameter:
whenceDescription
0offset is from the start of the file
1offset is from current offset
2offset is from the end of the file
If the parameter get is set, then instead of acquiring the lock only a test is performed if the file region can be locked.

By default locks are blocking, that is the call will block until the lock is granted (except when get is set or request is for unlocking). If you do not wish the lock to block, set the noblock parameter.

Locks are advisory locks, that is, they are not enforced on readers/writers that are not trying to take a lock.

You may hold just one lock on a file region. If shared lock is to be converted to an exclusive lock, the conversion is not atomic - the shared lock MIGHT be released first, before acquiring the exclusive lock. That happens only if the request for the exclusive lock can not be satisfied at the moment. This is done to prevent two processes from deadlocking by first holding a shared lock on a file and later trying to convert it to an exclusive lock. Processes still can deadlock by acquiring TWO locks simultaneously (each) on different files/regions in different order.

The API servers do not perform any kind of deadlock detection.

Required

ParameterDescription
fdint the file descriptor, which is locked or unlocked
typeint what operation is performed to the file lock

Optional

ParameterDescription
offsetint lock only bytes, starting from this position (default for offset is 0)
lengthint lock length bytes only, starting from offset (default for length is 0)
whenceint how to interpred the offset (default for whence is 0)
getint if set, then only test is performed if the file region can be locked
noblockint set, if you do not wish the lock to block

Output

The call is always successful unless read/write error is encountered. Result will be 0 regardless if lock was granted or not.

One should check the return field locked to see if lock was granted. Unlocking always sets locked to true, the same goes for blocking requests, as they are always successful (sooner or later).

So with result of 0 checking the value of locked makes sense only for non-blocking locks and for get checks.

Example

{
    result: 0,
    locked: true
}

Errors

CodeDescription
1000Log in required.
1007Invalid or closed file descriptor.
1008Please provide lock 'type'.
1012Invalid lock type. Please provide type (supported values: 0, 1, 2).
2000Log in failed.
4000Too many login tries from this IP address.
5004Read error. Try reopening the file.

2014 © pCloud. Terms and Conditions. Privacy Policy. Intellectual Property.
© pCloud. Terms and Conditions. Privacy Policy. Intellectual Property.
Reset Password
Check your e-mail for further instructions.
Reset