2 Unix SMB/Netbios implementation.
4 Shared memory functions
5 Copyright (C) Erik Devriendt 1996-1997
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #ifdef FAST_SHARE_MODES
29 extern int DEBUGLEVEL;
32 #define SMB_SHM_MAGIC 0x53484100
35 #define SMB_SHM_VERSION 2
37 /* WARNING : offsets are used because mmap() does not guarantee that all processes have the
38 shared memory mapped to the same address */
44 int total_size; /* in bytes */
46 smb_shm_offset_t first_free_off;
47 smb_shm_offset_t userdef_off; /* a userdefined offset. can be used to store root of tree or list */
48 struct { /* a cell is a range of bytes of sizeof(struct SmbShmBlockDesc) size */
51 int cells_system; /* number of cells used as allocated block descriptors */
55 #define SMB_SHM_NOT_FREE_OFF (-1)
56 struct SmbShmBlockDesc
58 smb_shm_offset_t next; /* offset of next block in the free list or SMB_SHM_NOT_FREE_OFF when block in use */
59 int size; /* user size in BlockDescSize units */
62 #define EOList_Addr (struct SmbShmBlockDesc *)( 0 )
63 #define EOList_Off (NULL_OFFSET)
65 #define CellSize sizeof(struct SmbShmBlockDesc)
67 /* HeaderSize aligned on 8 byte boundary */
68 #define AlignedHeaderSize ((sizeof(struct SmbShmHeader)+7) & ~7)
70 static int smb_shm_fd = -1;
71 static pstring smb_shm_processreg_name = "";
73 static struct SmbShmHeader *smb_shm_header_p = (struct SmbShmHeader *)0;
74 static int smb_shm_times_locked = 0;
76 static BOOL smb_shm_initialize_called = False;
78 static BOOL smb_shm_global_lock(void)
82 DEBUG(0,("ERROR smb_shm_global_lock : bad smb_shm_fd (%d)\n",smb_shm_fd));
86 smb_shm_times_locked++;
88 if(smb_shm_times_locked > 1)
90 DEBUG(2,("smb_shm_global_lock : locked %d times\n",smb_shm_times_locked));
94 /* Do an exclusive wait lock on the first byte of the file */
95 if (fcntl_lock(smb_shm_fd, F_SETLKW, 0, 1, F_WRLCK) == False)
97 DEBUG(0,("ERROR smb_shm_global_lock : fcntl_lock failed with code %d\n",errno));
98 smb_shm_times_locked--;
106 static BOOL smb_shm_global_unlock(void)
110 DEBUG(0,("ERROR smb_shm_global_unlock : bad smb_shm_fd (%d)\n",smb_shm_fd));
114 if(smb_shm_times_locked == 0)
116 DEBUG(0,("ERROR smb_shm_global_unlock : shmem not locked\n",smb_shm_fd));
120 smb_shm_times_locked--;
122 if(smb_shm_times_locked > 0)
124 DEBUG(2,("smb_shm_global_unlock : still locked %d times\n",smb_shm_times_locked));
128 /* Do a wait unlock on the first byte of the file */
129 if (fcntl_lock(smb_shm_fd, F_SETLKW, 0, 1, F_UNLCK) == False)
131 DEBUG(0,("ERROR smb_shm_global_unlock : fcntl_lock failed with code %d\n",errno));
132 smb_shm_times_locked++;
141 * Function to create the hash table for the share mode entries. Called
142 * when smb shared memory is global locked.
145 BOOL smb_shm_create_hash_table( unsigned int size )
147 size *= sizeof(smb_shm_offset_t);
149 smb_shm_global_lock();
150 smb_shm_header_p->userdef_off = smb_shm_alloc( size );
152 if(smb_shm_header_p->userdef_off == NULL_OFFSET)
154 DEBUG(0,("smb_shm_create_hash_table: Failed to create hash table of size %d\n",size));
155 smb_shm_global_unlock();
159 /* Clear hash buckets. */
160 memset( smb_shm_offset2addr(smb_shm_header_p->userdef_off), '\0', size);
161 smb_shm_global_unlock();
165 static BOOL smb_shm_register_process(char *processreg_file, pid_t pid, BOOL *other_processes)
167 int smb_shm_processes_fd = -1;
170 int seek_back = -sizeof(other_pid);
174 #ifndef SECURE_SHARE_MODES
175 smb_shm_processes_fd = open(processreg_file, O_RDWR | O_CREAT, 0666);
176 #else /* SECURE_SHARE_MODES */
177 smb_shm_processes_fd = open(processreg_file, O_RDWR | O_CREAT, 0600);
178 #endif /* SECURE_SHARE_MODES */
179 if ( smb_shm_processes_fd < 0 )
181 DEBUG(0,("ERROR smb_shm_register_process : processreg_file open failed with code %d\n",errno));
185 *other_processes = False;
187 while ((nb_read = read(smb_shm_processes_fd, &other_pid, sizeof(other_pid))) > 0)
191 if(process_exists(other_pid))
192 *other_processes = True;
196 DEBUG(2,("smb_shm_register_process : erasing stale record for pid %d (seek_back = %d)\n",
197 other_pid, seek_back));
198 other_pid = (pid_t)0;
199 erased_slot = lseek(smb_shm_processes_fd, seek_back, SEEK_CUR);
200 write(smb_shm_processes_fd, &other_pid, sizeof(other_pid));
202 free_slot = erased_slot;
207 free_slot = lseek(smb_shm_processes_fd, seek_back, SEEK_CUR);
211 DEBUG(0,("ERROR smb_shm_register_process : processreg_file read failed with code %d\n",errno));
212 close(smb_shm_processes_fd);
217 free_slot = lseek(smb_shm_processes_fd, 0, SEEK_END);
219 DEBUG(2,("smb_shm_register_process : writing record for pid %d at offset %d\n",pid,free_slot));
220 lseek(smb_shm_processes_fd, free_slot, SEEK_SET);
221 if(write(smb_shm_processes_fd, &pid, sizeof(pid)) < 0)
223 DEBUG(0,("ERROR smb_shm_register_process : processreg_file write failed with code %d\n",errno));
224 close(smb_shm_processes_fd);
228 close(smb_shm_processes_fd);
233 static BOOL smb_shm_unregister_process(char *processreg_file, pid_t pid)
236 int smb_shm_processes_fd = -1;
239 int seek_back = -sizeof(other_pid);
244 old_umask = umask(0);
245 smb_shm_processes_fd = open(processreg_file, O_RDWR);
247 if ( smb_shm_processes_fd < 0 )
249 DEBUG(0,("ERROR smb_shm_unregister_process : processreg_file open failed with code %d\n",errno));
253 while ((nb_read = read(smb_shm_processes_fd, &other_pid, sizeof(other_pid))) > 0)
255 DEBUG(2,("smb_shm_unregister_process : read record for pid %d\n",other_pid));
259 DEBUG(2,("smb_shm_unregister_process : erasing record for pid %d (seek_val = %d)\n",
260 other_pid, seek_back));
261 other_pid = (pid_t)0;
262 erased_slot = lseek(smb_shm_processes_fd, seek_back, SEEK_CUR);
263 if(write(smb_shm_processes_fd, &other_pid, sizeof(other_pid)) < 0)
265 DEBUG(0,("ERROR smb_shm_unregister_process : processreg_file write failed with code %d\n",errno));
266 close(smb_shm_processes_fd);
276 DEBUG(0,("ERROR smb_shm_unregister_process : processreg_file read failed with code %d\n",errno));
277 close(smb_shm_processes_fd);
283 DEBUG(0,("ERROR smb_shm_unregister_process : couldn't find pid %d in file %s\n",pid,processreg_file));
284 close(smb_shm_processes_fd);
289 close(smb_shm_processes_fd);
295 static BOOL smb_shm_validate_header(int size)
297 if( !smb_shm_header_p )
300 DEBUG(0,("ERROR smb_shm_validate_header : shmem not mapped\n"));
304 if(smb_shm_header_p->smb_shm_magic != SMB_SHM_MAGIC)
306 DEBUG(0,("ERROR smb_shm_validate_header : bad magic\n"));
309 if(smb_shm_header_p->smb_shm_version != SMB_SHM_VERSION)
311 DEBUG(0,("ERROR smb_shm_validate_header : bad version %X\n",smb_shm_header_p->smb_shm_version));
315 if(smb_shm_header_p->total_size != size)
317 DEBUG(0,("ERROR smb_shm_validate_header : shmem size mismatch (old = %d, new = %d)\n",smb_shm_header_p->total_size,size));
321 if(!smb_shm_header_p->consistent)
323 DEBUG(0,("ERROR smb_shm_validate_header : shmem not consistent\n"));
329 static BOOL smb_shm_initialize(int size)
331 struct SmbShmBlockDesc * first_free_block_p;
333 DEBUG(2,("smb_shm_initialize : initializing shmem file of size %d\n",size));
335 if( !smb_shm_header_p )
338 DEBUG(0,("ERROR smb_shm_initialize : shmem not mapped\n"));
342 smb_shm_header_p->smb_shm_magic = SMB_SHM_MAGIC;
343 smb_shm_header_p->smb_shm_version = SMB_SHM_VERSION;
344 smb_shm_header_p->total_size = size;
345 smb_shm_header_p->first_free_off = AlignedHeaderSize;
346 smb_shm_header_p->userdef_off = NULL_OFFSET;
348 first_free_block_p = (struct SmbShmBlockDesc *)smb_shm_offset2addr(smb_shm_header_p->first_free_off);
349 first_free_block_p->next = EOList_Off;
350 first_free_block_p->size = ( size - AlignedHeaderSize - CellSize ) / CellSize ;
352 smb_shm_header_p->statistics.cells_free = first_free_block_p->size;
353 smb_shm_header_p->statistics.cells_used = 0;
354 smb_shm_header_p->statistics.cells_system = 1;
356 smb_shm_header_p->consistent = True;
358 smb_shm_initialize_called = True;
363 static void smb_shm_solve_neighbors(struct SmbShmBlockDesc *head_p )
365 struct SmbShmBlockDesc *next_p;
367 /* Check if head_p and head_p->next are neighbors and if so join them */
368 if ( head_p == EOList_Addr ) return ;
369 if ( head_p->next == EOList_Off ) return ;
371 next_p = (struct SmbShmBlockDesc *)smb_shm_offset2addr(head_p->next);
372 if ( ( head_p + head_p->size + 1 ) == next_p)
374 head_p->size += next_p->size +1 ; /* adapt size */
375 head_p->next = next_p->next ; /* link out */
377 smb_shm_header_p->statistics.cells_free += 1;
378 smb_shm_header_p->statistics.cells_system -= 1;
384 BOOL smb_shm_open( char *file_name, int size)
387 BOOL created_new = False;
388 BOOL other_processes = True;
391 DEBUG(2,("smb_shm_open : using shmem file %s to be of size %d\n",file_name,size));
393 old_umask = umask(0);
394 #ifndef SECURE_SHARE_MODES
395 smb_shm_fd = open(file_name, O_RDWR | O_CREAT, 0666);
396 #else /* SECURE_SHARE_MODES */
397 smb_shm_fd = open(file_name, O_RDWR | O_CREAT, 0600);
398 #endif /* SECURE_SHARE_MODE */
400 if ( smb_shm_fd < 0 )
402 DEBUG(0,("ERROR smb_shm_open : open failed with code %d\n",errno));
406 if (!smb_shm_global_lock())
408 DEBUG(0,("ERROR smb_shm_open : can't do smb_shm_global_lock\n"));
412 if( (filesize = lseek(smb_shm_fd, 0, SEEK_END)) < 0)
414 DEBUG(0,("ERROR smb_shm_open : lseek failed with code %d\n",errno));
415 smb_shm_global_unlock();
420 /* return the file offset to 0 to save on later seeks */
421 lseek(smb_shm_fd,0,SEEK_SET);
425 /* we just created a new one */
429 /* to find out if some other process is already mapping the file,
430 we use a registration file containing the processids of the file mapping processes
433 /* construct processreg file name */
434 strcpy(smb_shm_processreg_name, file_name);
435 strcat(smb_shm_processreg_name, ".processes");
437 if (! smb_shm_register_process(smb_shm_processreg_name, getpid(), &other_processes))
439 smb_shm_global_unlock();
444 if (created_new || !other_processes)
446 /* we just created a new one, or are the first opener, lets set it size */
447 if( ftruncate(smb_shm_fd, size) <0)
449 DEBUG(0,("ERROR smb_shm_open : ftruncate failed with code %d\n",errno));
450 smb_shm_unregister_process(smb_shm_processreg_name, getpid());
451 smb_shm_global_unlock();
457 lseek(smb_shm_fd,0,SEEK_SET);
462 if (size != filesize )
464 /* the existing file has a different size and we are not the first opener.
465 Since another process is still using it, we will use the file size */
466 DEBUG(0,("WARNING smb_shm_open : filesize (%d) != expected size (%d), using filesize\n",filesize,size));
470 smb_shm_header_p = (struct SmbShmHeader *)mmap( NULL, size, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, smb_shm_fd, 0);
471 /* WARNING, smb_shm_header_p can be different for different processes mapping the same file ! */
472 if (smb_shm_header_p == (struct SmbShmHeader *)(-1))
474 DEBUG(0,("ERROR smb_shm_open : mmap failed with code %d\n",errno));
475 smb_shm_unregister_process(smb_shm_processreg_name, getpid());
476 smb_shm_global_unlock();
482 if (created_new || !other_processes)
484 smb_shm_initialize(size);
485 /* Create the hash buckets for the share file entries. */
486 smb_shm_create_hash_table( lp_shmem_hash_size() );
488 else if (!smb_shm_validate_header(size) )
490 /* existing file is corrupt, samba admin should remove it by hand */
491 DEBUG(0,("ERROR smb_shm_open : corrupt shared mem file, remove it manually\n"));
492 munmap((caddr_t)smb_shm_header_p, size);
493 smb_shm_unregister_process(smb_shm_processreg_name, getpid());
494 smb_shm_global_unlock();
499 smb_shm_global_unlock();
505 BOOL smb_shm_close( void )
508 if(smb_shm_initialize_called == False)
511 DEBUG(2,("smb_shm_close\n"));
512 if(smb_shm_times_locked > 0)
513 DEBUG(0,("WARNING smb_shm_close : shmem was still locked %d times\n",smb_shm_times_locked));;
514 if ((smb_shm_header_p != NULL) &&
515 (munmap((caddr_t)smb_shm_header_p, smb_shm_header_p->total_size) < 0))
517 DEBUG(0,("ERROR smb_shm_close : munmap failed with code %d\n",errno));
520 smb_shm_global_lock();
521 DEBUG(2,("calling smb_shm_unregister_process(%s, %d)\n", smb_shm_processreg_name, getpid()));
522 smb_shm_unregister_process(smb_shm_processreg_name, getpid());
523 smb_shm_global_unlock();
528 smb_shm_processreg_name[0] = '\0';
530 smb_shm_header_p = (struct SmbShmHeader *)0;
531 smb_shm_times_locked = 0;
536 smb_shm_offset_t smb_shm_alloc(int size)
539 struct SmbShmBlockDesc *scanner_p;
540 struct SmbShmBlockDesc *prev_p;
541 struct SmbShmBlockDesc *new_p;
542 smb_shm_offset_t result_offset;
545 if( !smb_shm_header_p )
548 DEBUG(0,("ERROR smb_shm_alloc : shmem not mapped\n"));
552 smb_shm_global_lock();
554 if( !smb_shm_header_p->consistent)
556 DEBUG(0,("ERROR smb_shm_alloc : shmem not consistent\n"));
557 smb_shm_global_unlock();
562 /* calculate the number of cells */
563 num_cells = (size + CellSize -1) / CellSize;
565 /* set start of scan */
566 prev_p = (struct SmbShmBlockDesc *)smb_shm_offset2addr(smb_shm_header_p->first_free_off);
569 /* scan the free list to find a matching free space */
570 while ( ( scanner_p != EOList_Addr ) && ( scanner_p->size < num_cells ) )
573 scanner_p = (struct SmbShmBlockDesc *)smb_shm_offset2addr(scanner_p->next);
576 /* at this point scanner point to a block header or to the end of the list */
577 if ( scanner_p == EOList_Addr )
579 DEBUG(0,("ERROR smb_shm_alloc : alloc of %d bytes failed, no free space found\n",size));
580 smb_shm_global_unlock();
581 return (NULL_OFFSET);
584 /* going to modify shared mem */
585 smb_shm_header_p->consistent = False;
587 /* if we found a good one : scanner == the good one */
588 if ( scanner_p->size <= num_cells + 2 )
590 /* there is no use in making a new one, it will be too small anyway
591 * we will link out scanner
593 if ( prev_p == scanner_p )
595 smb_shm_header_p->first_free_off = scanner_p->next ;
599 prev_p->next = scanner_p->next ;
601 smb_shm_header_p->statistics.cells_free -= scanner_p->size;
602 smb_shm_header_p->statistics.cells_used += scanner_p->size;
607 new_p = scanner_p + 1 + num_cells;
608 new_p->size = scanner_p->size - num_cells - 1;
609 new_p->next = scanner_p->next;
610 scanner_p->size = num_cells;
611 scanner_p->next = smb_shm_addr2offset(new_p);
613 if ( prev_p != scanner_p )
615 prev_p->next = smb_shm_addr2offset(new_p) ;
619 smb_shm_header_p->first_free_off = smb_shm_addr2offset(new_p) ;
621 smb_shm_header_p->statistics.cells_free -= num_cells+1;
622 smb_shm_header_p->statistics.cells_used += num_cells;
623 smb_shm_header_p->statistics.cells_system += 1;
626 result_offset = smb_shm_addr2offset( &(scanner_p[1]) );
627 scanner_p->next = SMB_SHM_NOT_FREE_OFF ;
629 /* end modification of shared mem */
630 smb_shm_header_p->consistent = True;
632 DEBUG(2,("smb_shm_alloc : request for %d bytes, allocated %d bytes at offset %d\n",size,scanner_p->size*CellSize,result_offset ));
634 smb_shm_global_unlock();
635 return ( result_offset );
640 BOOL smb_shm_free(smb_shm_offset_t offset)
642 struct SmbShmBlockDesc *header_p ; /* pointer to header of block to free */
643 struct SmbShmBlockDesc *scanner_p ; /* used to scan the list */
644 struct SmbShmBlockDesc *prev_p ; /* holds previous in the list */
646 if( !smb_shm_header_p )
649 DEBUG(0,("ERROR smb_shm_free : shmem not mapped\n"));
653 smb_shm_global_lock();
655 if( !smb_shm_header_p->consistent)
657 DEBUG(0,("ERROR smb_shm_free : shmem not consistent\n"));
658 smb_shm_global_unlock();
662 header_p = ( (struct SmbShmBlockDesc *)smb_shm_offset2addr(offset) - 1); /* make pointer to header of block */
664 if (header_p->next != SMB_SHM_NOT_FREE_OFF)
666 DEBUG(0,("ERROR smb_shm_free : bad offset (%d)\n",offset));
667 smb_shm_global_unlock();
671 /* find a place in the free_list to put the header in */
673 /* set scanner and previous pointer to start of list */
674 prev_p = (struct SmbShmBlockDesc *)smb_shm_offset2addr(smb_shm_header_p->first_free_off);
677 while ( ( scanner_p != EOList_Addr) && (scanner_p < header_p) ) /* while we didn't scan past its position */
680 scanner_p = (struct SmbShmBlockDesc *)smb_shm_offset2addr(scanner_p->next);
683 smb_shm_header_p->consistent = False;
685 DEBUG(2,("smb_shm_free : freeing %d bytes at offset %d\n",header_p->size*CellSize,offset));
687 if ( scanner_p == prev_p )
689 smb_shm_header_p->statistics.cells_free += header_p->size;
690 smb_shm_header_p->statistics.cells_used -= header_p->size;
692 /* we must free it at the beginning of the list */
693 smb_shm_header_p->first_free_off = smb_shm_addr2offset(header_p); /* set the free_list_pointer to this block_header */
695 /* scanner is the one that was first in the list */
696 header_p->next = smb_shm_addr2offset(scanner_p);
697 smb_shm_solve_neighbors( header_p ); /* if neighbors then link them */
699 smb_shm_header_p->consistent = True;
700 smb_shm_global_unlock();
705 smb_shm_header_p->statistics.cells_free += header_p->size;
706 smb_shm_header_p->statistics.cells_used -= header_p->size;
708 prev_p->next = smb_shm_addr2offset(header_p);
709 header_p->next = smb_shm_addr2offset(scanner_p);
710 smb_shm_solve_neighbors(header_p) ;
711 smb_shm_solve_neighbors(prev_p) ;
713 smb_shm_header_p->consistent = True;
714 smb_shm_global_unlock();
719 smb_shm_offset_t smb_shm_get_userdef_off(void)
721 if (!smb_shm_header_p)
724 return smb_shm_header_p->userdef_off;
727 BOOL smb_shm_set_userdef_off(smb_shm_offset_t userdef_off)
729 if (!smb_shm_header_p)
732 smb_shm_header_p->userdef_off = userdef_off;
736 void * smb_shm_offset2addr(smb_shm_offset_t offset)
738 if (offset == NULL_OFFSET )
741 if (!smb_shm_header_p)
744 return (void *)((char *)smb_shm_header_p + offset );
747 smb_shm_offset_t smb_shm_addr2offset(void *addr)
752 if (!smb_shm_header_p)
755 return (smb_shm_offset_t)((char *)addr - (char *)smb_shm_header_p);
758 /*******************************************************************
759 Lock a particular hash bucket entry.
760 ******************************************************************/
762 BOOL smb_shm_lock_hash_entry( unsigned int entry)
764 int start = (smb_shm_header_p->userdef_off + (entry * sizeof(smb_shm_offset_t)));
768 DEBUG(0,("ERROR smb_shm_lock_hash_entry : bad smb_shm_fd (%d)\n",smb_shm_fd));
772 if(entry >= lp_shmem_hash_size())
774 DEBUG(0,("ERROR smb_shm_lock_hash_entry : hash entry size too big (%d)\n", entry));
778 /* Do an exclusive wait lock on the 4 byte region mapping into this entry */
779 if (fcntl_lock(smb_shm_fd, F_SETLKW, start, sizeof(smb_shm_offset_t), F_WRLCK) == False)
781 DEBUG(0,("ERROR smb_shm_lock_hash_entry : fcntl_lock failed with code %d\n",errno));
785 DEBUG(9,("smb_shm_lock_hash_entry: locked hash bucket %d\n", entry));
789 /*******************************************************************
790 Unlock a particular hash bucket entry.
791 ******************************************************************/
793 BOOL smb_shm_unlock_hash_entry( unsigned int entry )
795 int start = (smb_shm_header_p->userdef_off + (entry * sizeof(smb_shm_offset_t)));
799 DEBUG(0,("ERROR smb_shm_unlock_hash_entry : bad smb_shm_fd (%d)\n",smb_shm_fd));
803 if(entry >= lp_shmem_hash_size())
805 DEBUG(0,("ERROR smb_shm_unlock_hash_entry : hash entry size too big (%d)\n", entry));
809 /* Do a wait lock on the 4 byte region mapping into this entry */
810 if (fcntl_lock(smb_shm_fd, F_SETLKW, start, sizeof(smb_shm_offset_t), F_UNLCK) == False)
812 DEBUG(0,("ERROR smb_shm_unlock_hash_entry : fcntl_lock failed with code %d\n",errno));
816 DEBUG(9,("smb_shm_unlock_hash_entry: unlocked hash bucket %d\n", entry));
820 /*******************************************************************
821 Gather statistics on shared memory usage.
822 ******************************************************************/
824 BOOL smb_shm_get_usage(int *bytes_free,
828 if( !smb_shm_header_p )
831 DEBUG(0,("ERROR smb_shm_free : shmem not mapped\n"));
834 *bytes_free = smb_shm_header_p->statistics.cells_free * CellSize;
835 *bytes_used = smb_shm_header_p->statistics.cells_used * CellSize;
836 *bytes_overhead = smb_shm_header_p->statistics.cells_system * CellSize + AlignedHeaderSize;
841 #else /* FAST_SHARE_MODES */
842 int shmem_dummy_procedure(void)
844 #endif /* FAST_SHARE_MODES */