Ejemplo n.º 1
0
/*===========================================================================*
 *				fs_mknod				     *
 *===========================================================================*/
PUBLIC int fs_mknod()
{
  struct inode *ip, *ldirp;
  char lastc[NAME_MAX];
  phys_bytes len;

  /* Copy the last component and set up caller's user and group id */
  len = min( (unsigned) fs_m_in.REQ_PATH_LEN, sizeof(lastc));
  err_code = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
  			    (vir_bytes) 0, (vir_bytes) lastc, (size_t) len, D);
  if (err_code != OK) return err_code;
  NUL(lastc, len, sizeof(lastc));
  
  caller_uid = (uid_t) fs_m_in.REQ_UID;
  caller_gid = (gid_t) fs_m_in.REQ_GID;
  
  /* Get last directory inode */
  if((ldirp = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
	  return(ENOENT);

  /* Try to create the new node */
  ip = new_node(ldirp, lastc, (mode_t) fs_m_in.REQ_MODE,
  		(zone_t) fs_m_in.REQ_DEV);

  put_inode(ip);
  put_inode(ldirp);
  return(err_code);
}
Ejemplo n.º 2
0
void Browser::createSearchMenu(Widget parent)
{
    ASSERT(parent);

    Widget pulldown;

    //
    // Create "Search" menu and options.
    //
    pulldown =
        this->searchMenuPulldown =
            XmCreatePulldownMenu(parent, "browSearchMenuPulldown", 
		NUL(ArgList), 0);

    this->searchMenu =
        XtVaCreateManagedWidget
            ("browSearchMenu",
             xmCascadeButtonWidgetClass,
             parent,
             XmNsubMenuId, pulldown,
             NULL);

    this->searchOption =
        new ButtonInterface(pulldown,
                            "browSearchOption",
                            this->searchCmd);

    Browser::AddHelpCallbacks(pulldown);
}
Ejemplo n.º 3
0
void OpenGLWindow::resizeGl()
{
    context->makeCurrent(this);

    renderer->setSize(width(), height());
    renderer->pMatrix.setToIdentity();
    float FOVvert = 60.0;
    float aspectRatio = (float) width() / (float) height();
    float nearPlane = 0.1;
    float farPlane = 1000;
    renderer->pMatrix.perspective(FOVvert, aspectRatio, nearPlane, farPlane);

#define PI 3.14159265359

    //Near
    float nearVert = nearPlane*tanf(FOVvert/2 * PI/180);
    float nearHorz = nearVert*aspectRatio;
    //qDebug() << "nearVert" << nearVert;
    //qDebug() << "nearHorz" << nearHorz;
    QVector4D NLL(-nearHorz,-nearVert,-nearPlane,1);
    QVector4D NLR(nearHorz,-nearVert,-nearPlane,1);
    QVector4D NUL(-nearHorz,nearVert,-nearPlane,1);
    QVector4D NUR(nearHorz,nearVert,-nearPlane,1);

    //Far
    float farVert = farPlane*tanf(FOVvert/2 * PI/180);
    float farHorz = farVert*aspectRatio;
    //qDebug() << "farVert" << farVert;
    //qDebug() << "farHorz" << farHorz;
    QVector4D FLL(-farHorz,-farVert,-farPlane,1);
    QVector4D FLR(farHorz,-farVert,-farPlane,1);
    QVector4D FUL(-farHorz,farVert,-farPlane,1);
    QVector4D FUR(farHorz,farVert,-farPlane,1);

    renderer->frustumCorners.clear();
    renderer->frustumCorners.push_back(NLL);
    renderer->frustumCorners.push_back(NLR);
    renderer->frustumCorners.push_back(NUL);
    renderer->frustumCorners.push_back(NUR);
    renderer->frustumCorners.push_back(FLL);
    renderer->frustumCorners.push_back(FLR);
    renderer->frustumCorners.push_back(FUL);
    renderer->frustumCorners.push_back(FUR);
/*
    qDebug() << "NLL" << NLL;
    qDebug() << "NLR" << NLR;
    qDebug() << "NUL" << NUL;
    qDebug() << "NUR" << NUR;
    qDebug() << "FLL" << FLL;
    qDebug() << "FLR" << FLR;
    qDebug() << "FUL" << FUL;
    qDebug() << "FUR" << FUR;
*/

    renderer->pMatrixInv = renderer->pMatrix;
    renderer->pMatrixInv.inverted();

    glViewport(0, 0, width(), height());
}
Ejemplo n.º 4
0
extern "C" Boolean VPERoot_MoveWindowWP (XtPointer clientData)
{
    VPERoot* vper = (VPERoot*)clientData;
    ASSERT(vper);
    vper->to_be_shown->restorePosition();
    vper->move_wpid = NUL(XtWorkProcId);
    return True;
}
Ejemplo n.º 5
0
extern "C" Boolean VPERoot_ShowWindowWP (XtPointer clientData)
{
    VPERoot* vper = (VPERoot*)clientData;
    ASSERT(vper);
    XtVaSetValues (vper->getRootWidget(), XmNmappedWhenManaged, True, NULL);
    vper->show_wpid = NUL(XtWorkProcId);
    return True;
}
Ejemplo n.º 6
0
/*===========================================================================*
 *				fs_unlink				     *
 *===========================================================================*/
int fs_unlink()
{
/* Perform the unlink(name) or rmdir(name) system call. The code for these two
 * is almost the same.  They differ only in some condition testing.  Unlink()
 * may be used by the superuser to do dangerous things; rmdir() may not.
 */
  register struct inode *rip;
  struct inode *rldirp;
  int r;
  char string[NAME_MAX + 1];
  phys_bytes len;

  /* Copy the last component */
  len = fs_m_in.REQ_PATH_LEN; /* including trailing '\0' */
  if (len > NAME_MAX + 1 || len > EXT2_NAME_MAX + 1)
	return(ENAMETOOLONG);

  r = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
                       (vir_bytes) 0, (vir_bytes) string, (size_t) len);
  if (r != OK) return r;
  NUL(string, len, sizeof(string));

  /* Temporarily open the dir. */
  if( (rldirp = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
	  return(EINVAL);

  /* The last directory exists.  Does the file also exist? */
  rip = advance(rldirp, string, IGN_PERM);
  r = err_code;

  /* If error, return inode. */
  if(r != OK) {
	/* Mount point? */
	if (r == EENTERMOUNT || r == ELEAVEMOUNT) {
		put_inode(rip);
		r = EBUSY;
	}
	put_inode(rldirp);
	return(r);
  }

  /* Now test if the call is allowed, separately for unlink() and rmdir(). */
  if(fs_m_in.m_type == REQ_UNLINK) {
	  /* Only the su may unlink directories, but the su can unlink any
	   * dir.*/
	  if( (rip->i_mode & I_TYPE) == I_DIRECTORY) r = EPERM;

	  /* Actually try to unlink the file; fails if parent is mode 0 etc. */
	  if (r == OK) r = unlink_file(rldirp, rip, string);
  } else {
	  r = remove_dir(rldirp, rip, string); /* call is RMDIR */
  }

  /* If unlink was possible, it has been done, otherwise it has not. */
  put_inode(rip);
  put_inode(rldirp);
  return(r);
}
Ejemplo n.º 7
0
void DXAnchorWindow::createWindowsMenu(Widget parent)
{
    ASSERT(parent);
 
    Widget	    pulldown;
 
    //
    // Create "Windows" menu and options.
    //
    pulldown =
	this->windowsMenuPulldown =
	    XmCreatePulldownMenu
		(parent, "windowsMenuPulldown", NUL(ArgList), 0);
    this->windowsMenu =
	XtVaCreateManagedWidget
	    ("windowsMenu",
	     xmCascadeButtonWidgetClass,
	     parent,
	     XmNsubMenuId, pulldown,
	     NULL);
 
    if (theDXApplication->appAllowsEditorAccess())
	this->openVPEOption =
	    new ButtonInterface
		(pulldown, "openVPEOption", this->openVPECmd);
 
    if (theDXApplication->appAllowsPanelAccess()) {
	if (theDXApplication->appAllowsOpenAllPanels())
	    this->openAllControlPanelsOption =
		new ButtonInterface
		    (pulldown,
		     "openAllControlPanelsOption",
		     theDXApplication->network->getOpenAllPanelsCommand());
  
	this->openControlPanelByNameMenu =
		new CascadeMenu("openControlPanelByNameOption",pulldown);
 
	// Builds the list of control panels
	XtAddCallback(pulldown,
		      XmNmapCallback,
		      (XtCallbackProc)DXAnchorWindow_WindowsMenuMapCB,
		      (XtPointer)this);
    }
 
    this->openAllColormapEditorsOption =
	new ButtonInterface
		(pulldown, "openAllColormapEditorsOption",
			theDXApplication->openAllColormapCmd);
 
    this->messageWindowOption =
	new ButtonInterface
	    (pulldown, "messageWindowOption",
	     theDXApplication->messageWindowCmd);
 
 
}
Ejemplo n.º 8
0
PixelImageFormat::PixelImageFormat (const char *name, ImageFormatDialog *dialog) : 
    ImageFormat(name, dialog)
{
    this->dirty = 0;
    this->size_val = NUL(char*);
    this->size_text = NUL(Widget);
    this->use_nodes_resolution = TRUE;
    this->use_nodes_aspect = TRUE;
    this->size_timer = 0;
}
Ejemplo n.º 9
0
/*===========================================================================*
 *				fs_create				     *
 *===========================================================================*/
int fs_create()
{
  phys_bytes len;
  int r;
  struct inode *ldirp;
  struct inode *rip;
  mode_t omode;
  char lastc[NAME_MAX + 1];

  /* Read request message */
  omode = (mode_t) fs_m_in.REQ_MODE;
  caller_uid = (uid_t) fs_m_in.REQ_UID;
  caller_gid = (gid_t) fs_m_in.REQ_GID;

  /* Try to make the file. */

  /* Copy the last component (i.e., file name) */
  len = fs_m_in.REQ_PATH_LEN; /* including trailing '\0' */
  if (len > NAME_MAX + 1 || len > EXT2_NAME_MAX + 1)
	return(ENAMETOOLONG);

  err_code = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
			      (vir_bytes) 0, (vir_bytes) lastc, (size_t) len);
  if (err_code != OK) return err_code;
  NUL(lastc, len, sizeof(lastc));

  /* Get last directory inode (i.e., directory that will hold the new inode) */
  if ((ldirp = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
	  return(ENOENT);

  /* Create a new inode by calling new_node(). */
  rip = new_node(ldirp, lastc, omode, NO_BLOCK);
  r = err_code;

  /* If an error occurred, release inode. */
  if (r != OK) {
	  put_inode(ldirp);
	  put_inode(rip);
	  return(r);
  }

  /* Reply message */
  fs_m_out.RES_INODE_NR = rip->i_num;
  fs_m_out.RES_MODE = rip->i_mode;
  fs_m_out.RES_FILE_SIZE_LO = rip->i_size;

  /* This values are needed for the execution */
  fs_m_out.RES_UID = rip->i_uid;
  fs_m_out.RES_GID = rip->i_gid;

  /* Drop parent dir */
  put_inode(ldirp);

  return(OK);
}
Ejemplo n.º 10
0
DXAnchorWindow::DXAnchorWindow(const char *name, boolean isAnchor, boolean usesMenuBar):
	DXWindow (name, isAnchor, usesMenuBar)
{
    //
    // Initialize member data.
    //
    this->fileMenu    = NUL(Widget);
    this->fileMenuPulldown    = NUL(Widget);

    this->openOption         = NUL(CommandInterface*);
    this->saveOption         = NUL(CommandInterface*);
    this->saveAsOption       = NUL(CommandInterface*);
    this->loadMacroOption    = NUL(CommandInterface*);
    this->loadMDFOption      = NUL(CommandInterface*);
    this->closeOption        = NUL(CommandInterface*);

    this->settingsCascade    = NUL(CascadeMenu*);
    this->saveCfgOption      = NUL(CommandInterface*);
    this->openCfgOption      = NUL(CommandInterface*);

    this->closeCmd =
	new CloseWindowCommand("close",this->commandScope,TRUE,this);


    if (theDXApplication->appAllowsEditorAccess()) {
	this->openVPECmd = new NoUndoAnchorCommand ("openVPE",
		this->commandScope, TRUE, this, NoUndoAnchorCommand::OpenVPE);
    } else {
	this->openVPECmd = NUL(Command*);
    }

    this->openVPEOption                = NUL(CommandInterface*);
    this->openAllControlPanelsOption   = NUL(CommandInterface*);
    this->openAllColormapEditorsOption = NUL(CommandInterface*);
    this->messageWindowOption          = NUL(CommandInterface*);
    this->onVisualProgramOption = NUL(CommandInterface*);


    // Widgets
    this->form = NUL(Widget);
    this->label = NUL(Widget);
    this->logoButton = NUL(Widget);
    this->logoMessage = NUL(Widget);

    this->timeoutId = 0;

    //
    // Install the default resources for THIS class (not the derived classes)
    //
    if (NOT DXAnchorWindow::ClassInitialized)
    {
	ASSERT(theApplication);
        DXAnchorWindow::ClassInitialized = TRUE;
	this->installDefaultResources(theApplication->getRootWidget());
    }
}
Ejemplo n.º 11
0
void ColormapEditor::createFileMenu(Widget parent)
{
    ASSERT(parent);

    Widget pulldown;

    //
    // Create "File" menu and options.
    //
    pulldown =
        this->fileMenuPulldown =
            XmCreatePulldownMenu(parent, "fileMenuPulldown", NUL(ArgList), 0);
    this->fileMenu =
        XtVaCreateManagedWidget
        ("fileMenu",
         xmCascadeButtonWidgetClass,
         parent,
         XmNsubMenuId, pulldown,
         NULL);

    this->newOption =
        new ButtonInterface(pulldown, "cmeNewOption",this->newCmd);


    boolean buttons = FALSE;
    if (this->openFileCmd) {
        this->openOption =
            new ButtonInterface(pulldown, "cmeOpenOption",this->openFileCmd);
        buttons = TRUE;
    }

    if (this->saveFileCmd) {
        this->saveAsOption =
            new ButtonInterface(pulldown, "cmeSaveAsOption", this->saveFileCmd);
        buttons = TRUE;
    }

    if (buttons)
        XtVaCreateManagedWidget
        ("optionSeparator", xmSeparatorWidgetClass, pulldown, NULL);

    this->closeOption =
        new ButtonInterface(pulldown, "cmeCloseOption", this->closeCmd);


}
Ejemplo n.º 12
0
void Browser::createMarkMenu(Widget parent)
{
    ASSERT(parent);

    Widget pulldown;

    //
    // Create "Mark" menu and options.
    //
    pulldown =
        this->fileMenuPulldown =
            XmCreatePulldownMenu(parent, "browMarkMenuPulldown",NUL(ArgList),0);

    this->markMenu =
        XtVaCreateManagedWidget
            ("browMarkMenu",
             xmCascadeButtonWidgetClass,
             parent,
             XmNsubMenuId, pulldown,
             NULL);

    this->placeMarkOption =
        new ButtonInterface(pulldown,
                            "browPlaceMarkOption",
                            this->placeMarkCmd);
    this->clearMarkOption =
        new ButtonInterface(pulldown,
                            "browClearMarkOption",
                            this->clearMarkCmd);
    this->gotoMarkOption =
        new ButtonInterface(pulldown,
                            "browGotoMarkOption",
                            this->gotoMarkCmd);

    Browser::AddHelpCallbacks(pulldown);
}
Ejemplo n.º 13
0
/*===========================================================================*
 *                             fs_slink 				     *
 *===========================================================================*/
PUBLIC int fs_slink()
{
  phys_bytes len;
  struct inode *sip;           /* inode containing symbolic link */
  struct inode *ldirp;         /* directory containing link */
  register int r;              /* error code */
  char string[NAME_MAX];       /* last component of the new dir's path name */
  struct buf *bp;              /* disk buffer for link */
    
  caller_uid = (uid_t) fs_m_in.REQ_UID;
  caller_gid = (gid_t) fs_m_in.REQ_GID;
  
  /* Copy the link name's last component */
  len = min( (unsigned) fs_m_in.REQ_PATH_LEN, sizeof(string));
  r = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
  			(vir_bytes) 0, (vir_bytes) string, (size_t) len, D);
  if (r != OK) return(r);
  NUL(string, len, sizeof(string));
  
  /* Temporarily open the dir. */
  if( (ldirp = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
	  return(EINVAL);

  /* Create the inode for the symlink. */
  sip = new_node(ldirp, string, (mode_t) (I_SYMBOLIC_LINK | RWX_MODES),
		   (zone_t) 0);

  /* Allocate a disk block for the contents of the symlink.
   * Copy contents of symlink (the name pointed to) into first disk block. */
  if( (r = err_code) == OK) {
  	bp = new_block(sip, (off_t) 0);
  	if (bp == NULL)
  		r = err_code;
  	else
  		r = sys_safecopyfrom(VFS_PROC_NR,
  				     (cp_grant_id_t) fs_m_in.REQ_GRANT3,
				     (vir_bytes) 0, (vir_bytes) bp->b_data,
				     (size_t) fs_m_in.REQ_MEM_SIZE, D);

	if(bp != NULL && r == OK) {
		bp->b_data[_MIN_BLOCK_SIZE-1] = '\0';
		sip->i_size = (off_t) strlen(bp->b_data);
		if(sip->i_size != fs_m_in.REQ_MEM_SIZE) {
			/* This can happen if the user provides a buffer
			 * with a \0 in it. This can cause a lot of trouble
			 * when the symlink is used later. We could just use
			 * the strlen() value, but we want to let the user
			 * know he did something wrong. ENAMETOOLONG doesn't
			 * exactly describe the error, but there is no
			 * ENAMETOOWRONG.
			 */
			r = ENAMETOOLONG;
		}
	}
	  
	put_block(bp, DIRECTORY_BLOCK); /* put_block() accepts NULL. */
  
	if(r != OK) {
		sip->i_nlinks = NO_LINK;
		if(search_dir(ldirp, string, NULL, DELETE, IGN_PERM) != OK)
			  panic("Symbolic link vanished");
	} 
  }

  /* put_inode() accepts NULL as a noop, so the below are safe. */
  put_inode(sip);
  put_inode(ldirp);
  
  return(r);
}
Ejemplo n.º 14
0
/*===========================================================================*
 *				fs_link 				     *
 *===========================================================================*/
int fs_link()
{
/* Perform the link(name1, name2) system call. */

  struct inode *ip, *rip;
  register int r;
  char string[MFS_NAME_MAX];
  struct inode *new_ip;
  phys_bytes len;

  len = min( (unsigned) fs_m_in.REQ_PATH_LEN, sizeof(string));
  /* Copy the link name's last component */
  r = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
  		       (vir_bytes) 0, (vir_bytes) string, (size_t) len);
  if (r != OK) return r;
  NUL(string, len, sizeof(string));
  
  /* Temporarily open the file. */
  if( (rip = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
	  return(EINVAL);
  
  /* Check to see if the file has maximum number of links already. */
  r = OK;
  if(rip->i_nlinks >= LINK_MAX)
	  r = EMLINK;

  /* Only super_user may link to directories. */
  if(r == OK)
	  if( (rip->i_mode & I_TYPE) == I_DIRECTORY && caller_uid != SU_UID) 
		  r = EPERM;

  /* If error with 'name', return the inode. */
  if (r != OK) {
	  put_inode(rip);
	  return(r);
  }

  /* Temporarily open the last dir */
  if( (ip = get_inode(fs_dev, (ino_t) fs_m_in.REQ_DIR_INO)) == NULL) {
	put_inode(rip);
	return(EINVAL);
  }

  if (ip->i_nlinks == NO_LINK) {	/* Dir does not actually exist */
  	put_inode(rip);
	put_inode(ip);
  	return(ENOENT);
  }

  /* If 'name2' exists in full (even if no space) set 'r' to error. */
  if((new_ip = advance(ip, string, IGN_PERM)) == NULL) {
	  r = err_code;
	  if(r == ENOENT)
		  r = OK;
  } else {
	  put_inode(new_ip);
	  r = EEXIST;
  }
  
  /* Try to link. */
  if(r == OK)
	  r = search_dir(ip, string, &rip->i_num, ENTER, IGN_PERM);

  /* If success, register the linking. */
  if(r == OK) {
	  rip->i_nlinks++;
	  rip->i_update |= CTIME;
	  IN_MARKDIRTY(rip);
  }
  
  /* Done.  Release both inodes. */
  put_inode(rip);
  put_inode(ip);
  return(r);
}
Ejemplo n.º 15
0
#include <dxconfig.h>
#include <defines.h>




#include <X11/cursorfont.h>
#include <Xm/Xm.h>

#include "HelpOnContextCommand.h"
#include "Application.h"
#include "MainWindow.h"


boolean HelpOnContextCommand::HelpOnContextCommandClassInitialized = FALSE;
Cursor  HelpOnContextCommand::HelpCursor = NUL(Cursor);


HelpOnContextCommand::HelpOnContextCommand(const char*   name,
					   CommandScope* scope,
					   boolean       active,
					   MainWindow*   window) :
	NoUndoCommand(name, scope, active)
{
    ASSERT(window);

    if (NOT HelpOnContextCommand::HelpOnContextCommandClassInitialized)
    {
	ASSERT(theApplication);
	HelpOnContextCommand::HelpCursor =
	    XCreateFontCursor(theApplication->getDisplay(), XC_question_arrow);
Ejemplo n.º 16
0
void ColormapEditor::createOptionsMenu(Widget parent)
{
    ASSERT(parent);

    Widget      pulldown;
    int		n;
    Arg		wargs[20];

    //
    // Create "Options" menu and options.
    //
    pulldown =
        this->optionsMenuPulldown =
            XmCreatePulldownMenu
            (parent, "optionsMenuPulldown", NUL(ArgList), 0);
    this->optionsMenu =
        XtVaCreateManagedWidget
        ("optionsMenu",
         xmCascadeButtonWidgetClass,
         parent,
         XmNsubMenuId, pulldown,
         NULL);


    this->setBackgroundOption =
        new ButtonInterface(pulldown, "cmeSetBackgroundOption", this->setBkgdCmd);

    n = 0;
    XtSetArg(wargs[n], XmNradioBehavior, True);
    n++;
    this->drawModePulldown =
        XmCreatePulldownMenu
        (pulldown, "drawModePulldown", wargs, n);

    this->drawModeButton =
        XtVaCreateManagedWidget
        ("cmeSetDrawModeOption",
         xmCascadeButtonWidgetClass,
         pulldown,
         XmNsubMenuId, this->drawModePulldown,
         XmNsensitive, TRUE,
         NULL);

    this->ticksOption =
        new ToggleButtonInterface(this->drawModePulldown,
                                  "cmeTicksOption", this->ticksCmd, TRUE);

    this->histogramOption =
        new ToggleButtonInterface(this->drawModePulldown,
                                  "cmeHistogramOption", this->histogramCmd, FALSE);

    this->logHistogramOption =
        new ToggleButtonInterface(this->drawModePulldown,
                                  "cmeLogHistogramOption", this->logHistogramCmd, FALSE);

    this->nBinsOption =
        new ButtonInterface(pulldown, "cmeNBinsOption", this->nBinsCmd);

    XtVaCreateManagedWidget
    ("optionSeparator", xmSeparatorWidgetClass, pulldown, NULL);

    n = 0;
    XtSetArg(wargs[n], XmNradioBehavior, True);
    n++;
    this->displayCPPulldown =
        XmCreatePulldownMenu
        (pulldown, "displayCPPulldown", wargs, n);

    this->displayCPButton =
        XtVaCreateManagedWidget
        ("displayCPButton",
         xmCascadeButtonWidgetClass,
         pulldown,
         XmNsubMenuId, this->displayCPPulldown,
         XmNsensitive, TRUE,
         NULL);

    this->displayCPOffOption =
        new ToggleButtonInterface(this->displayCPPulldown,
                                  "displayCPOffOption", this->displayCPOffCmd, FALSE);

    this->displayCPAllOption =
        new ToggleButtonInterface(this->displayCPPulldown,
                                  "displayCPAllOption", this->displayCPAllCmd, TRUE);

    this->displayCPSelectedOption =
        new ToggleButtonInterface(this->displayCPPulldown,
                                  "displayCPSelectedOption", this->displayCPSelectedCmd, FALSE);

    if (this->setColormapNameCmd)  {
        XtVaCreateManagedWidget
        ("optionSeparator", xmSeparatorWidgetClass, pulldown, NULL);
        this->setColormapNameOption =
            new ButtonInterface(pulldown, "setColormapNameOption",
                                this->setColormapNameCmd);
    } else
        this->setColormapNameOption = NULL;

}
Ejemplo n.º 17
0
void ColormapEditor::createEditMenu(Widget parent)
{
    ASSERT(parent);

    Widget            pulldown;

    //
    // Create "Execute" menu and options.
    //
    pulldown =
        this->editMenuPulldown =
            XmCreatePulldownMenu
            (parent, "editMenuPulldown", NUL(ArgList), 0);
    this->editMenu =
        XtVaCreateManagedWidget
        ("editMenu",
         xmCascadeButtonWidgetClass,
         parent,
         XmNsubMenuId, pulldown,
         NULL);

    XtAddCallback(pulldown,
                  XmNmapCallback,
                  (XtCallbackProc)ColormapEditor_EditMenuMapCB,
                  (XtPointer)this);

    //
    // Begin edit menu options
    //
    this->undoOption =
        new ButtonInterface(pulldown, "cmeUndoOption", this->undoCmd);

    this->copyOption =
        new ButtonInterface(pulldown, "cmeCopyOption", this->copyCmd);

    this->pasteOption =
        new ButtonInterface(pulldown, "cmePasteOption", this->pasteCmd);

    //
    // Reset maps cascade menu
    //
    CascadeMenu *cascade_menu = this->resetMapCascade =
                                    new CascadeMenu("cmeResetCascade",pulldown);
    Widget menu_parent = this->resetMapCascade->getMenuItemParent();

    CommandInterface *ci = new ButtonInterface(menu_parent,
            "cmeResetHSVOption",this->resetHSVCmd);
    cascade_menu->appendComponent(ci);
    ci = new ButtonInterface(menu_parent,
                             "cmeResetOpacityOption",this->resetOpacityCmd);
    cascade_menu->appendComponent(ci);

    ci = new ButtonInterface(menu_parent,
                             "cmeResetMinOption",this->resetMinCmd);
    cascade_menu->appendComponent(ci);
    ci = new ButtonInterface(menu_parent,
                             "cmeResetMaxOption",this->resetMaxCmd);
    cascade_menu->appendComponent(ci);

    XtVaCreateManagedWidget
    ("resetSeparator", xmSeparatorWidgetClass, menu_parent, NULL);

    ci = new ButtonInterface(menu_parent,
                             "cmeResetAllOption",this->resetAllCmd);
    cascade_menu->appendComponent(ci);
    ci = new ButtonInterface(menu_parent,
                             "cmeResetMinMaxOption",this->resetMinMaxCmd);
    cascade_menu->appendComponent(ci);

    //
    // More options
    //
    this->addControlOption =
        new ButtonInterface(pulldown, "cmeAddControlOption", this->addCtlCmd);

    this->horizontalOption =
        new ToggleButtonInterface(pulldown, "cmeHorizontalOption",
                                  this->consHCmd, False);

    this->verticalOption =
        new ToggleButtonInterface(pulldown, "cmeVerticalOption",
                                  this->consVCmd, False);

    this->waveformOption =
        new ButtonInterface(pulldown, "cmeWaveformOption", this->waveformCmd);

    XtVaCreateManagedWidget
    ("optionSeparator", xmSeparatorWidgetClass, pulldown, NULL);

    this->deleteSelectedOption =
        new ButtonInterface(pulldown, "cmeDeleteSelectedOption",
                            this->delSelectedCmd);

    this->selectAllOption =
        new ButtonInterface(pulldown, "cmeSelectAllOption",
                            this->selectAllCmd);

}
Ejemplo n.º 18
0
ColormapEditor::ColormapEditor(ColormapNode*    cmnode) :
    DXWindow("colormapEditor", FALSE)
{

    //
    // Initialize member data.
    //
    this->fileMenu       = NUL(Widget);
    this->editMenu       = NUL(Widget);
    this->optionsMenu    = NUL(Widget);

    this->fileMenuPulldown       = NUL(Widget);
    this->editMenuPulldown       = NUL(Widget);
    this->optionsMenuPulldown    = NUL(Widget);
    this->colormapEditor = NUL(Widget);

    this->newOption          = NUL(CommandInterface*);
    this->openOption         = NUL(CommandInterface*);
    this->saveAsOption       = NUL(CommandInterface*);
    this->closeOption        = NUL(CommandInterface*);

    this->addControlOption = NUL(CommandInterface*);
    this->undoOption = NUL(CommandInterface*);
    this->copyOption = NUL(CommandInterface*);
    this->pasteOption = NUL(CommandInterface*);
    this->resetMapCascade	     = NULL;
    this->waveformOption = NUL(CommandInterface*);
    this->deleteSelectedOption = NUL(CommandInterface*);

    this->nBinsOption = NUL(CommandInterface*);
    this->setBackgroundOption = NUL(CommandInterface*);
    this->ticksOption = NUL(CommandInterface*);
    this->histogramOption = NUL(CommandInterface*);
    this->logHistogramOption = NUL(CommandInterface*);
    this->horizontalOption = NUL(CommandInterface*);
    this->verticalOption = NUL(CommandInterface*);
    this->onVisualProgramOption = NUL(CommandInterface*);

    this->nBinsDialog = NUL(ColormapNBinsDialog*);
    this->addCtlDialog = NUL(ColormapAddCtlDialog*);
    this->waveformDialog = NUL(ColormapWaveDialog*);
    this->setNameDialog = NULL;
    this->openColormapDialog = NUL(OpenColormapDialog*);

    this->hue_selected = 0;
    this->sat_selected = 0;
    this->val_selected = 0;
    this->op_selected = 0;
    this->selected_area = 0;

    this->constrain_vert = FALSE;
    this->constrain_hor = FALSE;
    this->background_style = STRIPES;
    this->draw_mode = CME_GRID;

    this->doingActivateCallback = FALSE;
    this->neverManaged = TRUE;

    //
    // Intialize state.
    //

    this->colormapNode = cmnode;
    const char *t = cmnode->getTitle();
    if (t)
        this->setWindowTitle(t);

    ASSERT(this->commandScope);

    //
    // Create the commands.
    //
    this->closeCmd = new CloseWindowCommand("closeWindow",
                                            this->commandScope,
                                            TRUE,
                                            this);

    this->nBinsCmd = new ColormapEditCommand("nBins",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::NBins);

    this->addCtlCmd = new ColormapEditCommand("addControlPoint",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::AddControl);

    this->undoCmd = new ColormapEditCommand("undo",
                                            this->commandScope,
                                            TRUE,
                                            this,
                                            ColormapEditCommand::Undo);

    this->copyCmd = new ColormapEditCommand("copy",
                                            this->commandScope,
                                            TRUE,
                                            this,
                                            ColormapEditCommand::Copy);

    this->pasteCmd = new ColormapEditCommand("paste",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::Paste);

    this->waveformCmd = new ColormapEditCommand("waveform",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::Waveform);

    this->delSelectedCmd = new ColormapEditCommand("deleteSelectedPoint",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::DeleteSelected);

    this->selectAllCmd = new ColormapEditCommand("selectAll",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::SelectAll);

    this->setBkgdCmd = new ColormapEditCommand("setBackground",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::SetBackground);

    this->ticksCmd = new ColormapEditCommand("ticks",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::Ticks);

    this->histogramCmd = new ColormapEditCommand("histogram",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::Histogram);

    this->logHistogramCmd = new ColormapEditCommand("logHistogram",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::LogHistogram);

    this->consVCmd = new ColormapEditCommand("constrainVertical",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::ConstrainV);

    this->consHCmd = new ColormapEditCommand("constrainHorizonal",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::ConstrainH);

    this->newCmd = new ColormapEditCommand("new",
                                           this->commandScope,
                                           TRUE,
                                           this,
                                           ColormapEditCommand::New);

    this->resetAllCmd = new ColormapEditCommand("resetALL",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::ResetAll);

    this->resetHSVCmd = new ColormapEditCommand("resetHSV",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::ResetHSV);

    this->resetOpacityCmd = new ColormapEditCommand("resetOpacity",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::ResetOpacity);

    this->resetMinMaxCmd = new ColormapEditCommand("resetMinMax",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::ResetMinMax);

    this->resetMinCmd = new ColormapEditCommand("resetMin",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::ResetMin);

    this->resetMaxCmd = new ColormapEditCommand("resetMax",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::ResetMax);

    if (theDXApplication->appAllowsCMapOpenMap())
        this->openFileCmd = new ColormapFileCommand("openFile",
                this->commandScope,
                TRUE,
                this,
                TRUE);
    else
        this->openFileCmd = NULL;


    if (theDXApplication->appAllowsCMapSaveMap())
        this->saveFileCmd = new ColormapFileCommand("saveFile",
                this->commandScope,
                TRUE,
                this,
                FALSE);
    else
        this->saveFileCmd = NULL;


    this->displayCPOffCmd = new ColormapEditCommand("displayCPOff",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::DisplayCPOff);

    this->displayCPAllCmd = new ColormapEditCommand("displayCPAll",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::DisplayCPAll);

    this->displayCPSelectedCmd = new ColormapEditCommand("displayCPSelected",
            this->commandScope,
            TRUE,
            this,
            ColormapEditCommand::DisplayCPSelected);

    // FIXME: add restriction here
    if (theDXApplication->appAllowsCMapSetName())
        this->setColormapNameCmd = new ColormapEditCommand("setColormapName",
                this->commandScope,
                TRUE,
                this,
                ColormapEditCommand::SetColormapName);
    else
        this->setColormapNameCmd = NULL;


    //
    // Install the default resources for THIS class (not the derived classes)
    //
    if (NOT ColormapEditor::ClassInitialized)
    {
        ASSERT(theApplication);
        ColormapEditor::ClassInitialized = TRUE;
        this->installDefaultResources(theApplication->getRootWidget());
    }
}
Ejemplo n.º 19
0
/*===========================================================================*
 *                             fs_slink 				     *
 *===========================================================================*/
int fs_slink()
{
  phys_bytes len;
  struct inode *sip;           /* inode containing symbolic link */
  struct inode *ldirp;         /* directory containing link */
  register int r;              /* error code */
  char string[NAME_MAX];       /* last component of the new dir's path name */
  char* link_target_buf = NULL;       /* either sip->i_block or bp->b_data */
  struct buf *bp = NULL;    /* disk buffer for link */

  caller_uid = (uid_t) fs_m_in.REQ_UID;
  caller_gid = (gid_t) fs_m_in.REQ_GID;

  /* Copy the link name's last component */
  len = fs_m_in.REQ_PATH_LEN;
  if (len > NAME_MAX || len > EXT2_NAME_MAX)
	return(ENAMETOOLONG);

  r = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
		       (vir_bytes) 0, (vir_bytes) string, (size_t) len);
  if (r != OK) return(r);
  NUL(string, len, sizeof(string));

  /* Temporarily open the dir. */
  if( (ldirp = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
	  return(EINVAL);

  /* Create the inode for the symlink. */
  sip = new_node(ldirp, string, (mode_t) (I_SYMBOLIC_LINK | RWX_MODES),
		   (block_t) 0);

  /* If we can then create fast symlink (store it in inode),
   * Otherwise allocate a disk block for the contents of the symlink and
   * copy contents of symlink (the name pointed to) into first disk block. */
  if( (r = err_code) == OK) {
	if ( (fs_m_in.REQ_MEM_SIZE + 1) > sip->i_sp->s_block_size) {
		r = ENAMETOOLONG;
	} else if ((fs_m_in.REQ_MEM_SIZE + 1) <= MAX_FAST_SYMLINK_LENGTH) {
		r = sys_safecopyfrom(VFS_PROC_NR,
				     (cp_grant_id_t) fs_m_in.REQ_GRANT3,
				     (vir_bytes) 0, (vir_bytes) sip->i_block,
                                     (vir_bytes) fs_m_in.REQ_MEM_SIZE);
		sip->i_dirt = IN_DIRTY;
		link_target_buf = (char*) sip->i_block;
        } else {
		if ((bp = new_block(sip, (off_t) 0)) != NULL) {
			sys_safecopyfrom(VFS_PROC_NR,
					 (cp_grant_id_t) fs_m_in.REQ_GRANT3,
					 (vir_bytes) 0, (vir_bytes) b_data(bp),
					 (vir_bytes) fs_m_in.REQ_MEM_SIZE);
			lmfs_markdirty(bp);
			link_target_buf = b_data(bp);
		} else {
			r = err_code;
		}
	}
	if (r == OK) {
		assert(link_target_buf);
		link_target_buf[fs_m_in.REQ_MEM_SIZE] = '\0';
		sip->i_size = (off_t) strlen(link_target_buf);
		if (sip->i_size != fs_m_in.REQ_MEM_SIZE) {
			  /* This can happen if the user provides a buffer
			   * with a \0 in it. This can cause a lot of trouble
			   * when the symlink is used later. We could just use
			   * the strlen() value, but we want to let the user
			   * know he did something wrong. ENAMETOOLONG doesn't
			   * exactly describe the error, but there is no
			   * ENAMETOOWRONG.
			   */
			  r = ENAMETOOLONG;
		  }
	}

	put_block(bp, DIRECTORY_BLOCK); /* put_block() accepts NULL. */

	if(r != OK) {
		sip->i_links_count = NO_LINK;
		if (search_dir(ldirp, string, NULL, DELETE, IGN_PERM, 0) != OK)
			panic("Symbolic link vanished");
	}
  }

  /* put_inode() accepts NULL as a noop, so the below are safe. */
  put_inode(sip);
  put_inode(ldirp);

  return(r);
}
Ejemplo n.º 20
0
/*===========================================================================*
 *				fs_mkdir				     *
 *===========================================================================*/
PUBLIC int fs_mkdir()
{
  int r1, r2;			/* status codes */
  ino_t dot, dotdot;		/* inode numbers for . and .. */
  struct inode *rip, *ldirp;
  char lastc[NAME_MAX];         /* last component */
  phys_bytes len;

  /* Copy the last component and set up caller's user and group id */
  len = min( (unsigned) fs_m_in.REQ_PATH_LEN, sizeof(lastc));
  err_code = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
  			   (vir_bytes) 0, (vir_bytes) lastc, (size_t) len, D);
  if(err_code != OK) return(err_code);
  NUL(lastc, len, sizeof(lastc));

  caller_uid = (uid_t) fs_m_in.REQ_UID;
  caller_gid = (gid_t) fs_m_in.REQ_GID;
  
  /* Get last directory inode */
  if((ldirp = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
      return(ENOENT);
  
  /* Next make the inode. If that fails, return error code. */
  rip = new_node(ldirp, lastc, (mode_t) fs_m_in.REQ_MODE, (zone_t) 0);
  
  if(rip == NULL || err_code == EEXIST) {
	  put_inode(rip);		/* can't make dir: it already exists */
	  put_inode(ldirp);
	  return(err_code);
  }
  
  /* Get the inode numbers for . and .. to enter in the directory. */
  dotdot = ldirp->i_num;	/* parent's inode number */
  dot = rip->i_num;		/* inode number of the new dir itself */

  /* Now make dir entries for . and .. unless the disk is completely full. */
  /* Use dot1 and dot2, so the mode of the directory isn't important. */
  rip->i_mode = (mode_t) fs_m_in.REQ_MODE;	/* set mode */
  r1 = search_dir(rip, dot1, &dot, ENTER, IGN_PERM);/* enter . in the new dir*/
  r2 = search_dir(rip, dot2, &dotdot, ENTER, IGN_PERM); /* enter .. in the new
							 dir */

  /* If both . and .. were successfully entered, increment the link counts. */
  if (r1 == OK && r2 == OK) {
	  /* Normal case.  It was possible to enter . and .. in the new dir. */
	  rip->i_nlinks++;	/* this accounts for . */
	  ldirp->i_nlinks++;	/* this accounts for .. */
	  ldirp->i_dirt = DIRTY;	/* mark parent's inode as dirty */
  } else {
	  /* It was not possible to enter . or .. probably disk was full -
	   * links counts haven't been touched. */
	  if(search_dir(ldirp, lastc, NULL, DELETE, IGN_PERM) != OK)
		  panic("Dir disappeared: %ul", rip->i_num);
	  rip->i_nlinks--;	/* undo the increment done in new_node() */
  }
  rip->i_dirt = DIRTY;		/* either way, i_nlinks has changed */

  put_inode(ldirp);		/* return the inode of the parent dir */
  put_inode(rip);		/* return the inode of the newly made dir */
  return(err_code);		/* new_node() always sets 'err_code' */
}
Ejemplo n.º 21
0
/*===========================================================================*
 *                              fs_link                                      *
 *===========================================================================*/
PUBLIC int fs_link()
{
    /* Perform the link(name1, name2) system call. */

    register int r;
    char string[NAME_MAX + 1];
    phys_bytes len;
    struct puffs_node *pn, *pn_dir, *new_pn;
    time_t cur_time;
    struct puffs_kcn pkcnp;
    PUFFS_MAKECRED(pcr, &global_kcred);
    struct puffs_cn pcn = {&pkcnp, (struct puffs_cred *) __UNCONST(pcr), {0,0,0}};

    if (global_pu->pu_ops.puffs_node_link == NULL)
        return(OK);

    /* Copy the link name's last component */
    len = fs_m_in.REQ_PATH_LEN;
    if (len > NAME_MAX + 1)
        return(ENAMETOOLONG);

    r = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT, 0,
                         (vir_bytes) string, (size_t) len, D);
    if (r != OK) return(r);
    NUL(string, len, sizeof(string));

    if ((pn = puffs_pn_nodewalk(global_pu, 0, &fs_m_in.REQ_INODE_NR)) == NULL)
        return(EINVAL);

    /* Check to see if the file has maximum number of links already. */
    if (pn->pn_va.va_nlink >= LINK_MAX)
        return(EMLINK);

    /* Only super_user may link to directories. */
    if ((pn->pn_va.va_mode & I_TYPE) == I_DIRECTORY && caller_uid != SU_UID)
        return(EPERM);

    if ((pn_dir = puffs_pn_nodewalk(global_pu, 0, &fs_m_in.REQ_DIR_INO)) == NULL)
        return(EINVAL);

    if (pn_dir->pn_va.va_nlink == NO_LINK) {
        /* Dir does not actually exist */
        return(ENOENT);
    }

    /* If 'name2' exists in full (even if no space) set 'r' to error. */
    if ((new_pn = advance(pn_dir, string, IGN_PERM)) == NULL) {
        r = err_code;
        if (r == ENOENT) r = OK;
    } else {
        r = EEXIST;
    }

    if (r != OK) return(r);

    /* Try to link. */
    pcn.pcn_namelen = strlen(string);
    assert(pcn.pcn_namelen <= MAXPATHLEN);
    strcpy(pcn.pcn_name, string);

    if (buildpath) {
        if (puffs_path_pcnbuild(global_pu, &pcn, pn_dir) != 0)
            return(EINVAL);
    }

    if (global_pu->pu_ops.puffs_node_link(global_pu, pn_dir, pn, &pcn) != 0)
        r = EINVAL;

    if (buildpath)
        global_pu->pu_pathfree(global_pu, &pcn.pcn_po_full);

    if (r != OK) return(EINVAL);

    cur_time = clock_time();
    update_times(pn, CTIME, cur_time);
    update_times(pn_dir, MTIME | CTIME, cur_time);

    return(OK);
}
Ejemplo n.º 22
0
/*===========================================================================*
 *                              fs_unlink                                    *
 *===========================================================================*/
PUBLIC int fs_unlink()
{
    /* Perform the unlink(name) or rmdir(name) system call. The code for these two
     * is almost the same.  They differ only in some condition testing.  Unlink()
     * may be used by the superuser to do dangerous things; rmdir() may not.
     */
    int r;
    struct puffs_node *pn, *pn_dir;
    time_t cur_time;
    struct puffs_kcn pkcnp;
    struct puffs_cn pcn = {&pkcnp, 0, {0,0,0}};
    PUFFS_KCREDTOCRED(pcn.pcn_cred, &global_kcred);
    int len;

    /* Copy the last component */
    len = fs_m_in.REQ_PATH_LEN;
    pcn.pcn_namelen = len - 1;
    if (pcn.pcn_namelen > NAME_MAX)
        return(ENAMETOOLONG);

    r = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
                         (vir_bytes) 0, (vir_bytes) pcn.pcn_name,
                         (size_t) len, D);
    if (r != OK) return (r);
    NUL(pcn.pcn_name, len, sizeof(pcn.pcn_name));

    if ((pn_dir = puffs_pn_nodewalk(global_pu, 0, &fs_m_in.REQ_INODE_NR)) == NULL)
        return(EINVAL);

    /* The last directory exists. Does the file also exist? */
    pn = advance(pn_dir, pcn.pcn_name, IGN_PERM);
    r = err_code;

    /* If error, return pnode. */
    if (r != OK) {
        /* Mount point? */
        if (r == EENTERMOUNT || r == ELEAVEMOUNT) {
            r = EBUSY;
        }
        return(r);
    }

    /* Now test if the call is allowed, separately for unlink() and rmdir(). */
    if (fs_m_in.m_type == REQ_UNLINK) {
        /* Only the su may unlink directories, but the su can unlink any dir */
        if ((pn->pn_va.va_mode & I_TYPE) == I_DIRECTORY)
            r = EPERM;
        if (r == OK)
            r = unlink_file(pn_dir, pn, &pcn);
    } else {
        r = remove_dir(pn_dir, pn, &pcn); /* call is RMDIR */
    }

    if (pn->pn_va.va_nlink != 0) {
        cur_time = clock_time();
        update_times(pn, CTIME, cur_time);
        update_times(pn_dir, MTIME | CTIME, cur_time);
    }

    /* XXX Ideally, we should check pn->pn_flags & PUFFS_NODE_REMOVED, but
     * librefuse doesn't set it (neither manually or via puffs_pn_remove() ).
     * Thus we just check that "pn_count == 0". Otherwise release_node()
     * will be called in fs_put().
     */
    if (pn->pn_count == 0)
        release_node(global_pu, pn);

    return(r);
}
Ejemplo n.º 23
0
/*===========================================================================*
 *                              fs_rename                                    *
 *===========================================================================*/
PUBLIC int fs_rename()
{
    /* Perform the rename(name1, name2) system call. */
    struct puffs_node *old_dirp, *old_ip;      /* ptrs to old dir, file pnodes */
    struct puffs_node *new_dirp, *new_ip;      /* ptrs to new dir, file pnodes */
    struct puffs_kcn pkcnp_src;
    PUFFS_MAKECRED(pcr_src, &global_kcred);
    struct puffs_cn pcn_src = {&pkcnp_src, (struct puffs_cred *) __UNCONST(pcr_src), {0,0,0}};
    struct puffs_kcn pkcnp_dest;
    PUFFS_MAKECRED(pcr_dest, &global_kcred);
    struct puffs_cn pcn_targ = {&pkcnp_dest, (struct puffs_cred *) __UNCONST(pcr_dest), {0,0,0}};
    int r = OK;                           /* error flag; initially no error */
    int odir, ndir;                       /* TRUE iff {old|new} file is dir */
    int same_pdir;                        /* TRUE iff parent dirs are the same */
    phys_bytes len;
    time_t cur_time;

    if (global_pu->pu_ops.puffs_node_rename == NULL)
        return(EINVAL);

    /* Copy the last component of the old name */
    len = fs_m_in.REQ_REN_LEN_OLD; /* including trailing '\0' */
    if (len > NAME_MAX + 1)
        return(ENAMETOOLONG);

    r = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_REN_GRANT_OLD,
                         (vir_bytes) 0, (vir_bytes) pcn_src.pcn_name, (size_t) len, D);
    if (r != OK) return(r);
    NUL(pcn_src.pcn_name, len, sizeof(pcn_src.pcn_name));
    pcn_src.pcn_namelen = len - 1;

    /* Copy the last component of the new name */
    len = fs_m_in.REQ_REN_LEN_NEW; /* including trailing '\0' */
    if (len > NAME_MAX + 1)
        return(ENAMETOOLONG);

    r = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_REN_GRANT_NEW,
                         (vir_bytes) 0, (vir_bytes) pcn_targ.pcn_name, (size_t) len, D);
    if (r != OK) return(r);
    NUL(pcn_targ.pcn_name, len, sizeof(pcn_targ.pcn_name));
    pcn_targ.pcn_namelen = len - 1;

    /* Get old dir pnode */
    if ((old_dirp = puffs_pn_nodewalk(global_pu, 0, &fs_m_in.REQ_REN_OLD_DIR))
            == NULL)
        return(ENOENT);

    old_ip = advance(old_dirp, pcn_src.pcn_name, IGN_PERM);
    if (!old_ip) {
        return(ENOENT);
    }
    r = err_code;

    if (r == EENTERMOUNT || r == ELEAVEMOUNT) {
        old_ip = NULL;
        if (r == EENTERMOUNT) r = EXDEV;        /* should this fail at all? */
        else if (r == ELEAVEMOUNT) r = EINVAL;  /* rename on dot-dot */
    }

    /* Get new dir pnode */
    if ((new_dirp = puffs_pn_nodewalk(global_pu, 0, &fs_m_in.REQ_REN_NEW_DIR))
            == NULL) {
        r = ENOENT;
    } else {
        if (new_dirp->pn_va.va_nlink == NO_LINK) {
            /* Dir does not actually exist */
            return(ENOENT);
        }
    }

    /* not required to exist */
    new_ip = advance(new_dirp, pcn_targ.pcn_name, IGN_PERM);

    /* However, if the check failed because the file does exist, don't continue.
     * Note that ELEAVEMOUNT is covered by the dot-dot check later. */
    if (err_code == EENTERMOUNT) {
        new_ip = NULL;
        r = EBUSY;
    }

    if (old_ip != NULL) {
        /* TRUE iff dir */
        odir = ((old_ip->pn_va.va_mode & I_TYPE) == I_DIRECTORY);
    } else {
        odir = FALSE;
    }

    if (r != OK) return(r);

    /* Check for a variety of possible errors. */
    same_pdir = (old_dirp == new_dirp);

    /* The old or new name must not be . or .. */
    if (strcmp(pcn_src.pcn_name, ".") == 0 ||
            strcmp(pcn_src.pcn_name, "..") == 0 ||
            strcmp(pcn_targ.pcn_name, ".") == 0 ||
            strcmp(pcn_targ.pcn_name, "..") == 0) {
        r = EINVAL;
    }

    /* Some tests apply only if the new path exists. */
    if (new_ip == NULL) {
        if (odir && (new_dirp->pn_va.va_nlink >= SHRT_MAX ||
                     new_dirp->pn_va.va_nlink >= LINK_MAX) &&
                !same_pdir && r == OK) {
            r = EMLINK;
        }
    } else {
        if (old_ip == new_ip) r = SAME; /* old=new */

        /* dir ? */
        ndir = ((new_ip->pn_va.va_mode & I_TYPE) == I_DIRECTORY);
        if (odir == TRUE && ndir == FALSE) r = ENOTDIR;
        if (odir == FALSE && ndir == TRUE) r = EISDIR;
    }

    if (r == SAME) {
        r = OK;
        goto rename_out;
    }

    if (r != OK) return(r);

    /* If a process has another root directory than the system root, we might
     * "accidently" be moving it's working directory to a place where it's
     * root directory isn't a super directory of it anymore. This can make
     * the function chroot useless. If chroot will be used often we should
     * probably check for it here. */

    /* The rename will probably work. Only two things can go wrong now:
     * 1. being unable to remove the new file. (when new file already exists)
     * 2. being unable to make the new directory entry. (new file doesn't exists)
     *     [directory has to grow by one block and cannot because the disk
     *      is completely full].
     * 3. Something (doubtfully) else depending on the FS.
     */

    if (buildpath) {
        pcn_src.pcn_po_full = old_ip->pn_po;

        if (puffs_path_pcnbuild(global_pu, &pcn_targ, new_dirp) != 0)
            return(EINVAL);
    }

    r = global_pu->pu_ops.puffs_node_rename(global_pu, old_dirp, old_ip, &pcn_src,
                                            new_dirp, new_ip, &pcn_targ);
    if (r > 0) r = -r;

    if (buildpath) {
        if (r) {
            global_pu->pu_pathfree(global_pu, &pcn_targ.pcn_po_full);
        } else {
            struct puffs_pathinfo pi;
            struct puffs_pathobj po_old;

            /* handle this node */
            po_old = old_ip->pn_po;
            old_ip->pn_po = pcn_targ.pcn_po_full;

            if (old_ip->pn_va.va_type != VDIR) {
                global_pu->pu_pathfree(global_pu, &po_old);
                return(OK);
            }

            /* handle all child nodes for DIRs */
            pi.pi_old = &pcn_src.pcn_po_full;
            pi.pi_new = &pcn_targ.pcn_po_full;

            PU_LOCK();
            if (puffs_pn_nodewalk(global_pu, puffs_path_prefixadj, &pi)
                    != NULL) {
                /* Actually nomem */
                return(EINVAL);
            }
            PU_UNLOCK();
            global_pu->pu_pathfree(global_pu, &po_old);
        }
    }

rename_out:
    cur_time = clock_time();
    update_times(old_dirp, MTIME | CTIME, cur_time);
    update_times(new_dirp, MTIME | CTIME, cur_time);

    /* XXX see release_node comment in fs_unlink */
    if (new_ip && new_ip->pn_count == 0) {
        release_node(global_pu, new_ip);
    }

    return(r);
}
Ejemplo n.º 24
0
void 
DXAnchorWindow::createFileMenu(Widget parent)
{
    ASSERT(parent);
    int buttons = 0;
    Widget pulldown;

    //
    // Create "File" menu and options.
    //
    pulldown =
	this->fileMenuPulldown =
	    XmCreatePulldownMenu(parent, "fileMenuPulldown", NUL(ArgList), 0);
    this->fileMenu =
	XtVaCreateManagedWidget
	    ("fileMenu",
	     xmCascadeButtonWidgetClass,
	     parent,
	     XmNsubMenuId, pulldown,
	     NULL);

    //
    // Net file options. 
    //
    
    if (theDXApplication->appAllowsImageRWNetFile())  {
	this->openOption =
	   new ButtonInterface(pulldown, "fileOpenOption", 
			theDXApplication->openFileCmd);

	this->createFileHistoryMenu(pulldown);

	Network* net = theDXApplication->network;
	this->saveOption = 
	   new ButtonInterface(pulldown, "fileSaveOption", 
			net->getSaveCommand());
	this->saveAsOption = 
	   new ButtonInterface(pulldown, "fileSaveAsOption", 
			net->getSaveAsCommand());
	buttons = 1;
    }

    if (theDXApplication->appAllowsRWConfig()) {
	Command *openCfgCmd = theDXApplication->network->getOpenCfgCommand();
	Command *saveCfgCmd = theDXApplication->network->getSaveCfgCommand();
	if (openCfgCmd && saveCfgCmd) {
	    this->settingsCascade = new CascadeMenu("settingsCascade",pulldown);
	    Widget menu_parent = this->settingsCascade->getMenuItemParent();
	    this->saveCfgOption = new ButtonInterface(menu_parent, 
					"saveCfgOption", saveCfgCmd);
	    this->openCfgOption = new ButtonInterface(menu_parent, 
					"openCfgOption", openCfgCmd);
	    buttons = 1;
	} else if (openCfgCmd) {
	    this->openCfgOption = new ButtonInterface(pulldown, 
					"openCfgOption", openCfgCmd);
	    buttons = 1;
	} else if (saveCfgCmd) {
	    this->saveCfgOption = 
		new ButtonInterface(pulldown, 
					"saveCfgOption", saveCfgCmd);
	    buttons = 1;
	}
    }
 
    
    //
    // Macro/mdf options.
    //
    if (buttons) {
	XtVaCreateManagedWidget
		("optionSeparator", xmSeparatorWidgetClass, pulldown, NULL);
	buttons = 0;
    }
    if (theDXApplication->appAllowsImageLoad()) {
	this->loadMacroOption =
	    new ButtonInterface(pulldown, "fileLoadMacroOption", 
			theDXApplication->loadMacroCmd);
	this->loadMDFOption =
	    new ButtonInterface(pulldown, "fileLoadMDFOption", 	
			theDXApplication->loadMDFCmd);
	buttons = 1;
    }


    //
    // Close/quite
    //
    if (buttons) 
	XtVaCreateManagedWidget
		("optionSeparator", xmSeparatorWidgetClass, pulldown, NULL);

    this->closeOption = new ButtonInterface(pulldown,"fileCloseOption",this->closeCmd);

    XtAddCallback(pulldown,
		  XmNmapCallback,
		  (XtCallbackProc)DXAnchorWindow_FileMenuMapCB,
		  (XtPointer)this);
}
#include <dxconfig.h>
#include <defines.h>




#include <Xm/Xm.h>
#include <Xm/ToggleB.h>

#include "ToggleButtonInterface.h"


boolean ToggleButtonInterface::ToggleButtonInterfaceClassInitialized = FALSE;

Symbol ToggleButtonInterface::MsgToggleOn    = NUL(Symbol);
Symbol ToggleButtonInterface::MsgToggleOff   = NUL(Symbol);
Symbol ToggleButtonInterface::MsgToggleState = NUL(Symbol);


ToggleButtonInterface::ToggleButtonInterface(Widget   parent,
					     char*    name,
					     Command* command,
					     boolean  state,
					     const char *bubbleHelp):
	CommandInterface(name, command)
{
    ASSERT(parent);

    //
    // Perform class initialization, if necessary.