ࡱ; ,  !"#$%&'()*+-./Root Entry  "#$%'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`a ®`VTextStarWriter 5.0i{:# SfxDocumentInfo Mike {1Mike {1pvMike {1df Info 0 Info 1 Info 2 Info 3 {1@l8(<44Standard LIBIMBEDDED LIBIMBEDDED TASK,0,1,H,2,0,100,1,5918;2008;110;0;873;14971;9177;0;0SW5HDR.0{1pv!Outline0 #ZSBX sb Z Standard StarBASICSBX ARSBX AR SBX AR2c%bqqSWG, A<  #$%&'()*./0123456789:;<=>?@ABCDGHK  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFQRSTU 0WP $' '(. . p. @ . . . . . P. . . !. $. `'. 0*. -. /. 2. p5. @8. ;. =. @. 6')J2< vStandardStandard@Oh+'0 h t 15@'T@@*0@dKMike Mike SW5HDR.0{1pv! Frameformat ZeichenformatTextformatvorlageStandardRoot 5Standard  Illustration Table TextDrawingY .Y .Y .Y  .q= GeneralGeneraldNC#,###.00#,###.00SystemNC #,##0.00 CCC#,##0.00 CCCNC$#,##0.--;[RED]-$#,##0.-- $#,##0.---$#,##0.--REDNC$ MM/DD/YYYYMM/DD/YYYY def/SystemNC%MM/DD/YYMM/DD/YY def/SystemNC&NNNNMMMM DD, YYYYNNNNMMMM  DD, YYYYSystemNC' MMM D, YYMMM D, YY def/SystemNC. [HH]:MM:SS.00 [HH ]:MM:SS .00NC3MM/DD/YYYY HH:MM:SS MM/DD/YYYY HH :MM:SS  NCK MMM D, YYYYMMM D, YYYY def/SystemNCL MMMM D, YYYYMMMM  D, YYYY def/SystemNCM NN, MMM D, YYNN, MMM D, YY def/SystemNCNNN, MMMM D, YYYYNN, MMMM  D, YYYY def/SystemNCONNNNMMMM D, YYYYNNNNMMMM  D, YYYY def/SystemNCP D. MMM. YYYYD. MMM. YYYYDIN 5008 (EN 28601)NCQ D. MMMM YYYYD. MMMM  YYYYDIN 5008 (EN 28601)NCRMM-DDMM-DDDIN 5008 (EN 28601)NCSYY-MM-DDYY-MM-DDDIN 5008 (EN 28601)NCT YYYY-MM-DDYYYY-MM-DDDIN 5008 (EN 28601)NCUWWWWNCBXoePp 2$99 SUAP/=APdddAPddA PA  PSAAP/=APdddAPddZSW5HDR.0{1pvC(569a(Build:5169)(SV569)]D!Address Book Fileaddress! Frameformat ZeichenformatTextformatvorlageStandardRoot 5Standard  Illustration Table TextDrawingdE1 4 5*jK standard.dic soffice.dicZsun.dic@ IgnoreAllListY .Y .Y .Y  .6N ,ETcComputer Science 822SDAPdddA TimesNewRomanA @T_Lab 2 - Spr 2002SDAPdddA TimesNewRomanA @TOSDAPdddA TimesNewRomanA @TOverview: In this lab you will create a character device driver of the virtual device category will be used to create an implementation of counting semaphores. SUAPdd-dA TimesNewRomanA @A@. T`SUAPdd-dA TimesNewRomanA @A@. T>0 - Read chapters 1 through 4 of Linux Device Drivers 2nd Ed.SUAPdd-dA TimesNewRomanA @A@. A88::eT`SUAPdd-dA TimesNewRomanA @A@. T1 - Use mknod to create a character device named /dev/semn where n is your team number (which can be found in class/822/teams.txt). Give your device major number 20n and minor number 0. Give /dev/semn world read and write privileges. SUAPdd-dA TimesNewRomanA @A@. A8  A8  9A8 9:A8 :AA8 ACA8 CA8 A8 A8 TjS_APdd-dA TimesNewRomanA  A @A@. T2 - Use the chmod a+s command to add setuid privilege to the insmod, rmmod, and lsmod commands. This will permit you to build and test your device drivers from user mode. It is always desirable to minimize the time you spend as root!! SUAPdd-dA TimesNewRomanA @A@. A8 A8  A8 >MA8 QWA8 A8 TjS_APdd-dA TimesNewRomanA  A @A@. TP3 - Construct a makefile based upon the one shown on page 23 of the Devices Drivers book. You may find it useful to install acroread on your computer. Both acroread.tgz and the Device Drivers book are available in /local/share.S_APdd-dA TimesNewRomanA  A @A@. TjS_APdd-dA TimesNewRomanA  A @A@. Tc4 - Your device driver should be named semn.o where n is your team is your team number. Start by creating semn.c as the null installable module shown on page 15 of the device drivers book. S_APdd-dA TimesNewRomanA  A @A@. A8 +.A8 57A8 opA8 vyTjS_APdd-dA TimesNewRomanA  A @A@. T?5 - Build this and ensure that it can be installed and removed.S_APdd-dA TimesNewRomanA  A @A@. TCS8APdd-dA @A@. TJ6 - Now add code to register your module as the driver for /dev/semn. Build a test application and, using printk(), ensure that your open, close, and ioctl entry points are working as expected. S_APdd-dA TimesNewRomanA  A @A@. A8 C}A8 G|TjS_APdd-dA TimesNewRomanA  A @A@. T^You are now ready to begin work on the "real thing". The semaphore API is defined as follows S_APdd-dA TimesNewRomanA  A @A@. TF(you should retrieve semuser.h from /local/share/semuser.h) You will need to define an internal structure to represent your semaphores within the device driver!! The number of semaphores must be configurable at install time, but the maximum number of processes that will ever be bound to the semaphore must be limited to 8. S_APdddA TimesNewRomanA  A @A@. A8 XaTjS_APdd-dA TimesNewRomanA  A @A@. T/* semuser.h */S_APdd-dA TimesNewRomanA  A @A@. A8CourierTdSYAPdd-dACourierA  A @A@. T1#define SEM_ALLOC 101 /* alloc a free sem */SYAPdd-dACourierA  A @A@. T;#define SEM_BIND 102 /* bind to an existing sem */ S8APdd-dA @A@. A8 4A84CourierT3#define SEM_WAIT 103 /* normal dyjkstra wait */SYAPdd-dACourierA  A @A@. T+#define SEM_SIG 104 /* normal signal */S8APdd-dA @A@. A8 +A8+CourierT-#define SEM_SET 105 /* set the value */SYAPdd-dACourierA  A @A@. T0#define SEM_GET 106 /* retrieve the value */SYAPdd-dACourierA  A @A@. TdSYAPdd-dACourierA  A @A@. TnScAPdd-dA PACourierA  A @A@. TdSYAPdd-dACourierA  A @A@. T2/* Applications use this structure to pass data */SYAPdd-dACourierA  A @A@. T2/* to or from the semaphore device driver.. */SYAPdd-dACourierA  A @A@. TdSYAPdd-dACourierA  A @A@. Trtypedef structSYAPdd-dACourierA  A @A@. Te{SYAPdd-dACourierA  A @A@. T9 int semid; /* Sem id .. 0, 1, ... semcount - 1 */SYAPdd-dACourierA  A @A@. T9 /* set by alloc / read by bind */SYAPdd-dACourierA  A @A@. T9 int semval; /* For set/get operations */SYAPdd-dACourierA  A @A@. Tr} semuser_t; SYAPdd-dACourierA  A @A@. TdSYAPdd-dACourierA  A @A@. ToThe "parm" field of the ioctl call should be a pointer to a proper structure of this type. However, the driver must catch and prevent all application errors from affecting the health of the semaphore module or the system as a whole.S_APdddA TimesNewRomanA  A @A@. A8 ptA8 TjS_APdddA TimesNewRomanA  A @A@. Tioctls should work as follows:S_APdddA TimesNewRomanA  A @A@. TjS_APdddA TimesNewRomanA  A @A@. Tt SEM_ALLOC:S_APdddA TimesNewRomanA  A @A@. TjS_APdddA TimesNewRomanA  A @A@. TpIf a free semaphore exists allocate it to the caller, fill in the semid in the caller's structure, set the value of the semphore in the kernel's structure to 0, remember that the semaphore is allocated to this process and return(0). Otherwise return(-EBUSY). S_APdddA TimesNewRomanA  A @A@. TjS_APdddA TimesNewRomanA  A @A@. Ts SEM_BIND:S_APdddA TimesNewRomanA  A @A@. TjS_APdddA TimesNewRomanA  A @A@. T<The caller provides a semaphore id of 0...semcount in semid. If the semphore is not free and not already allocated or bound to the caller and has not exceeded the maximum number of bound or allocated clients return(0) and remember that the semaphore is now bound to the calling process. Otherwise return (-EINVAL); S_APdddA TimesNewRomanA  A @A@. A8 QTTjS_APdd-dA TimesNewRomanA  A @A@. T!SEM_WAIT/SEM_SIG/SEM_SET/SEM_GET:S_APdd-dA TimesNewRomanA  A @A@. TjS_APdd-dA TimesNewRomanA  A @A@. T If the semaphore is bound or allocated to the caller, carry out the standard semantics for a FIFO semaphore (I would add FIFO last). Otherwise return(-EINVAL); S_APdddA TimesNewRomanA  A @A@. TjS_APdd-dA TimesNewRomanA  A @A@. T When your release() function is called you should forget that the semaphore is allocated or bound to the to the process that just released it. When the last process that has the semaphore allocated or bound releases it, the semaphore becomes free for reassignment.S_APdd-dA TimesNewRomanA  A @A@. A8  A8 TOSDAPdddA TimesNewRomanA @TnA highly recommended strategy is to concurrently develop your device driver and your application test suite. SDAPdddA TimesNewRomanA @TOSDAPdddA TimesNewRomanA @TFProgramming standards (see /usr/src/linux/Documentation) augmented by:SDAPdddA TimesNewRomanA @T~/(1) Pay particular heed to guidelines regardingSDAPdddA TimesNewRomanA @T^Function lengthSDAPdddA TimesNewRomanA @T`Nesting of blocksSDAPdddA TimesNewRomanA @T{,(2) No lines of code longer that 72 bytes!!!SDAPdddA TimesNewRomanA @TOSDAPdddA TimesNewRomanA @JGeneric PrinterSGENPRT PostScriptH`Tl`Tld,,lprdefault_queueSGENPRT7 Uײ?U88/|?^/=UI$2P@UI$2?BI$ B I$ BI$ B$I$B<I$ BHI$ BTI$ B`I$$B I$  B I$$ BI$  BI$$ BI$  BI$$BI$ B I$ B,I$ B8I$$B\I$ BhI$ Bt I$0B$I$ B%I$ B&I$B'I$B(I$ B)I$Bz*I$B`+I$BF,I$B,-I$:>/=UI$2pUI$2?&BI$ BI$!BI$"BI$#BI$$B~I$%BdI$&BJI$'B0I$(BI$)BI$*B I$+B I$$,B I$ -BI$ .BI$ /BI$ 0@BI$ 1AB(I$$Ey!$2DBLI$ Ey! 3EBXI$ 4FBdI$ 5GBpI$0Ey!06KBI$ 7LBI$ 8MBI$ 9NB I$EY!:PB"I$ E|! ;QB#I$$<TB 'I$ =UB(I$>WB0*I$ ?XB<+I$ @YBH,I$ Ey! AZBT-I$ E B[B`.I$ E C\Bl/I$ Ey! D]Bx0I$ Ey! E^lZRoot Entry ®`VCompObj<Ole persist elements" SfxDocumentInfo uBasicManager2 4StarBASIC SfxWindows<SwNumRulesUStandardjSfxStyleSheetszSummaryInformation( !0SwPageStyleSheets$ &StarWriterDocument&6