DiscQuotasinaUNIX*Environment. RobertElz DepartmentofComputerScience UniversityofMelbourne, Parkville, Victoria, Australia. ABSTRACT Inmostcomputingenvironments,discspaceisnotinfinite.Thediscquota systemprovidesamechanismtocontrolusageofdiscspace,onanindividual basis. Quotasmaybesetforeachindividualuser,onany,orallfilesystems. Thequotasystemwillwarnuserswhentheyexceedtheirallottedlimit,but allowsomeextraspaceforcurrentwork.Repeatedlyremainingoverquotaat logout,willcauseafataloverquotaconditioneventually. ThequotasystemisanoptionalpartofVMUNIXthatmaybeincludedwhen thesystemisconfigured. 5thJuly,1983 *UNIXisatrademarkofBellLaboratories.

DiscQuotasinaUNIX*Environment. RobertElz DepartmentofComputerScience UniversityofMelbourne, Parkville, Victoria, Australia. 1.Users’viewofdiscquotas Tomostusers,discquotaswilleitherbeofnoconcern,orafactoflifethatcannotbe avoided.Thequota(1)commandwillprovideinformationonanydiscquotasthatmayhavebeen imposeduponauser. Therearetwoindividualpossiblequotasthatmaybeimposed,usuallyifoneis,bothwill be.Alimitcanbesetontheamountofspaceausercanoccupy,andtheremaybealimitonthe numberoffiles(inodes)hecanown. Quotaprovidesinformationonthequotasthathavebeensetbythesystemadministrators, ineachoftheseareas,andcurrentusage. Therearefournumbersforeachlimit,thecurrentusage,softlimit(quota),hardlimit,and numberofremainingloginwarnings.Thesoftlimitisthenumberof1Kblocks(orfiles)thatthe userisexpectedtoremainbelow.Eachtimetheuser’susagegoespastthislimit,hewillbe warned.Thehardlimitcannotbeexceeded.Ifauser’susagereachesthisnumber,further requestsforspace(orattemptstocreateafile)willfailwithanEDQUOTerror,andthefirst timethisoccurs,amessagewillbewrittentotheuser’sterminal.Onlyonemessagewillbeoutput,untilspaceoccupiedisreducedbelowthelimit,andreachesitagain,inordertoavoidcontinualnoisefromthoseprogramsthatignorewriteerrors. Wheneverauserlogsinwithausagegreaterthanhissoftlimit,hewillbewarned,andhis loginwarningcountdecremented.Whenhelogsinunderquota,thecounterisresettoitsmaximumvalue(whichisasystemconfigurationparameter,thatistypically3).Ifthewarningcount shouldeverreachzero(causedbythreesuccessiveloginsoverquota),theparticularlimitthathas beenexceededwillbetreatedasifthehardlimithasbeenreached,andnomoreresourceswillbe allocatedtotheuser.Theonlywaytoresetthisconditionistoreduceusagebelowquota,then loginagain. 1.1.Survivingwhenquotalimitisreached Inmostcases,theonlywaytorecoverfromoverquotaconditions,istoabortwhatever activitywasinprogressonthefilesystemthathasreacheditslimit,removesufficientfilestobring thelimitbackbelowquota,andretrythefailedprogram. However,ifyouareintheeditorandawritefailsbecauseofanoverquotasituation,thatis notasuitablecourseofaction,asitismostlikelythatinitiallyattemptingtowritethefilewill havetruncateditspreviouscontents,soshouldtheeditorbeabortedwithoutcorrectlywritingthe filenotonlywilltherecentchangesbelost,butpossiblymuch,orevenall,ofthedatathatpreviouslyexisted. Thereareseveralpossiblesafeexitsforausercaughtinthissituation.Hemayusetheeditor!shellescapecommandtoexaminehisfilespace,andremovesurplusfiles.Alternatively, usingcsh,hemaysuspendtheeditor,removesomefiles,thenresumeit.Athirdpossibility,isto *UNIXisatrademarkofBellLaboratories.

-2-writethefiletosomeotherfilesystem(perhapstoafileon/tmp)wheretheuser’squotahasnot beenexceeded.Thenafterrectifyingthequotasituation,thefilecanbemovedbacktothe filesystemitbelongson. 2.Administeringthequotasystem Tosetupandestablishthediscquotasystem,thereareseveralstepsnecessarytobeperformedbythesystemadministrator. First,thesystemmustbeconfiguredtoincludethediscquotasub-system.Thisisdoneby includingtheline: optionsQUOTA inthesystemconfigurationfile,thenrunningconfig(8)followedbyasystemconfiguration*. Second,adecisionastowhatfilesystemsneedtohavequotasappliedneedstobemade. Usually,onlyfilesystemsthathouseusers’homedirectories,orotheruserfiles,willneedtobe subjectedtothequotasystem,thoughitmayalsoproveusefultoalsoinclude/usr.Ifpossible, /tmpshouldusuallybefreeofquotas. Havingdecidedonwhichfilesystemsquotasneedtobesetupon,theadministratorshould thenallocatetheavailablespaceamongstthecompetingneeds.Howthisshouldbedoneis(way) beyondthescopeofthisdocument. Then,theedquota(8)commandcanbeusedtoactuallysetthelimitsdesireduponeach user.Whereanumberofusersaretobegiventhesamequotas(acommonoccurrence)the−p switchtoedquotawillallowthistobeeasilyaccomplished. Oncethequotasareset,readytooperate,thesystemmustbeinformedtoenforcequotason thedesiredfilesystems.Thisisaccomplishedwiththequotaon(8)command.Quotaonwilleither enablequotasforaparticularfilesystem,orwiththe−aswitch,willenablequotasforeachfilesystemindicatedin/etc/fstabasusingquotas.Seefstab(5)fordetails.Mostsitesusingthequota system,willincludetheline /etc/quotaon-a in/etc/rc.local. Shouldquotasneedtobedisabled,thequotaoff(8)commandwilldothat,however,should thefilesystembeabouttobedismounted,theumount(8)commandwilldisablequotasimmediatelybeforethefilesystemisunmounted.Thisisactuallyaneffectoftheumount(2)systemcall, anditguaranteesthatthequotasystemwillnotbedisablediftheumountwouldfailbecausethe filesystemisnotidle. Periodically(certainlyaftereachreboot,andwhenquotasarefirstenabledforafilesystem), therecordsretainedinthequotafileshouldbecheckedforconsistencywiththeactualnumberof blocksandfilesallocatedtotheuser.Thequotachk(8)commandcanbeusedtoaccomplishthis. Itisnotnecessarytodismountthefilesystem,ordisablethequotasystemtorunthiscommand, thoughonactivefilesystemsinaccurateresultsmayoccur.Thisdoesnorealharminmostcases, anotherrunofquotachkwhenthefilesystemisidlewillcertainlycorrectanyinaccuracy. Thesuper-usermayusethequota(1)commandtoexaminetheusageandquotasofany user,andtherepquota(8)commandmaybeusedtochecktheusagesandlimitsforallusersona filesystem. 3.Someimplementationdetail. Discquotausageandinformationisstoredinafileonthefilesystemthatthequotasareto beappliedto.Conventionally,thisfileisquotasintherootofthefilesystem.Whilethisnameis notknowntothesysteminanyway,severaloftheuserlevelutilities"know"it,andchoosingany othernamewouldnotbewise. *Seealsothedocument‘‘Building4.2BSDUNIXSystemswithConfig’’.

-3-Thedatainthefilecomprisesanarrayofstructures,indexedbyuid,onestructureforeach useronthesystem(whethertheuserhasaquotaonthisfilesystemornot).Iftheuidspaceis sparse,thenthefilemayhaveholesinit,whichwouldbelostbycopying,soitisbesttoavoid this. Thesystemisinformedoftheexistenceofthequotafilebythesetquota(2)systemcall.It thenreadsthequotaentriesforeachusercurrentlyactive,thenforanyfilesopenownedbyusers whoarenotcurrentlyactive.Eachsubsequentopenofafileonthefilesystem,willbeaccompaniedbyapairingwithitsquotainformation.Inmostcasesthisinformationwillberetainedin core,eitherbecausetheuserwhoownsthefileisrunningsomeprocess,becauseotherfilesare openownedbythesameuser,orbecausesomefile(perhapsthisone)wasrecentlyaccessed.In memory,thequotainformationiskepthashedbyuser-idandfilesystem,andretainedinanLRU chainsorecentlyreleaseddatacanbeeasilyreclaimed.Informationaboutthoseuserswhoselast processhasrecentlyterminatedisalsoretainedinthisway. Eachtimeablockisaccessedorreleased,andeachtimeaninodeisallocatedorfreed,the quotasystemgetstoldaboutit,andinthecaseofallocations,getstheopportunitytoobject. Measurementshaveshownthatthequotacodeusesaverysmallpercentageofthesystem cputimeconsumedinwritinganewblocktodisc. 4.Acknowledgments Thecurrentdiscquotasystemislooselybaseduponaveryearlyschemeimplementedatthe UniversityofNewSouthWales,andSydneyUniversityinthemid70’s.Thatsystemimplemented asinglecombinedlimitforbothfilesandblocksonallfilesystems. AlatersystemwasimplementedattheUniversityofMelbournebytheauthor,butwasnot kepthighlyaccurately,eg:chown’s(etc)didnotaffectquotas,nordidi/otoafileotherthanone ownedbytheinstigator. Thecurrentsystemhasbeenrunning(withonlyminormodifications)sinceJanuary82at Melbourne.Itisactuallyjustasmallpartofamuchbroaderresourcecontrolscheme,whichis capableofcontrollingalmostanythingthatisusuallyuncontrolledinunix.Therestofthisis,as yet,stillinastatewhereitisfartoosubjecttochangetobeconsideredfordistribution. Forthe4.2BSDrelease,muchworkhasbeendonetocleanupandsanelyincorporatethe quotacodebySamLefflerandKirkMcKusickatTheUniversityofCaliforniaatBerkeley.