libdsm 0.4.3
Minimalist and read-only SMB client lib
Loading...
Searching...
No Matches
Functions
smb_file.h File Reference

File operations. More...

#include "bdsm/smb_session.h"

Functions

BDSM_EXPORT int smb_fopen (smb_session *s, smb_tid tid, const char *path, uint32_t mod, smb_fd *fd)
 Open a file on a share.
 
BDSM_EXPORT void smb_fclose (smb_session *s, smb_fd fd)
 Close an open file.
 
BDSM_EXPORT ssize_t smb_fread (smb_session *s, smb_fd fd, void *buf, size_t buf_size)
 Read from an open file.
 
BDSM_EXPORT ssize_t smb_fwrite (smb_session *s, smb_fd fd, void *buf, size_t buf_size)
 Write to an open file.
 
BDSM_EXPORT ssize_t smb_fseek (smb_session *s, smb_fd fd, off_t offset, int whence)
 Sets/Moves/Get the read/write pointer for a given file.
 
BDSM_EXPORT int smb_file_rm (smb_session *s, smb_tid tid, const char *path)
 remove a file on a share.
 
BDSM_EXPORT int smb_file_mv (smb_session *s, smb_tid tid, const char *old_path, const char *new_path)
 move/rename a file/directory on a share.
 

Detailed Description

File operations.

Function Documentation

◆ smb_fclose()

BDSM_EXPORT void smb_fclose ( smb_session s,
smb_fd  fd 
)

Close an open file.

The smb_fd is invalidated and MUST not be use it anymore. You can give it the 0 value.

Parameters
sThe session object
fdThe SMB file descriptor

◆ smb_file_mv()

BDSM_EXPORT int smb_file_mv ( smb_session s,
smb_tid  tid,
const char *  old_path,
const char *  new_path 
)

move/rename a file/directory on a share.

Use this function to move and/or rename a file/directory

Parameters
sThe session object
tidThe tid of the share the file is in, obtained via smb_tree_connect()
old_pathThe current path of the file/directory to move/rename
new_pathThe new path of the file/directory
Returns
0 if move OK or -1 in case of error

◆ smb_file_rm()

BDSM_EXPORT int smb_file_rm ( smb_session s,
smb_tid  tid,
const char *  path 
)

remove a file on a share.

Use this function to delete a file

Parameters
sThe session object
tidThe tid of the share the file is in, obtained via smb_tree_connect()
pathThe path of the file to delete
Returns
0 if delete OK or "NT" error code

◆ smb_fopen()

BDSM_EXPORT int smb_fopen ( smb_session s,
smb_tid  tid,
const char *  path,
uint32_t  mod,
smb_fd fd 
)

Open a file on a share.

Use this function to obtain an smb_fd, necesary for file operations

Parameters
sThe session object
tidThe tid of the share the file is in, obtained via smb_tree_connect()
pathThe path of the file to open
modThe access modes requested (example: SMB_MOD_RO)
fdThe pointer to the smb file description that can be used for further file operations
Returns
0 on success or a DSM error code in case of error
See also
smb_tree_connect

◆ smb_fread()

BDSM_EXPORT ssize_t smb_fread ( smb_session s,
smb_fd  fd,
void *  buf,
size_t  buf_size 
)

Read from an open file.

The semantics is basically the same that the unix read() one. At most 'buf_size' bytes are read from the current seek offset and copied into the memory pointed by 'buf' from the open file represented by the smb file descriptor 'fd'.

Parameters
[in]sThe session object
[in]fd[description]
[out]bufcan be NULL in order to skip buf_size bytes
[in]buf_size[description]
Returns
The number of bytes read or -1 in case of error.

◆ smb_fseek()

BDSM_EXPORT ssize_t smb_fseek ( smb_session s,
smb_fd  fd,
off_t  offset,
int  whence 
)

Sets/Moves/Get the read/write pointer for a given file.

The behavior of this function is the same as the Unix fseek() function, except the SEEK_END argument isn't supported.

This functions adjust the read/write pointer depending on the value of offset and whence.

  • If whence == SMB_SEEK_SET, the read pointer is set at 'offset'
  • If whence == SMB_SEEK_CUR, the read pointer is adjusted by 'offset'
Parameters
sThe session object
fdThe file descriptors for which the read pointer is to be adjusted
offsetSet/Adjust quantity
whenceWhich action to perform. Supported operations are SMB_SEEK_SET and SMB_SEEK_CUR
Returns
The current read pointer position or -1 on error

◆ smb_fwrite()

BDSM_EXPORT ssize_t smb_fwrite ( smb_session s,
smb_fd  fd,
void *  buf,
size_t  buf_size 
)

Write to an open file.

At most 'buf_size' bytes from memory pointed by 'buf' are written to the current seek offset of the open file represented by the smb file descriptor 'fd'.

Parameters
[in]sThe session object
[in]fd[description]
[out]buf[description]
[in]buf_size[description]
Returns
The number of bytes written or -1 in case of error.