Writing OS/2 Warp Device Drivers in C Third Edition 2

Total Page:16

File Type:pdf, Size:1020Kb

Writing OS/2 Warp Device Drivers in C Third Edition 2 1 Tuesday, May 06, 1997 Writing OS/2 Warp Device Drivers in C Third Edition 2 Disclaimer This book and software are provided -as is.' The implied warranties of merchantability and fitness for a particular purpose are expressly disclaimed. This book and software may contain programs that are furnished as examples. These examples have not been thoroughly tested under all conditions. Therefore, the reliability, serviceability, or function of any program or program code herein is not guaranteed. The information presented in this book was valid at the time it was written and was conveyed as accurately as possible by the author. However, some information may be incorrect or may have changed prior to publication. The author makes no claims that the material contained in this book is entirely correct, and assumes no liability for use of the material contained herein. 3 Trademarks and Copyrights IBM, AT, OS/2, Personal System/2, PS/2, and Micro Channel are registered trademarks of the International Business Machines Corporation. C/2, XT, and Presentation Manager are trademarks of International Business Machines Corporation. Intel is a registered trademark of the Intel Corporation. Lotus 1-2-3 is a registered trademark of Lotus Development Corporation. MS-DOS, CodeView and Microsoft are registered trademarks of Microsoft Corporation. Microsoft and Microsoft Windows are registered trademarks of Microsoft Corporation. UNIX is a registered trademark of AT&T Bell Laboratories. Copyright 1993 by Van Nostrand Reinhold Library of Congress Catalog Card Number 93-2264 ISBN 0-442-01729-4 All rights reserved. No part of this work covered by the copyright hereon may be reproduced or used in any form or by any means-graphic, electronic, or mechanical, including photocopying, recording, taping, or information storage and retrieval systems-without written permission of the publisher. Van Nostrand Reinhold is an International Thomson Publishing company. ITP logo is a trademark under license. Printed in the United States of America Van Nostrand Reinhold International Thomson Publishing GmbH 115 Fifth Avenue KÜnigswinteror Str. 518 New York, NY 10003 5300 Bonn 3 International Thomson Publishing International Thomson Publishing Asia Berkshire House, 168-=173 38 Kim Tian Road, #0105 High Holborn, London WC1V 7AA Kim Tian Plaza England Singapore 0316 Thomas Nelson Australia International Thomson Publishing Japan 102 Dodds Street South Melbourne 3205 2-2-1 Hirakawacho Victoria, Australia Chiyada-Ku, Tokyo 102 Nelson Canada 1120 Birchmount Road Scarborough, Ontario M1K 5G4, Canada 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Library of Congress Cataloging-in-Publication Data Mastrianni, Steven J., 1951- Writing OS/2 2.x Device Drivers in C / Steven J. Mastrianni. - 3rd ed. p. cm. -- (VNR's OS/2 series) Includes index. ISBN 0-442-01229-4 1. OS/2 device drivers (Computer programs) 2. OS/2 (Computer file) 3. C (Computer program language) I. Title. II. Series. QA76.76.D49M371993 005.4'3--dc20 93-2264 CIP 4 Dedication This book is dedicated to Bernard Engelson, who passed away on June 8, 1994. His knowledge, compassion and understanding were an inspiration to everyone. He will be sorely missed. 5 Acknowledgments I would like to thank 7 Foreword 9 Table of Contents Writing OS/2 Warp Device Drivers in C.......................................................................1 Third Edition................................................................................................................1 Chapter 1 - The Evolution of PC Device Drivers ..........................................................33 Storage Devices................................................................................................34 Interface Adapter Cards....................................................................................35 The First Operating System For Personal Computers ........................................36 The First Bus....................................................................................................38 Chapter 2 - Understanding Device Drivers....................................................................41 Device Drivers Today.......................................................................................44 Device Drivers - A Summary ............................................................................46 Chapter 3 - The PC Hardware Architecture..................................................................49 The System Bus................................................................................................49 The IBM PC - Beginnings.................................................................................50 IBM PC XT......................................................................................................51 IBM PC AT......................................................................................................52 The AT Bus......................................................................................................53 The IBM PS/2 and Micro Channel....................................................................54 Enhanced Industry Standard Architecture (EISA) .............................................56 Bus Wars..........................................................................................................57 Real Mode........................................................................................................57 Protect Mode ...................................................................................................58 Using Addresses and Pointers ...........................................................................61 The Ring Architecture ......................................................................................61 Chapter 4 - An Overview of the OS/2 Operating System ..............................................65 Roots ...............................................................................................................66 Processes and Threads......................................................................................69 OS/2 1.0 - OS/2 Arrives ...................................................................................71 OS/2 1.1 - Presentation Manager Arrives..........................................................71 10 OS/2 1.2 - A Better File System........................................................................71 OS/2 1.3 – IBM’s First Solo Effort...................................................................73 OS/2 2.0- What OS/2 Was Really Meant to Be.................................................73 The OS/2 Application Programming Interface...................................................75 Chapter 5 - The Anatomy of an OS/2 Device Driver.....................................................77 Application-to-Driver Interface.........................................................................77 DOS Device Drivers and OS/2 Device Drivers..................................................78 Designing an OS/2 Device Driver .....................................................................79 Tools Necessary For Driver Development.........................................................79 The Basics of Driver Design .............................................................................80 Request Packets ...............................................................................................81 OS/2 Device Driver Architecture ......................................................................82 Device Driver Modes........................................................................................83 The Device Header...........................................................................................85 Capabilities Bit Strip.........................................................................................87 Providing a Low-Level Interface.......................................................................88 The Strategy Section ........................................................................................94 Initialization......................................................................................................96 A Common Strategy.........................................................................................98 Interrupt Section...............................................................................................99 The Timer Handler ...........................................................................................105 Context Hooks .................................................................................................106 Chapter 6 - Device Driver Strategy Commands ............................................................109 Summary of Device Driver Commands .............................................................112 0h / Init.............................................................................................................115 1H/ Media Check..............................................................................................120 2H / Build BPB ................................................................................................122 4H, 8H, 9H / Read or Write..............................................................................125 5H / Nondestructive Read No Wait...................................................................127 6H, AH / Input or Output Status.......................................................................128 7H,
Recommended publications
  • Introduction to MS-DOS
    1.Introduction to MS-DOS : MS-DOS (Microsoft Disk Operating System) was the Microsoft-marketed version of the first widely-installed operating system in personal computers. It was essentially the same operating system that (Bill Gates's) young company developed for IBM as Personal Computer - Disk Operating System in 1981. Most users of either DOS system simply referred to their system as Disk Operating System. Like PC-DOS, MS-DOS was (and still is) a non-graphical line-oriented command- driven operating system, with a relatively simple interface but not overly "friendly" user interface. Its prompt to enter a command looks like this: C:\> MS-DOS does not care about anything called an icon, wallpaper or screen saver. Rather than being considered as a Graphical User Interface (GUI) MS-DOS is what is known as a command-line interface. You type commands on what is called the command line. MS-DOS is a single-user, single-tasking computer operating system. In spite of its very small size and relative simplicity, it is one of the most successful operating systems that has been developed to date. In DOS, a file name consists of eight character followed by a 3 character file extension. The size of a file is restricted to a 4 byte file descriptor, which limits a file’s maximum size to approximately 4 billion characters. The first release of DOS could not read or write to disk drives so users could only read and write to a floppy disc. DOS was not a state of the art operating system, even for its time.
    [Show full text]
  • Operating System User's Mannal ~Zilog 03-0072-01 Revision a September 1978
    t_ .' Operating System User's Mannal ~Zilog 03-0072-01 Revision A September 1978 Copyright © 1978 by Zilog, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of Zilog. Zilog assumes no responsibility for the use of any circuitry other than circuitry embodied in a Zilog product. No other circuit patent licenses are implied. zaO-RIO Operating System User's Manual September 1978 TABLE OF CONTENTS CHAPTER 1 - INTRODUCTION AND OVERVIEW • 1 1.1 INTRODUCTION •• 1 1.2 SYSTEM OVERVIEW 3 1.2.1 Hardware Configuration • • • • • • 3 1.2.2 File Systems • • • • • • • . • • 3 1.2.3 System Initialization •••.••• 6 1.2.4 Commands • • .• .•..••• 7 1.2.5 I/O • • • . • • • • • . • • • • • . 7 CHAPTER 2 - RIO EXECUTIVE 9 2.1 SYSTEM INITIALIZATION 9 2.2 FILE NAME CONVENTIONS · 10 2.3 MEMORY MANAGEMENT . • • . 12 2.3.1 MEMMGR • . 13 2.4 COMMAND STRING INTERPRETATION · 13 2.5 ERROR HANDLING • • . 15 2.6 PROGRAM EXECUTION OF COMMANDS · 15 CHAPTER 3 - 1/0 STRUCTURE • · 16 3.1 OVERVIEW . • · 16 3.2 I/O REQUESTS - SYSTEM CALLS · 17 3.3 THE 'ASSIGN' I/O REQUEST ••• • 19 - i - 3.4 STANDARD RIO I/O DEVICES • • • 21 3.4.1 ZDOS . • • • . 21 3.4.2 DFS . 21 3.4.3 NULL . • • • . 21 3.4.4 CON . • • • . • • • • • 22 3.4.5 PCON • 27 3.4.6 FLOPPY • • • • • • • • • • 27 3.4.7 DISK • • • • • • 27 CHAPTER 4 - PROGRAM INTERFACE • • 28 4.1 PROGRAM LOCATION • • • • • 28 4.2 PARAMETER STRING ADDRESS · 29 4.3 PROGRAM STACK SPACE • • • 29 4.4 PROGRAM TERMINATION - ERROR HANDLING ••.
    [Show full text]
  • IODF Explorer
    The Input/Output Definition File (IODF) is a critical Control Point in the management of the IBM z/Series Platform. IODF Explorer Release 4.0 USER GUIDE Contact us for additional information: NewEra Software Technical Support 800-421-5035 [email protected] www.newera.com Rev: 2009-04-24 IODF Explorer 4.0 ¾ Copyright, Trademark and Legal Notices Copyrights This Getting Started Guide and the related Software Product(s) are protected under a Copyright dated 2009 by NewEra Software, Inc. All rights are reserved. License Agreement This Getting Started Guide describes the installation and operation of Image FOCUS, its environment and applications. It is made available only under the terms of a license agreement between the licensee and NewEra Software Inc. No part of this Guide or the related Software Product(s) may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying and recording, for any purpose, without the express written permission of NewEra Software, Inc. Trademarks and Copyrights of Others The following products and/or registered trademarks of International Business Machines Corporation are referenced in this document: MVS, VM, RACF, z/OS, SYSPLEX, JES, VTAM, TSO, ISPF, ICKDSF, DFSMSdss, DF/DSS, and others. 2 NewEra Software, Inc. ‐ Image Control Environment (ICE) Applications IODF Explorer 4.0 ¾ Technical Support Information NewEra Software is dedicated to providing the highest level of technical Around-the-clock- support support to meet our customers’ growing needs. In order to meet these needs, NewEra provides around‐the‐clock technical support, 7 days a week, 24 hours a day.
    [Show full text]
  • Hardware Configuration Definition User's Guide
    z/OS Version 2 Release 3 Hardware Configuration Definition User's Guide IBM SC34-2669-30 Note Before using this information and the product it supports, read the information in “Notices” on page 443. This edition applies to Version 2 Release 3 of z/OS (5650-ZOS) and to all subsequent releases and modifications until otherwise indicated in new editions. Last updated: 2019-02-16 © Copyright International Business Machines Corporation 1994, 2018. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents List of Figures..................................................................................................... xiii List of Tables.....................................................................................................xxiii About this document.......................................................................................... xxv Who this document is for..........................................................................................................................xxv Related information.................................................................................................................................. xxv How to use this document.......................................................................................................................xxvi How this document is organized............................................................................................................. xxvi How to read syntax diagrams................................................................................................................
    [Show full text]
  • Beyond MOV ADD XOR – the Unusual and Unexpected
    Beyond MOV ADD XOR the unusual and unexpected in x86 Mateusz "j00ru" Jurczyk, Gynvael Coldwind CONFidence 2013, Kraków Who • Mateusz Jurczyk o Information Security Engineer @ Google o http://j00ru.vexillium.org/ o @j00ru • Gynvael Coldwind o Information Security Engineer @ Google o http://gynvael.coldwind.pl/ o @gynvael Agenda • Getting you up to speed with new x86 research. • Highlighting interesting facts and tricks. • Both x86 and x86-64 discussed. Security relevance • Local vulnerabilities in CPU ↔ OS integration. • Subtle CPU-specific information disclosure. • Exploit mitigations on CPU level. • Loosely related considerations and quirks. x86 - introduction not required • Intel first ships 8086 in 1978 o 16-bit extension of the 8-bit 8085. • Only 80386 and later are used today. o first shipped in 1985 o fully 32-bit architecture o designed with security in mind . code and i/o privilege levels . memory protection . segmentation x86 - produced by... Intel, AMD, VIA - yeah, we all know these. • Chips and Technologies - left market after failed 386 compatible chip failed to boot the Windows operating system. • NEC - sold early Intel architecture compatibles such as NEC V20 and NEC V30; product line transitioned to NEC internal architecture http://www.cpu-collection.de/ x86 - other manufacturers Eastern Bloc KM1810BM86 (USSR) http://www.cpu-collection.de/ x86 - other manufacturers Transmeta, Rise Technology, IDT, National Semiconductor, Cyrix, NexGen, Chips and Technologies, IBM, UMC, DM&P Electronics, ZF Micro, Zet IA-32, RDC Semiconductors, Nvidia, ALi, SiS, GlobalFoundries, TSMC, Fujitsu, SGS-Thomson, Texas Instruments, ... (via Wikipedia) At first, a simple architecture... At first, a simple architecture... x86 bursted with new functions • No eXecute bit (W^X, DEP) o completely redefined exploit development, together with ASLR • Supervisor Mode Execution Prevention • RDRAND instruction o cryptographically secure prng • Related: TPM, VT-d, IOMMU Overall..
    [Show full text]
  • Computing :: Operatingsystems :: DOS Beyond 640K 2Nd
    DOS® Beyond 640K 2nd Edition DOS® Beyond 640K 2nd Edition James S. Forney Windcrest®/McGraw-Hill SECOND EDITION FIRST PRINTING © 1992 by James S. Forney. First Edition © 1989 by James S. Forney. Published by Windcrest Books, an imprint of TAB Books. TAB Books is a division of McGraw-Hill, Inc. The name "Windcrest" is a registered trademark of TAB Books. Printed in the United States of America. All rights reserved. The publisher takes no responsibility for the use of any of the materials or methods described in this book, nor for the products thereof. Library of Congress Cataloging-in-Publication Data Forney, James. DOS beyond 640K / by James S. Forney. - 2nd ed. p. cm. Rev. ed. of: MS-DOS beyond 640K. Includes index. ISBN 0-8306-9717-9 ISBN 0-8306-3744-3 (pbk.) 1. Operating systems (Computers) 2. MS-DOS (Computer file) 3. PC -DOS (Computer file) 4. Random access memory. I. Forney, James. MS-DOS beyond 640K. II. Title. QA76.76.063F644 1991 0058.4'3--dc20 91-24629 CIP TAB Books offers software for sale. For information and a catalog, please contact TAB Software Department, Blue Ridge Summit, PA 17294-0850. Acquisitions Editor: Stephen Moore Production: Katherine G. Brown Book Design: Jaclyn J. Boone Cover: Sandra Blair Design, Harrisburg, PA WTl To Sheila Contents Preface Xlll Acknowledgments xv Introduction xvii Chapter 1. The unexpanded system 1 Physical limits of the system 2 The physical machine 5 Life beyond 640K 7 The operating system 10 Evolution: a two-way street 12 What else is in there? 13 Out of hiding 13 Chapter 2.
    [Show full text]
  • NASM — the Netwide Assembler Version 2.09.04
    NASM — The Netwide Assembler version 2.09.04 -~~..~:#;L .-:#;L,.- .~:#:;.T -~~.~:;. .~:;. E8+U *T +U' *T# .97 *L E8+' *;T' *;, D97 `*L .97 '*L "T;E+:, D9 *L *L H7 I# T7 I# "*:. H7 I# I# U: :8 *#+ , :8 T, 79 U: :8 :8 ,#B. .IE, "T;E* .IE, J *+;#:T*" ,#B. .IE, .IE, © 1996−2010 The NASM Development Team — All Rights Reserved This document is redistributable under the license given in the file "LICENSE" distributed in the NASM archive. Contents Chapter 1: Introduction . .15 1.1 What Is NASM? . .15 1.1.1 Why Yet Another Assembler?. .15 1.1.2 License Conditions . .15 1.2 Contact Information . .16 1.3 Installation. .16 1.3.1 Installing NASM under MS−DOS or Windows . .16 1.3.2 Installing NASM under Unix . .17 Chapter 2: Running NASM . .18 2.1 NASM Command−Line Syntax . .18 2.1.1 The −o Option: Specifying the Output File Name . .18 2.1.2 The −f Option: Specifying the Output File Format . .19 2.1.3 The −l Option: Generating a Listing File . .19 2.1.4 The −M Option: Generate Makefile Dependencies . .19 2.1.5 The −MG Option: Generate Makefile Dependencies . .19 2.1.6 The −MF Option: Set Makefile Dependency File . .19 2.1.7 The −MD Option: Assemble and Generate Dependencies. .19 2.1.8 The −MT Option: Dependency Target Name. .20 2.1.9 The −MQ Option: Dependency Target Name (Quoted) . .20 2.1.10 The −MP Option: Emit phony targets. .20 2.1.11 The −F Option: Selecting a Debug Information Format .
    [Show full text]
  • Mystic Microsoft
    Kraig Brockschmidt Mystic Microsoft A Journey of Transformation in the Halls of High Technology Kraig Brockschmidt You’re invited to copy, print, and share this book… It’s free and it’s legal Mystic Microsoft is published under the Creative Commons Attribution-Noncommercial- No Derivative Works 2.5 License (see next page) This means you may freely and legally share, copy, distribute, and display this book without the need to worry about lawyers, royalties, and all that sort of stuff. This book’s website (www.mysticmicrosoft.com) even gives you all the files you need to print and bind your own copies. Of course, you are not allowed to make any changes to this work, nor are you allowed to use it for commercial purposes or profit from it in any way without permission from the author. As this book is offered freely, readers are encouraged, though not required, to reciprocate in two ways: (1) Express gratitude to the author by making a monetary contribution to the author’s work and/or writing a positive testimonial about the book with permission to use your words in promotional activities. See www.mysticmicrosoft.com for details or write to the author’s address on the next page. (2) “Pay it forward” by sharing the book with others and/or making a gift of money or volunteered time to a worthy cause of your choice. So that these gifts do not go unnoticed, please inform the author of your gifts via www.mysticmicrosoft.com (or regular mail) so the website can show the positive contributions that this work has inspired.
    [Show full text]
  • Microsoft Plays Hardball: Use of Exclusionary Pricing and Technical
    Antitrust Bulletin, XL:2, Summer 1995, 265-315 MICROSOFT PLAYS HARDBALL: The Use of Exclusionary Pricing and Technical Incompatibility to Maintain Monopoly Power in Markets for Operating System Software† by KENNETH C. BASEMAN* FREDERICK R. WARREN-BOULTON* and GLENN A. WOROCH** May 1995 ___________________ * Principals, MiCRA: Microeconomic Consulting and Research Associates, Inc., Washington, DC. ** University of California, Berkeley. † Forthcoming, Antitrust Bulletin, June 1995. We would like to express our appreciation for helpful comments and other assistance to Sturge Sobin, Linnet Harlan, Paul Dennis and the participants at the Columbia Business School's Institute for Tele-Information's Seminar on Sustaining Competition in Network Industries through Regulating and Pricing Access, especially Janusz Ordover and Bobby Willig. TABLE OF CONTENTS I. INTRODUCTION AND SUMMARY ................................... 1 II. BACKGROUND .................................................... 3 A. THE MARKET FOR PERSONAL COMPUTER OPERATING SYSTEMS ............................................................ 3 TABLE: NEW SHIPMENTS OF PERSONAL COMPUTER OPERATING SYSTEMS .............................................. 8 B. MICROSOFT'S PRACTICES ..................................... 9 III. FIRST-DEGREE PRICE DISCRIMINATION vs. INEFFICIENT SUBSTITUTION ................................................... 15 A. FIRST-DEGREE PRICE DISCRIMINATION ........................ 16 B. INEFFICIENT SUBSTITUTION ................................. 20 IV. ANTIFRAUD AND ANTIPIRACY
    [Show full text]
  • User's Manual
    User’s Manual P/N 064673-004 ® JANUS 2.4 GHz Installation Utility (4MB) Intermec Technologies Corporation 6001 36th Avenue West P.O. Box 4280 Everett, WA 98203-9280 U.S. service and technical support: 1-800-755-5505 U.S. media supplies ordering information: 1-800-227-9947 Canadian service and technical support: 1-800-688-7043 Canadian media supplies ordering information: 1-800-268-6936 Outside U.S. and Canada: Contact your local Intermec service supplier. The information contained herein is proprietary and is provided solely for the purpose of allowing customers to operate and/or service Intermec manufactured equipment and is not to be released, reproduced, or used for any other purpose without written permission of Intermec. Information and specifications in this manual are subject to change without notice. 1998 by Intermec Technologies Corporation All Rights Reserved The word Intermec, the Intermec logo, JANUS, IRL, TRAKKER, Antares, Duratherm, Precision Print, PrintSet, Virtual Wedge, and CrossBar are either trademarks or registered trademarks of Intermec Corporation. Throughout this manual, trademarked names may be used. Rather than put a trademark () symbol in every occurrence of a trademarked name, we state that we are using the names only in an editorial fashion, and to the benefit of the trademark owner, with no intention of infringement. Manual Change Record This page records the changes to this manual, which was originally released as version 001. Version Date Description of Change 002 12/96 New information was added for the JG2050 and for UDP Plus terminal emulation. 003 9/97 New information was added to describe using the installation utility on a JG2010.
    [Show full text]
  • Avaya Call Management System Software Installation, Maintenance, and Troubleshooting for Linux®
    Avaya Call Management System Software Installation, Maintenance, and Troubleshooting for Linux® Release 18.0.2 February 2018 © 2018 Avaya Inc. All Rights Reserved. CHANNEL PARTNER; AVAYA RESERVES THE RIGHT TO TAKE LEGAL ACTION AGAINST YOU AND ANYONE ELSE USING OR SELLING THE Notice SOFTWARE WITHOUT A LICENSE. BY INSTALLING, DOWNLOADING OR While reasonable efforts have been made to ensure that the information in this USING THE SOFTWARE, OR AUTHORIZING OTHERS TO DO SO, YOU, ON document is complete and accurate at the time of printing, Avaya assumes no BEHALF OF YOURSELF AND THE ENTITY FOR WHOM YOU ARE liability for any errors. Avaya reserves the right to make changes and INSTALLING, DOWNLOADING OR USING THE SOFTWARE corrections to the information in this document without the obligation to notify (HEREINAFTER REFERRED TO INTERCHANGEABLY AS "YOU" AND "END any person or organization of such changes. USER"), AGREE TO THESE TERMS AND CONDITIONS AND CREATE A BINDING CONTRACT BETWEEN YOU AND AVAYA INC. OR THE Documentation disclaimer APPLICABLE AVAYA AFFILIATE ("AVAYA"). "Documentation" means information published in varying mediums which may Avaya grants You a license within the scope of the license types described include product information, operating instructions and performance below, with the exception of Heritage Nortel Software, for which the scope of specifications that are generally made available to users of products. the license is detailed below. Where the order documentation does not Documentation does not include marketing materials. Avaya shall not be expressly identify a license type, the applicable license will be a Designated responsible for any modifications, additions, or deletions to the original System License.
    [Show full text]
  • Bash Scripts #4 Input/Output + Oneliners
    Bash Scripts #4 Input/Output + Oneliners By: Deepayan Patra & Sam Yong (Pixel) Pet Tax Sam’s doggo Yoshi How to Become a Bash Expert Bash as a full-fledged scripting language STEP 3 Bash as a data STEP 2 processing language Learn to browse files and run programs STEP 1 01 03 Unix Process Communication More Scripting Everything is a file! How to use pipes and more to stream info! 02 04 Scripting w. I/O Redirect Oneliners How programs talk to each other! One line programs to make Bash so easy! 01. Unix Process Comm. (it’s I/Opening) Unix as a 2-layered API ● C functions ○ for “real” system programming ● Shell commands ○ subset of C functionality ○ for scripting and interactive use Unix as a 2-layered API ● C functions (15-213) ○ for “real” system programming ● Shell commands (GPI) ○ subset of C functionality ○ for scripting and interactive use Unix process interacts with the world ● stdin ● stdout ● args ● stderr ● env Process ● exitcode ● fs ● fs ● network ● network We can script some of these ● stdin ● stdout ● args ● stderr ● env Process ● exitcode ● fs ● fs ● network ● network Input & Output (streams) ● stdin - standard input (file descriptor = 0) ○ raw_input, scanf ● stdout - standard output (file descriptor = 1) ○ print, printf ● stderr - standard error (file descriptor = 2) ○ fprint(stderr) Arguments ● args - command line arguments ● Scripts can access arguments with ○ $# = number of arguments given to the script (different from “argc” in C, which includes program name) ○ $1 = first argument, $2 = second argument, … ● e.g. $ echo Hello World ○ $# = 2 ○ $1 = Hello ○ $2 = World ○ $0 = echo DEMO Environment Variables ● A list of key-value pairs DEMO ● Essentially the shell’s global variables ● Any program can use these variables ○ Access a VAR by $VAR ● printenv - prints currently set environment variables Exit Code ● All programs exit with some code ● This is determined by the programmer ● In general, exit 0 means success ● Anything else indicates some error/failure ● Process can access last executed program’s exit code DEMO 02.
    [Show full text]