52 int pkt_len, param_len;
58 file_tmp = File_Handle;
60 if (File_Handle ==
NULL) {
65 fprintf(stderr,
"Could not allocate file handle space ...");
76 file_tmp ->
tree = Tree_Handle;
77 file_tmp ->
fid = 0xFFFF;
79 param_len = strlen(file_name) + 2;
87 if (File_Handle ==
NULL)
113 strcpy(p+1, file_name);
114 p = p + strlen(file_name);
119 if (
RFCNB_Send(Tree_Handle -> con -> Trans_Connect, pkt, pkt_len) < 0) {
122 fprintf(stderr,
"Error sending Open request\n");
125 if (File_Handle ==
NULL)
136 fprintf(stderr,
"Pkt_Len for Open resp = %i\n", pkt_len);
139 if (
RFCNB_Recv(Tree_Handle -> con -> Trans_Connect, pkt, pkt_len) < 0) {
142 fprintf(stderr,
"Error receiving response to open request\n");
145 if (File_Handle =
NULL)
158 fprintf(stderr,
"SMB_Open failed with errorclass = %i, Error Code = %i\n",
163 if (File_Handle =
NULL)
176 file_tmp -> fileloc = 0;
181 fprintf(stderr,
"SMB_Open succeeded, FID = %i\n", file_tmp -> fid);
195 struct SMB_Close_Prot_Def *prot_pkt;
196 struct SMB_Hdr_Def_LM12 *resp_pkt;
200 if (File_Handle ==
NULL) {
235 if (
RFCNB_Send(File_Handle -> tree -> con -> Trans_Connect, pkt, pkt_len) < 0) {
238 fprintf(stderr,
"Error sending Open request\n");
249 if (
RFCNB_Recv(File_Handle -> tree -> con -> Trans_Connect, pkt, pkt_len) < 0) {
252 fprintf(stderr,
"Error receiving response to open request\n");
266 fprintf(stderr,
"SMB_Close failed with errorclass = %i, Error Code = %i\n",
279 fprintf(stderr,
"File %s closed successfully.\n", File_Handle -> filename);
284 File_Handle -> tree =
NULL;
285 File_Handle -> filename[0] = 0;
286 File_Handle -> fid = 0xFFFF;
301 struct RFCNB_Pkt *snd_pkt, *recv_pkt, *data_ptr;
302 int snd_pkt_len, recv_pkt_len, this_read, bytes_left = numbytes;
303 int max_read_data, bytes_read = 0;
310 if (data_ptr ==
NULL) {
324 if (snd_pkt ==
NULL) {
334 if (recv_pkt ==
NULL) {
345 recv_pkt ->
next = data_ptr;
359 max_read_data = (File_Handle -> tree -> mbs) - recv_pkt_len;
361 while (bytes_left > 0) {
363 this_read = (bytes_left > max_read_data?max_read_data: bytes_left);
372 if (
RFCNB_Send(File_Handle -> tree -> con -> Trans_Connect, snd_pkt, snd_pkt_len) < 0) {
375 fprintf(stderr,
"Error sending read request\n");
390 data_ptr ->
data = (
data + bytes_read);
391 data_ptr ->
len = this_read;
393 if (
RFCNB_Recv(File_Handle -> tree -> con -> Trans_Connect, recv_pkt, recv_pkt_len + this_read) < 0) {
396 fprintf(stderr,
"Error receiving response to write\n");
411 fprintf(stderr,
"SMB_Read failed with errorclass = %i, Error Code = %i\n",
456 File_Handle -> fileloc = offset;
461 File_Handle -> fileloc = File_Handle -> fileloc + offset;
466 File_Handle -> fileloc = File_Handle ->
size + offset;
474 return(File_Handle -> fileloc);
486 int pkt_len, i, this_write, max_write_data, bytes_left = numbytes;
493 if (data_ptr ==
NULL) {
528 max_write_data = (File_Handle -> tree -> mbs) - pkt_len;
532 while (bytes_left > 0) {
536 this_write = (bytes_left > max_write_data?max_write_data:bytes_left);
539 data_ptr ->
len = this_write;
540 data_ptr ->
data =
data + tot_written;
542 pkt ->
next = data_ptr;
557 if (
RFCNB_Send(File_Handle -> tree -> con -> Trans_Connect, pkt, pkt_len + this_write) < 0) {
560 fprintf(stderr,
"Error sending write request\n");
573 if (
RFCNB_Recv(File_Handle -> tree -> con -> Trans_Connect, pkt, pkt_len) < 0) {
576 fprintf(stderr,
"Error receiving response to write\n");
590 fprintf(stderr,
"SMB_Write failed with errorclass = %i, Error Code = %i\n",
606 tot_written = tot_written + this_write;
607 bytes_left = bytes_left - this_write;
612 File_Handle -> fileloc = File_Handle -> fileloc + this_write;
615 fprintf(stderr,
"--This_write = %i, bytes_left = %i\n",
616 this_write, bytes_left);
641 int pkt_len, param_len;
647 file_tmp = File_Handle;
649 if (File_Handle ==
NULL) {
654 fprintf(stderr,
"Could not allocate file handle space ...");
665 file_tmp ->
tree = Tree_Handle;
666 file_tmp ->
fid = 0xFFFF;
668 param_len = strlen(file_name) + 2;
676 if (File_Handle ==
NULL)
703 strcpy(p+1, file_name);
704 p = p + strlen(file_name);
709 if (
RFCNB_Send(Tree_Handle -> con -> Trans_Connect, pkt, pkt_len) < 0) {
712 fprintf(stderr,
"Error sending Open request\n");
715 if (File_Handle ==
NULL)
726 fprintf(stderr,
"Pkt_Len for Create resp = %i\n", pkt_len);
729 if (
RFCNB_Recv(Tree_Handle -> con -> Trans_Connect, pkt, pkt_len) < 0) {
732 fprintf(stderr,
"Error receiving response to create request\n");
735 if (File_Handle ==
NULL)
748 fprintf(stderr,
"SMB_Create failed with errorclass = %i, Error Code = %i\n",
753 if (File_Handle ==
NULL)
763 file_tmp -> lastmod = 0;
764 file_tmp ->
size = 0;
766 file_tmp -> fileloc = 0;
771 fprintf(stderr,
"SMB_Create succeeded, FID = %i\n", file_tmp -> fid);
784 int pkt_len, param_len;
787 param_len = strlen(file_name) + 2;
817 strcpy(p+1, file_name);
818 p = p + strlen(file_name);
823 if (
RFCNB_Send(tree -> con -> Trans_Connect, pkt, pkt_len) < 0) {
826 fprintf(stderr,
"Error sending Delete request\n");
837 if (
RFCNB_Recv(tree -> con -> Trans_Connect, pkt, pkt_len) < 0) {
840 fprintf(stderr,
"Error receiving response to delete request\n");
854 fprintf(stderr,
"SMB_Delete failed with errorclass = %i, Error Code = %i\n",
867 fprintf(stderr,
"File %s deleted successfully.\n", file_name);
881 int pkt_len, param_len;
884 param_len = strlen(dir_name) + 2;
913 strcpy(p+1, dir_name);
914 p = p + strlen(dir_name);
919 if (
RFCNB_Send(tree -> con -> Trans_Connect, pkt, pkt_len) < 0) {
922 fprintf(stderr,
"Error sending Create Dir request\n");
933 if (
RFCNB_Recv(tree -> con -> Trans_Connect, pkt, pkt_len) < 0) {
936 fprintf(stderr,
"Error receiving response to Create Dir request\n");
950 fprintf(stderr,
"SMB_Create_Dir failed with errorclass = %i, Error Code = %i\n",
963 fprintf(stderr,
"Directory %s created successfully.\n", dir_name);
977 int pkt_len, param_len;
980 param_len = strlen(dir_name) + 2;
1009 strcpy(p+1, dir_name);
1010 p = p + strlen(dir_name);
1015 if (
RFCNB_Send(tree -> con -> Trans_Connect, pkt, pkt_len) < 0) {
1018 fprintf(stderr,
"Error sending Delete Dir request\n");
1029 if (
RFCNB_Recv(tree -> con -> Trans_Connect, pkt, pkt_len) < 0) {
1032 fprintf(stderr,
"Error receiving response to Delete Dir request\n");
1046 fprintf(stderr,
"SMB_Delete_Dir failed with errorclass = %i, Error Code = %i\n",
1059 fprintf(stderr,
"Directory %s deleted successfully.\n", dir_name);
1073 int pkt_len, param_len;
1076 param_len = strlen(dir_name) + 2;
1105 strcpy(p+1, dir_name);
1106 p = p + strlen(dir_name);
1111 if (
RFCNB_Send(tree -> con -> Trans_Connect, pkt, pkt_len) < 0) {
1114 fprintf(stderr,
"Error sending Check Dir Path request\n");
1125 if (
RFCNB_Recv(tree -> con -> Trans_Connect, pkt, pkt_len) < 0) {
1128 fprintf(stderr,
"Error receiving response to Check Dir request\n");
1142 fprintf(stderr,
"SMB_Check_Dir failed with errorclass = %i, Error Code = %i\n",
1155 fprintf(stderr,
"Directory %s checked successfully.\n", dir_name);
1176 int pkt_len, param_len, recv_param_len, recv_pkt_len, ret_count, i;
1179 param_len = strlen(dir_name) + 2 + resumekey_len + 3;
1196 if (recv_pkt ==
NULL) {
1229 strcpy(p+1, dir_name);
1230 p = p + strlen(dir_name) + 2;
1237 SSVAL(p, 0, resumekey_len);
1241 bcopy(resumekey, p, resumekey_len);
1245 if (
RFCNB_Send(tree -> con -> Trans_Connect, pkt, pkt_len) < 0) {
1248 fprintf(stderr,
"Error sending search request\n");
1260 if (
RFCNB_Recv(tree -> con -> Trans_Connect, recv_pkt, recv_pkt_len) < 0) {
1263 fprintf(stderr,
"Error receiving response to Check Dir request\n");
1278 fprintf(stderr,
"SMB_Check_Dir failed with errorclass = %i, Error Code = %i\n",
1299 for (i = 0; i < ret_count; i++) {
1301 bcopy(p, dirents[i].resume_key, 21);
1317 bcopy(p, dirents[i].filename, 13);
#define SIVAL(buf, pos, val)
#define SSVAL(buf, pos, val)
A const & max(A const &lhs, A const &rhs)
int SMB_Delete(SMB_Tree_Handle tree, char *file_name, WORD search)
SMB_File * SMB_Open(SMB_Tree_Handle Tree_Handle, SMB_File *File_Handle, char *file_name, WORD mode, WORD search)
SMB_File * SMB_Create(SMB_Tree_Handle Tree_Handle, SMB_File *File_Handle, char *file_name, WORD search)
off_t SMB_Lseek(SMB_File *File_Handle, off_t offset, int whence)
int SMB_Write(SMB_File *File_Handle, char *data, int numbytes)
int SMB_Close(SMB_File *File_Handle)
int SMB_Read(SMB_File *File_Handle, char *data, int numbytes)
int SMB_Check_Dir(SMB_Tree_Handle tree, char *dir_name)
int SMB_Search(SMB_Tree_Handle tree, char *dir_name, WORD search, SMB_CP_dirent *dirents, int direntc, char *resumekey, int resumekey_len)
int SMB_Create_Dir(SMB_Tree_Handle tree, char *dir_name)
int SMB_Delete_Dir(SMB_Tree_Handle tree, char *dir_name)
struct RFCNB_Pkt * RFCNB_Alloc_Pkt(int n)
void RFCNB_Free_Pkt(struct RFCNB_Pkt *pkt)
int RFCNB_Send(struct RFCNB_Con *Con_Handle, struct RFCNB_Pkt *udata, int Length)
int RFCNB_Recv(void *Con_Handle, struct RFCNB_Pkt *Data, int Length)
#define SMBlibE_SendFailed
#define SMBlibE_RecvFailed
#define SMB_searchr_dirent_len
#define SMB_openr_tim_offset
#define SMB_write_bcc_offset
#define SMB_creat_bcc_offset
#define SMB_deletdir_buf_offset
#define SMB_openr_fsz_offset
#define SMB_search_atr_offset
#define SMB_hdr_rcls_offset
#define SMB_hdr_flg_offset
#define SMB_write_cnt_offset
#define SMB_readr_cnt_offset
#define SMB_hdr_wct_offset
#define SMB_search_mdc_offset
#define SMB_searchr_dec_offset
#define SMB_searchr_buf_offset
#define SMB_open_buf_offset
#define SMB_delet_sat_offset
#define SMB_read_bcc_offset
#define SMB_open_atr_offset
#define SMB_write_buf_offset
#define SMB_checkdir_buf_offset
#define SMB_deletdir_bcc_offset
#define SMB_hdr_err_offset
#define SMB_search_buf_offset
#define SMB_write_fid_offset
#define SMB_creatdir_buf_offset
#define SMBvariableblockID
#define SMB_read_ofs_offset
#define SMB_openr_acc_offset
#define SMB_write_clf_offset
#define SMB_creat_dat_offset
#define SMB_hdr_mid_offset
#define SMB_clos_tim_offset
#define SMB_hdr_idf_offset
#define SMB_read_cnt_offset
#define SMB_hdr_uid_offset
#define SMB_read_fid_offset
#define SMB_creat_tim_offset
#define SMB_hdr_pid_offset
#define SMB_checkdir_bcc_offset
#define SMB_read_clf_offset
#define SMB_open_mod_offset
#define SMB_delet_bcc_offset
#define SMB_open_bcc_offset
#define SMB_search_bcc_offset
#define SMB_creat_buf_offset
#define SMB_hdr_flg2_offset
#define SMB_openr_fid_offset
#define SMB_creatdir_bcc_offset
#define SMB_write_ofs_offset
#define SMB_hdr_tid_offset
#define SMB_clos_fid_offset
#define SMB_delet_buf_offset
#define SMB_creat_atr_offset
#define SMB_creatr_fid_offset
#define SMB_hdr_com_offset
#define SMB_clos_bcc_offset
unsigned char file_attributes